@Override
public void onCreateBookmark(DialogFragment dialogFragment) {
- // Get the `EditTexts` from the `dialogFragment`.
+ // Get the views from the dialog fragment.
EditText createBookmarkNameEditText = dialogFragment.getDialog().findViewById(R.id.create_bookmark_name_edittext);
EditText createBookmarkUrlEditText = dialogFragment.getDialog().findViewById(R.id.create_bookmark_url_edittext);
- // Extract the strings from the `EditTexts`.
+ // Extract the strings from the edit texts.
String bookmarkNameString = createBookmarkNameEditText.getText().toString();
String bookmarkUrlString = createBookmarkUrlEditText.getText().toString();
- // Convert the favoriteIcon Bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
+ // Get a copy of the favorite icon bitmap.
+ Bitmap favoriteIcon = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((favoriteIcon.getHeight() > 256) || (favoriteIcon.getWidth() > 256)) {
+ favoriteIcon = Bitmap.createScaledBitmap(favoriteIcon, 256, 256, true);
+ }
+
+ // Create a favorite icon byte array output stream.
ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
- MainWebViewActivity.favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream);
+
+ // Convert the favorite icon bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
+ favoriteIcon.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream);
+
+ // Convert the favorite icon byte array stream to a byte array.
byte[] favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray();
// Display the new bookmark below the current items in the (0 indexed) list.
@Override
public void onCreateBookmarkFolder(DialogFragment dialogFragment) {
- // Get handles for the views in `dialogFragment`.
+ // Get handles for the views in the dialog fragment.
EditText createFolderNameEditText = dialogFragment.getDialog().findViewById(R.id.create_folder_name_edittext);
RadioButton defaultFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon_radiobutton);
ImageView folderIconImageView = dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon);
// Get new folder name string.
String folderNameString = createFolderNameEditText.getText().toString();
- // Get the new folder icon bitmap.
+ // Create a folder icon bitmap.
Bitmap folderIconBitmap;
+
+ // Set the folder icon bitmap according to the dialog.
if (defaultFolderIconRadioButton.isChecked()) { // Use the default folder icon.
- // Get the default folder icon and convert it to a bitmap.
+ // Get the default folder icon drawable.
Drawable folderIconDrawable = folderIconImageView.getDrawable();
+
+ // Convert the folder icon drawable to a bitmap drawable.
BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
+
+ // Convert the folder icon bitmap drawable to a bitmap.
folderIconBitmap = folderIconBitmapDrawable.getBitmap();
- } else { // Use the `WebView` favorite icon.
+ } else { // Use the WebView favorite icon.
+ // Get a copy of the favorite icon bitmap.
folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the folder icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((folderIconBitmap.getHeight() > 256) || (folderIconBitmap.getWidth() > 256)) {
+ folderIconBitmap = Bitmap.createScaledBitmap(folderIconBitmap, 256, 256, true);
+ }
}
- // Convert `folderIconBitmap` to a byte array. `0` is for lossless compression (the only option for a PNG).
+ // Create a folder icon byte array output stream.
ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
+
+ // Convert the folder icon bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
+
+ // Convert the folder icon byte array stream to a byte array.
byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
// Move all the bookmarks down one in the display order.
if (currentBookmarkIconRadioButton.isChecked()) { // Update the bookmark without changing the favorite icon.
bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString);
} else { // Update the bookmark using the `WebView` favorite icon.
- // Convert the favorite icon to a byte array. `0` is for lossless compression (the only option for a PNG).
+ // Get a copy of the favorite icon bitmap.
+ Bitmap favoriteIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((favoriteIconBitmap.getHeight() > 256) || (favoriteIconBitmap.getWidth() > 256)) {
+ favoriteIconBitmap = Bitmap.createScaledBitmap(favoriteIconBitmap, 256, 256, true);
+ }
+
+ // Create a favorite icon byte array output stream.
ByteArrayOutputStream newFavoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
- MainWebViewActivity.favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream);
+
+ // Convert the favorite icon bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
+ favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream);
+
+ // Convert the favorite icon byte array stream to a byte array.
byte[] newFavoriteIconByteArray = newFavoriteIconByteArrayOutputStream.toByteArray();
// Update the bookmark and the favorite icon.
// Update the name in the database.
bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString);
} else if (!currentFolderIconRadioButton.isChecked() && newFolderNameString.equals(oldFolderNameString)) { // Only the icon has changed.
- // Get the new folder icon `Bitmap`.
+ // Create the new folder icon Bitmap.
Bitmap folderIconBitmap;
+
+ // Populate the new folder icon bitmap.
if (defaultFolderIconRadioButton.isChecked()) {
- // Get the default folder icon and convert it to a `Bitmap`.
+ // Get the default folder icon drawable.
Drawable folderIconDrawable = defaultFolderIconImageView.getDrawable();
+
+ // Convert the folder icon drawable to a bitmap drawable.
BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
+
+ // Convert the folder icon bitmap drawable to a bitmap.
folderIconBitmap = folderIconBitmapDrawable.getBitmap();
- } else { // Use the `WebView` favorite icon.
+ } else { // Use the WebView favorite icon.
+ // Get a copy of the favorite icon bitmap.
folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the folder icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((folderIconBitmap.getHeight() > 256) || (folderIconBitmap.getWidth() > 256)) {
+ folderIconBitmap = Bitmap.createScaledBitmap(folderIconBitmap, 256, 256, true);
+ }
}
- // Convert the folder `Bitmap` to a byte array. `0` is for lossless compression (the only option for a PNG).
- ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
- folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
- byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
+ // Create a folder icon byte array output stream.
+ ByteArrayOutputStream newFolderIconByteArrayOutputStream = new ByteArrayOutputStream();
+
+ // Convert the folder icon bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
+ folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFolderIconByteArrayOutputStream);
+
+ // Convert the folder icon byte array stream to a byte array.
+ byte[] newFolderIconByteArray = newFolderIconByteArrayOutputStream.toByteArray();
// Update the folder icon in the database.
- bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, folderIconByteArray);
+ bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, newFolderIconByteArray);
} else { // The folder icon and the name have changed.
// Instantiate the new folder icon `Bitmap`.
Bitmap folderIconBitmap;
// Populate the new folder icon bitmap.
if (defaultFolderIconRadioButton.isChecked()) {
- // Get the default folder icon and convert it to a `Bitmap`.
+ // Get the default folder icon drawable.
Drawable folderIconDrawable = defaultFolderIconImageView.getDrawable();
+
+ // Convert the folder icon drawable to a bitmap drawable.
BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
+
+ // Convert the folder icon bitmap drawable to a bitmap.
folderIconBitmap = folderIconBitmapDrawable.getBitmap();
- } else { // Use the `WebView` favorite icon.
+ } else { // Use the WebView favorite icon.
+ // Get a copy of the favorite icon bitmap.
folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the folder icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((folderIconBitmap.getHeight() > 256) || (folderIconBitmap.getWidth() > 256)) {
+ folderIconBitmap = Bitmap.createScaledBitmap(folderIconBitmap, 256, 256, true);
+ }
}
- // Convert the folder `Bitmap` to a byte array. `0` is for lossless compression (the only option for a PNG).
- ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
- folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
- byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
+ // Create a folder icon byte array output stream.
+ ByteArrayOutputStream newFolderIconByteArrayOutputStream = new ByteArrayOutputStream();
+
+ // Convert the folder icon bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
+ folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFolderIconByteArrayOutputStream);
+
+ // Convert the folder icon byte array stream to a byte array.
+ byte[] newFolderIconByteArray = newFolderIconByteArrayOutputStream.toByteArray();
// Update the folder name and icon in the database.
- bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString, folderIconByteArray);
+ bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString, newFolderIconByteArray);
}
// Update the bookmarks cursor with the current contents of this folder.
if (currentBookmarkIconRadioButton.isChecked()) { // Update the bookmark without changing the favorite icon.
bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString, parentFolderNameString, displayOrderInt);
} else { // Update the bookmark using the `WebView` favorite icon.
- // Convert the favorite icon to a byte array. `0` is for lossless compression (the only option for a PNG).
+ // Get a copy of the favorite icon bitmap.
+ Bitmap favoriteIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((favoriteIconBitmap.getHeight() > 256) || (favoriteIconBitmap.getWidth() > 256)) {
+ favoriteIconBitmap = Bitmap.createScaledBitmap(favoriteIconBitmap, 256, 256, true);
+ }
+
+ // Create a favorite icon byte array output stream.
ByteArrayOutputStream newFavoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
- MainWebViewActivity.favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream);
+
+ // Convert the favorite icon bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
+ favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream);
+
+ // Convert the favorite icon byte array stream to a byte array.
byte[] newFavoriteIconByteArray = newFavoriteIconByteArrayOutputStream.toByteArray();
// Update the bookmark and the favorite icon.
if (currentBookmarkIconRadioButton.isChecked()) { // Update the folder without changing the favorite icon.
bookmarksDatabaseHelper.updateFolder(selectedBookmarkDatabaseId, oldFolderNameString, newFolderNameString, parentFolderNameString, displayOrderInt);
} else { // Update the folder and the icon.
- // Instantiate the new folder icon `Bitmap`.
+ // Create the new folder icon Bitmap.
Bitmap folderIconBitmap;
// Populate the new folder icon bitmap.
if (defaultFolderIconRadioButton.isChecked()) {
- // Get the default folder icon and convert it to a `Bitmap`.
+ // Get the default folder icon drawable.
Drawable folderIconDrawable = defaultFolderIconImageView.getDrawable();
+
+ // Convert the folder icon drawable to a bitmap drawable.
BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
+
+ // Convert the folder icon bitmap drawable to a bitmap.
folderIconBitmap = folderIconBitmapDrawable.getBitmap();
} else { // Use the `WebView` favorite icon.
+ // Get a copy of the favorite icon bitmap.
folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the folder icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((folderIconBitmap.getHeight() > 256) || (folderIconBitmap.getWidth() > 256)) {
+ folderIconBitmap = Bitmap.createScaledBitmap(folderIconBitmap, 256, 256, true);
+ }
}
- // Convert the folder icon to a byte array. `0` is for lossless compression (the only option for a PNG).
+ // Create a folder icon byte array output stream.
ByteArrayOutputStream newFolderIconByteArrayOutputStream = new ByteArrayOutputStream();
+
+ // Convert the folder icon bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFolderIconByteArrayOutputStream);
+
+ // Convert the folder icon byte array stream to a byte array.
byte[] newFolderIconByteArray = newFolderIconByteArrayOutputStream.toByteArray();
// Update the folder and the icon.
@Override
public void onCreateBookmark(DialogFragment dialogFragment) {
- // Get the `EditTexts` from the `dialogFragment`.
+ // Get the views from the dialog fragment.
EditText createBookmarkNameEditText = dialogFragment.getDialog().findViewById(R.id.create_bookmark_name_edittext);
EditText createBookmarkUrlEditText = dialogFragment.getDialog().findViewById(R.id.create_bookmark_url_edittext);
- // Extract the strings from the `EditTexts`.
+ // Extract the strings from the edit texts.
String bookmarkNameString = createBookmarkNameEditText.getText().toString();
String bookmarkUrlString = createBookmarkUrlEditText.getText().toString();
- // Convert the favoriteIcon Bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
+ // Get a copy of the favorite icon bitmap.
+ Bitmap favoriteIcon = favoriteIconBitmap;
+
+ // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((favoriteIcon.getHeight() > 256) || (favoriteIcon.getWidth() > 256)) {
+ favoriteIcon = Bitmap.createScaledBitmap(favoriteIcon, 256, 256, true);
+ }
+
+ // Create a favorite icon byte array output stream.
ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
- favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream);
+
+ // Convert the favorite icon bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
+ favoriteIcon.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream);
+
+ // Convert the favorite icon byte array stream to a byte array.
byte[] favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray();
// Display the new bookmark below the current items in the (0 indexed) list.
// Update the bookmarks cursor with the current contents of this folder.
bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentBookmarksFolder);
- // Update the `ListView`.
+ // Update the list view.
bookmarksCursorAdapter.changeCursor(bookmarksCursor);
// Scroll to the new bookmark.
@Override
public void onCreateBookmarkFolder(DialogFragment dialogFragment) {
- // Get handles for the views in `dialogFragment`.
+ // Get handles for the views in the dialog fragment.
EditText createFolderNameEditText = dialogFragment.getDialog().findViewById(R.id.create_folder_name_edittext);
RadioButton defaultFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon_radiobutton);
ImageView folderIconImageView = dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon);
// Get new folder name string.
String folderNameString = createFolderNameEditText.getText().toString();
- // Get the new folder icon `Bitmap`.
+ // Create a folder icon bitmap.
Bitmap folderIconBitmap;
+
+ // Set the folder icon bitmap according to the dialog.
if (defaultFolderIconRadioButton.isChecked()) { // Use the default folder icon.
- // Get the default folder icon and convert it to a `Bitmap`.
+ // Get the default folder icon drawable.
Drawable folderIconDrawable = folderIconImageView.getDrawable();
+
+ // Convert the folder icon drawable to a bitmap drawable.
BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
+
+ // Convert the folder icon bitmap drawable to a bitmap.
folderIconBitmap = folderIconBitmapDrawable.getBitmap();
- } else { // Use the `WebView` favorite icon.
+ } else { // Use the WebView favorite icon.
+ // Get a copy of the favorite icon bitmap.
folderIconBitmap = favoriteIconBitmap;
+
+ // Scale the folder icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((folderIconBitmap.getHeight() > 256) || (folderIconBitmap.getWidth() > 256)) {
+ folderIconBitmap = Bitmap.createScaledBitmap(folderIconBitmap, 256, 256, true);
+ }
}
- // Convert `folderIconBitmap` to a byte array. `0` is for lossless compression (the only option for a PNG).
+ // Create a folder icon byte array output stream.
ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
+
+ // Convert the folder icon bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
+
+ // Convert the folder icon byte array stream to a byte array.
byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
// Move all the bookmarks down one in the display order.
bookmarksListView.setSelection(0);
}
+ @Override
+ public void onSaveBookmark(DialogFragment dialogFragment, int selectedBookmarkDatabaseId) {
+ // Get handles for the views from `dialogFragment`.
+ EditText editBookmarkNameEditText = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_name_edittext);
+ EditText editBookmarkUrlEditText = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_url_edittext);
+ RadioButton currentBookmarkIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_current_icon_radiobutton);
+
+ // Store the bookmark strings.
+ String bookmarkNameString = editBookmarkNameEditText.getText().toString();
+ String bookmarkUrlString = editBookmarkUrlEditText.getText().toString();
+
+ // Update the bookmark.
+ if (currentBookmarkIconRadioButton.isChecked()) { // Update the bookmark without changing the favorite icon.
+ bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString);
+ } else { // Update the bookmark using the `WebView` favorite icon.
+ // Get a copy of the favorite icon bitmap.
+ Bitmap favoriteIcon = favoriteIconBitmap;
+
+ // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((favoriteIcon.getHeight() > 256) || (favoriteIcon.getWidth() > 256)) {
+ favoriteIcon = Bitmap.createScaledBitmap(favoriteIcon, 256, 256, true);
+ }
+
+ // Create a favorite icon byte array output stream.
+ ByteArrayOutputStream newFavoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
+
+ // Convert the favorite icon bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
+ favoriteIcon.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream);
+
+ // Convert the favorite icon byte array stream to a byte array.
+ byte[] newFavoriteIconByteArray = newFavoriteIconByteArrayOutputStream.toByteArray();
+
+ // Update the bookmark and the favorite icon.
+ bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString, newFavoriteIconByteArray);
+ }
+
+ // Update the bookmarks cursor with the current contents of this folder.
+ bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentBookmarksFolder);
+
+ // Update the list view.
+ bookmarksCursorAdapter.changeCursor(bookmarksCursor);
+ }
+
+ @Override
+ public void onSaveBookmarkFolder(DialogFragment dialogFragment, int selectedFolderDatabaseId) {
+ // Get handles for the views from `dialogFragment`.
+ EditText editFolderNameEditText = dialogFragment.getDialog().findViewById(R.id.edit_folder_name_edittext);
+ RadioButton currentFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_folder_current_icon_radiobutton);
+ RadioButton defaultFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_radiobutton);
+ ImageView defaultFolderIconImageView = dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_imageview);
+
+ // Get the new folder name.
+ String newFolderNameString = editFolderNameEditText.getText().toString();
+
+ // Check if the favorite icon has changed.
+ if (currentFolderIconRadioButton.isChecked()) { // Only the name has changed.
+ // Update the name in the database.
+ bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString);
+ } else if (!currentFolderIconRadioButton.isChecked() && newFolderNameString.equals(oldFolderNameString)) { // Only the icon has changed.
+ // Create the new folder icon Bitmap.
+ Bitmap folderIconBitmap;
+
+ // Populate the new folder icon bitmap.
+ if (defaultFolderIconRadioButton.isChecked()) {
+ // Get the default folder icon drawable.
+ Drawable folderIconDrawable = defaultFolderIconImageView.getDrawable();
+
+ // Convert the folder icon drawable to a bitmap drawable.
+ BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
+
+ // Convert the folder icon bitmap drawable to a bitmap.
+ folderIconBitmap = folderIconBitmapDrawable.getBitmap();
+ } else { // Use the `WebView` favorite icon.
+ // Get a copy of the favorite icon bitmap.
+ folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the folder icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((folderIconBitmap.getHeight() > 256) || (folderIconBitmap.getWidth() > 256)) {
+ folderIconBitmap = Bitmap.createScaledBitmap(folderIconBitmap, 256, 256, true);
+ }
+ }
+
+ // Create a folder icon byte array output stream.
+ ByteArrayOutputStream newFolderIconByteArrayOutputStream = new ByteArrayOutputStream();
+
+ // Convert the folder icon bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
+ folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFolderIconByteArrayOutputStream);
+
+ // Convert the folder icon byte array stream to a byte array.
+ byte[] newFolderIconByteArray = newFolderIconByteArrayOutputStream.toByteArray();
+
+ // Update the folder icon in the database.
+ bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, newFolderIconByteArray);
+ } else { // The folder icon and the name have changed.
+ // Get the new folder icon `Bitmap`.
+ Bitmap folderIconBitmap;
+ if (defaultFolderIconRadioButton.isChecked()) {
+ // Get the default folder icon drawable.
+ Drawable folderIconDrawable = defaultFolderIconImageView.getDrawable();
+
+ // Convert the folder icon drawable to a bitmap drawable.
+ BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
+
+ // Convert the folder icon bitmap drawable to a bitmap.
+ folderIconBitmap = folderIconBitmapDrawable.getBitmap();
+ } else { // Use the `WebView` favorite icon.
+ // Get a copy of the favorite icon bitmap.
+ folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the folder icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((folderIconBitmap.getHeight() > 256) || (folderIconBitmap.getWidth() > 256)) {
+ folderIconBitmap = Bitmap.createScaledBitmap(folderIconBitmap, 256, 256, true);
+ }
+ }
+
+ // Create a folder icon byte array output stream.
+ ByteArrayOutputStream newFolderIconByteArrayOutputStream = new ByteArrayOutputStream();
+
+ // Convert the folder icon bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
+ folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFolderIconByteArrayOutputStream);
+
+ // Convert the folder icon byte array stream to a byte array.
+ byte[] newFolderIconByteArray = newFolderIconByteArrayOutputStream.toByteArray();
+
+ // Update the folder name and icon in the database.
+ bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString, newFolderIconByteArray);
+ }
+
+ // Update the bookmarks cursor with the current contents of this folder.
+ bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentBookmarksFolder);
+
+ // Update the `ListView`.
+ bookmarksCursorAdapter.changeCursor(bookmarksCursor);
+ }
+
@Override
public void onCloseDownloadLocationPermissionDialog(int downloadType) {
switch (downloadType) {
}
}
- @Override
- public void onSaveBookmark(DialogFragment dialogFragment, int selectedBookmarkDatabaseId) {
- // Get handles for the views from `dialogFragment`.
- EditText editBookmarkNameEditText = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_name_edittext);
- EditText editBookmarkUrlEditText = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_url_edittext);
- RadioButton currentBookmarkIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_current_icon_radiobutton);
-
- // Store the bookmark strings.
- String bookmarkNameString = editBookmarkNameEditText.getText().toString();
- String bookmarkUrlString = editBookmarkUrlEditText.getText().toString();
-
- // Update the bookmark.
- if (currentBookmarkIconRadioButton.isChecked()) { // Update the bookmark without changing the favorite icon.
- bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString);
- } else { // Update the bookmark using the `WebView` favorite icon.
- // Convert the favorite icon to a byte array. `0` is for lossless compression (the only option for a PNG).
- ByteArrayOutputStream newFavoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
- favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream);
- byte[] newFavoriteIconByteArray = newFavoriteIconByteArrayOutputStream.toByteArray();
-
- // Update the bookmark and the favorite icon.
- bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString, newFavoriteIconByteArray);
- }
-
- // Update the bookmarks cursor with the current contents of this folder.
- bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentBookmarksFolder);
-
- // Update the `ListView`.
- bookmarksCursorAdapter.changeCursor(bookmarksCursor);
- }
-
- @Override
- public void onSaveBookmarkFolder(DialogFragment dialogFragment, int selectedFolderDatabaseId) {
- // Get handles for the views from `dialogFragment`.
- EditText editFolderNameEditText = dialogFragment.getDialog().findViewById(R.id.edit_folder_name_edittext);
- RadioButton currentFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_folder_current_icon_radiobutton);
- RadioButton defaultFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_radiobutton);
- ImageView folderIconImageView = dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_imageview);
-
- // Get the new folder name.
- String newFolderNameString = editFolderNameEditText.getText().toString();
-
- // Check if the favorite icon has changed.
- if (currentFolderIconRadioButton.isChecked()) { // Only the name has changed.
- // Update the name in the database.
- bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString);
- } else if (!currentFolderIconRadioButton.isChecked() && newFolderNameString.equals(oldFolderNameString)) { // Only the icon has changed.
- // Get the new folder icon `Bitmap`.
- Bitmap folderIconBitmap;
- if (defaultFolderIconRadioButton.isChecked()) {
- // Get the default folder icon and convert it to a `Bitmap`.
- Drawable folderIconDrawable = folderIconImageView.getDrawable();
- BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
- folderIconBitmap = folderIconBitmapDrawable.getBitmap();
- } else { // Use the `WebView` favorite icon.
- folderIconBitmap = favoriteIconBitmap;
- }
-
- // Convert the folder `Bitmap` to a byte array. `0` is for lossless compression (the only option for a PNG).
- ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
- folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
- byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
-
- // Update the folder icon in the database.
- bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, folderIconByteArray);
- } else { // The folder icon and the name have changed.
- // Get the new folder icon `Bitmap`.
- Bitmap folderIconBitmap;
- if (defaultFolderIconRadioButton.isChecked()) {
- // Get the default folder icon and convert it to a `Bitmap`.
- Drawable folderIconDrawable = folderIconImageView.getDrawable();
- BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
- folderIconBitmap = folderIconBitmapDrawable.getBitmap();
- } else { // Use the `WebView` favorite icon.
- folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
- }
-
- // Convert the folder `Bitmap` to a byte array. `0` is for lossless compression (the only option for a PNG).
- ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
- folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
- byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
-
- // Update the folder name and icon in the database.
- bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString, folderIconByteArray);
- }
-
- // Update the bookmarks cursor with the current contents of this folder.
- bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentBookmarksFolder);
-
- // Update the `ListView`.
- bookmarksCursorAdapter.changeCursor(bookmarksCursor);
- }
-
@Override
public void onHttpAuthenticationCancel() {
// Cancel the `HttpAuthHandler`.
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
+ // Get a copy of the favorite icon bitmap.
+ Bitmap favoriteIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((favoriteIconBitmap.getHeight() > 256) || (favoriteIconBitmap.getWidth() > 256)) {
+ favoriteIconBitmap = Bitmap.createScaledBitmap(favoriteIconBitmap, 256, 256, true);
+ }
+
// Create a drawable version of the favorite icon.
- Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebViewActivity.favoriteIconBitmap);
+ Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), favoriteIconBitmap);
- // Use `AlertDialog.Builder` to create the `AlertDialog`.
+ // Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
// Set the style according to the theme.
// Show the keyboard when the `AlertDialog` is displayed on the screen.
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
- // The `AlertDialog` needs to be shown before `setOnKeyListener()` can be called.
+ // The alert dialog needs to be shown before `setOnKeyListener()` can be called.
alertDialog.show();
// Get a handle for `create_bookmark_name_edittext`.
}
});
- // `onCreateDialog()` requires the return of an `AlertDialog`.
+ // Return the alert dialog.
return alertDialog;
}
}
\ No newline at end of file
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
+import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
// Remove the warning below that `getLayoutInflater()` might be null.
assert getActivity() != null;
- // Set the view. The parent view is `null` because it will be assigned by the `AlertDialog`.
+ // Set the view. The parent view is null because it will be assigned by the alert dialog.
dialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.create_bookmark_folder_dialog, null));
// Set an `onClick()` listener for the negative button.
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
- // Show the keyboard when the `Dialog` is displayed on the screen.
- alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
-
// The alert dialog must be shown before items in the alert dialog can be modified.
alertDialog.show();
}
});
+ // Get a copy of the favorite icon bitmap.
+ Bitmap favoriteIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((favoriteIconBitmap.getHeight() > 256) || (favoriteIconBitmap.getWidth() > 256)) {
+ favoriteIconBitmap = Bitmap.createScaledBitmap(favoriteIconBitmap, 256, 256, true);
+ }
+
// Display the current favorite icon.
- webPageIconImageView.setImageBitmap(MainWebViewActivity.favoriteIconBitmap);
+ webPageIconImageView.setImageBitmap(favoriteIconBitmap);
- // `onCreateDialog()` requires the return of an `AlertDialog`.
+ // Return the alert dialog.
return alertDialog;
}
}
\ No newline at end of file
// Run the default commands.
super.onAttach(context);
- // Get a handle for `EditBookmarkDatabaseViewListener` from the launching context.
-
+ // Get a handle for edit bookmark database view listener from the launching context.
editBookmarkDatabaseViewListener = (EditBookmarkDatabaseViewListener) context;
}
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
- // Set the keyboard to be hidden when the `AlertDialog` is first shown. If this is not set, the `AlertDialog` will not shrink when the keyboard is displayed.
- alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
-
// The alert dialog must be shown before items in the layout can be modified.
alertDialog.show();
// Display `currentIconBitmap` in `edit_bookmark_current_icon`.
currentIconImageView.setImageBitmap(currentIconBitmap);
- // Get a bitmap of the favorite icon from `MainWebViewActivity` and display it in `edit_bookmark_web_page_favorite_icon`.
- newFavoriteIconImageView.setImageBitmap(MainWebViewActivity.favoriteIconBitmap);
+ // Get a copy of the favorite icon bitmap.
+ Bitmap favoriteIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((favoriteIconBitmap.getHeight() > 256) || (favoriteIconBitmap.getWidth() > 256)) {
+ favoriteIconBitmap = Bitmap.createScaledBitmap(favoriteIconBitmap, 256, 256, true);
+ }
+
+ // Set the new favorite icon bitmap.
+ newFavoriteIconImageView.setImageBitmap(favoriteIconBitmap);
// Populate the bookmark name and URL `EditTexts`.
nameEditText.setText(currentBookmarkName);
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
- // Show the keyboard when the alert dialog is displayed on the screen.
- alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
-
// The alert dialog must be shown before items in the layout can be modified.
alertDialog.show();
urlEditText = alertDialog.findViewById(R.id.edit_bookmark_url_edittext);
editButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
- // Get the current favorite icon byte array from the `Cursor`.
+ // Get the current favorite icon byte array from the cursor.
byte[] currentIconByteArray = bookmarkCursor.getBlob(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON));
- // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last.
+ // Convert the byte array to a bitmap beginning at the first byte and ending at the last.
Bitmap currentIconBitmap = BitmapFactory.decodeByteArray(currentIconByteArray, 0, currentIconByteArray.length);
- // Display `currentIconBitmap` in `edit_bookmark_current_icon`.
+ // Display the current icon bitmap.
currentIconImageView.setImageBitmap(currentIconBitmap);
- // Get a `Bitmap` of the favorite icon from `MainWebViewActivity` and display it in `edit_bookmark_web_page_favorite_icon`.
- newFavoriteIconImageView.setImageBitmap(MainWebViewActivity.favoriteIconBitmap);
+ // Get a copy of the favorite icon bitmap.
+ Bitmap favoriteIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((favoriteIconBitmap.getHeight() > 256) || (favoriteIconBitmap.getWidth() > 256)) {
+ favoriteIconBitmap = Bitmap.createScaledBitmap(favoriteIconBitmap, 256, 256, true);
+ }
+
+ // Set the new favorite icon bitmap.
+ newFavoriteIconImageView.setImageBitmap(favoriteIconBitmap);
// Store the current bookmark name and URL.
currentName = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
- // Set the keyboard to be hidden when the `AlertDialog` is first shown. If this is not set, the `AlertDialog` will not shrink when the keyboard is displayed.
- alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
-
// The alert dialog must be shown before items in the layout can be modified.
alertDialog.show();
// Display the current icon bitmap in `edit_bookmark_current_icon`.
currentIconImageView.setImageBitmap(currentIconBitmap);
- // Get a bitmap of the favorite icon from `MainWebViewActivity` and display it in `edit_bookmark_web_page_favorite_icon`.
- newFavoriteIconImageView.setImageBitmap(MainWebViewActivity.favoriteIconBitmap);
+ // Get a copy of the favorite icon bitmap.
+ Bitmap favoriteIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((favoriteIconBitmap.getHeight() > 256) || (favoriteIconBitmap.getWidth() > 256)) {
+ favoriteIconBitmap = Bitmap.createScaledBitmap(favoriteIconBitmap, 256, 256, true);
+ }
+
+ // Set the new favorite icon bitmap.
+ newFavoriteIconImageView.setImageBitmap(favoriteIconBitmap);
// Populate the folder name edit text.
nameEditText.setText(currentFolderName);
// Initialize the database helper. The two `nulls` do not specify the database name or a `CursorFactory`. The `0` specifies a database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`.
final BookmarksDatabaseHelper bookmarksDatabaseHelper = new BookmarksDatabaseHelper(getContext(), null, null, 0);
- // Get a `Cursor` with the selected folder and move it to the first position.
+ // Get a cursor with the selected folder and move it to the first position.
Cursor folderCursor = bookmarksDatabaseHelper.getBookmark(selectedFolderDatabaseId);
folderCursor.moveToFirst();
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
- // Show the keyboard when the dialog is displayed on the screen.
- alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
-
// The alert dialog must be shown before items in the layout can be modified.
alertDialog.show();
- // Get handles for layout items in the `AlertDialog`.
- final Button editButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
- final RadioButton currentIconRadioButton = alertDialog.findViewById(R.id.edit_folder_current_icon_radiobutton);
+ // Get handles for the views in the alert dialog.
RadioGroup iconRadioGroup = alertDialog.findViewById(R.id.edit_folder_icon_radio_group);
+ final RadioButton currentIconRadioButton = alertDialog.findViewById(R.id.edit_folder_current_icon_radiobutton);
+ ImageView currentIconImageView = alertDialog.findViewById(R.id.edit_folder_current_icon_imageview);
+ ImageView webPageFavoriteIconImageView = alertDialog.findViewById(R.id.edit_folder_web_page_favorite_icon_imageview);
+ final EditText folderNameEditText = alertDialog.findViewById(R.id.edit_folder_name_edittext);
+ final Button editButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
// Initially disable the edit button.
editButton.setEnabled(false);
- // Get the current favorite icon byte array from the `Cursor`.
+ // Get the current favorite icon byte array from the Cursor.
byte[] currentIconByteArray = folderCursor.getBlob(folderCursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON));
- // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last.
+
+ // Convert the byte array to a bitmap beginning at the first byte and ending at the last.
Bitmap currentIconBitmap = BitmapFactory.decodeByteArray(currentIconByteArray, 0, currentIconByteArray.length);
- // Display `currentIconBitmap` in `edit_folder_current_icon`.
- ImageView currentIconImageView = alertDialog.findViewById(R.id.edit_folder_current_icon_imageview);
+
+ // Display the current icon bitmap.
currentIconImageView.setImageBitmap(currentIconBitmap);
- // Get a `Bitmap` of the favorite icon from `MainWebViewActivity` and display it in `edit_folder_web_page_favorite_icon`.
- ImageView webPageFavoriteIconImageView = alertDialog.findViewById(R.id.edit_folder_web_page_favorite_icon_imageview);
- webPageFavoriteIconImageView.setImageBitmap(MainWebViewActivity.favoriteIconBitmap);
+ // Get a copy of the favorite icon bitmap.
+ Bitmap favoriteIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+
+ // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
+ if ((favoriteIconBitmap.getHeight() > 256) || (favoriteIconBitmap.getWidth() > 256)) {
+ favoriteIconBitmap = Bitmap.createScaledBitmap(favoriteIconBitmap, 256, 256, true);
+ }
+
+ // Set the new favorite icon bitmap.
+ webPageFavoriteIconImageView.setImageBitmap(favoriteIconBitmap);
// Get the current folder name.
final String currentFolderName = folderCursor.getString(folderCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
// Display the current folder name in `edit_folder_name_edittext`.
- final EditText folderNameEditText = alertDialog.findViewById(R.id.edit_folder_name_edittext);
folderNameEditText.setText(currentFolderName);
// Update the status of the edit button when the folder name is changed.
android:layout_width="match_parent"
android:hint="@string/folder_name"
android:imeOptions="actionGo"
- android:inputType="textUri" />
+ android:inputType="textUri" >
+ <requestFocus />
+ </com.google.android.material.textfield.TextInputEditText>
</com.google.android.material.textfield.TextInputLayout>
<TextView