Skip to content

Commit

Permalink
Feature/421 add color customisations for crop image activity (#422)
Browse files Browse the repository at this point in the history
* Added customisations to change toolbar and activity background of crop image activity

* Added changelog changes

* Added default value for activity background
  • Loading branch information
Devenom1 authored Aug 19, 2022
1 parent a2ee60f commit f521736
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .documentation/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
```
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -77,13 +78,20 @@ 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())
cropImageOptions.activityTitle
else
resources.getString(R.string.crop_image_activity_title)
it.setDisplayHomeAsUpEnabled(true)
cropImageOptions.toolbarColor.takeIf { color -> color != -1 }?.let { toolbarColor ->
it.setBackgroundDrawable(ColorDrawable(toolbarColor))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -541,6 +542,20 @@ data class CropImageContractOptions @JvmOverloads constructor(
fun setIntentChooserPriorityList(priorityAppPackages: List<String>) = 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(
Expand Down
14 changes: 14 additions & 0 deletions cropper/src/main/java/com/canhub/cropper/CropImageOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion sample/src/main/java/com/canhub/cropper/sample/SampleCrop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ internal class SampleCrop : Fragment() {
/* setIntentChooserPriorityList(listOf(
"com.miui.gallery",
"com.google.android.apps.photos"
))
))
*/
// setActivityBackgroundColor(Color.BLACK)
// setToolbarColor(Color.GRAY)
}
)
}
Expand Down

0 comments on commit f521736

Please sign in to comment.