From 893e5d474eadfe5b9cb1b12ba931c23f858c4019 Mon Sep 17 00:00:00 2001 From: Denver Braganza Date: Thu, 31 Mar 2022 03:38:42 +0530 Subject: [PATCH 1/8] Fixes based on ktlint linting --- CHANGELOG.md | 3 ++- cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4aeea88e..3d1717ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - `Security` in case of vulnerabilities. ## [x.x.x] - unreleased - +### Fixed +- Fix disable closing AlertDialog when touching outside the dialog [#334](https://github.com/CanHub/Android-Image-Cropper/issues/334) ## [4.2.0] - 21/03/2022 ### Added - Added an option to skip manual editing and return entire image when required [#324](https://github.com/CanHub/Android-Image-Cropper/pull/324) diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt index 42f5ee4c..a6fd7494 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt @@ -115,6 +115,7 @@ open class CropImageActivity : */ open fun showImageSourceDialog(openSource: (Source) -> Unit) { AlertDialog.Builder(this) + .setCancelable(false) .setTitle(R.string.pick_image_chooser_title) .setItems( arrayOf( From 9e6f188e32620b0b321724b8e03ff66ff5ad4633 Mon Sep 17 00:00:00 2001 From: Denver Braganza Date: Thu, 31 Mar 2022 03:38:42 +0530 Subject: [PATCH 2/8] Fixes based on ktlint linting --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3014dd56..7f7acbae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -141,7 +141,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - ENOENT (no such file or directory) [#99](https://github.com/CanHub/Android-Image-Cropper/issues/99) -- `content://` instead of `file://` [#83](https://github.com/CanHub/Android-Image-Cropper/issues/83) [#84](https://github.com/CanHub/Android-Image-Cropper/issues/84) +- `content://` instead of `file://` [#83](https://github.com/CanHub/Android-Image-Cropper/issues/83) [#84](https://github.com/CanHub/Android-Image-Cropper/issues/84) ## [2.3.2-alpha] - 12/04/21 ### Added @@ -231,4 +231,3 @@ Versions `2.0.1` and `2.0.2` are similar, issues with jitpack. ## [1.0.0] - 21/11/20 - Copy from previous repo [ArthurHub](https://github.com/ArthurHub/Android-Image-Cropper/) -- From ee563694860fc5460769b6951a11e539209171d3 Mon Sep 17 00:00:00 2001 From: Denver Braganza Date: Thu, 15 Sep 2022 19:28:46 +0530 Subject: [PATCH 3/8] Fixed main issue --- .../main/java/com/canhub/cropper/CropImageActivity.kt | 2 +- .../main/java/com/canhub/cropper/CropImageOptions.kt | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt index 489abb3c..c82828e2 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt @@ -90,7 +90,7 @@ open class CropImageActivity : else resources.getString(R.string.crop_image_activity_title) it.setDisplayHomeAsUpEnabled(true) - cropImageOptions.toolbarColor.takeIf { color -> color != -1 }?.let { toolbarColor -> + cropImageOptions.toolbarColor?.let { toolbarColor -> it.setBackgroundDrawable(ColorDrawable(toolbarColor)) } } diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt b/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt index 9a2aa29b..373e3cdf 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt @@ -43,11 +43,13 @@ open class CropImageOptions : Parcelable { /** The shape of the cropping window. */ @JvmField var cropShape: CropShape + /** * The shape of cropper corners */ @JvmField var cornerShape: CropImageView.CropCornerShape + /** * The radius of the circular crop corner */ @@ -167,6 +169,7 @@ open class CropImageOptions : Parcelable { @JvmField @ColorInt var borderCornerColor: Int + /** * The fill color of circle corner */ @@ -349,7 +352,7 @@ open class CropImageOptions : Parcelable { /** Toolbar color **/ @JvmField - var toolbarColor: Int = -1 + var toolbarColor: Int? = null /** Init options with defaults. */ constructor() { @@ -418,7 +421,7 @@ open class CropImageOptions : Parcelable { cropperLabelTextColor = Color.WHITE showCropLabel = false activityBackgroundColor = Color.WHITE - toolbarColor = -1 + toolbarColor = null } /** Create object from parcel. */ @@ -487,7 +490,7 @@ open class CropImageOptions : Parcelable { cropperLabelText = parcel.readString()!! showCropLabel = parcel.readByte().toInt() != 0 activityBackgroundColor = parcel.readInt() - toolbarColor = parcel.readInt() + toolbarColor = parcel.readValue(Int::class.java.classLoader) as Int? } override fun writeToParcel(dest: Parcel, flags: Int) { @@ -555,7 +558,7 @@ open class CropImageOptions : Parcelable { dest.writeString(cropperLabelText) dest.writeByte((if (showCropLabel) 1 else 0).toByte()) dest.writeInt(activityBackgroundColor) - dest.writeInt(toolbarColor) + dest.writeValue(toolbarColor) } override fun describeContents(): Int { From c4b5409ef33ff9aced310e825020b9237e90a009 Mon Sep 17 00:00:00 2001 From: Denver Braganza Date: Thu, 15 Sep 2022 19:33:20 +0530 Subject: [PATCH 4/8] Fixed main issue --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e416320d..2d7d0f38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -145,7 +145,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - ENOENT (no such file or directory) [#99](https://github.com/CanHub/Android-Image-Cropper/issues/99) -- `content://` instead of `file://` [#83](https://github.com/CanHub/Android-Image-Cropper/issues/83) [#84](https://github.com/CanHub/Android-Image-Cropper/issues/84) +- `content://` instead of `file://` [#83](https://github.com/CanHub/Android-Image-Cropper/issues/83) [#84](https://github.com/CanHub/Android-Image-Cropper/issues/84) ## [2.3.2-alpha] - 12/04/21 ### Added From dbe7548e9f306fecd6e95bee1fbbd2e89ec8545b Mon Sep 17 00:00:00 2001 From: Denver Braganza Date: Thu, 15 Sep 2022 21:03:37 +0530 Subject: [PATCH 5/8] Added customizations for toolbar title color, toolbar menu text colors and toolbar back button color --- .documentation/features.md | 5 ++ .../com/canhub/cropper/CropImageActivity.kt | 60 +++++++++++++++++++ .../cropper/CropImageContractOptions.kt | 38 ++++++++++++ .../com/canhub/cropper/CropImageOptions.kt | 29 +++++++++ .../com/canhub/cropper/sample/SampleCrop.kt | 6 +- 5 files changed, 137 insertions(+), 1 deletion(-) diff --git a/.documentation/features.md b/.documentation/features.md index 0bba1153..cf70e474 100644 --- a/.documentation/features.md +++ b/.documentation/features.md @@ -55,6 +55,7 @@ cropImage.launch( setMaxCropResultSize(99999, 99999) setActivityTitle("") setActivityMenuIconColor(0) + setActivityMenuTextColor(Color.BLACK) setOutputUri(outputUri) setOutputCompressFormat(Bitmap.CompressFormat.JPEG) setOutputCompressQuality(90) @@ -73,6 +74,10 @@ cropImage.launch( setIntentChooserPriorityList(listOf("com.miui.gallery", "com.google.android.apps.photos")) setActivityBackgroundColor(Color.BLACK) setToolbarColor(Color.GRAY) + setToolbarColor(Color.WHITE) + setToolbarTitleColor(Color.BLACK) + setToolbarBackButtonColor(Color.BLACK) + setToolbarTintColor(Color.BLACK) } ) ``` \ No newline at end of file diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt index c82828e2..b3c2d378 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt @@ -1,10 +1,15 @@ package com.canhub.cropper import android.content.Intent +import android.graphics.PorterDuff +import android.graphics.PorterDuffColorFilter import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable import android.net.Uri import android.os.Bundle +import android.text.Spannable +import android.text.SpannableString +import android.text.style.ForegroundColorSpan import android.util.Log import android.view.KeyEvent import android.view.Menu @@ -93,6 +98,26 @@ open class CropImageActivity : cropImageOptions.toolbarColor?.let { toolbarColor -> it.setBackgroundDrawable(ColorDrawable(toolbarColor)) } + cropImageOptions.toolbarTitleColor?.let { toolbarTitleColor -> + val spannableTitle: Spannable = SpannableString(title) + spannableTitle.setSpan( + ForegroundColorSpan(toolbarTitleColor), + 0, + spannableTitle.length, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE + ) + title = spannableTitle + } + cropImageOptions.toolbarBackButtonColor?.let { backBtnColor -> + try { + val upArrow = ContextCompat.getDrawable( + this, androidx.appcompat.R.drawable.abc_ic_ab_back_material) + upArrow?.colorFilter = PorterDuffColorFilter(backBtnColor, PorterDuff.Mode.SRC_ATOP) + it.setHomeAsUpIndicator(upArrow) + } catch (e: Exception) { + e.printStackTrace() + } + } } } @@ -239,6 +264,19 @@ open class CropImageActivity : ) } } + cropImageOptions.activityMenuTextColor?.let { menuItemsTextColor -> + val menuItemIds = listOf( + R.id.ic_rotate_left_24, + R.id.ic_rotate_right_24, + R.id.ic_flip_24, + R.id.ic_flip_24_horizontally, + R.id.ic_flip_24_vertically, + R.id.crop_image_menu_crop + ) + for (itemId in menuItemIds) { + updateMenuItemTextColor(menu, itemId, menuItemsTextColor) + } + } return true } @@ -380,6 +418,28 @@ open class CropImageActivity : } } + /** + * Update the color of a specific menu item to the given color. + */ + open fun updateMenuItemTextColor(menu: Menu, itemId: Int, color: Int) { + val menuItem = menu.findItem(itemId) + val menuTitle = menuItem.title + if (menuTitle?.isNotBlank() == true) { + try { + val spannableTitle: Spannable = SpannableString(menuTitle) + spannableTitle.setSpan( + ForegroundColorSpan(color), + 0, + spannableTitle.length, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE + ) + menuItem.title = spannableTitle + } catch (e: Exception) { + Log.w("AIC", "Failed to update menu item color", e) + } + } + } + enum class Source { CAMERA, GALLERY } private companion object { diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt b/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt index 16b07904..503bdbbb 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt @@ -344,6 +344,15 @@ data class CropImageContractOptions @JvmOverloads constructor( return this } + /** + * the color to use for action bar items texts.

