support predictive back gestures

This commit is contained in:
Chloe committed 2025-04-24 11:59:31 -07:00
1 parent 776a4fa468
commit 67ca7707d8
3 files changed
+29 -3

No files matched your search

+2 -1
View File
@@ -39,8 +39,9 @@
android:label="@string/app_name"
android:hasFragileUserData="true"
android:requestLegacyExternalStorage="true"
android:enableOnBackInvokedCallback="true"
android:theme="@style/Theme.GeodeLauncher"
tools:targetApi="31">
tools:targetApi="35">
<activity
android:name=".AltMainActivity"
android:exported="false"
@@ -14,6 +14,7 @@ import android.util.Log
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.FrameLayout
import android.window.OnBackInvokedDispatcher
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.ui.platform.ComposeView
@@ -121,6 +122,13 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
return
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
onBackInvokedDispatcher.registerOnBackInvokedCallback(OnBackInvokedDispatcher.PRIORITY_DEFAULT) {
mGLSurfaceView?.sendKeyBack()
}
mGLSurfaceView?.manualBackEvents = true
}
}
private fun createVersionFile() {
@@ -55,6 +55,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
}
var sendTimestampEvents = false
var manualBackEvents = false
var cocos2dxEditText: Cocos2dxEditText? = null
set(value) {
@@ -249,7 +250,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
private fun legacyKeyDown(keyCode: Int, keyEvent: KeyEvent): Boolean {
return when (keyCode) {
KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_MENU -> {
if (keyEvent.repeatCount != 0 || BaseRobTopActivity.blockBackButton) {
if (keyEvent.repeatCount != 0 || BaseRobTopActivity.blockBackButton || manualBackEvents) {
return true
}
queueEvent { cocos2dxRenderer.handleKeyDown(keyCode) }
@@ -259,6 +260,22 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
}
}
fun sendKeyBack() {
if (BaseRobTopActivity.blockBackButton) {
return
}
if (useKeyboardEvents) {
queueEvent {
cocos2dxRenderer.handleKeyDown(KeyEvent.KEYCODE_BACK)
}
} else {
queueEvent {
GeodeUtils.nativeKeyDown(KeyEvent.KEYCODE_BACK, 0, false)
}
}
}
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
if (!useKeyboardEvents) {
return legacyKeyDown(keyCode, event)
@@ -270,7 +287,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
super.onKeyDown(keyCode, event)
}
else -> {
if (BaseRobTopActivity.blockBackButton) {
if (BaseRobTopActivity.blockBackButton || manualBackEvents) {
return true
}