[Commits] SDL: Add the ability to set SDL to handle Return as 'hide IME' o...

libsdl.org revision control commits-owner at libsdl.org
Tue Dec 12 12:48:58 PST 2017


details:   https://hg.libsdl.org/SDL/rev/0f2fb9ec6ad6
changeset: 11768:0f2fb9ec6ad6
user:      Sam Lantinga <slouken at libsdl.org>
date:      Tue Dec 12 12:52:23 2017 -0800
description:
Add the ability to set SDL to handle Return as 'hide IME' on Android softkeyboard. (thanks Rachel!)

diffstat:

 android-project/app/src/main/java/org/libsdl/app/SDLActivity.java |  19 ++++++++++
 include/SDL_hints.h                                               |  13 ++++++
 2 files changed, 32 insertions(+), 0 deletions(-)

diffs (52 lines):

diff -r 83596c8dabfc -r 0f2fb9ec6ad6 android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Tue Dec 12 12:52:17 2017 -0800
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Tue Dec 12 12:52:23 2017 -0800
@@ -1501,6 +1501,25 @@
          * and so we need to generate them ourselves in commitText.  To avoid duplicates on the handful of keys
          * that still do, we empty this out.
          */
+
+        /*
+         * Return DOES still generate a key event, however.  So rather than using it as the 'click a button' key
+         * as we do with physical keyboards, let's just use it to hide the keyboard.
+         */
+
+        if (event.getKeyCode() == 66) {
+            String imeHide = SDLActivity.nativeGetHint("SDL_ANDROID_RETURN_HIDES_IME");
+            if ((imeHide != null) && imeHide.equals("1")) {
+                Context c = SDL.getContext();
+                if (c instanceof SDLActivity) {
+                    SDLActivity activity = (SDLActivity)c;
+                    activity.sendCommand(SDLActivity.COMMAND_TEXTEDIT_HIDE, null);
+                    return true;
+                }
+            }
+        }
+
+
         return super.sendKeyEvent(event);
     }
 
diff -r 83596c8dabfc -r 0f2fb9ec6ad6 include/SDL_hints.h
--- a/include/SDL_hints.h	Tue Dec 12 12:52:17 2017 -0800
+++ b/include/SDL_hints.h	Tue Dec 12 12:52:23 2017 -0800
@@ -720,6 +720,19 @@
  */
 #define SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH "SDL_ANDROID_SEPARATE_MOUSE_AND_TOUCH"
 
+ /**
+ * \brief A variable to control whether the return key on the soft keyboard should hide the 
+ * soft keyboard on Android.
+ *
+ * The variable can be set to the following values:
+ *   "0"       - The return key will be handled as a key event. This is the behaviour of 
+ *               SDL <= 2.0.3. (default)
+ *   "1"       - The return key will hide the keyboard.
+ *
+ * The value of this hint is used at runtime, so it can be changed at any time.
+ */
+#define SDL_HINT_ANDROID_RETURN_HIDES_IME "SDL_ANDROID_RETURN_HIDES_IME"
+
 /**
  *  \brief override the binding element for keyboard inputs for Emscripten builds
  *


More information about the commits mailing list