+ private val browseActivityResultLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { imageUri: Uri? ->
+ // Only do something if the user didn't press back from the file picker.
+ if (imageUri != null) {
+ // Get a handle for the content resolver.
+ val contentResolver = requireContext().contentResolver
+
+ // Get the image MIME type.
+ val mimeType = contentResolver.getType(imageUri)
+
+ // Decode the image according to the type.
+ if (mimeType == "image/svg+xml") { // The image is an SVG.
+ // Display a snackbar.
+ Snackbar.make(customIconImageView, getString(R.string.cannot_use_svg), Snackbar.LENGTH_LONG).show()
+ } else { // The image is not an SVG.
+ // Get an input stream for the image URI.
+ val inputStream = contentResolver.openInputStream(imageUri)
+
+ // Get the bitmap from the URI.
+ // `ImageDecoder.decodeBitmap` can't be used, because when running `Drawable.toBitmap` later the `Software rendering doesn't support hardware bitmaps` error message might be produced.
+ var imageBitmap = BitmapFactory.decodeStream(inputStream)
+
+ // Scale the image down if it is greater than 64 pixels in either direction.
+ if ((imageBitmap != null) && ((imageBitmap.height > 128) || (imageBitmap.width > 128)))
+ imageBitmap = Bitmap.createScaledBitmap(imageBitmap, 128, 128, true)
+
+ // Display the new custom favorite icon.
+ customIconImageView.setImageBitmap(imageBitmap)
+
+ // Select the custom icon radio button.
+ customIconLinearLayout.performClick()
+ }
+ }
+ }
+
+ // Declare the class views.
+ private lateinit var currentIconRadioButton: RadioButton
+ private lateinit var customIconLinearLayout: LinearLayout
+ private lateinit var customIconImageView: ImageView
+ private lateinit var folderNameEditText: EditText
+ private lateinit var saveButton: Button
+
+ // Declare the class variables.
+ private lateinit var currentFolderName: String
+ private lateinit var editBookmarkFolderListener: EditBookmarkFolderListener
+
+ // The public interface is used to send information back to the parent activity.
+ interface EditBookmarkFolderListener {
+ fun saveBookmarkFolder(dialogFragment: DialogFragment, selectedFolderDatabaseId: Int)
+ }
+
+ override fun onAttach(context: Context) {
+ // Run the default commands.
+ super.onAttach(context)
+
+ // Get a handle for the edit bookmark folder listener from the launching context.
+ editBookmarkFolderListener = context as EditBookmarkFolderListener
+ }
+