diff --git a/forge-gui-android/AndroidManifest.xml b/forge-gui-android/AndroidManifest.xml index 4a93bf1c4e4..34ea6f288d3 100644 --- a/forge-gui-android/AndroidManifest.xml +++ b/forge-gui-android/AndroidManifest.xml @@ -16,7 +16,9 @@ + + @@ -37,7 +45,6 @@ - diff --git a/forge-gui-android/src/forge/app/Exiter.java b/forge-gui-android/src/forge/app/Exiter.java deleted file mode 100644 index 25709ba2ea0..00000000000 --- a/forge-gui-android/src/forge/app/Exiter.java +++ /dev/null @@ -1,10 +0,0 @@ -package forge.app; - -import android.app.Activity; -import android.os.Bundle; - -public class Exiter extends Activity { - @Override - protected void onCreate(Bundle savedInstanceState) { - } -} diff --git a/forge-gui-android/src/forge/app/Launcher.java b/forge-gui-android/src/forge/app/Launcher.java new file mode 100644 index 00000000000..84dabfd9797 --- /dev/null +++ b/forge-gui-android/src/forge/app/Launcher.java @@ -0,0 +1,91 @@ +package forge.app; + +import android.app.Activity; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import forge.gui.GuiBase; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class Launcher extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Intent main = new Intent(Launcher.this, Main.class); + main.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(main); + + Intent intent = getIntent(); + String action = intent.getAction(); + String type = intent.getType(); + + if (Intent.ACTION_SEND.equals(action) && type != null) { + final Handler handler = new Handler(); + handler.postDelayed(() -> { + if ("text/plain".equals(type)) { + Uri textUri = intent.getParcelableExtra(Intent.EXTRA_STREAM); + if (textUri != null) { + try { + InputStream in = getContentResolver().openInputStream(textUri); + BufferedReader r = new BufferedReader(new InputStreamReader(in)); + StringBuilder total = new StringBuilder(); + for (String line; (line = r.readLine()) != null; ) { + total.append(line).append('\n'); + } + GuiBase.getInterface().copyToClipboard(total.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + try { + GuiBase.getInterface().copyToClipboard(intent.getStringExtra(Intent.EXTRA_TEXT)); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }, 1500); + } + finish(); + } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + setIntent(intent); + String action = intent.getAction(); + String type = intent.getType(); + + if (Intent.ACTION_SEND.equals(action) && type != null) { + final Handler handler = new Handler(); + handler.postDelayed(() -> { + if ("text/plain".equals(type)) { + Uri textUri = intent.getParcelableExtra(Intent.EXTRA_STREAM); + if (textUri != null) { + try { + InputStream in = getContentResolver().openInputStream(textUri); + BufferedReader r = new BufferedReader(new InputStreamReader(in)); + StringBuilder total = new StringBuilder(); + for (String line; (line = r.readLine()) != null; ) { + total.append(line).append('\n'); + } + GuiBase.getInterface().copyToClipboard(total.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + try { + GuiBase.getInterface().copyToClipboard(intent.getStringExtra(Intent.EXTRA_TEXT)); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }, 1500); + } + } +} diff --git a/forge-gui-android/src/forge/app/Main.java b/forge-gui-android/src/forge/app/Main.java index 45140d7925d..166c282da3c 100644 --- a/forge-gui-android/src/forge/app/Main.java +++ b/forge-gui-android/src/forge/app/Main.java @@ -71,33 +71,12 @@ public class Main extends AndroidApplication { 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;