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

CropImageOptions: Option to change progress bar color. #390

Merged
merged 2 commits into from
Jun 17, 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers.

This expression contains a magic number. Consider defining it to a well named constant.

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers.

This expression contains a magic number. Consider defining it to a well named constant.

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers.

This expression contains a magic number. Consider defining it to a well named constant.

/**
* All the possible options that can be set to customize crop image.<br></br>
* Initialized with default values.
Expand Down Expand Up @@ -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. */
Canato marked this conversation as resolved.
Show resolved Hide resolved
@JvmField
@ColorInt
var progressBarColor: Int

/**
* if auto-zoom functionality is enabled.<br></br>
* default: true.
Expand Down Expand Up @@ -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) */
Expand All @@ -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
Expand All @@ -169,13 +179,15 @@ open class CropImageOptions : Parcelable {

/** the color of the guidelines lines */
@JvmField
@ColorInt
var guidelinesColor: Int

/**
* the color of the overlay background around the crop window cover the image parts not in the
* crop window.
*/
@JvmField
@ColorInt
var backgroundColor: Int

/** the min width the crop window is allowed to be. (in pixels) */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -323,6 +336,7 @@ open class CropImageOptions : Parcelable {

/** The default cropper label text color **/
@JvmField
@ColorInt
var cropperLabelTextColor: Int

/** The default cropper label text **/
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
5 changes: 5 additions & 0 deletions cropper/src/main/java/com/canhub/cropper/CropImageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
}

Expand Down