From 971738ae5942c3439568c54393708a3dd63c87f6 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 22 Jun 2017 19:23:29 -0700 Subject: Change color lighten and darken --- .idea/misc.xml | 2 +- library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 7319f02..085136f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -53,7 +53,7 @@ - + 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 eaa6d91..2c5a395 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt @@ -71,14 +71,14 @@ fun Int.withMinAlpha(@IntRange(from = 0L, to = 255L) alpha: Int): Int @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() } + .map { Math.min(255f * factor + it, 255f).toInt() } return Color.argb(Color.alpha(this), red, green, blue) } @ColorInt fun Int.darken(@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.max(it * (1 - factor), 0f).toInt() } + .map { Math.max(it - 255f * factor, 0f).toInt() } return Color.argb(Color.alpha(this), red, green, blue) } -- cgit v1.2.3