mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
Wear app UI refinements
<details>
<summary>Prompts Used</summary>
Thanks. Next up, let's make soem refinements to the watch app UI.
We'll remove the glasses-battery indicator from the watch UI (it's already on the glasses screen so not needed there).
We'll merge the connection status into the current-app display; rather than one line saying "Connected" and one line saying "Display off" or an app name like "Launcher", we'll merge these into one indicator (in the second line's position), which is "Screen off" or an app name if connected, or a connection status otherwise.
We'll make rotating the crown scroll/select in the same way that swiping up/down on the ring or glasses touchpad does. Apps that want to pay attention to the exact source and details of an input should be able to, but apps that don't pay attention should get sensible behavior by default. (There might already be some code attempting to do this, but currently in my testing the crown has no effect)
> All three refinements are in, and the wear app builds cleanly. Here's what changed:
>
> **Battery indicator removed.** The glasses-battery readout is gone from both places it appeared: the touchpad's status line and the Status screen's connection chip (which now says just "Connected", with "· charging" kept since that signals glasses-in-the-case rather than battery level). The watch-side `PhoneState.battery` field was dropped too since nothing reads it now — the phone still publishes it in the state item (documented in PROTOCOL.md), so nothing changes on the wire.
>
> **Merged status/current-app indicator.** The touchpad's separate top `StatusRow` ("● Connected · 78%") is removed, and `statusLine`/`focusLine` in Common.kt are merged into one `padLine()` used in the centre position: when connected it shows "Screen off", "Locked", "Listening…", or the foreground app name ("Launcher" when nothing's open); otherwise it shows the connection state ("No phone", "Open Faceclaw on phone", "Connecting…", "Glasses disconnected", …). The old status dot's color coding survives as the text color — app names render in the normal text color, problem/busy/off states in the red/amber/gray tones — so the at-a-glance signal isn't lost.
>
> **Crown scrolling.** The pipeline you suspected does exist and the phone side of it is already exactly what you described: crown steps arrive as `scroll-up`/`scroll-down` carrying `source: "watch"`, so apps that inspect the source can, and apps that just switch on the event type get the same behavior as a ring/touchpad swipe. I traced that path end-to-end and found no phone-side gap. The break is on the watch: rotary events are only delivered to a *focused* Compose node, and RemoteScreen requested focus once via `LaunchedEffect(Unit)` with a plain `FocusRequester` — fragile against the nav host and never re-run after anything steals focus (the keyboard activity round-trip, ambient mode, screen off/on). It now uses `rememberActiveFocusRequester()` (Google's documented rotary pattern, present in the bundled wear-compose 1.4.1, with the required `@OptIn(ExperimentalWearFoundationApi)`), plus a lifecycle observer that re-requests focus on every `ON_RESUME`. The accumulator/sensitivity logic is unchanged.
>
> One caveat on the crown: since I can't reproduce the failure off-hardware, this fix targets the most likely cause (focus never landing or being lost). Worth a quick on-device check — and if the crown *still* does nothing, the useful datapoint would be whether `adb logcat` on the phone shows `sys-event .../SCROLL_*` lines when you turn it, which would split watch-side from phone-side cleanly.
</details>
This commit is contained in:
1 parent
eef7aa2679
commit
dc1d4d30a9
4 files changed
+44
-57
No files matched your search
@@ -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<WindowEntry>,
|
||||
@@ -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", ""))
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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<Arrow?>(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,
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user