From 895bd88fe40823e827684a33ade3ce87866027ed Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 27 Nov 2017 15:10:15 +0100 Subject: [PATCH] adding dark version of theme colors --- .../commons/activities/BaseSimpleActivity.kt | 5 +- .../commons/extensions/Int.kt | 36 ++++ commons/src/main/res/values/colors.xml | 190 ++++++++++++++++++ 3 files changed, 227 insertions(+), 4 deletions(-) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt index 546586c3f..ea4ae5452 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt @@ -86,10 +86,7 @@ open class BaseSimpleActivity : AppCompatActivity() { fun updateStatusbarColor(color: Int) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - val hsv = FloatArray(3) - Color.colorToHSV(color, hsv) - hsv[2] *= 0.85f - window.statusBarColor = Color.HSVToColor(hsv) + window.statusBarColor = color.darkenColor() } } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Int.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Int.kt index 0408d9722..fbb6fc588 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Int.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Int.kt @@ -35,3 +35,39 @@ fun Int.getFormattedDuration(): String { fun Int.removeFlag(flag: Int) = (this or flag) - flag fun ClosedRange.random() = Random().nextInt(endInclusive - start) + start + +// taken from https://stackoverflow.com/a/40964456/1967672 +fun Int.darkenColor(): Int { + if (this == Color.WHITE) { + return -2105377 + } + var hsv = FloatArray(3) + Color.colorToHSV(this, hsv) + val hsl = hsv2hsl(hsv) + hsl[2] -= 12 / 100f + if (hsl[2] < 0) + hsl[2] = 0f + hsv = hsl2hsv(hsl) + return Color.HSVToColor(hsv) +} + +private fun hsl2hsv(hsl: FloatArray): FloatArray { + val hue = hsl[0] + var sat = hsl[1] + val light = hsl[2] + sat *= if (light < .5) light else 1 - light + return floatArrayOf(hue, 2f * sat / (light + sat), light + sat) +} + +private fun hsv2hsl(hsv: FloatArray): FloatArray { + val hue = hsv[0] + val sat = hsv[1] + val value = hsv[2] + + val newHue = (2f - sat) * value + var newSat = sat * value / if (newHue < 1f) newHue else 2f - newHue + if (newSat > 1f) + newSat = 1f + + return floatArrayOf(hue, newSat, newHue / 2f) +} diff --git a/commons/src/main/res/values/colors.xml b/commons/src/main/res/values/colors.xml index 5db40c4ff..c9c6b4e3d 100644 --- a/commons/src/main/res/values/colors.xml +++ b/commons/src/main/res/values/colors.xml @@ -56,6 +56,16 @@ #FF8F00 #FF6F00 + #FFDD76 + #FFD145 + #FFC711 + #EAB100 + #C99700 + #C28800 + #C27900 + #C26C00 + #C25400 + #BBDEFB #90CAF9 #64B5F6 @@ -66,6 +76,16 @@ #1565C0 #0D47A1 + #81C2F8 + #55AEF6 + #299AF3 + #0C89EE + #0A76CC + #1468B2 + #12579B + #0E4889 + #082E68 + #CFD8DC #B0BBC5 #90A4AE @@ -76,6 +96,16 @@ #37474F #263238 + #ACBCC2 + #8D9DAB + #6C8794 + #5B717C + #475D67 + #3B4E56 + #2C3A40 + #1E272B + #0D1113 + #D7CCC8 #BCAAA4 #A1887F @@ -86,6 +116,16 @@ #4E342E #3E2723 + #BDABA4 + #A28981 + #836960 + #69524A + #523A31 + #46312A + #362520 + #271A17 + #160E0C + #B2EBF2 #80DEEA #4DD0E1 @@ -96,6 +136,16 @@ #00838F #006064 + #7DDFEA + #4BD1E2 + #22BACE + #1C98A7 + #008697 + #007684 + #00606A + #004B52 + #002526 + #FFCCBC #FFAB91 #FF8A65 @@ -106,6 +156,16 @@ #D84315 #BF360C + #FF9E7F + #FF7D54 + #FF5B27 + #FF4105 + #E43700 + #CB3709 + #AF3812 + #A0310F + #852608 + #D1C4E9 #B39DDB #9575CD @@ -116,6 +176,16 @@ #4527A0 #311B92 + #AF98D9 + #9170CB + #7347BD + #603AA1 + #4D2B89 + #452682 + #3A2078 + #301B6F + #1F115E + #C8E6C9 #A5D6A7 #81C784 @@ -126,6 +196,16 @@ #2E7D32 #1B5E20 + #9ED3A0 + #7BC37E + #56B45B + #469E4A + #39843C + #317534 + #266229 + #1D5020 + #0D2E0F + #FFFFFF #EEEEEE #E0E0E0 @@ -136,6 +216,16 @@ #424242 #000000 + #DFDFDF + #D0D0D0 + #C2C2C2 + #9F9F9F + #7F7F7F + #565656 + #424242 + #232323 + #000000 + #C5CAE9 #9FA8DA #7986CB @@ -146,6 +236,16 @@ #283593 #1A237E + #99A2D9 + #7380C9 + #4C5EBA + #3E4DA1 + #2F3D88 + #29357D + #212D70 + #1A2363 + #0F154B + #B3E5FC #81D4fA #4fC3F7 @@ -156,6 +256,16 @@ #0277BD #01579B + #78D1FA + #46C0F8 + #14AFF5 + #029AE5 + #027FB8 + #0172A9 + #016094 + #015180 + #00355E + #DCEDC8 #C5E1A5 #AED581 @@ -166,6 +276,16 @@ #558B2F #33691E + #BFDE9A + #A8D277 + #91C653 + #7EB73C + #6B9C33 + #5D8631 + #4B7228 + #395D1F + #1C3910 + #F0F4C3 #E6EE9C #DCE775 @@ -176,6 +296,16 @@ #9E9D24 #827717 + #E3EB8F + #D9E567 + #CFDE40 + #C5D525 + #AAB820 + #929926 + #78831F + #6C6C18 + #4E480D + #FFE0B2 #FFCC80 #FFB74D @@ -186,6 +316,16 @@ #EF6C00 #E65100 + #FFC875 + #FFB443 + #FF9E0F + #E88A00 + #C27300 + #BE6A00 + #B85D00 + #B25100 + #A93B00 + #F8BBD0 #F48FB1 #F06292 @@ -196,6 +336,16 @@ #AD1457 #880E4F + #F383AA + #EF578A + #EB296A + #DA1558 + #B8124B + #A21347 + #8C1142 + #760D3B + #50082F + #E1BEE7 #CE93D8 #BA68C8 @@ -206,6 +356,16 @@ #6A1B9A #4A148C + #CD91D7 + #BA66C8 + #A241B2 + #843591 + #701B7E + #631977 + #54156F + #461166 + #2D0C56 + #FFCDD2 #EF9A9A #E57373 @@ -216,6 +376,16 @@ #C62828 #B71C1C + #FF909C + #E76565 + #DC3F3F + #EA1C17 + #E11B0C + #C41D18 + #A32222 + #931D1D + #821313 + #B2DFDB #80CBC4 #4DB6AC @@ -226,6 +396,16 @@ #00695C #004D40 + #87CDC7 + #54B9B0 + #398C84 + #1A746C + #005951 + #004C44 + #003C35 + #002B26 + #000F0D + #FFF9C4 #FFF590 #FFF176 @@ -236,4 +416,14 @@ #F9A825 #F57F17 + #FFF387 + #FFF053 + #FFEB39 + #FFE81A + #FDE300 + #F3C701 + #E7A603 + #DB8A06 + #C76208 +