From be27c4f8770e8acc600ac6d2bdf1605ff720f9b2 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:09:01 -0700 Subject: [PATCH] NativeLibrary: Create displayToastMsg Method --- .../org/dolphinemu/dolphinemu/NativeLibrary.java | 12 +++++++++--- Source/Android/jni/AndroidCommon/IDCache.cpp | 8 ++++++++ Source/Android/jni/AndroidCommon/IDCache.h | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index b83a489256..a3d02e31ee 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -454,6 +454,14 @@ public final class NativeLibrary private static native String GetCurrentTitleDescriptionUnchecked(); + @Keep + public static void displayToastMsg(final String text, final boolean long_length) + { + final int length = long_length ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT; + new Handler(Looper.getMainLooper()) + .post(() -> Toast.makeText(DolphinApplication.getAppContext(), text, length).show()); + } + @Keep public static boolean displayAlertMsg(final String caption, final String text, final boolean yesNo, final boolean isWarning, final boolean nonBlocking) @@ -466,9 +474,7 @@ public final class NativeLibrary // and are allowed to block. As a fallback, we can use toasts. if (emulationActivity == null || nonBlocking) { - new Handler(Looper.getMainLooper()).post( - () -> Toast.makeText(DolphinApplication.getAppContext(), text, Toast.LENGTH_LONG) - .show()); + displayToastMsg(text, true); } else { diff --git a/Source/Android/jni/AndroidCommon/IDCache.cpp b/Source/Android/jni/AndroidCommon/IDCache.cpp index a19423d67c..5fe151278f 100644 --- a/Source/Android/jni/AndroidCommon/IDCache.cpp +++ b/Source/Android/jni/AndroidCommon/IDCache.cpp @@ -12,6 +12,7 @@ static JavaVM* s_java_vm; static jclass s_string_class; static jclass s_native_library_class; +static jmethodID s_display_toast_msg; static jmethodID s_display_alert_msg; static jmethodID s_update_touch_pointer; static jmethodID s_on_title_changed; @@ -146,6 +147,11 @@ jclass GetNativeLibraryClass() return s_native_library_class; } +jmethodID GetDisplayToastMsg() +{ + return s_display_toast_msg; +} + jmethodID GetDisplayAlertMsg() { return s_display_alert_msg; @@ -528,6 +534,8 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) const jclass native_library_class = env->FindClass("org/dolphinemu/dolphinemu/NativeLibrary"); s_native_library_class = reinterpret_cast(env->NewGlobalRef(native_library_class)); + s_display_toast_msg = + env->GetStaticMethodID(s_native_library_class, "displayToastMsg", "(Ljava/lang/String;Z)V"); s_display_alert_msg = env->GetStaticMethodID(s_native_library_class, "displayAlertMsg", "(Ljava/lang/String;Ljava/lang/String;ZZZ)Z"); s_update_touch_pointer = diff --git a/Source/Android/jni/AndroidCommon/IDCache.h b/Source/Android/jni/AndroidCommon/IDCache.h index 604b68e38e..c324b6cb19 100644 --- a/Source/Android/jni/AndroidCommon/IDCache.h +++ b/Source/Android/jni/AndroidCommon/IDCache.h @@ -12,6 +12,7 @@ JNIEnv* GetEnvForThread(); jclass GetStringClass(); jclass GetNativeLibraryClass(); +jmethodID GetDisplayToastMsg(); jmethodID GetDisplayAlertMsg(); jmethodID GetUpdateTouchPointer(); jmethodID GetOnTitleChanged();