Wear watchface design

Makes the button-row appear and disappear with a slide-in/out gesture.
Rearranges the other UI elements for a more watchface-like view.

<details>
<summary>Prompts used</summary>

In faceclaw/wear, we have an Android Wear watch app which can be used as a glasses controller. Currently, its UI is a bit chaotic: we have a bottom row of buttons, the time, a foreground-window title, some help text, and a ring of indicators. The core interaction is tapping, double tapping, long tapping, and swiping (which have the same effect as on the R1 ring), which aren't location sensitive except that they can't hit the row of buttons. There is also a crown, which can be rotated as a prev/next input.

First, let's make a crown-direction setting (in the Watch section of the on-glasses Settings app), which is a toggle that can swap which crown-rotation direction is considered next vs prev. The default will be off, which will be opposite the direction that is currently default.

Next, we will make it so that the row of buttons is hidden by default. They will slide in from the bottom when the user swipes up from off-screen (distinguished from a swipe-up gesture sent to the glasses by the starting position of the swipe). They will slide out with a swipe down starting from anywhere below the top of the buttons (distinguishing from a swipe-down gesture sent to the glasses by the starting position of the swipe).

Next, we will remove the circle and four arrows; change the time from being small, curved and at the top of the screen to being larger, straight and vertically centered. We'll delete the gesture current hint ("● select  ●● back"), and take the current foreground-window display (which is currently either "Disconnected", "Screen off", or an app title) and place it below the time. When the current state is "Screen off", it will display as "●● Wake". We'll then make it so that when the glasses screen is off, all gestures except for double tap (which wakes the screen) are ignored.

gpt-5.6-Sol:

> Implemented the Wear controller redesign.
>
> - Added on-glasses Settings → Watch toggle: “Clockwise crown = next.” Default off maps clockwise to previous, opposite the former default.
> - Replaced the obsolete “Watch input wakes display” setting.
> - Bottom buttons are hidden initially, slide up from a bottom-edge swipe, and dismiss with a downward swipe anywhere in the tray.
> - Removed the ring, arrows, and gesture hint.
> - Added a large centered straight clock with foreground status beneath it; screen-off status is now “●● Wake.”
> - While the glasses display is off, non-double-tap gestures are ignored locally and defensively on the phone.
> - Updated faceclaw/wear/README.md and faceclaw/wear/PROTOCOL.md.
>
> Verification:
>
> - TypeScript type-check passed.
> - All 59 tests passed.
> - git diff --check passed.
> - Wear Gradle compilation could not start because the sandbox blocks Gradle’s local lock socket/cache access.

</details>
This commit is contained in:
James Babcock committed 2026-08-28 10:28:37 -07:00
1 parent b9e5e56ac8
commit f858f10ce2
13 files changed
+220 -173

No files matched your search

