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 7564d2bc997ef5d6
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
     1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java	Thu Aug 01 09:15:36 2013 -0700
     1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java	Fri Aug 02 12:38:39 2013 -0300
     1.3 @@ -236,6 +236,7 @@
     1.4      public static native void onNativeResize(int x, int y, int format);
     1.5      public static native void onNativeKeyDown(int keycode);
     1.6      public static native void onNativeKeyUp(int keycode);
     1.7 +    public static native void onNativeKeyboardFocusLost();
     1.8      public static native void onNativeTouch(int touchDevId, int pointerFingerId,
     1.9                                              int action, float x, 
    1.10                                              float y, float p);
    1.11 @@ -829,6 +830,23 @@
    1.12  
    1.13          return false;
    1.14      }
    1.15 +        
    1.16 +    //
    1.17 +    @Override
    1.18 +    public boolean onKeyPreIme (int keyCode, KeyEvent event) {
    1.19 +        // As seen on StackOverflow: http://stackoverflow.com/questions/7634346/keyboard-hide-event
    1.20 +        // FIXME: Discussion at http://bugzilla.libsdl.org/show_bug.cgi?id=1639
    1.21 +        // FIXME: This is not a 100% effective solution to the problem of detecting if the keyboard is showing or not
    1.22 +        // FIXME: A more effective solution would be to change our Layout from AbsoluteLayout to Relative or Linear
    1.23 +        // FIXME: And determine the keyboard presence doing this: http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android
    1.24 +        // FIXME: An even more effective way would be if Android provided this out of the box, but where would the fun be in that :)
    1.25 +        if (event.getAction()==KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
    1.26 +            if (SDLActivity.mTextEdit != null && SDLActivity.mTextEdit.getVisibility() == View.VISIBLE) {
    1.27 +                SDLActivity.onNativeKeyboardFocusLost();
    1.28 +            }
    1.29 +        }
    1.30 +        return super.onKeyPreIme(keyCode, event);
    1.31 +    }
    1.32  
    1.33      @Override
    1.34      public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
     2.1 --- a/src/core/android/SDL_android.c	Thu Aug 01 09:15:36 2013 -0700
     2.2 +++ b/src/core/android/SDL_android.c	Fri Aug 02 12:38:39 2013 -0300
     2.3 @@ -162,6 +162,15 @@
     2.4      Android_OnKeyUp(keycode);
     2.5  }
     2.6  
     2.7 +// Keyboard Focus Lost
     2.8 +void Java_org_libsdl_app_SDLActivity_onNativeKeyboardFocusLost(
     2.9 +                                    JNIEnv* env, jclass jcls)
    2.10 +{
    2.11 +    /* Calling SDL_StopTextInput will take care of hiding the keyboard and cleaning up the DummyText widget */
    2.12 +    SDL_StopTextInput();
    2.13 +}
    2.14 +
    2.15 +
    2.16  // Touch
    2.17  void Java_org_libsdl_app_SDLActivity_onNativeTouch(
    2.18                                      JNIEnv* env, jclass jcls,