From 12c232eefc7c78f7d40da9894e395dee4ce6d8c2 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Sun, 18 Aug 2019 22:58:13 +0100 Subject: [PATCH] ANDROID: Add a button to show the virtual keyboard --- backends/platform/android/android.cpp | 13 ++++++ backends/platform/android/android.mk | 6 ++- backends/platform/android/jni.cpp | 15 ++++++ backends/platform/android/jni.h | 2 + .../android/org/scummvm/scummvm/ScummVM.java | 1 + .../org/scummvm/scummvm/ScummVMActivity.java | 44 ++++++++++++++++++ .../res/drawable-hdpi/ic_action_settings.png | Bin 0 -> 437 bytes .../res/drawable-mdpi/ic_action_settings.png | Bin 0 -> 310 bytes .../res/drawable-xhdpi/ic_action_settings.png | Bin 0 -> 471 bytes .../drawable-xxhdpi/ic_action_settings.png | Bin 0 -> 672 bytes dists/android/res/layout/main.xml | 21 ++++++++- 11 files changed, 99 insertions(+), 3 deletions(-) create mode 100755 dists/android/res/drawable-hdpi/ic_action_settings.png create mode 100755 dists/android/res/drawable-mdpi/ic_action_settings.png create mode 100755 dists/android/res/drawable-xhdpi/ic_action_settings.png create mode 100755 dists/android/res/drawable-xxhdpi/ic_action_settings.png diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index f3dc0b58768..2ae36c80735 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -350,6 +350,7 @@ void OSystem_Android::initBackend() { ConfMan.registerDefault("fullscreen", true); ConfMan.registerDefault("aspect_ratio", true); ConfMan.registerDefault("touchpad_mouse_mode", true); + ConfMan.registerDefault("onscreen_control", true); ConfMan.setInt("autosave_period", 0); ConfMan.setBool("FM_high_quality", false); @@ -360,6 +361,11 @@ void OSystem_Android::initBackend() { else ConfMan.setBool("touchpad_mouse_mode", true); + if (ConfMan.hasKey("onscreen_control")) + JNI::showKeyboardControl(ConfMan.getBool("onscreen_control")); + else + ConfMan.setBool("onscreen_control", true); + // must happen before creating TimerManager to avoid race in // creating EventManager setupKeymapper(); @@ -411,6 +417,7 @@ bool OSystem_Android::hasFeature(Feature f) { f == kFeatureOverlaySupportsAlpha || f == kFeatureOpenUrl || f == kFeatureTouchpadMode || + f == kFeatureOnScreenControl || f == kFeatureClipboardSupport); } @@ -439,6 +446,10 @@ void OSystem_Android::setFeatureState(Feature f, bool enable) { ConfMan.setBool("touchpad_mouse_mode", enable); _touchpad_mode = enable; break; + case kFeatureOnScreenControl: + ConfMan.setBool("onscreen_control", enable); + JNI::showKeyboardControl(enable); + break; default: break; } @@ -456,6 +467,8 @@ bool OSystem_Android::getFeatureState(Feature f) { return _use_mouse_palette; case kFeatureTouchpadMode: return ConfMan.getBool("touchpad_mouse_mode"); + case kFeatureOnScreenControl: + return ConfMan.getBool("onscreen_control"); default: return false; } diff --git a/backends/platform/android/android.mk b/backends/platform/android/android.mk index b5f559c3a40..eaae5dd3dd4 100644 --- a/backends/platform/android/android.mk +++ b/backends/platform/android/android.mk @@ -21,7 +21,11 @@ RESOURCES = \ $(PATH_BUILD_RES)/drawable/scummvm.png \ $(PATH_BUILD_RES)/drawable/scummvm_big.png \ $(PATH_BUILD_RES)/drawable-xhdpi/leanback_icon.png \ - $(PATH_BUILD_RES)/drawable-xhdpi/ouya_icon.png + $(PATH_BUILD_RES)/drawable-xhdpi/ouya_icon.png \ + $(PATH_BUILD_RES)/drawable-hdpi/ic_action_settings.png \ + $(PATH_BUILD_RES)/drawable-mdpi/ic_action_settings.png \ + $(PATH_BUILD_RES)/drawable-xhdpi/ic_action_settings.png \ + $(PATH_BUILD_RES)/drawable-xxhdpi/ic_action_settings.png DIST_ANDROID_MK = $(PATH_DIST)/jni/Android.mk DIST_BUILD_XML = $(PATH_DIST)/custom_rules.xml diff --git a/backends/platform/android/jni.cpp b/backends/platform/android/jni.cpp index ffe60062fbc..905423a5a69 100644 --- a/backends/platform/android/jni.cpp +++ b/backends/platform/android/jni.cpp @@ -84,6 +84,7 @@ jmethodID JNI::_MID_setTextInClipboard = 0; jmethodID JNI::_MID_isConnectionLimited = 0; jmethodID JNI::_MID_setWindowCaption = 0; jmethodID JNI::_MID_showVirtualKeyboard = 0; +jmethodID JNI::_MID_showKeyboardControl = 0; jmethodID JNI::_MID_getSysArchives = 0; jmethodID JNI::_MID_initSurface = 0; jmethodID JNI::_MID_deinitSurface = 0; @@ -361,6 +362,19 @@ void JNI::showVirtualKeyboard(bool enable) { } } +void JNI::showKeyboardControl(bool enable) { + JNIEnv *env = JNI::getEnv(); + + env->CallVoidMethod(_jobj, _MID_showKeyboardControl, enable); + + if (env->ExceptionCheck()) { + LOGE("Error trying to show virtual keyboard control"); + + env->ExceptionDescribe(); + env->ExceptionClear(); + } +} + void JNI::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { JNIEnv *env = JNI::getEnv(); @@ -517,6 +531,7 @@ void JNI::create(JNIEnv *env, jobject self, jobject asset_manager, FIND_METHOD(, setTextInClipboard, "([B)Z"); FIND_METHOD(, isConnectionLimited, "()Z"); FIND_METHOD(, showVirtualKeyboard, "(Z)V"); + FIND_METHOD(, showKeyboardControl, "(Z)V"); FIND_METHOD(, getSysArchives, "()[Ljava/lang/String;"); FIND_METHOD(, initSurface, "()Ljavax/microedition/khronos/egl/EGLSurface;"); FIND_METHOD(, deinitSurface, "()V"); diff --git a/backends/platform/android/jni.h b/backends/platform/android/jni.h index e65e7f5dc82..aa89174dfc5 100644 --- a/backends/platform/android/jni.h +++ b/backends/platform/android/jni.h @@ -64,6 +64,7 @@ public: static bool setTextInClipboard(const Common::String &text); static bool isConnectionLimited(); static void showVirtualKeyboard(bool enable); + static void showKeyboardControl(bool enable); static void addSysArchivesToSearchSet(Common::SearchSet &s, int priority); static inline bool haveSurface(); @@ -101,6 +102,7 @@ private: static jmethodID _MID_isConnectionLimited; static jmethodID _MID_setWindowCaption; static jmethodID _MID_showVirtualKeyboard; + static jmethodID _MID_showKeyboardControl; static jmethodID _MID_getSysArchives; static jmethodID _MID_initSurface; static jmethodID _MID_deinitSurface; diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVM.java b/backends/platform/android/org/scummvm/scummvm/ScummVM.java index 7b6627f6673..37fe76ebda5 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVM.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVM.java @@ -61,6 +61,7 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable { abstract protected boolean isConnectionLimited(); abstract protected void setWindowCaption(String caption); abstract protected void showVirtualKeyboard(boolean enable); + abstract protected void showKeyboardControl(boolean enable); abstract protected String[] getSysArchives(); public ScummVM(AssetManager asset_manager, SurfaceHolder holder) { diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java index 58af703d563..7bb0fe80574 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java @@ -15,10 +15,12 @@ import android.os.Environment; import android.text.ClipboardManager; import android.util.DisplayMetrics; import android.util.Log; +import android.view.View; import android.view.SurfaceView; import android.view.SurfaceHolder; import android.view.MotionEvent; import android.view.inputmethod.InputMethodManager; +import android.widget.ImageView; import android.widget.Toast; import java.io.File; @@ -39,6 +41,17 @@ public class ScummVMActivity extends Activity { } } + public View.OnClickListener keyboardBtnOnClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + runOnUiThread(new Runnable() { + public void run() { + toggleKeyboard(); + } + }); + } + }; + private class MyScummVM extends ScummVM { private boolean usingSmallScreen() { // Multiple screen sizes came in with Android 1.6. Have @@ -150,6 +163,15 @@ public class ScummVMActivity extends Activity { }); } + @Override + protected void showKeyboardControl(final boolean enable) { + runOnUiThread(new Runnable() { + public void run() { + showKeyboardView(enable); + } + }); + } + @Override protected String[] getSysArchives() { return new String[0]; @@ -233,6 +255,9 @@ public class ScummVMActivity extends Activity { _events = new ScummVMEventsHoneycomb(this, _scummvm, _mouseHelper); } + // On screen button listener + ((ImageView)findViewById(R.id.show_keyboard)).setOnClickListener(keyboardBtnOnClickListener); + main_surface.setOnKeyListener(_events); main_surface.setOnTouchListener(_events); @@ -324,6 +349,25 @@ public class ScummVMActivity extends Activity { InputMethodManager.HIDE_IMPLICIT_ONLY); } + private void toggleKeyboard() { + SurfaceView main_surface = (SurfaceView)findViewById(R.id.main_surface); + InputMethodManager imm = (InputMethodManager) + getSystemService(INPUT_METHOD_SERVICE); + + imm.toggleSoftInputFromWindow(main_surface.getWindowToken(), + InputMethodManager.SHOW_IMPLICIT, + InputMethodManager.HIDE_IMPLICIT_ONLY); + } + + private void showKeyboardView(boolean show) { + ImageView keyboardBtn = (ImageView)findViewById(R.id.show_keyboard); + + if (show) + keyboardBtn.setVisibility(View.VISIBLE); + else + keyboardBtn.setVisibility(View.GONE); + } + private void showMouseCursor(boolean show) { /* Currently hiding the system mouse cursor is only supported on OUYA. If other systems provide similar diff --git a/dists/android/res/drawable-hdpi/ic_action_settings.png b/dists/android/res/drawable-hdpi/ic_action_settings.png new file mode 100755 index 0000000000000000000000000000000000000000..d9733250f5216aab9ab74f4684534e0a35bd7193 GIT binary patch literal 437 zcmV;m0ZRUfP)m#0`kdGa8hbm&e8gC4@!r z#zB0UU(}nzTxytrYJ+Do3`!AJ8f7|VT-89%MI4HSe({Vij&jLDk}$n|a1^u95oDHJ z#B5++x|Jw99lv8o30s(34yOic5Pt!4HUa}RboIuq7Z`ZOT*UW07rHFW6+U=|a^e7E zzjZ9M1(Mgy0DdhsfnsWoeDv#JZrs^z{qC%U^HW}hJW0i3pht8_Rw&V(%0iYn;p|U7 f7K;_RJ^~B?-@SK_4WXY400000NkvXXu0mjf^c1cV literal 0 HcmV?d00001 diff --git a/dists/android/res/drawable-mdpi/ic_action_settings.png b/dists/android/res/drawable-mdpi/ic_action_settings.png new file mode 100755 index 0000000000000000000000000000000000000000..898735802155296266da7318f6b4272609f79155 GIT binary patch literal 310 zcmV-60m=S}P)F4h3>c|t*#H0krGS(V zl)HtIk?|S59k3rr@j|(ufevsaq=$*hAx9AlDbk7B6(1g-~zCAmTY2Y(SX@Cm(`!iZLyhW8LAU1!~q#%OkjAdvk z-h^6l#6*p}ObH;S9GHb8REo*8bBL7#K;IezshI}kQ^P`>snfzW}r#sDOA>l(i0bhSs{uYf8@Z#b-4-ub$ ze5g$bdelyU4coO7kU@Y0Y%CX1cg|kD#${v5iI?TU(&bbBvzkRff6fk`7p0uo-!{H3 zXQ(&=Gj~8eV@0yac1)dWBJ^$Pa&(ar69yq5T{PMW7@A-whJJlSfsp#W7?8t7bbi1R z`aLN_#Fu`L@)DHEKiTxV_9zhT1jz#+U|~OCihd8_FZl2Srl`db{sMkLOnyKJe_?q) zpwHMYmb+p{6o3G|1k@u#piTn%IBV1IRffZnW N002ovPDHLkV1k>8#gG61 literal 0 HcmV?d00001 diff --git a/dists/android/res/drawable-xxhdpi/ic_action_settings.png b/dists/android/res/drawable-xxhdpi/ic_action_settings.png new file mode 100755 index 0000000000000000000000000000000000000000..51f75277893a6a7404706dacab4a5d89723709e8 GIT binary patch literal 672 zcmV;R0$=@!P)`;C<5Gw+-u|5`7p)+00000 z005LkRpLosE|*8y)%MF%RaKt|NK^P1*==N7{`t{awoXLs5D>5UTiLA#njJ*KYs%m2 zp`dsE+M(&nwnac-Hj&yQz>%d-TiZz^K#>{&g@6DAAOI9u+%bgD8W~U>1C1e`JzwHA zwXyI#cwhYYiM+X*K*#Yt-&Qtf`CNkN0}udH>4a^^)|6BrIp>B?0GA*@00IC32q=aV z0>X0kX`3>pqAH-D-0LU1>=yGeU>B)v+JRWW!r#p2$oHe;>3P)+?WbfUwjC7>FSN5P$#}HxeF` z3ks3XnNl9fWS9#I@l16}c_eZ{^Z|f?sgP_k&W2pQuH&&YIeY>D0SG_7600IyIcizb$U>Md5QYPCx zQV{}d%3<%&^f3GNf;1tRm5+#Q{*@sB0000006 + + + + + +