Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added skip editing option #324

Merged
merged 4 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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