ANDROID: Synchronize keyboard status between Java and C++

Without this, if keyboard is displayed by the user, the C++ side never
knows about it.
This commit is contained in:
Le Philousophe 2023-07-01 17:43:20 +02:00
parent 4c13924a38
commit e62b59f16c
6 changed files with 20 additions and 2 deletions

View File

@ -646,7 +646,6 @@ void OSystem_Android::setFeatureState(Feature f, bool enable) {
switch (f) {
case kFeatureVirtualKeyboard:
_virtkeybd_on = enable;
JNI::showVirtualKeyboard(enable);
break;
default:
@ -950,6 +949,10 @@ int OSystem_Android::getGraphicsMode() const {
return 0;
}
void OSystem_Android::syncVirtkeyboardState(bool virtkeybd_on) {
_virtkeybd_on = virtkeybd_on;
}
#if defined(USE_OPENGL) && defined(USE_GLAD)
void *OSystem_Android::getOpenGLProcAddress(const char *name) const {
// eglGetProcAddress exists since Android 2.3 (API Level 9)

View File

@ -188,6 +188,8 @@ public:
void applyTouchSettings(bool _3dMode, bool overlayShown);
void setupTouchMode(int oldValue, int newValue);
void syncVirtkeyboardState(bool virtkeybd_on);
void applyOrientationSettings();
bool pollEvent(Common::Event &event) override;

View File

@ -134,6 +134,8 @@ const JNINativeMethod JNI::_natives[] = {
(void *)JNI::updateTouch },
{ "setupTouchMode", "(II)V",
(void *)JNI::setupTouchMode },
{ "syncVirtkeyboardState", "(Z)V",
(void *)JNI::syncVirtkeyboardState },
{ "setPause", "(Z)V",
(void *)JNI::setPause },
{ "getNativeVersionInfo", "()Ljava/lang/String;",
@ -963,6 +965,13 @@ void JNI::setupTouchMode(JNIEnv *env, jobject self, jint oldValue, jint newValue
_system->setupTouchMode(oldValue, newValue);
}
void JNI::syncVirtkeyboardState(JNIEnv *env, jobject self, jboolean newState) {
if (!_system)
return;
_system->syncVirtkeyboardState(newState);
}
void JNI::setPause(JNIEnv *env, jobject self, jboolean value) {
if (!_system)
return;

View File

@ -189,6 +189,7 @@ private:
int arg2, int arg3, int arg4, int arg5, int arg6);
static void updateTouch(JNIEnv *env, jobject self, int action, int ptr, int x, int y);
static void setupTouchMode(JNIEnv *env, jobject self, jint oldValue, jint newValue);
static void syncVirtkeyboardState(JNIEnv *env, jobject self, jboolean newState);
static void setPause(JNIEnv *env, jobject self, jboolean value);
static jstring getNativeVersionInfo(JNIEnv *env, jobject self);

View File

@ -62,6 +62,8 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {
final public native void setupTouchMode(int oldValue, int newValue);
final public native void updateTouch(int action, int ptr, int x, int y);
final public native void syncVirtkeyboardState(boolean newState);
final public native String getNativeVersionInfo();
// Callbacks from C++ peer instance

View File

@ -490,6 +490,7 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
_videoLayout.addView(_screenKeyboard, sKeyboardLayout);
_videoLayout.bringChildToFront(_screenKeyboard);
}
_scummvm.syncVirtkeyboardState(true);
}
});
} else {
@ -510,10 +511,10 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
//Log.d(ScummVM.LOG_TAG, "showScreenKeyboardWithoutTextInputField - captureMouse(true)");
_main_surface.captureMouse(true);
//_main_surface.showSystemMouseCursor(false);
_scummvm.syncVirtkeyboardState(false);
}
});
}
// TODO Do we need to inform native ScummVM code of keyboard shown state?
// _main_surface.nativeScreenKeyboardShown( keyboardWithoutTextInputShown ? 1 : 0 );
}
}