aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/kotlin/ca
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-22 19:43:10 -0700
committerAllan Wang <me@allanwang.ca>2017-06-22 19:43:10 -0700
commitff17cd5daac40418e6e1bc89e9f65bd0fc8ea6af (patch)
tree02391363e8f2af64820f4b231cb9aaab030e56f2 /library/src/main/kotlin/ca
parent971738ae5942c3439568c54393708a3dd63c87f6 (diff)
downloadkau-ff17cd5daac40418e6e1bc89e9f65bd0fc8ea6af.tar.gz
kau-ff17cd5daac40418e6e1bc89e9f65bd0fc8ea6af.tar.bz2
kau-ff17cd5daac40418e6e1bc89e9f65bd0fc8ea6af.zip
Change lighten and darken again
Diffstat (limited to 'library/src/main/kotlin/ca')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerView.kt2
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt12
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)