diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-22 19:43:10 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-22 19:43:10 -0700 |
commit | ff17cd5daac40418e6e1bc89e9f65bd0fc8ea6af (patch) | |
tree | 02391363e8f2af64820f4b231cb9aaab030e56f2 /library/src | |
parent | 971738ae5942c3439568c54393708a3dd63c87f6 (diff) | |
download | kau-ff17cd5daac40418e6e1bc89e9f65bd0fc8ea6af.tar.gz kau-ff17cd5daac40418e6e1bc89e9f65bd0fc8ea6af.tar.bz2 kau-ff17cd5daac40418e6e1bc89e9f65bd0fc8ea6af.zip |
Change lighten and darken again
Diffstat (limited to 'library/src')
3 files changed, 9 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) 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 <string name="kau_exit_confirmation">Are you sure you want to exit?</string> <string name="kau_exit_confirmation_x">Are you sure you want to exit %s?</string> <string name="kau_glass">Glass</string> + <string name="kau_got_it">Got it</string> <string name="kau_great">Great</string> + <string name="kau_hide">Hide</string> <string name="kau_light">Light</string> <string name="kau_login">Login</string> <string name="kau_logout">Logout</string> |