From f97578591f6d97b0aec7bc5b6466b9f4fc5a48b1 Mon Sep 17 00:00:00 2001
From: ziji Wu <2193177243@qq.com>
Date: Thu, 10 Oct 2019 19:42:49 +0800
Subject: [PATCH] comment
---
src/.idea/workspace.xml | 165 +++++++++---------
.../micode/notes/ui/NotesListActivity.java | 125 +++++++++++--
2 files changed, 196 insertions(+), 94 deletions(-)
diff --git a/src/.idea/workspace.xml b/src/.idea/workspace.xml
index 1de928d..0b04a9e 100644
--- a/src/.idea/workspace.xml
+++ b/src/.idea/workspace.xml
@@ -7,19 +7,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
@@ -54,24 +42,35 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
@@ -97,8 +96,8 @@
-
-
+
+
@@ -108,15 +107,6 @@
-
-
-
-
-
-
-
-
-
@@ -134,15 +124,6 @@
-
-
-
-
-
-
-
-
-
@@ -828,7 +809,14 @@
1570527902675
-
+
+ 1570673666384
+
+
+
+ 1570673666384
+
+
@@ -845,7 +833,7 @@
-
+
@@ -863,14 +851,14 @@
-
+
-
+
@@ -914,31 +902,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1221,18 +1184,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1247,24 +1198,70 @@
-
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/app/src/main/java/net/micode/notes/ui/NotesListActivity.java b/src/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
index 3326c4c..6940eee 100644
--- a/src/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
+++ b/src/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
@@ -317,7 +317,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
item.setTitle(R.string.menu_deselect_all);
} else {
item.setChecked(false);
- item.setTitle(R.string.menu_select_all);//设置标题,
+ item.setTitle(R.string.menu_select_all);//设置标题,字符来自R文件
}
}
}
@@ -346,17 +346,20 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
boolean checked) {
mNotesListAdapter.setCheckedItem(position, checked);
updateMenu();
- }
+ }//在选中项目更改后更新
+ //对菜单点击进行响应
public boolean onMenuItemClick(MenuItem item) {
if (mNotesListAdapter.getSelectedCount() == 0) {
Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),
- Toast.LENGTH_SHORT).show();
+ Toast.LENGTH_SHORT).show();//显示没有选中,操作无效
return true;
}
switch (item.getItemId()) {
+ //对项目进行操作
case R.id.delete:
+ //删除
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(getString(R.string.alert_title_delete));
builder.setIcon(android.R.drawable.ic_dialog_alert);
@@ -373,20 +376,28 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
builder.show();
break;
case R.id.move:
+ //移动
startQueryDestinationFolders();
break;
default:
+ //返回false,操作失败
return false;
}
return true;
}
}
+ /*
+ * 该类实现点击新建便签按钮,新建便签的实现方法
+ * */
private class NewNoteOnTouchListener implements OnTouchListener {
public boolean onTouch(View v, MotionEvent event) {
+ //获取事件列表中的操作
switch (event.getAction()) {
+ //按下按钮的情况
case MotionEvent.ACTION_DOWN: {
+ //显示默认窗体
Display display = getWindowManager().getDefaultDisplay();
int screenHeight = display.getHeight();
int newNoteViewHeight = mAddNewNote.getHeight();
@@ -463,14 +474,19 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
+ //对token进行选择,执行不同操作
switch (token) {
+ //文件夹下列表查询
case FOLDER_NOTE_LIST_QUERY_TOKEN:
mNotesListAdapter.changeCursor(cursor);
break;
+ //文件列表查询
case FOLDER_LIST_QUERY_TOKEN:
+ //存在文件夹
if (cursor != null && cursor.getCount() > 0) {
showFolderListMenu(cursor);
} else {
+ //记入错误日志,无文件夹
Log.e(TAG, "Query folder failed");
}
break;
@@ -480,8 +496,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
+ /*
+ * 该方法实现了展示文件夹列表的功能
+ * @ cursor 游标,获取文件夹信息
+ * */
private void showFolderListMenu(Cursor cursor) {
+ //新建窗体
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
+ //设置标题
builder.setTitle(R.string.menu_title_select_folder);
final FoldersListAdapter adapter = new FoldersListAdapter(this, cursor);
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
@@ -498,12 +520,18 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mModeCallBack.finishActionMode();
}
});
+ //展示窗体
builder.show();
}
+ /*
+ * 该方法实现了创建空的新便签功能
+ * */
private void createNewNote() {
Intent intent = new Intent(this, NoteEditActivity.class);
+ //设置便签状态,插入或者编辑
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
+ //插入便签信息
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mCurrentFolderId);
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
}
@@ -545,8 +573,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}.execute();
}
+ /*
+ * 该方法实现了删除文件夹得功能
+ * @ folderId 要删除文件夹得id
+ * */
private void deleteFolder(long folderId) {
if (folderId == Notes.ID_ROOT_FOLDER) {
+ //删除父文件夹时报错
Log.e(TAG, "Wrong folder id, should not happen " + folderId);
return;
}
@@ -556,10 +589,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
HashSet widgets = DataUtils.getFolderNoteWidget(mContentResolver,
folderId);
if (!isSyncMode()) {
- // if not synced, delete folder directly
+ // 如果没有同步,直接删除
DataUtils.batchDeleteNotes(mContentResolver, ids);
} else {
- // in sync mode, we'll move the deleted folder into the trash folder
+ // 如果同步,丢入垃圾箱
DataUtils.batchMoveToFolder(mContentResolver, ids, Notes.ID_TRASH_FOLER);
}
if (widgets != null) {
@@ -579,25 +612,35 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
}
+ /*
+ * 该方法实现了打开文件夹的功能
+ * */
private void openFolder(NoteItemData data) {
+ //获取当前文件夹id
mCurrentFolderId = data.getId();
startAsyncNotesListQuery();
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
+ //状态设为
mState = ListEditState.CALL_RECORD_FOLDER;
mAddNewNote.setVisibility(View.GONE);
} else {
mState = ListEditState.SUB_FOLDER;
}
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
+ //设置文本内容为“通话便签”
mTitleBar.setText(R.string.call_record_folder_name);
} else {
mTitleBar.setText(data.getSnippet());
}
+ //将内容展示出来
mTitleBar.setVisibility(View.VISIBLE);
}
+ //界面视图下点击操作
public void onClick(View v) {
+ //对点击的id进行区分
switch (v.getId()) {
+ //如果按下“新建便签”按钮,新建便签
case R.id.btn_new_note:
createNewNote();
break;
@@ -607,42 +650,59 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
private void showSoftInput() {
+ //获取输入法服务
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ //如果输入法存在
if (inputMethodManager != null) {
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
}
+ //隐藏输入键盘
private void hideSoftInput(View view) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
+ /*
+ * 该方法实现了新建或者修改文件夹的方法
+ * @ create 判断是否为新建文件夹
+ * false - 修改文件夹
+ * true - 新建文件夹
+ * */
private void showCreateOrModifyFolderDialog(final boolean create) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ //声明视图,使用样式为dialog_edit_text
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
final EditText etName = (EditText) view.findViewById(R.id.et_foler_name);
+ //显示键盘
showSoftInput();
if (!create) {
if (mFocusNoteDataItem != null) {
etName.setText(mFocusNoteDataItem.getSnippet());
+ //显示内容“修改文件夹名称”
builder.setTitle(getString(R.string.menu_folder_change_name));
} else {
+ //错误信息写入日志
Log.e(TAG, "The long click data item is null");
return;
}
} else {
etName.setText("");
+ //显示内容,“新建文件夹”
builder.setTitle(this.getString(R.string.menu_create_folder));
}
+ //设置ok按钮
builder.setPositiveButton(android.R.string.ok, null);
+ //设置“取消”按钮
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
hideSoftInput(etName);
}
});
+ //展示窗体,显示界面
final Dialog dialog = builder.setView(view).show();
final Button positive = (Button)dialog.findViewById(android.R.id.button1);
positive.setOnClickListener(new OnClickListener() {
@@ -680,7 +740,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
positive.setEnabled(false);
}
/**
- * When the name edit text is null, disable the positive button
+ * 当未输入名称时,ok键为灰色
*/
etName.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@@ -689,9 +749,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
+ //如果输入内容为空
if (TextUtils.isEmpty(etName.getText())) {
+ //ok键无效,置为灰色
positive.setEnabled(false);
} else {
+ //否则,ok键有效
positive.setEnabled(true);
}
}
@@ -705,13 +768,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
@Override
public void onBackPressed() {
+ //对当前状态进行选择
switch (mState) {
+ //位于子文件夹下
case SUB_FOLDER:
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
+ //状态置为列表状态
mState = ListEditState.NOTE_LIST;
startAsyncNotesListQuery();
mTitleBar.setVisibility(View.GONE);
break;
+ //位于通话记录文件夹下
case CALL_RECORD_FOLDER:
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mState = ListEditState.NOTE_LIST;
@@ -719,6 +786,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mTitleBar.setVisibility(View.GONE);
startAsyncNotesListQuery();
break;
+ //位于便签列表下
case NOTE_LIST:
super.onBackPressed();
break;
@@ -727,6 +795,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
+ //更新widget的方法,根据appWidgetId设置widget形式
private void updateWidget(int appWidgetId, int appWidgetType) {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
if (appWidgetType == Notes.TYPE_WIDGET_2X) {
@@ -742,14 +811,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
appWidgetId
});
+ //将intent的内容广播
sendBroadcast(intent);
setResult(RESULT_OK, intent);
}
private final OnCreateContextMenuListener mFolderOnCreateContextMenuListener = new OnCreateContextMenuListener() {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
+ //如果当前便签数据项不为空
if (mFocusNoteDataItem != null) {
menu.setHeaderTitle(mFocusNoteDataItem.getSnippet());
+ //设置菜单内容
menu.add(0, MENU_FOLDER_VIEW, 0, R.string.menu_folder_view);
menu.add(0, MENU_FOLDER_DELETE, 0, R.string.menu_folder_delete);
menu.add(0, MENU_FOLDER_CHANGE_NAME, 0, R.string.menu_folder_change_name);
@@ -759,26 +831,37 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
@Override
public void onContextMenuClosed(Menu menu) {
+ //如果当前处于便签列表形式
if (mNotesListView != null) {
+ //显示菜单栏
mNotesListView.setOnCreateContextMenuListener(null);
}
+ //调用父类的构造函数
super.onContextMenuClosed(menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if (mFocusNoteDataItem == null) {
+ //长按数据项为空,报错并记入日志
Log.e(TAG, "The long click data item is null");
return false;
}
+ //对item的id进行判断
switch (item.getItemId()) {
+ //如果是文件夹,打开文件夹
case MENU_FOLDER_VIEW:
openFolder(mFocusNoteDataItem);
break;
+ //如果是删除文件夹
case MENU_FOLDER_DELETE:
+ //声明警示窗口
AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ //设置标题
builder.setTitle(getString(R.string.alert_title_delete));
+ //设置警告图标
builder.setIcon(android.R.drawable.ic_dialog_alert);
+ //设置内容,确认是否删除
builder.setMessage(getString(R.string.alert_message_delete_folder));
builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@@ -786,16 +869,18 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
deleteFolder(mFocusNoteDataItem.getId());
}
});
+ //取消则不执行任何操作
builder.setNegativeButton(android.R.string.cancel, null);
builder.show();
break;
+ //如果是修改文件夹名称
case MENU_FOLDER_CHANGE_NAME:
showCreateOrModifyFolderDialog(false);
break;
default:
break;
}
-
+ //操作成功,返回true
return true;
}
@@ -804,38 +889,56 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
menu.clear();
if (mState == ListEditState.NOTE_LIST) {
getMenuInflater().inflate(R.menu.note_list, menu);
- // set sync or sync_cancel
+ // 设置是否同步
menu.findItem(R.id.menu_sync).setTitle(
GTaskSyncService.isSyncing() ? R.string.menu_sync_cancel : R.string.menu_sync);
- } else if (mState == ListEditState.SUB_FOLDER) {
+ } else if (mState == ListEditState.SUB_FOLDER) {//如果位于子文件夹下
+ //菜单采用子文件夹下的形式,只有添加便签选项
getMenuInflater().inflate(R.menu.sub_folder, menu);
- } else if (mState == ListEditState.CALL_RECORD_FOLDER) {
+ } else if (mState == ListEditState.CALL_RECORD_FOLDER) {//如果位于通话记录文件夹下
+ //菜单仅仅提供搜索功能
getMenuInflater().inflate(R.menu.call_record_folder, menu);
} else {
+ //状态不合法,记入日志
Log.e(TAG, "Wrong state:" + mState);
}
+ //
return true;
}
+ /*
+ * 该方法实现了对菜单功能的实现
+ * @ item 选中的菜单项
+ * */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
+ //对选中的菜单项进行判断
switch (item.getItemId()) {
+ //如果按下的是新建文件夹按钮
case R.id.menu_new_folder: {
+ //新建文件夹,true - 新建模式
showCreateOrModifyFolderDialog(true);
break;
}
+ //如果按下的是导出文本按钮
case R.id.menu_export_text: {
+ //导出文本
exportNoteToText();
break;
}
+ //如果按下的是同步按钮
case R.id.menu_sync: {
+ //判断当前是否为同步模式
if (isSyncMode()) {
+ //处于同步模式,且确认后直接同步
if (TextUtils.equals(item.getTitle(), getString(R.string.menu_sync))) {
GTaskSyncService.startSync(this);
} else {
+ //处于同步模式,取消同步
GTaskSyncService.cancelSync(this);
}
} else {
+ //不处于同步模式,
startPreferenceActivity();
}
break;
@@ -905,11 +1008,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}.execute();
}
+ //判断是否位于同步模式的私有方法
private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
}
private void startPreferenceActivity() {
+ //新建activity,如果有父activity,用父activity,否则新建
Activity from = getParent() != null ? getParent() : this;
Intent intent = new Intent(from, NotesPreferenceActivity.class);
from.startActivityIfNeeded(intent, -1);