Temporary fix for bug #1639 SDL does not message back closing of screen keyboard
authorGabriel Jacobo <gabomdq@gmail.com>
Fri, 02 Aug 2013 12:38:39 -0300
changeset 7564 d2bc997ef5d6
parent 7563 c128ed448c30
child 7565 3d97fc52d294
Temporary fix for bug #1639 SDL does not message back closing of screen keyboard See FIXME notes on patch for details.
android-project/src/org/libsdl/app/SDLActivity.java
src/core/android/SDL_android.c
--- a/android-project/src/org/libsdl/app/SDLActivity.java	Thu Aug 01 09:15:36 2013 -0700
+++ b/android-project/src/org/libsdl/app/SDLActivity.java	Fri Aug 02 12:38:39 2013 -0300
@@ -236,6 +236,7 @@
     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 @@
 
         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) {
--- a/src/core/android/SDL_android.c	Thu Aug 01 09:15:36 2013 -0700
+++ b/src/core/android/SDL_android.c	Fri Aug 02 12:38:39 2013 -0300
@@ -162,6 +162,15 @@
     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,