+ @Override
+ public void onEditBookmarkCancel(DialogFragment editBookmarkDialogFragment) {
+ // Do nothing because the user selected `Cancel`.
+ }
+
+ @Override
+ public void onEditBookmarkSave(DialogFragment editBookmarkDialogFragment) {
+ // Get the `EditText`s from the `editBookmarkDialogFragment` and extract the strings.
+ EditText editBookmarkNameEditText = (EditText) editBookmarkDialogFragment.getDialog().findViewById(R.id.edit_bookmark_name_edittext);
+ String bookmarkNameString = editBookmarkNameEditText.getText().toString();
+ EditText editBookmarkUrlEditText = (EditText) editBookmarkDialogFragment.getDialog().findViewById(R.id.edit_bookmark_url_edittext);
+ String bookmarkUrlString = editBookmarkUrlEditText.getText().toString();
+
+ CheckBox useNewFavoriteIconBitmap = (CheckBox) editBookmarkDialogFragment.getDialog().findViewById(R.id.edit_bookmark_use_new_favorite_icon_checkbox);
+ byte[] favoriteIconByteArray;
+
+ // Get a long array with the the databaseId of the selected bookmark and convert it to an `int`.
+ long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
+ int selectedBookmarkDatabaseId = (int) selectedBookmarksLongArray[0];
+
+ if (useNewFavoriteIconBitmap.isChecked()) {
+ ImageView newFavoriteIconImageView = (ImageView) editBookmarkDialogFragment.getDialog().findViewById(R.id.edit_bookmark_new_favorite_icon);
+ Drawable favoriteIconDrawable = newFavoriteIconImageView.getDrawable();
+ Bitmap favoriteIconBitmap = ((BitmapDrawable) favoriteIconDrawable).getBitmap();
+ ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
+ favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream);
+ favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray();
+ bookmarksDatabaseHandler.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString, favoriteIconByteArray);
+
+ } else {
+ // Update the bookmark.
+ bookmarksDatabaseHandler.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString);
+ }
+
+ contextualActionMode.finish();
+
+ // Refresh the `ListView`.
+ updateBookmarksListView();
+ }
+