diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index b1416dbc6..999317511 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -3134,7 +3134,36 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { ) /** Pages for the bottom-screen dashboard; the dashboard is offered only while at least one exists. */ - private fun bottomPages(): List = sessionBottomPages(BottomPageActions(takeScreenshot = ::captureScreenshot, fps = { if (::hud.isInitialized) hud.liveFps else null })) + private fun bottomPages(): List = sessionBottomPages(BottomPageActions( + takeScreenshot = ::captureScreenshot, + fps = { if (::hud.isInitialized) hud.liveFps else null }, + openSettings = ::openSettingsBelow, + )) + + // A settings page opened on the bottom screen sits under the dashboard window, so the dashboard hides + // until the setting is on; choosing Dashboard in the menu again shows it sooner. + private fun openSettingsBelow(intent: android.content.Intent, done: () -> Boolean) { + val presentation = secondScreenPresentation ?: return + val options = android.app.ActivityOptions.makeBasic().setLaunchDisplayId(presentation.display.displayId) + val opened = listOf(intent, android.content.Intent(android.provider.Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)).any { + runCatching { startActivity(android.content.Intent(it).addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK), options.toBundle()) } + .onFailure { e -> Log.w(TAG, "could not open ${it.action} on display ${presentation.display.displayId}", e) } + .isSuccess + } + if (!opened) return + presentation.hide() + var checks = 0 + uiHandler.postDelayed(object : Runnable { + override fun run() { + if (secondScreenPresentation !== presentation || presentation.isShowing) return + if (done()) { + presentation.show() + return + } + if (++checks < SETTINGS_WATCH_CHECKS) uiHandler.postDelayed(this, SETTINGS_WATCH_MS) + } + }, SETTINGS_WATCH_MS) + } /** Copies the game frame (no overlay) at the size it is shown and saves it to Pictures/DroidDeck. */ private fun captureScreenshot(onDone: (Boolean) -> Unit) { @@ -4564,6 +4593,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private const val TEXT_FIELD_TAP_MS = 1_000L private const val PAUSED_FRAME_MAX_EDGE = 1920f private const val PAUSED_FRAME_REDRAW_MS = 150L + private const val SETTINGS_WATCH_MS = 1_000L + private const val SETTINGS_WATCH_CHECKS = 600 private const val TAG = "SessionActivity" private var startedScreens = 0 @Volatile private var activeInstallWorker: Any? = null diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BottomChatPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/BottomChatPage.kt index d5fa26467..cd74f18bc 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BottomChatPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BottomChatPage.kt @@ -89,9 +89,12 @@ private fun VoiceRow(context: Context) { BottomPillButton(stringResource(if (on) R.string.bottom_chat_mic_on else R.string.bottom_chat_mic_off), "bottom-chat-mic") { SessionService.setMicEnabled(context, !on) } + } else { + Text(stringResource(R.string.bottom_chat_mic_unavailable), fontSize = 12.sp, color = colors.onSurfaceVariant, + maxLines = 3, modifier = Modifier.weight(1f)) } Text(stringResource(R.string.bottom_chat_volume, volume * 100 / max), fontSize = 14.sp, color = colors.onSurfaceVariant, - modifier = Modifier.weight(1f), textAlign = TextAlign.End) + modifier = if (SessionState.micAvailable) Modifier.weight(1f) else Modifier, textAlign = TextAlign.End) BottomPillButton("−", "bottom-chat-volume-down") { step(AudioManager.ADJUST_LOWER) } BottomPillButton("+", "bottom-chat-volume-up") { step(AudioManager.ADJUST_RAISE) } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BottomNotificationsPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/BottomNotificationsPage.kt index 10cbaf786..379c74b6d 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BottomNotificationsPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BottomNotificationsPage.kt @@ -39,8 +39,17 @@ import com.droiddeck.launcher.R import com.droiddeck.launcher.session.BottomNotifications import kotlinx.coroutines.delay +/** DroidDeck's own switch on Android 11 and later; the list of all apps before that. */ +internal fun notificationAccessIntent(context: android.content.Context): Intent = + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { + Intent(Settings.ACTION_NOTIFICATION_LISTENER_DETAIL_SETTINGS).putExtra( + Settings.EXTRA_NOTIFICATION_LISTENER_COMPONENT_NAME, + android.content.ComponentName(context, com.droiddeck.launcher.session.BottomNotificationListener::class.java).flattenToString(), + ) + } else Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS) + @Composable -fun BottomNotificationsPage() { +fun BottomNotificationsPage(openSettings: ((Intent, () -> Boolean) -> Unit)?) { val context = LocalContext.current val colors = MaterialTheme.colorScheme val pal = LocalPalette.current @@ -56,9 +65,9 @@ fun BottomNotificationsPage() { verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterVertically)) { Text(stringResource(R.string.bottom_notifications_why), fontSize = 15.sp, color = colors.onBackground, textAlign = TextAlign.Center) BottomPillButton(stringResource(R.string.bottom_notifications_allow), "bottom-notifications-allow") { - runCatching { - context.startActivity(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) - } + val intent = notificationAccessIntent(context) + if (openSettings != null) openSettings(intent) { BottomNotifications.granted(context) } + else runCatching { context.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) } } } return diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BottomPages.kt b/app/src/main/java/com/droiddeck/launcher/ui/BottomPages.kt index 183427858..2cc648b76 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BottomPages.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BottomPages.kt @@ -12,13 +12,15 @@ import com.droiddeck.launcher.R class BottomPageActions( val takeScreenshot: ((onDone: (Boolean) -> Unit) -> Unit)? = null, val fps: () -> Float? = { null }, + /** Opens an Android settings page on the bottom screen; the dashboard comes back once [done] is true. */ + val openSettings: ((intent: android.content.Intent, done: () -> Boolean) -> Unit)? = null, ) /** The pages the bottom-screen dashboard offers during a session, in tab order. */ fun sessionBottomPages(actions: BottomPageActions): List = listOf( BottomPage("telemetry", R.string.bottom_page_telemetry, Icons.Outlined.Speed) { BottomTelemetryPage(actions.fps) }, BottomPage("downloads", R.string.bottom_page_downloads, Icons.Outlined.Download) { BottomDownloadsPage() }, - BottomPage("notifications", R.string.bottom_page_notifications, Icons.Outlined.Notifications) { BottomNotificationsPage() }, + BottomPage("notifications", R.string.bottom_page_notifications, Icons.Outlined.Notifications) { BottomNotificationsPage(actions.openSettings) }, BottomPage("screenshots", R.string.bottom_page_screenshots, Icons.Outlined.PhotoLibrary) { BottomScreenshotsPage(actions.takeScreenshot) }, BottomPage("chat", R.string.bottom_page_chat, Icons.Outlined.Forum) { BottomChatPage() }, ) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d7e976138..93030b637 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1885,7 +1885,7 @@ Waiting to start Notifications DroidDeck bottom screen - Show messages and other notifications here while you play. Android asks you once to allow notification access for DroidDeck. They stay on this screen only and are not saved. + Show messages and other notifications here while you play. They stay on this screen only and are not saved. Android asks once: its notification access page opens on this screen; turn DroidDeck on there and this page comes back by itself. Allow notification access No notifications. %1$d notifications @@ -1902,6 +1902,7 @@ Close chat Mic on Mic off + Mic is off for this game. To talk, turn on Microphone in DroidDeck\'s Steam settings (Audio) and start the game again. Volume %1$d%% Telemetry FPS