[Commits] SDL: Provide the correct state of the on-screen keyboard to the ...

libsdl.org revision control commits-owner at libsdl.org
Sun Aug 13 21:05:20 PDT 2017


details:   https://hg.libsdl.org/SDL/rev/ab3f2402a777
changeset: 11271:ab3f2402a777
user:      Sam Lantinga <slouken at libsdl.org>
date:      Sun Aug 13 21:05:15 2017 -0700
description:
Provide the correct state of the on-screen keyboard to the API (patch from Sylvain)

diffstat:

 android-project/src/org/libsdl/app/SDLActivity.java |  44 +++++++++++++++++++++
 src/core/android/SDL_android.c                      |  14 ++++++
 src/core/android/SDL_android.h                      |   1 +
 src/video/android/SDL_androidkeyboard.c             |   2 +-
 4 files changed, 60 insertions(+), 1 deletions(-)

diffs (122 lines):

diff -r 31ce9a8ce2bd -r ab3f2402a777 android-project/src/org/libsdl/app/SDLActivity.java
--- a/android-project/src/org/libsdl/app/SDLActivity.java	Sun Aug 13 20:55:59 2017 -0700
+++ b/android-project/src/org/libsdl/app/SDLActivity.java	Sun Aug 13 21:05:15 2017 -0700
@@ -59,6 +59,7 @@
     protected static SDLActivity mSingleton;
     protected static SDLSurface mSurface;
     protected static View mTextEdit;
+    protected static boolean mScreenKeyboardShown;
     protected static ViewGroup mLayout;
     protected static SDLJoystickHandler mJoystickHandler;
     protected static SDLHapticHandler mHapticHandler;
@@ -440,6 +441,8 @@
 
                     InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                     imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0);
+                    
+                    mScreenKeyboardShown = false;
                 }
                 break;
             case COMMAND_SET_KEEP_SCREEN_ON:
@@ -568,6 +571,45 @@
       return;
     }
 
+
+    /**
+     * This method is called by SDL using JNI.
+     */
+    public static boolean isScreenKeyboardShown() 
+    {
+       if (mTextEdit == null) {
+          return false;
+       }
+
+       if (mScreenKeyboardShown == false) {
+          return false;
+       }
+
+       InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+       if (imm.isAcceptingText()) {
+          return true;
+       }
+
+       return false;
+    }
+
+
+
+    /**
+     * This method is called by SDL using JNI.
+     */
+    public static int openURL(String url)
+    {
+       try {
+          Intent i = new Intent(Intent.ACTION_VIEW);
+          i.setData(Uri.parse(url));
+          mSingleton.startActivity(i);
+       } catch (Exception ex) {
+          return -1;
+       }
+       return 0;
+    }
+
     /**
      * This method is called by SDL using JNI.
      */
@@ -647,6 +689,8 @@
 
             InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
             imm.showSoftInput(mTextEdit, 0);
+
+            mScreenKeyboardShown = true;
         }
     }
 
diff -r 31ce9a8ce2bd -r ab3f2402a777 src/core/android/SDL_android.c
--- a/src/core/android/SDL_android.c	Sun Aug 13 20:55:59 2017 -0700
+++ b/src/core/android/SDL_android.c	Sun Aug 13 21:05:15 2017 -0700
@@ -1684,6 +1684,20 @@
     Android_JNI_SendMessage(COMMAND_TEXTEDIT_HIDE, 0);
 }
 
+SDL_bool Android_JNI_IsScreenKeyboardShown()
+{
+    jmethodID mid;
+    jboolean is_shown = 0;
+    JNIEnv *mEnv = Android_JNI_GetEnv();
+    mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,"isScreenKeyboardShown","()Z");
+    if (mid) {
+        is_shown = (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, mid);
+    }
+
+    return is_shown;
+}
+
+
 int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
 {
     JNIEnv *env;
diff -r 31ce9a8ce2bd -r ab3f2402a777 src/core/android/SDL_android.h
--- a/src/core/android/SDL_android.h	Sun Aug 13 20:55:59 2017 -0700
+++ b/src/core/android/SDL_android.h	Sun Aug 13 21:05:15 2017 -0700
@@ -38,6 +38,7 @@
 extern SDL_bool Android_JNI_GetAccelerometerValues(float values[3]);
 extern void Android_JNI_ShowTextInput(SDL_Rect *inputRect);
 extern void Android_JNI_HideTextInput(void);
+extern SDL_bool Android_JNI_IsScreenKeyboardShown(void);
 extern ANativeWindow* Android_JNI_GetNativeWindow(void);
 
 /* Audio support */
diff -r 31ce9a8ce2bd -r ab3f2402a777 src/video/android/SDL_androidkeyboard.c
--- a/src/video/android/SDL_androidkeyboard.c	Sun Aug 13 20:55:59 2017 -0700
+++ b/src/video/android/SDL_androidkeyboard.c	Sun Aug 13 21:05:15 2017 -0700
@@ -357,7 +357,7 @@
 SDL_bool
 Android_IsScreenKeyboardShown(_THIS, SDL_Window * window)
 {
-    return SDL_IsTextInputActive();
+    return Android_JNI_IsScreenKeyboardShown();
 }
 
 void


More information about the commits mailing list