Provide the correct state of the on-screen keyboard to the API (patch from Sylvain)
authorSam Lantinga <slouken@libsdl.org>
Sun, 13 Aug 2017 21:05:15 -0700
changeset 11271ab3f2402a777
parent 11270 31ce9a8ce2bd
child 11272 d60ede5a0c2e
Provide the correct state of the on-screen keyboard to the API (patch from Sylvain)
android-project/src/org/libsdl/app/SDLActivity.java
src/core/android/SDL_android.c
src/core/android/SDL_android.h
src/video/android/SDL_androidkeyboard.c
     1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java	Sun Aug 13 20:55:59 2017 -0700
     1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java	Sun Aug 13 21:05:15 2017 -0700
     1.3 @@ -59,6 +59,7 @@
     1.4      protected static SDLActivity mSingleton;
     1.5      protected static SDLSurface mSurface;
     1.6      protected static View mTextEdit;
     1.7 +    protected static boolean mScreenKeyboardShown;
     1.8      protected static ViewGroup mLayout;
     1.9      protected static SDLJoystickHandler mJoystickHandler;
    1.10      protected static SDLHapticHandler mHapticHandler;
    1.11 @@ -440,6 +441,8 @@
    1.12  
    1.13                      InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    1.14                      imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0);
    1.15 +                    
    1.16 +                    mScreenKeyboardShown = false;
    1.17                  }
    1.18                  break;
    1.19              case COMMAND_SET_KEEP_SCREEN_ON:
    1.20 @@ -568,6 +571,45 @@
    1.21        return;
    1.22      }
    1.23  
    1.24 +
    1.25 +    /**
    1.26 +     * This method is called by SDL using JNI.
    1.27 +     */
    1.28 +    public static boolean isScreenKeyboardShown() 
    1.29 +    {
    1.30 +       if (mTextEdit == null) {
    1.31 +          return false;
    1.32 +       }
    1.33 +
    1.34 +       if (mScreenKeyboardShown == false) {
    1.35 +          return false;
    1.36 +       }
    1.37 +
    1.38 +       InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    1.39 +       if (imm.isAcceptingText()) {
    1.40 +          return true;
    1.41 +       }
    1.42 +
    1.43 +       return false;
    1.44 +    }
    1.45 +
    1.46 +
    1.47 +
    1.48 +    /**
    1.49 +     * This method is called by SDL using JNI.
    1.50 +     */
    1.51 +    public static int openURL(String url)
    1.52 +    {
    1.53 +       try {
    1.54 +          Intent i = new Intent(Intent.ACTION_VIEW);
    1.55 +          i.setData(Uri.parse(url));
    1.56 +          mSingleton.startActivity(i);
    1.57 +       } catch (Exception ex) {
    1.58 +          return -1;
    1.59 +       }
    1.60 +       return 0;
    1.61 +    }
    1.62 +
    1.63      /**
    1.64       * This method is called by SDL using JNI.
    1.65       */
    1.66 @@ -647,6 +689,8 @@
    1.67  
    1.68              InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    1.69              imm.showSoftInput(mTextEdit, 0);
    1.70 +
    1.71 +            mScreenKeyboardShown = true;
    1.72          }
    1.73      }
    1.74  
     2.1 --- a/src/core/android/SDL_android.c	Sun Aug 13 20:55:59 2017 -0700
     2.2 +++ b/src/core/android/SDL_android.c	Sun Aug 13 21:05:15 2017 -0700
     2.3 @@ -1684,6 +1684,20 @@
     2.4      Android_JNI_SendMessage(COMMAND_TEXTEDIT_HIDE, 0);
     2.5  }
     2.6  
     2.7 +SDL_bool Android_JNI_IsScreenKeyboardShown()
     2.8 +{
     2.9 +    jmethodID mid;
    2.10 +    jboolean is_shown = 0;
    2.11 +    JNIEnv *mEnv = Android_JNI_GetEnv();
    2.12 +    mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,"isScreenKeyboardShown","()Z");
    2.13 +    if (mid) {
    2.14 +        is_shown = (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, mid);
    2.15 +    }
    2.16 +
    2.17 +    return is_shown;
    2.18 +}
    2.19 +
    2.20 +
    2.21  int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
    2.22  {
    2.23      JNIEnv *env;
     3.1 --- a/src/core/android/SDL_android.h	Sun Aug 13 20:55:59 2017 -0700
     3.2 +++ b/src/core/android/SDL_android.h	Sun Aug 13 21:05:15 2017 -0700
     3.3 @@ -38,6 +38,7 @@
     3.4  extern SDL_bool Android_JNI_GetAccelerometerValues(float values[3]);
     3.5  extern void Android_JNI_ShowTextInput(SDL_Rect *inputRect);
     3.6  extern void Android_JNI_HideTextInput(void);
     3.7 +extern SDL_bool Android_JNI_IsScreenKeyboardShown(void);
     3.8  extern ANativeWindow* Android_JNI_GetNativeWindow(void);
     3.9  
    3.10  /* Audio support */
     4.1 --- a/src/video/android/SDL_androidkeyboard.c	Sun Aug 13 20:55:59 2017 -0700
     4.2 +++ b/src/video/android/SDL_androidkeyboard.c	Sun Aug 13 21:05:15 2017 -0700
     4.3 @@ -357,7 +357,7 @@
     4.4  SDL_bool
     4.5  Android_IsScreenKeyboardShown(_THIS, SDL_Window * window)
     4.6  {
     4.7 -    return SDL_IsTextInputActive();
     4.8 +    return Android_JNI_IsScreenKeyboardShown();
     4.9  }
    4.10  
    4.11  void