From be5b4d980d1da12342c11176905bc5e3a975a20c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 15 Nov 2021 16:52:54 -0800 Subject: [PATCH] Added nativeGetHintBoolean for Java code --- .../main/java/org/libsdl/app/SDLActivity.java | 5 +++-- src/core/android/SDL_android.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index a65c6a136..02c64b1bd 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -499,8 +499,8 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh // If we do, the normal hardware back button will no longer work and people have to use home, // but the mouse right click will work. // - String trapBack = SDLActivity.nativeGetHint("SDL_ANDROID_TRAP_BACK_BUTTON"); - if ((trapBack != null) && trapBack.equals("1")) { + boolean trapBack = SDLActivity.nativeGetHintBoolean("SDL_ANDROID_TRAP_BACK_BUTTON", false); + if (trapBack) { // Exit and let the mouse handler handle this button (if appropriate) return; } @@ -803,6 +803,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh public static native void onNativeSurfaceChanged(); public static native void onNativeSurfaceDestroyed(); public static native String nativeGetHint(String name); + public static native boolean nativeGetHintBoolean(String name, boolean default_value); public static native void nativeSetenv(String name, String value); public static native void onNativeOrientationChanged(int orientation); public static native void nativeAddTouch(int touchId, String name); diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index ac3d74493..e23841413 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -148,6 +148,10 @@ JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetHint)( JNIEnv *env, jclass cls, jstring name); +JNIEXPORT jboolean JNICALL SDL_JAVA_INTERFACE(nativeGetHintBoolean)( + JNIEnv *env, jclass cls, + jstring name, jboolean default_value); + JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetenv)( JNIEnv *env, jclass cls, jstring name, jstring value); @@ -189,6 +193,7 @@ static JNINativeMethod SDLActivity_tab[] = { { "nativeResume", "()V", SDL_JAVA_INTERFACE(nativeResume) }, { "nativeFocusChanged", "(Z)V", SDL_JAVA_INTERFACE(nativeFocusChanged) }, { "nativeGetHint", "(Ljava/lang/String;)Ljava/lang/String;", SDL_JAVA_INTERFACE(nativeGetHint) }, + { "nativeGetHintBoolean", "(Ljava/lang/String;Z)Z", SDL_JAVA_INTERFACE(nativeGetHintBoolean) }, { "nativeSetenv", "(Ljava/lang/String;Ljava/lang/String;)V", SDL_JAVA_INTERFACE(nativeSetenv) }, { "onNativeOrientationChanged", "(I)V", SDL_JAVA_INTERFACE(onNativeOrientationChanged) }, { "nativeAddTouch", "(ILjava/lang/String;)V", SDL_JAVA_INTERFACE(nativeAddTouch) }, @@ -1306,6 +1311,19 @@ JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetHint)( return result; } +JNIEXPORT jboolean JNICALL SDL_JAVA_INTERFACE(nativeGetHintBoolean)( + JNIEnv *env, jclass cls, + jstring name, jboolean default_value) +{ + jboolean result; + + const char *utfname = (*env)->GetStringUTFChars(env, name, NULL); + result = SDL_GetHintBoolean(utfname, default_value); + (*env)->ReleaseStringUTFChars(env, name, utfname); + + return result; +} + JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetenv)( JNIEnv *env, jclass cls, jstring name, jstring value)