Fixed hiding the Android virtual keyboard when the return key is pressed
authorSam Lantinga <slouken@libsdl.org>
Thu, 23 May 2019 11:05:43 -0700
changeset 1275253a3b17a1c08
parent 12751 06fa9a25d2a0
child 12753 ba1a66b57385
Fixed hiding the Android virtual keyboard when the return key is pressed
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
src/core/android/SDL_android.c
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Thu May 23 09:08:40 2019 +0200
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Thu May 23 11:05:43 2019 -0700
     1.3 @@ -762,6 +762,7 @@
     1.4      public static native void onNativeResize();
     1.5      public static native void onNativeKeyDown(int keycode);
     1.6      public static native void onNativeKeyUp(int keycode);
     1.7 +    public static native boolean onNativeSoftReturnKey();
     1.8      public static native void onNativeKeyboardFocusLost();
     1.9      public static native void onNativeMouse(int button, int action, float x, float y, boolean relative);
    1.10      public static native void onNativeTouch(int touchDevId, int pointerFingerId,
    1.11 @@ -2087,14 +2088,8 @@
    1.12           */
    1.13  
    1.14          if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
    1.15 -            String imeHide = SDLActivity.nativeGetHint("SDL_RETURN_KEY_HIDES_IME");
    1.16 -            if ((imeHide != null) && imeHide.equals("1")) {
    1.17 -                Context c = SDL.getContext();
    1.18 -                if (c instanceof SDLActivity) {
    1.19 -                    SDLActivity activity = (SDLActivity)c;
    1.20 -                    activity.sendCommand(SDLActivity.COMMAND_TEXTEDIT_HIDE, null);
    1.21 -                    return true;
    1.22 -                }
    1.23 +            if (SDLActivity.onNativeSoftReturnKey()) {
    1.24 +                return true;
    1.25              }
    1.26          }
    1.27  
    1.28 @@ -2107,6 +2102,11 @@
    1.29  
    1.30          for (int i = 0; i < text.length(); i++) {
    1.31              char c = text.charAt(i);
    1.32 +            if (c == '\n') {
    1.33 +                if (SDLActivity.onNativeSoftReturnKey()) {
    1.34 +                    return true;
    1.35 +                }
    1.36 +            }
    1.37              nativeGenerateScancodeForUnichar(c);
    1.38          }
    1.39  
     2.1 --- a/src/core/android/SDL_android.c	Thu May 23 09:08:40 2019 +0200
     2.2 +++ b/src/core/android/SDL_android.c	Thu May 23 11:05:43 2019 -0700
     2.3 @@ -97,6 +97,9 @@
     2.4          JNIEnv *env, jclass jcls,
     2.5          jint keycode);
     2.6  
     2.7 +JNIEXPORT jboolean JNICALL SDL_JAVA_INTERFACE(onNativeSoftReturnKey)(
     2.8 +        JNIEnv *env, jclass jcls);
     2.9 +
    2.10  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyboardFocusLost)(
    2.11          JNIEnv *env, jclass jcls);
    2.12  
    2.13 @@ -920,6 +923,17 @@
    2.14      Android_OnKeyUp(keycode);
    2.15  }
    2.16  
    2.17 +/* Virtual keyboard return key might stop text input */
    2.18 +JNIEXPORT jboolean JNICALL SDL_JAVA_INTERFACE(onNativeSoftReturnKey)(
    2.19 +                                    JNIEnv *env, jclass jcls)
    2.20 +{
    2.21 +    if (SDL_GetHintBoolean(SDL_HINT_RETURN_KEY_HIDES_IME, SDL_FALSE)) {
    2.22 +        SDL_StopTextInput();
    2.23 +        return JNI_TRUE;
    2.24 +    }
    2.25 +    return JNI_FALSE;
    2.26 +}
    2.27 +
    2.28  /* Keyboard Focus Lost */
    2.29  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyboardFocusLost)(
    2.30                                      JNIEnv *env, jclass jcls)
    2.31 @@ -1127,7 +1141,6 @@
    2.32      }
    2.33  }
    2.34  
    2.35 -
    2.36  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeSetComposingText)(
    2.37                                      JNIEnv *env, jclass cls,
    2.38                                      jstring text, jint newCursorPosition)