- // Get a handle for `createBookmarkFolderListener` from `context`.
- try {
- createBookmarkFolderListener = (CreateBookmarkFolderListener) context;
- } catch(ClassCastException exception) {
- throw new ClassCastException(context.toString() + " must implement CreateBookmarkFolderListener.");
- }
+ // Get a handle for `createBookmarkFolderListener` from the launching context.
+ createBookmarkFolderListener = (CreateBookmarkFolderListener) context;
+ }
+
+ public static CreateBookmarkFolderDialog createBookmarkFolder(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 favorite icon in the bundle.
+ argumentsBundle.putByteArray("favorite_icon_byte_array", favoriteIconByteArray);
+
+ // Create a new instance of the dialog.
+ CreateBookmarkFolderDialog createBookmarkFolderDialog = new CreateBookmarkFolderDialog();
+
+ // Add the bundle to the dialog.
+ createBookmarkFolderDialog.setArguments(argumentsBundle);
+
+ // Return the new dialog.
+ return createBookmarkFolderDialog;