fix weird issue with toolbar keys having wrong color for their state

and remove related semi-workaround
This commit is contained in:
Helium314 2025-01-26 11:25:50 +01:00
parent 419c0d847b
commit 54f222c0ee
3 changed files with 7 additions and 9 deletions

View file

@ -65,10 +65,6 @@ class ClipboardHistoryView @JvmOverloads constructor(
keyBackgroundId = keyboardViewAttr.getResourceId(R.styleable.KeyboardView_keyBackground, 0)
keyboardViewAttr.recycle()
val keyboardAttr = context.obtainStyledAttributes(attrs, R.styleable.Keyboard, defStyle, R.style.SuggestionStripView)
// todo (maybe): setting the correct color only works because the activated state is inverted
// even when state is activated, the not activated color is set
// in suggestionStripView the same thing works correctly, wtf?
// need to properly fix it (and maybe undo the inverted isActivated) when adding a toggle key
getEnabledClipboardToolbarKeys(DeviceProtectedUtils.getSharedPreferences(context))
.forEach { toolbarKeys.add(createToolbarKey(context, KeyboardIconsSet.instance, it)) }
keyboardAttr.recycle()
@ -169,6 +165,9 @@ class ClipboardHistoryView @JvmOverloads constructor(
adapter = clipboardAdapter
layoutParams.width = ResourceUtils.getKeyboardWidth(context, Settings.getInstance().current)
}
// absurd workaround so Android sets the correct color from stateList (depending on "activated")
toolbarKeys.forEach { it.isEnabled = false; it.isEnabled = true }
}
fun stopClipboardHistory() {

View file

@ -626,9 +626,9 @@ private fun stateList(pressed: Int, normal: Int): ColorStateList {
return ColorStateList(states, intArrayOf(pressed, normal))
}
private fun activatedStateList(normal: Int, activated: Int): ColorStateList {
val states = arrayOf(intArrayOf(-android.R.attr.state_activated), intArrayOf(android.R.attr.state_activated))
return ColorStateList(states, intArrayOf(normal, activated))
private fun activatedStateList(activated: Int, normal: Int): ColorStateList {
val states = arrayOf(intArrayOf(android.R.attr.state_activated), intArrayOf(-android.R.attr.state_activated))
return ColorStateList(states, intArrayOf(activated, normal))
}
enum class ColorType {

View file

@ -26,7 +26,6 @@ import helium314.keyboard.latin.R
import helium314.keyboard.latin.databinding.ReorderDialogItemBinding
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.ToolbarKey.*
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.util.EnumMap
import java.util.Locale
@ -38,7 +37,7 @@ fun createToolbarKey(context: Context, iconsSet: KeyboardIconsSet, key: ToolbarK
val contentDescriptionId = context.resources.getIdentifier(key.name.lowercase(), "string", context.packageName)
if (contentDescriptionId != 0)
button.contentDescription = context.getString(contentDescriptionId)
button.isActivated = !when (key) {
button.isActivated = when (key) {
INCOGNITO -> Settings.readAlwaysIncognitoMode(DeviceProtectedUtils.getSharedPreferences(context))
ONE_HANDED -> Settings.getInstance().current.mOneHandedModeEnabled
AUTOCORRECT -> Settings.getInstance().current.mAutoCorrectionEnabledPerUserSettings