对NoteListActivity 的注释

pull/6/head
SheYu 11 months ago
parent f58b236284
commit 92ce5196a8

Binary file not shown.

@ -24,7 +24,14 @@ import android.telephony.PhoneNumberUtils;
import android.util.Log; import android.util.Log;
import java.util.HashMap; import java.util.HashMap;
/**
* @Package: net.micode.notes.data
* @ClassName: Contact
* @Description: java
* @Author: WUSHUXIAN
* @CreateDate: 2023/12/20 23:26
* @Version: 1.0
*/
public class Contact { public class Contact {
private static HashMap<String, String> sContactCache; private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact"; private static final String TAG = "Contact";

@ -62,12 +62,16 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.HashSet; import java.util.HashSet;
//主界面,一进入就是这个界面
/** /**
* @author k * @Package: net.micode.notes.ui
* * @ClassName: NotesListActivity
* @Description:
* @Author: WUSHUXIAN
* @CreateDate: 2023/12/20 23:02
* @Version: 1.0
*/ */
public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener { //没有用特定的标签加注释。。。感觉没有什么用 public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener {
private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0; private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;
private static final int FOLDER_LIST_QUERY_TOKEN = 1; private static final int FOLDER_LIST_QUERY_TOKEN = 1;
@ -78,7 +82,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private static final int MENU_FOLDER_CHANGE_NAME = 2; private static final int MENU_FOLDER_CHANGE_NAME = 2;
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction"; //单行超过80个字符 private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
private enum ListEditState { private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
@ -123,51 +127,68 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private final static int REQUEST_CODE_OPEN_NODE = 102; private final static int REQUEST_CODE_OPEN_NODE = 102;
private final static int REQUEST_CODE_NEW_NODE = 103; private final static int REQUEST_CODE_NEW_NODE = 103;
@Override @Override
// 创建类 /**
protected void onCreate(final Bundle savedInstanceState) { //需要是final类型 根据程序上下文环境Java关键字final有“这是无法改变的”或者“终态的”含义它可以修饰非抽象类、非抽象类成员方法和变量。你可能出于两种理解而需要阻止改变设计或效率。 * @method onCreate
// final类不能被继承没有子类final类中的方法默认是final的。 * @description final Javafinal
//final方法不能被子类的方法覆盖但可以被继承。 * finalfinalfinal
//final成员变量表示常量只能被赋值一次赋值后值不再改变。 * final
//final不能用于修饰构造方法。 * final
* final
* @date: 2023/12/20 23:13
* @author: WUSHUXIAN
* @param void
* @return void
*/
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // 调用父类的onCreate函数 super.onCreate(savedInstanceState); // 调用父类的onCreate函数
setContentView(R.layout.note_list); setContentView(R.layout.note_list);
initResources(); initResources();
/**
* Insert an introduction when user firstly use this application
*/
setAppInfoFromRawRes(); setAppInfoFromRawRes();
} }
@Override @Override
// 返回一些子模块完成的数据交给主Activity处理 /**
* @method onActivityResult
* @description: Activity
*
* requestCode
* resultCode
* data
* @date: 2023/12/20 23:26
* @author: WUSHUXIAN
* @param void
* @return void
*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// 结果值 和 要求值 符合要求 // 结果值 和 要求值 符合要求
if (resultCode == RESULT_OK if (resultCode == RESULT_OK
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) { && (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
mNotesListAdapter.changeCursor(null); mNotesListAdapter.changeCursor(null);
} else { } else {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);// 调用 Activity 的onActivityResult()
// 调用 Activity 的onActivityResult
} }
} }
/**
* @method setAppInfoFromRawRes
* @description:
* @date: 2023/12/20 23:24
* @author: WUSHUXIAN
* @param
* @return
*/
private void setAppInfoFromRawRes() { private void setAppInfoFromRawRes() {
// Android平台给我们提供了一个SharedPreferences类它是一个轻量级的存储类特别适合用于保存软件配置参数。 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);// Android平台给我们提供了一个SharedPreferences类它是一个轻量级的存储类特别适合用于保存软件配置参数。
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) { if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
InputStream in = null; InputStream in = null;
try { try {
// 把资源文件放到应用程序的/raw/raw下那么就可以在应用中使用getResources获取资源后, // 把资源文件放到应用程序的/raw/raw下那么就可以在应用中使用getResources获取资源后,以openRawResource方法不带后缀的资源文件名打开这个文件。
// 以openRawResource方法不带后缀的资源文件名打开这个文件。
in = getResources().openRawResource(R.raw.introduction); in = getResources().openRawResource(R.raw.introduction);
if (in != null) { if (in != null) {
InputStreamReader isr = new InputStreamReader(in); InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr); BufferedReader br = new BufferedReader(isr);
char [] buf = new char[1024]; // 自行定义的数值,使用者不知道有什么意义 char [] buf = new char[1024];
int len = 0; int len = 0;
while ((len = br.read(buf)) > 0) { while ((len = br.read(buf)) > 0) {
sb.append(buf, 0, len); sb.append(buf, 0, len);
@ -210,8 +231,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
super.onStart(); super.onStart();
startAsyncNotesListQuery(); startAsyncNotesListQuery();
} }
/**
// 初始化资源 * @method initResources
* @description
* @date: 2023/12/20 23:09
* @author: WUSHUXIAN
* @param
* @return
*/
private void initResources() { private void initResources() {
mContentResolver = this.getContentResolver(); // 获取应用程序的数据,得到类似数据表的东西 mContentResolver = this.getContentResolver(); // 获取应用程序的数据,得到类似数据表的东西
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver()); mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
@ -236,7 +263,15 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mModeCallBack = new ModeCallback(); mModeCallBack = new ModeCallback();
} }
// 继承自ListView.MultiChoiceModeListener 和 OnMenuItemClickListener //
/**
* @Package: net.micode.notes.ui
* @ClassName: ModeCallback
* @Description: ListView.MultiChoiceModeListener OnMenuItemClickListener
* @Author: WUSHUXIAN
* @CreateDate: 2023/12/20 23:37
* @Version: 1.0
*/
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener { private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
private DropdownMenu mDropDownMenu; private DropdownMenu mDropDownMenu;
private ActionMode mActionMode; private ActionMode mActionMode;
@ -274,8 +309,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}); });
return true; return true;
} }
/**
// 更新菜单 * @method updateMenu
* @description
* @date: 2023/12/16 23:36
* @author: WUSHUXIAN
* @param
* @return
*/
private void updateMenu() { private void updateMenu() {
int selectedCount = mNotesListAdapter.getSelectedCount(); int selectedCount = mNotesListAdapter.getSelectedCount();
// Update dropdown menu // Update dropdown menu
@ -318,7 +359,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mNotesListAdapter.setCheckedItem(position, checked); mNotesListAdapter.setCheckedItem(position, checked);
updateMenu(); updateMenu();
} }
/**
* @method onMenuItemClick
* @description:
* @date: 2023/12/20 23:39
* @author: WUSHUXIAN
* @param
* @return
*/
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
if (mNotesListAdapter.getSelectedCount() == 0) { if (mNotesListAdapter.getSelectedCount() == 0) {
Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none), Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),
@ -350,9 +398,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true; return true;
} }
} }
//接口的实现
private class NewNoteOnTouchListener implements OnTouchListener { private class NewNoteOnTouchListener implements OnTouchListener {
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) { switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: { case MotionEvent.ACTION_DOWN: {
@ -412,22 +459,44 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} }
}; };
/**
* @method startAsyncNotesListQuery
* @description: Notes
* @date: 2023/12/20 23:45
* @author: WUSHUXIAN
* @param
* @return
*/
private void startAsyncNotesListQuery() { private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION : NORMAL_SELECTION;
: NORMAL_SELECTION;
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null, mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] { Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {String.valueOf(mCurrentFolderId)},
String.valueOf(mCurrentFolderId) NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
} }
/**
* @Package: net.micode.notes.ui
* @ClassName: BackgroundQueryHandler
* @Description: AsyncQueryHandler
* @Author: WUSHUXIAN
* @CreateDate: 2023/12/21 0:01
* @Version: 1.0
*/
private final class BackgroundQueryHandler extends AsyncQueryHandler { private final class BackgroundQueryHandler extends AsyncQueryHandler {
public BackgroundQueryHandler(ContentResolver contentResolver) { public BackgroundQueryHandler(ContentResolver contentResolver) {
super(contentResolver); super(contentResolver);
} }
@Override @Override
/**
* @method onQueryComplete
* @description:
* @date: 2023/12/20 23:56
* @author: WUSHUXIAN
* @param token
* @param cookie cookie
* @param cursor
* @return void
*/
protected void onQueryComplete(int token, Object cookie, Cursor cursor) { protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
switch (token) { switch (token) {
case FOLDER_NOTE_LIST_QUERY_TOKEN: case FOLDER_NOTE_LIST_QUERY_TOKEN:
@ -473,22 +542,29 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mCurrentFolderId); intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mCurrentFolderId);
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE); this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
} }
/**
* @method batchDelete
* @description: 便
* @date: 2023/12/21 0:14
* @author: WUSHUXIAN
* @param
* @return void
*/
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
private void batchDelete() { private void batchDelete() {
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() { new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) { protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget(); HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget();
//如果没有同步,直接删除
if (!isSyncMode()) { if (!isSyncMode()) {
// if not synced, delete notes directly
if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
.getSelectedItemIds())) { .getSelectedItemIds())) {
} else { } else {
Log.e(TAG, "Delete notes error, should not happens"); Log.e(TAG, "Delete notes error, should not happens");
} }
} else { }
// in sync mode, we'll move the deleted note into the trash //已同步,将删除的便签移到垃圾桶
// folder else {
if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
.getSelectedItemIds(), Notes.ID_TRASH_FOLER)) { .getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
Log.e(TAG, "Move notes to trash folder error, should not happens"); Log.e(TAG, "Move notes to trash folder error, should not happens");
@ -511,7 +587,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} }
}.execute(); }.execute();
} }
/**
* @method deleteFolder
* @description:
* @date: 2023/12/21 0:32
* @author: WUSHUXIAN
* @param folderId
* @return void
*/
private void deleteFolder(long folderId) { private void deleteFolder(long folderId) {
if (folderId == Notes.ID_ROOT_FOLDER) { if (folderId == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Wrong folder id, should not happen " + folderId); Log.e(TAG, "Wrong folder id, should not happen " + folderId);
@ -580,7 +663,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
} }
/**
* @method showCreateOrModifyFolderDialog
* @description:
* @date: 2023/12/21 0:39
* @author: WUSHUXIAN
* @param create
* @return void
*/
private void showCreateOrModifyFolderDialog(final boolean create) { private void showCreateOrModifyFolderDialog(final boolean create) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null); View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
@ -638,13 +728,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
dialog.dismiss(); dialog.dismiss();
} }
}); });
//如果便签名是空的,则禁用确认按钮
if (TextUtils.isEmpty(etName.getText())) { if (TextUtils.isEmpty(etName.getText())) {
positive.setEnabled(false); positive.setEnabled(false);
} }
/**
* When the name edit text is null, disable the positive button
*/
etName.addTextChangedListener(new TextWatcher() { etName.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -671,7 +758,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
* *
*/ */
@Override @Override
public void onBackPressed() { switch (mState) { public void onBackPressed() {
switch (mState) {
case SUB_FOLDER: case SUB_FOLDER:
mCurrentFolderId = Notes.ID_ROOT_FOLDER; mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mState = ListEditState.NOTE_LIST; mState = ListEditState.NOTE_LIST;

@ -30,7 +30,14 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
/**
* @Package: net.micode.notes.ui
* @ClassName: NotesListAdapter
* @Description: java
* @Author: WUSHUXIAN
* @CreateDate: 2023/12/20 23:04
* @Version: 1.0
*/
public class NotesListAdapter extends CursorAdapter { public class NotesListAdapter extends CursorAdapter {
private static final String TAG = "NotesListAdapter"; private static final String TAG = "NotesListAdapter";
private Context mContext; private Context mContext;

@ -29,7 +29,14 @@ import net.micode.notes.data.Notes;
import net.micode.notes.tool.DataUtils; import net.micode.notes.tool.DataUtils;
import net.micode.notes.tool.ResourceParser.NoteItemBgResources; import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
/**
* @Package: net.micode.notes.ui
* @ClassName: NotesListItem
* @Description: java
* @Author: WUSHUXIAN
* @CreateDate: 2023/12/20 23:09
* @Version: 1.0
*/
public class NotesListItem extends LinearLayout { public class NotesListItem extends LinearLayout {
private ImageView mAlert; private ImageView mAlert;
private TextView mTitle; private TextView mTitle;

@ -39,6 +39,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
NoteColumns.SNIPPET NoteColumns.SNIPPET
}; };
public static final int COLUMN_ID = 0; public static final int COLUMN_ID = 0;
public static final int COLUMN_BG_COLOR_ID = 1; public static final int COLUMN_BG_COLOR_ID = 1;
public static final int COLUMN_SNIPPET = 2; public static final int COLUMN_SNIPPET = 2;

Loading…
Cancel
Save