+ // Set the folder icon according to the type.
+ if (foldersMergeCursor.getPosition() > 1) { // Set a user folder icon.
+ // Initialize a default folder icon byte array output stream.
+ ByteArrayOutputStream defaultFolderIconByteArrayOutputStream = new ByteArrayOutputStream();
+
+ // Covert the default folder bitmap to a PNG and store it in the output stream. `0` is for lossless compression (the only option for a PNG).
+ defaultFolderBitmap.compress(Bitmap.CompressFormat.PNG, 0, defaultFolderIconByteArrayOutputStream);
+
+ // Convert the default folder icon output stream to a byte array.
+ byte[] defaultFolderIconByteArray = defaultFolderIconByteArrayOutputStream.toByteArray();
+
+
+ // Get the folder icon byte array from the cursor.
+ byte[] folderIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON));
+
+ // Convert the byte array to a bitmap beginning at the first byte and ending at the last.
+ Bitmap folderIconBitmap = BitmapFactory.decodeByteArray(folderIconByteArray, 0, folderIconByteArray.length);
+
+
+ // Set the icon according to the type.
+ if (Arrays.equals(folderIconByteArray, defaultFolderIconByteArray)) { // The default folder icon is used.
+ // Set a smaller and darker folder icon, which works well with the spinner.
+ spinnerItemImageView.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.folder_dark_blue));
+ } else { // A custom folder icon is uses.
+ // Set the folder image stored in the cursor.
+ spinnerItemImageView.setImageBitmap(folderIconBitmap);
+ }
+ } else { // Set the `All Folders` or `Home Folder` icon.
+ // Set the gray folder image. `ContextCompat` must be used until the minimum API >= 21.
+ spinnerItemImageView.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.folder_gray));
+ }
+