- public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- switch (item.getItemId()) {
- case R.id.select_all:
- // Get the total number of bookmarks.
- int numberOfBookmarks = bookmarksListView.getCount();
-
- // Select them all.
- for (int i = 0; i < numberOfBookmarks; i++) {
- bookmarksListView.setItemChecked(i, true);
- }
- break;
-
- case R.id.delete:
- // Set the deleting bookmarks flag, which prevents the delete menu item from being enabled until the current process finishes.
- deletingBookmarks = true;
-
- // Get an array of the selected row IDs.
- long[] selectedBookmarksIdsLongArray = bookmarksListView.getCheckedItemIds();
-
- // Get an array of checked bookmarks. `.clone()` makes a copy that won't change if the list view is reloaded, which is needed for re-selecting the bookmarks on undelete.
- SparseBooleanArray selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions().clone();
-
- // Update the bookmarks cursor with the current contents of the bookmarks database except for the specified database IDs.
- switch (currentFolderDatabaseId) {
- // Get a cursor with all the folders.
- case ALL_FOLDERS_DATABASE_ID:
- if (sortByDisplayOrder) {
- bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray);
- } else {
- bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksExcept(selectedBookmarksIdsLongArray);
- }
- break;
-
- // Get a cursor for the home folder.
- case HOME_FOLDER_DATABASE_ID:
- if (sortByDisplayOrder) {
- bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray, "");
- } else {
- bookmarksCursor = bookmarksDatabaseHelper.getBookmarksExcept(selectedBookmarksIdsLongArray, "");
- }
- break;
-
- // Display the selected folder.
- default:
- // Get a cursor for the selected folder.
- if (sortByDisplayOrder) {
- bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray, currentFolderName);
- } else {
- bookmarksCursor = bookmarksDatabaseHelper.getBookmarksExcept(selectedBookmarksIdsLongArray, currentFolderName);
- }
- }
+ public boolean onActionItemClicked(ActionMode mode, MenuItem menuItem) {
+ // Get a the menu item ID.
+ int menuItemId = menuItem.getItemId();
+
+ // Run the command that corresponds to the selected menu item.
+ if (menuItemId == R.id.select_all) { // Select all the bookmarks.
+ // Get the total number of bookmarks.
+ int numberOfBookmarks = bookmarksListView.getCount();
+
+ // Select them all.
+ for (int i = 0; i < numberOfBookmarks; i++) {
+ bookmarksListView.setItemChecked(i, true);
+ }
+ } else if (menuItemId == R.id.delete) { // Delete the selected bookmarks.
+ // Set the deleting bookmarks flag, which prevents the delete menu item from being enabled until the current process finishes.
+ deletingBookmarks = true;
+
+ // Get an array of the selected row IDs.
+ long[] selectedBookmarksIdsLongArray = bookmarksListView.getCheckedItemIds();
+
+ // Get an array of checked bookmarks. `.clone()` makes a copy that won't change if the list view is reloaded, which is needed for re-selecting the bookmarks on undelete.
+ SparseBooleanArray selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions().clone();
+
+ // Update the bookmarks cursor with the current contents of the bookmarks database except for the specified database IDs.
+ switch (currentFolderDatabaseId) {
+ // Get a cursor with all the folders.
+ case ALL_FOLDERS_DATABASE_ID:
+ if (sortByDisplayOrder) {
+ bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray);
+ } else {
+ bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksExcept(selectedBookmarksIdsLongArray);
+ }
+ break;
+
+ // Get a cursor for the home folder.
+ case HOME_FOLDER_DATABASE_ID:
+ if (sortByDisplayOrder) {
+ bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray, "");
+ } else {
+ bookmarksCursor = bookmarksDatabaseHelper.getBookmarksExcept(selectedBookmarksIdsLongArray, "");
+ }
+ break;
+
+ // Display the selected folder.
+ default:
+ // Get a cursor for the selected folder.
+ if (sortByDisplayOrder) {
+ bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray, currentFolderName);
+ } else {
+ bookmarksCursor = bookmarksDatabaseHelper.getBookmarksExcept(selectedBookmarksIdsLongArray, currentFolderName);
+ }
+ }