From ff17cd5daac40418e6e1bc89e9f65bd0fc8ea6af Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 22 Jun 2017 19:43:10 -0700 Subject: Change lighten and darken again --- .../kotlin/ca/allanwang/kau/dialogs/color/ColorPickerView.kt | 2 +- library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt | 12 ++++++------ library/src/main/res/values/strings_commons.xml | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'library/src') 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) diff --git a/library/src/main/res/values/strings_commons.xml b/library/src/main/res/values/strings_commons.xml index 1bbca44..6bc8299 100644 --- a/library/src/main/res/values/strings_commons.xml +++ b/library/src/main/res/values/strings_commons.xml @@ -21,7 +21,9 @@ Most resources are verbatim and x represents a formatted item Are you sure you want to exit? Are you sure you want to exit %s? Glass + Got it Great + Hide Light Login Logout -- cgit v1.2.3