aboutsummaryrefslogtreecommitdiff
path: root/library/src/main
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-12 18:58:57 -0700
committerAllan Wang <me@allanwang.ca>2017-06-12 18:58:57 -0700
commit5431209bf04f1ea7a4d283893e0d8a4e796b0c90 (patch)
treeb9b5e9d3391db49b354493338f562728afed8077 /library/src/main
parenta429a5e0dbc96ae67bc68e27527239a43390e3f1 (diff)
downloadkau-5431209bf04f1ea7a4d283893e0d8a4e796b0c90.tar.gz
kau-5431209bf04f1ea7a4d283893e0d8a4e796b0c90.tar.bz2
kau-5431209bf04f1ea7a4d283893e0d8a4e796b0c90.zip
Add color to fg/bg
Diffstat (limited to 'library/src/main')
-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.kt8
2 files changed, 9 insertions, 1 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 9d0c9c1..8c26645 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 = if (backgroundColor.isColorDark()) backgroundColor.lighten(0.2f) else backgroundColor.darken(0.2f)
+ val backgroundColorTint = backgroundColor.colorToForeground(0.2f)
lateinit var dialog: MaterialDialog
lateinit var builder: Builder
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 35681b0..0e835eb 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
@@ -70,6 +70,14 @@ fun Int.darken(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.2f): Int {
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
+ = if (isColorDark()) darken(factor) else lighten(factor)
+
+@ColorInt
+fun Int.colorToForeground(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.2f): Int
+ = if (isColorDark()) lighten(factor) else darken(factor)
+
@Throws(IllegalArgumentException::class)
fun String.toColor(): Int {
val toParse: String