Add the ability to set SDL to handle Return as 'hide IME' on Android softkeyboard. (thanks Rachel!)
authorSam Lantinga <slouken@libsdl.org>
Tue, 12 Dec 2017 12:52:23 -0800
changeset 117680f2fb9ec6ad6
parent 11767 83596c8dabfc
child 11769 f0aad4dbf696
Add the ability to set SDL to handle Return as 'hide IME' on Android softkeyboard. (thanks Rachel!)
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
include/SDL_hints.h
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Tue Dec 12 12:52:17 2017 -0800
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Tue Dec 12 12:52:23 2017 -0800
     1.3 @@ -1501,6 +1501,25 @@
     1.4           * and so we need to generate them ourselves in commitText.  To avoid duplicates on the handful of keys
     1.5           * that still do, we empty this out.
     1.6           */
     1.7 +
     1.8 +        /*
     1.9 +         * Return DOES still generate a key event, however.  So rather than using it as the 'click a button' key
    1.10 +         * as we do with physical keyboards, let's just use it to hide the keyboard.
    1.11 +         */
    1.12 +
    1.13 +        if (event.getKeyCode() == 66) {
    1.14 +            String imeHide = SDLActivity.nativeGetHint("SDL_ANDROID_RETURN_HIDES_IME");
    1.15 +            if ((imeHide != null) && imeHide.equals("1")) {
    1.16 +                Context c = SDL.getContext();
    1.17 +                if (c instanceof SDLActivity) {
    1.18 +                    SDLActivity activity = (SDLActivity)c;
    1.19 +                    activity.sendCommand(SDLActivity.COMMAND_TEXTEDIT_HIDE, null);
    1.20 +                    return true;
    1.21 +                }
    1.22 +            }
    1.23 +        }
    1.24 +
    1.25 +
    1.26          return super.sendKeyEvent(event);
    1.27      }
    1.28  
     2.1 --- a/include/SDL_hints.h	Tue Dec 12 12:52:17 2017 -0800
     2.2 +++ b/include/SDL_hints.h	Tue Dec 12 12:52:23 2017 -0800
     2.3 @@ -720,6 +720,19 @@
     2.4   */
     2.5  #define SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH "SDL_ANDROID_SEPARATE_MOUSE_AND_TOUCH"
     2.6  
     2.7 + /**
     2.8 + * \brief A variable to control whether the return key on the soft keyboard should hide the 
     2.9 + * soft keyboard on Android.
    2.10 + *
    2.11 + * The variable can be set to the following values:
    2.12 + *   "0"       - The return key will be handled as a key event. This is the behaviour of 
    2.13 + *               SDL <= 2.0.3. (default)
    2.14 + *   "1"       - The return key will hide the keyboard.
    2.15 + *
    2.16 + * The value of this hint is used at runtime, so it can be changed at any time.
    2.17 + */
    2.18 +#define SDL_HINT_ANDROID_RETURN_HIDES_IME "SDL_ANDROID_RETURN_HIDES_IME"
    2.19 +
    2.20  /**
    2.21   *  \brief override the binding element for keyboard inputs for Emscripten builds
    2.22   *