ANDROID: Add a button to show the virtual keyboard

This commit is contained in:
Cameron Cawley 2019-08-18 22:58:13 +01:00 committed by Filippos Karapetis
parent c2054682f0
commit 12c232eefc
11 changed files with 99 additions and 3 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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");

View file

@ -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;

View file

@ -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) {

View file

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

View file

@ -1,12 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.scummvm.scummvm.EditableSurfaceView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:focusable="true"
android:focusableInTouchMode="true"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_settings"
android:id="@+id/show_keyboard"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" />
</RelativeLayout>