aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-07-05 12:51:21 -0700
committerAllan Wang <me@allanwang.ca>2017-07-05 12:51:21 -0700
commit10e2ee9d4f105d9737b98b1caacf5e6ccb1c3c7d (patch)
tree81f2976a43b65a28c428b1ae60a62888e573a756 /core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
parent4e254b4b983b8531193c02852d2866a876d8cfcf (diff)
downloadkau-10e2ee9d4f105d9737b98b1caacf5e6ccb1c3c7d.tar.gz
kau-10e2ee9d4f105d9737b98b1caacf5e6ccb1c3c7d.tar.bz2
kau-10e2ee9d4f105d9737b98b1caacf5e6ccb1c3c7d.zip
Remap color dark and fix up swipe
Diffstat (limited to 'core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt13
1 files changed, 8 insertions, 5 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
index 8590d6f..84a7c06 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
@@ -19,8 +19,8 @@ import com.afollestad.materialdialogs.R
/**
* Created by Allan Wang on 2017-06-08.
*/
-fun Int.isColorDark(): Boolean
- = (0.299 * Color.red(this) + 0.587 * Color.green(this) + 0.114 * Color.blue(this)) / 255.0 < 0.5
+val Int.isColorDark: Boolean
+ get() = (0.299 * Color.red(this) + 0.587 * Color.green(this) + 0.114 * Color.blue(this)) / 255.0 < 0.5
fun Int.toHexString(withAlpha: Boolean = false, withHexPrefix: Boolean = true): String {
val hex = if (withAlpha) String.format("#%08X", this)
@@ -36,6 +36,9 @@ fun Int.toHSV(): FloatArray {
return hsv
}
+inline val Int.isColorOpaque: Boolean
+ get() = Color.alpha(this) == 255
+
fun FloatArray.toColor(): Int = Color.HSVToColor(this)
fun Int.isColorVisibleOn(@ColorInt color: Int, @IntRange(from = 0L, to = 255L) delta: Int = 25,
@@ -49,7 +52,7 @@ fun Int.isColorVisibleOn(@ColorInt color: Int, @IntRange(from = 0L, to = 255L) d
@ColorInt
fun Context.getDisabledColor(): Int {
val primaryColor = resolveColor(android.R.attr.textColorPrimary)
- val disabledColor = if (primaryColor.isColorDark()) Color.BLACK else Color.WHITE
+ val disabledColor = if (primaryColor.isColorDark) Color.BLACK else Color.WHITE
return disabledColor.adjustAlpha(0.3f)
}
@@ -86,11 +89,11 @@ fun Int.darken(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.1f): Int {
@ColorInt
fun Int.colorToBackground(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.1f): Int
- = if (isColorDark()) darken(factor) else lighten(factor)
+ = if (isColorDark) darken(factor) else lighten(factor)
@ColorInt
fun Int.colorToForeground(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.1f): Int
- = if (isColorDark()) lighten(factor) else darken(factor)
+ = if (isColorDark) lighten(factor) else darken(factor)
@Throws(IllegalArgumentException::class)
fun String.toColor(): Int {