aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-22 19:23:29 -0700
committerAllan Wang <me@allanwang.ca>2017-06-22 19:23:29 -0700
commit971738ae5942c3439568c54393708a3dd63c87f6 (patch)
treeb3a6f6ff623f163ac68b2e6f2d2c0776265cb473
parent1d1322523492f3cc805d364ca9e3ef9a25b0fbad (diff)
downloadkau-971738ae5942c3439568c54393708a3dd63c87f6.tar.gz
kau-971738ae5942c3439568c54393708a3dd63c87f6.tar.bz2
kau-971738ae5942c3439568c54393708a3dd63c87f6.zip
Change color lighten and darken
-rw-r--r--.idea/misc.xml2
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt4
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 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
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)
}