Fixed hiding the Android virtual keyboard when the return key is pressed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
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 17697da..41279a2 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 2e7240d..2793ec7 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)