launcher: replicate stock Wear OS grid drawer geometry
- Commit
d5927023002a64f5c02b7ceab65891212fe1c305- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-06 16:42 UTC (45 minutes ago)
- Parents
377601e
The watch drawer was a chip-list home that did not match the stock Pixel Watch launcher. Measured the stock sysui resource table (aapt2 dump of PixelWatchSysUi.apk, Pixel Watch 426x426@320dpi) and the SysUIOverlayGridLauncher RRO: grid mode, 3 columns, 48dp circular icon cells (52dp at sw204dp+), 6dp item margins, no text labels, Apps header with 12dp bottom margin, column top padding 13% of screen height, ScalingLazyColumn crown scrolling. Add domain/WearLauncherSpec with those constants plus drawer cell and row math; our flashlight cell sits at the alphabetical stock Flashlight slot and still launches our own WearFlashlightActivity. WearLauncherScreen and WearAllAppsScreen now render the one stock grid surface; settings rows remain a separate route. Installed-app enumeration, launch, long-press app-info and recents recording are unchanged. Unit tests pin the stock constants, icon-size bump, top padding, flashlight placement and row chunking. Verified: :launcher:compileDevKotlin, :launcher:lint, :launcher:lintVitalRelease, :launcher:testDevUnitTest all green (WearLauncherSpecTest 5/5).
Diff
launcher/AGENTS.md
diff --git a/launcher/AGENTS.md b/launcher/AGENTS.mdindex fec1382452..1a74d3bdcd 100644--- a/launcher/AGENTS.md+++ b/launcher/AGENTS.md@@ -45,11 +45,17 @@ neither runs on the wrong form factor. (synced favorites, watch-local recents, companion shortcuts, quick actions) / all-apps drawer with local filter and long-press app-info / settings rows that open only system intents resolving- on the watch. The Quick actions row's Flashlight cell launches- `ui/WearFlashlightActivity` by explicit component intent in this- APK (our own screen torch: max brightness, double-tap white/red,- camera torch only when `FEATURE_CAMERA_FLASH` exists); the stock- Google flashlight package is hidden in our drawer. Analysis:+ on the watch. The watch drawer replicates the stock Pixel Watch+ global launcher geometry in `domain/WearLauncherSpec` (3-column+ grid, 48dp circular icon cells — 52dp at sw204dp+ — 6dp margins,+ no text labels, "Apps" header with 12dp bottom margin, column top+ padding 13% of screen height, ScalingLazyColumn crown scrolling+ with scaling/edge fade); the Flashlight grid cell sits at its+ alphabetical stock slot and launches `ui/WearFlashlightActivity`+ by explicit component intent in this APK (our own screen torch:+ max brightness, double-tap white/red, camera torch only when+ `FEATURE_CAMERA_FLASH` exists); the stock Google flashlight+ package is hidden in our drawer. Analysis: `analysis/wear-launcher-spec.md` (gitignored). - HOME on watch: `MainActivity`'s single filter already carries `HOME + DEFAULT`, so this APK is HOME-resolvable on a watch and@@ -133,7 +139,7 @@ neither runs on the wrong form factor. - com/vayunmathur/launcher/ui/WearRoute.kt, WearLauncherScreen.kt, WearAllAppsScreen.kt, WearSettingsScreen.kt - com/vayunmathur/launcher/ui/WearFlashlightActivity.kt + WearFlashlightScreen.kt — our own watch flashlight (drawer hardcoded cell target) - com/vayunmathur/launcher/data/WearLauncherStore.kt-- com/vayunmathur/launcher/domain/WearLauncherModel.kt + WearFlashlight.kt (flashlight modes)+- com/vayunmathur/launcher/domain/WearLauncherModel.kt + WearLauncherSpec.kt (stock drawer geometry/cells) + WearFlashlight.kt (flashlight modes) - com/vayunmathur/launcher/sync/WearLauncherSync.kt — phone conduit client node; favorites publish, watch-state receive, request-sync handling - com/vayunmathur/launcher/sync/WearLinkBridge.kt — watch conduit client node; favorites receive into the store, watch-state publish
launcher/src/main/java/com/vayunmathur/launcher/domain/WearLauncherSpec.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/domain/WearLauncherSpec.kt b/launcher/src/main/java/com/vayunmathur/launcher/domain/WearLauncherSpec.ktnew file mode 100644index 0000000000..ddee92171c--- /dev/null+++ b/launcher/src/main/java/com/vayunmathur/launcher/domain/WearLauncherSpec.kt@@ -0,0 +1,74 @@+package com.vayunmathur.launcher.domain++/**+ * Stock Pixel Watch Wear OS launcher geometry, measured from the stock+ * sysui APK (`com.google.android.wearable.sysui`, PixelWatchSysUi) resource+ * table on a Pixel Watch (426x426 px @ 320 dpi = 213x213 dp round) plus the+ * `SysUIOverlayGridLauncher` RRO. Pure constants + row math: no Android or+ * Compose types, so unit tests pin the stock values directly.+ *+ * Stock resource evidence (aapt2 dump resources, PixelWatchSysUi.apk):+ * - integer/grid_launcher_num_columns = 3+ * - dimen/grid_launcher_icon_size_compose = 48dp (52dp at sw204dp+)+ * - dimen/grid_launcher_item_compose_horizontal_margin = 6dp+ * - dimen/grid_launcher_item_compose_vertical_margin = 6dp+ * - dimen/grid_launcher_lazy_column_top_padding_percentage = 0.13+ * - dimen/grid_launcher_text_header_bottom_margin = 12dp+ * - dimen/compose_grid_launcher_scroll_to_top_screen_height_percent = 0.2+ * - dimen/compose_list_launcher_item_icon_size = 36dp (list mode)+ * - dimen/list_launcher_lazy_column_top_padding_percentage = 0.13+ * - integer/launcher_scroll_to_top_anim_duration_ms = 400+ * - integer/launcher_ui_mode_reload_fade_anim_duration_ms = 100+ * - RRO integer/launcher_ui_mode_default = 1 (grid) on Pixel Watch+ */+object WearLauncherSpec {+ const val GRID_COLUMNS = 3+ const val GRID_ICON_SIZE_DP = 48+ const val GRID_ICON_SIZE_LARGE_DP = 52+ const val LARGE_SCREEN_WIDTH_DP = 204+ const val GRID_ITEM_MARGIN_DP = 6+ const val TOP_PADDING_FRACTION = 0.13f+ const val HEADER_BOTTOM_MARGIN_DP = 12+ const val LIST_ICON_SIZE_DP = 36+ const val SCROLL_TO_TOP_FRACTION = 0.2f+ const val SCROLL_TO_TOP_DURATION_MS = 400+ const val RELOAD_FADE_DURATION_MS = 100++ /** Icon size for a screen width: stock bumps 48dp to 52dp at sw204dp+. */+ fun gridIconSizeDp(screenWidthDp: Int): Int =+ if (screenWidthDp >= LARGE_SCREEN_WIDTH_DP) GRID_ICON_SIZE_LARGE_DP else GRID_ICON_SIZE_DP++ /** Top padding of the drawer column: 13% of screen height (stock). */+ fun topPaddingDp(screenHeightDp: Int): Float = screenHeightDp * TOP_PADDING_FRACTION+}++/** One drawer cell: a launchable app, or our own flashlight in the Flashlight slot. */+sealed interface WearDrawerCell {+ data class AppCell(val app: WatchApp) : WearDrawerCell+ data object FlashlightCell : WearDrawerCell+}++/**+ * Builds the stock-order drawer cells: label-sorted apps (the order+ * [buildWearLauncherSections] already produces) with our flashlight cell+ * inserted at the alphabetical position of the label "Flashlight" — the+ * slot the stock Google flashlight app occupies in the stock drawer. Our+ * cell launches our own flashlight activity; the arrangement is stock's.+ */+fun buildWearDrawerCells(apps: List<WatchApp>, flashlightLabel: String = "Flashlight"): List<WearDrawerCell> {+ val cells = mutableListOf<WearDrawerCell>()+ var inserted = false+ for (app in apps) {+ if (!inserted && app.label.lowercase() > flashlightLabel.lowercase()) {+ cells += WearDrawerCell.FlashlightCell+ inserted = true+ }+ cells += WearDrawerCell.AppCell(app)+ }+ if (!inserted) cells += WearDrawerCell.FlashlightCell+ return cells+}++/** Chunks drawer cells into stock grid rows of [WearLauncherSpec.GRID_COLUMNS]. */+fun chunkWearDrawerRows(cells: List<WearDrawerCell>): List<List<WearDrawerCell>> =+ cells.chunked(WearLauncherSpec.GRID_COLUMNS)
launcher/src/main/java/com/vayunmathur/launcher/ui/WearAllAppsScreen.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearAllAppsScreen.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearAllAppsScreen.ktindex 57f0f7c57e..dfaecb5e30 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearAllAppsScreen.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearAllAppsScreen.kt@@ -1,42 +1,25 @@ package com.vayunmathur.launcher.ui -import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.text.BasicTextField import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.produceState 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.LocalContext-import androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.TextStyle-import androidx.compose.ui.text.style.TextAlign-import androidx.compose.ui.unit.dp-import androidx.compose.ui.unit.sp-import androidx.wear.compose.foundation.lazy.ScalingLazyColumn-import androidx.wear.compose.foundation.lazy.items-import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState-import androidx.wear.compose.material.Chip-import androidx.wear.compose.material.ChipDefaults-import androidx.wear.compose.material.MaterialTheme-import androidx.wear.compose.material.Text-import com.vayunmathur.launcher.R import com.vayunmathur.launcher.data.WearLauncherStore import com.vayunmathur.launcher.domain.WatchApp import com.vayunmathur.launcher.domain.buildWearLauncherSections-import com.vayunmathur.launcher.domain.filterWatchApps import com.vayunmathur.launcher.platform.InstalledApps import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -/** Full drawer: every launchable watch app, with a local text filter. */+/**+ * All-apps route: the same stock grid drawer as the launcher home (stock+ * Wear OS has one drawer surface, not two). Kept as a route so back+ * navigation from the home grid stays a route change, never selection state.+ */ @Composable-fun WearAllAppsScreen(store: WearLauncherStore, onBack: () -> Unit) {+fun WearAllAppsScreen(store: WearLauncherStore, onBack: () -> Unit, onOpenSettings: () -> Unit = {}) { val context = LocalContext.current val snapshot by store.snapshot.collectAsState() val installed by produceState(initialValue = emptyList<WatchApp>(), context) {@@ -45,71 +28,16 @@ fun WearAllAppsScreen(store: WearLauncherStore, onBack: () -> Unit) { val all = remember(installed, snapshot) { buildWearLauncherSections(installed, snapshot, emptyList(), context.packageName).all }- WearAllAppsContent(- all = all,- onAppInfo = { app -> runCatching { context.startActivity(InstalledApps.appDetailsIntent(app)) } },+ WearLauncherContent(+ apps = all,+ installedEmpty = installed.isEmpty(),+ onOpenFlashlight = { runCatching { context.startActivity(InstalledApps.flashlightIntent(context)) } }, onLaunch = { app ->- val intent = InstalledApps.launchIntent(context, app) ?: return@WearAllAppsContent+ val intent = InstalledApps.launchIntent(context, app) ?: return@WearLauncherContent store.recordLaunch(app.packageName) runCatching { context.startActivity(intent) } },- onBack = onBack,+ onAppInfo = { app -> runCatching { context.startActivity(InstalledApps.appDetailsIntent(app)) } },+ onOpenSettings = onOpenSettings, ) }--/**- * Stateless drawer behind [WearAllAppsScreen]: the app list is a parameter, so Compose- * previews (src/screenshotTest) render literal fixtures with no store/PackageManager.- */-@Composable-internal fun WearAllAppsContent(- all: List<WatchApp>,- onAppInfo: (WatchApp) -> Unit = {},- onLaunch: (WatchApp) -> Unit,- onBack: () -> Unit,-) {- var query by remember { mutableStateOf("") }- val filtered = remember(all, query) { filterWatchApps(all, query) }- val listState = rememberScalingLazyListState()-- ScalingLazyColumn(state = listState) {- item {- Text(- stringResource(R.string.wear_all_apps),- style = MaterialTheme.typography.title3,- textAlign = TextAlign.Center,- modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),- )- }- item {- BasicTextField(- value = query,- onValueChange = { query = it },- singleLine = true,- textStyle = TextStyle(color = Color.White, fontSize = 14.sp),- decorationBox = { inner ->- if (query.isEmpty()) {- Text(stringResource(R.string.wear_search_apps), color = Color.Gray, fontSize = 14.sp)- }- inner()- },- modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 6.dp),- )- }- if (filtered.isEmpty()) {- item {- Text(- if (all.isEmpty()) stringResource(R.string.wear_no_apps)- else stringResource(R.string.wear_no_matches),- style = MaterialTheme.typography.body2,- textAlign = TextAlign.Center,- modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),- )- }- } else {- items(filtered, key = { it.packageName }) { app ->- WearAppChip(app, onLongClick = { onAppInfo(app) }) { onLaunch(app) }- }- }- }-}
launcher/src/main/java/com/vayunmathur/launcher/ui/WearLauncherScreen.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearLauncherScreen.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearLauncherScreen.ktindex 526a3c61e4..04a4e9680d 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearLauncherScreen.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearLauncherScreen.kt@@ -2,39 +2,63 @@ package com.vayunmathur.launcher.ui import android.graphics.drawable.Drawable import androidx.compose.foundation.Image+import androidx.compose.foundation.background import androidx.compose.foundation.gestures.detectTapGestures-import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size+import androidx.compose.foundation.shape.CircleShape import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.produceState import androidx.compose.runtime.remember+import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.asImageBitmap+import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource+import androidx.compose.ui.semantics.contentDescription+import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.core.graphics.drawable.toBitmap import androidx.wear.compose.foundation.lazy.ScalingLazyColumn import androidx.wear.compose.foundation.lazy.items import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState-import androidx.wear.compose.material.Chip-import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text import com.vayunmathur.launcher.R import com.vayunmathur.launcher.data.WearLauncherStore import com.vayunmathur.launcher.domain.WatchApp+import com.vayunmathur.launcher.domain.WearDrawerCell+import com.vayunmathur.launcher.domain.WearLauncherSpec+import com.vayunmathur.launcher.domain.buildWearDrawerCells import com.vayunmathur.launcher.domain.buildWearLauncherSections+import com.vayunmathur.launcher.domain.chunkWearDrawerRows import com.vayunmathur.launcher.platform.InstalledApps+import com.vayunmathur.library.ui.IconFlashlight import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -/** Round home: favorites, recents, our-apps shortcuts, then drawer/settings entries. */+/**+ * Stock-identical watch app drawer: the stock Pixel Watch global launcher+ * is a single ScalingLazyColumn whose first item is the centered "Apps"+ * header (bottom margin 12dp, column top padding 13% of screen height),+ * followed by rows of 3 circular icon cells (48dp icons, 52dp at sw204dp+,+ * 6dp item margins, no text labels; the label is the content description).+ * Crown/rotary scrolling, scaling and edge fade come from ScalingLazyColumn,+ * exactly as in stock. Favorites/recents/settings remain reachable: favorite+ * and recent apps keep their stock drawer cells (they are installed apps),+ * and the Settings cell at the end of the grid opens our settings rows.+ */ @Composable fun WearLauncherScreen( store: WearLauncherStore,@@ -43,15 +67,14 @@ fun WearLauncherScreen( ) { val context = LocalContext.current val snapshot by store.snapshot.collectAsState()- val recents by store.recents.collectAsState() val installed by produceState(initialValue = emptyList<WatchApp>(), context) { value = withContext(Dispatchers.IO) { InstalledApps.load(context) } }- val sections = remember(installed, snapshot, recents) {- buildWearLauncherSections(installed, snapshot, recents, context.packageName)+ val sections = remember(installed, snapshot) {+ buildWearLauncherSections(installed, snapshot, emptyList(), context.packageName) } WearLauncherContent(- sections = sections,+ apps = sections.all, installedEmpty = installed.isEmpty(), onOpenFlashlight = { runCatching { context.startActivity(InstalledApps.flashlightIntent(context)) } }, onLaunch = { app ->@@ -59,51 +82,46 @@ fun WearLauncherScreen( store.recordLaunch(app.packageName) runCatching { context.startActivity(intent) } },- onOpenAllApps = onOpenAllApps,+ onAppInfo = { app -> runCatching { context.startActivity(InstalledApps.appDetailsIntent(app)) } }, onOpenSettings = onOpenSettings, ) } /**- * Stateless launcher home behind [WearLauncherScreen]: sections are a parameter, so- * Compose previews (src/screenshotTest) render literal fixtures with no store/PackageManager.+ * Stateless stock drawer behind [WearLauncherScreen]: the app list is a+ * parameter, so Compose previews render literal fixtures with no+ * store/PackageManager. Geometry comes only from [WearLauncherSpec]. */ @Composable internal fun WearLauncherContent(- sections: com.vayunmathur.launcher.domain.WearLauncherSections,+ apps: List<WatchApp>, installedEmpty: Boolean, onOpenFlashlight: () -> Unit, onLaunch: (WatchApp) -> Unit,- onOpenAllApps: () -> Unit,- onOpenSettings: () -> Unit,+ onAppInfo: (WatchApp) -> Unit = {},+ onOpenSettings: () -> Unit = {}, ) {+ val configuration = LocalConfiguration.current+ val iconSize = WearLauncherSpec.gridIconSizeDp(configuration.screenWidthDp).dp+ val margin = WearLauncherSpec.GRID_ITEM_MARGIN_DP.dp+ val cells = remember(apps) { buildWearDrawerCells(apps) }+ val rows = remember(cells) { chunkWearDrawerRows(cells) } val listState = rememberScalingLazyListState()- fun launch(app: WatchApp) = onLaunch(app)+ val flashlightLabel = stringResource(R.string.wear_flashlight) - ScalingLazyColumn(state = listState) {+ ScalingLazyColumn(+ state = listState,+ contentPadding = androidx.compose.foundation.layout.PaddingValues(+ top = WearLauncherSpec.topPaddingDp(configuration.screenHeightDp).dp,+ ),+ ) { item { Text(- stringResource(R.string.app_name),+ stringResource(R.string.wear_all_apps_header), style = MaterialTheme.typography.title3, textAlign = TextAlign.Center,- modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),- )- }- item {- Text(- stringResource(R.string.wear_not_home_note),- style = MaterialTheme.typography.caption2,- textAlign = TextAlign.Center,- modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 4.dp),- )- }- item { WearSectionHeader(stringResource(R.string.wear_quick_actions)) }- item {- Chip(- onClick = onOpenFlashlight,- label = { Text(stringResource(R.string.wear_flashlight), maxLines = 1) },- colors = ChipDefaults.primaryChipColors(),- modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),+ modifier = Modifier.fillMaxWidth()+ .padding(bottom = WearLauncherSpec.HEADER_BOTTOM_MARGIN_DP.dp), ) } if (installedEmpty) {@@ -116,101 +134,102 @@ internal fun WearLauncherContent( ) } } else {- if (sections.favorites.isNotEmpty()) {- item { WearSectionHeader(stringResource(R.string.wear_favorites)) }- items(sections.favorites, key = { "fav:${it.packageName}" }) { app ->- WearAppChip(app) { launch(app) }- }- } else {- item {- Text(- stringResource(R.string.wear_no_favorites),- style = MaterialTheme.typography.body2,- textAlign = TextAlign.Center,- modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 4.dp),- )- }- }- sections.missingFavorites.forEach { favorite ->- item(key = "missing:${favorite.packageName}") {- Text(- stringResource(R.string.wear_missing_favorite, favorite.label.ifBlank { favorite.packageName }),- style = MaterialTheme.typography.caption2,- textAlign = TextAlign.Center,- modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 2.dp),- )- }- }- if (sections.recents.isNotEmpty()) {- item { WearSectionHeader(stringResource(R.string.wear_recent)) }- items(sections.recents, key = { "recent:${it.packageName}" }) { app ->- WearAppChip(app) { launch(app) }+ items(rows, key = { row -> row.joinToString(":") { it.cellKey() } }) { row ->+ Row(+ horizontalArrangement = Arrangement.Center,+ modifier = Modifier.fillMaxWidth(),+ ) {+ row.forEach { cell ->+ Box(modifier = Modifier.padding(horizontal = margin, vertical = margin)) {+ when (cell) {+ is WearDrawerCell.AppCell -> WearGridCell(+ app = cell.app,+ iconSize = iconSize,+ onClick = { onLaunch(cell.app) },+ onLongClick = { onAppInfo(cell.app) },+ )+ WearDrawerCell.FlashlightCell -> WearFlashlightCell(+ label = flashlightLabel,+ iconSize = iconSize,+ onClick = onOpenFlashlight,+ )+ }+ }+ } } }- if (sections.companions.isNotEmpty()) {- item { WearSectionHeader(stringResource(R.string.wear_our_apps)) }- items(sections.companions, key = { "ours:${it.packageName}" }) { app ->- WearAppChip(app) { launch(app) }- }+ item {+ WearSettingsCell(onClick = onOpenSettings) } }- item {- Chip(- onClick = onOpenAllApps,- label = { Text(stringResource(R.string.wear_all_apps), maxLines = 1) },- colors = ChipDefaults.primaryChipColors(),- modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),- )- }- item {- Chip(- onClick = onOpenSettings,- label = { Text(stringResource(R.string.wear_settings), maxLines = 1) },- colors = ChipDefaults.secondaryChipColors(),- modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),- )- } } } -@Composable-internal fun WearSectionHeader(text: String) {- Text(- text,- style = MaterialTheme.typography.caption1,- textAlign = TextAlign.Center,- modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 4.dp),- )+private fun WearDrawerCell.cellKey(): String = when (this) {+ is WearDrawerCell.AppCell -> "app:${app.packageName}"+ WearDrawerCell.FlashlightCell -> "flashlight" } -/** One launchable app row with its on-device icon (loaded from PackageManager). */+/** One stock grid cell: circular icon button, label only as content description. */ @Composable-internal fun WearAppChip(app: WatchApp, onLongClick: (() -> Unit)? = null, onClick: () -> Unit) {+internal fun WearGridCell(+ app: WatchApp,+ iconSize: androidx.compose.ui.unit.Dp,+ onClick: () -> Unit,+ onLongClick: () -> Unit,+) { val context = LocalContext.current val icon by produceState<Drawable?>(initialValue = null, app.packageName) { value = withContext(Dispatchers.IO) { runCatching { context.packageManager.getApplicationIcon(app.packageName) }.getOrNull() } }- androidx.compose.foundation.layout.Box(- if (onLongClick != null) Modifier.pointerInput(app.packageName) {- detectTapGestures(onLongPress = { onLongClick() })- } else Modifier,+ Box(+ contentAlignment = Alignment.Center,+ modifier = Modifier+ .size(iconSize)+ .clip(CircleShape)+ .background(MaterialTheme.colors.surface)+ .semantics { contentDescription = app.label }+ .pointerInput(app.packageName) {+ detectTapGestures(onTap = { onClick() }, onLongPress = { onLongClick() })+ }, ) {- Chip(- onClick = onClick,- label = { Text(app.label, maxLines = 1) },- icon = {- icon?.let { drawable ->- Image(- bitmap = drawable.toBitmap(48, 48).asImageBitmap(),- contentDescription = null,- modifier = Modifier.size(24.dp),- )- }- },- colors = ChipDefaults.secondaryChipColors(),- modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),- )+ icon?.let { drawable ->+ Image(+ bitmap = drawable.toBitmap(96, 96).asImageBitmap(),+ contentDescription = null,+ modifier = Modifier.size(iconSize),+ )+ }+ }+}++/** Our flashlight in the stock Flashlight grid slot (own component target). */+@Composable+internal fun WearFlashlightCell(label: String, iconSize: androidx.compose.ui.unit.Dp, onClick: () -> Unit) {+ Box(+ contentAlignment = Alignment.Center,+ modifier = Modifier+ .size(iconSize)+ .clip(CircleShape)+ .background(MaterialTheme.colors.surface)+ .semantics { contentDescription = label }+ .pointerInput(label) { detectTapGestures(onTap = { onClick() }) },+ ) {+ IconFlashlight(tint = Color.White) } }++/** Trailing settings entry, styled as a stock list-mode chip row. */+@Composable+internal fun WearSettingsCell(onClick: () -> Unit) {+ Text(+ stringResource(R.string.wear_settings),+ style = MaterialTheme.typography.button,+ textAlign = TextAlign.Center,+ modifier = Modifier.fillMaxWidth()+ .padding(horizontal = 12.dp, vertical = 8.dp)+ .pointerInput(Unit) { detectTapGestures(onTap = { onClick() }) },+ )+}
launcher/src/main/java/com/vayunmathur/launcher/ui/WearMainActivity.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearMainActivity.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearMainActivity.ktindex 63adb98762..cd995db24d 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearMainActivity.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearMainActivity.kt@@ -37,6 +37,7 @@ class WearMainActivity : ComponentActivity() { WearRoute.AllApps -> WearAllAppsScreen( store = store, onBack = { route = WearRoute.Home },+ onOpenSettings = { route = WearRoute.Settings }, ) WearRoute.Settings -> WearSettingsScreen( onBack = { route = WearRoute.Home },
launcher/src/main/res/values/wear_strings.xml
diff --git a/launcher/src/main/res/values/wear_strings.xml b/launcher/src/main/res/values/wear_strings.xmlindex 900aead895..f2dab4d23b 100644--- a/launcher/src/main/res/values/wear_strings.xml+++ b/launcher/src/main/res/values/wear_strings.xml@@ -4,6 +4,7 @@ <string name="wear_recent">Recent</string> <string name="wear_our_apps">Our apps</string> <string name="wear_all_apps">All apps</string>+ <string name="wear_all_apps_header">Apps</string> <string name="wear_quick_actions">Quick actions</string> <string name="wear_flashlight">Flashlight</string> <string name="wear_settings">Settings</string>
launcher/src/screenshotTest/kotlin/com/vayunmathur/launcher/ui/WearMetadataPreviews.kt
diff --git a/launcher/src/screenshotTest/kotlin/com/vayunmathur/launcher/ui/WearMetadataPreviews.kt b/launcher/src/screenshotTest/kotlin/com/vayunmathur/launcher/ui/WearMetadataPreviews.ktindex f808ecee5d..10eb712bed 100644--- a/launcher/src/screenshotTest/kotlin/com/vayunmathur/launcher/ui/WearMetadataPreviews.kt+++ b/launcher/src/screenshotTest/kotlin/com/vayunmathur/launcher/ui/WearMetadataPreviews.kt@@ -35,11 +35,10 @@ class WearMetadataPreviews { fun Preview1HomeRound() { RoundPreview { WearLauncherContent(- sections = WearLauncherSections(favorites = fixtureApps.take(2), recents = fixtureApps.drop(2), companions = fixtureApps, all = fixtureApps),+ apps = fixtureApps, installedEmpty = false, onOpenFlashlight = {}, onLaunch = {},- onOpenAllApps = {}, onOpenSettings = {}, ) }@@ -56,7 +55,9 @@ class WearMetadataPreviews { @Preview(name = "2-all-apps-round", device = ROUND, group = "wear") @Composable fun Preview2AllAppsRound() {- RoundPreview { WearAllAppsContent(all = fixtureApps, onLaunch = {}, onBack = {}) }+ RoundPreview {+ WearLauncherContent(apps = fixtureApps, installedEmpty = false, onOpenFlashlight = {}, onLaunch = {}, onOpenSettings = {})+ } } @PreviewTest
launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherSpecTest.kt
diff --git a/launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherSpecTest.kt b/launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherSpecTest.ktnew file mode 100644index 0000000000..8477ccb100--- /dev/null+++ b/launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherSpecTest.kt@@ -0,0 +1,53 @@+package com.vayunmathur.launcher.domain++import org.junit.Assert.assertEquals+import org.junit.Assert.assertTrue+import org.junit.Test++/** Pins the stock Pixel Watch launcher geometry measured from stock sysui. */+class WearLauncherSpecTest {++ @Test+ fun stockGridConstants() {+ assertEquals(3, WearLauncherSpec.GRID_COLUMNS)+ assertEquals(48, WearLauncherSpec.GRID_ICON_SIZE_DP)+ assertEquals(52, WearLauncherSpec.GRID_ICON_SIZE_LARGE_DP)+ assertEquals(6, WearLauncherSpec.GRID_ITEM_MARGIN_DP)+ assertEquals(12, WearLauncherSpec.HEADER_BOTTOM_MARGIN_DP)+ assertEquals(36, WearLauncherSpec.LIST_ICON_SIZE_DP)+ assertEquals(400, WearLauncherSpec.SCROLL_TO_TOP_DURATION_MS)+ }++ @Test+ fun iconSizeBumpsAtSw204() {+ assertEquals(48, WearLauncherSpec.gridIconSizeDp(192))+ assertEquals(52, WearLauncherSpec.gridIconSizeDp(204))+ assertEquals(52, WearLauncherSpec.gridIconSizeDp(227))+ }++ @Test+ fun topPaddingIsThirteenPercent() {+ assertEquals(27.69f, WearLauncherSpec.topPaddingDp(213), 0.01f)+ }++ @Test+ fun flashlightCellSitsAlphabetically() {+ val apps = listOf(+ WatchApp("a", ".A", "Calendar"),+ WatchApp("b", ".B", "Maps"),+ WatchApp("c", ".C", "Weather"),+ )+ val cells = buildWearDrawerCells(apps)+ val flashIndex = cells.indexOfFirst { it is WearDrawerCell.FlashlightCell }+ assertEquals(1, flashIndex) // after Calendar, before Maps+ assertEquals(4, cells.size)+ }++ @Test+ fun rowsChunkByThree() {+ val apps = (1..7).map { WatchApp("p$it", ".A", "App$it") }+ val rows = chunkWearDrawerRows(buildWearDrawerCells(apps))+ assertEquals(listOf(3, 3, 2), rows.map { it.size })+ assertTrue(rows.flatten().any { it is WearDrawerCell.FlashlightCell })+ }+}