0.1.0-2-beta.1.fix.4
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
// file: Android/common/src/main/java/com/sasedev/games/common/NativeBridge.java
|
||||
// version: 3
|
||||
// version: 4
|
||||
|
||||
package com.sasedev.games.common;
|
||||
|
||||
/** Stable Java/JNI platform bridge contract shared by Android game applications. */
|
||||
public final class NativeBridge {
|
||||
private static final int CONTRACT_VERSION = 2;
|
||||
private static final int CONTRACT_VERSION = 3;
|
||||
|
||||
private NativeBridge() {
|
||||
}
|
||||
@@ -26,9 +26,6 @@ public final class NativeBridge {
|
||||
*/
|
||||
public static native int nativeContractVersion();
|
||||
|
||||
/** Sends a platform-native Back request to the Rust SDL runtime. */
|
||||
private static native void nativeRequestPlatformBack();
|
||||
|
||||
/** Verifies that the loaded native bridge matches the Java contract. */
|
||||
public static void requireCompatibleContract() {
|
||||
final int nativeVersion = nativeContractVersion();
|
||||
@@ -37,9 +34,4 @@ public final class NativeBridge {
|
||||
"Native bridge contract mismatch: java=" + CONTRACT_VERSION + ", native=" + nativeVersion);
|
||||
}
|
||||
}
|
||||
|
||||
/** Requests Back through the common Rust engine quit policy. */
|
||||
public static void requestPlatformBack() {
|
||||
nativeRequestPlatformBack();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// file: Android/common/src/main/java/com/sasedev/games/common/SaseGameActivity.java
|
||||
// version: 5
|
||||
// version: 6
|
||||
|
||||
package com.sasedev.games.common;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Common Android activity boundary for games.sasedev applications.
|
||||
@@ -12,24 +13,18 @@ import android.os.Bundle;
|
||||
* <p>The SDL3 Android AAR supplies the common {@code SDLActivity} host. Game-specific activities extend this class.</p>
|
||||
*/
|
||||
public abstract class SaseGameActivity extends org.libsdl.app.SDLActivity {
|
||||
private static final String LOG_TAG = "games.sasedev";
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
NativeBridge.requireCompatibleContract();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
Api33BackHandler.register(this);
|
||||
if (Build.VERSION.SDK_INT >= 36) {
|
||||
Api36BackObserver.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
NativeBridge.requestPlatformBack();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected final String[] getLibraries() {
|
||||
@@ -43,15 +38,15 @@ public abstract class SaseGameActivity extends org.libsdl.app.SDLActivity {
|
||||
*/
|
||||
public abstract String gameId();
|
||||
|
||||
/** API 33+ predictive Back bridge isolated from pre-33 class loading. */
|
||||
private static final class Api33BackHandler {
|
||||
private Api33BackHandler() {
|
||||
/** API 36+ non-consuming Back observer isolated from older Android runtimes. */
|
||||
private static final class Api36BackObserver {
|
||||
private Api36BackObserver() {
|
||||
}
|
||||
|
||||
static void register(SaseGameActivity activity) {
|
||||
activity.getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
|
||||
android.window.OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
NativeBridge::requestPlatformBack);
|
||||
android.window.OnBackInvokedDispatcher.PRIORITY_SYSTEM_NAVIGATION_OBSERVER,
|
||||
() -> Log.i(LOG_TAG, "Android system Back observed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user