Browse Source

[android, ui] Fix sticky focus behavior (#3242)

This fixes an issue where game cards can stack focus highlights by touching and sliding in Grid/List views. Running and exiting the game by touch leaves a sticky focus that is not cleared. It is again possible to stack focus highlights that way.

The first commit fixes the bug, the second refactors and simplifies the state management in GradientBorderCardView.

WIP for now, until I thoroughly test it.

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3242
Reviewed-by: crueter <crueter@eden-emu.dev>
Reviewed-by: DraVee <dravee@eden-emu.dev>
Co-authored-by: Mike22 <misakupka@gmail.com>
Co-committed-by: Mike22 <misakupka@gmail.com>
pull/3247/head
Mike22 2 weeks ago
committed by crueter
parent
commit
7234875a53
No known key found for this signature in database GPG Key ID: 425ACD2D4830EBC6
  1. 23
      src/android/app/src/main/java/org/yuzu/yuzu_emu/views/GradientBorderCardView.kt

23
src/android/app/src/main/java/org/yuzu/yuzu_emu/views/GradientBorderCardView.kt

@ -35,6 +35,14 @@ class GradientBorderCardView @JvmOverloads constructor(
updateThemeState() updateThemeState()
} }
private fun updateBorderState() {
val shouldShow = isPressed || isFocused || isSelected
if (showGradientBorder != shouldShow) {
showGradientBorder = shouldShow
invalidate()
}
}
private fun updateThemeState() { private fun updateThemeState() {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val themeIndex = try { val themeIndex = try {
@ -43,6 +51,7 @@ class GradientBorderCardView @JvmOverloads constructor(
0 // Default to Eden theme if error 0 // Default to Eden theme if error
} }
isEdenTheme = themeIndex == 0 isEdenTheme = themeIndex == 0
invalidate()
} }
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
@ -93,27 +102,22 @@ class GradientBorderCardView @JvmOverloads constructor(
override fun onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect?) { override fun onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect?) {
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect) super.onFocusChanged(gainFocus, direction, previouslyFocusedRect)
showGradientBorder = gainFocus
invalidate()
updateBorderState()
} }
override fun setSelected(selected: Boolean) { override fun setSelected(selected: Boolean) {
super.setSelected(selected) super.setSelected(selected)
showGradientBorder = selected
invalidate()
updateBorderState()
} }
override fun setPressed(pressed: Boolean) { override fun setPressed(pressed: Boolean) {
super.setPressed(pressed) super.setPressed(pressed)
if (pressed) {
showGradientBorder = true
invalidate()
}
updateBorderState()
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {
super.onDraw(canvas) super.onDraw(canvas)
if (showGradientBorder && !isPressed) {
if (showGradientBorder) {
canvas.drawPath(borderPath, borderPaint) canvas.drawPath(borderPath, borderPaint)
} }
} }
@ -121,6 +125,5 @@ class GradientBorderCardView @JvmOverloads constructor(
override fun onAttachedToWindow() { override fun onAttachedToWindow() {
super.onAttachedToWindow() super.onAttachedToWindow()
updateThemeState() updateThemeState()
requestLayout()
} }
} }
Loading…
Cancel
Save