+8 -20
View File
@@ -58,7 +58,7 @@ import { type InProcessAppOptions, type InProcessWindow } from "../ui/shell/in-p
import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-apps-persistence"; import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-apps-persistence";
import { appViewportRect, SIDEBAR_WIDTH, sidebarStripVisible, type WindowHeightMode } from "../ui/shell/geometry"; import { appViewportRect, SIDEBAR_WIDTH, sidebarStripVisible, type WindowHeightMode } from "../ui/shell/geometry";
import { type LayerActions } from "../ui/layers"; import { type LayerActions } from "../ui/layers";
import { assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, brightnessSetting, brightnessSettingToLevel, displayModeSetting, watchWakesDisplaySetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings"; import { assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, brightnessSetting, brightnessSettingToLevel, displayModeSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization"; import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
import { import {
getInstalledEvenHubAppById, getInstalledEvenHubAppById,
@@ -1409,22 +1409,17 @@ class DashboardController {
* finger-down/finger-up (the watch) hold for as long as the user does. * finger-down/finger-up (the watch) hold for as long as the user does.
*/ */
async injectSyntheticRingInput(kind: WearRemoteInputKind, origin: SyntheticInputOrigin = "ring"): Promise<void> { async injectSyntheticRingInput(kind: WearRemoteInputKind, origin: SyntheticInputOrigin = "ring"): Promise<void> {
// Watch-scheme input (the Wear app, the phone's pad/d-pad, mirror touches) // Match the ring while the display is dark: only a double-click wakes it,
// wakes a dark display and then lands normally, resuming the previous // and that wake is handled by Shell.receiveInput. This check also protects
// focus. The ring's own scheme keeps its double-tap-only wake. // against a watch acting on a stale state snapshot.
if ( if (
origin === "watch" && origin === "watch" &&
!shell.isScreenOn() && !shell.isScreenOn() &&
!this.glassesLocked &&
(this.phase === "connected" || this.phase === "charging") &&
watchWakesDisplaySetting.get() &&
kind !== "double-click" && kind !== "double-click" &&
kind !== "wakeword" &&
kind !== "long-press-release" kind !== "long-press-release"
) { ) {
shell.wake(shell.getFocus()); this.appendLog(`${kind} (watch scheme) ignored while display is off`);
this.requestShellRender(); return;
this.appendLog(`${kind} (watch scheme) woke the display`);
} }
if (kind === "long-press") { if (kind === "long-press") {
// Hardware delivers a press event and then a release when the finger // Hardware delivers a press event and then a release when the finger
@@ -1452,15 +1447,8 @@ class DashboardController {
return; return;
} }
if (!shell.isScreenOn()) { if (!shell.isScreenOn()) {
// The same wake policy as the rest of the watch scheme: honour the if (kind === "double-tap") await this.injectSyntheticRingInput("double-click", "watch");
// "input wakes display" setting; with it off, only a double-tap (a return;
// normal double-click) reaches the dark display.
if (!watchWakesDisplaySetting.get()) {
if (kind === "double-tap") await this.injectSyntheticRingInput("double-click", "watch");
return;
}
shell.wake(shell.getFocus());
this.requestShellRender();
} }
if (kind !== "tap") { if (kind !== "tap") {
await this.injectSyntheticRingInput(MIRROR_TOUCH_GESTURES[kind], "watch"); await this.injectSyntheticRingInput(MIRROR_TOUCH_GESTURES[kind], "watch");
+8 -4
View File
@@ -25,6 +25,7 @@ import {
displayModeSetting, displayModeSetting,
onAnySettingChanged, onAnySettingChanged,
watchCanUnlockSetting, watchCanUnlockSetting,
watchCrownClockwiseNextSetting,
watchMirrorAssistantSetting, watchMirrorAssistantSetting,
watchRemoteEnabledSetting, watchRemoteEnabledSetting,
} from "../ui/dashboard-settings"; } from "../ui/dashboard-settings";
@@ -209,6 +210,7 @@ export class WearRemote {
apps: this.listApps(), apps: this.listApps(),
displayMode: displayModeSetting.get(), displayMode: displayModeSetting.get(),
remoteEnabled: watchRemoteEnabledSetting.get(), remoteEnabled: watchRemoteEnabledSetting.get(),
crownClockwiseNext: watchCrownClockwiseNextSetting.get(),
canUnlock: watchCanUnlockSetting.get(), canUnlock: watchCanUnlockSetting.get(),
mirrorAssistant: watchMirrorAssistantSetting.get(), mirrorAssistant: watchMirrorAssistantSetting.get(),
assistantAvailable: shell.isAssistantAvailable(), assistantAvailable: shell.isAssistantAvailable(),
@@ -294,10 +296,8 @@ export class WearRemote {
ack(false, "The glasses are not connected."); ack(false, "The glasses are not connected.");
return; return;
} }
// The lock only yields to a double-click, exactly as the ring's does // The lock and a dark display only yield to a double-click, exactly as
// (handled inside the controller); a dark display wakes on any watch- // the ring does (handled inside the controller).
// scheme gesture (injectSyntheticRingInput, shared with the phone's own
// pad and d-pad).
const repeatable = kind === "scroll-up" || kind === "scroll-down" || kind === "swipe-up" || kind === "swipe-down"; const repeatable = kind === "scroll-up" || kind === "scroll-down" || kind === "swipe-up" || kind === "swipe-down";
const steps = repeatable ? Math.min(MAX_SCROLL_STEPS, Math.max(1, Math.round(readNumber(payload.steps, 1)))) : 1; const steps = repeatable ? Math.min(MAX_SCROLL_STEPS, Math.max(1, Math.round(readNumber(payload.steps, 1)))) : 1;
for (let i = 0; i < steps; i++) { for (let i = 0; i < steps; i++) {
@@ -339,6 +339,10 @@ export class WearRemote {
ack(false, "The glasses are not connected."); ack(false, "The glasses are not connected.");
return; return;
} }
if (payload.source === "gesture" && !shell.isScreenOn()) {
ack(true);
return;
}
if (state.glassesLocked && command !== "unlock" && command !== "lock") { if (state.glassesLocked && command !== "unlock" && command !== "lock") {
ack(false, "The glasses are locked."); ack(false, "The glasses are locked.");
return; return;
+6 -6
View File
@@ -328,13 +328,13 @@ export const watchCanUnlockSetting = new ConfigSettingBoolean({
"Let the watch unlock the glasses' lock screen (which otherwise waits for the phone to be unlocked). Your watch is on your wrist; turn this off if you would rather it stay a phone-only unlock.", "Let the watch unlock the glasses' lock screen (which otherwise waits for the phone to be unlocked). Your watch is on your wrist; turn this off if you would rather it stay a phone-only unlock.",
}); });
export const watchWakesDisplaySetting = new ConfigSettingBoolean({ export const watchCrownClockwiseNextSetting = new ConfigSettingBoolean({
id: "watch-wakes-display", id: "watch-crown-clockwise-next",
label: "Watch input wakes display", label: "Clockwise crown = next",
storageKey: "watch.wakesDisplay", storageKey: "watch.crownClockwiseNext",
defaultValue: true, defaultValue: false,
description: description:
"Any gesture from the watch turns the glasses display on (the ring only wakes it with a double-tap). Off: watch input is ignored while the display is off, as ring input is.", "Choose which crown direction moves to the next item. Off: clockwise moves to the previous item. On: clockwise moves to the next item.",
}); });
export const watchMirrorAssistantSetting = new ConfigSettingBoolean({ export const watchMirrorAssistantSetting = new ConfigSettingBoolean({
+2 -2
View File
@@ -60,9 +60,9 @@ import {
screenTimeoutSetting, screenTimeoutSetting,
wakeWordActionSetting, wakeWordActionSetting,
watchCanUnlockSetting, watchCanUnlockSetting,
watchCrownClockwiseNextSetting,
watchMirrorAssistantSetting, watchMirrorAssistantSetting,
watchRemoteEnabledSetting, watchRemoteEnabledSetting,
watchWakesDisplaySetting,
} from "../dashboard-settings"; } from "../dashboard-settings";
import { wearBridge } from "../../native/wear-bridge"; import { wearBridge } from "../../native/wear-bridge";
import { SettingsPanelLayer, type SettingsSection } from "./settings-panel"; import { SettingsPanelLayer, type SettingsSection } from "./settings-panel";
@@ -167,7 +167,7 @@ function settingsSections(): SettingsSection[] {
// a watch running the companion app is currently reachable. // a watch running the companion app is currently reachable.
items: [ items: [
toggleSettingMenuItem(watchRemoteEnabledSetting), toggleSettingMenuItem(watchRemoteEnabledSetting),
toggleSettingMenuItem(watchWakesDisplaySetting), toggleSettingMenuItem(watchCrownClockwiseNextSetting),
toggleSettingMenuItem(watchCanUnlockSetting), toggleSettingMenuItem(watchCanUnlockSetting),
toggleSettingMenuItem(watchMirrorAssistantSetting), toggleSettingMenuItem(watchMirrorAssistantSetting),
], ],
+6 -3
View File
@@ -18,7 +18,7 @@ answered on `/faceclaw/ack`.
| Path | Payload | Effect | | Path | Payload | Effect |
| --- | --- | --- | | --- | --- | --- |
| `/faceclaw/input` | `{gesture, steps?}` | A ring gesture through the same path as the phone UI's test buttons. `gesture` ∈ `click`, `double-click`, `scroll-up`, `scroll-down`, `long-press` (complete short hold), `long-press-start`, `long-press-release`, `wakeword` ("Hey Even"), `swipe-up`, `swipe-down`, `swipe-left`, `swipe-right` (spatial input only a watch can produce: delivered to the glasses UI as `swipe-*` events for components that navigate spatially — launcher grid, settings columns, sidebar, Music — with a scroll / click / double-click fallback elsewhere). `steps` (1–12) repeats a scroll. Refused while the glasses are disconnected. The lock screen is honoured exactly as for the ring (only a double-click reaches it, toggling the locked display). | | `/faceclaw/input` | `{gesture, steps?}` | A ring gesture through the same path as the phone UI's test buttons. `gesture` ∈ `click`, `double-click`, `scroll-up`, `scroll-down`, `long-press` (complete short hold), `long-press-start`, `long-press-release`, `wakeword` ("Hey Even"), `swipe-up`, `swipe-down`, `swipe-left`, `swipe-right` (spatial input only a watch can produce: delivered to the glasses UI as `swipe-*` events for components that navigate spatially — launcher grid, settings columns, sidebar, Music — with a scroll / click / double-click fallback elsewhere). `steps` (1–12) repeats a scroll. Refused while the glasses are disconnected. The lock screen is honoured exactly as for the ring. While the display is off, only a double-click is accepted and it wakes the display. |
| `/faceclaw/command` | `{command, …}` | `launch-app {appId}`, `focus-window {windowId}`, `close-window {windowId}`, `sidebar`, `wake`, `sleep`, `lock`, `unlock`, `connect`, `disconnect`, `close-assistant`, `display-mode {value}` (`value` ∈ `576x288`, `576x480`, `640x480`; sets the phone's Display > Display mode). Everything but connect/disconnect needs a connection; everything but lock/unlock is refused while locked; `unlock` also needs the phone's "Watch can unlock glasses" setting. | | `/faceclaw/command` | `{command, …}` | `launch-app {appId}`, `focus-window {windowId}`, `close-window {windowId}`, `sidebar`, `wake`, `sleep`, `lock`, `unlock`, `connect`, `disconnect`, `close-assistant`, `display-mode {value}` (`value` ∈ `576x288`, `576x480`, `640x480`; sets the phone's Display > Display mode). Everything but connect/disconnect needs a connection; everything but lock/unlock is refused while locked; `unlock` also needs the phone's "Watch can unlock glasses" setting. |
| `/faceclaw/assistant` | `{text}` | Send a query to the assistant (`shell.sendToAssistant`) — the reply shows on the glasses and streams back to the watch as events. | | `/faceclaw/assistant` | `{text}` | Send a query to the assistant (`shell.sendToAssistant`) — the reply shows on the glasses and streams back to the watch as events. |
| `/faceclaw/text` | `{text}` | Type text into the foreground window (`receiveTextInput`, e.g. the terminal). Refused when the window doesn't take text. | | `/faceclaw/text` | `{text}` | Type text into the foreground window (`receiveTextInput`, e.g. the terminal). Refused when the window doesn't take text. |
@@ -54,14 +54,17 @@ dashboard state, re-sent whenever it changes (and at least every 30 s):
"windows": [{"windowId": "…", "title": "…", "appId": "…", "focused": true, "closeable": true, "acceptsText": false}], "windows": [{"windowId": "…", "title": "…", "appId": "…", "focused": true, "closeable": true, "acceptsText": false}],
"apps": [{"appId": "timer", "title": "Timer"}], "apps": [{"appId": "timer", "title": "Timer"}],
"displayMode": "576x288", "displayMode": "576x288",
"remoteEnabled": true, "canUnlock": true, "mirrorAssistant": true, "remoteEnabled": true, "crownClockwiseNext": false,
"canUnlock": true, "mirrorAssistant": true,
"assistantAvailable": true "assistantAvailable": true
} }
``` ```
`protocol` is reserved for incompatible revisions of this format (nothing `protocol` is reserved for incompatible revisions of this format (nothing
checks it yet); `displayMode` mirrors the phone's Display > Display mode and checks it yet); `displayMode` mirrors the phone's Display > Display mode and
is what the `display-mode` command changes. is what the `display-mode` command changes. `crownClockwiseNext` mirrors the
on-glasses Settings > Watch toggle; when false (the default), clockwise crown
rotation sends previous/up, and when true it sends next/down.
`apps` is the launcher grid plus installed EvenHub packages, i.e. exactly what `apps` is the launcher grid plus installed EvenHub packages, i.e. exactly what
the assistant's `apps.launch` tool accepts. the assistant's `apps.launch` tool accepts.
+7 -5
View File
@@ -15,7 +15,7 @@ the phone it only tells you to install it.
| double-tap, or a two-finger tap | **back**, everywhere: closes menus, leaves a settings column, leaves a folder or the launcher grid, returns to the sidebar (and from the sidebar turns the display off, as the ring does) | | double-tap, or a two-finger tap | **back**, everywhere: closes menus, leaves a settings column, leaves a folder or the launcher grid, returns to the sidebar (and from the sidebar turns the display off, as the ring does) |
| press and hold | the app's context menu (a long press, held until you lift your finger) | | press and hold | the app's context menu (a long press, held until you lift your finger) |
| swipe ↑ ↓ ← → | **spatial navigation, with no mode to enter first**: the launcher highlights one app and the swipe moves it by a row or a column; the settings panel moves between its columns and down its lists; the sidebar moves up and down; Music skips to the previous / next track. Right goes *into* things (sidebar → window, section → items) and left comes back *out* (first column → sidebar). Anywhere without a spatial meaning, up/down scroll, right selects and left goes back. One step per swipe (long swipes used to repeat, which overshot lists whenever the display lagged); use repeated flicks, the crown, or a two-finger page swipe to cover distance. "Natural swipe" flips the vertical sense; left/right can be remapped in settings. | | swipe ↑ ↓ ← → | **spatial navigation, with no mode to enter first**: the launcher highlights one app and the swipe moves it by a row or a column; the settings panel moves between its columns and down its lists; the sidebar moves up and down; Music skips to the previous / next track. Right goes *into* things (sidebar → window, section → items) and left comes back *out* (first column → sidebar). Anywhere without a spatial meaning, up/down scroll, right selects and left goes back. One step per swipe (long swipes used to repeat, which overshot lists whenever the display lagged); use repeated flicks, the crown, or a two-finger page swipe to cover distance. "Natural swipe" flips the vertical sense; left/right can be remapped in settings. |
| rotate the crown | up / down (one step per detent-ish, sensitivity adjustable) — in the launcher that is rows, elsewhere scrolling | | rotate the crown | previous / next (one step per detent-ish, sensitivity adjustable) — clockwise is previous by default; reverse it in the on-glasses Settings > Watch section |
| two-finger swipe up / down | scroll a page (3 steps) | | two-finger swipe up / down | scroll a page (3 steps) |
| **twist the wrist twice** (two brisk flicks, either direction) | back — from the gyroscope; on by default, sensitivity adjustable | | **twist the wrist twice** (two brisk flicks, either direction) | back — from the gyroscope; on by default, sensitivity adjustable |
| **tip taps** — tap your index finger against your thumb | select; two quick taps = back. From the accelerometer; **off by default** (experimental): on a wrist, ordinary hand movement produced phantom selects in testing. Turn on in Watch settings; needs ~¼ s of stillness before a tap counts, and both motion gestures are ignored while the watch is off the wrist or buzzing. | | **tip taps** — tap your index finger against your thumb | select; two quick taps = back. From the accelerometer; **off by default** (experimental): on a wrist, ordinary hand movement produced phantom selects in testing. Turn on in Watch settings; needs ~¼ s of stillness before a tap counts, and both motion gestures are ignored while the watch is off the wrist or buzzing. |
@@ -31,7 +31,9 @@ ever seeing a difference.
long press; button 2 = back; button 3 = "Hey Even". You can also set long press; button 2 = back; button 3 = "Hey Even". You can also set
the watch's button shortcut to open Faceclaw. the watch's button shortcut to open Faceclaw.
**Bottom row buttons**: Assistant, Type into app, Apps, Status. **Bottom row buttons**: Assistant, Type into app, Apps, Status. They are hidden
by default; swipe up beginning at the bottom edge to slide them in, then swipe
down beginning in the button tray to hide them.
- **Assistant** — ask the assistant using the *watch's* microphone (system - **Assistant** — ask the assistant using the *watch's* microphone (system
speech recognition) or the Wear keyboard, and read the reply on the watch as speech recognition) or the Wear keyboard, and read the reply on the watch as
@@ -53,9 +55,9 @@ wrist dropping and freezes the app, so the remote would need a wake-up tap
before every gesture. before every gesture.
Phone-side switches live in Faceclaw's Settings > Watch: turn watch control Phone-side switches live in Faceclaw's Settings > Watch: turn watch control
off entirely, decide whether watch input wakes a dark display (on by default — off entirely, reverse the crown direction, forbid unlocking from the watch,
the ring only wakes it with a double-tap), forbid unlocking from the watch, or stop mirroring assistant replies. While the glasses display is off, every
or stop mirroring assistant replies. watch gesture except a double-tap is ignored; double-tap wakes it.
The watch buzzes differently when the phone refuses or doesn't answer a The watch buzzes differently when the phone refuses or doesn't answer a
gesture (glasses disconnected, locked, watch control off); the pill at the gesture (glasses disconnected, locked, watch control off); the pill at the
+8
View File
@@ -32,6 +32,14 @@ android {
buildConfig = true buildConfig = true
} }
lint {
// androidx.lifecycle 2.9.x ships a NullSafeMutableLiveData lint check
// that crashes under this AGP's lint (Kotlin analysis API mismatch:
// "Found class KaCallableMemberCall, but interface was expected").
// We don't use LiveData, so nothing is lost by disabling it.
disable += "NullSafeMutableLiveData"
}
compileOptions { compileOptions {
sourceCompatibility = JavaVersion.VERSION_17 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17
@@ -20,6 +20,7 @@ class MainActivity : ComponentActivity() {
private val stemHandler = Handler(Looper.getMainLooper()) private val stemHandler = Handler(Looper.getMainLooper())
private var stemHoldRunnable: Runnable? = null private var stemHoldRunnable: Runnable? = null
private var stemHoldSent = false private var stemHoldSent = false
private var stemOneIgnored = false
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -67,10 +68,16 @@ class MainActivity : ComponentActivity() {
if (event.repeatCount == 0) { if (event.repeatCount == 0) {
cancelStemHold() cancelStemHold()
stemHoldSent = false stemHoldSent = false
stemOneIgnored = glassesScreenIsOff()
if (stemOneIgnored) return true
val runnable = Runnable { val runnable = Runnable {
stemHoldSent = true if (glassesScreenIsOff()) {
haptics.heavy() stemOneIgnored = true
link.sendGesture(Gesture.LONG_PRESS_START) } else {
stemHoldSent = true
haptics.heavy()
link.sendGesture(Gesture.LONG_PRESS_START)
}
} }
stemHoldRunnable = runnable stemHoldRunnable = runnable
stemHandler.postDelayed(runnable, STEM_HOLD_MS) stemHandler.postDelayed(runnable, STEM_HOLD_MS)
@@ -85,7 +92,7 @@ class MainActivity : ComponentActivity() {
return true return true
} }
KeyEvent.KEYCODE_STEM_3 -> { KeyEvent.KEYCODE_STEM_3 -> {
if (event.repeatCount == 0) { if (event.repeatCount == 0 && !glassesScreenIsOff()) {
haptics.click() haptics.click()
link.sendGesture(Gesture.WAKEWORD) link.sendGesture(Gesture.WAKEWORD)
} }
@@ -98,11 +105,15 @@ class MainActivity : ComponentActivity() {
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean { override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
if (keyCode == KeyEvent.KEYCODE_STEM_1) { if (keyCode == KeyEvent.KEYCODE_STEM_1) {
cancelStemHold() cancelStemHold()
if (stemOneIgnored) {
stemOneIgnored = false
return true
}
if (stemHoldSent) { if (stemHoldSent) {
stemHoldSent = false stemHoldSent = false
haptics.click() haptics.click()
link.sendGesture(Gesture.LONG_PRESS_RELEASE) link.sendGesture(Gesture.LONG_PRESS_RELEASE)
} else { } else if (!glassesScreenIsOff()) {
haptics.click() haptics.click()
link.sendGesture(Gesture.CLICK) link.sendGesture(Gesture.CLICK)
} }
@@ -117,6 +128,9 @@ class MainActivity : ComponentActivity() {
stemHoldRunnable = null stemHoldRunnable = null
} }
private fun glassesScreenIsOff(): Boolean =
link.state.value?.let { it.connected && !it.screenOn } == true
private companion object { private companion object {
const val STEM_HOLD_MS = 450L const val STEM_HOLD_MS = 450L
} }
@@ -107,6 +107,8 @@ data class PhoneState(
val windows: List<WindowEntry>, val windows: List<WindowEntry>,
val apps: List<AppEntry>, val apps: List<AppEntry>,
val remoteEnabled: Boolean, val remoteEnabled: Boolean,
/** False by default: clockwise moves to the previous item. */
val crownClockwiseNext: Boolean,
val canUnlock: Boolean, val canUnlock: Boolean,
val mirrorAssistant: Boolean, val mirrorAssistant: Boolean,
val assistantAvailable: Boolean, val assistantAvailable: Boolean,
@@ -151,6 +153,7 @@ data class PhoneState(
} }
} ?: emptyList(), } ?: emptyList(),
remoteEnabled = o.optBoolean("remoteEnabled", true), remoteEnabled = o.optBoolean("remoteEnabled", true),
crownClockwiseNext = o.optBoolean("crownClockwiseNext", false),
canUnlock = o.optBoolean("canUnlock", true), canUnlock = o.optBoolean("canUnlock", true),
mirrorAssistant = o.optBoolean("mirrorAssistant", true), mirrorAssistant = o.optBoolean("mirrorAssistant", true),
assistantAvailable = o.optBoolean("assistantAvailable", false), assistantAvailable = o.optBoolean("assistantAvailable", false),
@@ -37,7 +37,7 @@ data class Prefs(
* exactly when a remote wants to stay ready. * exactly when a remote wants to stay ready.
*/ */
val keepScreenOn: Boolean = true, val keepScreenOn: Boolean = true,
/** Swipe/crown direction follows the content (touch-scroll style) instead of the ring. */ /** Swipe direction follows the content (touch-scroll style) instead of the ring. */
val naturalScroll: Boolean = false, val naturalScroll: Boolean = false,
/** Tap the top/bottom of the pad to scroll instead of swiping. */ /** Tap the top/bottom of the pad to scroll instead of swiping. */
val tapZones: Boolean = false, val tapZones: Boolean = false,
@@ -64,7 +64,7 @@ fun padLine(state: PhoneState?, link: LinkStatus): StatusLine = when {
state.remoteEnabled == false -> StatusLine("Watch control off", StatusTone.PROBLEM) state.remoteEnabled == false -> StatusLine("Watch control off", StatusTone.PROBLEM)
state.connected -> when { state.connected -> when {
state.locked -> StatusLine("Locked", StatusTone.OFF) state.locked -> StatusLine("Locked", StatusTone.OFF)
!state.screenOn -> StatusLine("Screen off", StatusTone.OFF) !state.screenOn -> StatusLine("●● Wake", StatusTone.OFF)
state.listening -> StatusLine("Listening…", StatusTone.BUSY) state.listening -> StatusLine("Listening…", StatusTone.BUSY)
else -> StatusLine(state.foreground?.title ?: "Launcher", StatusTone.GOOD) else -> StatusLine(state.foreground?.title ?: "Launcher", StatusTone.GOOD)
} }
@@ -1,15 +1,18 @@
package com.faceclaw.wear.ui package com.faceclaw.wear.ui
import androidx.compose.foundation.Canvas import android.text.format.DateFormat
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.focusable import androidx.compose.foundation.focusable
@@ -24,18 +27,18 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier 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
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.input.rotary.onRotaryScrollEvent import androidx.compose.ui.input.rotary.onRotaryScrollEvent
import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.compose.LocalLifecycleOwner
@@ -47,7 +50,6 @@ import androidx.wear.compose.material.ButtonDefaults
import androidx.wear.compose.material.Icon import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.material.Text import androidx.wear.compose.material.Text
import androidx.wear.compose.material.TimeText
import com.faceclaw.wear.Command import com.faceclaw.wear.Command
import com.faceclaw.wear.FingerTapDetector import com.faceclaw.wear.FingerTapDetector
import com.faceclaw.wear.Gesture import com.faceclaw.wear.Gesture
@@ -59,20 +61,15 @@ import com.faceclaw.wear.R
import com.faceclaw.wear.SwipeAction import com.faceclaw.wear.SwipeAction
import com.faceclaw.wear.WristTwistDetector import com.faceclaw.wear.WristTwistDetector
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import kotlin.math.abs import kotlin.math.abs
private const val MAX_SWIPE_STEPS = 4
/** A two-finger swipe scrolls this many steps: a "page". */ /** A two-finger swipe scrolls this many steps: a "page". */
private const val TWO_FINGER_SWIPE_STEPS = 3 private const val TWO_FINGER_SWIPE_STEPS = 3
private const val FLASH_MS = 160L private val EDGE_REVEAL_ZONE = 24.dp
private const val ARROW_LIT_MS = 220L private val BUTTON_TRAY_HEIGHT = 62.dp
private const val RING_RADIUS_FRACTION = 0.33f
private const val RING_CENTER_Y_FRACTION = 0.47f
private val ARROW_INSET = 6.dp
private val ARROW_SIZE = 18.dp
/** The d-pad directions, for lighting the arrow that was just swiped. */
enum class Arrow { UP, DOWN, LEFT, RIGHT }
/** /**
* The touchpad. The whole screen is the pad: tap = select, double-tap = * The touchpad. The whole screen is the pad: tap = select, double-tap =
@@ -80,8 +77,8 @@ enum class Arrow { UP, DOWN, LEFT, RIGHT }
* the hold menu ("right click"), swipes in four directions = spatial * the hold menu ("right click"), swipes in four directions = spatial
* navigation (crown and two-finger vertical swipes = plain scrolling, a page * navigation (crown and two-finger vertical swipes = plain scrolling, a page
* at a time for the latter). Fingertip pinch-taps from the motion sensors * at a time for the latter). Fingertip pinch-taps from the motion sensors
* select / go back, and two quick wrist twists go back. The small buttons at * select / go back, and two quick wrist twists go back. An upward swipe that
* the bottom reach the rest. * begins at the bottom edge reveals the otherwise-hidden action buttons.
*/ */
// rememberActiveFocusRequester (rotary focus) is still experimental in Wear Compose 1.4. // rememberActiveFocusRequester (rotary focus) is still experimental in Wear Compose 1.4.
@OptIn(ExperimentalWearFoundationApi::class) @OptIn(ExperimentalWearFoundationApi::class)
@@ -98,14 +95,13 @@ fun RemoteScreen(
val linkStatus by link.link.collectAsStateWithLifecycle() val linkStatus by link.link.collectAsStateWithLifecycle()
val notice by link.notice.collectAsStateWithLifecycle() val notice by link.notice.collectAsStateWithLifecycle()
val currentPrefs by rememberUpdatedState(prefs) val currentPrefs by rememberUpdatedState(prefs)
val currentState by rememberUpdatedState(state)
val view = LocalView.current val view = LocalView.current
var holding by remember { mutableStateOf(false) } val density = LocalDensity.current
// Brief ring highlight acknowledging a sensor (tip-tap) gesture. val edgeRevealPx = remember(density) { with(density) { EDGE_REVEAL_ZONE.toPx() } }
var flashUntil by remember { mutableStateOf(0L) } val buttonTrayHeightPx = remember(density) { with(density) { BUTTON_TRAY_HEIGHT.toPx() } }
var flashing by remember { mutableStateOf(false) } var controlsVisible by remember { mutableStateOf(false) }
// Which d-pad arrow lights up for the swipe just sent. var longPressSent by remember { mutableStateOf(false) }
var litArrow by remember { mutableStateOf<Arrow?>(null) }
var litTick by remember { mutableStateOf(0L) }
// Rotary (crown) events are only delivered to a focused node. // Rotary (crown) events are only delivered to a focused node.
// rememberActiveFocusRequester requests focus through the hierarchical // rememberActiveFocusRequester requests focus through the hierarchical
// focus machinery; the resume observer below takes it back after every // focus machinery; the resume observer below takes it back after every
@@ -130,17 +126,19 @@ fun RemoteScreen(
onUnavailable = { haptics.error() }, onUnavailable = { haptics.error() },
) )
fun glassesScreenIsOff(): Boolean = currentState?.connected == true && currentState?.screenOn == false
fun gestureAllowed(gesture: Gesture): Boolean =
!glassesScreenIsOff() || gesture == Gesture.DOUBLE_CLICK
fun scroll(gesture: Gesture, steps: Int) { fun scroll(gesture: Gesture, steps: Int) {
if (!gestureAllowed(gesture)) return
haptics.tick() haptics.tick()
link.sendGesture(gesture, steps) link.sendGesture(gesture, steps)
} }
fun light(arrow: Arrow) {
litArrow = arrow
litTick = System.currentTimeMillis()
}
fun click() { fun click() {
if (!gestureAllowed(Gesture.CLICK)) return
haptics.click() haptics.click()
link.sendGesture(Gesture.CLICK) link.sendGesture(Gesture.CLICK)
} }
@@ -153,12 +151,18 @@ fun RemoteScreen(
/** Run a horizontal-swipe action; `left` says which way the finger went. */ /** Run a horizontal-swipe action; `left` says which way the finger went. */
fun perform(action: SwipeAction, left: Boolean) { fun perform(action: SwipeAction, left: Boolean) {
when (action) { when (action) {
SwipeAction.NAVIGATE -> { haptics.click(); link.sendGesture(if (left) Gesture.SWIPE_LEFT else Gesture.SWIPE_RIGHT) } SwipeAction.NAVIGATE -> {
SwipeAction.SIDEBAR -> { haptics.click(); link.sendCommand(Command.SIDEBAR) } val gesture = if (left) Gesture.SWIPE_LEFT else Gesture.SWIPE_RIGHT
if (gestureAllowed(gesture)) { haptics.click(); link.sendGesture(gesture) }
}
SwipeAction.SIDEBAR -> if (!glassesScreenIsOff()) {
haptics.click()
link.sendCommand(Command.SIDEBAR, "source" to "gesture")
}
SwipeAction.DOUBLE_CLICK -> doubleClick() SwipeAction.DOUBLE_CLICK -> doubleClick()
SwipeAction.CLICK -> click() SwipeAction.CLICK -> click()
SwipeAction.LONG_PRESS -> { haptics.heavy(); link.sendGesture(Gesture.LONG_PRESS) } SwipeAction.LONG_PRESS -> if (!glassesScreenIsOff()) { haptics.heavy(); link.sendGesture(Gesture.LONG_PRESS) }
SwipeAction.WAKEWORD -> { haptics.click(); link.sendGesture(Gesture.WAKEWORD) } SwipeAction.WAKEWORD -> if (!glassesScreenIsOff()) { haptics.click(); link.sendGesture(Gesture.WAKEWORD) }
SwipeAction.NONE -> Unit SwipeAction.NONE -> Unit
} }
} }
@@ -196,28 +200,41 @@ fun RemoteScreen(
} }
}, },
onLongPressStart = { onLongPressStart = {
holding = true longPressSent = !glassesScreenIsOff()
haptics.heavy() if (longPressSent) {
link.sendGesture(Gesture.LONG_PRESS_START) haptics.heavy()
link.sendGesture(Gesture.LONG_PRESS_START)
}
}, },
onLongPressEnd = { onLongPressEnd = {
holding = false if (longPressSent) {
haptics.click() longPressSent = false
link.sendGesture(Gesture.LONG_PRESS_RELEASE) haptics.click()
link.sendGesture(Gesture.LONG_PRESS_RELEASE)
}
}, },
onSwipe = { dx, dy, _ -> onSwipe = { start, dx, dy, _ ->
if (abs(dy) >= abs(dx)) { val vertical = abs(dy) >= abs(dx)
// One step per swipe, regardless of length: the glasses val padBottom = padHeight[0]
// repaint per step, and multi-step swipes overshot lists when {
// whenever the display lagged the finger. Fast repeated vertical && !controlsVisible && dy < 0 && start.y >= padBottom - edgeRevealPx -> {
// swiping, the crown, or a two-finger page swipe cover controlsVisible = true
// long distances instead. haptics.click()
val up = swipeIsUp(dy) }
light(if (up) Arrow.UP else Arrow.DOWN) vertical && controlsVisible && dy > 0 && start.y >= padBottom - buttonTrayHeightPx -> {
scroll(if (up) Gesture.SWIPE_UP else Gesture.SWIPE_DOWN, 1) controlsVisible = false
} else { haptics.click()
light(if (dx < 0) Arrow.LEFT else Arrow.RIGHT) }
perform(if (dx < 0) currentPrefs.swipeLeft else currentPrefs.swipeRight, left = dx < 0) vertical -> {
// One step per swipe, regardless of length: the glasses
// repaint per step, and multi-step swipes overshot lists
// whenever the display lagged the finger. Fast repeated
// swiping, the crown, or a two-finger page swipe cover
// long distances instead.
val up = swipeIsUp(dy)
scroll(if (up) Gesture.SWIPE_UP else Gesture.SWIPE_DOWN, 1)
}
else -> perform(if (dx < 0) currentPrefs.swipeLeft else currentPrefs.swipeRight, left = dx < 0)
} }
}, },
) )
@@ -235,8 +252,8 @@ fun RemoteScreen(
sensitivity = { currentPrefs.tapSensitivity }, sensitivity = { currentPrefs.tapSensitivity },
quietUntil = { haptics.quietUntil() }, quietUntil = { haptics.quietUntil() },
onBody = { onBody.onBody }, onBody = { onBody.onBody },
onTap = { flashUntil = System.currentTimeMillis() + FLASH_MS; click() }, onTap = { click() },
onDoubleTap = { flashUntil = System.currentTimeMillis() + FLASH_MS; doubleClick() }, onDoubleTap = { doubleClick() },
) )
} }
WhileStartedEffect(fingerTapDetector, start = { fingerTapDetector?.start() }, stop = { fingerTapDetector?.stop() }) WhileStartedEffect(fingerTapDetector, start = { fingerTapDetector?.start() }, stop = { fingerTapDetector?.stop() })
@@ -248,21 +265,10 @@ fun RemoteScreen(
sensitivity = { currentPrefs.twistSensitivity }, sensitivity = { currentPrefs.twistSensitivity },
quietUntil = { haptics.quietUntil() }, quietUntil = { haptics.quietUntil() },
onBody = { onBody.onBody }, onBody = { onBody.onBody },
onDoubleTwist = { flashUntil = System.currentTimeMillis() + FLASH_MS; doubleClick() }, onDoubleTwist = { doubleClick() },
) )
} }
WhileStartedEffect(wristTwistDetector, start = { wristTwistDetector?.start() }, stop = { wristTwistDetector?.stop() }) WhileStartedEffect(wristTwistDetector, start = { wristTwistDetector?.start() }, stop = { wristTwistDetector?.stop() })
LaunchedEffect(litTick) {
if (litTick == 0L) return@LaunchedEffect
delay(ARROW_LIT_MS)
litArrow = null
}
LaunchedEffect(flashUntil) {
if (flashUntil == 0L) return@LaunchedEffect
flashing = true
delay((flashUntil - System.currentTimeMillis()).coerceAtLeast(1L))
flashing = false
}
// A refused or unanswered gesture gets a distinct buzz, so the wrist knows // A refused or unanswered gesture gets a distinct buzz, so the wrist knows
// without looking (the notice pill says why). // without looking (the notice pill says why).
@@ -275,15 +281,16 @@ fun RemoteScreen(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.onRotaryScrollEvent { event -> .onRotaryScrollEvent { event ->
// Clockwise (positive) scrolls down, as in every Wear list.
crownAccumulator += event.verticalScrollPixels crownAccumulator += event.verticalScrollPixels
val threshold = currentPrefs.crownSensitivity.pixelsPerStep val threshold = currentPrefs.crownSensitivity.pixelsPerStep
var steps = 0 var steps = 0
while (crownAccumulator >= threshold) { crownAccumulator -= threshold; steps++ } while (crownAccumulator >= threshold) { crownAccumulator -= threshold; steps++ }
while (crownAccumulator <= -threshold) { crownAccumulator += threshold; steps-- } while (crownAccumulator <= -threshold) { crownAccumulator += threshold; steps-- }
// Capped low: a fast twirl otherwise outruns the display. // Capped low: a fast twirl otherwise outruns the display.
if (steps > 0) { light(Arrow.DOWN); scroll(Gesture.SCROLL_DOWN, steps.coerceAtMost(2)) } val clockwise = if (currentState?.crownClockwiseNext == true) Gesture.SCROLL_DOWN else Gesture.SCROLL_UP
if (steps < 0) { light(Arrow.UP); scroll(Gesture.SCROLL_UP, (-steps).coerceAtMost(2)) } val counterClockwise = if (currentState?.crownClockwiseNext == true) Gesture.SCROLL_UP else Gesture.SCROLL_DOWN
if (steps > 0) scroll(clockwise, steps.coerceAtMost(2))
if (steps < 0) scroll(counterClockwise, (-steps).coerceAtMost(2))
true true
} }
.focusRequester(focusRequester) .focusRequester(focusRequester)
@@ -291,68 +298,47 @@ fun RemoteScreen(
.onSizeChanged { padHeight[0] = it.height.toFloat() } .onSizeChanged { padHeight[0] = it.height.toFloat() }
.pointerInput(callbacks) { detectTouchpadGestures(callbacks) }, .pointerInput(callbacks) { detectTouchpadGestures(callbacks) },
) { ) {
// The pad: a ring with a d-pad arrow at each compass point (the one StraightTime(modifier = Modifier.align(Alignment.Center))
// you swiped lights up), the current glasses app in the middle, and
// the tap legend under it. Brightens while a hold is in progress.
BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
val ringRadius = minOf(maxWidth, maxHeight) * RING_RADIUS_FRACTION
val ringCenterY = maxHeight * RING_CENTER_Y_FRACTION
val ringColor = if (holding || flashing) MaterialTheme.colors.primary else Color(0xFF2E2E2E)
Canvas(modifier = Modifier.fillMaxSize()) {
drawCircle(
color = ringColor,
radius = ringRadius.toPx(),
center = Offset(size.width / 2f, ringCenterY.toPx()),
style = Stroke(width = if (holding || flashing) 4f else 2f),
)
}
TimeText() AnimatedVisibility(
visible = !controlsVisible,
ArrowGlyph("▲", litArrow == Arrow.UP, Modifier.align(Alignment.TopCenter).padding(top = ringCenterY - ringRadius + ARROW_INSET)) enter = fadeIn(),
ArrowGlyph("▼", litArrow == Arrow.DOWN, Modifier.align(Alignment.TopCenter).padding(top = ringCenterY + ringRadius - ARROW_INSET - ARROW_SIZE)) exit = fadeOut(),
ArrowGlyph("◀", litArrow == Arrow.LEFT, Modifier.align(Alignment.TopStart).padding(start = maxWidth / 2 - ringRadius + ARROW_INSET, top = ringCenterY - ARROW_SIZE / 2)) modifier = Modifier.align(Alignment.Center).offset(y = 46.dp),
ArrowGlyph("▶", litArrow == Arrow.RIGHT, Modifier.align(Alignment.TopEnd).padding(end = maxWidth / 2 - ringRadius + ARROW_INSET, top = ringCenterY - ARROW_SIZE / 2)) ) {
// 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) val pad = padLine(state, linkStatus)
Text( Text(
text = if (holding) "holding" else pad.text, text = pad.text,
style = MaterialTheme.typography.title3, style = MaterialTheme.typography.title3,
color = when { color = if (pad.tone == StatusTone.GOOD) MaterialTheme.colors.onSurface else pad.tone.color(),
holding -> MaterialTheme.colors.primary
pad.tone == StatusTone.GOOD -> MaterialTheme.colors.onSurface
else -> pad.tone.color()
},
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
modifier = Modifier modifier = Modifier.padding(horizontal = 42.dp),
.align(Alignment.TopCenter)
.padding(top = ringCenterY - 44.dp, start = 60.dp, end = 60.dp),
)
Text(
text = if (prefs.tapZones) "▲▼ tap zones · ● select" else "● select ●● back ‒ menu",
style = MaterialTheme.typography.caption3,
color = MaterialTheme.colors.onSurfaceVariant,
textAlign = TextAlign.Center,
maxLines = 1,
modifier = Modifier
.align(Alignment.TopCenter)
.padding(top = ringCenterY + 18.dp, start = 56.dp, end = 56.dp),
) )
}
AnimatedVisibility(
visible = controlsVisible,
enter = slideInVertically(initialOffsetY = { it }),
exit = slideOutVertically(targetOffsetY = { it }),
modifier = Modifier.align(Alignment.BottomCenter),
) {
Row( Row(
// Four 36dp buttons need 144dp; at this height the round // Four 36dp buttons need 144dp; at this height the round
// display's chord is ~186dp wide, so 36dp margins keep every // display's chord is ~186dp wide, so 36dp margins keep every
// button inside the glass. // button inside the glass.
modifier = Modifier modifier = Modifier
.align(Alignment.BottomCenter)
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 36.dp, vertical = 26.dp), .height(BUTTON_TRAY_HEIGHT)
.pointerInput(Unit) {
detectTrayDismiss {
controlsVisible = false
haptics.click()
}
}
.padding(horizontal = 36.dp)
.padding(bottom = 26.dp),
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {
@@ -393,14 +379,27 @@ private fun WhileStartedEffect(key: Any?, start: () -> Unit, stop: () -> Unit) {
} }
} }
/** A large, straight clock fixed on the vertical centre of the touchpad. */
@Composable @Composable
private fun ArrowGlyph(glyph: String, lit: Boolean, modifier: Modifier) { private fun StraightTime(modifier: Modifier = Modifier) {
val context = LocalContext.current
var now by remember { mutableStateOf(System.currentTimeMillis()) }
val pattern = remember(context) { if (DateFormat.is24HourFormat(context)) "HH:mm" else "h:mm" }
val formatter = remember(pattern) { SimpleDateFormat(pattern, Locale.getDefault()) }
LaunchedEffect(Unit) {
while (true) {
val current = System.currentTimeMillis()
now = current
delay(60_000L - current % 60_000L)
}
}
Text( Text(
text = glyph, text = formatter.format(Date(now)),
style = MaterialTheme.typography.caption1, color = MaterialTheme.colors.onSurface,
color = if (lit) MaterialTheme.colors.primary else Color(0xFF6E6E6E), fontSize = 42.sp,
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
modifier = modifier.size(ARROW_SIZE), maxLines = 1,
modifier = modifier,
) )
} }
@@ -4,8 +4,10 @@ import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.waitForUpOrCancellation import androidx.compose.foundation.gestures.waitForUpOrCancellation
import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.PointerEventPass
import androidx.compose.ui.input.pointer.PointerInputScope import androidx.compose.ui.input.pointer.PointerInputScope
import androidx.compose.ui.input.pointer.positionChanged import androidx.compose.ui.input.pointer.positionChanged
import kotlin.math.abs
/** What the remote's touch surface can report. */ /** What the remote's touch surface can report. */
class TouchpadCallbacks( class TouchpadCallbacks(
@@ -17,7 +19,7 @@ class TouchpadCallbacks(
val onLongPressStart: () -> Unit, val onLongPressStart: () -> Unit,
val onLongPressEnd: () -> Unit, val onLongPressEnd: () -> Unit,
/** Finger travelled past touch slop; dx/dy are the total displacement. */ /** Finger travelled past touch slop; dx/dy are the total displacement. */
val onSwipe: (dx: Float, dy: Float, durationMs: Long) -> Unit, val onSwipe: (start: Offset, dx: Float, dy: Float, durationMs: Long) -> Unit,
) )
/** /**
@@ -86,7 +88,7 @@ suspend fun PointerInputScope.detectTouchpadGestures(callbacks: TouchpadCallback
callbacks.onLongPressEnd() callbacks.onLongPressEnd()
} }
maxPointers >= 2 -> if (moved) callbacks.onTwoFingerSwipe(displacement.x, displacement.y) else callbacks.onTwoFingerTap() maxPointers >= 2 -> if (moved) callbacks.onTwoFingerSwipe(displacement.x, displacement.y) else callbacks.onTwoFingerTap()
moved -> callbacks.onSwipe(displacement.x, displacement.y, duration) moved -> callbacks.onSwipe(down.position, displacement.x, displacement.y, duration)
else -> { else -> {
// A plain tap; give a second tap a chance to make it a double. // A plain tap; give a second tap a chance to make it a double.
val second = withTimeoutOrNull(doubleTapTimeout) { awaitFirstDown() } val second = withTimeoutOrNull(doubleTapTimeout) { awaitFirstDown() }
@@ -108,6 +110,30 @@ suspend fun PointerInputScope.detectTouchpadGestures(callbacks: TouchpadCallback
} }
} }
/**
* Observe the button tray before its child buttons consume a pointer. A
* downward drag claims the gesture and dismisses the tray; a tap remains
* untouched so the button below receives its normal click.
*/
suspend fun PointerInputScope.detectTrayDismiss(onDismiss: () -> Unit) {
val slop = viewConfiguration.touchSlop
awaitEachGesture {
val down = awaitFirstDown(requireUnconsumed = false, pass = PointerEventPass.Initial)
var dismissed = false
while (true) {
val event = awaitPointerEvent(PointerEventPass.Initial)
val primary = event.changes.firstOrNull { it.id == down.id } ?: event.changes.first()
val displacement = primary.position - down.position
if (!dismissed && displacement.y > slop && displacement.y >= abs(displacement.x)) {
dismissed = true
onDismiss()
}
if (dismissed) event.changes.forEach { it.consume() }
if (event.changes.none { it.pressed }) break
}
}
}
/** Poll interval while a hold or drag is in progress (no timeout semantics needed). */ /** Poll interval while a hold or drag is in progress (no timeout semantics needed). */
private const val HOLD_POLL_MS = 60_000L private const val HOLD_POLL_MS = 60_000L