diff options
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt | 8 |
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() } |