Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Temporary fix for bug #1639 SDL does not message back closing of scre…
Browse files Browse the repository at this point in the history
…en keyboard

See FIXME notes on patch for details.
  • Loading branch information
gabomdq committed Aug 2, 2013
1 parent 90ed304 commit ab59089
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions src/core/android/SDL_android.c
Expand Up @@ -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,
Expand Down

0 comments on commit ab59089

Please sign in to comment.