From 9b540831dbb96d5113e3b894b64ac2d667568669 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Sat, 17 Jun 2023 16:11:15 +0800 Subject: [PATCH 1/2] [Android] support receiving text intent - allow deck manager to import shared text intent --- forge-gui-android/AndroidManifest.xml | 9 +++++- forge-gui-android/src/forge/app/Main.java | 38 ++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/forge-gui-android/AndroidManifest.xml b/forge-gui-android/AndroidManifest.xml index c8617a41c1b..4a93bf1c4e4 100644 --- a/forge-gui-android/AndroidManifest.xml +++ b/forge-gui-android/AndroidManifest.xml @@ -24,11 +24,18 @@ + android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|screenLayout" + android:launchMode="singleInstance" + android:theme="@android:style/Theme.Black.NoTitleBar"> + + + + + diff --git a/forge-gui-android/src/forge/app/Main.java b/forge-gui-android/src/forge/app/Main.java index b7b83289f27..edfc0da6b09 100644 --- a/forge-gui-android/src/forge/app/Main.java +++ b/forge-gui-android/src/forge/app/Main.java @@ -3,6 +3,7 @@ package forge.app; import java.io.File; import java.io.InputStream; import java.io.OutputStream; +import java.text.Normalizer; import java.util.ArrayList; import android.graphics.Point; @@ -62,11 +63,44 @@ import org.apache.commons.lang3.tuple.Pair; public class Main extends AndroidApplication { AndroidAdapter Gadapter; ArrayList gamepads; + AndroidClipboard androidClipboard; + boolean hasLaunched; + + private AndroidClipboard getAndroidClipboard() { + if (androidClipboard == null) + androidClipboard = new AndroidClipboard(); + return androidClipboard; + } + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + String action = intent.getAction(); + String type = intent.getType(); + + if (Intent.ACTION_SEND.equals(action) && type != null) { + if ("text/plain".equals(type)) { + getAndroidClipboard().setContents(intent.getStringExtra(Intent.EXTRA_TEXT)); + } + } + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gamepads = getGameControllers(); + + Intent intent = getIntent(); + String action = intent.getAction(); + String type = intent.getType(); + + if (Intent.ACTION_SEND.equals(action) && type != null) { + if ("text/plain".equals(type)) { + getAndroidClipboard().setContents(intent.getStringExtra(Intent.EXTRA_TEXT)); + } + } + if (hasLaunched) + return; + hasLaunched = true; //init Sentry //SentryAndroid.init(this); @@ -262,6 +296,7 @@ public class Main extends AndroidApplication { @Override protected void onDestroy() { + hasLaunched = false; try { final Forge forge = (Forge) Gdx.app.getApplicationListener(); if (forge != null) @@ -315,7 +350,8 @@ public class Main extends AndroidApplication { public String getContents() { if (cm.getPrimaryClip().getItemCount() > 0) { try { - return cm.getPrimaryClip().getItemAt(0).coerceToText(getContext()).toString(); + String text = cm.getPrimaryClip().getItemAt(0).coerceToText(getContext()).toString(); + return Normalizer.normalize(text, Normalizer.Form.NFD); } catch (Exception ex) { ex.printStackTrace(); From 68d98eeb55e70d79522ce1828a74a23ba27822f4 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Sat, 17 Jun 2023 16:14:31 +0800 Subject: [PATCH 2/2] Update Main.java --- forge-gui-android/src/forge/app/Main.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/forge-gui-android/src/forge/app/Main.java b/forge-gui-android/src/forge/app/Main.java index edfc0da6b09..45140d7925d 100644 --- a/forge-gui-android/src/forge/app/Main.java +++ b/forge-gui-android/src/forge/app/Main.java @@ -245,7 +245,7 @@ public class Main extends AndroidApplication { String message = getDeviceName()+"\n"+"Android "+AndroidRelease+"\n"+"RAM "+ totalRAM+"MB" +"\n"+"LibGDX "+ Version.VERSION+"\n"+"Can't access external storage"; Sentry.addBreadcrumb(new Breadcrumb(message)); Main.this.setRequestedOrientation(Main.this.getResources().getConfiguration().orientation); - initialize(Forge.getApp(new AndroidClipboard(), adapter, "", false, true, totalRAM, isTabletDevice, AndroidAPI, AndroidRelease, getDeviceName())); + initialize(Forge.getApp(getAndroidClipboard(), adapter, "", false, true, totalRAM, isTabletDevice, AndroidAPI, AndroidRelease, getDeviceName())); displayMessage(adapter, true, message); return; } @@ -258,7 +258,7 @@ public class Main extends AndroidApplication { String message = getDeviceName()+"\n"+"Android "+AndroidRelease+"\n"+"RAM "+ totalRAM+"MB" +"\n"+"LibGDX "+ Version.VERSION+"\n"+"Can't access external storage\nPath: " + assetsDir; Sentry.addBreadcrumb(new Breadcrumb(message)); Main.this.setRequestedOrientation(Main.this.getResources().getConfiguration().orientation); - initialize(Forge.getApp(new AndroidClipboard(), adapter, "", false, true, totalRAM, isTabletDevice, AndroidAPI, AndroidRelease, getDeviceName())); + initialize(Forge.getApp(getAndroidClipboard(), adapter, "", false, true, totalRAM, isTabletDevice, AndroidAPI, AndroidRelease, getDeviceName())); displayMessage(adapter, true, message); return; } @@ -284,12 +284,12 @@ public class Main extends AndroidApplication { isPortrait = true; Main.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } - initialize(Forge.getApp(new AndroidClipboard(), adapter, assetsDir, propertyConfig, isPortrait, totalRAM, isTabletDevice, AndroidAPI, AndroidRelease, getDeviceName())); + initialize(Forge.getApp(getAndroidClipboard(), adapter, assetsDir, propertyConfig, isPortrait, totalRAM, isTabletDevice, AndroidAPI, AndroidRelease, getDeviceName())); } else { isPortrait = true; //fake init for permission instruction Main.this.setRequestedOrientation(Main.this.getResources().getConfiguration().orientation); - initialize(Forge.getApp(new AndroidClipboard(), adapter, "", false, isPortrait, totalRAM, isTabletDevice, AndroidAPI, AndroidRelease, getDeviceName())); + initialize(Forge.getApp(getAndroidClipboard(), adapter, "", false, isPortrait, totalRAM, isTabletDevice, AndroidAPI, AndroidRelease, getDeviceName())); displayMessage(adapter, false, ""); } }