From 37a2059fa15f23093fc38bca236f517ef96b030d Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 12 Jun 2017 19:16:51 -0700 Subject: Add with alpha fun --- library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt | 8 ++++++++ 1 file changed, 8 insertions(+) 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 @@ -56,6 +56,14 @@ fun Int.adjustAlpha(factor: Float): Int { return Color.argb(alpha, Color.red(this), Color.green(this), Color.blue(this)) } +@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)) -- cgit v1.2.3