Skip to content

Commit

Permalink
Fixed hiding the Android virtual keyboard when the return key is pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed May 23, 2019
1 parent f91b878 commit 8b57331
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Expand Up @@ -762,6 +762,7 @@ boolean sendCommand(int command, Object data) {
public static native void onNativeResize();
public static native void onNativeKeyDown(int keycode);
public static native void onNativeKeyUp(int keycode);
public static native boolean onNativeSoftReturnKey();
public static native void onNativeKeyboardFocusLost();
public static native void onNativeMouse(int button, int action, float x, float y, boolean relative);
public static native void onNativeTouch(int touchDevId, int pointerFingerId,
Expand Down Expand Up @@ -2087,14 +2088,8 @@ public boolean sendKeyEvent(KeyEvent event) {
*/

if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
String imeHide = SDLActivity.nativeGetHint("SDL_RETURN_KEY_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;
}
if (SDLActivity.onNativeSoftReturnKey()) {
return true;
}
}

Expand All @@ -2107,6 +2102,11 @@ public boolean commitText(CharSequence text, int newCursorPosition) {

for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c == '\n') {
if (SDLActivity.onNativeSoftReturnKey()) {
return true;
}
}
nativeGenerateScancodeForUnichar(c);
}

Expand Down
15 changes: 14 additions & 1 deletion src/core/android/SDL_android.c
Expand Up @@ -97,6 +97,9 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyUp)(
JNIEnv *env, jclass jcls,
jint keycode);

JNIEXPORT jboolean JNICALL SDL_JAVA_INTERFACE(onNativeSoftReturnKey)(
JNIEnv *env, jclass jcls);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyboardFocusLost)(
JNIEnv *env, jclass jcls);

Expand Down Expand Up @@ -920,6 +923,17 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyUp)(
Android_OnKeyUp(keycode);
}

/* Virtual keyboard return key might stop text input */
JNIEXPORT jboolean JNICALL SDL_JAVA_INTERFACE(onNativeSoftReturnKey)(
JNIEnv *env, jclass jcls)
{
if (SDL_GetHintBoolean(SDL_HINT_RETURN_KEY_HIDES_IME, SDL_FALSE)) {
SDL_StopTextInput();
return JNI_TRUE;
}
return JNI_FALSE;
}

/* Keyboard Focus Lost */
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyboardFocusLost)(
JNIEnv *env, jclass jcls)
Expand Down Expand Up @@ -1127,7 +1141,6 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeGenerateScancod
}
}


JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeSetComposingText)(
JNIEnv *env, jclass cls,
jstring text, jint newCursorPosition)
Expand Down

0 comments on commit 8b57331

Please sign in to comment.