From 12c232eefc7c78f7d40da9894e395dee4ce6d8c2 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Sun, 18 Aug 2019 22:58:13 +0100 Subject: ANDROID: Add a button to show the virtual keyboard --- .../android/org/scummvm/scummvm/ScummVM.java | 1 + .../org/scummvm/scummvm/ScummVMActivity.java | 44 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) (limited to 'backends/platform/android/org/scummvm') diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVM.java b/backends/platform/android/org/scummvm/scummvm/ScummVM.java index 7b6627f667..37fe76ebda 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 58af703d56..7bb0fe8057 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 -- cgit v1.2.3