Open tmm1 opened 6 years ago
@tmm1 Could you show me the codes about DPAD?
For SwitchButton I think you need onKeyDown https://developer.android.com/training/game-controllers/controller-input.html#dpad
And also use setOnFocusChangeListener to change the style on focus, so user can tell it is active
The code for handling DPAD is not too complicated. I used kotlin subclass, but it should be easy to add the same thing to the java base class.
class MySwitchMultiButton(context: Context, attributeSet: AttributeSet): SwitchMultiButton(context, attributeSet) {
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
KEYCODE_DPAD_LEFT -> {
if (selectedTab > 0) {
selectedTab -= 1
return true
}
}
KEYCODE_DPAD_RIGHT -> {
val field = SwitchMultiButton::class.java.declaredFields.find { it.name == "mTabNum" }!!
field.isAccessible = true
if (selectedTab < field.getInt(this)-1) {
selectedTab += 1
return true
}
}
}
return super.onKeyDown(keyCode, event)
}
}
I think onDraw
should also check isFocused()
and change the style/color so the user knows the switch button is focused on the screen.
@tmm1 Hey gay, I don't know how to test TV Application by remote. I have created a branch (v1.1.6_tv) base on your codes. It will be thankful if you could test it.
FYI, In Android Studio you should be able to make TV emulator and use on-screen remote dpad.
The SwitchButton renders to screen as expected, but it is not possible to use DPAD remote to navigate or select the buttons.