From 79e1d9331c4c5b703ab69ca74620e808ba46d43c Mon Sep 17 00:00:00 2001 From: bhagyalaxmi naik Date: Fri, 10 Jun 2022 09:52:22 +0530 Subject: [PATCH 1/5] Helper text label added on top of crop overlay - Added a helper text on top of crop overlay which moves along with it - Exposed xml attrs and setter to update the copy text styles --- .idea/deploymentTargetDropDown.xml | 17 +++++ .../cropper/CropImageContractOptions.kt | 5 ++ .../com/canhub/cropper/CropImageOptions.kt | 31 ++++++++ .../java/com/canhub/cropper/CropImageView.kt | 75 ++++++++++++++++++- .../com/canhub/cropper/CropOverlayView.kt | 73 ++++++++++++++++++ cropper/src/main/res/values/attrs.xml | 4 + .../cropper/sample/SampleUsingImageView.kt | 4 +- .../SampleOptionsBottomSheet.kt | 7 +- .../options_dialog/SampleOptionsEntity.kt | 1 + .../res/layout/fragment_crop_image_view.xml | 4 + .../src/main/res/layout/fragment_options.xml | 3 + .../res/layout/switch_crop_text_label.xml | 19 +++++ sample/src/main/res/values/dimens.xml | 1 + sample/src/main/res/values/strings.xml | 2 + 14 files changed, 243 insertions(+), 3 deletions(-) create mode 100644 .idea/deploymentTargetDropDown.xml create mode 100644 sample/src/main/res/layout/switch_crop_text_label.xml diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 00000000..d611d10c --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt b/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt index bdddaa7e..babfa250 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt @@ -127,6 +127,11 @@ data class CropImageContractOptions @JvmOverloads constructor( return this } + fun setShowCropLabel(showCropLabel: Boolean): CropImageContractOptions { + cropImageOptions.showCropLabel = showCropLabel + return this + } + /** * if auto-zoom functionality is enabled.

* default: true. diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt b/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt index 136c9ccc..d784514a 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt @@ -4,6 +4,7 @@ import android.content.res.Resources import android.graphics.Bitmap.CompressFormat import android.graphics.Color import android.graphics.Rect +import android.graphics.Typeface import android.net.Uri import android.os.Parcel import android.os.Parcelable @@ -83,6 +84,12 @@ open class CropImageOptions : Parcelable { @JvmField var showCropOverlay: Boolean + /** + * If enabled, show a text label on top of crop overlay UI, which gets moved along with the cropper + */ + @JvmField + var showCropLabel: Boolean + /** * if to show progress bar when image async loading/cropping is in progress.

* default: true, disable to provide custom progress bar UI. @@ -311,6 +318,19 @@ open class CropImageOptions : Parcelable { @JvmField var intentChooserPriorityList: List? + /** The initial text size of cropper label **/ + @JvmField + var cropperLabelTextSize: Float + + /** The default cropper label text color **/ + @JvmField + var cropperLabelTextColor: Int + + /** The default cropper label text **/ + @JvmField + var cropperLabelText: String? = "" + + /** Init options with defaults. */ constructor() { val dm = Resources.getSystem().displayMetrics @@ -373,6 +393,9 @@ open class CropImageOptions : Parcelable { showIntentChooser = false intentChooserTitle = null intentChooserPriorityList = listOf() + cropperLabelTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20f, dm) + cropperLabelTextColor = Color.WHITE + showCropLabel = false } /** Create object from parcel. */ @@ -435,6 +458,10 @@ open class CropImageOptions : Parcelable { showIntentChooser = parcel.readByte().toInt() != 0 intentChooserTitle = parcel.readString() intentChooserPriorityList = parcel.createStringArrayList() + cropperLabelTextSize = parcel.readFloat() + cropperLabelTextColor = parcel.readInt() + cropperLabelText = parcel.readString()!! + showCropLabel = parcel.readByte().toInt() != 0 } override fun writeToParcel(dest: Parcel, flags: Int) { @@ -496,6 +523,10 @@ open class CropImageOptions : Parcelable { dest.writeByte((if (showIntentChooser) 1 else 0).toByte()) dest.writeString(intentChooserTitle) dest.writeStringList(intentChooserPriorityList) + dest.writeFloat(cropperLabelTextSize) + dest.writeInt(cropperLabelTextColor) + dest.writeString(cropperLabelText) + dest.writeByte((if (showCropLabel) 1 else 0).toByte()) } override fun describeContents(): Int { diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageView.kt b/cropper/src/main/java/com/canhub/cropper/CropImageView.kt index 7033b52c..143ef2c0 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageView.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageView.kt @@ -5,6 +5,7 @@ import android.content.Context import android.graphics.Bitmap import android.graphics.Bitmap.CompressFormat import android.graphics.BitmapFactory +import android.graphics.Color import android.graphics.Matrix import android.graphics.Rect import android.graphics.RectF @@ -105,6 +106,29 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute */ private var mShowCropOverlay = true + /** If true, shows a helper text label over crop overlay UI + * default: false + */ + private var mShowCropLabel = false + + /** + * Helper text label over crop overlay UI + * default: empty string + */ + private var mCropTextLabel = "" + + /** + * Text size for text label over crop overlay UI + * default: 20sp + */ + private var mCropLabelTextSize = 20f + + /** + * Text color for text label over crop overlay UI + * default: White + */ + private var mCropLabelTextColor = Color.WHITE + /** * if to show progress bar when image async loading/cropping is in progress.

* default: true, disable to provide custom progress bar UI. @@ -403,6 +427,36 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute setCropOverlayVisibility() } } + /** + * If enabled, show a text label on top of crop overlay UI, which gets moved along with the cropper + */ + var isShowCropLabel: Boolean + get() = mShowCropLabel + set(showCropLabel) { + if (mShowCropLabel != showCropLabel) { + mShowCropLabel = showCropLabel + //set crop label visibility + mCropOverlayView?.setCropperTextLabelVisibility(mShowCropLabel) + } + } + var cropLabelText: String + get() = mCropTextLabel + set(cropLabelText) { + mCropTextLabel = cropLabelText + mCropOverlayView?.setCropLabelText(cropLabelText) + } + var cropLabelTextSize: Float + get() = mCropLabelTextSize + set(textSize) { + mCropLabelTextSize = cropLabelTextSize + mCropOverlayView?.setCropLabelTextSize(textSize) + } + var cropLabelTextColor: Int + get() = mCropLabelTextColor + set(cropLabelTextColor) { + mCropLabelTextColor = cropLabelTextColor + mCropOverlayView?.setCropLabelTextColor(cropLabelTextColor) + } /** Returns the integer of the imageResource */ /** * Sets a Drawable as the content of the CropImageView. @@ -1037,7 +1091,7 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute bundle.putInt("CROP_MAX_ZOOM", mMaxZoom) bundle.putBoolean("CROP_FLIP_HORIZONTALLY", mFlipHorizontally) bundle.putBoolean("CROP_FLIP_VERTICALLY", mFlipVertically) - + bundle.putBoolean("SHOW_CROP_LABEL", mShowCropLabel) return bundle } @@ -1088,6 +1142,8 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute mMaxZoom = state.getInt("CROP_MAX_ZOOM") mFlipHorizontally = state.getBoolean("CROP_FLIP_HORIZONTALLY") mFlipVertically = state.getBoolean("CROP_FLIP_VERTICALLY") + mShowCropLabel = state.getBoolean("SHOW_CROP_LABEL") + mCropOverlayView.setCropperTextLabelVisibility(mShowCropLabel) } super.onRestoreInstanceState(state.getParcelable("instanceState")) } else { @@ -1882,6 +1938,21 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute R.styleable.CropImageView_cropFlipHorizontally, options.flipVertically ) + //crop label + options.cropperLabelTextSize = ta.getDimension( + R.styleable.CropImageView_cropperLabelTextSize, + options.cropperLabelTextSize + ) + options.cropperLabelTextColor = ta.getInteger( + R.styleable.CropImageView_cropperLabelTextColor, + options.cropperLabelTextColor + ) + options.cropperLabelText = ta.getString( + R.styleable.CropImageView_cropperLabelText) + options.showCropLabel = ta.getBoolean( + R.styleable.CropImageView_cropShowLabel, + options.showCropLabel + ) isSaveBitmapToInstanceState = ta.getBoolean( R.styleable.CropImageView_cropSaveBitmapToInstanceState, isSaveBitmapToInstanceState @@ -1902,6 +1973,8 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute mScaleType = options.scaleType mAutoZoomEnabled = options.autoZoomEnabled mMaxZoom = options.maxZoom + mCropLabelTextSize = options.cropperLabelTextSize + mShowCropLabel = options.showCropLabel mShowCropOverlay = options.showCropOverlay mShowProgressBar = options.showProgressBar mFlipHorizontally = options.flipHorizontally diff --git a/cropper/src/main/java/com/canhub/cropper/CropOverlayView.kt b/cropper/src/main/java/com/canhub/cropper/CropOverlayView.kt index 9579ec7b..affef89e 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropOverlayView.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropOverlayView.kt @@ -34,6 +34,18 @@ class CropOverlayView companion object { + /** + * Creates the paint object for drawing text label over crop overlay + */ + private fun getTextPaint(options: CropImageOptions): Paint { + return Paint().apply { + strokeWidth = 1f + textSize = options.cropperLabelTextSize + style = Paint.Style.FILL + textAlign = Paint.Align.CENTER + this.color = options.cropperLabelTextColor + } + } /** Creates the Paint object for drawing. */ private fun getNewPaint(color: Int): Paint = Paint().apply { @@ -92,6 +104,8 @@ class CropOverlayView /** The Paint used to darken the surrounding areas outside the crop area. */ private var mBackgroundPaint: Paint? = null + private var mTextLabelPaint: Paint? = null + /** Used for oval crop window shape or non-straight rotation drawing. */ private val mPath = Path() @@ -164,6 +178,14 @@ class CropOverlayView var cornerShape: CropImageView.CropCornerShape? = null private set + /** To show the text label over crop overlay **/ + private var isCropLabelEnabled: Boolean = false + /** Text to show over text label over crop overlay */ + private var cropLabelText: String = "" + /** Text color to apply over text label over crop overlay */ + private var cropLabelTextSize: Float = 20f + /** Text color to apply over text label over crop overlay */ + private var cropLabelTextColor = Color.WHITE /** the initial crop window rectangle to set */ private val mInitialCropWindowRect = Rect() @@ -253,7 +275,37 @@ class CropOverlayView invalidate() } } + /** + * Sets the cropper label if it is enabled + */ + fun setCropperTextLabelVisibility(isEnabled: Boolean) { + this.isCropLabelEnabled = isEnabled + invalidate() + } + + /** + * Sets the copy text for cropper text + */ + fun setCropLabelText(textLabel: String?) { + textLabel?.let { + this.cropLabelText = it + } + } + /** + * Sets the text size for cropper text + */ + fun setCropLabelTextSize(textSize: Float) { + this.cropLabelTextSize = textSize + invalidate() + } + /** + * Sets the text color for cropper text + */ + fun setCropLabelTextColor(textColor: Int) { + this.cropLabelTextColor = textColor + invalidate() + } /** * Sets the guidelines for the CropOverlayView to be either on, off, or to show when resizing the * application. @@ -410,6 +462,10 @@ class CropOverlayView fun setInitialAttributeValues(options: CropImageOptions) { mOptions = options mCropWindowHandler.setInitialAttributeValues(options) + setCropLabelTextColor(options.cropperLabelTextColor) + setCropLabelTextSize(options.cropperLabelTextSize) + setCropLabelText(options.cropperLabelText) + setCropperTextLabelVisibility(options.showCropLabel) setCropCornerRadius(options.cropCornerRadius) setCropCornerShape(options.cornerShape) setCropShape(options.cropShape) @@ -430,6 +486,7 @@ class CropOverlayView getNewPaintOrNull(options.borderCornerThickness, options.borderCornerColor) mGuidelinePaint = getNewPaintOrNull(options.guidelinesThickness, options.guidelinesColor) mBackgroundPaint = getNewPaint(options.backgroundColor) + mTextLabelPaint = getTextPaint(options) } /** @@ -570,10 +627,26 @@ class CropOverlayView } // To retain the changes in Paint object when the App goes background this is required mBorderCornerPaint = getNewPaintOrNull(mOptions?.borderCornerThickness ?: 0.0f, mOptions?.borderCornerColor ?: Color.WHITE) + drawCropLabelText(canvas) drawBorders(canvas) drawCorners(canvas) } + /** Draws a text label (which can acts an helper text) on top of crop overlay **/ + private fun drawCropLabelText(canvas: Canvas) { + if (isCropLabelEnabled) { + val rect = mCropWindowHandler.getRect() + var xCoordinate = (rect.left + rect.right) / 2 + var yCoordinate = rect.top - 50 + mTextLabelPaint?.apply { + textSize = cropLabelTextSize + color = cropLabelTextColor + } + canvas.drawText(cropLabelText, xCoordinate, yCoordinate, mTextLabelPaint!!) + canvas.save() + } + } + /** Draw shadow background over the image not including the crop area. */ private fun drawBackground(canvas: Canvas) { val rect = mCropWindowHandler.getRect() diff --git a/cropper/src/main/res/values/attrs.xml b/cropper/src/main/res/values/attrs.xml index 82318aa8..0db22609 100644 --- a/cropper/src/main/res/values/attrs.xml +++ b/cropper/src/main/res/values/attrs.xml @@ -54,6 +54,10 @@ + + + + \ No newline at end of file diff --git a/sample/src/main/java/com/canhub/cropper/sample/SampleUsingImageView.kt b/sample/src/main/java/com/canhub/cropper/sample/SampleUsingImageView.kt index a214897a..b563aade 100644 --- a/sample/src/main/java/com/canhub/cropper/sample/SampleUsingImageView.kt +++ b/sample/src/main/java/com/canhub/cropper/sample/SampleUsingImageView.kt @@ -106,6 +106,7 @@ internal class SampleUsingImageView : maxZoom = options.maxZoomLvl isFlippedHorizontally = options.flipHorizontal isFlippedVertically = options.flipVertically + isShowCropLabel = options.showCropLabel } if (options.scaleType == CropImageView.ScaleType.CENTER_INSIDE) @@ -191,6 +192,7 @@ internal class SampleUsingImageView : showCropOverlay = true, showProgressBar = true, flipHorizontal = false, - flipVertically = false + flipVertically = false, + showCropLabel = false ) } diff --git a/sample/src/main/java/com/canhub/cropper/sample/options_dialog/SampleOptionsBottomSheet.kt b/sample/src/main/java/com/canhub/cropper/sample/options_dialog/SampleOptionsBottomSheet.kt index 08e1cb48..ce45b5e1 100644 --- a/sample/src/main/java/com/canhub/cropper/sample/options_dialog/SampleOptionsBottomSheet.kt +++ b/sample/src/main/java/com/canhub/cropper/sample/options_dialog/SampleOptionsBottomSheet.kt @@ -114,6 +114,7 @@ internal class SampleOptionsBottomSheet : BottomSheetDialogFragment() { binding.progressBar.toggle.isChecked = options.showProgressBar binding.flipHorizontal.toggle.isChecked = options.flipHorizontal binding.flipVertical.toggle.isChecked = options.flipVertically + binding.cropLabelText.toggle.isChecked = options.showCropLabel } override fun onDismiss(dialog: DialogInterface) { @@ -134,7 +135,8 @@ internal class SampleOptionsBottomSheet : BottomSheetDialogFragment() { showCropOverlay = true, showProgressBar = true, flipHorizontal = false, - flipVertically = false + flipVertically = false, + showCropLabel = true ) private fun bindingActions() { @@ -253,5 +255,8 @@ internal class SampleOptionsBottomSheet : BottomSheetDialogFragment() { binding.progressBar.toggle.setOnCheckedChangeListener { _, isChecked -> options = options.copy(showProgressBar = isChecked) } + binding.cropLabelText.toggle.setOnCheckedChangeListener { _, isChecked -> + options = options.copy(showCropLabel = isChecked) + } } } diff --git a/sample/src/main/java/com/canhub/cropper/sample/options_dialog/SampleOptionsEntity.kt b/sample/src/main/java/com/canhub/cropper/sample/options_dialog/SampleOptionsEntity.kt index cdc538a7..0e7597df 100644 --- a/sample/src/main/java/com/canhub/cropper/sample/options_dialog/SampleOptionsEntity.kt +++ b/sample/src/main/java/com/canhub/cropper/sample/options_dialog/SampleOptionsEntity.kt @@ -20,4 +20,5 @@ internal data class SampleOptionsEntity( val showProgressBar: Boolean, val flipHorizontal: Boolean, val flipVertically: Boolean, + val showCropLabel: Boolean ) : Parcelable diff --git a/sample/src/main/res/layout/fragment_crop_image_view.xml b/sample/src/main/res/layout/fragment_crop_image_view.xml index a2edb728..bea13125 100644 --- a/sample/src/main/res/layout/fragment_crop_image_view.xml +++ b/sample/src/main/res/layout/fragment_crop_image_view.xml @@ -24,6 +24,10 @@ app:cropCornerRadius="@dimen/default_crop_corner_radius" app:cropBorderCornerOffset="@dimen/default_crop_corner_offset" app:cropBorderCornerThickness="@dimen/default_crop_corner_offset" + app:cropShowLabel="true" + app:cropperLabelText="@string/default_crop_label_text" + app:cropperLabelTextSize="@dimen/default_crop_text_size" + app:cropBorderCornerColor="@color/cardview_shadow_start_color" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/sample/src/main/res/layout/fragment_options.xml b/sample/src/main/res/layout/fragment_options.xml index 06db3d79..0e3c2e08 100644 --- a/sample/src/main/res/layout/fragment_options.xml +++ b/sample/src/main/res/layout/fragment_options.xml @@ -95,6 +95,9 @@ + \ No newline at end of file diff --git a/sample/src/main/res/layout/switch_crop_text_label.xml b/sample/src/main/res/layout/switch_crop_text_label.xml new file mode 100644 index 00000000..ca675818 --- /dev/null +++ b/sample/src/main/res/layout/switch_crop_text_label.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/sample/src/main/res/values/dimens.xml b/sample/src/main/res/values/dimens.xml index fbc3b9c2..e63ff37a 100644 --- a/sample/src/main/res/values/dimens.xml +++ b/sample/src/main/res/values/dimens.xml @@ -39,4 +39,5 @@ 8dp 8dp 4dp + 20sp \ No newline at end of file diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 497af191..b8bba517 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -91,4 +91,6 @@ This is a sample code using the library. The sample here is for extend CropImageActivity, to be about to custom build your personal view around it. For that we need to use CropImageView. Click to change rotation: %1$s Corner Shape + Show Crop Label Text + Sample crop label From 649c0ef0c77cc5971980991e71ce5dee7cb24225 Mon Sep 17 00:00:00 2001 From: bhagyalaxmi naik Date: Fri, 10 Jun 2022 09:54:23 +0530 Subject: [PATCH 2/5] Removed unwanted file commit --- .idea/deploymentTargetDropDown.xml | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 .idea/deploymentTargetDropDown.xml diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index d611d10c..00000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file From 0ff3afa7a53496a0f3631443c764859a49df344f Mon Sep 17 00:00:00 2001 From: bhagyalaxmi naik Date: Fri, 10 Jun 2022 11:24:14 +0530 Subject: [PATCH 3/5] Resolved lint errors --- .../com/canhub/cropper/CropImageOptions.kt | 4 +--- .../java/com/canhub/cropper/CropImageView.kt | 7 +++--- .../com/canhub/cropper/CropOverlayView.kt | 22 +++++++++---------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt b/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt index d784514a..081142bc 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt @@ -4,7 +4,6 @@ import android.content.res.Resources import android.graphics.Bitmap.CompressFormat import android.graphics.Color import android.graphics.Rect -import android.graphics.Typeface import android.net.Uri import android.os.Parcel import android.os.Parcelable @@ -330,7 +329,6 @@ open class CropImageOptions : Parcelable { @JvmField var cropperLabelText: String? = "" - /** Init options with defaults. */ constructor() { val dm = Resources.getSystem().displayMetrics @@ -393,7 +391,7 @@ open class CropImageOptions : Parcelable { showIntentChooser = false intentChooserTitle = null intentChooserPriorityList = listOf() - cropperLabelTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20f, dm) + cropperLabelTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20f, dm) cropperLabelTextColor = Color.WHITE showCropLabel = false } diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageView.kt b/cropper/src/main/java/com/canhub/cropper/CropImageView.kt index 143ef2c0..7cf6c707 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageView.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageView.kt @@ -430,12 +430,11 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute /** * If enabled, show a text label on top of crop overlay UI, which gets moved along with the cropper */ - var isShowCropLabel: Boolean + var isShowCropLabel: Boolean get() = mShowCropLabel set(showCropLabel) { if (mShowCropLabel != showCropLabel) { mShowCropLabel = showCropLabel - //set crop label visibility mCropOverlayView?.setCropperTextLabelVisibility(mShowCropLabel) } } @@ -1938,7 +1937,6 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute R.styleable.CropImageView_cropFlipHorizontally, options.flipVertically ) - //crop label options.cropperLabelTextSize = ta.getDimension( R.styleable.CropImageView_cropperLabelTextSize, options.cropperLabelTextSize @@ -1948,7 +1946,8 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute options.cropperLabelTextColor ) options.cropperLabelText = ta.getString( - R.styleable.CropImageView_cropperLabelText) + R.styleable.CropImageView_cropperLabelText + ) options.showCropLabel = ta.getBoolean( R.styleable.CropImageView_cropShowLabel, options.showCropLabel diff --git a/cropper/src/main/java/com/canhub/cropper/CropOverlayView.kt b/cropper/src/main/java/com/canhub/cropper/CropOverlayView.kt index affef89e..7f39f10a 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropOverlayView.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropOverlayView.kt @@ -38,13 +38,13 @@ class CropOverlayView * Creates the paint object for drawing text label over crop overlay */ private fun getTextPaint(options: CropImageOptions): Paint { - return Paint().apply { - strokeWidth = 1f - textSize = options.cropperLabelTextSize - style = Paint.Style.FILL - textAlign = Paint.Align.CENTER - this.color = options.cropperLabelTextColor - } + return Paint().apply { + strokeWidth = 1f + textSize = options.cropperLabelTextSize + style = Paint.Style.FILL + textAlign = Paint.Align.CENTER + this.color = options.cropperLabelTextColor + } } /** Creates the Paint object for drawing. */ private fun getNewPaint(color: Int): Paint = @@ -278,10 +278,10 @@ class CropOverlayView /** * Sets the cropper label if it is enabled */ - fun setCropperTextLabelVisibility(isEnabled: Boolean) { - this.isCropLabelEnabled = isEnabled - invalidate() - } + fun setCropperTextLabelVisibility(isEnabled: Boolean) { + this.isCropLabelEnabled = isEnabled + invalidate() + } /** * Sets the copy text for cropper text From f517a568709dde04bd9f1e056b8abcbbb1b56f22 Mon Sep 17 00:00:00 2001 From: bhagyalaxmi naik Date: Fri, 10 Jun 2022 17:19:07 +0530 Subject: [PATCH 4/5] Change log updated and few PR feedback addressesd - Old java style coding updated as per feedback --- CHANGELOG.md | 4 ++++ .../java/com/canhub/cropper/CropOverlayView.kt | 16 +++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 341f0a74..275efe88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - The translation of `Camera` and `Gallery` does not exist in some languages. +## [unreleased 4.2.2] +### Added +- Added a helper text on top of crop overlay which moves along with it. [#381](https://github.com/CanHub/Android-Image-Cropper/issues/381) + ## [4.2.1] - 04/04/2022 ### Added - Added support for optionally displaying an intent chooser when selecting image source. [#325](https://github.com/CanHub/Android-Image-Cropper/issues/325) diff --git a/cropper/src/main/java/com/canhub/cropper/CropOverlayView.kt b/cropper/src/main/java/com/canhub/cropper/CropOverlayView.kt index 7f39f10a..237191b8 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropOverlayView.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropOverlayView.kt @@ -35,17 +35,15 @@ class CropOverlayView companion object { /** - * Creates the paint object for drawing text label over crop overlay - */ - private fun getTextPaint(options: CropImageOptions): Paint { - return Paint().apply { + * Creates the paint object for drawing text label over crop overlay */ + private fun getTextPaint(options: CropImageOptions): Paint = + Paint().apply { strokeWidth = 1f textSize = options.cropperLabelTextSize style = Paint.Style.FILL textAlign = Paint.Align.CENTER this.color = options.cropperLabelTextColor } - } /** Creates the Paint object for drawing. */ private fun getNewPaint(color: Int): Paint = Paint().apply { @@ -104,7 +102,7 @@ class CropOverlayView /** The Paint used to darken the surrounding areas outside the crop area. */ private var mBackgroundPaint: Paint? = null - private var mTextLabelPaint: Paint? = null + private var textLabelPaint: Paint? = null /** Used for oval crop window shape or non-straight rotation drawing. */ private val mPath = Path() @@ -486,7 +484,7 @@ class CropOverlayView getNewPaintOrNull(options.borderCornerThickness, options.borderCornerColor) mGuidelinePaint = getNewPaintOrNull(options.guidelinesThickness, options.guidelinesColor) mBackgroundPaint = getNewPaint(options.backgroundColor) - mTextLabelPaint = getTextPaint(options) + textLabelPaint = getTextPaint(options) } /** @@ -638,11 +636,11 @@ class CropOverlayView val rect = mCropWindowHandler.getRect() var xCoordinate = (rect.left + rect.right) / 2 var yCoordinate = rect.top - 50 - mTextLabelPaint?.apply { + textLabelPaint?.apply { textSize = cropLabelTextSize color = cropLabelTextColor } - canvas.drawText(cropLabelText, xCoordinate, yCoordinate, mTextLabelPaint!!) + canvas.drawText(cropLabelText, xCoordinate, yCoordinate, textLabelPaint!!) canvas.save() } } From bec2ef12c764d459e7537be6952bd32dcd95c482 Mon Sep 17 00:00:00 2001 From: bhagyalaxmi naik Date: Fri, 10 Jun 2022 17:25:19 +0530 Subject: [PATCH 5/5] Crash fix: On click Sample of CustomActivity option over sample App Added missing activity declaration over Manifest.xml --- CHANGELOG.md | 2 ++ sample/src/main/AndroidManifest.xml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 275efe88..0ed6834b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [unreleased 4.2.2] ### Added - Added a helper text on top of crop overlay which moves along with it. [#381](https://github.com/CanHub/Android-Image-Cropper/issues/381) +### Fixed +- Crash on click of Sample of CustomActivity option over sample App, added the missing activity declaration on Manifest.xml ## [4.2.1] - 04/04/2022 ### Added diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 6247b07c..55cb9a21 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -20,7 +20,7 @@