Skip to content

Commit

Permalink
Provide the correct state of the on-screen keyboard to the API (patch…
Browse files Browse the repository at this point in the history
… from Sylvain)
  • Loading branch information
slouken committed Aug 14, 2017
1 parent 6ee6613 commit e54eede
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
44 changes: 44 additions & 0 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -59,6 +59,7 @@ public enum NativeState {
protected static SDLActivity mSingleton;
protected static SDLSurface mSurface;
protected static View mTextEdit;
protected static boolean mScreenKeyboardShown;
protected static ViewGroup mLayout;
protected static SDLJoystickHandler mJoystickHandler;
protected static SDLHapticHandler mHapticHandler;
Expand Down Expand Up @@ -440,6 +441,8 @@ public void handleMessage(Message msg) {

InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0);

mScreenKeyboardShown = false;
}
break;
case COMMAND_SET_KEEP_SCREEN_ON:
Expand Down Expand Up @@ -568,6 +571,45 @@ public void setOrientationBis(int w, int h, boolean resizable, String hint)
return;
}


/**
* This method is called by SDL using JNI.
*/
public static boolean isScreenKeyboardShown()
{
if (mTextEdit == null) {
return false;
}

if (mScreenKeyboardShown == false) {
return false;
}

InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isAcceptingText()) {
return true;
}

return false;
}



/**
* This method is called by SDL using JNI.
*/
public static int openURL(String url)
{
try {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
mSingleton.startActivity(i);
} catch (Exception ex) {
return -1;
}
return 0;
}

/**
* This method is called by SDL using JNI.
*/
Expand Down Expand Up @@ -647,6 +689,8 @@ public void run() {

InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mTextEdit, 0);

mScreenKeyboardShown = true;
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/core/android/SDL_android.c
Expand Up @@ -1684,6 +1684,20 @@ void Android_JNI_HideTextInput(void)
Android_JNI_SendMessage(COMMAND_TEXTEDIT_HIDE, 0);
}

SDL_bool Android_JNI_IsScreenKeyboardShown()
{
jmethodID mid;
jboolean is_shown = 0;
JNIEnv *mEnv = Android_JNI_GetEnv();
mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,"isScreenKeyboardShown","()Z");
if (mid) {
is_shown = (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, mid);
}

return is_shown;
}


int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
{
JNIEnv *env;
Expand Down
1 change: 1 addition & 0 deletions src/core/android/SDL_android.h
Expand Up @@ -38,6 +38,7 @@ extern void Android_JNI_SetOrientation(int w, int h, int resizable, const char *
extern SDL_bool Android_JNI_GetAccelerometerValues(float values[3]);
extern void Android_JNI_ShowTextInput(SDL_Rect *inputRect);
extern void Android_JNI_HideTextInput(void);
extern SDL_bool Android_JNI_IsScreenKeyboardShown(void);
extern ANativeWindow* Android_JNI_GetNativeWindow(void);

/* Audio support */
Expand Down
2 changes: 1 addition & 1 deletion src/video/android/SDL_androidkeyboard.c
Expand Up @@ -357,7 +357,7 @@ Android_HasScreenKeyboardSupport(_THIS)
SDL_bool
Android_IsScreenKeyboardShown(_THIS, SDL_Window * window)
{
return SDL_IsTextInputActive();
return Android_JNI_IsScreenKeyboardShown();
}

void
Expand Down

0 comments on commit e54eede

Please sign in to comment.