From 90d294efcdac7f852a16252492e8802faaf6c810 Mon Sep 17 00:00:00 2001 From: Denver Braganza Date: Wed, 9 Mar 2022 14:40:24 +0530 Subject: [PATCH] Added skip editing option (#324) * Added skip editing option --- CHANGELOG.md | 2 ++ .../main/java/com/canhub/cropper/CropImageActivity.kt | 5 +++++ .../com/canhub/cropper/CropImageContractOptions.kt | 10 ++++++++++ .../main/java/com/canhub/cropper/CropImageOptions.kt | 10 ++++++++++ .../sample/crop_image/app/SCropImageFragment.kt | 1 + 5 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5a65ea9..713b560b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [4.2.0] - unreleased ### Fixed - Added missing support for `ScaleType.CENTER_CROP` [#220](https://github.com/CanHub/Android-Image-Cropper/issues/220) +### Added +- Added an option to skip manual editing and return entire image when required [#324](https://github.com/CanHub/Android-Image-Cropper/pull/324) ## [4.1.0] - 02/02/2022 ### Fixed diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt index 1e030459..72eca958 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt @@ -135,6 +135,7 @@ open class CropImageActivity : } override fun onCreateOptionsMenu(menu: Menu): Boolean { + if (cropImageOptions.skipEditing) return true menuInflater.inflate(R.menu.crop_image_menu, menu) if (!cropImageOptions.allowRotation) { @@ -218,6 +219,10 @@ open class CropImageActivity : if (cropImageOptions.initialRotation > 0) cropImageView?.rotatedDegrees = cropImageOptions.initialRotation + + if (cropImageOptions.skipEditing) { + cropImage() + } } else setResult(null, error, 1) } diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt b/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt index 2d8a760e..85015cb3 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt @@ -490,6 +490,16 @@ data class CropImageContractOptions @JvmOverloads constructor( cropImageOptions.cropMenuCropButtonIcon = drawableResource return this } + + /** + * Set whether the cropping option should be allowed or skipped entirely.

+ * *Default: false* + */ + fun setSkipEditing(skipEditing: Boolean): CropImageContractOptions { + cropImageOptions.skipEditing = skipEditing + cropImageOptions.showCropOverlay = !skipEditing + return this + } } 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 29a1e888..82150410 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt @@ -284,6 +284,13 @@ open class CropImageOptions : Parcelable { @JvmField var cropMenuCropButtonIcon: Int + /** + * Allows you to skip the editing (cropping, flipping or rotating) option. + * This returns the entire selected image directly + */ + @JvmField + var skipEditing: Boolean + /** Init options with defaults. */ constructor() { val dm = Resources.getSystem().displayMetrics @@ -342,6 +349,7 @@ open class CropImageOptions : Parcelable { flipVertically = false cropMenuCropButtonTitle = null cropMenuCropButtonIcon = 0 + skipEditing = false } /** Create object from parcel. */ @@ -400,6 +408,7 @@ open class CropImageOptions : Parcelable { flipVertically = parcel.readByte().toInt() != 0 cropMenuCropButtonTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel) cropMenuCropButtonIcon = parcel.readInt() + skipEditing = parcel.readByte().toInt() != 0 } override fun writeToParcel(dest: Parcel, flags: Int) { @@ -457,6 +466,7 @@ open class CropImageOptions : Parcelable { dest.writeByte((if (flipVertically) 1 else 0).toByte()) TextUtils.writeToParcel(cropMenuCropButtonTitle, dest, flags) dest.writeInt(cropMenuCropButtonIcon) + dest.writeByte((if (skipEditing) 1 else 0).toByte()) } override fun describeContents(): Int { diff --git a/sample/src/main/java/com/canhub/cropper/sample/crop_image/app/SCropImageFragment.kt b/sample/src/main/java/com/canhub/cropper/sample/crop_image/app/SCropImageFragment.kt index 2cc97f3b..5d5eda7e 100644 --- a/sample/src/main/java/com/canhub/cropper/sample/crop_image/app/SCropImageFragment.kt +++ b/sample/src/main/java/com/canhub/cropper/sample/crop_image/app/SCropImageFragment.kt @@ -190,6 +190,7 @@ internal class SCropImageFragment : Fragment(), SCropImageContract.View { // setAllowRotation(false) // setNoOutputImage(false) // setFixAspectRatio(true) +// setSkipEditing(true) } ) }