From 3ad0e4a5eb53b6ec0008de3e8149959be5a7f1ab Mon Sep 17 00:00:00 2001
From: Mars_RH <1658408137@qq.com>
Date: Thu, 25 May 2023 21:19:33 +0800
Subject: [PATCH 1/3] fixing bug and adding new fetures
---
src/app/src/main/AndroidManifest.xml | 14 +-
.../net/micode/notes/ui/NoteEditActivity.java | 1 +
.../micode/notes/ui/NotesListActivity.java | 50 +-
.../micode/notes/ui/RecycleBinActivity.java | 753 ++++++++++++++++++
src/app/src/main/res/layout/recycle_bin.xml | 36 +
src/app/src/main/res/menu/note_list.xml | 4 +
src/app/src/main/res/values/styles.xml | 2 +-
7 files changed, 851 insertions(+), 9 deletions(-)
create mode 100644 src/app/src/main/java/net/micode/notes/ui/RecycleBinActivity.java
create mode 100644 src/app/src/main/res/layout/recycle_bin.xml
diff --git a/src/app/src/main/AndroidManifest.xml b/src/app/src/main/AndroidManifest.xml
index 006f76f..25017cc 100644
--- a/src/app/src/main/AndroidManifest.xml
+++ b/src/app/src/main/AndroidManifest.xml
@@ -40,17 +40,27 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop"
- android:theme="@style/Theme.AppCompat"
- android:uiOptions="splitActionBarWhenNarrow"
+ android:theme="@style/NoteTheme"
android:windowSoftInputMode="adjustPan"
android:exported="true" >
+
+
+
+
+
+
+
>() {
protected HashSet doInBackground(Void... unused) {
HashSet widgets = mNotesListAdapter.getSelectedWidget();
- if (!isSyncMode()) {
- // if not synced, delete notes directly
+// if (!isSyncMode()) {
+// // if not synced, delete notes directly
+// if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
+// .getSelectedItemIds())) {
+// } else {
+// Log.e(TAG, "Delete notes error, should not happens");
+// }
+// } else {
+// // in sync mode, we'll move the deleted note into the trash
+// // folder
+// if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
+// .getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
+// Log.e(TAG, "Move notes to trash folder error, should not happens");
+// }
+// }
+// return widgets;
+
+ mCurrentFolderId = mFocusNoteDataItem.getFolderId();
+
+ if (mCurrentFolderId == Notes.ID_TRASH_FOLER){
+ // if in trash, delete notes directly
if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
.getSelectedItemIds())) {
} else {
Log.e(TAG, "Delete notes error, should not happens");
}
- } else {
- // in sync mode, we'll move the deleted note into the trash
- // folder
+ }
+ else{
+ //move to trash
if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
.getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
Log.e(TAG, "Move notes to trash folder error, should not happens");
@@ -814,12 +834,30 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
case R.id.menu_search:
onSearchRequested();
break;
+ case R.id.RecycleBin:
+ recycleBin();
+ // TODO: 2023/5/25 add a page for the recyclebin
+ break;
default:
break;
}
return true;
}
+// private void recycleBin(){
+// mState = ListEditState.SUB_FOLDER;
+// mCurrentFolderId = Notes.ID_TRASH_FOLER;
+// startAsyncNotesListQuery();
+// mTitleBar.setText("trash folder");
+// mTitleBar.setVisibility(View.VISIBLE);
+// }
+
+ private void recycleBin() {
+ Intent intent=new Intent(NotesListActivity.this,RecycleBinActivity.class);
+ startActivity(intent);
+ finish();
+ }
+
@Override
public boolean onSearchRequested() {
startSearch(null, false, null /* appData */, false);
diff --git a/src/app/src/main/java/net/micode/notes/ui/RecycleBinActivity.java b/src/app/src/main/java/net/micode/notes/ui/RecycleBinActivity.java
new file mode 100644
index 0000000..dbb127d
--- /dev/null
+++ b/src/app/src/main/java/net/micode/notes/ui/RecycleBinActivity.java
@@ -0,0 +1,753 @@
+package net.micode.notes.ui;
+
+import android.app.Activity;
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.appwidget.AppWidgetManager;
+import android.content.AsyncQueryHandler;
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.database.Cursor;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.text.Editable;
+import android.text.TextUtils;
+import android.text.TextWatcher;
+import android.util.Log;
+import android.view.ActionMode;
+import android.view.ContextMenu;
+import android.view.ContextMenu.ContextMenuInfo;
+import android.view.Display;
+import android.view.HapticFeedbackConstants;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.MenuItem.OnMenuItemClickListener;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.View.OnCreateContextMenuListener;
+import android.view.View.OnTouchListener;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView.OnItemLongClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ListView;
+import android.widget.PopupMenu;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import net.micode.notes.R;
+import net.micode.notes.data.Notes;
+import net.micode.notes.data.Notes.NoteColumns;
+import net.micode.notes.gtask.remote.GTaskSyncService;
+import net.micode.notes.model.WorkingNote;
+import net.micode.notes.tool.BackupUtils;
+import net.micode.notes.tool.DataUtils;
+import net.micode.notes.tool.ResourceParser;
+import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
+import net.micode.notes.widget.NoteWidgetProvider_2x;
+import net.micode.notes.widget.NoteWidgetProvider_4x;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashSet;
+
+public class RecycleBinActivity 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;
+
+ private ListView mNotesListView;
+
+ private Button mAddNewNote;
+
+ private boolean mDispatch;
+
+ private int mOriginY;
+
+ private int mDispatchY;
+
+ private TextView mTitleBar;
+
+ private long mCurrentFolderId;
+
+ private ContentResolver mContentResolver;
+
+ private ModeCallback mModeCallBack;
+
+ private static final String TAG = "RecycleActivity";
+
+ 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;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.recycle_bin);
+ initResources();
+
+ /**
+ * Insert an introduction when user firstly use this application
+ */
+ setAppInfoFromRawRes();
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (resultCode == RESULT_OK
+ && (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
+ mNotesListAdapter.changeCursor(null);
+ } else {
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+ }
+
+ private void setAppInfoFromRawRes() {
+ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
+ if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
+ StringBuilder sb = new StringBuilder();
+ InputStream in = null;
+ try {
+ in = getResources().openRawResource(R.raw.introduction);
+ if (in != null) {
+ InputStreamReader isr = new InputStreamReader(in);
+ BufferedReader br = new BufferedReader(isr);
+ char [] buf = new char[1024];
+ int len = 0;
+ while ((len = br.read(buf)) > 0) {
+ sb.append(buf, 0, len);
+ }
+ } else {
+ Log.e(TAG, "Read introduction file error");
+ return;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ return;
+ } finally {
+ if(in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
+ AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
+ ResourceParser.RED);
+ note.setWorkingText(sb.toString());
+ if (note.saveNote()) {
+ sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
+ } else {
+ Log.e(TAG, "Save introduction note error");
+ return;
+ }
+ }
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ startAsyncNotesListQuery();
+ }
+
+ private void initResources() {
+ mContentResolver = this.getContentResolver();
+ mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
+ mCurrentFolderId = Notes.ID_TRASH_FOLER;
+ mNotesListView = (ListView) findViewById(R.id.notes_list);
+ mNotesListView.addFooterView(LayoutInflater.from(this).inflate(R.layout.note_list_footer, null),
+ null, false);
+ mNotesListView.setOnItemClickListener(new OnListItemClickListener());
+ mNotesListView.setOnItemLongClickListener(this);
+ mNotesListAdapter = new NotesListAdapter(this);
+ mNotesListView.setAdapter(mNotesListAdapter);
+// mAddNewNote = (Button) findViewById(R.id.btn_new_note);
+// mAddNewNote.setOnClickListener(this);
+// mAddNewNote.setOnTouchListener(new NewNoteOnTouchListener());
+ mDispatch = false;
+ mDispatchY = 0;
+ mOriginY = 0;
+ mTitleBar = (TextView) findViewById(R.id.tv_title_bar);
+ mState = ListEditState.NOTE_LIST;
+ mModeCallBack = new ModeCallback();
+ }
+
+ private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
+ private DropdownMenu mDropDownMenu;
+ private ActionMode mActionMode;
+ private MenuItem mMoveMenu;
+
+ public boolean onCreateActionMode(ActionMode mode, Menu menu) {
+ getMenuInflater().inflate(R.menu.note_list_options, menu);
+ menu.findItem(R.id.delete).setOnMenuItemClickListener(this);
+ mMoveMenu = menu.findItem(R.id.move);
+ if (mFocusNoteDataItem.getParentId() == Notes.ID_CALL_RECORD_FOLDER
+ || DataUtils.getUserFolderCount(mContentResolver) == 0) {
+ mMoveMenu.setVisible(false);
+ } else {
+ mMoveMenu.setVisible(true);
+ mMoveMenu.setOnMenuItemClickListener(this);
+ }
+ mActionMode = mode;
+ mNotesListAdapter.setChoiceMode(true);
+ mNotesListView.setLongClickable(false);
+// mAddNewNote.setVisibility(View.GONE);
+
+ View customView = LayoutInflater.from(RecycleBinActivity.this).inflate(
+ R.layout.note_list_dropdown_menu, null);
+ mode.setCustomView(customView);
+ mDropDownMenu = new DropdownMenu(RecycleBinActivity.this,
+ (Button) customView.findViewById(R.id.selection_menu),
+ R.menu.note_list_dropdown);
+ mDropDownMenu.setOnDropdownMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
+ public boolean onMenuItemClick(MenuItem item) {
+ mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected());
+ updateMenu();
+ return true;
+ }
+
+ });
+ return true;
+ }
+
+ private void updateMenu() {
+ int selectedCount = mNotesListAdapter.getSelectedCount();
+ // Update dropdown menu
+ String format = getResources().getString(R.string.menu_select_title, selectedCount);
+ mDropDownMenu.setTitle(format);
+ MenuItem item = mDropDownMenu.findItem(R.id.action_select_all);
+ if (item != null) {
+ if (mNotesListAdapter.isAllSelected()) {
+ item.setChecked(true);
+ item.setTitle(R.string.menu_deselect_all);
+ } else {
+ item.setChecked(false);
+ item.setTitle(R.string.menu_select_all);
+ }
+ }
+ }
+
+ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void onDestroyActionMode(ActionMode mode) {
+ mNotesListAdapter.setChoiceMode(false);
+ mNotesListView.setLongClickable(true);
+// mAddNewNote.setVisibility(View.VISIBLE);
+ }
+
+ public void finishActionMode() {
+ mActionMode.finish();
+ }
+
+ public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
+ boolean checked) {
+ mNotesListAdapter.setCheckedItem(position, checked);
+ updateMenu();
+ }
+
+ public boolean onMenuItemClick(MenuItem item) {
+ if (mNotesListAdapter.getSelectedCount() == 0) {
+ Toast.makeText(RecycleBinActivity.this, getString(R.string.menu_select_none),
+ Toast.LENGTH_SHORT).show();
+ return true;
+ }
+
+ switch (item.getItemId()) {
+ case R.id.delete:
+ AlertDialog.Builder builder = new AlertDialog.Builder(RecycleBinActivity.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()));
+ builder.setPositiveButton(android.R.string.ok,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog,
+ int which) {
+ batchDelete();
+ }
+ });
+ builder.setNegativeButton(android.R.string.cancel, null);
+ builder.show();
+ break;
+ case R.id.move:
+// startQueryDestinationFolders();
+ break;
+ default:
+ 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();
+ int start = screenHeight - newNoteViewHeight;
+ int eventY = start + (int) event.getY();
+ /**
+ * Minus TitleBar's height
+ */
+ if (mState == ListEditState.SUB_FOLDER) {
+ eventY -= mTitleBar.getHeight();
+ start -= mTitleBar.getHeight();
+ }
+ /**
+ * HACKME:When click the transparent part of "New Note" button, dispatch
+ * the event to the list view behind this button. The transparent part of
+ * "New Note" button could be expressed by formula y=-0.12x+94(Unit:pixel)
+ * and the line top of the button. The coordinate based on left of the "New
+ * Note" button. The 94 represents maximum height of the transparent part.
+ * Notice that, if the background of the button changes, the formula should
+ * also change. This is very bad, just for the UI designer's strong requirement.
+ */
+ if (event.getY() < (event.getX() * (-0.12) + 94)) {
+ View view = mNotesListView.getChildAt(mNotesListView.getChildCount() - 1
+ - mNotesListView.getFooterViewsCount());
+ if (view != null && view.getBottom() > start
+ && (view.getTop() < (start + 94))) {
+ mOriginY = (int) event.getY();
+ mDispatchY = eventY;
+ event.setLocation(event.getX(), mDispatchY);
+ mDispatch = true;
+ return mNotesListView.dispatchTouchEvent(event);
+ }
+ }
+ break;
+ }
+ case MotionEvent.ACTION_MOVE: {
+ if (mDispatch) {
+ mDispatchY += (int) event.getY() - mOriginY;
+ event.setLocation(event.getX(), mDispatchY);
+ return mNotesListView.dispatchTouchEvent(event);
+ }
+ break;
+ }
+ default: {
+ if (mDispatch) {
+ event.setLocation(event.getX(), mDispatchY);
+ mDispatch = false;
+ return mNotesListView.dispatchTouchEvent(event);
+ }
+ break;
+ }
+ }
+ return false;
+ }
+
+ };
+
+ private void startAsyncNotesListQuery() {
+ String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
+ : NORMAL_SELECTION;
+ mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
+ Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {
+ String.valueOf(mCurrentFolderId)
+ }, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
+ }
+
+ private final class BackgroundQueryHandler extends AsyncQueryHandler {
+ public BackgroundQueryHandler(ContentResolver contentResolver) {
+ super(contentResolver);
+ }
+
+ @Override
+ protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
+ 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;
+ default:
+ return;
+ }
+ }
+ }
+
+ private void showFolderListMenu(Cursor cursor) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(RecycleBinActivity.this);
+ builder.setTitle(R.string.menu_title_select_folder);
+ final FoldersListAdapter adapter = new FoldersListAdapter(this, cursor);
+ builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
+
+ public void onClick(DialogInterface dialog, int which) {
+ DataUtils.batchMoveToFolder(mContentResolver,
+ mNotesListAdapter.getSelectedItemIds(), adapter.getItemId(which));
+ Toast.makeText(
+ RecycleBinActivity.this,
+ getString(R.string.format_move_notes_to_folder,
+ mNotesListAdapter.getSelectedCount(),
+ adapter.getFolderName(RecycleBinActivity.this, which)),
+ Toast.LENGTH_SHORT).show();
+ 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);
+ }
+
+ private void batchDelete() {
+
+ if (mCurrentFolderId == Notes.ID_TRASH_FOLER){
+ // if in trash, delete notes directly
+ if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
+ .getSelectedItemIds())) {
+ } else {
+ Log.e(TAG, "Delete notes error, should not happens");
+ }
+ }
+ else{
+ //move to trash
+ if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
+ .getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
+ Log.e(TAG, "Move notes to trash folder error, should not happens");
+ }
+ }
+ }
+
+ private void deleteFolder(long folderId) {
+ if (folderId == Notes.ID_ROOT_FOLDER) {
+ Log.e(TAG, "Wrong folder id, should not happen " + folderId);
+ return;
+ }
+
+ HashSet ids = new HashSet();
+ ids.add(folderId);
+ HashSet widgets = DataUtils.getFolderNoteWidget(mContentResolver,
+ folderId);
+ if (true) {
+ // 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) {
+ for (AppWidgetAttribute widget : widgets) {
+ if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
+ && widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) {
+ updateWidget(widget.widgetId, widget.widgetType);
+ }
+ }
+ }
+ }
+
+ private void openNode(NoteItemData data) {
+ Intent intent = new Intent(this, NoteEditActivity.class);
+ intent.setAction(Intent.ACTION_VIEW);
+ intent.putExtra(Intent.EXTRA_UID, data.getId());
+ this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
+ }
+
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.btn_new_note:
+ createNewNote();
+ break;
+ default:
+ break;
+ }
+ }
+
+ 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);
+ }
+
+ @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;
+// mAddNewNote.setVisibility(View.VISIBLE);
+ mTitleBar.setVisibility(View.GONE);
+ startAsyncNotesListQuery();
+ break;
+ case NOTE_LIST:
+ super.onBackPressed();
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void updateWidget(int appWidgetId, int appWidgetType) {
+ Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
+ if (appWidgetType == Notes.TYPE_WIDGET_2X) {
+ intent.setClass(this, NoteWidgetProvider_2x.class);
+ } else if (appWidgetType == Notes.TYPE_WIDGET_4X) {
+ intent.setClass(this, NoteWidgetProvider_4x.class);
+ } else {
+ Log.e(TAG, "Unspported widget type");
+ return;
+ }
+
+ intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
+ appWidgetId
+ });
+
+ 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);
+ }
+ }
+ };
+
+ @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;
+ }
+ 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() {
+ public void onClick(DialogInterface dialog, int which) {
+ deleteFolder(mFocusNoteDataItem.getId());
+ }
+ });
+ builder.setNegativeButton(android.R.string.cancel, null);
+ builder.show();
+ break;
+ case MENU_FOLDER_CHANGE_NAME:
+// showCreateOrModifyFolderDialog(false);
+ break;
+ default:
+ break;
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ 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) {
+ getMenuInflater().inflate(R.menu.sub_folder, menu);
+ } else if (mState == ListEditState.CALL_RECORD_FOLDER) {
+ getMenuInflater().inflate(R.menu.call_record_folder, menu);
+ } else {
+ Log.e(TAG, "Wrong state:" + mState);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.menu_new_folder: {
+// showCreateOrModifyFolderDialog(true);
+ break;
+ }
+ case R.id.menu_export_text: {
+// exportNoteToText();
+ break;
+ }
+ case R.id.menu_setting: {
+ startPreferenceActivity();
+ break;
+ }
+ case R.id.menu_new_note: {
+ createNewNote();
+ break;
+ }
+ case R.id.menu_search:
+ onSearchRequested();
+ break;
+// case R.id.RecycleBin:
+// recycleBin();
+// break;
+ default:
+ break;
+ }
+ return true;
+ }
+
+// private void recycleBin() {
+// Intent intent=new Intent(RecycleBinActivity.this,RecycleBinActivity.class);
+// startActivity(intent);
+// finish();
+// }
+
+ @Override
+ public boolean onSearchRequested() {
+ startSearch(null, false, null /* appData */, false);
+ return true;
+ }
+
+ private void startPreferenceActivity() {
+ Activity from = getParent() != null ? getParent() : this;
+ Intent intent = new Intent(from, NotesPreferenceActivity.class);
+ from.startActivityIfNeeded(intent, -1);
+ }
+
+ private class OnListItemClickListener implements OnItemClickListener {
+
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ if (view instanceof NotesListItem) {
+ NoteItemData item = ((NotesListItem) view).getItemData();
+ if (mNotesListAdapter.isInChoiceMode()) {
+ if (item.getType() == Notes.TYPE_NOTE) {
+ position = position - mNotesListView.getHeaderViewsCount();
+ mModeCallBack.onItemCheckedStateChanged(null, position, id,
+ !mNotesListAdapter.isSelectedItem(position));
+ }
+ return;
+ }
+
+ switch (mState) {
+ case NOTE_LIST:
+ if (item.getType() == Notes.TYPE_FOLDER
+ || item.getType() == Notes.TYPE_SYSTEM) {
+// openFolder(item);
+ } else if (item.getType() == Notes.TYPE_NOTE) {
+ openNode(item);
+ } else {
+ Log.e(TAG, "Wrong note type in NOTE_LIST");
+ }
+ break;
+ case SUB_FOLDER:
+ case CALL_RECORD_FOLDER:
+ if (item.getType() == Notes.TYPE_NOTE) {
+ openNode(item);
+ } else {
+ Log.e(TAG, "Wrong note type in SUB_FOLDER");
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ }
+
+ public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
+ if (view instanceof NotesListItem) {
+ mFocusNoteDataItem = ((NotesListItem) view).getItemData();
+ if (mFocusNoteDataItem.getType() == Notes.TYPE_NOTE && !mNotesListAdapter.isInChoiceMode()) {
+ if (mNotesListView.startActionMode(mModeCallBack) != null) {
+ mModeCallBack.onItemCheckedStateChanged(null, position, id, true);
+ mNotesListView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
+ } else {
+ Log.e(TAG, "startActionMode fails");
+ }
+ } else if (mFocusNoteDataItem.getType() == Notes.TYPE_FOLDER) {
+ mNotesListView.setOnCreateContextMenuListener(mFolderOnCreateContextMenuListener);
+ }
+ }
+ return false;
+ }
+}
diff --git a/src/app/src/main/res/layout/recycle_bin.xml b/src/app/src/main/res/layout/recycle_bin.xml
new file mode 100644
index 0000000..3d60df5
--- /dev/null
+++ b/src/app/src/main/res/layout/recycle_bin.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/app/src/main/res/menu/note_list.xml b/src/app/src/main/res/menu/note_list.xml
index 42ea736..3bc14f2 100644
--- a/src/app/src/main/res/menu/note_list.xml
+++ b/src/app/src/main/res/menu/note_list.xml
@@ -36,4 +36,8 @@
+
+
diff --git a/src/app/src/main/res/values/styles.xml b/src/app/src/main/res/values/styles.xml
index d750e65..ad0d90d 100644
--- a/src/app/src/main/res/values/styles.xml
+++ b/src/app/src/main/res/values/styles.xml
@@ -64,6 +64,6 @@
\ No newline at end of file
--
2.34.1
From 34dac7cef71357473e03afdbfa87692d3ab3c8a3 Mon Sep 17 00:00:00 2001
From: Mars_RH <1658408137@qq.com>
Date: Fri, 26 May 2023 21:20:41 +0800
Subject: [PATCH 2/3] =?UTF-8?q?=E5=9B=9E=E6=94=B6=E7=AB=99=E9=9B=8F?=
=?UTF-8?q?=E5=BD=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/.idea/deploymentTargetDropDown.xml | 2 +-
.../micode/notes/ui/NotesListActivity.java | 14 +-
.../micode/notes/ui/RecycleBinActivity.java | 846 ++++++++++--------
src/app/src/main/res/layout/note_list.xml | 4 +-
src/app/src/main/res/layout/recycle_bin.xml | 19 +-
.../src/main/res/menu/recyclebin_options.xml | 21 +
src/app/src/main/res/values/strings.xml | 2 +
7 files changed, 494 insertions(+), 414 deletions(-)
create mode 100644 src/app/src/main/res/menu/recyclebin_options.xml
diff --git a/src/.idea/deploymentTargetDropDown.xml b/src/.idea/deploymentTargetDropDown.xml
index a35bc82..efbebf5 100644
--- a/src/.idea/deploymentTargetDropDown.xml
+++ b/src/.idea/deploymentTargetDropDown.xml
@@ -12,6 +12,6 @@
-
+
\ No newline at end of file
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 1026792..21e9e1e 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
@@ -495,21 +495,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mCurrentFolderId = mFocusNoteDataItem.getFolderId();
- if (mCurrentFolderId == Notes.ID_TRASH_FOLER){
- // if in trash, delete notes directly
- if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
- .getSelectedItemIds())) {
- } else {
- Log.e(TAG, "Delete notes error, should not happens");
- }
- }
- else{
+
//move to trash
if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
.getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
Log.e(TAG, "Move notes to trash folder error, should not happens");
}
- }
return widgets;
}
@@ -836,7 +827,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
break;
case R.id.RecycleBin:
recycleBin();
- // TODO: 2023/5/25 add a page for the recyclebin
break;
default:
break;
@@ -855,6 +845,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private void recycleBin() {
Intent intent=new Intent(NotesListActivity.this,RecycleBinActivity.class);
startActivity(intent);
+ mTitleBar.setText("trash folder");
+ mTitleBar.setVisibility(View.VISIBLE);
finish();
}
diff --git a/src/app/src/main/java/net/micode/notes/ui/RecycleBinActivity.java b/src/app/src/main/java/net/micode/notes/ui/RecycleBinActivity.java
index dbb127d..d60060b 100644
--- a/src/app/src/main/java/net/micode/notes/ui/RecycleBinActivity.java
+++ b/src/app/src/main/java/net/micode/notes/ui/RecycleBinActivity.java
@@ -28,6 +28,7 @@ import android.view.Display;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.Menu;
+import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.MotionEvent;
@@ -103,7 +104,7 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
private ContentResolver mContentResolver;
- private ModeCallback mModeCallBack;
+// private ModeCallback mModeCallBack;
private static final String TAG = "RecycleActivity";
@@ -111,6 +112,8 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
private NoteItemData mFocusNoteDataItem;
+ private MenuItem menuItem;
+
private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";
private static final String ROOT_FOLDER_SELECTION = "(" + NoteColumns.TYPE + "<>"
@@ -130,7 +133,7 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
/**
* Insert an introduction when user firstly use this application
*/
- setAppInfoFromRawRes();
+// setAppInfoFromRawRes();
}
@Override
@@ -143,51 +146,50 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
}
}
- private void setAppInfoFromRawRes() {
- SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
- if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
- StringBuilder sb = new StringBuilder();
- InputStream in = null;
- try {
- in = getResources().openRawResource(R.raw.introduction);
- if (in != null) {
- InputStreamReader isr = new InputStreamReader(in);
- BufferedReader br = new BufferedReader(isr);
- char [] buf = new char[1024];
- int len = 0;
- while ((len = br.read(buf)) > 0) {
- sb.append(buf, 0, len);
- }
- } else {
- Log.e(TAG, "Read introduction file error");
- return;
- }
- } catch (IOException e) {
- e.printStackTrace();
- return;
- } finally {
- if(in != null) {
- try {
- in.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
-
- WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
- AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
- ResourceParser.RED);
- note.setWorkingText(sb.toString());
- if (note.saveNote()) {
- sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
- } else {
- Log.e(TAG, "Save introduction note error");
- return;
- }
- }
- }
+// private void setAppInfoFromRawRes() {
+// SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
+// if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
+// StringBuilder sb = new StringBuilder();
+// InputStream in = null;
+// try {
+// in = getResources().openRawResource(R.raw.introduction);
+// if (in != null) {
+// InputStreamReader isr = new InputStreamReader(in);
+// BufferedReader br = new BufferedReader(isr);
+// char [] buf = new char[1024];
+// int len = 0;
+// while ((len = br.read(buf)) > 0) {
+// sb.append(buf, 0, len);
+// }
+// } else {
+// Log.e(TAG, "Read introduction file error");
+// return;
+// }
+// } catch (IOException e) {
+// e.printStackTrace();
+// return;
+// } finally {
+// if(in != null) {
+// try {
+// in.close();
+// } catch (IOException e) {
+// e.printStackTrace();
+// }
+// }
+// }
+//
+// WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
+// AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
+// ResourceParser.RED);
+// note.setWorkingText(sb.toString());
+// if (note.saveNote()) {
+// sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
+// } else {
+// Log.e(TAG, "Save introduction note error");
+// return;
+// }
+// }
+// }
@Override
protected void onStart() {
@@ -199,12 +201,13 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
mContentResolver = this.getContentResolver();
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
mCurrentFolderId = Notes.ID_TRASH_FOLER;
- mNotesListView = (ListView) findViewById(R.id.notes_list);
+ mNotesListView = (ListView) findViewById(R.id.recycle_list);
mNotesListView.addFooterView(LayoutInflater.from(this).inflate(R.layout.note_list_footer, null),
null, false);
mNotesListView.setOnItemClickListener(new OnListItemClickListener());
- mNotesListView.setOnItemLongClickListener(this);
+// mNotesListView.setOnItemLongClickListener(this);
mNotesListAdapter = new NotesListAdapter(this);
+ mNotesListAdapter.setChoiceMode(true);
mNotesListView.setAdapter(mNotesListAdapter);
// mAddNewNote = (Button) findViewById(R.id.btn_new_note);
// mAddNewNote.setOnClickListener(this);
@@ -214,185 +217,189 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
mOriginY = 0;
mTitleBar = (TextView) findViewById(R.id.tv_title_bar);
mState = ListEditState.NOTE_LIST;
- mModeCallBack = new ModeCallback();
+// mModeCallBack = new ModeCallback();
+// mNotesListView.startActionMode(mModeCallBack);
}
- private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
- private DropdownMenu mDropDownMenu;
- private ActionMode mActionMode;
- private MenuItem mMoveMenu;
-
- public boolean onCreateActionMode(ActionMode mode, Menu menu) {
- getMenuInflater().inflate(R.menu.note_list_options, menu);
- menu.findItem(R.id.delete).setOnMenuItemClickListener(this);
- mMoveMenu = menu.findItem(R.id.move);
- if (mFocusNoteDataItem.getParentId() == Notes.ID_CALL_RECORD_FOLDER
- || DataUtils.getUserFolderCount(mContentResolver) == 0) {
- mMoveMenu.setVisible(false);
- } else {
- mMoveMenu.setVisible(true);
- mMoveMenu.setOnMenuItemClickListener(this);
- }
- mActionMode = mode;
- mNotesListAdapter.setChoiceMode(true);
- mNotesListView.setLongClickable(false);
-// mAddNewNote.setVisibility(View.GONE);
-
- View customView = LayoutInflater.from(RecycleBinActivity.this).inflate(
- R.layout.note_list_dropdown_menu, null);
- mode.setCustomView(customView);
- mDropDownMenu = new DropdownMenu(RecycleBinActivity.this,
- (Button) customView.findViewById(R.id.selection_menu),
- R.menu.note_list_dropdown);
- mDropDownMenu.setOnDropdownMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
- public boolean onMenuItemClick(MenuItem item) {
- mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected());
- updateMenu();
- return true;
- }
-
- });
- return true;
- }
-
- private void updateMenu() {
- int selectedCount = mNotesListAdapter.getSelectedCount();
- // Update dropdown menu
- String format = getResources().getString(R.string.menu_select_title, selectedCount);
- mDropDownMenu.setTitle(format);
- MenuItem item = mDropDownMenu.findItem(R.id.action_select_all);
- if (item != null) {
- if (mNotesListAdapter.isAllSelected()) {
- item.setChecked(true);
- item.setTitle(R.string.menu_deselect_all);
- } else {
- item.setChecked(false);
- item.setTitle(R.string.menu_select_all);
- }
- }
- }
-
- public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void onDestroyActionMode(ActionMode mode) {
- mNotesListAdapter.setChoiceMode(false);
- mNotesListView.setLongClickable(true);
-// mAddNewNote.setVisibility(View.VISIBLE);
- }
-
- public void finishActionMode() {
- mActionMode.finish();
- }
-
- public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
- boolean checked) {
- mNotesListAdapter.setCheckedItem(position, checked);
- updateMenu();
- }
-
- public boolean onMenuItemClick(MenuItem item) {
- if (mNotesListAdapter.getSelectedCount() == 0) {
- Toast.makeText(RecycleBinActivity.this, getString(R.string.menu_select_none),
- Toast.LENGTH_SHORT).show();
- return true;
- }
-
- switch (item.getItemId()) {
- case R.id.delete:
- AlertDialog.Builder builder = new AlertDialog.Builder(RecycleBinActivity.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()));
- builder.setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog,
- int which) {
- batchDelete();
- }
- });
- builder.setNegativeButton(android.R.string.cancel, null);
- builder.show();
- break;
- case R.id.move:
-// startQueryDestinationFolders();
- break;
- default:
- return false;
- }
- return true;
- }
+ /**
+ * 重置选择器状态
+ */
+ private void reset_ChoiseMode(){
+ mNotesListAdapter.setChoiceMode(false);
+ mNotesListAdapter.setChoiceMode(true);
}
+ // TODO: 2023/5/26 重写这一块
+// private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
+// private DropdownMenu mDropDownMenu;
+// private ActionMode mActionMode;
+// private MenuItem mMoveMenu;
+//
+// public boolean onCreateActionMode(ActionMode mode, Menu menu) {
+// getMenuInflater().inflate(R.menu.note_list_options, menu);
+// menu.findItem(R.id.delete).setOnMenuItemClickListener(this);
+// mMoveMenu = menu.findItem(R.id.move);
+//
+// mMoveMenu.setVisible(true);
+// mMoveMenu.setOnMenuItemClickListener(this);
+//
+// mActionMode = mode;
+// mNotesListAdapter.setChoiceMode(true);
+// mNotesListView.setLongClickable(false);
+//// mAddNewNote.setVisibility(View.GONE);
+//
+// View customView = LayoutInflater.from(RecycleBinActivity.this).inflate(
+// R.layout.note_list_dropdown_menu, null);
+// mode.setCustomView(customView);
+// mDropDownMenu = new DropdownMenu(RecycleBinActivity.this,
+// (Button) customView.findViewById(R.id.selection_menu),
+// R.menu.note_list_dropdown);
+// mDropDownMenu.setOnDropdownMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
+// public boolean onMenuItemClick(MenuItem item) {
+// mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected());
+// updateMenu();
+// return true;
+// }
+//
+// });
+// return true;
+// }
+//
+// private void updateMenu() {
+// int selectedCount = mNotesListAdapter.getSelectedCount();
+// // Update dropdown menu
+// String format = getResources().getString(R.string.menu_select_title, selectedCount);
+// mDropDownMenu.setTitle(format);
+// MenuItem item = mDropDownMenu.findItem(R.id.action_select_all);
+// if (item != null) {
+// if (mNotesListAdapter.isAllSelected()) {
+// item.setChecked(true);
+// item.setTitle(R.string.menu_deselect_all);
+// } else {
+// item.setChecked(false);
+// item.setTitle(R.string.menu_select_all);
+// }
+// }
+// }
+//
+// public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
+// return false;
+// }
+//
+// public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
+// return false;
+// }
+//
+// public void onDestroyActionMode(ActionMode mode) {
+//// mNotesListAdapter.setChoiceMode(false);
+//// mNotesListView.setLongClickable(true);
+//// mAddNewNote.setVisibility(View.VISIBLE);
+// }
+//
+// public void finishActionMode() {
+// mActionMode.finish();
+// }
+//
+// public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
+// boolean checked) {
+// mNotesListAdapter.setCheckedItem(position, checked);
+// updateMenu();
+// }
+//
+// public boolean onMenuItemClick(MenuItem item) {
+// if (mNotesListAdapter.getSelectedCount() == 0) {
+// Toast.makeText(RecycleBinActivity.this, getString(R.string.menu_select_none),
+// Toast.LENGTH_SHORT).show();
+// return true;
+// }
+//
+// switch (item.getItemId()) {
+// case R.id.delete:
+// AlertDialog.Builder builder = new AlertDialog.Builder(RecycleBinActivity.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()));
+// builder.setPositiveButton(android.R.string.ok,
+// new DialogInterface.OnClickListener() {
+// public void onClick(DialogInterface dialog,
+// int which) {
+// batchDelete();
+// }
+// });
+// builder.setNegativeButton(android.R.string.cancel, null);
+// builder.show();
+// break;
+// case R.id.move:
+//// startQueryDestinationFolders();
+// break;
+// default:
+// 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();
- int start = screenHeight - newNoteViewHeight;
- int eventY = start + (int) event.getY();
- /**
- * Minus TitleBar's height
- */
- if (mState == ListEditState.SUB_FOLDER) {
- eventY -= mTitleBar.getHeight();
- start -= mTitleBar.getHeight();
- }
- /**
- * HACKME:When click the transparent part of "New Note" button, dispatch
- * the event to the list view behind this button. The transparent part of
- * "New Note" button could be expressed by formula y=-0.12x+94(Unit:pixel)
- * and the line top of the button. The coordinate based on left of the "New
- * Note" button. The 94 represents maximum height of the transparent part.
- * Notice that, if the background of the button changes, the formula should
- * also change. This is very bad, just for the UI designer's strong requirement.
- */
- if (event.getY() < (event.getX() * (-0.12) + 94)) {
- View view = mNotesListView.getChildAt(mNotesListView.getChildCount() - 1
- - mNotesListView.getFooterViewsCount());
- if (view != null && view.getBottom() > start
- && (view.getTop() < (start + 94))) {
- mOriginY = (int) event.getY();
- mDispatchY = eventY;
- event.setLocation(event.getX(), mDispatchY);
- mDispatch = true;
- return mNotesListView.dispatchTouchEvent(event);
- }
- }
- break;
- }
- case MotionEvent.ACTION_MOVE: {
- if (mDispatch) {
- mDispatchY += (int) event.getY() - mOriginY;
- event.setLocation(event.getX(), mDispatchY);
- return mNotesListView.dispatchTouchEvent(event);
- }
- break;
- }
- default: {
- if (mDispatch) {
- event.setLocation(event.getX(), mDispatchY);
- mDispatch = false;
- return mNotesListView.dispatchTouchEvent(event);
- }
- break;
- }
- }
- return false;
- }
-
- };
+// 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();
+// int start = screenHeight - newNoteViewHeight;
+// int eventY = start + (int) event.getY();
+// /**
+// * Minus TitleBar's height
+// */
+// if (mState == ListEditState.SUB_FOLDER) {
+// eventY -= mTitleBar.getHeight();
+// start -= mTitleBar.getHeight();
+// }
+// /**
+// * HACKME:When click the transparent part of "New Note" button, dispatch
+// * the event to the list view behind this button. The transparent part of
+// * "New Note" button could be expressed by formula y=-0.12x+94(Unit:pixel)
+// * and the line top of the button. The coordinate based on left of the "New
+// * Note" button. The 94 represents maximum height of the transparent part.
+// * Notice that, if the background of the button changes, the formula should
+// * also change. This is very bad, just for the UI designer's strong requirement.
+// */
+// if (event.getY() < (event.getX() * (-0.12) + 94)) {
+// View view = mNotesListView.getChildAt(mNotesListView.getChildCount() - 1
+// - mNotesListView.getFooterViewsCount());
+// if (view != null && view.getBottom() > start
+// && (view.getTop() < (start + 94))) {
+// mOriginY = (int) event.getY();
+// mDispatchY = eventY;
+// event.setLocation(event.getX(), mDispatchY);
+// mDispatch = true;
+// return mNotesListView.dispatchTouchEvent(event);
+// }
+// }
+// break;
+// }
+// case MotionEvent.ACTION_MOVE: {
+// if (mDispatch) {
+// mDispatchY += (int) event.getY() - mOriginY;
+// event.setLocation(event.getX(), mDispatchY);
+// return mNotesListView.dispatchTouchEvent(event);
+// }
+// break;
+// }
+// default: {
+// if (mDispatch) {
+// event.setLocation(event.getX(), mDispatchY);
+// mDispatch = false;
+// return mNotesListView.dispatchTouchEvent(event);
+// }
+// break;
+// }
+// }
+// return false;
+// }
+//
+// };
private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
@@ -442,35 +449,24 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
mNotesListAdapter.getSelectedCount(),
adapter.getFolderName(RecycleBinActivity.this, which)),
Toast.LENGTH_SHORT).show();
- mModeCallBack.finishActionMode();
+// 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);
- }
+// 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);
+// }
private void batchDelete() {
-
- if (mCurrentFolderId == Notes.ID_TRASH_FOLER){
- // if in trash, delete notes directly
- if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
- .getSelectedItemIds())) {
- } else {
- Log.e(TAG, "Delete notes error, should not happens");
- }
- }
- else{
- //move to trash
- if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
- .getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
- Log.e(TAG, "Move notes to trash folder error, should not happens");
- }
+ // delete notes directly
+ if (!DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
+ .getSelectedItemIds())) {
+ Log.e(TAG, "Delete notes error, should not happens");
}
}
@@ -484,7 +480,7 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
ids.add(folderId);
HashSet widgets = DataUtils.getFolderNoteWidget(mContentResolver,
folderId);
- if (true) {
+ if (false) {
// if not synced, delete folder directly
DataUtils.batchDeleteNotes(mContentResolver, ids);
} else {
@@ -501,57 +497,60 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
}
}
- private void openNode(NoteItemData data) {
- Intent intent = new Intent(this, NoteEditActivity.class);
- intent.setAction(Intent.ACTION_VIEW);
- intent.putExtra(Intent.EXTRA_UID, data.getId());
- this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
- }
+// private void openNode(NoteItemData data) {
+// Intent intent = new Intent(this, NoteEditActivity.class);
+// intent.setAction(Intent.ACTION_VIEW);
+// intent.putExtra(Intent.EXTRA_UID, data.getId());
+// this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
+// }
public void onClick(View v) {
- switch (v.getId()) {
- case R.id.btn_new_note:
- createNewNote();
- break;
- default:
- break;
- }
+// switch (v.getId()) {
+// case R.id.btn_new_note:
+// createNewNote();
+// break;
+// default:
+// break;
+// }
}
- private void showSoftInput() {
- InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- if (inputMethodManager != null) {
- inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
- }
- }
+// 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);
- }
+// private void hideSoftInput(View view) {
+// InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+// inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
+// }
@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;
-// mAddNewNote.setVisibility(View.VISIBLE);
- mTitleBar.setVisibility(View.GONE);
- startAsyncNotesListQuery();
- break;
- case NOTE_LIST:
- super.onBackPressed();
- break;
- default:
- break;
- }
+// 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;
+//// mAddNewNote.setVisibility(View.VISIBLE);
+// mTitleBar.setVisibility(View.GONE);
+// startAsyncNotesListQuery();
+// break;
+// case NOTE_LIST:
+// super.onBackPressed();
+// break;
+// default:
+// break;
+// }
+ Intent intent=new Intent(RecycleBinActivity.this,NotesListActivity.class);
+ startActivity(intent);
+ finish();
}
private void updateWidget(int appWidgetId, int appWidgetType) {
@@ -573,22 +572,22 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
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);
- }
- }
- };
+// 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);
+// }
+// }
+// };
@Override
public void onContextMenuClosed(Menu menu) {
- if (mNotesListView != null) {
- mNotesListView.setOnCreateContextMenuListener(null);
- }
+// if (mNotesListView != null) {
+// mNotesListView.setOnCreateContextMenuListener(null);
+// }
super.onContextMenuClosed(menu);
}
@@ -626,52 +625,123 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
return true;
}
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.recyclebin_options,menu);
+
+ menuItem = menu.findItem(R.id.select_all);
+
+ return super.onCreateOptionsMenu(menu);
+ }
+
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
+
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) {
- getMenuInflater().inflate(R.menu.sub_folder, menu);
- } else if (mState == ListEditState.CALL_RECORD_FOLDER) {
- getMenuInflater().inflate(R.menu.call_record_folder, menu);
- } else {
- Log.e(TAG, "Wrong state:" + mState);
- }
+ getMenuInflater().inflate(R.menu.recyclebin_options, menu);
+
+
+
+// View customView = LayoutInflater.from(RecycleBinActivity.this).inflate(
+// R.layout.note_list_dropdown_menu, null);
+// mode.setCustomView(customView);
+//
+// DropdownMenu mDropDownMenu = new DropdownMenu(RecycleBinActivity.this,
+// (Button) customView.findViewById(R.id.selection_menu),
+// R.menu.note_list_dropdown);
+// mDropDownMenu.setOnDropdownMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
+// public boolean onMenuItemClick(MenuItem item) {
+// mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected());
+// updateMenu();
+// return true;
+// }
+//
+// });
+// if (mState == ListEditState.NOTE_LIST) {
+// getMenuInflater().inflate(R.menu.recyclebin_options, 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) {
+// getMenuInflater().inflate(R.menu.sub_folder, menu);
+// } else if (mState == ListEditState.CALL_RECORD_FOLDER) {
+// getMenuInflater().inflate(R.menu.call_record_folder, menu);
+// } else {
+// Log.e(TAG, "Wrong state:" + mState);
+// }
return true;
}
+// private void startQueryDestinationFolders() {
+// String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?";
+// selection = (mState == RecycleBinActivity.ListEditState.NOTE_LIST) ? selection:
+// "(" + selection + ") OR (" + NoteColumns.ID + "=" + Notes.ID_ROOT_FOLDER + ")";
+//
+// mBackgroundQueryHandler.startQuery(FOLDER_LIST_QUERY_TOKEN,
+// null,
+// Notes.CONTENT_NOTE_URI,
+// FoldersListAdapter.PROJECTION,
+// selection,
+// new String[] {
+// String.valueOf(Notes.TYPE_FOLDER),
+// String.valueOf(Notes.ID_TRASH_FOLER),
+// String.valueOf(mCurrentFolderId)
+// },
+// NoteColumns.MODIFIED_DATE + " DESC");
+// }
+
+ /**
+ * 当顶部菜单项被选择时所执行的函数
+ */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.menu_new_folder: {
-// showCreateOrModifyFolderDialog(true);
- break;
- }
- case R.id.menu_export_text: {
-// exportNoteToText();
- break;
- }
- case R.id.menu_setting: {
- startPreferenceActivity();
- break;
+// switch (item.getItemId()) {
+// case R.id.menu_new_folder: {
+//// showCreateOrModifyFolderDialog(true);
+// break;
+// }
+// case R.id.menu_export_text: {
+//// exportNoteToText();
+// break;
+// }
+// case R.id.menu_setting: {
+//// startPreferenceActivity();
+// break;
+// }
+// case R.id.menu_new_note: {
+//// createNewNote();
+// break;
+// }
+// case R.id.menu_search:
+// onSearchRequested();
+// break;
+//// case R.id.RecycleBin:
+//// recycleBin();
+//// break;
+// default:
+// break;
+// }
+// TODO: 2023/5/26 为这两个选项加入弹窗
+ if (item.getItemId() == R.id.recover) {
+ if (!DataUtils.batchMoveToFolder(mContentResolver,
+ mNotesListAdapter.getSelectedItemIds(), Notes.ID_ROOT_FOLDER))
+ Log.e(TAG, "Recover error, should not happens");
+ }
+ else if (item.getItemId() == R.id.realdelete) {
+ batchDelete();
+ }
+ else if (item.getItemId() == R.id.select_all) {
+ if (!mNotesListAdapter.isAllSelected()){
+ item.setTitle("deselect_all");
+ mNotesListAdapter.selectAll(true);
}
- case R.id.menu_new_note: {
- createNewNote();
- break;
+ else {
+ item.setTitle("selected_all");
+ mNotesListAdapter.selectAll(false);
}
- case R.id.menu_search:
- onSearchRequested();
- break;
-// case R.id.RecycleBin:
-// recycleBin();
-// break;
- default:
- break;
+ return true;
}
+ reset_ChoiseMode();
return true;
}
@@ -687,67 +757,71 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
return true;
}
- private void startPreferenceActivity() {
- Activity from = getParent() != null ? getParent() : this;
- Intent intent = new Intent(from, NotesPreferenceActivity.class);
- from.startActivityIfNeeded(intent, -1);
- }
+// private void startPreferenceActivity() {
+// Activity from = getParent() != null ? getParent() : this;
+// Intent intent = new Intent(from, NotesPreferenceActivity.class);
+// from.startActivityIfNeeded(intent, -1);
+// }
private class OnListItemClickListener implements OnItemClickListener {
public void onItemClick(AdapterView> parent, View view, int position, long id) {
if (view instanceof NotesListItem) {
NoteItemData item = ((NotesListItem) view).getItemData();
- if (mNotesListAdapter.isInChoiceMode()) {
- if (item.getType() == Notes.TYPE_NOTE) {
- position = position - mNotesListView.getHeaderViewsCount();
- mModeCallBack.onItemCheckedStateChanged(null, position, id,
- !mNotesListAdapter.isSelectedItem(position));
- }
- return;
+ if (item.getType() == Notes.TYPE_NOTE) {
+ position = position - mNotesListView.getHeaderViewsCount();
+ mNotesListAdapter.setCheckedItem(position, !mNotesListAdapter.isSelectedItem(position));
+ if (mNotesListAdapter.isAllSelected())
+ menuItem.setTitle("unselected");
+// mModeCallBack.onItemCheckedStateChanged(null, position, id, !mNotesListAdapter.isSelectedItem(position));
}
- switch (mState) {
- case NOTE_LIST:
- if (item.getType() == Notes.TYPE_FOLDER
- || item.getType() == Notes.TYPE_SYSTEM) {
-// openFolder(item);
- } else if (item.getType() == Notes.TYPE_NOTE) {
- openNode(item);
- } else {
- Log.e(TAG, "Wrong note type in NOTE_LIST");
- }
- break;
- case SUB_FOLDER:
- case CALL_RECORD_FOLDER:
- if (item.getType() == Notes.TYPE_NOTE) {
- openNode(item);
- } else {
- Log.e(TAG, "Wrong note type in SUB_FOLDER");
- }
- break;
- default:
- break;
- }
+// switch (mState) {
+// case NOTE_LIST:
+// if (item.getType() == Notes.TYPE_FOLDER
+// || item.getType() == Notes.TYPE_SYSTEM) {
+//// openFolder(item);
+// } else if (item.getType() == Notes.TYPE_NOTE) {
+//// openNode(item);
+// } else {
+// Log.e(TAG, "Wrong note type in NOTE_LIST");
+// }
+// break;
+// case SUB_FOLDER:
+// case CALL_RECORD_FOLDER:
+// if (item.getType() == Notes.TYPE_NOTE) {
+//// openNode(item);
+// } else {
+// Log.e(TAG, "Wrong note type in SUB_FOLDER");
+// }
+// break;
+// default:
+// break;
+// }
}
}
}
- public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
- if (view instanceof NotesListItem) {
- mFocusNoteDataItem = ((NotesListItem) view).getItemData();
- if (mFocusNoteDataItem.getType() == Notes.TYPE_NOTE && !mNotesListAdapter.isInChoiceMode()) {
- if (mNotesListView.startActionMode(mModeCallBack) != null) {
- mModeCallBack.onItemCheckedStateChanged(null, position, id, true);
- mNotesListView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
- } else {
- Log.e(TAG, "startActionMode fails");
- }
- } else if (mFocusNoteDataItem.getType() == Notes.TYPE_FOLDER) {
- mNotesListView.setOnCreateContextMenuListener(mFolderOnCreateContextMenuListener);
- }
- }
+ @Override
+ public boolean onItemLongClick(AdapterView> adapterView, View view, int i, long l) {
return false;
}
+
+// public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
+// if (view instanceof NotesListItem) {
+// mFocusNoteDataItem = ((NotesListItem) view).getItemData();
+// if (mFocusNoteDataItem.getType() == Notes.TYPE_NOTE && !mNotesListAdapter.isInChoiceMode()) {
+// if (mNotesListView.startActionMode(mModeCallBack) != null) {
+// mModeCallBack.onItemCheckedStateChanged(null, position, id, true);
+// mNotesListView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
+// } else {
+// Log.e(TAG, "startActionMode fails");
+// }
+// } else if (mFocusNoteDataItem.getType() == Notes.TYPE_FOLDER) {
+// mNotesListView.setOnCreateContextMenuListener(mFolderOnCreateContextMenuListener);
+// }
+// }
+// return false;
+// }
}
diff --git a/src/app/src/main/res/layout/note_list.xml b/src/app/src/main/res/layout/note_list.xml
index 6b25d38..711f443 100644
--- a/src/app/src/main/res/layout/note_list.xml
+++ b/src/app/src/main/res/layout/note_list.xml
@@ -31,11 +31,11 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/title_bar_bg"
- android:visibility="gone"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="#FFEAD1AE"
- android:textSize="@dimen/text_font_size_medium" />
+ android:textSize="@dimen/text_font_size_medium"
+ android:visibility="gone" />
@@ -9,28 +10,18 @@
-
-
+ android:orientation="vertical"
+ tools:ignore="UselessParent">
+ android:fadingEdge="none" />
diff --git a/src/app/src/main/res/menu/recyclebin_options.xml b/src/app/src/main/res/menu/recyclebin_options.xml
new file mode 100644
index 0000000..bdaaa61
--- /dev/null
+++ b/src/app/src/main/res/menu/recyclebin_options.xml
@@ -0,0 +1,21 @@
+
+
+
+
diff --git a/src/app/src/main/res/values/strings.xml b/src/app/src/main/res/values/strings.xml
index 55df868..b52ff32 100644
--- a/src/app/src/main/res/values/strings.xml
+++ b/src/app/src/main/res/values/strings.xml
@@ -126,6 +126,8 @@
Notes
set
cancel
+ realdelete
+ recover
- %1$s result for \"%2$s\"
--
2.34.1
From 6678e4852c9b51a6f811eedce82c606caf832dae Mon Sep 17 00:00:00 2001
From: Mars_RH <1658408137@qq.com>
Date: Fri, 26 May 2023 22:02:22 +0800
Subject: [PATCH 3/3] finally compelete the new function,im very tired
---
README.md | 11 +-
.../micode/notes/ui/RecycleBinActivity.java | 654 +-----------------
2 files changed, 44 insertions(+), 621 deletions(-)
diff --git a/README.md b/README.md
index c98c5ae..2914774 100644
--- a/README.md
+++ b/README.md
@@ -10,10 +10,13 @@
- 2023/4/21 完成新功能需求文档
- 2023/4/28 新体系结构初稿设计完成
- 2023/4/28 新功能UI雏形设计完成
+- 2023/5/26 久违的更新了readme文件
+- 2023/5/26 完成了回收站的雏形
## TODO
-- [x] 新功能需求分析
-- [ ] 新功能实现
+- [ ] 回收站
- [ ] BUG修复
-- [x] 体系结构
-- [ ] UI设计
\ No newline at end of file
+- [ ] 背景切换
+- [ ] 代码质量分析报告
+- [ ] 需求与设计方案
+- [ ] 汇报PPT
\ No newline at end of file
diff --git a/src/app/src/main/java/net/micode/notes/ui/RecycleBinActivity.java b/src/app/src/main/java/net/micode/notes/ui/RecycleBinActivity.java
index d60060b..b49fdf7 100644
--- a/src/app/src/main/java/net/micode/notes/ui/RecycleBinActivity.java
+++ b/src/app/src/main/java/net/micode/notes/ui/RecycleBinActivity.java
@@ -1,88 +1,32 @@
package net.micode.notes.ui;
+import android.annotation.SuppressLint;
import android.app.Activity;
-import androidx.appcompat.app.AppCompatActivity;
-
import android.app.AlertDialog;
-import android.app.Dialog;
-import android.appwidget.AppWidgetManager;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
-import android.content.SharedPreferences;
import android.database.Cursor;
-import android.os.AsyncTask;
import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.text.Editable;
-import android.text.TextUtils;
-import android.text.TextWatcher;
import android.util.Log;
-import android.view.ActionMode;
-import android.view.ContextMenu;
-import android.view.ContextMenu.ContextMenuInfo;
-import android.view.Display;
-import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.Menu;
-import android.view.MenuInflater;
import android.view.MenuItem;
-import android.view.MenuItem.OnMenuItemClickListener;
-import android.view.MotionEvent;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.View.OnCreateContextMenuListener;
-import android.view.View.OnTouchListener;
-import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
-import android.widget.AdapterView.OnItemLongClickListener;
-import android.widget.Button;
-import android.widget.EditText;
import android.widget.ListView;
-import android.widget.PopupMenu;
-import android.widget.TextView;
import android.widget.Toast;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.gtask.remote.GTaskSyncService;
-import net.micode.notes.model.WorkingNote;
-import net.micode.notes.tool.BackupUtils;
import net.micode.notes.tool.DataUtils;
-import net.micode.notes.tool.ResourceParser;
-import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
-import net.micode.notes.widget.NoteWidgetProvider_2x;
-import net.micode.notes.widget.NoteWidgetProvider_4x;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.HashSet;
-
-public class RecycleBinActivity 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
- };
+public class RecycleBinActivity extends Activity {
+ private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;
- private ListEditState mState;
+ private static final int FOLDER_LIST_QUERY_TOKEN = 1;
private BackgroundQueryHandler mBackgroundQueryHandler;
@@ -90,28 +34,12 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
private ListView mNotesListView;
- private Button mAddNewNote;
-
- private boolean mDispatch;
-
- private int mOriginY;
-
- private int mDispatchY;
-
- private TextView mTitleBar;
-
private long mCurrentFolderId;
private ContentResolver mContentResolver;
-// private ModeCallback mModeCallBack;
-
private static final String TAG = "RecycleActivity";
- public static final int NOTES_LISTVIEW_SCROLL_RATE = 30;
-
- private NoteItemData mFocusNoteDataItem;
-
private MenuItem menuItem;
private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";
@@ -122,18 +50,13 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
+ 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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recycle_bin);
initResources();
-
- /**
- * Insert an introduction when user firstly use this application
- */
-// setAppInfoFromRawRes();
}
@Override
@@ -146,270 +69,45 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
}
}
-// private void setAppInfoFromRawRes() {
-// SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
-// if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
-// StringBuilder sb = new StringBuilder();
-// InputStream in = null;
-// try {
-// in = getResources().openRawResource(R.raw.introduction);
-// if (in != null) {
-// InputStreamReader isr = new InputStreamReader(in);
-// BufferedReader br = new BufferedReader(isr);
-// char [] buf = new char[1024];
-// int len = 0;
-// while ((len = br.read(buf)) > 0) {
-// sb.append(buf, 0, len);
-// }
-// } else {
-// Log.e(TAG, "Read introduction file error");
-// return;
-// }
-// } catch (IOException e) {
-// e.printStackTrace();
-// return;
-// } finally {
-// if(in != null) {
-// try {
-// in.close();
-// } catch (IOException e) {
-// e.printStackTrace();
-// }
-// }
-// }
-//
-// WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
-// AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
-// ResourceParser.RED);
-// note.setWorkingText(sb.toString());
-// if (note.saveNote()) {
-// sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
-// } else {
-// Log.e(TAG, "Save introduction note error");
-// return;
-// }
-// }
-// }
-
@Override
protected void onStart() {
super.onStart();
startAsyncNotesListQuery();
}
+ @SuppressLint("InflateParams")
private void initResources() {
mContentResolver = this.getContentResolver();
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
mCurrentFolderId = Notes.ID_TRASH_FOLER;
- mNotesListView = (ListView) findViewById(R.id.recycle_list);
+ mNotesListView = findViewById(R.id.recycle_list);
mNotesListView.addFooterView(LayoutInflater.from(this).inflate(R.layout.note_list_footer, null),
null, false);
mNotesListView.setOnItemClickListener(new OnListItemClickListener());
-// mNotesListView.setOnItemLongClickListener(this);
mNotesListAdapter = new NotesListAdapter(this);
mNotesListAdapter.setChoiceMode(true);
mNotesListView.setAdapter(mNotesListAdapter);
-// mAddNewNote = (Button) findViewById(R.id.btn_new_note);
-// mAddNewNote.setOnClickListener(this);
-// mAddNewNote.setOnTouchListener(new NewNoteOnTouchListener());
- mDispatch = false;
- mDispatchY = 0;
- mOriginY = 0;
- mTitleBar = (TextView) findViewById(R.id.tv_title_bar);
- mState = ListEditState.NOTE_LIST;
-// mModeCallBack = new ModeCallback();
-// mNotesListView.startActionMode(mModeCallBack);
}
/**
* 重置选择器状态
*/
- private void reset_ChoiseMode(){
+ private void reset_ChoiseMode() {
mNotesListAdapter.setChoiceMode(false);
mNotesListAdapter.setChoiceMode(true);
}
- // TODO: 2023/5/26 重写这一块
-// private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
-// private DropdownMenu mDropDownMenu;
-// private ActionMode mActionMode;
-// private MenuItem mMoveMenu;
-//
-// public boolean onCreateActionMode(ActionMode mode, Menu menu) {
-// getMenuInflater().inflate(R.menu.note_list_options, menu);
-// menu.findItem(R.id.delete).setOnMenuItemClickListener(this);
-// mMoveMenu = menu.findItem(R.id.move);
-//
-// mMoveMenu.setVisible(true);
-// mMoveMenu.setOnMenuItemClickListener(this);
-//
-// mActionMode = mode;
-// mNotesListAdapter.setChoiceMode(true);
-// mNotesListView.setLongClickable(false);
-//// mAddNewNote.setVisibility(View.GONE);
-//
-// View customView = LayoutInflater.from(RecycleBinActivity.this).inflate(
-// R.layout.note_list_dropdown_menu, null);
-// mode.setCustomView(customView);
-// mDropDownMenu = new DropdownMenu(RecycleBinActivity.this,
-// (Button) customView.findViewById(R.id.selection_menu),
-// R.menu.note_list_dropdown);
-// mDropDownMenu.setOnDropdownMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
-// public boolean onMenuItemClick(MenuItem item) {
-// mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected());
-// updateMenu();
-// return true;
-// }
-//
-// });
-// return true;
-// }
-//
-// private void updateMenu() {
-// int selectedCount = mNotesListAdapter.getSelectedCount();
-// // Update dropdown menu
-// String format = getResources().getString(R.string.menu_select_title, selectedCount);
-// mDropDownMenu.setTitle(format);
-// MenuItem item = mDropDownMenu.findItem(R.id.action_select_all);
-// if (item != null) {
-// if (mNotesListAdapter.isAllSelected()) {
-// item.setChecked(true);
-// item.setTitle(R.string.menu_deselect_all);
-// } else {
-// item.setChecked(false);
-// item.setTitle(R.string.menu_select_all);
-// }
-// }
-// }
-//
-// public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
-// return false;
-// }
-//
-// public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
-// return false;
-// }
-//
-// public void onDestroyActionMode(ActionMode mode) {
-//// mNotesListAdapter.setChoiceMode(false);
-//// mNotesListView.setLongClickable(true);
-//// mAddNewNote.setVisibility(View.VISIBLE);
-// }
-//
-// public void finishActionMode() {
-// mActionMode.finish();
-// }
-//
-// public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
-// boolean checked) {
-// mNotesListAdapter.setCheckedItem(position, checked);
-// updateMenu();
-// }
-//
-// public boolean onMenuItemClick(MenuItem item) {
-// if (mNotesListAdapter.getSelectedCount() == 0) {
-// Toast.makeText(RecycleBinActivity.this, getString(R.string.menu_select_none),
-// Toast.LENGTH_SHORT).show();
-// return true;
-// }
-//
-// switch (item.getItemId()) {
-// case R.id.delete:
-// AlertDialog.Builder builder = new AlertDialog.Builder(RecycleBinActivity.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()));
-// builder.setPositiveButton(android.R.string.ok,
-// new DialogInterface.OnClickListener() {
-// public void onClick(DialogInterface dialog,
-// int which) {
-// batchDelete();
-// }
-// });
-// builder.setNegativeButton(android.R.string.cancel, null);
-// builder.show();
-// break;
-// case R.id.move:
-//// startQueryDestinationFolders();
-// break;
-// default:
-// 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();
-// int start = screenHeight - newNoteViewHeight;
-// int eventY = start + (int) event.getY();
-// /**
-// * Minus TitleBar's height
-// */
-// if (mState == ListEditState.SUB_FOLDER) {
-// eventY -= mTitleBar.getHeight();
-// start -= mTitleBar.getHeight();
-// }
-// /**
-// * HACKME:When click the transparent part of "New Note" button, dispatch
-// * the event to the list view behind this button. The transparent part of
-// * "New Note" button could be expressed by formula y=-0.12x+94(Unit:pixel)
-// * and the line top of the button. The coordinate based on left of the "New
-// * Note" button. The 94 represents maximum height of the transparent part.
-// * Notice that, if the background of the button changes, the formula should
-// * also change. This is very bad, just for the UI designer's strong requirement.
-// */
-// if (event.getY() < (event.getX() * (-0.12) + 94)) {
-// View view = mNotesListView.getChildAt(mNotesListView.getChildCount() - 1
-// - mNotesListView.getFooterViewsCount());
-// if (view != null && view.getBottom() > start
-// && (view.getTop() < (start + 94))) {
-// mOriginY = (int) event.getY();
-// mDispatchY = eventY;
-// event.setLocation(event.getX(), mDispatchY);
-// mDispatch = true;
-// return mNotesListView.dispatchTouchEvent(event);
-// }
-// }
-// break;
-// }
-// case MotionEvent.ACTION_MOVE: {
-// if (mDispatch) {
-// mDispatchY += (int) event.getY() - mOriginY;
-// event.setLocation(event.getX(), mDispatchY);
-// return mNotesListView.dispatchTouchEvent(event);
-// }
-// break;
-// }
-// default: {
-// if (mDispatch) {
-// event.setLocation(event.getX(), mDispatchY);
-// mDispatch = false;
-// return mNotesListView.dispatchTouchEvent(event);
-// }
-// break;
-// }
-// }
-// return false;
-// }
-//
-// };
+
private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
: NORMAL_SELECTION;
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)
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
}
+ @SuppressLint("HandlerLeak")
private final class BackgroundQueryHandler extends AsyncQueryHandler {
public BackgroundQueryHandler(ContentResolver contentResolver) {
super(contentResolver);
@@ -429,7 +127,6 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
}
break;
default:
- return;
}
}
}
@@ -438,30 +135,20 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
AlertDialog.Builder builder = new AlertDialog.Builder(RecycleBinActivity.this);
builder.setTitle(R.string.menu_title_select_folder);
final FoldersListAdapter adapter = new FoldersListAdapter(this, cursor);
- builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
-
- public void onClick(DialogInterface dialog, int which) {
- DataUtils.batchMoveToFolder(mContentResolver,
- mNotesListAdapter.getSelectedItemIds(), adapter.getItemId(which));
- Toast.makeText(
- RecycleBinActivity.this,
- getString(R.string.format_move_notes_to_folder,
- mNotesListAdapter.getSelectedCount(),
- adapter.getFolderName(RecycleBinActivity.this, which)),
- Toast.LENGTH_SHORT).show();
-// mModeCallBack.finishActionMode();
- }
+ builder.setAdapter(adapter, (dialog, which) -> {
+ DataUtils.batchMoveToFolder(mContentResolver,
+ mNotesListAdapter.getSelectedItemIds(), adapter.getItemId(which));
+ Toast.makeText(
+ RecycleBinActivity.this,
+ getString(R.string.format_move_notes_to_folder,
+ mNotesListAdapter.getSelectedCount(),
+ adapter.getFolderName(RecycleBinActivity.this, which)),
+ Toast.LENGTH_SHORT).show();
});
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);
-// }
-
+ // TODO: 2023/5/26 修改一下删除函数
private void batchDelete() {
// delete notes directly
if (!DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
@@ -470,168 +157,28 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
}
}
- private void deleteFolder(long folderId) {
- if (folderId == Notes.ID_ROOT_FOLDER) {
- Log.e(TAG, "Wrong folder id, should not happen " + folderId);
- return;
- }
-
- HashSet ids = new HashSet();
- ids.add(folderId);
- HashSet widgets = DataUtils.getFolderNoteWidget(mContentResolver,
- folderId);
- if (false) {
- // 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) {
- for (AppWidgetAttribute widget : widgets) {
- if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
- && widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) {
- updateWidget(widget.widgetId, widget.widgetType);
- }
- }
- }
- }
-
-// private void openNode(NoteItemData data) {
-// Intent intent = new Intent(this, NoteEditActivity.class);
-// intent.setAction(Intent.ACTION_VIEW);
-// intent.putExtra(Intent.EXTRA_UID, data.getId());
-// this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
-// }
-
- public void onClick(View v) {
-// switch (v.getId()) {
-// case R.id.btn_new_note:
-// createNewNote();
-// break;
-// default:
-// break;
-// }
- }
-
-// 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);
-// }
-
@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;
-//// mAddNewNote.setVisibility(View.VISIBLE);
-// mTitleBar.setVisibility(View.GONE);
-// startAsyncNotesListQuery();
-// break;
-// case NOTE_LIST:
-// super.onBackPressed();
-// break;
-// default:
-// break;
-// }
- Intent intent=new Intent(RecycleBinActivity.this,NotesListActivity.class);
+ Intent intent = new Intent(RecycleBinActivity.this, NotesListActivity.class);
startActivity(intent);
finish();
}
- private void updateWidget(int appWidgetId, int appWidgetType) {
- Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
- if (appWidgetType == Notes.TYPE_WIDGET_2X) {
- intent.setClass(this, NoteWidgetProvider_2x.class);
- } else if (appWidgetType == Notes.TYPE_WIDGET_4X) {
- intent.setClass(this, NoteWidgetProvider_4x.class);
- } else {
- Log.e(TAG, "Unspported widget type");
- return;
- }
-
- intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
- appWidgetId
- });
-
- 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);
-// }
-// }
-// };
-
@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;
- }
- 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() {
- public void onClick(DialogInterface dialog, int which) {
- deleteFolder(mFocusNoteDataItem.getId());
- }
- });
- builder.setNegativeButton(android.R.string.cancel, null);
- builder.show();
- break;
- case MENU_FOLDER_CHANGE_NAME:
-// showCreateOrModifyFolderDialog(false);
- break;
- default:
- break;
- }
-
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.recyclebin_options,menu);
-
- menuItem = menu.findItem(R.id.select_all);
+ getMenuInflater().inflate(R.menu.recyclebin_options, menu);
- return super.onCreateOptionsMenu(menu);
+ return super.onCreateOptionsMenu(menu);
}
@Override
@@ -639,103 +186,29 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
menu.clear();
getMenuInflater().inflate(R.menu.recyclebin_options, menu);
+ menuItem = menu.findItem(R.id.select_all);
-
-
-// View customView = LayoutInflater.from(RecycleBinActivity.this).inflate(
-// R.layout.note_list_dropdown_menu, null);
-// mode.setCustomView(customView);
-//
-// DropdownMenu mDropDownMenu = new DropdownMenu(RecycleBinActivity.this,
-// (Button) customView.findViewById(R.id.selection_menu),
-// R.menu.note_list_dropdown);
-// mDropDownMenu.setOnDropdownMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
-// public boolean onMenuItemClick(MenuItem item) {
-// mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected());
-// updateMenu();
-// return true;
-// }
-//
-// });
-// if (mState == ListEditState.NOTE_LIST) {
-// getMenuInflater().inflate(R.menu.recyclebin_options, 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) {
-// getMenuInflater().inflate(R.menu.sub_folder, menu);
-// } else if (mState == ListEditState.CALL_RECORD_FOLDER) {
-// getMenuInflater().inflate(R.menu.call_record_folder, menu);
-// } else {
-// Log.e(TAG, "Wrong state:" + mState);
-// }
return true;
}
-// private void startQueryDestinationFolders() {
-// String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?";
-// selection = (mState == RecycleBinActivity.ListEditState.NOTE_LIST) ? selection:
-// "(" + selection + ") OR (" + NoteColumns.ID + "=" + Notes.ID_ROOT_FOLDER + ")";
-//
-// mBackgroundQueryHandler.startQuery(FOLDER_LIST_QUERY_TOKEN,
-// null,
-// Notes.CONTENT_NOTE_URI,
-// FoldersListAdapter.PROJECTION,
-// selection,
-// new String[] {
-// String.valueOf(Notes.TYPE_FOLDER),
-// String.valueOf(Notes.ID_TRASH_FOLER),
-// String.valueOf(mCurrentFolderId)
-// },
-// NoteColumns.MODIFIED_DATE + " DESC");
-// }
-
/**
- * 当顶部菜单项被选择时所执行的函数
+ * 当顶部菜单项被选择时所执行的函数
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
-// switch (item.getItemId()) {
-// case R.id.menu_new_folder: {
-//// showCreateOrModifyFolderDialog(true);
-// break;
-// }
-// case R.id.menu_export_text: {
-//// exportNoteToText();
-// break;
-// }
-// case R.id.menu_setting: {
-//// startPreferenceActivity();
-// break;
-// }
-// case R.id.menu_new_note: {
-//// createNewNote();
-// break;
-// }
-// case R.id.menu_search:
-// onSearchRequested();
-// break;
-//// case R.id.RecycleBin:
-//// recycleBin();
-//// break;
-// default:
-// break;
-// }
+
// TODO: 2023/5/26 为这两个选项加入弹窗
if (item.getItemId() == R.id.recover) {
if (!DataUtils.batchMoveToFolder(mContentResolver,
mNotesListAdapter.getSelectedItemIds(), Notes.ID_ROOT_FOLDER))
Log.e(TAG, "Recover error, should not happens");
- }
- else if (item.getItemId() == R.id.realdelete) {
+ } else if (item.getItemId() == R.id.realdelete) {
batchDelete();
- }
- else if (item.getItemId() == R.id.select_all) {
- if (!mNotesListAdapter.isAllSelected()){
+ } else if (item.getItemId() == R.id.select_all) {
+ if (!mNotesListAdapter.isAllSelected()) {
item.setTitle("deselect_all");
mNotesListAdapter.selectAll(true);
- }
- else {
+ } else {
item.setTitle("selected_all");
mNotesListAdapter.selectAll(false);
}
@@ -745,83 +218,30 @@ public class RecycleBinActivity extends Activity implements OnClickListener, OnI
return true;
}
-// private void recycleBin() {
-// Intent intent=new Intent(RecycleBinActivity.this,RecycleBinActivity.class);
-// startActivity(intent);
-// finish();
-// }
-
@Override
public boolean onSearchRequested() {
startSearch(null, false, null /* appData */, false);
return true;
}
-// private void startPreferenceActivity() {
-// Activity from = getParent() != null ? getParent() : this;
-// Intent intent = new Intent(from, NotesPreferenceActivity.class);
-// from.startActivityIfNeeded(intent, -1);
-// }
-
+ // TODO: 2023/5/26 将title改成一个icon
private class OnListItemClickListener implements OnItemClickListener {
public void onItemClick(AdapterView> parent, View view, int position, long id) {
if (view instanceof NotesListItem) {
NoteItemData item = ((NotesListItem) view).getItemData();
+
if (item.getType() == Notes.TYPE_NOTE) {
position = position - mNotesListView.getHeaderViewsCount();
mNotesListAdapter.setCheckedItem(position, !mNotesListAdapter.isSelectedItem(position));
+
if (mNotesListAdapter.isAllSelected())
- menuItem.setTitle("unselected");
-// mModeCallBack.onItemCheckedStateChanged(null, position, id, !mNotesListAdapter.isSelectedItem(position));
+ menuItem.setTitle("deselected_all");
+ else if (menuItem.getTitle() == "deselected_all")
+ menuItem.setTitle("selected_all");
}
-
-// switch (mState) {
-// case NOTE_LIST:
-// if (item.getType() == Notes.TYPE_FOLDER
-// || item.getType() == Notes.TYPE_SYSTEM) {
-//// openFolder(item);
-// } else if (item.getType() == Notes.TYPE_NOTE) {
-//// openNode(item);
-// } else {
-// Log.e(TAG, "Wrong note type in NOTE_LIST");
-// }
-// break;
-// case SUB_FOLDER:
-// case CALL_RECORD_FOLDER:
-// if (item.getType() == Notes.TYPE_NOTE) {
-//// openNode(item);
-// } else {
-// Log.e(TAG, "Wrong note type in SUB_FOLDER");
-// }
-// break;
-// default:
-// break;
-// }
}
}
}
-
- @Override
- public boolean onItemLongClick(AdapterView> adapterView, View view, int i, long l) {
- return false;
- }
-
-// public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
-// if (view instanceof NotesListItem) {
-// mFocusNoteDataItem = ((NotesListItem) view).getItemData();
-// if (mFocusNoteDataItem.getType() == Notes.TYPE_NOTE && !mNotesListAdapter.isInChoiceMode()) {
-// if (mNotesListView.startActionMode(mModeCallBack) != null) {
-// mModeCallBack.onItemCheckedStateChanged(null, position, id, true);
-// mNotesListView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
-// } else {
-// Log.e(TAG, "startActionMode fails");
-// }
-// } else if (mFocusNoteDataItem.getType() == Notes.TYPE_FOLDER) {
-// mNotesListView.setOnCreateContextMenuListener(mFolderOnCreateContextMenuListener);
-// }
-// }
-// return false;
-// }
}
--
2.34.1