From adc8a27440f6089ab25338af6af2a5823a3e6632 Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Fri, 5 Jun 2015 23:28:33 +0300 Subject: [PATCH] SDL_IsScreenKeyboardShown() will work with SDL_ANDROID_ToggleScreenKeyboardWithoutTextInput() --- project/java/MainActivity.java | 27 ++++++++++++++----- project/java/Video.java | 13 ++------- .../src/video/android/SDL_androidvideo.c | 17 +++++------- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index 5e3b4a292..801c4fe88 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -487,18 +487,31 @@ public class MainActivity extends Activity if( !keyboardWithoutTextInputShown ) { keyboardWithoutTextInputShown = true; - _inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); - _inputManager.showSoftInput(mGLView, InputMethodManager.SHOW_FORCED); - getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + runOnUiThread(new Runnable() + { + public void run() + { + _inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + _inputManager.showSoftInput(mGLView, InputMethodManager.SHOW_FORCED); + getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + } + }); } else { keyboardWithoutTextInputShown = false; - getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); - _inputManager.hideSoftInputFromWindow(mGLView.getWindowToken(), 0); - DimSystemStatusBar.get().dim(_videoLayout); - //DimSystemStatusBar.get().dim(mGLView); + runOnUiThread(new Runnable() + { + public void run() + { + getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); + _inputManager.hideSoftInputFromWindow(mGLView.getWindowToken(), 0); + DimSystemStatusBar.get().dim(_videoLayout); + //DimSystemStatusBar.get().dim(mGLView); + } + }); } + mGLView.nativeScreenKeyboardShown( keyboardWithoutTextInputShown ? 1 : 0 ); } public void showScreenKeyboard(final String oldText) diff --git a/project/java/Video.java b/project/java/Video.java index 558e937cc..06bba388d 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -759,17 +759,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer public void showScreenKeyboardWithoutTextInputField() // Called from native code { - class Callback implements Runnable - { - public MainActivity parent; - public void run() - { - parent.showScreenKeyboardWithoutTextInputField(); - } - } - Callback cb = new Callback(); - cb.parent = context; - context.runOnUiThread(cb); + context.showScreenKeyboardWithoutTextInputField(); } public void showScreenKeyboard(final String oldText, int unused) // Called from native code @@ -1067,4 +1057,5 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL { public static native void nativeMouseWheel( int scrollX, int scrollY ); public static native void nativeGamepadAnalogJoystickInput( float stick1x, float stick1y, float stick2x, float stick2y, float ltrigger, float rtrigger, int usingHat ); public static native void nativeScreenVisibleRect( int x, int y, int w, int h ); + public static native void nativeScreenKeyboardShown( int shown ); } diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c index 7f492b793..8429626f4 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c @@ -298,20 +298,15 @@ void SDL_ANDROID_CallJavaHideScreenKeyboard() int SDL_ANDROID_IsScreenKeyboardShown() { - /* - // Efficient implementation sometimes fails for no real reason, so poll Java from time to time - // Or maybe not, this was when I've added some debug code, not observed anymore - static int safetyCounter = 0; - if( safetyCounter >= 60 ) { - safetyCounter = 0; - SDL_ANDROID_IsScreenKeyboardShownFlag = (*JavaEnv)->CallIntMethod( JavaEnv, JavaRenderer, JavaIsScreenKeyboardShown ); - } - safetyCounter ++; - */ - return SDL_ANDROID_IsScreenKeyboardShownFlag; } +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeScreenKeyboardShown) ( JNIEnv* env, jobject thiz, jint shown ) +{ + SDL_ANDROID_IsScreenKeyboardShownFlag = shown; +} + void SDL_ANDROID_CallJavaSetScreenKeyboardHintMessage(const char *hint) { (*JavaEnv)->PushLocalFrame(JavaEnv, 1);