- // Get a handle for `EditFolderListener` from `parentActivity`.
- try {
- editBookmarkFolderListener = (EditBookmarkFolderListener) context;
- } catch(ClassCastException exception) {
- throw new ClassCastException(context.toString() + " must implement EditBookmarkFolderListener.");
- }
+ // Get a handle for `EditFolderListener` from the launching context.
+ editBookmarkFolderListener = (EditBookmarkFolderListener) context;
+ }
+
+ // Store the database ID in the arguments bundle.
+ public static EditBookmarkFolderDialog folderDatabaseId(int databaseId, Bitmap favoriteIconBitmap) {
+ // Create a favorite icon byte array output stream.
+ ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
+
+ // Convert the favorite icon to a PNG and place it in the byte array output stream. `0` is for lossless compression (the only option for a PNG).
+ favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream);
+
+ // Convert the byte array output stream to a byte array.
+ byte[] favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray();
+
+ // Create an arguments bundle
+ Bundle argumentsBundle = new Bundle();
+
+ // Store the variables in the bundle.
+ argumentsBundle.putInt("database_id", databaseId);
+ argumentsBundle.putByteArray("favorite_icon_byte_array", favoriteIconByteArray);
+
+ // Create a new instance of the dialog.
+ EditBookmarkFolderDialog editBookmarkFolderDialog = new EditBookmarkFolderDialog();
+
+ // Add the arguments bundle to the dialog.
+ editBookmarkFolderDialog.setArguments(argumentsBundle);
+
+ // Return the new dialog.
+ return editBookmarkFolderDialog;