diff --git a/.documentation/features.md b/.documentation/features.md index cf300158..0bba1153 100644 --- a/.documentation/features.md +++ b/.documentation/features.md @@ -71,6 +71,8 @@ cropImage.launch( setNoOutputImage(false) setFixAspectRatio(false) setIntentChooserPriorityList(listOf("com.miui.gallery", "com.google.android.apps.photos")) + setActivityBackgroundColor(Color.BLACK) + setToolbarColor(Color.GRAY) } ) ``` \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index cbea3ecf..dfea6f9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [x.x.x] - unreleased ### Fixed - Fixed the mistake in hindi conversion of "Crop" [#402](https://github.com/CanHub/Android-Image-Cropper/issues/402) +- Added the option to set custom color to toolbar of CropImageActivity [#421](https://github.com/CanHub/Android-Image-Cropper/issues/421) +- Added the option to set custom background color to activity of CropImageActivity [#421](https://github.com/CanHub/Android-Image-Cropper/issues/421) ## [4.3.1] - 20/07/2022 ### Fix diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt index d90c6d35..78fae1ad 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt @@ -1,6 +1,7 @@ package com.canhub.cropper import android.content.Intent +import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable import android.net.Uri import android.os.Bundle @@ -77,6 +78,10 @@ open class CropImageActivity : latestTmpUri = savedInstanceState.getString(BUNDLE_KEY_TMP_URI)?.toUri() } + cropImageOptions.activityBackgroundColor.let { activityBackgroundColor -> + binding.root.setBackgroundColor(activityBackgroundColor) + } + supportActionBar?.let { title = if (cropImageOptions.activityTitle.isNotEmpty()) @@ -84,6 +89,9 @@ open class CropImageActivity : else resources.getString(R.string.crop_image_activity_title) it.setDisplayHomeAsUpEnabled(true) + cropImageOptions.toolbarColor.takeIf { color -> color != -1 }?.let { toolbarColor -> + it.setBackgroundDrawable(ColorDrawable(toolbarColor)) + } } } diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt b/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt index babfa250..16b07904 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageContractOptions.kt @@ -3,6 +3,7 @@ package com.canhub.cropper import android.graphics.Bitmap import android.graphics.Rect import android.net.Uri +import androidx.annotation.ColorInt import androidx.annotation.DrawableRes import com.canhub.cropper.CropImageOptions.Companion.DEGREES_360 import com.canhub.cropper.CropImageView.CropShape @@ -541,6 +542,20 @@ data class CropImageContractOptions @JvmOverloads constructor( fun setIntentChooserPriorityList(priorityAppPackages: List) = cropImageOptions.apply { this.intentChooserPriorityList = priorityAppPackages } + + /** + * Sets the background color of the Crop Image Activity screen. + */ + fun setActivityBackgroundColor(@ColorInt color: Int) = cropImageOptions.apply { + this.activityBackgroundColor = color + } + + /** + * Sets the toolbar color of the Crop Image Activity screen. + */ + fun setToolbarColor(@ColorInt color: Int) = cropImageOptions.apply { + this.toolbarColor = color + } } fun options( diff --git a/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt b/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt index 2d471b4a..9a2aa29b 100644 --- a/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt +++ b/cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt @@ -343,6 +343,14 @@ open class CropImageOptions : Parcelable { @JvmField var cropperLabelText: String? = "" + /** Crop Image background color **/ + @JvmField + var activityBackgroundColor: Int + + /** Toolbar color **/ + @JvmField + var toolbarColor: Int = -1 + /** Init options with defaults. */ constructor() { val dm = Resources.getSystem().displayMetrics @@ -409,6 +417,8 @@ open class CropImageOptions : Parcelable { cropperLabelTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20f, dm) cropperLabelTextColor = Color.WHITE showCropLabel = false + activityBackgroundColor = Color.WHITE + toolbarColor = -1 } /** Create object from parcel. */ @@ -476,6 +486,8 @@ open class CropImageOptions : Parcelable { cropperLabelTextColor = parcel.readInt() cropperLabelText = parcel.readString()!! showCropLabel = parcel.readByte().toInt() != 0 + activityBackgroundColor = parcel.readInt() + toolbarColor = parcel.readInt() } override fun writeToParcel(dest: Parcel, flags: Int) { @@ -542,6 +554,8 @@ open class CropImageOptions : Parcelable { dest.writeInt(cropperLabelTextColor) dest.writeString(cropperLabelText) dest.writeByte((if (showCropLabel) 1 else 0).toByte()) + dest.writeInt(activityBackgroundColor) + dest.writeInt(toolbarColor) } override fun describeContents(): Int { diff --git a/sample/src/main/java/com/canhub/cropper/sample/SampleCrop.kt b/sample/src/main/java/com/canhub/cropper/sample/SampleCrop.kt index d2b90c6f..21f8bc99 100644 --- a/sample/src/main/java/com/canhub/cropper/sample/SampleCrop.kt +++ b/sample/src/main/java/com/canhub/cropper/sample/SampleCrop.kt @@ -187,8 +187,10 @@ internal class SampleCrop : Fragment() { /* setIntentChooserPriorityList(listOf( "com.miui.gallery", "com.google.android.apps.photos" - )) + )) */ +// setActivityBackgroundColor(Color.BLACK) +// setToolbarColor(Color.GRAY) } ) }