From c948413dbeab8b3139c22b30ee3e85e1a7fda6aa Mon Sep 17 00:00:00 2001 From: Niklas Baudy Date: Fri, 17 Jun 2022 15:50:01 +0200 Subject: [PATCH] CropImageOptions: Option to change progress bar color. (#390) * CropImageOptions: Option to change progress bar color. --- CHANGELOG.md | 4 +++- .../java/com/canhub/cropper/CropImageOptions.kt | 17 +++++++++++++++++ .../java/com/canhub/cropper/CropImageView.kt | 5 +++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b39a4466..ccc3975e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [x.x.x] - unreleased +- CropImageOptions: Option to change progress bar color. [#390](https://github.com/CanHub/Android-Image-Cropper/issues/390) + ## [4.3.0] - 10/06/2022 ### 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) @@ -128,7 +130,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - ENOENT (no such file or directory) [#99](https://github.com/CanHub/Android-Image-Cropper/issues/99) -- `content://` instead of `file://` [#83](https://github.com/CanHub/Android-Image-Cropper/issues/83) [#84](https://github.com/CanHub/Android-Image-Cropper/issues/84) +- `content://` instead of `file://` [#83](https://github.com/CanHub/Android-Image-Cropper/issues/83) [#84](https://github.com/CanHub/Android-Image-Cropper/issues/84) ## [2.3.2-alpha] - 12/04/21 ### Added diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt b/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt index b84bb03e..2d471b4a 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt @@ -9,10 +9,13 @@ import android.os.Parcel import android.os.Parcelable import android.text.TextUtils import android.util.TypedValue +import androidx.annotation.ColorInt import com.canhub.cropper.CropImageView.CropShape import com.canhub.cropper.CropImageView.Guidelines import com.canhub.cropper.CropImageView.RequestSizeOptions +private val COLOR_PURPLE = Color.rgb(153, 51, 153) + /** * All the possible options that can be set to customize crop image.

* Initialized with default values. @@ -96,6 +99,11 @@ open class CropImageOptions : Parcelable { @JvmField var showProgressBar: Boolean + /** The color of the progress bar. Only works on API level 21 and upwards. */ + @JvmField + @ColorInt + var progressBarColor: Int + /** * if auto-zoom functionality is enabled.

* default: true. @@ -140,6 +148,7 @@ open class CropImageOptions : Parcelable { /** the color of the guidelines lines */ @JvmField + @ColorInt var borderLineColor: Int /** thickness of the corner line. (in pixels) */ @@ -156,6 +165,7 @@ open class CropImageOptions : Parcelable { /** the color of the corner line */ @JvmField + @ColorInt var borderCornerColor: Int /** * The fill color of circle corner @@ -169,6 +179,7 @@ open class CropImageOptions : Parcelable { /** the color of the guidelines lines */ @JvmField + @ColorInt var guidelinesColor: Int /** @@ -176,6 +187,7 @@ open class CropImageOptions : Parcelable { * crop window. */ @JvmField + @ColorInt var backgroundColor: Int /** the min width the crop window is allowed to be. (in pixels) */ @@ -220,6 +232,7 @@ open class CropImageOptions : Parcelable { /** the color to use for action bar items icons */ @JvmField + @ColorInt var activityMenuIconColor: Int /** the Android Uri to save the cropped image to */ @@ -323,6 +336,7 @@ open class CropImageOptions : Parcelable { /** The default cropper label text color **/ @JvmField + @ColorInt var cropperLabelTextColor: Int /** The default cropper label text **/ @@ -344,6 +358,7 @@ open class CropImageOptions : Parcelable { scaleType = CropImageView.ScaleType.FIT_CENTER showCropOverlay = true showProgressBar = true + progressBarColor = COLOR_PURPLE autoZoomEnabled = true multiTouchEnabled = false centerMoveEnabled = true @@ -409,6 +424,7 @@ open class CropImageOptions : Parcelable { scaleType = CropImageView.ScaleType.values()[parcel.readInt()] showCropOverlay = parcel.readByte().toInt() != 0 showProgressBar = parcel.readByte().toInt() != 0 + progressBarColor = parcel.readInt() autoZoomEnabled = parcel.readByte().toInt() != 0 multiTouchEnabled = parcel.readByte().toInt() != 0 centerMoveEnabled = parcel.readByte().toInt() != 0 @@ -474,6 +490,7 @@ open class CropImageOptions : Parcelable { dest.writeInt(scaleType.ordinal) dest.writeByte((if (showCropOverlay) 1 else 0).toByte()) dest.writeByte((if (showProgressBar) 1 else 0).toByte()) + dest.writeInt(progressBarColor) dest.writeByte((if (autoZoomEnabled) 1 else 0).toByte()) dest.writeByte((if (multiTouchEnabled) 1 else 0).toByte()) dest.writeByte((if (centerMoveEnabled) 1 else 0).toByte()) diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageView.kt b/cropper/src/main/java/com/canhub/cropper/CropImageView.kt index 7b83c89a..4c3170aa 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageView.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageView.kt @@ -2,6 +2,7 @@ package com.canhub.cropper import android.app.Activity import android.content.Context +import android.content.res.ColorStateList import android.graphics.Bitmap import android.graphics.Bitmap.CompressFormat import android.graphics.BitmapFactory @@ -10,6 +11,7 @@ import android.graphics.Matrix import android.graphics.Rect import android.graphics.RectF import android.net.Uri +import android.os.Build import android.os.Bundle import android.os.Parcelable import android.provider.MediaStore @@ -1962,6 +1964,9 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute mCropOverlayView.setCropWindowChangeListener(this) mCropOverlayView.setInitialAttributeValues(options) mProgressBar = v.findViewById(R.id.CropProgressBar) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + mProgressBar.indeterminateTintList = ColorStateList.valueOf(options.progressBarColor) + } setProgressBarVisibility() }