diff options
Diffstat (limited to 'library/src/main/kotlin/ca')
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerView.kt | 2 | ||||
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt | 12 |
2 files changed, 7 insertions, 7 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerView.kt b/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerView.kt index 2643d27..da864c9 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerView.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerView.kt @@ -32,7 +32,7 @@ internal class ColorPickerView @JvmOverloads constructor( var circleSize: Int = context.dimen(R.dimen.kau_color_circle_size).toInt() val backgroundColor = context.resolveColor(R.attr.md_background_color, if (context.resolveColor(android.R.attr.textColorPrimary).isColorDark()) Color.WHITE else 0xff424242.toInt()) - val backgroundColorTint = backgroundColor.colorToForeground(0.2f) + val backgroundColorTint = backgroundColor.colorToForeground() lateinit var dialog: MaterialDialog lateinit var builder: ColorContract lateinit var colorsTop: IntArray diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt index 2c5a395..8ae23d1 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt @@ -69,25 +69,25 @@ fun Int.withMinAlpha(@IntRange(from = 0L, to = 255L) alpha: Int): Int = Color.argb(Math.max(alpha, Color.alpha(this)), Color.red(this), Color.green(this), Color.blue(this)) @ColorInt -fun Int.lighten(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.2f): Int { +fun Int.lighten(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.1f): Int { val (red, green, blue) = intArrayOf(Color.red(this), Color.green(this), Color.blue(this)) - .map { Math.min(255f * factor + it, 255f).toInt() } + .map { (it * (1f - factor) + 255f * factor).toInt() } return Color.argb(Color.alpha(this), red, green, blue) } @ColorInt -fun Int.darken(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.2f): Int { +fun Int.darken(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.1f): Int { val (red, green, blue) = intArrayOf(Color.red(this), Color.green(this), Color.blue(this)) - .map { Math.max(it - 255f * factor, 0f).toInt() } + .map { (it * (1f - factor)).toInt() } return Color.argb(Color.alpha(this), red, green, blue) } @ColorInt -fun Int.colorToBackground(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.2f): Int +fun Int.colorToBackground(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.1f): Int = if (isColorDark()) darken(factor) else lighten(factor) @ColorInt -fun Int.colorToForeground(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.2f): Int +fun Int.colorToForeground(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.1f): Int = if (isColorDark()) lighten(factor) else darken(factor) @Throws(IllegalArgumentException::class) |