Skip to content

Commit

Permalink
Added skip editing option (#324)
Browse files Browse the repository at this point in the history
* Added skip editing option
  • Loading branch information
Devenom1 authored Mar 9, 2022
1 parent eeb7a99 commit 90d294e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -218,6 +219,10 @@ open class CropImageActivity :

if (cropImageOptions.initialRotation > 0)
cropImageView?.rotatedDegrees = cropImageOptions.initialRotation

if (cropImageOptions.skipEditing) {
cropImage()
}
} else setResult(null, error, 1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br></br>
* *Default: false*
*/
fun setSkipEditing(skipEditing: Boolean): CropImageContractOptions {
cropImageOptions.skipEditing = skipEditing
cropImageOptions.showCropOverlay = !skipEditing
return this
}
}

fun options(
Expand Down
10 changes: 10 additions & 0 deletions cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -342,6 +349,7 @@ open class CropImageOptions : Parcelable {
flipVertically = false
cropMenuCropButtonTitle = null
cropMenuCropButtonIcon = 0
skipEditing = false
}

/** Create object from parcel. */
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ internal class SCropImageFragment : Fragment(), SCropImageContract.View {
// setAllowRotation(false)
// setNoOutputImage(false)
// setFixAspectRatio(true)
// setSkipEditing(true)
}
)
}
Expand Down

0 comments on commit 90d294e

Please sign in to comment.