diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 38c0b93..5e65b71 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -72,7 +72,15 @@ + + diff --git a/app/src/main/java/be/mygod/reactmap/MainActivity.kt b/app/src/main/java/be/mygod/reactmap/MainActivity.kt index 1ef39e1..f3df53d 100644 --- a/app/src/main/java/be/mygod/reactmap/MainActivity.kt +++ b/app/src/main/java/be/mygod/reactmap/MainActivity.kt @@ -37,6 +37,8 @@ class MainActivity : FragmentActivity(), Shizuku.OnRequestPermissionResultListen const val ACTION_RESTART_GAME = "be.mygod.reactmap.action.RESTART_GAME" const val ACTION_ACCUWEATHER = "be.mygod.reactmap.action.ACCUWEATHER" private const val KEY_WELCOME = "welcome" + private const val PACKAGE_POKEMON_GO = "com.nianticlabs.pokemongo" + private const val PACKAGE_POKEMON_GO_ARES = "com.nianticlabs.pokemongo.ares" private val forceStopPackage by lazy { Class.forName("android.app.IActivityManager").getDeclaredMethod( @@ -99,6 +101,7 @@ class MainActivity : FragmentActivity(), Shizuku.OnRequestPermissionResultListen Snackbar.make(findViewById(R.id.content), R.string.restart_game_dialog_message, Snackbar.LENGTH_LONG).show() } + "be.mygod.reactmap.action.SPLITSCREEN" -> pendingSplitscreen = true Intent.ACTION_VIEW -> { Timber.d("Handling URI ${intent.data}") if (currentFragment?.handleUri(intent.data) != true) pendingOverrideUri = intent.data @@ -121,14 +124,28 @@ class MainActivity : FragmentActivity(), Shizuku.OnRequestPermissionResultListen setPadding(padding, 0, padding, 0) } setView(switch) - setPositiveButton(R.string.restart_game_standard) { _, _ -> - restartGame("com.nianticlabs.pokemongo", switch.isChecked) - } + setPositiveButton(R.string.restart_game_standard) { _, _ -> restartGame(PACKAGE_POKEMON_GO, switch.isChecked) } setNegativeButton(R.string.restart_game_samsung) { _, _ -> - restartGame("com.nianticlabs.pokemongo.ares", switch.isChecked) + restartGame(PACKAGE_POKEMON_GO_ARES, switch.isChecked) } setNeutralButton(android.R.string.cancel, null) }.show() + private var pendingSplitscreen = false + override fun onEnterAnimationComplete() { + if (!pendingSplitscreen) return + startActivity(listOf(PACKAGE_POKEMON_GO, PACKAGE_POKEMON_GO_ARES) + .mapNotNull(app.packageManager::getLaunchIntentForPackage).let { list -> + when (list.size) { + 0 -> Intent(Intent.ACTION_CHOOSER).putExtra(Intent.EXTRA_INTENT, Intent()) + 1 -> list.first() + else -> Intent(Intent.ACTION_CHOOSER).apply { + putExtra(Intent.EXTRA_INTENT, list.first()) + putExtra(Intent.EXTRA_ALTERNATE_INTENTS, list.drop(1).toTypedArray()) + } + } + }.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT)) + pendingSplitscreen = false + } override fun onRequestPermissionResult(requestCode: Int, grantResult: Int) { if (grantResult != PackageManager.PERMISSION_GRANTED) { diff --git a/app/src/main/java/be/mygod/reactmap/SplitscreenShortcut.kt b/app/src/main/java/be/mygod/reactmap/SplitscreenShortcut.kt new file mode 100644 index 0000000..7cae1e9 --- /dev/null +++ b/app/src/main/java/be/mygod/reactmap/SplitscreenShortcut.kt @@ -0,0 +1,14 @@ +package be.mygod.reactmap + +import android.app.Activity +import android.content.Intent +import android.os.Bundle + +class SplitscreenShortcut : Activity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + // https://developer.android.com/develop/ui/views/launch/shortcuts/managing-shortcuts#start-one + startActivity(Intent(this, MainActivity::class.java).setAction(intent.action)) + finish() + } +} diff --git a/app/src/main/res/drawable/ic_device_splitscreen.xml b/app/src/main/res/drawable/ic_device_splitscreen.xml new file mode 100644 index 0000000..266cac3 --- /dev/null +++ b/app/src/main/res/drawable/ic_device_splitscreen.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_shortcut_splitscreen.xml b/app/src/main/res/drawable/ic_shortcut_splitscreen.xml new file mode 100644 index 0000000..f96c646 --- /dev/null +++ b/app/src/main/res/drawable/ic_shortcut_splitscreen.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 459634f..c8a4c9f 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -27,5 +27,7 @@ Użytkownik nieznaleziony - brak dostępu do powiadomień Włącz podzielony ekran + Podzielony ekran + Podziel ekran z grą Odśwież diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4642493..3a98e98 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -30,6 +30,8 @@ Human not found Enter split screen + Split screen + Start split screen with game Refresh Terms of Use\nBy using %s (“the Map”) on your vehicle, you diff --git a/app/src/main/res/xml/shortcuts.xml b/app/src/main/res/xml/shortcuts.xml new file mode 100644 index 0000000..5e58749 --- /dev/null +++ b/app/src/main/res/xml/shortcuts.xml @@ -0,0 +1,14 @@ + + + + + +