From dc0d4b3b762c675046046b21928b8a2cda613161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 26 Aug 2024 23:46:20 +0200 Subject: [PATCH] Add Android shortcuts for launching with Vulkan/OpenGL Define shortcuts to launch the client with either Vulkan or OpenGL graphics backend, which can be accessed by long-pressing the app icon on the home screen. This feature is available for Android 7.1 and newer. --- scripts/android/cmake_android.sh | 2 ++ scripts/android/files/AndroidManifest.xml | 6 +++- scripts/android/files/build.sh | 2 ++ .../java/org/ddnet/client/NativeMain.java | 24 +++++++++++++-- scripts/android/files/res/values/strings.xml | 4 ++- scripts/android/files/res/xml/shortcuts.xml | 30 +++++++++++++++++++ 6 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 scripts/android/files/res/xml/shortcuts.xml diff --git a/scripts/android/cmake_android.sh b/scripts/android/cmake_android.sh index 81720dc60..b2468227f 100755 --- a/scripts/android/cmake_android.sh +++ b/scripts/android/cmake_android.sh @@ -197,6 +197,7 @@ cd "${BUILD_FOLDER}" || exit 1 mkdir -p src/main mkdir -p src/main/res/values +mkdir -p src/main/res/xml mkdir -p src/main/res/mipmap function copy_dummy_files() { @@ -213,6 +214,7 @@ copy_dummy_files scripts/android/files/proguard-rules.pro proguard-rules.pro copy_dummy_files scripts/android/files/settings.gradle settings.gradle copy_dummy_files scripts/android/files/AndroidManifest.xml src/main/AndroidManifest.xml copy_dummy_files scripts/android/files/res/values/strings.xml src/main/res/values/strings.xml +copy_dummy_files scripts/android/files/res/xml/shortcuts.xml src/main/res/xml/shortcuts.xml copy_dummy_files other/icons/DDNet_256x256x32.png src/main/res/mipmap/ic_launcher.png copy_dummy_files other/icons/DDNet_256x256x32.png src/main/res/mipmap/ic_launcher_round.png diff --git a/scripts/android/files/AndroidManifest.xml b/scripts/android/files/AndroidManifest.xml index e1b356e49..fcf771bec 100644 --- a/scripts/android/files/AndroidManifest.xml +++ b/scripts/android/files/AndroidManifest.xml @@ -30,7 +30,8 @@ android:name="org.ddnet.client.NativeMain" android:exported="true" android:configChanges="orientation|screenSize|screenLayout|keyboardHidden" - android:screenOrientation="landscape"> + android:screenOrientation="landscape" + android:launchMode="singleInstance"> @@ -38,6 +39,9 @@ + diff --git a/scripts/android/files/build.sh b/scripts/android/files/build.sh index f2528b091..a52d3c3a5 100644 --- a/scripts/android/files/build.sh +++ b/scripts/android/files/build.sh @@ -51,6 +51,8 @@ sed -i "s/TW_VERSION_NAME/${TW_VERSION_NAME}/g" build.gradle sed -i "s/DDNet/${APK_BASENAME}/g" src/main/res/values/strings.xml +sed -i "s/org.ddnet.client/${APK_PACKAGE_NAME}/g" src/main/res/xml/shortcuts.xml + sed -i "s/\"DDNet\"/\"${APK_BASENAME}\"/g" src/main/AndroidManifest.xml sed -i "s/org.ddnet.client/${APK_PACKAGE_NAME}/g" src/main/AndroidManifest.xml diff --git a/scripts/android/files/java/org/ddnet/client/NativeMain.java b/scripts/android/files/java/org/ddnet/client/NativeMain.java index a3d6400f8..fc994236d 100644 --- a/scripts/android/files/java/org/ddnet/client/NativeMain.java +++ b/scripts/android/files/java/org/ddnet/client/NativeMain.java @@ -10,6 +10,8 @@ public class NativeMain extends SDLActivity { private static final int COMMAND_RESTART_APP = SDLActivity.COMMAND_USER + 1; + private String[] launchArguments = new String[0]; + @Override protected String[] getLibraries() { return new String[] { @@ -20,17 +22,35 @@ public class NativeMain extends SDLActivity { @Override public void onCreate(Bundle SavedInstanceState) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + + Intent intent = getIntent(); + if(intent != null) { + String gfxBackend = intent.getStringExtra("gfx-backend"); + if(gfxBackend != null) { + if(gfxBackend.equals("Vulkan")) { + launchArguments = new String[] {"gfx_backend Vulkan"}; + } else if(gfxBackend.equals("OpenGL")) { + launchArguments = new String[] {"gfx_backend OpenGL"}; + } + } + } + super.onCreate(SavedInstanceState); } + @Override + protected String[] getArguments() { + return launchArguments; + } + @Override protected boolean onUnhandledMessage(int command, Object param) { if(command == COMMAND_RESTART_APP) { restartApp(); return true; } - return false; - } + return false; + } private void restartApp() { Intent restartIntent = diff --git a/scripts/android/files/res/values/strings.xml b/scripts/android/files/res/values/strings.xml index b3f47362e..24bbf05b0 100644 --- a/scripts/android/files/res/values/strings.xml +++ b/scripts/android/files/res/values/strings.xml @@ -1,4 +1,6 @@ - DDNet + DDNet + Play (Vulkan) + Play (OpenGL) diff --git a/scripts/android/files/res/xml/shortcuts.xml b/scripts/android/files/res/xml/shortcuts.xml new file mode 100644 index 000000000..558afd216 --- /dev/null +++ b/scripts/android/files/res/xml/shortcuts.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + +