fix: google tv virtual remote dpad
This commit is contained in:
@@ -9,6 +9,8 @@ import android.app.PictureInPictureParams
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.util.Rational
|
||||
import android.view.KeyEvent
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.FileProvider
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.android.RenderMode
|
||||
@@ -25,6 +27,7 @@ class MainActivity : FlutterActivity() {
|
||||
private val PIP_CHANNEL = "app.plezy/pip"
|
||||
private val EXTERNAL_PLAYER_CHANNEL = "app.plezy/external_player"
|
||||
private var watchNextPlugin: WatchNextPlugin? = null
|
||||
private var cachedFlutterView: android.view.View? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -39,6 +42,37 @@ class MainActivity : FlutterActivity() {
|
||||
handleWatchNextIntent(intent)
|
||||
}
|
||||
|
||||
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
||||
// Ensure FlutterView has focus for DPAD events so they reach Flutter's
|
||||
// key event system. Without this, Android's native focus navigation can
|
||||
// consume DPAD direction events (especially from the Google TV virtual
|
||||
// remote) before they reach Flutter.
|
||||
when (event.keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_UP,
|
||||
KeyEvent.KEYCODE_DPAD_DOWN,
|
||||
KeyEvent.KEYCODE_DPAD_LEFT,
|
||||
KeyEvent.KEYCODE_DPAD_RIGHT,
|
||||
KeyEvent.KEYCODE_DPAD_CENTER -> {
|
||||
val fv = cachedFlutterView ?: findFlutterView(window.decorView)?.also { cachedFlutterView = it }
|
||||
if (fv != null && !fv.hasFocus()) {
|
||||
fv.requestFocus()
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.dispatchKeyEvent(event)
|
||||
}
|
||||
|
||||
private fun findFlutterView(view: android.view.View): android.view.View? {
|
||||
if (view.javaClass.name.contains("FlutterView")) return view
|
||||
if (view is ViewGroup) {
|
||||
for (i in 0 until view.childCount) {
|
||||
val found = findFlutterView(view.getChildAt(i))
|
||||
if (found != null) return found
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
// Handle Watch Next deep link when app is already running
|
||||
|
||||
Reference in New Issue
Block a user