2 * Copyright © 2016-2019 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
6 * Privacy Browser is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser. If not, see <http://www.gnu.org/licenses/>.
20 package com.stoutner.privacybrowser.activities;
22 import android.app.Activity;
23 import android.content.Context;
24 import android.content.Intent;
25 import android.database.Cursor;
26 import android.graphics.Bitmap;
27 import android.graphics.BitmapFactory;
28 import android.graphics.Typeface;
29 import android.graphics.drawable.BitmapDrawable;
30 import android.graphics.drawable.Drawable;
31 import android.os.Bundle;
32 import android.support.design.widget.FloatingActionButton;
33 import android.support.design.widget.Snackbar;
34 import android.support.v4.app.NavUtils;
35 import android.support.v7.app.ActionBar;
36 import android.support.v7.app.AppCompatActivity;
37 // `AppCompatDialogFragment` is required instead of `DialogFragment` or an error is produced on API <=22.
38 import android.support.v7.app.AppCompatDialogFragment;
39 import android.support.v7.widget.Toolbar;
40 import android.util.SparseBooleanArray;
41 import android.view.ActionMode;
42 import android.view.Menu;
43 import android.view.MenuItem;
44 import android.view.View;
45 import android.view.ViewGroup;
46 import android.view.WindowManager;
47 import android.widget.AbsListView;
48 import android.widget.CursorAdapter;
49 import android.widget.EditText;
50 import android.widget.ImageView;
51 import android.widget.ListView;
52 import android.widget.RadioButton;
53 import android.widget.TextView;
55 import com.stoutner.privacybrowser.dialogs.CreateBookmarkDialog;
56 import com.stoutner.privacybrowser.dialogs.CreateBookmarkFolderDialog;
57 import com.stoutner.privacybrowser.dialogs.EditBookmarkDialog;
58 import com.stoutner.privacybrowser.dialogs.EditBookmarkFolderDialog;
59 import com.stoutner.privacybrowser.dialogs.MoveToFolderDialog;
60 import com.stoutner.privacybrowser.R;
61 import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper;
63 import java.io.ByteArrayOutputStream;
65 public class BookmarksActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener, EditBookmarkDialog.EditBookmarkListener,
66 EditBookmarkFolderDialog.EditBookmarkFolderListener, MoveToFolderDialog.MoveToFolderListener {
68 // `currentFolder` is public static so it can be accessed from `MoveToFolderDialog`.
69 // It is used in `onCreate`, `onOptionsItemSelected()`, `onBackPressed()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`,
70 // and `loadFolder()`.
71 public static String currentFolder;
73 // `checkedItemIds` is public static so it can be accessed from `MoveToFolderDialog`. It is also used in `onCreate()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`,
74 // and `updateMoveIcons()`.
75 public static long[] checkedItemIds;
78 // `bookmarksDatabaseHelper` is used in `onCreate()`, `onOptionsItemSelected()`, `onBackPressed()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`,
79 // `onMoveToFolder()`, `deleteBookmarkFolderContents()`, `loadFolder()`, and `onDestroy()`.
80 private BookmarksDatabaseHelper bookmarksDatabaseHelper;
82 // `bookmarksListView` is used in `onCreate()`, `onOptionsItemSelected()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`,
83 // `updateMoveIcons()`, `scrollBookmarks()`, and `loadFolder()`.
84 private ListView bookmarksListView;
86 // `bookmarksCursor` is used in `onCreate()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`, `deleteBookmarkFolderContents()`,
87 // `loadFolder()`, and `onDestroy()`.
88 private Cursor bookmarksCursor;
90 // `bookmarksCursorAdapter` is used in `onCreate(), `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`, and `onLoadFolder()`.
91 private CursorAdapter bookmarksCursorAdapter;
93 // `contextualActionMode` is used in `onCreate()`, `onSaveEditBookmark()`, `onSaveEditBookmarkFolder()` and `onMoveToFolder()`.
94 private ActionMode contextualActionMode;
96 // `appBar` is used in `onCreate()` and `loadFolder()`.
97 private ActionBar appBar;
99 // `oldFolderName` is used in `onCreate()` and `onSaveBookmarkFolder()`.
100 private String oldFolderNameString;
102 // `moveBookmarkUpMenuItem` is used in `onCreate()` and `updateMoveIcons()`.
103 private MenuItem moveBookmarkUpMenuItem;
105 // `moveBookmarkDownMenuItem` is used in `onCreate()` and `updateMoveIcons()`.
106 private MenuItem moveBookmarkDownMenuItem;
108 // `bookmarksDeletedSnackbar` is used in `onCreate()`, `onOptionsItemSelected()`, and `onBackPressed()`.
109 private Snackbar bookmarksDeletedSnackbar;
111 // `closeActivityAfterDismissingSnackbar` is used in `onCreate()`, `onOptionsItemSelected()`, and `onBackPressed()`.
112 private boolean closeActivityAfterDismissingSnackbar;
115 protected void onCreate(Bundle savedInstanceState) {
116 // Disable screenshots if not allowed.
117 if (!MainWebViewActivity.allowScreenshots) {
118 getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
121 // Set the activity theme.
122 if (MainWebViewActivity.darkTheme) {
123 setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
125 setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
128 // Run the default commands.
129 super.onCreate(savedInstanceState);
131 // Get the intent that launched the activity.
132 Intent launchingIntent = getIntent();
134 // Set the current folder variable.
135 if (launchingIntent.getStringExtra("Current Folder") != null) { // Set the current folder from the intent.
136 currentFolder = launchingIntent.getStringExtra("Current Folder");
137 } else { // Set the current folder to be `""`, which is the home folder.
141 // Set the content view.
142 setContentView(R.layout.bookmarks_coordinatorlayout);
144 // Use the `SupportActionBar` from `android.support.v7.app.ActionBar` until the minimum API is >= 21.
145 final Toolbar bookmarksAppBar = findViewById(R.id.bookmarks_toolbar);
146 setSupportActionBar(bookmarksAppBar);
148 // Get a handle for the activity, the app bar, and the ListView.
149 final Activity bookmarksActivity = this;
150 appBar = getSupportActionBar();
151 bookmarksListView = findViewById(R.id.bookmarks_listview);
153 // Remove the incorrect lint warning that `appBar` might be null.
154 assert appBar != null;
156 // Display the home arrow on the app bar.
157 appBar.setDisplayHomeAsUpEnabled(true);
159 // Initialize the database helper. `this` specifies the context. The two `nulls` do not specify the database name or a `CursorFactory`.
160 // The `0` specifies a database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`.
161 bookmarksDatabaseHelper = new BookmarksDatabaseHelper(this, null, null, 0);
163 // Load the home folder.
166 // Set a listener so that tapping a list item loads the URL or folder.
167 bookmarksListView.setOnItemClickListener((parent, view, position, id) -> {
168 // Convert the id from long to int to match the format of the bookmarks database.
169 int databaseID = (int) id;
171 // Get the bookmark cursor for this ID and move it to the first row.
172 Cursor bookmarkCursor = bookmarksDatabaseHelper.getBookmarkCursor(databaseID);
173 bookmarkCursor.moveToFirst();
175 // Act upon the bookmark according to the type.
176 if (bookmarkCursor.getInt(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) { // The selected bookmark is a folder.
177 // Update the current folder.
178 currentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
180 // Load the new folder.
182 } else { // The selected bookmark is not a folder.
183 // Get the bookmark URL and assign it to `formattedUrlString`.
184 MainWebViewActivity.formattedUrlString = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL));
186 // Set `MainWebViewActivity` to load the new URL on restart.
187 MainWebViewActivity.loadUrlOnRestart = true;
189 // Update the bookmarks folder for the bookmarks drawer in `MainWebViewActivity`.
190 MainWebViewActivity.currentBookmarksFolder = currentFolder;
192 // Close the bookmarks drawer and reload the bookmarks `ListView` when returning to `MainWebViewActivity`.
193 MainWebViewActivity.restartFromBookmarksActivity = true;
195 // Return to `MainWebViewActivity`.
196 NavUtils.navigateUpFromSameTask(bookmarksActivity);
199 // Close the `Cursor`.
200 bookmarkCursor.close();
203 // Get a handle for the activity.
204 Activity activity = this;
206 // `MultiChoiceModeListener` handles long clicks.
207 bookmarksListView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
208 // Instantiate the common variables.
209 MenuItem editBookmarkMenuItem;
210 MenuItem deleteBookmarksMenuItem;
211 MenuItem selectAllBookmarksMenuItem;
212 boolean deletingBookmarks;
215 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
216 // Inflate the menu for the contextual app bar and set the title.
217 getMenuInflater().inflate(R.menu.bookmarks_context_menu, menu);
220 if (currentFolder.isEmpty()) {
221 // Use `R.string.bookmarks` if we are in the home folder.
222 mode.setTitle(R.string.bookmarks);
223 } else { // Use the current folder name as the title.
224 mode.setTitle(currentFolder);
227 // Get a handle for `MenuItems` that need to be selectively disabled.
228 moveBookmarkUpMenuItem = menu.findItem(R.id.move_bookmark_up);
229 moveBookmarkDownMenuItem = menu.findItem(R.id.move_bookmark_down);
230 editBookmarkMenuItem = menu.findItem(R.id.edit_bookmark);
231 deleteBookmarksMenuItem = menu.findItem(R.id.delete_bookmark);
232 selectAllBookmarksMenuItem = menu.findItem(R.id.context_menu_select_all_bookmarks);
234 // Disable the delete bookmarks menu item if a delete is pending.
235 if (deletingBookmarks) {
236 deleteBookmarksMenuItem.setEnabled(false);
239 // Store `contextualActionMode` so it can be closed programatically.
240 contextualActionMode = mode;
247 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
248 // Get a handle for the move to folder menu item.
249 MenuItem moveToFolderMenuItem = menu.findItem(R.id.move_to_folder);
251 // Get a `Cursor` with all of the folders.
252 Cursor folderCursor = bookmarksDatabaseHelper.getAllFoldersCursor();
254 // Enable the move to folder menu item if at least one folder exists.
255 moveToFolderMenuItem.setVisible(folderCursor.getCount() > 0);
262 public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
263 // Get a long array of the selected bookmarks.
264 long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
266 // Calculate the number of selected bookmarks.
267 int numberOfSelectedBookmarks = selectedBookmarksLongArray.length;
269 // Adjust the `ActionMode` and the `Menu` according to the number of selected bookmarks.
270 if (numberOfSelectedBookmarks == 0) { // No bookmarks are selected.
271 // Close the `ActionMode`.
273 } else if (numberOfSelectedBookmarks == 1) { // One bookmark is selected.
274 // List the number of selected bookmarks in the subtitle.
275 mode.setSubtitle(getString(R.string.selected) + " 1");
277 // Show the `Move Up`, `Move Down`, and `Edit` options.
278 moveBookmarkUpMenuItem.setVisible(true);
279 moveBookmarkDownMenuItem.setVisible(true);
280 editBookmarkMenuItem.setVisible(true);
282 // Update the enabled status of the move icons.
284 } else { // More than one bookmark is selected.
285 // List the number of selected bookmarks in the subtitle.
286 mode.setSubtitle(getString(R.string.selected) + " " + numberOfSelectedBookmarks);
288 // Hide non-applicable `MenuItems`.
289 moveBookmarkUpMenuItem.setVisible(false);
290 moveBookmarkDownMenuItem.setVisible(false);
291 editBookmarkMenuItem.setVisible(false);
294 // Do not show `Select All` if all the bookmarks are already checked.
295 if (bookmarksListView.getCheckedItemIds().length == bookmarksListView.getCount()) {
296 selectAllBookmarksMenuItem.setVisible(false);
298 selectAllBookmarksMenuItem.setVisible(true);
303 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
304 // Get the menu item ID.
305 int menuItemId = item.getItemId();
307 // Instantiate the common variables.
308 int selectedBookmarkPosition;
309 int selectedBookmarkNewPosition;
310 final SparseBooleanArray selectedBookmarksPositionsSparseBooleanArray;
312 switch (menuItemId) {
313 case R.id.move_bookmark_up:
314 // Get the array of checked bookmark positions.
315 selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
317 // Store the position of the selected bookmark. Only one bookmark is selected when `move_bookmark_up` is enabled.
318 selectedBookmarkPosition = selectedBookmarksPositionsSparseBooleanArray.keyAt(0);
320 // Calculate the new position of the selected bookmark.
321 selectedBookmarkNewPosition = selectedBookmarkPosition - 1;
323 // Iterate through the bookmarks.
324 for (int i = 0; i < bookmarksListView.getCount(); i++) {
325 // Get the database ID for the current bookmark.
326 int currentBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(i);
328 // Update the display order for the current bookmark.
329 if (i == selectedBookmarkPosition) { // The current bookmark is the selected bookmark.
330 // Move the current bookmark up one.
331 bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i - 1);
332 } else if ((i + 1) == selectedBookmarkPosition){ // The current bookmark is immediately above the selected bookmark.
333 // Move the current bookmark down one.
334 bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i + 1);
335 } else { // The current bookmark is not changing positions.
336 // Move `bookmarksCursor` to the current bookmark position.
337 bookmarksCursor.moveToPosition(i);
339 // Update the display order only if it is not correct in the database.
340 if (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)) != i) {
341 bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i);
346 // Update `bookmarksCursor` with the current contents of the bookmarks database.
347 bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
349 // Update the `ListView`.
350 bookmarksCursorAdapter.changeCursor(bookmarksCursor);
352 // Scroll with the bookmark.
353 scrollBookmarks(selectedBookmarkNewPosition);
355 // Update the enabled status of the move icons.
359 case R.id.move_bookmark_down:
360 // Get the array of checked bookmark positions.
361 selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
363 // Store the position of the selected bookmark. Only one bookmark is selected when `move_bookmark_down` is enabled.
364 selectedBookmarkPosition = selectedBookmarksPositionsSparseBooleanArray.keyAt(0);
366 // Calculate the new position of the selected bookmark.
367 selectedBookmarkNewPosition = selectedBookmarkPosition + 1;
369 // Iterate through the bookmarks.
370 for (int i = 0; i <bookmarksListView.getCount(); i++) {
371 // Get the database ID for the current bookmark.
372 int currentBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(i);
374 // Update the display order for the current bookmark.
375 if (i == selectedBookmarkPosition) { // The current bookmark is the selected bookmark.
376 // Move the current bookmark down one.
377 bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i + 1);
378 } else if ((i - 1) == selectedBookmarkPosition) { // The current bookmark is immediately below the selected bookmark.
379 // Move the bookmark below the selected bookmark up one.
380 bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i - 1);
381 } else { // The current bookmark is not changing positions.
382 // Move `bookmarksCursor` to the current bookmark position.
383 bookmarksCursor.moveToPosition(i);
385 // Update the display order only if it is not correct in the database.
386 if (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)) != i) {
387 bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i);
392 // Update `bookmarksCursor` with the current contents of the bookmarks database.
393 bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
395 // Update the `ListView`.
396 bookmarksCursorAdapter.changeCursor(bookmarksCursor);
398 // Scroll with the bookmark.
399 scrollBookmarks(selectedBookmarkNewPosition);
401 // Update the enabled status of the move icons.
405 case R.id.move_to_folder:
406 // Store `checkedItemIds` for use by the `AlertDialog`.
407 checkedItemIds = bookmarksListView.getCheckedItemIds();
409 // Show the `MoveToFolderDialog` `AlertDialog` and name the instance `@string/move_to_folder
410 AppCompatDialogFragment moveToFolderDialog = new MoveToFolderDialog();
411 moveToFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.move_to_folder));
414 case R.id.edit_bookmark:
415 // Get the array of checked bookmark positions.
416 selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
418 // Get the position of the selected bookmark. Only one bookmark is selected when `edit_bookmark_down` is enabled.
419 selectedBookmarkPosition = selectedBookmarksPositionsSparseBooleanArray.keyAt(0);
421 // Move the `Cursor` to the selected position and find out if it is a folder.
422 bookmarksCursor.moveToPosition(selectedBookmarkPosition);
423 boolean isFolder = (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1);
425 // Get the selected bookmark database ID.
426 int databaseId = bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper._ID));
428 // Show the edit bookmark or edit bookmark folder dialog.
430 // Save the current folder name, which is used in `onSaveBookmarkFolder()`.
431 oldFolderNameString = bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
433 // Show the edit bookmark folder dialog.
434 AppCompatDialogFragment editFolderDialog = EditBookmarkFolderDialog.folderDatabaseId(databaseId);
435 editFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.edit_folder));
437 // Show the edit bookmark dialog.
438 AppCompatDialogFragment editBookmarkDialog = EditBookmarkDialog.bookmarkDatabaseId(databaseId);
439 editBookmarkDialog.show(getSupportFragmentManager(), getResources().getString(R.string.edit_bookmark));
443 case R.id.delete_bookmark:
444 // Set the deleting bookmarks flag, which prevents the delete menu item from being enabled until the current process finishes.
445 deletingBookmarks = true;
447 // Get an array of the selected row IDs.
448 final long[] selectedBookmarksIdsLongArray = bookmarksListView.getCheckedItemIds();
450 // Get the array of checked bookmarks. `.clone()` makes a copy that won't change if `bookmarksListView` is reloaded, which is needed for re-selecting the bookmarks on undelete.
451 selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions().clone();
453 // Update `bookmarksCursor` with the current contents of the bookmarks database except for the specified database IDs.
454 bookmarksCursor = bookmarksDatabaseHelper.getBookmarksCursorExcept(selectedBookmarksIdsLongArray, currentFolder);
456 // Update the `ListView`.
457 bookmarksCursorAdapter.changeCursor(bookmarksCursor);
459 // Show a Snackbar with the number of deleted bookmarks.
460 bookmarksDeletedSnackbar = Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), getString(R.string.bookmarks_deleted) + " " + selectedBookmarksIdsLongArray.length,
461 Snackbar.LENGTH_LONG).setAction(R.string.undo, view -> {
462 // Do nothing because everything will be handled by `onDismissed()` below.
464 .addCallback(new Snackbar.Callback() {
466 public void onDismissed(Snackbar snackbar, int event) {
468 // The user pushed the `Undo` button.
469 case Snackbar.Callback.DISMISS_EVENT_ACTION:
470 // Update `bookmarksCursor` with the current contents of the bookmarks database, including the "deleted" bookmarks.
471 bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
473 // Update the `ListView`.
474 bookmarksCursorAdapter.changeCursor(bookmarksCursor);
476 // Re-select the previously selected bookmarks.
477 for (int i = 0; i < selectedBookmarksPositionsSparseBooleanArray.size(); i++) {
478 bookmarksListView.setItemChecked(selectedBookmarksPositionsSparseBooleanArray.keyAt(i), true);
483 // The `Snackbar` was dismissed without the `Undo` button being pushed.
485 // Delete each selected bookmark.
486 for (long databaseIdLong : selectedBookmarksIdsLongArray) {
487 // Convert `databaseIdLong` to an int.
488 int databaseIdInt = (int) databaseIdLong;
490 // Delete the contents of the folder if the selected bookmark is a folder.
491 if (bookmarksDatabaseHelper.isFolder(databaseIdInt)) {
492 deleteBookmarkFolderContents(databaseIdInt);
495 // Delete the selected bookmark.
496 bookmarksDatabaseHelper.deleteBookmark(databaseIdInt);
499 // Update the display order.
500 for (int i = 0; i < bookmarksListView.getCount(); i++) {
501 // Get the database ID for the current bookmark.
502 int currentBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(i);
504 // Move `bookmarksCursor` to the current bookmark position.
505 bookmarksCursor.moveToPosition(i);
507 // Update the display order only if it is not correct in the database.
508 if (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)) != i) {
509 bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i);
514 // Enable the delete bookmarks menu item.
515 deleteBookmarksMenuItem.setEnabled(true);
517 // Reset the deleting bookmarks flag.
518 deletingBookmarks = false;
520 // Close the activity if back has been pressed.
521 if (closeActivityAfterDismissingSnackbar) {
522 // Update the bookmarks folder for the bookmarks drawer in the main WebView activity.
523 MainWebViewActivity.currentBookmarksFolder = currentFolder;
525 // Close the bookmarks drawer and reload the bookmarks ListView when returning to the main WebView activity.
526 MainWebViewActivity.restartFromBookmarksActivity = true;
528 // Return to `MainWebViewActivity`.
529 NavUtils.navigateUpFromSameTask(activity);
534 //Show the `SnackBar`.
535 bookmarksDeletedSnackbar.show();
537 // Close the `ActionBar`.
541 case R.id.context_menu_select_all_bookmarks:
542 // Get the total number of bookmarks.
543 int numberOfBookmarks = bookmarksListView.getCount();
546 for (int i = 0; i < numberOfBookmarks; i++) {
547 bookmarksListView.setItemChecked(i, true);
552 // Consume the click.
557 public void onDestroyActionMode(ActionMode mode) {
562 // Get handles for the `FloatingActionButtons`.
563 FloatingActionButton createBookmarkFolderFab = findViewById(R.id.create_bookmark_folder_fab);
564 FloatingActionButton createBookmarkFab = findViewById(R.id.create_bookmark_fab);
566 // Set the create new bookmark folder FAB to display the `AlertDialog`.
567 createBookmarkFolderFab.setOnClickListener(v -> {
568 // Show the `CreateBookmarkFolderDialog` `AlertDialog` and name the instance `@string/create_folder`.
569 AppCompatDialogFragment createBookmarkFolderDialog = new CreateBookmarkFolderDialog();
570 createBookmarkFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.create_folder));
573 // Set the create new bookmark FAB to display the `AlertDialog`.
574 createBookmarkFab.setOnClickListener(view -> {
575 // Show the `CreateBookmarkDialog` `AlertDialog` and name the instance `@string/create_bookmark`.
576 AppCompatDialogFragment createBookmarkDialog = new CreateBookmarkDialog();
577 createBookmarkDialog.show(getSupportFragmentManager(), getResources().getString(R.string.create_bookmark));
582 public boolean onCreateOptionsMenu(Menu menu) {
584 getMenuInflater().inflate(R.menu.bookmarks_options_menu, menu);
591 public boolean onOptionsItemSelected(MenuItem menuItem) {
592 // Get the ID of the menu item that was selected.
593 int menuItemId = menuItem.getItemId();
595 switch (menuItemId) {
596 case android.R.id.home: // The home arrow is identified as `android.R.id.home`, not just `R.id.home`.
597 if (currentFolder.isEmpty()) { // Currently in the home folder.
599 if ((bookmarksDeletedSnackbar != null) && bookmarksDeletedSnackbar.isShown()) { // Close the bookmarks delete snackbar before going home.
600 // Set the close flag.
601 closeActivityAfterDismissingSnackbar = true;
603 // Dismiss the snackbar.
604 bookmarksDeletedSnackbar.dismiss();
605 } else { // Go home immediately.
606 // Update the bookmarks folder for the bookmarks drawer in `MainWebViewActivity`.
607 MainWebViewActivity.currentBookmarksFolder = "";
609 // Close the bookmarks drawer and reload the bookmarks `ListView` when returning to `MainWebViewActivity`.
610 MainWebViewActivity.restartFromBookmarksActivity = true;
612 // Return to `MainWebViewActivity`.
613 NavUtils.navigateUpFromSameTask(this);
615 } else { // Currently in a subfolder.
616 // Place the former parent folder in `currentFolder`.
617 currentFolder = bookmarksDatabaseHelper.getParentFolder(currentFolder);
619 // Load the new folder.
624 case R.id.options_menu_select_all_bookmarks:
625 // Get the total number of bookmarks.
626 int numberOfBookmarks = bookmarksListView.getCount();
629 for (int i = 0; i < numberOfBookmarks; i++) {
630 bookmarksListView.setItemChecked(i, true);
634 case R.id.bookmarks_database_view:
635 // Launch `BookmarksDatabaseViewActivity`.
636 Intent bookmarksDatabaseViewIntent = new Intent(this, BookmarksDatabaseViewActivity.class);
637 startActivity(bookmarksDatabaseViewIntent);
644 public void onBackPressed() {
645 // Check to see if a snackbar is currently displayed. If so, it must be closed before exiting so that a pending delete is completed before reloading the ListView in the bookmarks drawer.
646 if ((bookmarksDeletedSnackbar != null) && bookmarksDeletedSnackbar.isShown()) { // Close the bookmarks delete snackbar before going home.
647 // Set the close flag.
648 closeActivityAfterDismissingSnackbar = true;
650 // Dismiss the snackbar.
651 bookmarksDeletedSnackbar.dismiss();
652 } else { // Go home immediately.
653 // Update the bookmarks folder for the bookmarks drawer in the main WebView activity.
654 MainWebViewActivity.currentBookmarksFolder = currentFolder;
656 // Close the bookmarks drawer and reload the bookmarks ListView when returning to the main WebView activity.
657 MainWebViewActivity.restartFromBookmarksActivity = true;
659 // Exit `BookmarksActivity`.
660 super.onBackPressed();
665 public void onCreateBookmark(AppCompatDialogFragment dialogFragment) {
666 // Get the `EditTexts` from the `dialogFragment`.
667 EditText createBookmarkNameEditText = dialogFragment.getDialog().findViewById(R.id.create_bookmark_name_edittext);
668 EditText createBookmarkUrlEditText = dialogFragment.getDialog().findViewById(R.id.create_bookmark_url_edittext);
670 // Extract the strings from the `EditTexts`.
671 String bookmarkNameString = createBookmarkNameEditText.getText().toString();
672 String bookmarkUrlString = createBookmarkUrlEditText.getText().toString();
674 // Convert the favoriteIcon Bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
675 ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
676 MainWebViewActivity.favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream);
677 byte[] favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray();
679 // Display the new bookmark below the current items in the (0 indexed) list.
680 int newBookmarkDisplayOrder = bookmarksListView.getCount();
682 // Create the bookmark.
683 bookmarksDatabaseHelper.createBookmark(bookmarkNameString, bookmarkUrlString, currentFolder, newBookmarkDisplayOrder, favoriteIconByteArray);
685 // Update `bookmarksCursor` with the current contents of this folder.
686 bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
688 // Update the `ListView`.
689 bookmarksCursorAdapter.changeCursor(bookmarksCursor);
691 // Scroll to the new bookmark.
692 bookmarksListView.setSelection(newBookmarkDisplayOrder);
696 public void onCreateBookmarkFolder(AppCompatDialogFragment dialogFragment) {
697 // Get handles for the views in `dialogFragment`.
698 EditText createFolderNameEditText = dialogFragment.getDialog().findViewById(R.id.create_folder_name_edittext);
699 RadioButton defaultFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon_radiobutton);
700 ImageView folderIconImageView = dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon);
702 // Get new folder name string.
703 String folderNameString = createFolderNameEditText.getText().toString();
705 // Get the new folder icon `Bitmap`.
706 Bitmap folderIconBitmap;
707 if (defaultFolderIconRadioButton.isChecked()) { // Use the default folder icon.
708 // Get the default folder icon and convert it to a `Bitmap`.
709 Drawable folderIconDrawable = folderIconImageView.getDrawable();
710 BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
711 folderIconBitmap = folderIconBitmapDrawable.getBitmap();
712 } else { // Use the `WebView` favorite icon.
713 folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
716 // Convert `folderIconBitmap` to a byte array. `0` is for lossless compression (the only option for a PNG).
717 ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
718 folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
719 byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
721 // Move all the bookmarks down one in the display order.
722 for (int i = 0; i < bookmarksListView.getCount(); i++) {
723 int databaseId = (int) bookmarksListView.getItemIdAtPosition(i);
724 bookmarksDatabaseHelper.updateDisplayOrder(databaseId, i + 1);
727 // Create the folder, which will be placed at the top of the `ListView`.
728 bookmarksDatabaseHelper.createFolder(folderNameString, currentFolder, folderIconByteArray);
730 // Update `bookmarksCursor` with the current contents of this folder.
731 bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
733 // Update the `ListView`.
734 bookmarksCursorAdapter.changeCursor(bookmarksCursor);
736 // Scroll to the new folder.
737 bookmarksListView.setSelection(0);
741 public void onSaveBookmark(AppCompatDialogFragment dialogFragment, int selectedBookmarkDatabaseId) {
742 // Get handles for the views from `dialogFragment`.
743 EditText editBookmarkNameEditText = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_name_edittext);
744 EditText editBookmarkUrlEditText = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_url_edittext);
745 RadioButton currentBookmarkIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_current_icon_radiobutton);
747 // Store the bookmark strings.
748 String bookmarkNameString = editBookmarkNameEditText.getText().toString();
749 String bookmarkUrlString = editBookmarkUrlEditText.getText().toString();
751 // Update the bookmark.
752 if (currentBookmarkIconRadioButton.isChecked()) { // Update the bookmark without changing the favorite icon.
753 bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString);
754 } else { // Update the bookmark using the `WebView` favorite icon.
755 // Convert the favorite icon to a byte array. `0` is for lossless compression (the only option for a PNG).
756 ByteArrayOutputStream newFavoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
757 MainWebViewActivity.favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream);
758 byte[] newFavoriteIconByteArray = newFavoriteIconByteArrayOutputStream.toByteArray();
760 // Update the bookmark and the favorite icon.
761 bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString, newFavoriteIconByteArray);
764 // Close the contextual action mode.
765 contextualActionMode.finish();
767 // Update `bookmarksCursor` with the contents of the current folder.
768 bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
770 // Update the `ListView`.
771 bookmarksCursorAdapter.changeCursor(bookmarksCursor);
775 public void onSaveBookmarkFolder(AppCompatDialogFragment dialogFragment, int selectedFolderDatabaseId) {
776 // Get handles for the views from `dialogFragment`.
777 RadioButton currentFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_folder_current_icon_radiobutton);
778 RadioButton defaultFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_radiobutton);
779 ImageView defaultFolderIconImageView = dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_imageview);
780 EditText editFolderNameEditText = dialogFragment.getDialog().findViewById(R.id.edit_folder_name_edittext);
782 // Get the new folder name.
783 String newFolderNameString = editFolderNameEditText.getText().toString();
785 // Check if the favorite icon has changed.
786 if (currentFolderIconRadioButton.isChecked()) { // Only the name has changed.
787 // Update the name in the database.
788 bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString);
789 } else if (!currentFolderIconRadioButton.isChecked() && newFolderNameString.equals(oldFolderNameString)) { // Only the icon has changed.
790 // Get the new folder icon `Bitmap`.
791 Bitmap folderIconBitmap;
792 if (defaultFolderIconRadioButton.isChecked()) {
793 // Get the default folder icon and convert it to a `Bitmap`.
794 Drawable folderIconDrawable = defaultFolderIconImageView.getDrawable();
795 BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
796 folderIconBitmap = folderIconBitmapDrawable.getBitmap();
797 } else { // Use the `WebView` favorite icon.
798 folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
801 // Convert the folder `Bitmap` to a byte array. `0` is for lossless compression (the only option for a PNG).
802 ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
803 folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
804 byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
806 // Update the folder icon in the database.
807 bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, folderIconByteArray);
808 } else { // The folder icon and the name have changed.
809 // Instantiate the new folder icon `Bitmap`.
810 Bitmap folderIconBitmap;
812 // Populate the new folder icon bitmap.
813 if (defaultFolderIconRadioButton.isChecked()) {
814 // Get the default folder icon and convert it to a `Bitmap`.
815 Drawable folderIconDrawable = defaultFolderIconImageView.getDrawable();
816 BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
817 folderIconBitmap = folderIconBitmapDrawable.getBitmap();
818 } else { // Use the `WebView` favorite icon.
819 folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
822 // Convert the folder `Bitmap` to a byte array. `0` is for lossless compression (the only option for a PNG).
823 ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
824 folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
825 byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
827 // Update the folder name and icon in the database.
828 bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString, folderIconByteArray);
831 // Update `bookmarksCursor` with the current contents of this folder.
832 bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
834 // Update the `ListView`.
835 bookmarksCursorAdapter.changeCursor(bookmarksCursor);
837 // Close the contextual action mode.
838 contextualActionMode.finish();
842 public void onMoveToFolder(AppCompatDialogFragment dialogFragment) {
843 // Get a handle for the `ListView` from `dialogFragment`.
844 ListView folderListView = dialogFragment.getDialog().findViewById(R.id.move_to_folder_listview);
846 // Store a long array of the selected folders.
847 long[] newFolderLongArray = folderListView.getCheckedItemIds();
849 // Get the new folder database ID. Only one folder will be selected.
850 int newFolderDatabaseId = (int) newFolderLongArray[0];
852 // Instantiate `newFolderName`.
853 String newFolderName;
855 // Set the new folder name.
856 if (newFolderDatabaseId == 0) {
857 // The new folder is the home folder, represented as `""` in the database.
860 // Get the new folder name from the database.
861 newFolderName = bookmarksDatabaseHelper.getFolderName(newFolderDatabaseId);
864 // Get a long array with the the database ID of the selected bookmarks.
865 long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
867 // Move each of the selected bookmarks to the new folder.
868 for (long databaseIdLong : selectedBookmarksLongArray) {
869 // Get `databaseIdInt` for each selected bookmark.
870 int databaseIdInt = (int) databaseIdLong;
872 // Move the selected bookmark to the new folder.
873 bookmarksDatabaseHelper.moveToFolder(databaseIdInt, newFolderName);
876 // Update `bookmarksCursor` with the current contents of this folder.
877 bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
879 // Update the `ListView`.
880 bookmarksCursorAdapter.changeCursor(bookmarksCursor);
882 // Close the contextual app bar.
883 contextualActionMode.finish();
886 private void deleteBookmarkFolderContents(int databaseId) {
887 // Get the name of the folder.
888 String folderName = bookmarksDatabaseHelper.getFolderName(databaseId);
890 // Get the contents of the folder.
891 Cursor folderCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(folderName);
893 // Delete each of the bookmarks in the folder.
894 for (int i = 0; i < folderCursor.getCount(); i++) {
895 // Move `folderCursor` to the current row.
896 folderCursor.moveToPosition(i);
898 // Get the database ID of the item.
899 int itemDatabaseId = folderCursor.getInt(folderCursor.getColumnIndex(BookmarksDatabaseHelper._ID));
901 // If this is a folder, recursively delete the contents first.
902 if (bookmarksDatabaseHelper.isFolder(itemDatabaseId)) {
903 deleteBookmarkFolderContents(itemDatabaseId);
906 // Delete the bookmark.
907 bookmarksDatabaseHelper.deleteBookmark(itemDatabaseId);
911 private void updateMoveIcons() {
912 // Get a long array of the selected bookmarks.
913 long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
915 // Get the database IDs for the first, last, and selected bookmarks.
916 int selectedBookmarkDatabaseId = (int) selectedBookmarksLongArray[0];
917 int firstBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(0);
918 // bookmarksListView is 0 indexed.
919 int lastBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(bookmarksListView.getCount() - 1);
921 // Update the move bookmark up `MenuItem`.
922 if (selectedBookmarkDatabaseId == firstBookmarkDatabaseId) { // The selected bookmark is in the first position.
923 // Disable the move bookmark up `MenuItem`.
924 moveBookmarkUpMenuItem.setEnabled(false);
926 // Set the move bookmark up icon to be ghosted.
927 moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_disabled);
928 } else { // The selected bookmark is not in the first position.
929 // Enable the move bookmark up `MenuItem`.
930 moveBookmarkUpMenuItem.setEnabled(true);
932 // Set the icon according to the theme.
933 if (MainWebViewActivity.darkTheme) {
934 moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_enabled_dark);
936 moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_enabled_light);
940 // Update the move bookmark down `MenuItem`.
941 if (selectedBookmarkDatabaseId == lastBookmarkDatabaseId) { // The selected bookmark is in the last position.
942 // Disable the move bookmark down `MenuItem`.
943 moveBookmarkDownMenuItem.setEnabled(false);
945 // Set the move bookmark down icon to be ghosted.
946 moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_disabled);
947 } else { // The selected bookmark is not in the last position.
948 // Enable the move bookmark down `MenuItem`.
949 moveBookmarkDownMenuItem.setEnabled(true);
951 // Set the icon according to the theme.
952 if (MainWebViewActivity.darkTheme) {
953 moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_enabled_dark);
955 moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_enabled_light);
960 private void scrollBookmarks(int selectedBookmarkPosition) {
961 // Get the first and last visible bookmark positions.
962 int firstVisibleBookmarkPosition = bookmarksListView.getFirstVisiblePosition();
963 int lastVisibleBookmarkPosition = bookmarksListView.getLastVisiblePosition();
965 // Calculate the number of bookmarks per screen.
966 int numberOfBookmarksPerScreen = lastVisibleBookmarkPosition - firstVisibleBookmarkPosition;
968 // Scroll with the moved bookmark if necessary.
969 if (selectedBookmarkPosition <= firstVisibleBookmarkPosition) { // The selected bookmark position is at or above the top of the screen.
970 // Scroll to the selected bookmark position.
971 bookmarksListView.setSelection(selectedBookmarkPosition);
972 } else if (selectedBookmarkPosition >= (lastVisibleBookmarkPosition - 1)) { // The selected bookmark is at or below the bottom of the screen. The `-1` handles partial bookmarks displayed at the bottom of the `ListView`.
973 // Scroll to display the selected bookmark at the bottom of the screen. `+1` assured that the entire bookmark will be displayed in situations where only a partial bookmark fits at the bottom of the `ListView`.
974 bookmarksListView.setSelection(selectedBookmarkPosition - numberOfBookmarksPerScreen + 1);
978 private void loadFolder() {
979 // Update `bookmarksCursor` with the contents of the bookmarks database for the current folder.
980 bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
982 // Setup a `CursorAdapter`. `this` specifies the `Context`. `false` disables `autoRequery`.
983 bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) {
985 public View newView(Context context, Cursor cursor, ViewGroup parent) {
986 // Inflate the individual item layout. `false` does not attach it to the root.
987 return getLayoutInflater().inflate(R.layout.bookmarks_activity_item_linearlayout, parent, false);
991 public void bindView(View view, Context context, Cursor cursor) {
992 // Get handles for the views.
993 ImageView bookmarkFavoriteIcon = view.findViewById(R.id.bookmark_favorite_icon);
994 TextView bookmarkNameTextView = view.findViewById(R.id.bookmark_name);
996 // Get the favorite icon byte array from the `Cursor`.
997 byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON));
999 // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last.
1000 Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length);
1002 // Display the bitmap in `bookmarkFavoriteIcon`.
1003 bookmarkFavoriteIcon.setImageBitmap(favoriteIconBitmap);
1005 // Get the bookmark name from the cursor and display it in `bookmarkNameTextView`.
1006 String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
1007 bookmarkNameTextView.setText(bookmarkNameString);
1009 // Make the font bold for folders.
1010 if (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) {
1011 bookmarkNameTextView.setTypeface(Typeface.DEFAULT_BOLD);
1012 } else { // Reset the font to default for normal bookmarks.
1013 bookmarkNameTextView.setTypeface(Typeface.DEFAULT);
1018 // Populate the `ListView` with the adapter.
1019 bookmarksListView.setAdapter(bookmarksCursorAdapter);
1021 // Set the `AppBar` title.
1022 if (currentFolder.isEmpty()) {
1023 appBar.setTitle(R.string.bookmarks);
1025 appBar.setTitle(currentFolder);
1030 public void onDestroy() {
1031 // Close the bookmarks cursor and database.
1032 bookmarksCursor.close();
1033 bookmarksDatabaseHelper.close();
1035 // Run the default commands.