aboutsummaryrefslogtreecommitdiff
path: root/library/src
diff options
context:
space:
mode:
Diffstat (limited to 'library/src')
-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