rename stateList to pressedStateList for clarification

This commit is contained in:
Helium314 2025-01-26 11:27:40 +01:00
parent 54f222c0ee
commit 833aa321b9

View file

@ -195,12 +195,12 @@ class DynamicColors(context: Context, override val themeStyle: String, override
}
adjustedBackgroundStateList =
if (themeStyle == STYLE_HOLO) {
stateList(accent, adjustedBackground)
pressedStateList(accent, adjustedBackground)
} else if (isNight) {
if (hasKeyBorders) stateList(doubleAdjustedAccent, keyBackground)
else stateList(adjustedAccent, adjustedKeyBackground)
if (hasKeyBorders) pressedStateList(doubleAdjustedAccent, keyBackground)
else pressedStateList(adjustedAccent, adjustedKeyBackground)
} else {
stateList(accent, Color.WHITE)
pressedStateList(accent, Color.WHITE)
}
val stripBackground = if (keyboardBackground == null && !hasKeyBorders) {
@ -210,7 +210,7 @@ class DynamicColors(context: Context, override val themeStyle: String, override
}
val pressedStripElementBackground = if (keyboardBackground == null) adjustedBackground
else if (isDarkColor(background)) 0x22ffffff else 0x11000000
stripBackgroundList = stateList(pressedStripElementBackground, stripBackground)
stripBackgroundList = pressedStateList(pressedStripElementBackground, stripBackground)
adjustedBackgroundFilter =
if (themeStyle == STYLE_HOLO) colorFilter(adjustedBackground)
@ -218,47 +218,47 @@ class DynamicColors(context: Context, override val themeStyle: String, override
if (hasKeyBorders) {
backgroundStateList =
if (!isNight) stateList(adjustedFunctionalKey, background)
else stateList(adjustedKeyBackground, background)
if (!isNight) pressedStateList(adjustedFunctionalKey, background)
else pressedStateList(adjustedKeyBackground, background)
keyStateList =
if (!isNight) stateList(adjustedBackground, keyBackground)
else stateList(adjustedKeyBackground, keyBackground)
if (!isNight) pressedStateList(adjustedBackground, keyBackground)
else pressedStateList(adjustedKeyBackground, keyBackground)
functionalKeyStateList =
if (!isNight) stateList(doubleAdjustedFunctionalKey, functionalKey)
else stateList(functionalKey, doubleAdjustedKeyBackground)
if (!isNight) pressedStateList(doubleAdjustedFunctionalKey, functionalKey)
else pressedStateList(functionalKey, doubleAdjustedKeyBackground)
actionKeyStateList =
if (!isNight) stateList(gesture, accent)
else stateList(doubleAdjustedAccent, accent)
if (!isNight) pressedStateList(gesture, accent)
else pressedStateList(doubleAdjustedAccent, accent)
spaceBarStateList =
if (themeStyle == STYLE_HOLO) stateList(spaceBar, spaceBar)
if (themeStyle == STYLE_HOLO) pressedStateList(spaceBar, spaceBar)
else keyStateList
} else {
// need to set color to background if key borders are disabled, or there will be ugly keys
backgroundStateList =
if (!isNight) stateList(adjustedFunctionalKey, background)
else stateList(adjustedKeyBackground, background)
if (!isNight) pressedStateList(adjustedFunctionalKey, background)
else pressedStateList(adjustedKeyBackground, background)
keyStateList =
if (!isNight) stateList(adjustedFunctionalKey, Color.TRANSPARENT)
else stateList(functionalKey, Color.TRANSPARENT)
if (!isNight) pressedStateList(adjustedFunctionalKey, Color.TRANSPARENT)
else pressedStateList(functionalKey, Color.TRANSPARENT)
functionalKeyStateList =
if (themeStyle == STYLE_HOLO) stateList(functionalKey, Color.TRANSPARENT)
if (themeStyle == STYLE_HOLO) pressedStateList(functionalKey, Color.TRANSPARENT)
else keyStateList
actionKeyStateList =
if (themeStyle == STYLE_HOLO) stateList(accent, Color.TRANSPARENT)
else if (!isNight) stateList(gesture, accent)
else stateList(doubleAdjustedAccent, accent)
if (themeStyle == STYLE_HOLO) pressedStateList(accent, Color.TRANSPARENT)
else if (!isNight) pressedStateList(gesture, accent)
else pressedStateList(doubleAdjustedAccent, accent)
spaceBarStateList =
if (!isNight) stateList(gesture, adjustedFunctionalKey)
else stateList(adjustedKeyBackground, spaceBar)
if (!isNight) pressedStateList(gesture, adjustedFunctionalKey)
else pressedStateList(adjustedKeyBackground, spaceBar)
}
keyTextFilter = colorFilter(keyText)
@ -409,7 +409,7 @@ class DefaultColors (
adjustedBackground = darken(background)
doubleAdjustedBackground = darken(adjustedBackground)
}
adjustedBackgroundStateList = stateList(doubleAdjustedBackground, adjustedBackground)
adjustedBackgroundStateList = pressedStateList(doubleAdjustedBackground, adjustedBackground)
val stripBackground: Int
val pressedStripElementBackground: Int
@ -424,7 +424,7 @@ class DefaultColors (
stripBackground = adjustedBackground
pressedStripElementBackground = doubleAdjustedBackground
}
stripBackgroundList = stateList(pressedStripElementBackground, stripBackground)
stripBackgroundList = pressedStateList(pressedStripElementBackground, stripBackground)
if (themeStyle == STYLE_HOLO && keyboardBackground == null) {
val darkerBackground = adjustLuminosityAndKeepAlpha(background, -0.2f)
@ -437,22 +437,22 @@ class DefaultColors (
adjustedBackgroundFilter = colorFilter(adjustedBackground)
if (hasKeyBorders) {
backgroundStateList = stateList(brightenOrDarken(background, true), background)
keyStateList = if (themeStyle == STYLE_HOLO) stateList(keyBackground, keyBackground)
else stateList(brightenOrDarken(keyBackground, true), keyBackground)
functionalKeyStateList = stateList(brightenOrDarken(functionalKey, true), functionalKey)
backgroundStateList = pressedStateList(brightenOrDarken(background, true), background)
keyStateList = if (themeStyle == STYLE_HOLO) pressedStateList(keyBackground, keyBackground)
else pressedStateList(brightenOrDarken(keyBackground, true), keyBackground)
functionalKeyStateList = pressedStateList(brightenOrDarken(functionalKey, true), functionalKey)
actionKeyStateList = if (themeStyle == STYLE_HOLO) functionalKeyStateList
else stateList(brightenOrDarken(accent, true), accent)
spaceBarStateList = if (themeStyle == STYLE_HOLO) stateList(spaceBar, spaceBar)
else stateList(brightenOrDarken(spaceBar, true), spaceBar)
else pressedStateList(brightenOrDarken(accent, true), accent)
spaceBarStateList = if (themeStyle == STYLE_HOLO) pressedStateList(spaceBar, spaceBar)
else pressedStateList(brightenOrDarken(spaceBar, true), spaceBar)
} else {
// need to set color to background if key borders are disabled, or there will be ugly keys
backgroundStateList = stateList(brightenOrDarken(background, true), background)
keyStateList = stateList(keyBackground, Color.TRANSPARENT)
backgroundStateList = pressedStateList(brightenOrDarken(background, true), background)
keyStateList = pressedStateList(keyBackground, Color.TRANSPARENT)
functionalKeyStateList = keyStateList
actionKeyStateList = if (themeStyle == STYLE_HOLO) functionalKeyStateList
else stateList(brightenOrDarken(accent, true), accent)
spaceBarStateList = stateList(brightenOrDarken(spaceBar, true), spaceBar)
else pressedStateList(brightenOrDarken(accent, true), accent)
spaceBarStateList = pressedStateList(brightenOrDarken(spaceBar, true), spaceBar)
}
keyTextFilter = colorFilter(keyText)
actionKeyIconColorFilter = when {
@ -556,7 +556,7 @@ class AllColors(private val colorMap: EnumMap<ColorType, Int>, override val them
override fun get(color: ColorType): Int = colorMap[color] ?: color.default()
override fun setColor(drawable: Drawable, color: ColorType) {
val colorStateList = stateListMap.getOrPut(color) { stateList(brightenOrDarken(get(color), true), get(color)) }
val colorStateList = stateListMap.getOrPut(color) { pressedStateList(brightenOrDarken(get(color), true), get(color)) }
DrawableCompat.setTintMode(drawable, PorterDuff.Mode.MULTIPLY)
DrawableCompat.setTintList(drawable, colorStateList)
}
@ -621,7 +621,7 @@ private fun colorFilter(color: Int, mode: BlendModeCompat = BlendModeCompat.MODU
return BlendModeColorFilterCompat.createBlendModeColorFilterCompat(color, mode)!!
}
private fun stateList(pressed: Int, normal: Int): ColorStateList {
private fun pressedStateList(pressed: Int, normal: Int): ColorStateList {
val states = arrayOf(intArrayOf(android.R.attr.state_pressed), intArrayOf(-android.R.attr.state_pressed))
return ColorStateList(states, intArrayOf(pressed, normal))
}