aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/android/org
diff options
context:
space:
mode:
authorCameron Cawley2018-10-02 14:57:48 +0100
committerDavid Turner2018-10-05 00:10:27 +0100
commit539c3330a8dd4a0d47e3b422bf527a4d4f6a22e5 (patch)
treebbcdce724bf78c20ba41263f09cee250a5a61afb /backends/platform/android/org
parent66153aa28ac26114bd051182f621799850d90a6f (diff)
downloadscummvm-rg350-539c3330a8dd4a0d47e3b422bf527a4d4f6a22e5.tar.gz
scummvm-rg350-539c3330a8dd4a0d47e3b422bf527a4d4f6a22e5.tar.bz2
scummvm-rg350-539c3330a8dd4a0d47e3b422bf527a4d4f6a22e5.zip
ANDROID: Implement clipboard support
Diffstat (limited to 'backends/platform/android/org')
-rw-r--r--backends/platform/android/org/scummvm/scummvm/ScummVM.java4
-rw-r--r--backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java41
2 files changed, 45 insertions, 0 deletions
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVM.java b/backends/platform/android/org/scummvm/scummvm/ScummVM.java
index 47dcb32b22..163b50f42d 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVM.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVM.java
@@ -49,11 +49,15 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {
// Feed an event to ScummVM. Safe to call from other threads.
final public native void pushEvent(int type, int arg1, int arg2, int arg3,
int arg4, int arg5);
+ final public native String getCurrentCharset();
// Callbacks from C++ peer instance
abstract protected void getDPI(float[] values);
abstract protected void displayMessageOnOSD(String msg);
abstract protected void openUrl(String url);
+ abstract protected boolean hasTextInClipboard();
+ abstract protected byte[] getTextFromClipboard();
+ abstract protected boolean setTextInClipboard(byte[] text);
abstract protected boolean isConnectionLimited();
abstract protected void setWindowCaption(String caption);
abstract protected void showVirtualKeyboard(boolean enable);
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
index 225496ca0d..58af703d56 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
@@ -12,6 +12,7 @@ import android.net.wifi.WifiInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
+import android.text.ClipboardManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.SurfaceView;
@@ -27,6 +28,8 @@ public class ScummVMActivity extends Activity {
/* Establish whether the hover events are available */
private static boolean _hoverAvailable;
+ private ClipboardManager _clipboard;
+
static {
try {
MouseHelper.checkHoverAvailable(); // this throws exception if we're on too old version
@@ -84,6 +87,42 @@ public class ScummVMActivity extends Activity {
}
@Override
+ protected boolean hasTextInClipboard() {
+ return _clipboard.hasText();
+ }
+
+ @Override
+ protected byte[] getTextFromClipboard() {
+ CharSequence text = _clipboard.getText();
+ if (text != null) {
+ String encoding = getCurrentCharset();
+ byte[] out;
+ Log.d(LOG_TAG, String.format("Converting from UTF-8 to %s", encoding));
+ try {
+ out = text.toString().getBytes(encoding);
+ } catch (java.io.UnsupportedEncodingException e) {
+ out = text.toString().getBytes();
+ }
+ return out;
+ }
+ return null;
+ }
+
+ @Override
+ protected boolean setTextInClipboard(byte[] text) {
+ String encoding = getCurrentCharset();
+ String out;
+ Log.d(LOG_TAG, String.format("Converting from %s to UTF-8", encoding));
+ try {
+ out = new String(text, encoding);
+ } catch (java.io.UnsupportedEncodingException e) {
+ out = new String(text);
+ }
+ _clipboard.setText(out);
+ return true;
+ }
+
+ @Override
protected boolean isConnectionLimited() {
WifiManager wifiMgr = (WifiManager)getSystemService(Context.WIFI_SERVICE);
if (wifiMgr != null && wifiMgr.isWifiEnabled()) {
@@ -167,6 +206,8 @@ public class ScummVMActivity extends Activity {
savePath = getDir("saves", MODE_WORLD_READABLE).getPath();
}
+ _clipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
+
// Start ScummVM
_scummvm = new MyScummVM(main_surface.getHolder());