Update NotesListActivity.java

main
p6zpjanrb 10 months ago
parent 55390d17be
commit 25ea5ecf7a

@ -77,65 +77,91 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
//这个类实现了一个便签列表的界面,并包含了点击事件和长按事件的处理。
public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener {
// 定义查询便签列表的令牌
private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;
// 定义查询文件夹列表的令牌
private static final int FOLDER_LIST_QUERY_TOKEN = 1;
// 定义文件夹菜单选项的常量
private static final int MENU_FOLDER_DELETE = 0;
private static final int MENU_FOLDER_VIEW = 1;
private static final int MENU_FOLDER_CHANGE_NAME = 2;
// 定义保存便签介绍的偏好设置参数名称
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
// 枚举类型,表示列表编辑状态
private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
};
// 保存当前列表的编辑状态
private ListEditState mState;
// 后台查询操作的处理程序
private BackgroundQueryHandler mBackgroundQueryHandler;
// 便签列表数据适配器
private NotesListAdapter mNotesListAdapter;
// 显示便签列表的ListView
private ListView mNotesListView;
// 添加新便签的按钮
private Button mAddNewNote;
// 标识是否分发触摸事件
private boolean mDispatch;
// 原始触摸事件的Y坐标
private int mOriginY;
// 分发触摸事件的Y坐标
private int mDispatchY;
// 显示标题的文本视图
private TextView mTitleBar;
// 当前文件夹的ID
private long mCurrentFolderId;
// 内容解析器,用于访问应用程序的内容提供程序
private ContentResolver mContentResolver;
// 操作模式的回调接口
private ModeCallback mModeCallBack;
// 日志标签
private static final String TAG = "NotesListActivity";
// 便签列表滚动速率
public static final int NOTES_LISTVIEW_SCROLL_RATE = 30;
// 当前焦点便签数据项
private NoteItemData mFocusNoteDataItem;
// 便签正常选择的条件
private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";
// 根文件夹选择的条件
private static final String ROOT_FOLDER_SELECTION = "(" + NoteColumns.TYPE + "<>"
+ Notes.TYPE_SYSTEM + " AND " + NoteColumns.PARENT_ID + "=?)" + " OR ("
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER + " AND "
+ NoteColumns.NOTES_COUNT + ">0)";
// 打开便签的请求码
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
/*
onCreate Activity Activity onCreate note_list initResources setAppInfoFromRawRes
*/
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.note_list);
@ -146,7 +172,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
*/
setAppInfoFromRawRes();
}
/*
onActivityResult startActivityForResult 便便 mNotesListAdapter.changeCursor(null) 便 onActivityResult
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK
@ -156,7 +184,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
super.onActivityResult(requestCode, resultCode, data);
}
}
/*
setAppInfoFromRawRes 便 SharedPreferences StringBuilder getResources().openRawResource(R.raw.introduction) introduction StringBuilder WorkingNote IDApp Widget ID便便便 true
*/
private void setAppInfoFromRawRes() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
@ -204,11 +234,23 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
@Override
/*
onStart startAsyncNotesListQuery
*/
protected void onStart() {
super.onStart();
startAsyncNotesListQuery();
}
/*
initResources
ContentResolver BackgroundQueryHandler
mCurrentFolderId
mNotesListView
mAddNewNote
ModeCallback
*/
private void initResources() {
mContentResolver = this.getContentResolver();
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
@ -230,7 +272,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mState = ListEditState.NOTE_LIST;
mModeCallBack = new ModeCallback();
}
/*
ModeCallback ListView
ActionMode
*/
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
private DropdownMenu mDropDownMenu;
private ActionMode mActionMode;
@ -268,7 +315,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
});
return true;
}
/*
updateMenu
使
/
*/
private void updateMenu() {
int selectedCount = mNotesListAdapter.getSelectedCount();
// Update dropdown menu
@ -285,17 +339,24 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
}
/*
onPrepareActionMode ActionMode false
*/
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
//onActionItemClicked 方法用于在点击 ActionMode 的菜单项时执行一些操作,但在这个方法中并没有实现任何逻辑,返回值为 false。
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// TODO Auto-generated method stub
return false;
}
/*
onDestroyActionMode ActionMode
false
mAddNewNote
*/
public void onDestroyActionMode(ActionMode mode) {
mNotesListAdapter.setChoiceMode(false);
mNotesListView.setLongClickable(true);
@ -305,13 +366,22 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
public void finishActionMode() {
mActionMode.finish();
}
/*
onItemCheckedStateChanged
updateMenu
*/
public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
boolean checked) {
mNotesListAdapter.setCheckedItem(position, checked);
updateMenu();
}
/*
onMenuItemClick
Toast
true
*/
public boolean onMenuItemClick(MenuItem item) {
if (mNotesListAdapter.getSelectedCount() == 0) {
Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),

Loading…
Cancel
Save