+ * *Default: NONE* + */ + fun setActivityMenuTextColor(activityMenuTextColor: Int): CropImageContractOptions { + cropImageOptions.activityMenuTextColor = activityMenuTextColor + return this + } + /** * the Android Uri to save the cropped image to.

* *Default: NONE, will create a temp file* @@ -556,6 +565,35 @@ data class CropImageContractOptions @JvmOverloads constructor( fun setToolbarColor(@ColorInt color: Int) = cropImageOptions.apply { this.toolbarColor = color } + + /** + * Sets the toolbar color of the Crop Image Activity screen. + */ + fun setToolbarTitleColor(@ColorInt color: Int) = cropImageOptions.apply { + this.toolbarTitleColor = color + } + + /** + * Sets the toolbar back button color of the Crop Image Activity screen. + */ + fun setToolbarBackButtonColor(@ColorInt color: Int) = cropImageOptions.apply { + this.toolbarBackButtonColor = color + } + + /** + * Sets the tint color for all items on the toolbar of the Crop Image Activity screen. + * This includes setting the colors of the following together + * 1. Toolbar back button + * 2. Toolbar text + * 3. Toolbar menu icon color + * 4. Toolbar menu text color + */ + fun setToolbarTintColor(@ColorInt color: Int) = cropImageOptions.apply { + this.activityMenuTextColor = color + this.activityMenuIconColor = color + this.toolbarTitleColor = color + this.toolbarBackButtonColor = color + } } fun options( diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt b/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt index 373e3cdf..41f25d5b 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt @@ -238,6 +238,11 @@ open class CropImageOptions : Parcelable { @ColorInt var activityMenuIconColor: Int + /** the color to use for action bar items texts */ + @JvmField + @ColorInt + var activityMenuTextColor: Int? = null + /** the Android Uri to save the cropped image to */ @JvmField var customOutputUri: Uri? @@ -354,6 +359,18 @@ open class CropImageOptions : Parcelable { @JvmField var toolbarColor: Int? = null + /** Toolbar color **/ + @JvmField + var toolbarTitleColor: Int? = null + + /** Toolbar color **/ + @JvmField + var toolbarBackButtonColor: Int? = null + + /** Toolbar tint color **/ + @JvmField + var toolbarTintColor: Int? = null + /** Init options with defaults. */ constructor() { val dm = Resources.getSystem().displayMetrics @@ -396,6 +413,7 @@ open class CropImageOptions : Parcelable { maxCropResultHeight = 99999 activityTitle = "" activityMenuIconColor = 0 + activityMenuTextColor = null customOutputUri = null outputCompressFormat = CompressFormat.JPEG outputCompressQuality = 90 @@ -422,6 +440,9 @@ open class CropImageOptions : Parcelable { showCropLabel = false activityBackgroundColor = Color.WHITE toolbarColor = null + toolbarTitleColor = null + toolbarBackButtonColor = null + toolbarTintColor = null } /** Create object from parcel. */ @@ -464,6 +485,7 @@ open class CropImageOptions : Parcelable { maxCropResultHeight = parcel.readInt() activityTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel) activityMenuIconColor = parcel.readInt() + activityMenuTextColor = parcel.readValue(Int::class.java.classLoader) as Int? customOutputUri = parcel.readParcelable(Uri::class.java.classLoader) outputCompressFormat = CompressFormat.valueOf(parcel.readString()!!) outputCompressQuality = parcel.readInt() @@ -491,6 +513,9 @@ open class CropImageOptions : Parcelable { showCropLabel = parcel.readByte().toInt() != 0 activityBackgroundColor = parcel.readInt() toolbarColor = parcel.readValue(Int::class.java.classLoader) as Int? + toolbarTitleColor = parcel.readValue(Int::class.java.classLoader) as Int? + toolbarBackButtonColor = parcel.readValue(Int::class.java.classLoader) as Int? + toolbarTintColor = parcel.readValue(Int::class.java.classLoader) as Int? } override fun writeToParcel(dest: Parcel, flags: Int) { @@ -532,6 +557,7 @@ open class CropImageOptions : Parcelable { dest.writeInt(maxCropResultHeight) TextUtils.writeToParcel(activityTitle, dest, flags) dest.writeInt(activityMenuIconColor) + dest.writeValue(activityMenuTextColor) dest.writeParcelable(customOutputUri, flags) dest.writeString(outputCompressFormat.name) dest.writeInt(outputCompressQuality) @@ -559,6 +585,9 @@ open class CropImageOptions : Parcelable { dest.writeByte((if (showCropLabel) 1 else 0).toByte()) dest.writeInt(activityBackgroundColor) dest.writeValue(toolbarColor) + dest.writeValue(toolbarTitleColor) + dest.writeValue(toolbarBackButtonColor) + dest.writeValue(toolbarTintColor) } override fun describeContents(): Int { diff --git a/sample/src/main/java/com/canhub/cropper/sample/SampleCrop.kt b/sample/src/main/java/com/canhub/cropper/sample/SampleCrop.kt index 6674be43..cee96248 100644 --- a/sample/src/main/java/com/canhub/cropper/sample/SampleCrop.kt +++ b/sample/src/main/java/com/canhub/cropper/sample/SampleCrop.kt @@ -169,6 +169,7 @@ internal class SampleCrop : Fragment() { // setMaxCropResultSize(999, 999) // setActivityTitle("CUSTOM title") // setActivityMenuIconColor(RED) +// setActivityMenuTextColor(Color.BLACK) // setOutputUri(outputUri) // setOutputCompressFormat(Bitmap.CompressFormat.PNG) // setOutputCompressQuality(50) @@ -193,7 +194,10 @@ internal class SampleCrop : Fragment() { )) */ // setActivityBackgroundColor(Color.BLACK) -// setToolbarColor(Color.GRAY) +// setToolbarColor(Color.WHITE) +// setToolbarTitleColor(Color.BLACK) +// setToolbarBackButtonColor(Color.BLACK) +// setToolbarTintColor(Color.BLACK) } ) } From b124b136cb984cd5487ea573e31c4e853d2b1bae Mon Sep 17 00:00:00 2001 From: Denver Braganza Date: Thu, 15 Sep 2022 21:07:08 +0530 Subject: [PATCH 6/8] Updated CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d7d0f38..f00d312f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - `Security` in case of vulnerabilities. ## [x.x.x] - unreleased +### Added +- Added options to customize colors of toolbar back button, title and menu texts. [#437](https://github.com/CanHub/Android-Image-Cropper/issues/437) +### Fixed +- Fixed and issue where setting toolbar color to white would do nothing. [#437](https://github.com/CanHub/Android-Image-Cropper/issues/437) ## [4.3.2] - 08/09/2022 ### Fixed From c6fe9aaf78febbf82d2f522cd1f77d70742cb75d Mon Sep 17 00:00:00 2001 From: Denver Braganza Date: Thu, 15 Sep 2022 21:34:16 +0530 Subject: [PATCH 7/8] Fixed ktlint issues --- .../src/main/java/com/canhub/cropper/CropImageActivity.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt index b3c2d378..19b619c2 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt @@ -84,6 +84,10 @@ open class CropImageActivity : latestTmpUri = savedInstanceState.getString(BUNDLE_KEY_TMP_URI)?.toUri() } + setCustomizations() + } + + private fun setCustomizations() { cropImageOptions.activityBackgroundColor.let { activityBackgroundColor -> binding.root.setBackgroundColor(activityBackgroundColor) } @@ -136,7 +140,9 @@ open class CropImageActivity : ) cropImageOptions.let { options -> options.intentChooserTitle - ?.takeIf { title -> title.isNotBlank() } + ?.takeIf { title -> + title.isNotBlank() + } ?.let { icTitle -> ciIntentChooser.setIntentChooserTitle(icTitle) } From b67d9de06220873252f811500b844d594e4ead05 Mon Sep 17 00:00:00 2001 From: Denver Braganza Date: Thu, 15 Sep 2022 21:38:35 +0530 Subject: [PATCH 8/8] Fixed ktlint issues --- cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt index 19b619c2..56582869 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt @@ -115,7 +115,9 @@ open class CropImageActivity : cropImageOptions.toolbarBackButtonColor?.let { backBtnColor -> try { val upArrow = ContextCompat.getDrawable( - this, androidx.appcompat.R.drawable.abc_ic_ab_back_material) + this, + androidx.appcompat.R.drawable.abc_ic_ab_back_material + ) upArrow?.colorFilter = PorterDuffColorFilter(backBtnColor, PorterDuff.Mode.SRC_ATOP) it.setHomeAsUpIndicator(upArrow) } catch (e: Exception) {