feat(ui): support portrait launcher layouts (#1606)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-26 09:14:35 -04:00
1 parent db56cff880
commit 78f95c5a0c
18 files changed
+427 -73

No files matched your search

+5 -5
View File
@@ -73,7 +73,7 @@
<activity
android:name=".FrontEndActivity"
android:exported="true"
android:screenOrientation="sensorLandscape"
android:screenOrientation="user"
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|density|keyboard|keyboardHidden|navigation">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@@ -125,7 +125,7 @@
android:excludeFromRecents="true"
android:noHistory="true"
android:taskAffinity="${applicationId}.home"
android:screenOrientation="sensorLandscape"
android:screenOrientation="user"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -146,14 +146,14 @@
<activity
android:name=".files.FileManagerActivity"
android:exported="false"
android:screenOrientation="sensorLandscape"
android:screenOrientation="user"
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|density"
android:theme="@style/AppTheme" />
<activity
android:name=".files.FilePickerActivity"
android:exported="false"
android:screenOrientation="sensorLandscape"
android:screenOrientation="user"
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|density"
android:theme="@style/AppTheme" />
@@ -185,7 +185,7 @@
<activity
android:name=".stores.StoreLoginActivity"
android:exported="false"
android:screenOrientation="sensorLandscape"
android:screenOrientation="user"
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|density"
android:theme="@style/AppTheme" />
@@ -168,6 +168,7 @@ class FrontEndActivity : ComponentActivity() {
private var picturePosition by mutableStateOf("center")
private var stretch16x9 by mutableStateOf(false)
private var orientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
private var launcherOrientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER)
private var launcherFullscreen by mutableStateOf(true)
private var downloadSource by mutableStateOf(DownloadSource.MODE_AUTO)
private var downloadMirror by mutableStateOf("")
@@ -775,7 +776,8 @@ class FrontEndActivity : ComponentActivity() {
steamGamesX64 = cachedX64
backActionsInverted = SessionPrefs.backActionsInverted(this)
orientation = SessionPrefs.orientation(this)
requestedOrientation = orientation
launcherOrientation = com.droiddeck.launcher.core.AppUiPrefs.orientation(this)
requestedOrientation = launcherOrientation
launcherFullscreen = SessionPrefs.launcherFullscreen(this)
downloadSource = DownloadSource.mode(this)
downloadMirror = DownloadSource.mirror(this)
@@ -844,6 +846,7 @@ class FrontEndActivity : ComponentActivity() {
phantomProcessStatus = phantomProcessStatus,
showPhantomGate = showPhantomGate,
orientation = orientation,
launcherOrientation = launcherOrientation,
launcherFullscreen = launcherFullscreen,
downloadSource = downloadSource,
downloadMirror = downloadMirror,
@@ -1026,6 +1029,10 @@ class FrontEndActivity : ComponentActivity() {
onOrientation = { value ->
SessionPrefs.setOrientation(this, value)
orientation = value
},
onLauncherOrientation = { value ->
com.droiddeck.launcher.core.AppUiPrefs.setOrientation(this, value)
launcherOrientation = value
requestedOrientation = value
},
onLauncherFullscreen = { on ->
@@ -1321,7 +1328,8 @@ class FrontEndActivity : ComponentActivity() {
override fun onResume() {
super.onResume()
orientation = SessionPrefs.orientation(this)
requestedOrientation = orientation
launcherOrientation = com.droiddeck.launcher.core.AppUiPrefs.orientation(this)
requestedOrientation = launcherOrientation
refreshWifiDiscovery()
com.droiddeck.launcher.stores.StoresState.refresh(this)
com.droiddeck.launcher.stores.StoresState.libraryListener = { refreshAddedGames(); refresh() }
@@ -13,7 +13,7 @@ class HomeActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestedOrientation = com.droiddeck.launcher.session.SessionPrefs.orientation(this)
requestedOrientation = com.droiddeck.launcher.core.AppUiPrefs.orientation(this)
routeHome()
}
@@ -1,11 +1,32 @@
package com.droiddeck.launcher.core
import android.content.Context
import android.content.pm.ActivityInfo
import com.droiddeck.launcher.R
object AppUiPrefs {
const val DEFAULT_SCALE = 100
val scales = listOf(75, 85, 100, 115, 125, 150)
val orientationOptions = listOf(
ActivityInfo.SCREEN_ORIENTATION_USER to R.string.setup_launcher_orientation_auto,
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT to R.string.setup_orientation_portrait,
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE to R.string.setup_orientation_auto,
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE to R.string.setup_orientation_landscape,
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE to R.string.setup_orientation_reverse,
)
fun orientation(context: Context): Int =
context.getSharedPreferences("app-ui", Context.MODE_PRIVATE)
.getInt("orientation", ActivityInfo.SCREEN_ORIENTATION_USER)
.takeIf { value -> orientationOptions.any { it.first == value } }
?: ActivityInfo.SCREEN_ORIENTATION_USER
fun setOrientation(context: Context, value: Int) {
require(orientationOptions.any { it.first == value })
context.getSharedPreferences("app-ui", Context.MODE_PRIVATE).edit().putInt("orientation", value).apply()
}
internal fun normalizeScale(percent: Int): Int = percent.takeIf { it in scales } ?: DEFAULT_SCALE
fun scale(context: Context): Int = normalizeScale(
@@ -21,7 +21,7 @@ class FileManagerActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestedOrientation = com.droiddeck.launcher.session.SessionPrefs.orientation(this)
requestedOrientation = com.droiddeck.launcher.core.AppUiPrefs.orientation(this)
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 1)
}
@@ -6,6 +6,8 @@ import android.widget.Toast
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.rememberScrollState
import android.content.res.Configuration
import androidx.compose.foundation.background
import androidx.compose.foundation.border
@@ -21,6 +23,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.grid.GridCells
@@ -668,6 +671,7 @@ fun FileManagerScreen(
)
}
val compactToolbar = LocalConfiguration.current.screenWidthDp < 600
Column(modifier = Modifier.fillMaxSize()) {
if (pickMode && !pickerTitle.isNullOrEmpty()) {
Text(
@@ -698,6 +702,7 @@ fun FileManagerScreen(
modifier = Modifier
.fillMaxWidth()
.background(MaterialTheme.colorScheme.surfaceContainer)
.then(if (compactToolbar) Modifier.horizontalScroll(rememberScrollState()) else Modifier)
.padding(horizontal = 8.dp, vertical = 6.dp),
) {
IconButton(onClick = { requestNavigation(FileManagerNavigation.UP) }, enabled = canGoUp && !cancellingNavigation, modifier = Modifier.focusGlide(CircleShape)) {
@@ -776,10 +781,10 @@ fun FileManagerScreen(
fontWeight = FontWeight.SemiBold,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f),
modifier = if (compactToolbar) Modifier.widthIn(max = 140.dp) else Modifier.weight(1f),
)
} else if (LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT) {
Spacer(Modifier.weight(1f))
if (!compactToolbar) Spacer(Modifier.weight(1f))
} else {
Text(
text = currentDir.name.ifBlank { currentDir.absolutePath },
@@ -788,7 +793,7 @@ fun FileManagerScreen(
fontWeight = FontWeight.SemiBold,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f),
modifier = if (compactToolbar) Modifier.widthIn(max = 140.dp) else Modifier.weight(1f),
)
}
@@ -928,13 +933,14 @@ fun FileManagerScreen(
modifier = Modifier
.fillMaxWidth()
.background(MaterialTheme.colorScheme.primary.copy(alpha = 0.12f))
.then(if (compactToolbar) Modifier.horizontalScroll(rememberScrollState()) else Modifier)
.padding(horizontal = 12.dp, vertical = 6.dp),
) {
Text(
stringResource(R.string.fm_selected_count, selectedPaths.size),
color = MaterialTheme.colorScheme.onBackground,
fontSize = 13.sp,
modifier = Modifier.weight(1f),
modifier = if (compactToolbar) Modifier.padding(end = 12.dp) else Modifier.weight(1f),
)
val allVisibleSelected = visibleEntries.isNotEmpty() && visibleEntries.all { it.absolutePath in selectedPaths }
val anyVisibleSelected = visibleEntries.any { it.absolutePath in selectedPaths }
@@ -25,7 +25,7 @@ class FilePickerActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestedOrientation = com.droiddeck.launcher.session.SessionPrefs.orientation(this)
requestedOrientation = com.droiddeck.launcher.core.AppUiPrefs.orientation(this)
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 1)
}
@@ -88,6 +88,7 @@ class StoreLoginActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestedOrientation = com.droiddeck.launcher.core.AppUiPrefs.orientation(this)
store = Store.byId(intent.getStringExtra(EXTRA_STORE))
clientUrl = intent.getStringExtra(EXTRA_CLIENT_URL)?.takeIf { store == Store.EPIC }
oauthState = savedInstanceState?.getString(KEY_STATE) ?: generateState()
@@ -36,6 +36,7 @@ class XboxLoginActivity : ComponentActivity() {
@SuppressLint("SetJavaScriptEnabled")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestedOrientation = com.droiddeck.launcher.core.AppUiPrefs.orientation(this)
host = LinearLayout(this).apply { orientation = LinearLayout.VERTICAL; setBackgroundColor(Color.BLACK) }
status = TextView(this).apply { setTextColor(Color.WHITE); text = "Preparing Microsoft sign-in…"; setPadding(24, 16, 24, 16) }
host.addView(status)
@@ -41,6 +41,9 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.relocation.BringIntoViewRequester
import androidx.compose.foundation.relocation.bringIntoViewRequester
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Apps
@@ -87,6 +90,40 @@ import com.droiddeck.launcher.core.PhantomProcessLimit
internal val AttentionAmber = Color(0xFFFFB547)
@Composable
internal fun BottomBar(
s: FrontEndState, selected: String,
onSelect: (String) -> Unit, onFocusSelect: (String) -> Unit, a: FrontEndActions, modifier: Modifier,
) {
val shown = Hops.railPreview ?: selected
val keys = navigationKeys(s)
val bounds = remember { androidx.compose.runtime.mutableStateMapOf<String, androidx.compose.ui.geometry.Rect>() }
val tint = androidx.compose.runtime.rememberUpdatedState(LocalPalette.current.signal)
var barAt by remember { mutableStateOf(androidx.compose.ui.geometry.Offset.Zero) }
Row(modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface), verticalAlignment = Alignment.CenterVertically) {
BoxWithConstraints(Modifier.weight(1f)) {
val itemWidth = (maxWidth / keys.size).coerceIn(56.dp, 88.dp)
Box(Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()).onGloballyPositioned { barAt = it.boundsInRoot().topLeft }) {
if (shown in keys) ChipGlide(keys.indexOf(shown), bounds[shown]?.translate(-barAt), tint, GlideAxis.Horizontal, corner = 14.dp, fill = 0.14f, outline = 0f)
Row(Modifier.selectableGroup().padding(vertical = 4.dp), horizontalArrangement = Arrangement.Center) {
NavigationItems(s, shown, compact = true, iconOnly = false, height = 56.dp, width = itemWidth,
place = { key -> Modifier.onGloballyPositioned { bounds[key] = it.boundsInRoot(); Hops.railBounds[key] = it.boundsInRoot() } },
onSelect = onSelect, onFocusSelect = onFocusSelect)
}
}
}
if (s.running != null) ResumeRailItem(s.running, compact = true, iconOnly = true, a.onResume)
}
}
private fun navigationKeys(s: FrontEndState) = buildList {
add("steam"); add("games")
if (s.gameStoresEnabled) add("stores")
add("desktop"); add("components")
if (s.isHomeApp) add("android-apps")
add("setup"); add("updates")
}
@Composable
internal fun SideRail(
s: FrontEndState, selected: String,
@@ -95,8 +132,6 @@ internal fun SideRail(
val colors = MaterialTheme.colorScheme
val compact = LocalConfiguration.current.screenHeightDp < 420
val iconOnly = isNarrowScreen()
val setupNeedsAttention = !s.ready || (s.available != null && s.available != s.installed) ||
PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = modifier.width(if (iconOnly) 64.dp else 92.dp).background(colors.surface).padding(vertical = if (compact) 8.dp else 12.dp),
@@ -105,14 +140,7 @@ internal fun SideRail(
BoxWithConstraints(Modifier.weight(1f).fillMaxWidth()) {
val fit = (maxHeight / count - 4.dp).coerceIn(44.dp, if (iconOnly) 48.dp else if (compact) 52.dp else 60.dp)
val shown = Hops.railPreview ?: selected
val keys = buildList {
add("steam"); add("games")
if (s.gameStoresEnabled) add("stores")
add("desktop")
add("components")
if (s.isHomeApp) add("android-apps")
add("setup"); add("updates")
}
val keys = navigationKeys(s)
val bounds = remember { androidx.compose.runtime.mutableStateMapOf<String, androidx.compose.ui.geometry.Rect>() }
val tint = androidx.compose.runtime.rememberUpdatedState(LocalPalette.current.signal)
var railAt by remember { mutableStateOf(androidx.compose.ui.geometry.Offset.Zero) }
@@ -129,14 +157,7 @@ internal fun SideRail(
Hops.railBounds[key] = it.boundsInRoot()
}
}
RailItem(stringResource(R.string.rail_steam), Icons.Outlined.SportsEsports, "steam", shown == "steam", compact, iconOnly, fit, place = place, onFocus = { onFocusSelect("steam") }) { onSelect("steam") }
RailItem(stringResource(R.string.rail_games), Icons.Outlined.VideoLibrary, "games", shown == "games", compact, iconOnly, fit, place = place, onFocus = { onFocusSelect("games") }) { onSelect("games") }
if (s.gameStoresEnabled) RailItem(stringResource(R.string.rail_stores), Icons.Outlined.LocalMall, "stores", shown == "stores", compact, iconOnly, fit, count = s.storeDownloadsActive, place = place, onFocus = { onFocusSelect("stores") }) { onSelect("stores") }
RailItem(stringResource(R.string.rail_desktop), Icons.Outlined.DesktopWindows, "desktop", shown == "desktop", compact, iconOnly, fit, place = place, onFocus = { onFocusSelect("desktop") }) { onSelect("desktop") }
RailItem(stringResource(R.string.rail_components), Icons.Outlined.Layers, "components", shown == "components", compact, iconOnly, fit, place = place, onFocus = { onFocusSelect("components") }) { onSelect("components") }
if (s.isHomeApp) RailItem(stringResource(R.string.rail_apps), Icons.Outlined.Apps, "android-apps", shown == "android-apps", compact, iconOnly, fit, place = place, onFocus = { onFocusSelect("android-apps") }) { onSelect("android-apps") }
RailItem(stringResource(R.string.rail_setup), Icons.Outlined.Tune, "setup", shown == "setup", compact, iconOnly, fit, badge = setupNeedsAttention, place = place, onFocus = { onFocusSelect("setup") }) { onSelect("setup") }
RailItem(stringResource(R.string.rail_updates), Icons.Outlined.SystemUpdate, "updates", shown == "updates", compact, iconOnly, fit, badge = s.updates.hasUpdate, place = place, onFocus = { onFocusSelect("updates") }) { onSelect("updates") }
NavigationItems(s, shown, compact, iconOnly, fit, if (iconOnly) 52.dp else 80.dp, place, onSelect, onFocusSelect)
}
}
}
@@ -151,8 +172,36 @@ internal fun SideRail(
}
@Composable
private fun NavigationItems(
s: FrontEndState, shown: String, compact: Boolean, iconOnly: Boolean, height: Dp, width: Dp,
place: (String) -> Modifier, onSelect: (String) -> Unit, onFocusSelect: (String) -> Unit,
) {
val setupNeedsAttention = !s.ready || (s.available != null && s.available != s.installed) ||
PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)
for (key in navigationKeys(s)) {
val (label, icon) = when (key) {
"steam" -> R.string.rail_steam to Icons.Outlined.SportsEsports
"games" -> R.string.rail_games to Icons.Outlined.VideoLibrary
"stores" -> R.string.rail_stores to Icons.Outlined.LocalMall
"desktop" -> R.string.rail_desktop to Icons.Outlined.DesktopWindows
"components" -> R.string.rail_components to Icons.Outlined.Layers
"android-apps" -> R.string.rail_apps to Icons.Outlined.Apps
"setup" -> R.string.rail_setup to Icons.Outlined.Tune
else -> R.string.rail_updates to Icons.Outlined.SystemUpdate
}
key(key) {
RailItem(stringResource(label), icon, key, shown == key, compact, iconOnly, height, width,
badge = (key == "setup" && setupNeedsAttention) || (key == "updates" && s.updates.hasUpdate),
count = if (key == "stores") s.storeDownloadsActive else 0,
place = place, onFocus = { onFocusSelect(key) }) { onSelect(key) }
}
}
}
@Composable
@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)
private fun RailItem(
label: String, icon: ImageVector, key: String, current: Boolean, compact: Boolean, iconOnly: Boolean, height: Dp,
label: String, icon: ImageVector, key: String, current: Boolean, compact: Boolean, iconOnly: Boolean, height: Dp, width: Dp,
badge: Boolean = false,
count: Int = 0,
place: (String) -> Modifier = { Modifier },
@@ -181,6 +230,8 @@ private fun RailItem(
Motion.tw(220), label = "railFill",
)
val scale by animateFloatAsState(if (pressed) 0.95f else 1f, Motion.sp(0.5f, Spring.StiffnessMedium), label = "railScale")
val bringIntoView = remember { BringIntoViewRequester() }
LaunchedEffect(current) { if (current) bringIntoView.bringIntoView() }
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
@@ -189,7 +240,8 @@ private fun RailItem(
.then(place(key))
.landingPop(Hops.railLanded[key] ?: 0)
.graphicsLayer { scaleX = scale; scaleY = scale }
.size(width = if (iconOnly) 52.dp else 80.dp, height = height)
.size(width = width, height = height)
.bringIntoViewRequester(bringIntoView)
.clip(Shape14)
.background(fill)
.glideBorder(focused, Shape14, pal.signal)
@@ -11,6 +11,7 @@ import androidx.compose.foundation.focusGroup
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.focus.onFocusChanged
import android.provider.Settings
import android.view.Display
@@ -138,6 +139,7 @@ class FrontEndState(
val phantomProcessStatus: PhantomProcessStatus = PhantomProcessStatus.NOT_APPLICABLE,
val showPhantomGate: Boolean = false,
val orientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
val launcherOrientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER,
val launcherFullscreen: Boolean = true,
val downloadSource: String = DownloadSource.MODE_AUTO,
val downloadMirror: String = "",
@@ -219,6 +221,7 @@ class FrontEndActions(
val onAppScale: (Int) -> Unit = {},
val onLauncherIcon: (String) -> Unit = {},
val onOrientation: (Int) -> Unit = {},
val onLauncherOrientation: (Int) -> Unit = {},
val onLauncherFullscreen: (Boolean) -> Unit = {},
val onAnimationsEnabled: (Boolean) -> Unit = {},
val onDownloadSource: (String) -> Unit = {},
@@ -386,7 +389,12 @@ internal suspend fun focusSoon(target: () -> FocusRequester) {
@Composable
fun FrontEndScreen(s: FrontEndState, a: FrontEndActions, page: (@Composable () -> Unit)? = null) {
val frontFocus = remember { FrontFocus() }
CompositionLocalProvider(LocalFrontFocus provides frontFocus) { FrontEndScreenBody(s, a, page, frontFocus) }
androidx.compose.foundation.layout.BoxWithConstraints(Modifier.fillMaxSize()) {
CompositionLocalProvider(
LocalFrontFocus provides frontFocus,
LocalNarrowPane provides (maxWidth < NarrowPaneWidth),
) { FrontEndScreenBody(s, a, page, frontFocus) }
}
}
@OptIn(ExperimentalComposeUiApi::class)
@@ -486,11 +494,12 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
val window = LocalWindowInfo.current
val androidContext = androidx.compose.ui.platform.LocalContext.current
var anyFocused by remember { mutableStateOf(false) }
Box(
androidx.compose.foundation.layout.BoxWithConstraints(
modifier = Modifier.fillMaxSize().background(colors.background)
.windowInsetsPadding(if (s.launcherFullscreen) WindowInsets.displayCutout else WindowInsets.systemBars)
.onFocusChanged { anyFocused = it.hasFocus },
) {
val bottomNavigation = maxHeight > maxWidth
LaunchedEffect(processSettingsPageVisible) {
if (processSettingsPageVisible) return@LaunchedEffect
snapshotFlow { window.isWindowFocused }.first { it }
@@ -527,10 +536,19 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
focusWithinFrames({ frontFocus.focusedRail == null && anyFocused }) { frontFocus.paneEntry() }
}
val paneFocus = Modifier
.focusProperties { enter = { frontFocus.paneEntry() } }
.focusProperties {
enter = { frontFocus.paneEntry() }
exit = { direction ->
if (bottomNavigation && direction == FocusDirection.Down) frontFocus.railFor(railSelection)
else FocusRequester.Default
}
}
.focusGroup()
val railFocus = Modifier
.focusProperties { enter = { frontFocus.railFor(railSelection) } }
.focusProperties {
enter = { frontFocus.railFor(railSelection) }
if (bottomNavigation) up = frontFocus.paneEntry()
}
.focusGroup()
LaunchedEffect(Hops.restore) {
val r = Hops.restore ?: return@LaunchedEffect
@@ -544,12 +562,16 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
}
var screenAt by remember { mutableStateOf(Offset.Zero) }
CompositionLocalProvider(LocalShowSection provides { key -> selected = key }) {
Row(modifier = Modifier.fillMaxSize().onGloballyPositioned { screenAt = it.positionInRoot() }) {
SideRail(s, railSelection, onRailSelect, onRailFocus, a, railFocus.fillMaxHeight())
Box(Modifier.width(1.dp).fillMaxHeight().background(pal.line))
Column(modifier = Modifier.weight(1f).fillMaxHeight()) {
LauncherLayout(
bottomNavigation, pal.line,
Modifier.fillMaxSize().onGloballyPositioned { screenAt = it.positionInRoot() },
navigation = {
if (bottomNavigation) BottomBar(s, railSelection, onRailSelect, onRailFocus, a, railFocus)
else SideRail(s, railSelection, onRailSelect, onRailFocus, a, railFocus.fillMaxHeight())
},
) {
Pane(
s, selected, a, page, Modifier.weight(1f).fillMaxWidth().then(paneFocus), { selected = it },
s, selected, a, page, Modifier.fillMaxSize().then(paneFocus), { selected = it },
onAndroidAppClick = { app ->
if (s.secondScreenDisplays.isEmpty()) a.onAndroidApp(app, null)
else appToChooseDisplay = app
@@ -557,7 +579,6 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
onOpenDeveloperOptions = requestDeveloperOptions,
onRequestWirelessAdb = requestWirelessAdbFix,
)
}
}
}
@@ -398,7 +398,12 @@ internal fun SetupPanel(
ActionRow(stringResource(R.string.setup_default_home), s.defaultHomeLabel ?: stringResource(R.string.setup_choose_home), stringResource(R.string.setup_choose), a.onHomeApp)
}
ChoiceRow(
host, "orientation", stringResource(R.string.setup_orientation), null,
host, "launcher-orientation", stringResource(R.string.setup_launcher_orientation), null,
com.droiddeck.launcher.core.AppUiPrefs.orientationOptions.map { (value, label) -> value to stringResource(label) },
s.launcherOrientation, onPick = a.onLauncherOrientation,
)
ChoiceRow(
host, "orientation", stringResource(R.string.setup_session_orientation), stringResource(R.string.setup_session_orientation_hint),
SessionPrefs.orientationOptions.map { (value, label) -> value to stringResource(label) },
s.orientation, onPick = a.onOrientation,
)
@@ -2,6 +2,12 @@ package com.droiddeck.launcher.ui
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.unit.dp
@@ -13,3 +19,38 @@ val LocalNarrowPane = compositionLocalOf { false }
@Composable
internal fun isNarrowScreen(): Boolean = LocalConfiguration.current.screenWidthDp < 600
@Composable
internal fun LauncherLayout(
bottomNavigation: Boolean, divider: Color, modifier: Modifier = Modifier,
navigation: @Composable () -> Unit, content: @Composable () -> Unit,
) {
Layout(modifier = modifier, content = {
Box { content() }
Box(Modifier.background(divider))
Box { navigation() }
}) { children, constraints ->
val width = constraints.maxWidth
val height = constraints.maxHeight
val line = 1.dp.roundToPx()
val nav = children[2].measure(Constraints(
minWidth = if (bottomNavigation) width else 0, maxWidth = width,
minHeight = if (bottomNavigation) 0 else height, maxHeight = height,
))
val contentWidth = if (bottomNavigation) width else (width - nav.width - line).coerceAtLeast(0)
val contentHeight = if (bottomNavigation) (height - nav.height - line).coerceAtLeast(0) else height
val pane = children[0].measure(Constraints.fixed(contentWidth, contentHeight))
val edge = children[1].measure(Constraints.fixed(if (bottomNavigation) width else line, if (bottomNavigation) line else height))
layout(width, height) {
if (bottomNavigation) {
pane.placeRelative(0, 0)
edge.placeRelative(0, contentHeight)
nav.placeRelative(0, contentHeight + line)
} else {
nav.placeRelative(0, 0)
edge.placeRelative(nav.width, 0)
pane.placeRelative(nav.width + line, 0)
}
}
}
}
@@ -128,7 +128,7 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier)
},
onOpen = a.onSteamSettings, onPrimary = a.onPlay,
modifier = modifier.clipToBounds(),
start = if (narrow) 20.dp else 44.dp, bottom = if (narrow) 20.dp else 44.dp,
start = if (narrow) 20.dp else 44.dp, bottom = 44.dp,
background = {
when {
games.isEmpty() -> EmptyLibrary(
@@ -141,12 +141,20 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier)
},
scrim = { if (games.size >= WALL_MIN_GAMES) WallFade() },
words = {
Row(
val runtimeStatus: @Composable () -> Unit = {
if (s.busy || !s.ready || (s.available != null && s.available != s.installed)) RuntimeChip(s)
}
if (narrow) Column(
verticalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.onPlaced { words = it.boundsInParent() },
) {
Wordmark(30.dp)
runtimeStatus()
} else Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp),
modifier = Modifier.onPlaced { words = it.boundsInParent() },
) {
Wordmark(if (narrow) 30.dp else 40.dp)
if (s.busy || !s.ready || (s.available != null && s.available != s.installed)) RuntimeChip(s)
runtimeStatus()
}
},
button = { click ->
@@ -1065,36 +1065,61 @@ internal fun ModeHeader(
if (query.isNotEmpty()) onQuery("")
}
BackHandler(enabled = searching && !clearSearchFocus) { close() }
Column(Modifier.fillMaxWidth()) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp), modifier = Modifier.fillMaxWidth().heightIn(min = 52.dp).padding(vertical = 4.dp)) {
if (lead != null) lead()
else Text(
title, fontSize = 15.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1,
modifier = Modifier.padding(start = 4.dp, end = 4.dp),
)
BoxWithConstraints(Modifier.weight(1f), contentAlignment = Alignment.CenterStart) {
if (searching || open > 0.01f) {
val closable = maxWidth >= 80.dp
val w = androidx.compose.ui.unit.lerp(44.dp, (maxWidth - if (closable) 36.dp else 0.dp).coerceIn(44.dp, 520.dp), open)
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(4.dp)) {
Box(Modifier.width(w).graphicsLayer { alpha = (open * 1.6f).coerceAtMost(1f) }) {
AdbTextField(
value = query, onValueChange = onQuery, label = "", keyboardType = KeyboardType.Text, imeAction = ImeAction.Search,
placeholder = placeholder, compact = true, focusOnShow = focusOnOpen,
clearFocus = clearSearchFocus || !searching,
onFocusChange = { focused -> if (!focused && query.isEmpty()) { searching = false; focusOnOpen = false } },
)
}
if (searching && closable) SmallIconButton(Icons.Filled.Close, stringResource(R.string.common_close), tint = colors.onSurfaceVariant, onClick = close)
}
} else SearchIcon(stringResource(R.string.stores_search_open)) { searching = true; focusOnOpen = true }
val heading: @Composable () -> Unit = {
if (lead != null) lead()
else Text(
title, fontSize = 15.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1,
modifier = Modifier.padding(start = 4.dp, end = 4.dp),
)
}
val searchField: @Composable (Modifier) -> Unit = { modifier ->
BoxWithConstraints(modifier, contentAlignment = Alignment.CenterStart) {
val closable = maxWidth >= 80.dp
val w = androidx.compose.ui.unit.lerp(44.dp, (maxWidth - if (closable) 36.dp else 0.dp).coerceIn(44.dp, 520.dp), open)
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(4.dp)) {
Box(Modifier.width(w).graphicsLayer { alpha = (open * 1.6f).coerceAtMost(1f) }) {
AdbTextField(
value = query, onValueChange = onQuery, label = "", keyboardType = KeyboardType.Text, imeAction = ImeAction.Search,
placeholder = placeholder, compact = true, focusOnShow = focusOnOpen,
clearFocus = clearSearchFocus || !searching,
onFocusChange = { focused -> if (!focused && query.isEmpty()) { searching = false; focusOnOpen = false } },
)
}
if (searching && closable) SmallIconButton(Icons.Filled.Close, stringResource(R.string.common_close), tint = colors.onSurfaceVariant, onClick = close)
}
trailing()
}
Box(Modifier.fillMaxWidth().height(1.dp).background(pal.line))
}
val searchButton: @Composable () -> Unit = {
SearchIcon(stringResource(R.string.stores_search_open)) { searching = true; focusOnOpen = true }
}
BoxWithConstraints(Modifier.fillMaxWidth()) {
val stacked = maxWidth < NarrowPaneWidth
Column(Modifier.fillMaxWidth()) {
if (stacked) {
Box(Modifier.padding(vertical = 4.dp)) { heading() }
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp),
modifier = Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()).heightIn(min = 52.dp).padding(vertical = 4.dp),
) {
searchButton()
trailing()
}
if (searching || open > 0.01f) searchField(Modifier.fillMaxWidth().padding(bottom = 6.dp))
} else Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp),
modifier = Modifier.fillMaxWidth().heightIn(min = 52.dp).padding(vertical = 4.dp),
) {
heading()
if (searching || open > 0.01f) searchField(Modifier.weight(1f))
else Box(Modifier.weight(1f)) { searchButton() }
trailing()
}
Box(Modifier.fillMaxWidth().height(1.dp).background(pal.line))
}
}
}
internal fun storePalette(base: Palette, store: Store?): Palette {
val (accent, deep) = when (store) {
Store.GOG -> Color(0xFFC25BC8) to Color(0xFF9A3FA1)
+5
View File
@@ -829,6 +829,11 @@
<string name="setup_home_on">DroidDeck can be the Home app</string>
<string name="setup_home_off">DroidDeck is never offered as a Home app</string>
<string name="setup_orientation">Orientation</string>
<string name="setup_launcher_orientation">Launcher orientation</string>
<string name="setup_launcher_orientation_auto">Follow device rotation</string>
<string name="setup_orientation_portrait">Portrait</string>
<string name="setup_session_orientation">Game and desktop orientation</string>
<string name="setup_session_orientation_hint">Applies to Steam, games, desktop, and the controller editor.</string>
<string name="setup_orientation_auto">Automatic landscape</string>
<string name="setup_orientation_landscape">Landscape</string>
<string name="setup_orientation_reverse">Reverse landscape</string>
@@ -2,6 +2,7 @@ package com.droiddeck.launcher.session
import android.content.Context
import android.content.pm.ActivityInfo
import com.droiddeck.launcher.core.AppUiPrefs
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
@@ -17,6 +18,7 @@ class OrientationTest {
@Before fun clearOrientation() {
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
context.getSharedPreferences("app-ui", Context.MODE_PRIVATE).edit().clear().commit()
}
@Test fun landscapeChoicesPersistGloballyAndCanRestoreAutomaticRotation() {
@@ -41,4 +43,25 @@ class OrientationTest {
}
assertEquals(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE, SessionPrefs.orientation(context))
}
@Test fun launcherFollowsDeviceRotationAndPortraitDoesNotChangeSessions() {
assertEquals(ActivityInfo.SCREEN_ORIENTATION_USER, AppUiPrefs.orientation(context))
for ((value, _) in AppUiPrefs.orientationOptions) {
AppUiPrefs.setOrientation(context, value)
assertEquals(value, AppUiPrefs.orientation(context))
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
}
AppUiPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, AppUiPrefs.orientation(context))
}
@Test fun invalidLauncherOrientationFallsBackAndInvalidChoicePreservesPreference() {
context.getSharedPreferences("app-ui", Context.MODE_PRIVATE).edit().putInt("orientation", 999).commit()
assertEquals(ActivityInfo.SCREEN_ORIENTATION_USER, AppUiPrefs.orientation(context))
AppUiPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
assertThrows(IllegalArgumentException::class.java) { AppUiPrefs.setOrientation(context, 999) }
assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, AppUiPrefs.orientation(context))
}
}
@@ -0,0 +1,137 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.*
import androidx.compose.ui.unit.dp
import org.junit.Assert.*
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], qualifiers = "w960dp-h900dp-mdpi")
class PortraitLayoutTest {
@get:Rule val compose = createRobolectricComposeRule()
@Before fun freezeAnimations() {
compose.mainClock.autoAdvance = false
Hops.railPreview = null
}
@Test fun navigationSitsAtBottomAndRotatingPreservesContentState() {
val portrait = mutableStateOf(true)
compose.setContent {
DroidDeckTheme {
LauncherLayout(portrait.value, Color.Gray,
Modifier.size(if (portrait.value) 480.dp else 800.dp, if (portrait.value) 800.dp else 480.dp).testTag("launcher"),
navigation = {
if (portrait.value) BottomBar(state, "steam", {}, {}, actions, Modifier)
else SideRail(state, "steam", {}, {}, actions, Modifier.fillMaxHeight())
},
) {
var count by remember { mutableIntStateOf(0) }
Box(Modifier.fillMaxSize().testTag("pane")) {
TextButton(onClick = { count++ }) { Text("Count $count") }
}
}
}
}
compose.mainClock.advanceTimeBy(1_000)
val root = compose.onNodeWithTag("launcher").getUnclippedBoundsInRoot()
val pane = compose.onNodeWithTag("pane").getUnclippedBoundsInRoot()
val steam = compose.onNodeWithTag("rail-steam").getUnclippedBoundsInRoot()
assertEquals(root.left, pane.left)
assertEquals(root.right, pane.right)
assertTrue(steam.top >= pane.bottom)
assertEquals(root.bottom - 4.dp, steam.bottom)
compose.onNodeWithText("Count 0").performClick()
compose.runOnIdle { portrait.value = false }
compose.mainClock.advanceTimeBy(1_000)
compose.onNodeWithText("Count 1").assertExists()
val landscapePane = compose.onNodeWithTag("pane").getUnclippedBoundsInRoot()
val rail = compose.onNodeWithTag("rail-steam").getUnclippedBoundsInRoot()
assertTrue(landscapePane.left > rail.right)
assertEquals(0.dp, landscapePane.top)
compose.runOnIdle { portrait.value = true }
compose.mainClock.advanceTimeBy(1_000)
compose.onNodeWithText("Count 1").assertExists()
}
@Test fun narrowBottomBarScrollsToEveryDestinationWithAppsAndResumeVisible() {
val selected = mutableStateOf("steam")
compose.setContent {
DroidDeckTheme {
BottomBar(stateWithAppsAndSession, selected.value, { selected.value = it }, {}, actions, Modifier.size(320.dp, 64.dp))
}
}
compose.mainClock.advanceTimeBy(1_000)
for (key in listOf("games", "stores", "desktop", "components", "android-apps", "setup", "updates", "steam")) {
compose.onNodeWithTag("rail-$key").performScrollTo()
compose.mainClock.advanceTimeBy(1_000)
compose.onNodeWithTag("rail-$key").assertIsDisplayed().performClick()
compose.mainClock.advanceTimeBy(1_000)
compose.runOnIdle { assertEquals(key, selected.value); assertNull(Hops.railPreview) }
compose.onNodeWithTag("rail-$key").assertIsSelected().assertHeightIsAtLeast(48.dp).assertWidthIsAtLeast(48.dp)
}
compose.onNodeWithContentDescription("Resume Steam").assertIsDisplayed()
}
@Test fun compactHeaderKeepsAllActionsReachable() {
compose.setContent {
DroidDeckTheme {
CompositionLocalProvider(LocalNarrowPane provides true) {
Box(Modifier.size(320.dp, 240.dp)) {
ModeHeader("Library", "", {}, "Search library") {
for (label in listOf("Filter", "Sort", "View", "Frontend files", "Add game")) {
SecondaryButton(label) {}
}
}
}
}
}
}
compose.mainClock.advanceTimeBy(1_000)
compose.onNodeWithText("Add game").performScrollTo()
compose.mainClock.advanceTimeBy(1_000)
compose.onNodeWithText("Add game").assertIsDisplayed()
compose.onNodeWithText("Filter").performScrollTo()
compose.mainClock.advanceTimeBy(1_000)
compose.onNodeWithText("Filter").assertIsDisplayed()
}
private fun state(home: Boolean = false, running: String? = null) = FrontEndState(
installed = "r9", ready = true, available = null, busy = false, stage = "", percent = -1,
desktopInstalled = true, offlineAccount = null, offline = false, frameGenLabel = "",
romsDir = null, logsEnabled = false, steamGames = emptyList(), emulators = emptyList(), running = running,
isHomeApp = home,
)
private val state get() = state()
private val stateWithAppsAndSession get() = state(home = true, running = "Steam")
private val actions = FrontEndActions(
onPlay = {}, onPlayDesktopUi = {}, onSteamGame = {}, onDesktop = {}, onEmulator = {},
onRom = {}, onResume = {}, onSteamSettings = {}, onDesktopSettings = {},
onInstallPackage = {}, onRemovePackage = {}, onRuntime = {}, onFrameGenPick = {},
onImportLossless = {}, onProtons = {}, onComponents = {}, onPerformance = {},
onRoms = {}, onFiles = {}, onLogs = {}, onOffline = {},
onWirelessAdbPair = { _, _, _, _ -> }, onWirelessAdbApply = { _, _, _, _ -> },
onSetPhantomProcessLimit = { _, _ -> },
)
}