From ab59089e3b5e518e022a50bc6c2c5727ba8fa9f6 Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Fri, 2 Aug 2013 12:38:39 -0300 Subject: [PATCH] Temporary fix for bug #1639 SDL does not message back closing of screen keyboard See FIXME notes on patch for details. --- .../src/org/libsdl/app/SDLActivity.java | 18 ++++++++++++++++++ src/core/android/SDL_android.c | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java index 48b371adb..62a3be1ba 100644 --- a/android-project/src/org/libsdl/app/SDLActivity.java +++ b/android-project/src/org/libsdl/app/SDLActivity.java @@ -236,6 +236,7 @@ boolean sendCommand(int command, Object data) { public static native void onNativeResize(int x, int y, int format); public static native void onNativeKeyDown(int keycode); public static native void onNativeKeyUp(int keycode); + public static native void onNativeKeyboardFocusLost(); public static native void onNativeTouch(int touchDevId, int pointerFingerId, int action, float x, float y, float p); @@ -829,6 +830,23 @@ public boolean onKey(View v, int keyCode, KeyEvent event) { return false; } + + // + @Override + public boolean onKeyPreIme (int keyCode, KeyEvent event) { + // As seen on StackOverflow: http://stackoverflow.com/questions/7634346/keyboard-hide-event + // FIXME: Discussion at http://bugzilla.libsdl.org/show_bug.cgi?id=1639 + // FIXME: This is not a 100% effective solution to the problem of detecting if the keyboard is showing or not + // FIXME: A more effective solution would be to change our Layout from AbsoluteLayout to Relative or Linear + // FIXME: And determine the keyboard presence doing this: http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android + // FIXME: An even more effective way would be if Android provided this out of the box, but where would the fun be in that :) + if (event.getAction()==KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { + if (SDLActivity.mTextEdit != null && SDLActivity.mTextEdit.getVisibility() == View.VISIBLE) { + SDLActivity.onNativeKeyboardFocusLost(); + } + } + return super.onKeyPreIme(keyCode, event); + } @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 7a008ff84..0d47b4bae 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -162,6 +162,15 @@ void Java_org_libsdl_app_SDLActivity_onNativeKeyUp( Android_OnKeyUp(keycode); } +// Keyboard Focus Lost +void Java_org_libsdl_app_SDLActivity_onNativeKeyboardFocusLost( + JNIEnv* env, jclass jcls) +{ + /* Calling SDL_StopTextInput will take care of hiding the keyboard and cleaning up the DummyText widget */ + SDL_StopTextInput(); +} + + // Touch void Java_org_libsdl_app_SDLActivity_onNativeTouch( JNIEnv* env, jclass jcls,