make lightening and darkening colors more flexible
This commit is contained in:
parent
54bb10b802
commit
962e24712a
2 changed files with 19 additions and 3 deletions
|
@ -461,7 +461,7 @@ class CustomizationActivity : BaseSimpleActivity() {
|
|||
if (newColor == baseConfig.primaryColor) {
|
||||
apply_to_all.setBackgroundResource(R.drawable.button_background_rounded)
|
||||
} else {
|
||||
val applyBackground = resources.getDrawable(R.drawable.button_background_rounded) as RippleDrawable
|
||||
val applyBackground = resources.getDrawable(R.drawable.button_background_rounded, theme) as RippleDrawable
|
||||
(applyBackground as LayerDrawable).findDrawableByLayerId(R.id.button_background_holder).applyColorFilter(newColor)
|
||||
apply_to_all.background = applyBackground
|
||||
}
|
||||
|
|
|
@ -109,12 +109,12 @@ fun Int.flipBit(bit: Int) = if (this and bit == 0) addBit(bit) else removeBit(bi
|
|||
fun ClosedRange<Int>.random() = Random().nextInt(endInclusive - start) + start
|
||||
|
||||
// taken from https://stackoverflow.com/a/40964456/1967672
|
||||
fun Int.darkenColor(): Int {
|
||||
fun Int.darkenColor(factor: Int = 8): Int {
|
||||
if (this == Color.WHITE || this == Color.BLACK) {
|
||||
return this
|
||||
}
|
||||
|
||||
val DARK_FACTOR = 8
|
||||
val DARK_FACTOR = factor
|
||||
var hsv = FloatArray(3)
|
||||
Color.colorToHSV(this, hsv)
|
||||
val hsl = hsv2hsl(hsv)
|
||||
|
@ -125,6 +125,22 @@ fun Int.darkenColor(): Int {
|
|||
return Color.HSVToColor(hsv)
|
||||
}
|
||||
|
||||
fun Int.lightenColor(factor: Int = 8): Int {
|
||||
if (this == Color.WHITE || this == Color.BLACK) {
|
||||
return this
|
||||
}
|
||||
|
||||
val LIGHT_FACTOR = factor
|
||||
var hsv = FloatArray(3)
|
||||
Color.colorToHSV(this, hsv)
|
||||
val hsl = hsv2hsl(hsv)
|
||||
hsl[2] += LIGHT_FACTOR / 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]
|
||||
|
|
Loading…
Reference in a new issue