mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
Add right-stick page scrolling to launcher
This commit is contained in:
1 parent
c0abf31a6b
commit
01b2527e0f
1 file changed
+19
@@ -2208,10 +2208,29 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
|
||||
private val triggerKeys = com.droiddeck.launcher.input.TriggerKeys { dispatchKeyEvent(it) }
|
||||
private var rightStickScrollAt = 0L
|
||||
|
||||
private fun scrollPageWithRightStick(event: android.view.MotionEvent): Boolean {
|
||||
if (event.actionMasked != android.view.MotionEvent.ACTION_MOVE ||
|
||||
!event.isFromSource(android.view.InputDevice.SOURCE_JOYSTICK)) return false
|
||||
val device = event.device ?: return false
|
||||
val axis = if (device.getMotionRange(android.view.MotionEvent.AXIS_RY, event.source) != null)
|
||||
android.view.MotionEvent.AXIS_RY else android.view.MotionEvent.AXIS_RZ
|
||||
val value = event.getAxisValue(axis)
|
||||
if (kotlin.math.abs(value) < 0.55f) return false
|
||||
val now = android.os.SystemClock.uptimeMillis()
|
||||
if (now - rightStickScrollAt < 130L) return true
|
||||
rightStickScrollAt = now
|
||||
val key = if (value > 0f) android.view.KeyEvent.KEYCODE_PAGE_DOWN else android.view.KeyEvent.KEYCODE_PAGE_UP
|
||||
dispatchKeyEvent(android.view.KeyEvent(now, now, android.view.KeyEvent.ACTION_DOWN, key, 0))
|
||||
dispatchKeyEvent(android.view.KeyEvent(now, now, android.view.KeyEvent.ACTION_UP, key, 0))
|
||||
return true
|
||||
}
|
||||
|
||||
override fun dispatchGenericMotionEvent(event: android.view.MotionEvent): Boolean {
|
||||
if (compatLaunch != null && !compatLaunch!!.loading.ended &&
|
||||
com.droiddeck.launcher.input.PadBridge.isControllerMotionEvent(event)) return true
|
||||
if (scrollPageWithRightStick(event)) return true
|
||||
triggerKeys.onMotion(event)
|
||||
return super.dispatchGenericMotionEvent(event)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user