فهرست منبع

Keep track of whether the Android on-screen keyboard was opened by the application

Fixes https://github.com/libsdl-org/SDL/issues/9202
Sam Lantinga 1 سال پیش
والد
کامیت
edbcef11ff
3فایلهای تغییر یافته به همراه14 افزوده شده و 8 حذف شده
  1. 2 8
      src/video/android/SDL_androidevents.c
  2. 11 0
      src/video/android/SDL_androidkeyboard.c
  3. 1 0
      src/video/android/SDL_androidkeyboard.h

+ 2 - 8
src/video/android/SDL_androidevents.c

@@ -130,10 +130,7 @@ void Android_PumpEvents_Blocking(SDL_VideoDevice *_this)
 #endif
 
             /* Make sure SW Keyboard is restored when an app becomes foreground */
-            if (SDL_TextInputActive() &&
-                SDL_GetHintBoolean(SDL_HINT_ENABLE_SCREEN_KEYBOARD, SDL_TRUE)) {
-                Android_ShowScreenKeyboard(_this, Android_Window); /* Only showTextInput */
-            }
+            Android_RestoreScreenKeyboardOnResume(_this, Android_Window);
 
             SDL_SendAppEvent(SDL_EVENT_DID_ENTER_FOREGROUND);
             SDL_SendWindowEvent(Android_Window, SDL_EVENT_WINDOW_RESTORED, 0, 0);
@@ -210,10 +207,7 @@ void Android_PumpEvents_NonBlocking(SDL_VideoDevice *_this)
 #endif
 
             /* Make sure SW Keyboard is restored when an app becomes foreground */
-            if (SDL_TextInputActive() &&
-                SDL_GetHintBoolean(SDL_HINT_ENABLE_SCREEN_KEYBOARD, SDL_TRUE)) {
-                Android_ShowScreenKeyboard(_this, Android_Window); /* Only showTextInput */
-            }
+            Android_RestoreScreenKeyboardOnResume(_this, Android_Window);
 
             SDL_SendAppEvent(SDL_EVENT_DID_ENTER_FOREGROUND);
             SDL_SendWindowEvent(Android_Window, SDL_EVENT_WINDOW_RESTORED, 0, 0);

+ 11 - 0
src/video/android/SDL_androidkeyboard.c

@@ -313,6 +313,8 @@ static SDL_Scancode Android_Keycodes[] = {
     SDL_SCANCODE_PASTE,            /* AKEYCODE_PASTE */
 };
 
+static bool SDL_screen_keyboard_shown;
+
 static SDL_Scancode TranslateKeycode(int keycode)
 {
     SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
@@ -345,11 +347,20 @@ void Android_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window)
 {
     SDL_VideoData *videodata = _this->driverdata;
     Android_JNI_ShowScreenKeyboard(&videodata->textRect);
+    SDL_screen_keyboard_shown = SDL_TRUE;
 }
 
 void Android_HideScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window)
 {
     Android_JNI_HideScreenKeyboard();
+    SDL_screen_keyboard_shown = SDL_FALSE;
+}
+
+void Android_RestoreScreenKeyboardOnResume(SDL_VideoDevice *_this, SDL_Window *window)
+{
+    if (SDL_screen_keyboard_shown) {
+        Android_ShowScreenKeyboard(_this, window);
+    }
 }
 
 SDL_bool Android_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window)

+ 1 - 0
src/video/android/SDL_androidkeyboard.h

@@ -28,5 +28,6 @@ extern int Android_OnKeyUp(int keycode);
 extern SDL_bool Android_HasScreenKeyboardSupport(SDL_VideoDevice *_this);
 extern void Android_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window);
 extern void Android_HideScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window);
+extern void Android_RestoreScreenKeyboardOnResume(SDL_VideoDevice *_this, SDL_Window *window);
 extern SDL_bool Android_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window);
 extern int Android_SetTextInputRect(SDL_VideoDevice *_this, const SDL_Rect *rect);