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:
Anthony Calosa
2023-06-25 13:54:32 +08:00
parent 8468f5a21e
commit 198180eec5
4 changed files with 101 additions and 34 deletions

View File

@@ -16,7 +16,9 @@
<application
android:allowBackup="true"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|screenLayout"
android:isGame="true"
android:appCategory="game"
android:configChanges="density|fontScale|keyboard|keyboardHidden|layoutDirection|locale|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
@@ -24,8 +26,14 @@
<activity
android:name=".Main"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|screenLayout"
android:configChanges="density|fontScale|keyboard|keyboardHidden|layoutDirection|locale|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"
android:launchMode="singleInstance"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:exported="false">
</activity>
<activity
android:name=".Launcher"
android:configChanges="density|fontScale|keyboard|keyboardHidden|layoutDirection|locale|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"
android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -37,7 +45,6 @@
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity android:name=".Exiter" android:theme="@android:style/Theme.NoDisplay"/>
<meta-data android:name="io.sentry.dsn" android:value="https://a0b8dbad9b8a49cfa51bf65d462e8dae:b3f27d7461224cb8836eb5c6050c666c@sentry.cardforge.org/2?buffer.enabled=false" />
<!-- manually added -->

View File

@@ -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) {
}
}

View 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);
}
}
}

View File

@@ -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;