mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
fix share text/data to Forge app
- add additional launcher activity to prevent GLES Context loss (when sharing data via intent) - fix passing data from another app to Forge via share text / share file / share deck
This commit is contained in:
@@ -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) {
|
||||
}
|
||||
}
|
||||
91
forge-gui-android/src/forge/app/Launcher.java
Normal file
91
forge-gui-android/src/forge/app/Launcher.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user