Skip to content

Commit

Permalink
Oval crop corners added (#307)
Browse files Browse the repository at this point in the history
* Added provision to add Oval crop corners when the crop style is Rectangle

* Setters exposed to had crop corner radius and fill color

* Change log updated
  • Loading branch information
bhagyae5308 authored Feb 2, 2022
1 parent b23eb70 commit 65a62af
Show file tree
Hide file tree
Showing 17 changed files with 406 additions and 104 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [unreleased 4.0.2]
### Added
- Added provision to add Oval crop corners when the crop style is Rectangle [#305](https://github.com/CanHub/Android-Image-Cropper/issues/305)

## [4.0.1] - unreleased
### Fixed
- When TakePictureContract returns false or null return null result. [#287](https://github.com/CanHub/Android-Image-Cropper/issues/287)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@ data class CropImageContractOptions @JvmOverloads constructor(
cropImageOptions.cropShape = cropShape
return this
}
/**
* To set the shape of the cropper corner (RECTANGLE / OVAL)
* Default: RECTANGLE
*/
fun setCropCornerShape(cornerShape: CropImageView.CropCornerShape): CropImageContractOptions {
cropImageOptions.cornerShape = cornerShape
return this
}

/**
* To set the fill color of the Oval crop corner
* @param circleFillColorHexValue Hex value of the color (Default is WHITE)
*/
fun setCircleCornerFillColor(circleFillColorHexValue: Int): CropImageContractOptions {
cropImageOptions.circleCornerFillColorHexValue = circleFillColorHexValue
return this
}

/**
* To set the Oval crop corner radius
* Default is 10
*/
fun setCropCornerRadius(cornerRadius: Float): CropImageContractOptions {
cropImageOptions.cropCornerRadius = cornerRadius
return this
}

/**
* An edge of the crop window will snap to the corresponding edge of a specified bounding box
Expand Down
24 changes: 24 additions & 0 deletions cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ 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
*/
@JvmField
var cropCornerRadius: Float

/**
* An edge of the crop window will snap to the corresponding edge of a specified bounding box when
Expand Down Expand Up @@ -141,6 +151,11 @@ open class CropImageOptions : Parcelable {
/** the color of the corner line */
@JvmField
var borderCornerColor: Int
/**
* The fill color of circle corner
*/
@JvmField
var circleCornerFillColorHexValue: Int

/** the thickness of the guidelines lines. (in pixels) */
@JvmField
Expand Down Expand Up @@ -275,6 +290,9 @@ open class CropImageOptions : Parcelable {
imageSourceIncludeCamera = true
imageSourceIncludeGallery = true
cropShape = CropShape.RECTANGLE
cornerShape = CropImageView.CropCornerShape.RECTANGLE
circleCornerFillColorHexValue = Color.WHITE
cropCornerRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10f, dm)
snapRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3f, dm)
touchRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24f, dm)
guidelines = Guidelines.ON_TOUCH
Expand Down Expand Up @@ -331,6 +349,8 @@ open class CropImageOptions : Parcelable {
imageSourceIncludeCamera = parcel.readByte().toInt() != 0
imageSourceIncludeGallery = parcel.readByte().toInt() != 0
cropShape = CropShape.values()[parcel.readInt()]
cornerShape = CropImageView.CropCornerShape.values()[parcel.readInt()]
cropCornerRadius = parcel.readFloat()
snapRadius = parcel.readFloat()
touchRadius = parcel.readFloat()
guidelines = Guidelines.values()[parcel.readInt()]
Expand All @@ -351,6 +371,7 @@ open class CropImageOptions : Parcelable {
borderCornerOffset = parcel.readFloat()
borderCornerLength = parcel.readFloat()
borderCornerColor = parcel.readInt()
circleCornerFillColorHexValue = parcel.readInt()
guidelinesThickness = parcel.readFloat()
guidelinesColor = parcel.readInt()
backgroundColor = parcel.readInt()
Expand Down Expand Up @@ -385,6 +406,8 @@ open class CropImageOptions : Parcelable {
dest.writeByte((if (imageSourceIncludeCamera) 1 else 0).toByte())
dest.writeByte((if (imageSourceIncludeGallery) 1 else 0).toByte())
dest.writeInt(cropShape.ordinal)
dest.writeInt(cornerShape.ordinal)
dest.writeFloat(cropCornerRadius)
dest.writeFloat(snapRadius)
dest.writeFloat(touchRadius)
dest.writeInt(guidelines.ordinal)
Expand All @@ -405,6 +428,7 @@ open class CropImageOptions : Parcelable {
dest.writeFloat(borderCornerOffset)
dest.writeFloat(borderCornerLength)
dest.writeInt(borderCornerColor)
dest.writeInt(circleCornerFillColorHexValue)
dest.writeFloat(guidelinesThickness)
dest.writeInt(guidelinesColor)
dest.writeInt(backgroundColor)
Expand Down
28 changes: 28 additions & 0 deletions cropper/src/main/java/com/canhub/cropper/CropImageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute
set(cropShape) {
mCropOverlayView!!.setCropShape(cropShape!!)
}
/**
* The shape of the crop corner in the crop overlay (Rectangular / Circular)
*/
var cornerShape: CropCornerShape?
get() = mCropOverlayView!!.cornerShape
set(cornerShape) {
mCropOverlayView!!.setCropCornerShape(cornerShape!!)
}

/** if auto-zoom functionality is enabled. default: true. */
/** Set auto-zoom functionality to enabled/disabled. */
var isAutoZoomEnabled: Boolean
Expand Down Expand Up @@ -1440,6 +1449,12 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute

RECTANGLE, OVAL, RECTANGLE_VERTICAL_ONLY, RECTANGLE_HORIZONTAL_ONLY
}
/**
* Possible crop corner shape
*/
enum class CropCornerShape {
RECTANGLE, OVAL
}

/**
* Options for scaling the bounds of cropping image to the bounds of Crop Image View.<br></br>
Expand Down Expand Up @@ -1759,6 +1774,16 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute
options.cropShape.ordinal
)
]
options.cornerShape = CropCornerShape.values()[
ta.getInt(
R.styleable.CropImageView_cornerShape,
options.cornerShape.ordinal
)
]
options.cropCornerRadius = ta.getDimension(
R.styleable.CropImageView_cropCornerRadius,
options.cropCornerRadius
)
options.guidelines = Guidelines.values()[
ta.getInt(
R.styleable.CropImageView_cropGuidelines, options.guidelines.ordinal
Expand All @@ -1776,6 +1801,9 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute
R.styleable.CropImageView_cropInitialCropWindowPaddingRatio,
options.initialCropWindowPaddingRatio
)
options.circleCornerFillColorHexValue = ta.getInteger(
R.styleable.CropImageView_cropCornerCircleFillColor, options.circleCornerFillColorHexValue
)
options.borderLineThickness = ta.getDimension(
R.styleable.CropImageView_cropBorderLineThickness,
options.borderLineThickness
Expand Down
Loading

0 comments on commit 65a62af

Please sign in to comment.