aboutsummaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-12 19:16:51 -0700
committerAllan Wang <me@allanwang.ca>2017-06-12 19:16:51 -0700
commit37a2059fa15f23093fc38bca236f517ef96b030d (patch)
tree79106e7edb3b28053a6704b36a9b830c79405a52 /library
parent5431209bf04f1ea7a4d283893e0d8a4e796b0c90 (diff)
downloadkau-37a2059fa15f23093fc38bca236f517ef96b030d.tar.gz
kau-37a2059fa15f23093fc38bca236f517ef96b030d.tar.bz2
kau-37a2059fa15f23093fc38bca236f517ef96b030d.zip
Add with alpha fun
Diffstat (limited to 'library')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt8
1 files changed, 8 insertions, 0 deletions
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 0e835eb..e7a3e21 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
@@ -57,6 +57,14 @@ fun Int.adjustAlpha(factor: Float): Int {
}
@ColorInt
+fun Int.withAlpha(@IntRange(from = 0L, to = 255L) alpha: Int): Int
+ = Color.argb(alpha, Color.red(this), Color.green(this), Color.blue(this))
+
+@ColorInt
+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 {
val (red, green, blue) = intArrayOf(Color.red(this), Color.green(this), Color.blue(this))
.map { Math.min(it * (1 + factor), 255.0f).toInt() }