|
|
|
@ -94,7 +94,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
private enum ListEditState {
|
|
|
|
|
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ListEditState mState;
|
|
|
|
|
|
|
|
|
@ -247,6 +247,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
private Menu menu;
|
|
|
|
|
private MenuItem mMoveMenu;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
|
getMenuInflater().inflate(R.menu.note_list_options, menu);
|
|
|
|
|
this.menu = menu;
|
|
|
|
@ -265,6 +266,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
mAddNewNote.setVisibility(View.GONE);
|
|
|
|
|
mMenuSet.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
|
|
//取一个自定义的视图,设置给ActionMode,
|
|
|
|
|
// 并创建一个DropdownMenu(自定义的下拉菜单)对象,并设置下拉菜单项的点击监听器。
|
|
|
|
|
View customView = LayoutInflater.from(NotesListActivity.this).inflate(
|
|
|
|
|
R.layout.note_list_dropdown_menu, null);
|
|
|
|
|
mode.setCustomView(customView);
|
|
|
|
@ -282,6 +285,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*更新下拉菜单的标题和选择项状态
|
|
|
|
|
*/
|
|
|
|
|
private void updateMenu() {
|
|
|
|
|
int selectedCount = mNotesListAdapter.getSelectedCount();
|
|
|
|
|
// Update dropdown menu
|
|
|
|
@ -309,6 +315,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//取消选择模式,清除选择项,恢复一些视图的可见性,并通知适配器数据集变化
|
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
|
|
|
|
mNotesListAdapter.setChoiceMode(false);
|
|
|
|
|
mNotesListView.clearChoices();
|
|
|
|
@ -349,6 +356,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
//判断是否有选中的项,如果没有则弹出一个Toast提示用户选择项为空
|
|
|
|
|
if (mNotesListAdapter.getSelectedCount() == 0) {
|
|
|
|
|
Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
@ -357,11 +365,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
builder.setMessage(getString(R.string.alert_message_delete_notes,
|
|
|
|
|
mNotesListAdapter.getSelectedCount()));
|
|
|
|
|
//确认按钮被点击时,调用batchDelete()方法批量删除选中的项;取消按钮则关闭对话框。
|
|
|
|
|
builder.setPositiveButton(android.R.string.ok,
|
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
@ -372,6 +382,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
|
|
|
|
builder.show();
|
|
|
|
|
break;
|
|
|
|
|
//如果是移动菜单项,则调用startQueryDestinationFolders()方法,
|
|
|
|
|
// 该方法会开启异步线程,并查询所有的目标文件夹,
|
|
|
|
|
// 查询结果会在回调函数onQueryComplete()中得到处理和展示
|
|
|
|
|
case R.id.move:
|
|
|
|
|
startQueryDestinationFolders();
|
|
|
|
|
break;
|
|
|
|
@ -383,10 +396,18 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*写便签的监听
|
|
|
|
|
*/
|
|
|
|
|
private class NewNoteOnTouchListener implements OnTouchListener {
|
|
|
|
|
|
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
|
switch (event.getAction()) {
|
|
|
|
|
//当用户按下手指时触发。
|
|
|
|
|
// 根据屏幕和"New Note"视图的高度计算出开始位置和事件Y坐标。
|
|
|
|
|
// 如果当前状态是ListEditState.SUB_FOLDER(列表编辑状态为子文件夹),
|
|
|
|
|
// 则减去标题栏的高度。然后检查是否点击了"New Note"按钮的透明部分,
|
|
|
|
|
// 如果是,则将事件分派给按钮后面的列表视图。
|
|
|
|
|
case MotionEvent.ACTION_DOWN: {
|
|
|
|
|
Display display = getWindowManager().getDefaultDisplay();
|
|
|
|
|
int screenHeight = display.getHeight();
|
|
|
|
@ -423,6 +444,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//当用户滑动手指时触发。如果之前已经分派了事件(即mDispatch为true),
|
|
|
|
|
// 则更新分派Y坐标并将事件重新定位,然后将其分派给列表视图。
|
|
|
|
|
case MotionEvent.ACTION_MOVE: {
|
|
|
|
|
if (mDispatch) {
|
|
|
|
|
mDispatchY += (int) event.getY() - mOriginY;
|
|
|
|
@ -431,6 +454,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//当用户释放手指时触发。
|
|
|
|
|
// 如果之前已经分派了事件(即mDispatch为true),则将事件重新定位并取消分派。
|
|
|
|
|
default: {
|
|
|
|
|
if (mDispatch) {
|
|
|
|
|
event.setLocation(event.getX(), mDispatchY);
|
|
|
|
@ -443,8 +468,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 启动异步查询便签列表的操作
|
|
|
|
|
*/
|
|
|
|
|
private void startAsyncNotesListQuery() {
|
|
|
|
|
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
|
|
|
|
|
: NORMAL_SELECTION;
|
|
|
|
@ -454,6 +482,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 执行后台查询操作
|
|
|
|
|
*/
|
|
|
|
|
@SuppressLint("HandlerLeak")
|
|
|
|
|
private final class BackgroundQueryHandler extends AsyncQueryHandler {
|
|
|
|
|
public BackgroundQueryHandler(ContentResolver contentResolver) {
|
|
|
|
|
super(contentResolver);
|
|
|
|
@ -478,6 +510,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示文件夹列表的菜单,供用户选择将便签移动到哪个文件夹中。
|
|
|
|
|
* @param cursor
|
|
|
|
|
*/
|
|
|
|
|
private void showFolderListMenu(Cursor cursor) {
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
|
|
|
|
|
builder.setTitle(R.string.menu_title_select_folder);
|
|
|
|
@ -506,6 +542,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量删除便签
|
|
|
|
|
*/
|
|
|
|
|
@SuppressLint("StaticFieldLeak")
|
|
|
|
|
private void batchDelete() {
|
|
|
|
|
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
|
|
|
|
@ -606,6 +645,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示软键盘
|
|
|
|
|
*/
|
|
|
|
|
private void showSoftInput() {
|
|
|
|
|
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
if (inputMethodManager != null) {
|
|
|
|
@ -618,6 +660,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示创建或编辑文件夹对话框
|
|
|
|
|
* @param create
|
|
|
|
|
*/
|
|
|
|
|
private void showCreateOrModifyFolderDialog(final boolean create) {
|
|
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
|
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
|
|
|
|
@ -731,6 +778,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新指定标识的小部件
|
|
|
|
|
* @param appWidgetId
|
|
|
|
|
* @param appWidgetType
|
|
|
|
|
*/
|
|
|
|
|
private void updateWidget(int appWidgetId, int appWidgetType) {
|
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
|
if (appWidgetType == Notes.TYPE_WIDGET_2X) {
|
|
|
|
@ -750,6 +802,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final OnCreateContextMenuListener mFolderOnCreateContextMenuListener = new OnCreateContextMenuListener() {
|
|
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
|
|
|
|
if (mFocusNoteDataItem != null) {
|
|
|
|
@ -803,6 +856,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据当前状态 mState 的不同,在菜单准备显示时根据状态填充不同的菜单项,并根据条件设置指定菜单项的标题。
|
|
|
|
|
* @param menu
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
|
menu.clear();
|
|
|
|
@ -867,6 +925,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导出笔记到文本文件
|
|
|
|
|
*/
|
|
|
|
|
@SuppressLint("StaticFieldLeak")
|
|
|
|
|
private void exportNoteToText() {
|
|
|
|
|
final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this);
|
|
|
|
|
new AsyncTask<Void, Void, Integer>() {
|
|
|
|
@ -960,6 +1022,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询目标文件夹列表
|
|
|
|
|
*/
|
|
|
|
|
private void startQueryDestinationFolders() {
|
|
|
|
|
String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?";
|
|
|
|
|
selection = (mState == ListEditState.NOTE_LIST) ? selection:
|
|
|
|
|