diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index 17697daac..41279a245 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -762,6 +762,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh 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, @@ -2087,14 +2088,8 @@ class SDLInputConnection extends BaseInputConnection { */ 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; } } @@ -2107,6 +2102,11 @@ class SDLInputConnection extends BaseInputConnection { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); + if (c == '\n') { + if (SDLActivity.onNativeSoftReturnKey()) { + return true; + } + } nativeGenerateScancodeForUnichar(c); } diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 2e7240d29..2793ec70a 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -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); @@ -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) @@ -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)