diff --git a/wear/app/src/main/kotlin/com/faceclaw/wear/Protocol.kt b/wear/app/src/main/kotlin/com/faceclaw/wear/Protocol.kt index 32916cb0..35c6dc3a 100644 --- a/wear/app/src/main/kotlin/com/faceclaw/wear/Protocol.kt +++ b/wear/app/src/main/kotlin/com/faceclaw/wear/Protocol.kt @@ -100,7 +100,8 @@ data class PhoneState( val listening: Boolean, /** Display mode wire value ("576x288" | "576x480" | "640x480"). */ val displayMode: String, - val battery: Int?, + // The state item also carries "battery"; the watch doesn't show it (the + // glasses' own top bar does), so it is left unparsed. val charging: Boolean, val foreground: AppEntry?, val windows: List, @@ -126,7 +127,6 @@ data class PhoneState( worn = if (o.isNull("worn")) null else o.optBoolean("worn"), listening = o.optBoolean("listening", false), displayMode = o.optString("displayMode", "576x288"), - battery = if (o.isNull("battery")) null else o.optInt("battery").takeIf { it >= 0 }, charging = o.optBoolean("charging", false), foreground = foreground?.let { AppEntry(it.optString("appId", ""), it.optString("title", "")) diff --git a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/Common.kt b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/Common.kt index 6fb65cd1..975f24f7 100644 --- a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/Common.kt +++ b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/Common.kt @@ -4,15 +4,9 @@ import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width -import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -52,58 +46,36 @@ fun NoticeOverlay(notice: Notice?) { } } -/** The pad's top line: how the glasses and phone are doing, in a few words. */ +/** The pad's single indicator line, with a tone that picks its colour. */ data class StatusLine(val text: String, val tone: StatusTone) enum class StatusTone { GOOD, BUSY, OFF, PROBLEM } -fun statusLine(state: PhoneState?, link: LinkStatus): StatusLine = when { +/** + * The pad's centre indicator: what the next gesture lands on when everything + * is connected (the foreground app, or the screen/lock state in the way of + * it), otherwise the connection problem to fix first. + */ +fun padLine(state: PhoneState?, link: LinkStatus): StatusLine = when { !link.phoneReachable -> StatusLine("No phone", StatusTone.PROBLEM) !link.phoneAppInstalled -> StatusLine("Install Faceclaw on phone", StatusTone.PROBLEM) link.appRunning == false -> StatusLine("Open Faceclaw on phone", StatusTone.PROBLEM) state == null -> StatusLine("Waiting for phone", StatusTone.BUSY) state.remoteEnabled == false -> StatusLine("Watch control off", StatusTone.PROBLEM) - state.connected -> { - val battery = state.battery?.let { " · $it%" + if (state.charging) "⚡" else "" } ?: "" - StatusLine("Connected$battery", StatusTone.GOOD) + state.connected -> when { + state.locked -> StatusLine("Locked", StatusTone.OFF) + !state.screenOn -> StatusLine("Screen off", StatusTone.OFF) + state.listening -> StatusLine("Listening…", StatusTone.BUSY) + else -> StatusLine(state.foreground?.title ?: "Launcher", StatusTone.GOOD) } state.phase == "connecting" -> StatusLine("Connecting…", StatusTone.BUSY) state.phase == "disconnecting" -> StatusLine("Disconnecting…", StatusTone.BUSY) else -> StatusLine("Glasses disconnected", StatusTone.OFF) } -/** The pad's centre line: what the input will land on. */ -fun focusLine(state: PhoneState?): String = when { - state == null || !state.connected -> "" - state.locked -> "Locked" - !state.screenOn -> "Display off" - state.listening -> "Listening…" - else -> state.foreground?.title ?: "Launcher" -} - fun StatusTone.color(): Color = when (this) { StatusTone.GOOD -> Color(0xFF7BD88F) StatusTone.BUSY -> Color(0xFFF2C14E) StatusTone.OFF -> Color(0xFF8A8A8A) StatusTone.PROBLEM -> Color(0xFFFF8A80) } - -/** Status dot + text, e.g. "● Connected · 100%". */ -@Composable -fun StatusRow(line: StatusLine, modifier: Modifier = Modifier) { - Row(modifier = modifier, verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center) { - Box( - modifier = Modifier - .size(7.dp) - .background(line.tone.color(), CircleShape), - ) - Spacer(modifier = Modifier.width(6.dp)) - Text( - text = line.text, - style = MaterialTheme.typography.caption2, - color = MaterialTheme.colors.onSurfaceVariant, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - ) - } -} diff --git a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/RemoteScreen.kt b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/RemoteScreen.kt index 3d5acc00..66a709e2 100644 --- a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/RemoteScreen.kt +++ b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/RemoteScreen.kt @@ -23,7 +23,6 @@ import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Color @@ -41,6 +40,8 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.wear.compose.foundation.ExperimentalWearFoundationApi +import androidx.wear.compose.foundation.rememberActiveFocusRequester import androidx.wear.compose.material.Button import androidx.wear.compose.material.ButtonDefaults import androidx.wear.compose.material.Icon @@ -82,6 +83,8 @@ enum class Arrow { UP, DOWN, LEFT, RIGHT } * select / go back, and two quick wrist twists go back. The small buttons at * the bottom reach the rest. */ +// rememberActiveFocusRequester (rotary focus) is still experimental in Wear Compose 1.4. +@OptIn(ExperimentalWearFoundationApi::class) @Composable fun RemoteScreen( link: PhoneLink, @@ -103,7 +106,19 @@ fun RemoteScreen( // Which d-pad arrow lights up for the swipe just sent. var litArrow by remember { mutableStateOf(null) } var litTick by remember { mutableStateOf(0L) } - val focusRequester = remember { FocusRequester() } + // Rotary (crown) events are only delivered to a focused node. + // rememberActiveFocusRequester requests focus through the hierarchical + // focus machinery; the resume observer below takes it back after every + // excursion that steals it (the keyboard activity, ambient, screen off). + val focusRequester = rememberActiveFocusRequester() + val lifecycleOwner = LocalLifecycleOwner.current + DisposableEffect(lifecycleOwner, focusRequester) { + val observer = LifecycleEventObserver { _, event -> + if (event == Lifecycle.Event.ON_RESUME) focusRequester.requestFocus() + } + lifecycleOwner.lifecycle.addObserver(observer) + onDispose { lifecycleOwner.lifecycle.removeObserver(observer) } + } var crownAccumulator by remember { mutableStateOf(0f) } // Pad height in px, for the tap zones; written by onSizeChanged, read by // the gesture callbacks (plain holder: the callbacks are remembered once). @@ -249,8 +264,6 @@ fun RemoteScreen( flashing = false } - LaunchedEffect(Unit) { focusRequester.requestFocus() } - // A refused or unanswered gesture gets a distinct buzz, so the wrist knows // without looking (the notice pill says why). LaunchedEffect(notice?.id) { @@ -295,24 +308,25 @@ fun RemoteScreen( } TimeText() - StatusRow( - statusLine(state, linkStatus), - modifier = Modifier.align(Alignment.TopCenter).padding(top = 28.dp, start = 36.dp, end = 36.dp), - ) ArrowGlyph("▲", litArrow == Arrow.UP, Modifier.align(Alignment.TopCenter).padding(top = ringCenterY - ringRadius + ARROW_INSET)) ArrowGlyph("▼", litArrow == Arrow.DOWN, Modifier.align(Alignment.TopCenter).padding(top = ringCenterY + ringRadius - ARROW_INSET - ARROW_SIZE)) ArrowGlyph("◀", litArrow == Arrow.LEFT, Modifier.align(Alignment.TopStart).padding(start = maxWidth / 2 - ringRadius + ARROW_INSET, top = ringCenterY - ARROW_SIZE / 2)) ArrowGlyph("▶", litArrow == Arrow.RIGHT, Modifier.align(Alignment.TopEnd).padding(end = maxWidth / 2 - ringRadius + ARROW_INSET, top = ringCenterY - ARROW_SIZE / 2)) - // What the next gesture lands on (the app on the glasses, or the - // state in the way of it) above the centre line; the tap legend - // below it, clear of the side arrows. - val focus = if (holding) "holding" else focusLine(state).ifEmpty { "—" } + // The single status indicator: what the next gesture lands on (the + // app on the glasses, or the screen/lock state in the way of it), + // or the connection problem to fix first. Above the centre line; + // the tap legend below it, clear of the side arrows. + val pad = padLine(state, linkStatus) Text( - text = focus, + text = if (holding) "holding" else pad.text, style = MaterialTheme.typography.title3, - color = if (holding) MaterialTheme.colors.primary else MaterialTheme.colors.onSurface, + color = when { + holding -> MaterialTheme.colors.primary + pad.tone == StatusTone.GOOD -> MaterialTheme.colors.onSurface + else -> pad.tone.color() + }, textAlign = TextAlign.Center, maxLines = 1, overflow = TextOverflow.Ellipsis, diff --git a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/StatusScreen.kt b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/StatusScreen.kt index 62144725..a95fa84d 100644 --- a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/StatusScreen.kt +++ b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/StatusScreen.kt @@ -42,9 +42,10 @@ fun StatusScreen(link: PhoneLink, haptics: Haptics, onOpenSettings: () -> Unit) ScalingLazyColumn(state = listState, modifier = Modifier.fillMaxSize()) { item { ListHeader { Text("Glasses") } } item { + // No battery figure here: the glasses' own top bar shows it. val phaseLabel = when { state == null -> "No status yet" - connected -> "Connected" + (state?.battery?.let { " · $it%" } ?: "") + if (state?.charging == true) " charging" else "" + connected -> "Connected" + if (state?.charging == true) " · charging" else "" state?.phase == "connecting" -> "Connecting…" state?.phase == "disconnecting" -> "Disconnecting…" else -> "Disconnected"