Add Wear OS companion app and remote controls

Add a Wearable Data Layer bridge for syncing dashboard state and commands.

Introduce a standalone watch app with assistant, app launcher, touchpad remote, settings, and connectivity UI.
This commit is contained in:
Kalani Helekunihi committed 2026-08-23 15:02:35 -05:00
1 parent cc4b69fb80
commit 8fa04d1b46
85 files changed
+5813 -102

No files matched your search

+3
View File
@@ -12,6 +12,9 @@ dependencies {
// code" entry. Scanner UI and camera live in Play Services, so Faceclaw
// needs no camera permission and no third-party scanner app.
implementation 'com.google.android.gms:play-services-code-scanner:16.1.0'
// Wearable Data Layer (MessageClient / DataClient / CapabilityClient) for
// the Wear OS watch remote; see FaceclawWearBridge and wear/.
implementation 'com.google.android.gms:play-services-wearable:19.0.0'
}
def faceclawSherpaOnnxVersion = "1.13.0"
@@ -110,6 +110,22 @@
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
<!-- Wear OS: Play services routes watch-app messages (paths under
/faceclaw) and watch reachability changes here, starting the app
process if needed. See FaceclawWearBridge. -->
<service
android:name="com.faceclaw.app.FaceclawWearListenerService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data android:scheme="wear" android:host="*" android:pathPrefix="/faceclaw" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.gms.wearable.CAPABILITY_CHANGED" />
<data android:scheme="wear" android:host="*" android:pathPrefix="/" />
</intent-filter>
</service>
<receiver
android:name="com.faceclaw.app.FaceclawTimerReceiver"
android:enabled="true"
@@ -0,0 +1,378 @@
package com.faceclaw.app;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.wearable.CapabilityClient;
import com.google.android.gms.wearable.CapabilityInfo;
import com.google.android.gms.wearable.DataMap;
import com.google.android.gms.wearable.MessageEvent;
import com.google.android.gms.wearable.Node;
import com.google.android.gms.wearable.PutDataMapRequest;
import com.google.android.gms.wearable.PutDataRequest;
import com.google.android.gms.wearable.Wearable;
import org.json.JSONException;
import org.json.JSONObject;
import java.nio.charset.StandardCharsets;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/**
* Phone side of the Wear OS integration: the single place that talks to the
* Wearable Data Layer (Google Play services), so the JS side only ever sees
* JSON strings and never touches Play services types.
*
* Inbound: FaceclawWearListenerService hands every watch message to
* {@link #handleMessage}; it is forwarded to the JS listener on the thread
* that registered it (the main isolate), mirroring FaceclawSettings. Messages
* that arrive before a listener exists (the watch poked a phone whose JS
* dashboard is not up yet) are kept for a short while and replayed on
* registration; the watch is told with an ack carrying jsReady=false so it
* can say "open Faceclaw on your phone".
*
* Outbound: {@link #publishState} mirrors the dashboard state into a Data
* Layer item (delivered even if the watch is out of range right now, and
* available to the watch app the moment it opens), while {@link #sendToWatch}
* sends fire-and-forget messages (acks, assistant text) to every reachable
* watch that advertises the Faceclaw watch-app capability.
*
* Everything is a no-op on phones without Google Play services.
*/
public final class FaceclawWearBridge {
private static final String TAG = "FaceclawWear";
/** Advertised by the watch app (wear/app/src/main/res/values/wear.xml). */
public static final String CAPABILITY_WATCH = "faceclaw_watch";
/** Advertised by this app (res/values/wear.xml) so the watch can find the phone. */
public static final String CAPABILITY_PHONE = "faceclaw_phone";
public static final String PATH_PREFIX = "/faceclaw";
public static final String PATH_STATE = "/faceclaw/state";
public static final String PATH_STATE_REQUEST = "/faceclaw/state/request";
public static final String PATH_ACK = "/faceclaw/ack";
public static final String PATH_EVENT = "/faceclaw/event";
private static final String STATE_KEY_JSON = "json";
private static final String STATE_KEY_UPDATED_AT = "updatedAt";
/** Messages kept for a listener that is not registered yet. */
private static final int PENDING_LIMIT = 16;
private static final long PENDING_MAX_AGE_MS = 30_000;
private static volatile FaceclawWearBridge instance;
private final Context context;
private final boolean available;
private final Object lock = new Object();
private FaceclawWearListener listener;
private Handler listenerHandler;
private final ArrayDeque<PendingMessage> pending = new ArrayDeque<>();
private final List<Node> watchNodes = new ArrayList<>();
private String lastPublishedState = null;
private static final class PendingMessage {
final String path;
final String json;
final String nodeId;
final long receivedAt;
PendingMessage(String path, String json, String nodeId, long receivedAt) {
this.path = path;
this.json = json;
this.nodeId = nodeId;
this.receivedAt = receivedAt;
}
}
private FaceclawWearBridge(Context context) {
this.context = context.getApplicationContext();
boolean playServices;
try {
playServices = GoogleApiAvailability.getInstance()
.isGooglePlayServicesAvailable(this.context) == ConnectionResult.SUCCESS;
} catch (Throwable error) {
Log.w(TAG, "Play services availability check failed", error);
playServices = false;
}
this.available = playServices;
if (!available) {
Log.i(TAG, "Google Play services unavailable; watch integration disabled");
}
}
/** Initialize (idempotent) and return the singleton. */
public static FaceclawWearBridge getInstance(Context context) {
if (instance == null) {
synchronized (FaceclawWearBridge.class) {
if (instance == null) {
instance = new FaceclawWearBridge(context);
}
}
}
return instance;
}
/** Whether the Wearable Data Layer can be used on this phone at all. */
public boolean isAvailable() {
return available;
}
/**
* Register the JS listener. Must be called from the thread whose isolate
* owns it; that thread's Looper is captured for dispatch. Replays any
* recently queued watch messages and refreshes the reachable-watch set.
*/
public void setListener(FaceclawWearListener newListener) {
Looper looper = Looper.myLooper();
if (looper == null) {
Log.w(TAG, "wear listener registered from a Looper-less thread; it will never be notified");
}
List<PendingMessage> replay;
synchronized (lock) {
listener = newListener;
listenerHandler = looper != null ? new Handler(looper) : null;
replay = new ArrayList<>(pending);
pending.clear();
}
long now = System.currentTimeMillis();
for (PendingMessage message : replay) {
if (now - message.receivedAt <= PENDING_MAX_AGE_MS) {
dispatchMessage(message.path, message.json, message.nodeId);
}
}
refreshWatchNodes();
}
public void clearListener() {
synchronized (lock) {
listener = null;
listenerHandler = null;
}
}
public boolean isWatchReachable() {
synchronized (lock) {
return !watchNodes.isEmpty();
}
}
/** Display name of a reachable watch ("" if none). */
public String getWatchName() {
synchronized (lock) {
return watchNodes.isEmpty() ? "" : watchNodes.get(0).getDisplayName();
}
}
/** Re-query which watches advertise the Faceclaw watch-app capability. */
public void refreshWatchNodes() {
if (!available) return;
try {
Wearable.getCapabilityClient(context)
.getCapability(CAPABILITY_WATCH, CapabilityClient.FILTER_REACHABLE)
.addOnSuccessListener(this::updateWatchNodes)
.addOnFailureListener(error -> Log.w(TAG, "capability query failed", error));
} catch (Throwable error) {
Log.w(TAG, "capability query failed", error);
}
}
/**
* Mirror the dashboard state to the watch. Identical consecutive states
* are not re-sent (the Data Layer would drop them anyway).
*/
public void publishState(String json) {
publishState(json, false);
}
/** As {@link #publishState(String)}; `force` re-sends an unchanged state. */
public void publishState(String json, boolean force) {
if (!available || json == null) return;
synchronized (lock) {
if (!force && json.equals(lastPublishedState)) return;
lastPublishedState = json;
}
try {
PutDataMapRequest request = PutDataMapRequest.create(PATH_STATE);
DataMap map = request.getDataMap();
map.putString(STATE_KEY_JSON, json);
map.putLong(STATE_KEY_UPDATED_AT, System.currentTimeMillis());
PutDataRequest put = request.asPutDataRequest().setUrgent();
Wearable.getDataClient(context)
.putDataItem(put)
.addOnFailureListener(error -> Log.w(TAG, "state publish failed", error));
} catch (Throwable error) {
Log.w(TAG, "state publish failed", error);
}
}
/** Send a message to every reachable watch running the Faceclaw watch app. */
public void sendToWatch(String path, String json) {
if (!available) return;
List<Node> targets;
synchronized (lock) {
targets = new ArrayList<>(watchNodes);
}
if (targets.isEmpty()) {
// Nothing known yet (first message after boot): look the watch up, then send.
try {
Wearable.getCapabilityClient(context)
.getCapability(CAPABILITY_WATCH, CapabilityClient.FILTER_REACHABLE)
.addOnSuccessListener(info -> {
updateWatchNodes(info);
for (Node node : info.getNodes()) {
sendToNode(node.getId(), path, json);
}
})
.addOnFailureListener(error -> Log.w(TAG, "capability query failed", error));
} catch (Throwable error) {
Log.w(TAG, "capability query failed", error);
}
return;
}
for (Node node : targets) {
sendToNode(node.getId(), path, json);
}
}
/** Send a message to one specific node (e.g. an ack back to the sender). */
public void sendToNode(String nodeId, String path, String json) {
if (!available || nodeId == null || nodeId.isEmpty()) return;
try {
byte[] payload = (json != null ? json : "{}").getBytes(StandardCharsets.UTF_8);
Wearable.getMessageClient(context)
.sendMessage(nodeId, path, payload)
.addOnFailureListener(error -> Log.w(TAG, "send " + path + " to " + nodeId + " failed", error));
} catch (Throwable error) {
Log.w(TAG, "send " + path + " failed", error);
}
}
/** Reply to a watch message; `seq` echoes the watch's sequence number. */
public void sendAck(String nodeId, long seq, boolean ok, boolean jsReady, String message) {
JSONObject ack = new JSONObject();
try {
ack.put("seq", seq);
ack.put("ok", ok);
ack.put("jsReady", jsReady);
ack.put("message", message != null ? message : "");
} catch (JSONException ignored) {
// The keys are constants; this cannot happen.
}
sendToNode(nodeId, PATH_ACK, ack.toString());
}
/** Entry point for FaceclawWearListenerService; may run on any thread. */
void handleMessage(MessageEvent event) {
if (event == null) return;
String path = event.getPath();
if (path == null || !path.startsWith(PATH_PREFIX)) return;
byte[] data = event.getData();
String json = data != null && data.length > 0 ? new String(data, StandardCharsets.UTF_8) : "{}";
String nodeId = event.getSourceNodeId();
Log.d(TAG, "recv " + path + " seq=" + readSeq(json));
boolean delivered = dispatchMessage(path, json, nodeId);
if (delivered) return;
// No JS listener yet: keep the message briefly, and tell the watch so
// it can explain why nothing is happening.
synchronized (lock) {
long now = System.currentTimeMillis();
while (!pending.isEmpty() && now - pending.peekFirst().receivedAt > PENDING_MAX_AGE_MS) {
pending.pollFirst();
}
if (pending.size() >= PENDING_LIMIT) {
pending.pollFirst();
}
pending.addLast(new PendingMessage(path, json, nodeId, now));
}
sendAck(nodeId, readSeq(json), false, false, "Faceclaw is not running on the phone. Open it to connect the glasses.");
}
/** Entry point for FaceclawWearListenerService's capability callback. */
void handleCapabilityChanged(CapabilityInfo info) {
if (info == null || !CAPABILITY_WATCH.equals(info.getName())) return;
updateWatchNodes(info);
}
private void updateWatchNodes(CapabilityInfo info) {
Set<Node> nodes = info != null ? info.getNodes() : Collections.<Node>emptySet();
// Every reachable watch gets messages; a nearby (Bluetooth-linked)
// one is listed first so it is the name the phone UI shows.
List<Node> reachable = new ArrayList<>();
for (Node node : nodes) {
if (node.isNearby()) reachable.add(0, node); else reachable.add(node);
}
boolean changed;
String name;
synchronized (lock) {
changed = !sameNodeIds(watchNodes, reachable);
watchNodes.clear();
watchNodes.addAll(reachable);
name = watchNodes.isEmpty() ? "" : watchNodes.get(0).getDisplayName();
}
if (changed) {
Log.i(TAG, reachable.isEmpty() ? "no Faceclaw watch reachable" : "watch reachable: " + name);
boolean reachableNow = !reachable.isEmpty();
FaceclawWearListener target;
Handler handler;
synchronized (lock) {
target = listener;
handler = listenerHandler;
}
if (target != null && handler != null) {
handler.post(() -> {
try {
target.onWatchConnection(reachableNow, name);
} catch (Exception error) {
Log.w(TAG, "watch connection listener failed", error);
}
});
}
}
}
private static boolean sameNodeIds(List<Node> a, List<Node> b) {
if (a.size() != b.size()) return false;
for (int i = 0; i < a.size(); i++) {
if (!a.get(i).getId().equals(b.get(i).getId())) return false;
}
return true;
}
/** Post to the JS listener; false when there is none to post to. */
private boolean dispatchMessage(String path, String json, String nodeId) {
FaceclawWearListener target;
Handler handler;
synchronized (lock) {
target = listener;
handler = listenerHandler;
}
if (target == null || handler == null) return false;
handler.post(() -> {
try {
target.onMessage(path, json, nodeId);
} catch (Exception error) {
Log.w(TAG, "wear message listener failed for " + path, error);
}
});
return true;
}
private static long readSeq(String json) {
try {
return new JSONObject(json).optLong("seq", 0);
} catch (JSONException error) {
return 0;
}
}
}
@@ -0,0 +1,19 @@
package com.faceclaw.app;
/**
* Callbacks from the Android Wear (Wear OS) bridge; implemented in JS. Every
* call is delivered on the thread that registered the listener (see
* FaceclawWearBridge.setListener).
*/
public interface FaceclawWearListener {
/**
* A message from the watch app. `path` is the Data Layer message path
* (e.g. "/faceclaw/input"); `json` is the UTF-8 payload (always a JSON
* object, "{}" when the watch sent none); `nodeId` identifies the watch
* so a reply can be addressed to it.
*/
void onMessage(String path, String json, String nodeId);
/** The set of reachable watches running the Faceclaw watch app changed. */
void onWatchConnection(boolean reachable, String watchName);
}
@@ -0,0 +1,26 @@
package com.faceclaw.app;
import android.util.Log;
import com.google.android.gms.wearable.CapabilityInfo;
import com.google.android.gms.wearable.MessageEvent;
import com.google.android.gms.wearable.WearableListenerService;
/**
* Play services starts this service (in the app process) for every Data
* Layer message under /faceclaw and for capability changes, whether or not
* the app is running. It only forwards to FaceclawWearBridge, which owns the
* hand-off to the JS side.
*/
public class FaceclawWearListenerService extends WearableListenerService {
@Override
public void onMessageReceived(MessageEvent event) {
Log.d("FaceclawWear", "service onMessageReceived " + event.getPath() + " from " + event.getSourceNodeId());
FaceclawWearBridge.getInstance(this).handleMessage(event);
}
@Override
public void onCapabilityChanged(CapabilityInfo info) {
FaceclawWearBridge.getInstance(this).handleCapabilityChanged(info);
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Wearable Data Layer capability advertised to the watch, so the Faceclaw
watch app can find the phone that has Faceclaw installed. The watch app
advertises "faceclaw_watch" in return (see wear/). -->
<resources>
<string-array name="android_wear_capabilities">
<item>faceclaw_phone</item>
</string-array>
</resources>
+7
View File
@@ -5,6 +5,13 @@ for interfacing with Android SDK).
Typescript parts are in app/. Java parts are in App_Resources/Android/src/main/java/com/faceclaw/app/.
wear/ is a separate Gradle project (Kotlin + Compose for Wear OS): the watch
remote that drives Faceclaw over the Wearable Data Layer. Its phone-side
counterparts are FaceclawWearBridge.java, app/native/wear-bridge.ts and
app/g2/wear-remote.ts; the message format is in wear/PROTOCOL.md. Build it
with `cd wear && ./gradlew :app:assembleDebug` (needs JAVA_HOME and
ANDROID_HOME); it is not part of `npm run build`.
If build.sh exists, it's a machine-specific wrapper that sets some environment
variables to point to where tools are installed, then runs `npm run build`.
If build_and_run.sh exists, it does everything build.sh does plus
+15
View File
@@ -74,3 +74,18 @@ https://support.evenrealities.com/hc/en-us/articles/14127464826511-Privacy-Polic
Apps downloaded from the EvenHub app store come with their own privacy
policies.
## Wear OS Watch
The optional Faceclaw watch app (wear/) talks to the phone over Google Play
services' Wearable Data Layer, the same channel the watch uses for
notifications and other companion apps. Gestures, commands, the watch's own
speech-recognition results, and the mirrored glasses status and assistant
replies travel between your watch and your phone over their Bluetooth (or,
when paired that way, Wi-Fi) link; Faceclaw does not send any of it to a
server. Speech recognized on the watch uses the watch's system speech
recognizer, which may send audio to Google under Google's privacy policy:
Google: https://policies.google.com/privacy
The phone does nothing watch-related on phones without Google Play services.
+31 -1
View File
@@ -65,11 +65,41 @@ To install, run
battery life similar to the stock Even app.
* Connection management with auto-reconnect, and autodetection of conflict
with the official Even Realities app
* On-phone screen mirroring and simulated ring input
* On-phone screen mirroring with touch control: tap what you see on the
mirror (sidebar icons, launcher cells), or use the phone's own touchpad,
d-pad and Back/Menu buttons — the same spatial scheme as the watch — plus
a compact ring simulator. A display-mode picker (576×288 band, 576×480
tall, or the full 640×480 panel with an auto-hiding sidebar) and a
brightness slider with an Auto toggle sit beside the mirror.
* A Wear OS watch app that replaces (and outdoes) the R1 ring: tap, swipe,
hold and crown gestures, side buttons, app launching and window switching,
voice or keyboard queries to the assistant with the reply on your wrist,
typing into apps, and glasses status/lock/display control (see "Watch
remote" below)
* Dual-language NativeScript architecture with Java for the multithreaded
Android API and bluetooth stack bits, Typescript for the bits you want to
hack on
## Watch remote (Wear OS)
The `wear/` directory holds a companion app for Wear OS 3+ watches that turns
the watch into a remote for the glasses. The whole watch face is a touchpad
that mirrors the ring (tap, double-tap, hold, swipe, crown scrolling, side
buttons), and beyond the ring it can launch apps, switch and close windows,
wake/sleep/lock the display, send spoken or typed queries straight to the
assistant (using the watch's own microphone) and show the reply on the wrist,
and type text into apps such as the terminal. Its swipes are a spatial
control scheme the ring never had, with no mode to enter first: the
launcher highlights one app and moves it by rows and columns, right goes
into things (sidebar → window, settings section → items, next track in
Music), left backs out, tap selects, hold opens the context menu, double-tap
or a two-finger tap is back everywhere, and two wrist twists go back; up/down
scroll and right/left select/back everywhere else. The ring's own scheme is
unchanged — watch input is tagged as a separate source. Faceclaw's Settings > Watch
section has the phone-side switches. See [wear/README.md](wear/README.md) for
building and installing it; it is a separate Gradle build, sideloaded over
adb, and needs no Play Store. The phone side requires Google Play services.
## Connecting an external agent (OpenClaw)
Instead of calling an LLM API directly from the phone, the voice assistant
+75
View File
@@ -55,3 +55,78 @@ Button.-primary {
border-width: 1;
border-radius: 8;
}
/* The phone's controller for the glasses (phone-ui/remote-controls.xml). */
.remote-controls {
margin: 0 8 0 8;
}
.display-controls {
margin-bottom: 6;
}
.mode-button {
font-size: 13;
padding: 6 10;
margin-right: 6;
}
.brightness-icon {
font-size: 16;
margin: 0 4 0 4;
color: #444444;
}
.auto-toggle Label {
font-size: 13;
margin-right: 2;
}
.touchpad {
height: 230;
background-color: #1f1f1f;
border-radius: 14;
border-width: 1;
border-color: #3a3a3a;
color: #f0f0f0;
margin-top: 2;
}
.pad-focus {
font-size: 20;
color: #ffffff;
}
.pad-dpad-button {
width: 46;
height: 46;
margin: 6;
padding: 0;
font-size: 16;
border-radius: 23;
background-color: #333333;
color: #e8e8e8;
}
.pad-dpad-down {
margin-bottom: 30;
}
.pad-legend {
font-size: 11;
color: #8a8a8a;
margin-bottom: 8;
}
.action-row {
margin-top: 6;
}
.action-button {
margin: 2;
font-size: 14;
}
.ring-row {
margin-top: 4;
}
.ring-label {
font-size: 12;
color: #666666;
margin: 0 6 0 4;
}
.ring-button {
width: 44;
height: 36;
margin: 1;
padding: 0;
font-size: 13;
}
+10
View File
@@ -4,6 +4,7 @@
* makes the content area exactly the 576x288 surface EvenHub apps expect.
*/
import { GrayImage } from "../../graphics/image";
import { EVENHUB_SCREEN_WIDTH } from "./compositor";
import { type DashboardInputEvent, type Layer, type LayerContext } from "../../ui/layers";
import {
createInProcessWindow,
@@ -20,6 +21,15 @@ class EvenHubAppLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const size = ctx.stack.getBaseSize();
// EvenHub apps lay out for the stock 576-wide surface. In the full-panel
// display mode the window is 640 wide; paint at stock width and centre
// it rather than leaving all the slack on the right.
if (size.width > EVENHUB_SCREEN_WIDTH) {
const content = this.session.paint({ width: EVENHUB_SCREEN_WIDTH, height: size.height }, ctx.stack.isFocused());
const image = new GrayImage(size.width, size.height, 0);
content.composeInto(image, Math.floor((size.width - EVENHUB_SCREEN_WIDTH) / 2), 0);
return image;
}
return this.session.paint(size, ctx.stack.isFocused());
}
+8 -3
View File
@@ -20,7 +20,7 @@
import { ApplicationSettings } from "@nativescript/core";
import { GrayImage } from "../../graphics/image";
import { EvenHubFont } from "../../graphics/evenhub-font";
import { type DashboardInputEvent, type Layer } from "../../ui/layers";
import { type DashboardInputEvent, type InputSource, type Layer } from "../../ui/layers";
import {
anthropicApiKeySetting,
elevenLabsApiKeySetting,
@@ -1346,12 +1346,17 @@ function luminance(r: number, g: number, b: number): number {
return Math.round(0.2126 * r + 0.7152 * g + 0.0722 * b);
}
/** ring/left-arm/right-arm -> PB EventSourceType. */
function gestureSource(source: "ring" | "left-arm" | "right-arm"): number {
/**
* ring/left-arm/right-arm -> PB EventSourceType. The watch is reported to
* EvenHub apps as the ring: they only know stock hardware, and the watch's
* ring-vocabulary gestures mean the same thing.
*/
function gestureSource(source: InputSource): number {
switch (source) {
case "right-arm":
return 1;
case "ring":
case "watch":
return 2;
case "left-arm":
return 3;
+115 -15
View File
@@ -5,7 +5,7 @@ import { GrayImage } from "../../graphics/image";
import { type Plane } from "../../graphics/plane";
import { renderIcon, type IconName } from "../../graphics/icons";
import { clamp } from "../../util/numeric-util";
import { DashboardInputEvent, Layer, LayerActions, LayerContext } from "../../ui/layers";
import { DashboardInputEvent, isWatchInput, Layer, LayerActions, LayerContext } from "../../ui/layers";
import { drawSelectionHighlight, MenuLayer, scrollToKeepSelectionVisible, type MenuItem } from "../../ui/menu";
import { iconGridMinRowHeight } from "../../ui/metrics";
import { WINDOW_MENU_LAYOUT } from "../../ui/window-menu";
@@ -64,12 +64,19 @@ type LauncherGridEntry =
* picks the item); a tap launches an app or opens a folder (the same grid,
* restricted to that folder's apps). Double-click backs out one level (item →
* row, folder → top grid), and from the top level yields to the sidebar.
* That is the ring's scheme; the watch (see handleWatchInput) skips row mode
* and moves one cell at a time in four directions.
*
* The folder grouping lives in the settings store (see launcher-folders.ts)
* and is re-read every paint, so assistant folder tools take effect without
* the layer holding any copy of the state.
*/
class LauncherGridLayer implements Layer {
// Watch swipes are spatial: up/down move between rows, left/right between
// columns. From row mode, right goes into the row (left backs out, like
// double-click); from the first column, left returns to row mode, which
// keeps "left" pointing toward the sidebar all the way out.
readonly acceptsDirectional = true;
private mode: LauncherMode = "row";
private selectedRow = 0;
private selectedCol = 1;
@@ -307,6 +314,10 @@ class LauncherGridLayer implements Layer {
}
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
if (isWatchInput(event)) {
await this.handleWatchInput(event, ctx);
return;
}
const entries = this.entries();
const rows = this.rowCount(entries.length);
switch (event.type) {
@@ -341,20 +352,7 @@ class LauncherGridLayer implements Layer {
this.itemsInRow(entries.length, this.selectedRow) - 1,
);
} else {
const entry = entries[this.selectedRow * COLS + this.selectedCol];
if (!entry) return;
if (entry.kind === "folder") {
this.currentFolder = entry.name;
this.mode = "row";
this.selectedRow = 0;
this.scrollRow = 0;
} else {
// Return to the top grid before launching, so the launcher never
// shows (even briefly) stale folder contents when re-entered.
if (this.currentFolder !== null) this.exitFolder();
this.mode = "row";
await this.options.launchApp(entry.appId);
}
await this.openSelected(entries);
}
return;
}
@@ -371,6 +369,108 @@ class LauncherGridLayer implements Layer {
return;
}
}
/**
* The watch's scheme: there is no row mode to enter first. The selection is
* always one cell; up/down/left/right (and the crown) move it spatially,
* select opens it, back leaves the folder or the grid, and stepping left
* past the first column leaves for the sidebar, which is where "left" goes.
* Row mode is restored on the way out so a ring user finds the grid as
* they left it.
*/
private async handleWatchInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
const entries = this.entries();
const rows = this.rowCount(entries.length);
if (this.mode === "row") {
this.mode = "item";
this.selectedCol = clamp(this.selectedCol, 0, this.itemsInRow(entries.length, this.selectedRow) - 1);
}
const leave = () => {
this.mode = "row";
shell.yieldFocusToSidebar();
};
switch (event.type) {
case "swipe-up":
case "swipe-down":
case "scroll-up":
case "scroll-down": {
const delta = event.type === "swipe-down" || event.type === "scroll-down" ? 1 : -1;
this.selectedRow = clamp(this.selectedRow + delta, 0, rows - 1);
// Keep the column; a shorter last row clamps it.
this.selectedCol = clamp(this.selectedCol, 0, this.itemsInRow(entries.length, this.selectedRow) - 1);
return;
}
case "swipe-right":
this.selectedCol = clamp(this.selectedCol + 1, 0, this.itemsInRow(entries.length, this.selectedRow) - 1);
return;
case "swipe-left":
if (this.selectedCol > 0) {
this.selectedCol--;
} else if (this.currentFolder !== null) {
this.exitFolder();
this.mode = "item";
} else {
leave();
}
return;
case "click":
await this.openSelected(entries);
return;
case "double-click":
if (this.currentFolder !== null) {
this.exitFolder();
this.mode = "item";
} else {
leave();
}
return;
default:
return;
}
}
/**
* A touch on the phone's mirror: the cell under it becomes the selection
* and opens (the same as a watch select on it). Uses the geometry paint
* lays the grid out with, so it lands on what the mirror showed.
*/
async hitTest(x: number, y: number, ctx: LayerContext): Promise<boolean> {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const entries = this.entries();
const gridTop = this.currentFolder !== null ? GRID_TOP + font.lineHeight + 4 : GRID_TOP;
const gridBottom = height - 4;
if (y < gridTop || y >= gridBottom || x < 0 || x >= width) return false;
const rowH = iconGridMinRowHeight(font, ICON_SIZE, LABEL_GAP);
const colW = width / COLS;
const row = this.scrollRow + Math.floor((y - gridTop) / rowH);
const col = Math.floor(x / colW);
if (row < 0 || row >= this.rowCount(entries.length)) return false;
if (col < 0 || col >= this.itemsInRow(entries.length, row)) return false;
this.mode = "item";
this.selectedRow = row;
this.selectedCol = col;
await this.openSelected(entries);
return true;
}
/** Open the selected cell: enter a folder, or launch the app. */
private async openSelected(entries: readonly LauncherGridEntry[]): Promise<void> {
const entry = entries[this.selectedRow * COLS + this.selectedCol];
if (!entry) return;
if (entry.kind === "folder") {
this.currentFolder = entry.name;
this.mode = "row";
this.selectedRow = 0;
this.scrollRow = 0;
} else {
// Return to the top grid before launching, so the launcher never
// shows (even briefly) stale folder contents when re-entered.
if (this.currentFolder !== null) this.exitFolder();
this.mode = "row";
await this.options.launchApp(entry.appId);
}
}
}
/**
+25 -1
View File
@@ -17,7 +17,14 @@ import {
} from "../../native/media-controller";
import { mediaBrowserBridge, type MediaBrowserApp } from "../../native/media-browser";
import { MediaBrowseLayer } from "./media-browse";
import { Layer, type DashboardInputEvent, type LayerContext, type PaintBelow } from "../../ui/layers";
import {
directionalFallback,
isDirectionalInput,
Layer,
type DashboardInputEvent,
type LayerContext,
type PaintBelow,
} from "../../ui/layers";
import {
createInProcessWindow,
YieldAtRootLayer,
@@ -59,6 +66,8 @@ type FocusColumn = "actions" | "playlist";
* player's queue when it exposes one (scroll to a track, click to jump).
*/
class MusicAppLayer implements Layer {
// Watch swipes skip tracks: right = next, left = previous.
readonly acceptsDirectional = true;
private focusColumn: FocusColumn = "actions";
private selectedActionIndex = 0;
private selectedQueueIndex = 0;
@@ -215,6 +224,10 @@ class MusicAppLayer implements Layer {
return;
}
const media = mediaControllerBridge.snapshot();
if ((!media.accessEnabled || !media.available) && isDirectionalInput(event)) {
// Nothing to skip between yet: the setup prompts take select / back.
return this.handleInput(directionalFallback(event), ctx);
}
if (!media.accessEnabled) {
if (event.type === "click") {
mediaControllerBridge.openNotificationAccessSettings();
@@ -233,6 +246,16 @@ class MusicAppLayer implements Layer {
const actions = this.buildActions(media, queue);
this.reconcileSelection(actions, queue);
switch (event.type) {
case "swipe-right":
if (media.canSkipNext) await mediaControllerBridge.skipNext();
return;
case "swipe-left":
if (media.canSkipPrevious) await mediaControllerBridge.skipPrevious();
return;
case "swipe-up":
return this.handleInput({ type: "scroll-up" }, ctx);
case "swipe-down":
return this.handleInput({ type: "scroll-down" }, ctx);
case "scroll-up":
if (this.focusColumn === "playlist") {
this.selectedQueueIndex = Math.max(0, this.selectedQueueIndex - 1);
@@ -437,6 +460,7 @@ class VolumeModalLayer implements Layer {
/** Let back leave the playlist column before the root wrapper yields to the shell. */
class MusicRootLayer implements Layer {
readonly acceptsDirectional = true;
private readonly yieldAtRoot: YieldAtRootLayer;
constructor(private readonly music: MusicAppLayer) {
+264 -24
View File
@@ -1,5 +1,5 @@
import { Application, ImageSource } from "@nativescript/core";
import { EvenAIStatus, EvenAIStatusName, EventSourceType, EventSourceTypeName, OsEventTypeList, OsEventTypeName } from "./events";
import { EvenAIStatus, EvenAIStatusName, EventSourceType, EventSourceTypeName, OsEventTypeList, OsEventTypeName, WatchGestureType, WatchGestureTypeName } from "./events";
import { loadDeviceAddresses } from "./device-addresses";
import { ensureBlePermissions, ensureVoicePermissions } from "./android-permissions";
import { FaceclawCommunicatorBridge, type RawInputEvent } from "../native/faceclaw-communicator";
@@ -12,6 +12,29 @@ import { openEvenAppSettings, readEvenAppNotificationState } from "../native/eve
import { grayImageToPreviewSource } from "../native/gray-image-preview";
import { firmwareIncompatibilityMessage } from "./firmware-compat";
import { resumeAutoReconnect, suppressAutoReconnect } from "./reconnect-policy";
import { WearRemote, type WearRemoteInputKind } from "./wear-remote";
/** Who a synthetic (non-firmware) input stands for. */
type SyntheticInputOrigin = "ring" | "watch";
/** Gestures the phone's mirror view reports (see handleMirrorTouch). */
export type MirrorTouchKind =
| "tap"
| "double-tap"
| "long-press"
| "swipe-up"
| "swipe-down"
| "swipe-left"
| "swipe-right";
const MIRROR_TOUCH_GESTURES: Record<Exclude<MirrorTouchKind, "tap">, WearRemoteInputKind> = {
"double-tap": "double-click",
"long-press": "long-press",
"swipe-up": "swipe-up",
"swipe-down": "swipe-down",
"swipe-left": "swipe-left",
"swipe-right": "swipe-right",
};
import { findSoundEffect, playSoundEffect } from "../ui/sound-effects";
import { isWelcomeSoundPending, setWelcomeSoundPending } from "../phone-ui/onboarding-state";
import { beginRenderPass, endRenderPass } from "../util/render-freshness";
@@ -33,9 +56,9 @@ import { ALL_APPS } from "../apps/all-apps";
import { type AppContext, type AppDefinition, type AppLaunchParams, type TextEditorHost } from "../apps/app-definition";
import { type InProcessAppOptions, type InProcessWindow } from "../ui/shell/in-process-window";
import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-apps-persistence";
import { appViewportRect, type WindowHeightMode } from "../ui/shell/geometry";
import { appViewportRect, SIDEBAR_WIDTH, sidebarWidth, type WindowHeightMode } from "../ui/shell/geometry";
import { type LayerActions } from "../ui/layers";
import { assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, brightnessSetting, brightnessSettingToLevel, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
import { assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, brightnessSetting, brightnessSettingToLevel, displayModeSetting, watchWakesDisplaySetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
import {
getInstalledEvenHubAppById,
@@ -84,13 +107,20 @@ const LOCK_SCREEN_MESSAGE = "Glasses locked; unlock the phone to unlock the glas
// Top-bar clock refresh; the phone-side preview polls the Java composite so
// it reflects every app (including worker apps the TS side never renders).
const SHELL_REFRESH_INTERVAL_MS = 60_000;
// Safety-net poll only; the preview is event-driven (every composited frame
// schedules a refresh), so this just covers anything that slips through.
const PREVIEW_INTERVAL_MS = 1_000;
const SCREEN_TIMEOUT_CHECK_MS = 1_000;
const EVENHUB_SCREEN_OFF_SUSPEND_DELAY_MS = 5_000;
const EVENHUB_WAKE_READY_TIMEOUT_MS = 4_500;
const FOREGROUND_NOTIFICATION_MIN_UPDATE_MS = 30_000;
const FRAME_TRANSMIT_BACKPRESSURE_TIMEOUT_MS = 6_000;
const CONNECTED_PREVIEW_MIN_UPDATE_MS = 1_000;
// Preview refresh floor. Refreshes are scheduled per composited frame with a
// trailing update, so the mirror tracks the glasses within this bound instead
// of the old 1s poll (which lagged up to two polls behind).
const CONNECTED_PREVIEW_MIN_UPDATE_MS = 150;
// The GIF recorder keeps its old cadence; per-frame captures would balloon it.
const RECORDING_MIN_CAPTURE_MS = 1_000;
// Below this, a disconnect is more likely a flat battery than a BLE problem.
const LOW_BATTERY_PERCENT = 5;
const EVEN_APP_DETECTED_MESSAGE =
@@ -138,6 +168,9 @@ function eventLabel(kind: string, eventType: number): string {
if (kind === "even-ai") {
return EvenAIStatusName[eventType] ?? `EVEN_AI_UNKNOWN_${eventType}`;
}
if (kind === "watch-gesture") {
return WatchGestureTypeName[eventType] ?? `WATCH_UNKNOWN_${eventType}`;
}
return eventName(eventType);
}
@@ -182,6 +215,8 @@ class DashboardController {
private glassesWorn: boolean | null = null;
private phoneLocked = false;
private glassesLocked = false;
// Wear OS watch remote; constructed last so it sees a fully wired shell.
private wearRemote: WearRemote | null = null;
private lockSurfaceConfigured = false;
private lastLockScreenEnabled = lockScreenEnabledSetting.get();
private offState: (() => void) | null = null;
@@ -265,10 +300,14 @@ class DashboardController {
},
getScreenTimeoutMs: () => screenTimeoutSettingToMs(screenTimeoutSetting.get()),
requestShellRender: () => this.requestShellRender(),
onWindowsChanged: () => this.persistOpenApps(),
onWindowsChanged: () => {
this.persistOpenApps();
this.wearRemote?.schedulePublish();
},
onScreenStateChanged: (on) => {
this.handleScreenStateChanged(on);
if (on) this.requestShellRender();
this.wearRemote?.schedulePublish();
},
});
// Boot hooks register windows that exist from startup (the launcher,
@@ -290,6 +329,7 @@ class DashboardController {
this.pushBrightness();
this.syncEvenHubScreenOffSetting();
this.applyVerticalPositionIfChanged();
this.applyDisplayModeIfChanged();
this.syncAssistantBridgeIfChanged();
this.syncLockScreenSettingIfChanged();
});
@@ -297,6 +337,24 @@ class DashboardController {
// connection stays up (with re-dial) so proactive tool calls work
// outside voice turns.
this.syncAssistantBridge();
// The watch drives the same synthetic-input path as the phone UI's test
// buttons, plus app/window/lock commands; it mirrors the state below.
this.wearRemote = new WearRemote({
apps: LAUNCHABLE_APPS,
injectInput: (kind) => this.injectSyntheticRingInput(kind, "watch"),
launchApp: (appId) => this.launchApp(appId),
connect: () => this.connect(),
disconnect: () => this.disconnect(),
setGlassesLocked: (locked, reason) => this.setGlassesLocked(locked, reason),
requestShellRender: () => this.requestShellRender(),
getState: () => ({
phase: this.phase,
status: this.status,
glassesLocked: this.glassesLocked,
glassesWorn: this.glassesWorn,
}),
appendLog: (line) => this.appendLog(line),
});
}
// Bridge settings changes re-dial the connection; unrelated setting changes
@@ -339,6 +397,48 @@ class DashboardController {
// don't trigger a full reposition.
private lastVerticalPosition = verticalPositionSetting.get();
private lastDisplayMode = displayModeSetting.get();
/**
* Display mode changed (Settings > Display, or the phone page's picker):
* every window's viewport size changes. In-process windows re-measure in
* place; worker windows get their canvas once at open, so they are closed
* and launched again at the new size.
*/
private applyDisplayModeIfChanged(): void {
const mode = displayModeSetting.get();
if (mode === this.lastDisplayMode) return;
this.lastDisplayMode = mode;
this.appendLog(`display mode: ${mode}`);
const foregroundWindowId = shell.foregroundWindow()?.windowId;
void (async () => {
const relaunch: string[] = [];
for (const window of Array.from(shell.getWindows())) {
if (window.relayout) {
window.relayout();
await this.configureWindowSurface(
window.surfaceId,
window.windowId === foregroundWindowId,
window.heightMode,
);
} else if (window.closeable) {
relaunch.push(window.appId);
shell.closeWindow(window.windowId);
}
}
for (const appId of relaunch) {
await this.launchApp(appId);
}
if (foregroundWindowId && shell.getWindows().some((w) => w.windowId === foregroundWindowId)) {
shell.focusWindow(foregroundWindowId);
}
shell.foregroundWindow()?.requestRender();
this.requestShellRender();
})().catch((error) => {
this.appendLog(`display mode change failed: ${this.formatError(error)}`);
});
}
private applyVerticalPositionIfChanged(): void {
const position = verticalPositionSetting.get();
if (position === this.lastVerticalPosition) return;
@@ -400,6 +500,7 @@ class DashboardController {
private handleWearState(wearing: boolean): void {
this.glassesWorn = wearing;
this.appendLog(wearing ? "glasses wear state: ON_HEAD" : "glasses wear state: OFF_HEAD");
this.wearRemote?.schedulePublish();
if (!wearing && this.phoneLocked && lockScreenEnabledSetting.get()) {
this.setGlassesLocked(true, "glasses removed while phone locked");
}
@@ -420,6 +521,7 @@ class DashboardController {
if (locked === this.glassesLocked) return;
this.glassesLocked = locked;
this.appendLog(`glasses ${locked ? "locked" : "unlocked"}: ${reason}`);
this.wearRemote?.schedulePublish();
void this.syncLockSurface().catch((error) => {
this.appendLog(`lock screen update failed: ${this.formatError(error)}`);
});
@@ -947,6 +1049,7 @@ class DashboardController {
// Repaint the top bar (battery indicators live in the shell chrome).
this.requestShellRender();
}
this.wearRemote?.schedulePublish();
});
this.offEvenAppConflict = communicator.onEvenAppConflict((message) => {
this.refreshEvenAppStatus();
@@ -959,6 +1062,10 @@ class DashboardController {
this.emit();
});
this.offFrameMetrics = communicator.onFrameMetrics(() => {
// Every composited frame refreshes the phone-side mirror (bounded by
// CONNECTED_PREVIEW_MIN_UPDATE_MS) so it tracks the glasses instead
// of trailing the 1s safety-net poll.
this.schedulePreviewUpdate();
if (this.phase === "connected") {
this.setStatus("Connected.");
// A rendered frame means the session is warmed up (fixedLayoutCreated),
@@ -1255,20 +1362,94 @@ class DashboardController {
}
}
async injectSyntheticRingInput(
kind: "click" | "double-click" | "scroll-up" | "scroll-down" | "long-press" | "wakeword",
): Promise<void> {
/**
* Feed a ring gesture from somewhere other than the ring (the phone UI's
* test buttons, the watch). "long-press" is a complete short hold;
* "long-press-start" / "long-press-release" let a source with a real
* finger-down/finger-up (the watch) hold for as long as the user does.
*/
async injectSyntheticRingInput(kind: WearRemoteInputKind, origin: SyntheticInputOrigin = "ring"): Promise<void> {
// Watch-scheme input (the Wear app, the phone's pad/d-pad, mirror touches)
// wakes a dark display and then lands normally, resuming the previous
// focus. The ring's own scheme keeps its double-tap-only wake.
if (
origin === "watch" &&
!shell.isScreenOn() &&
!this.glassesLocked &&
(this.phase === "connected" || this.phase === "charging") &&
watchWakesDisplaySetting.get() &&
kind !== "double-click" &&
kind !== "wakeword" &&
kind !== "long-press-release"
) {
shell.wake(shell.getFocus());
this.requestShellRender();
this.appendLog(`${kind} (watch scheme) woke the display`);
}
if (kind === "long-press") {
// Hardware delivers a press event and then a release when the finger
// lifts; emulate a short hold so the escape-menu countdown never fires.
await this.handleInputEvent(this.buildSyntheticRingInput("long-press"));
await this.handleInputEvent(this.buildSyntheticRingInput("long-press-release"));
await this.handleInputEvent(this.buildSyntheticRingInput("long-press", origin));
await this.handleInputEvent(this.buildSyntheticRingInput("long-press-release", origin));
return;
}
const event = this.buildSyntheticRingInput(kind);
const event = this.buildSyntheticRingInput(kind === "long-press-start" ? "long-press" : kind, origin);
await this.handleInputEvent(event);
}
/**
* A touch on the phone's mirror of the glasses display. Gestures other than
* a tap are the watch scheme (swipes navigate, double-tap is back, a hold
* is the menu). A tap lands on what the mirror shows: a sidebar icon
* switches to that window, a launcher cell opens, anything else selects.
* Coordinates are fractions of the mirror (0..1).
*/
async handleMirrorTouch(kind: MirrorTouchKind, nx: number, ny: number): Promise<void> {
if (this.phase !== "connected" && this.phase !== "charging") return;
if (this.glassesLocked) {
// Same as the ring: only a double-tap reaches a locked display.
if (kind === "double-tap") await this.injectSyntheticRingInput("double-click", "watch");
return;
}
if (!shell.isScreenOn()) {
shell.wake(shell.getFocus());
this.requestShellRender();
}
if (kind !== "tap") {
await this.injectSyntheticRingInput(MIRROR_TOUCH_GESTURES[kind], "watch");
return;
}
const x = Math.round(Math.min(1, Math.max(0, nx)) * G2_LENS_WIDTH);
const y = Math.round(Math.min(1, Math.max(0, ny)) * G2_LENS_HEIGHT);
const stripShown = sidebarWidth() > 0 || shell.getFocus() === "sidebar";
this.appendLog(`mirror tap at ${x},${y}`);
if (!shell.hasOverlay() && stripShown && x < SIDEBAR_WIDTH) {
const target = shell.windowAtSidebarPoint(x, y);
if (target) {
this.appendLog(`mirror tap: sidebar -> ${target.title}`);
shell.focusWindow(target.windowId);
shell.foregroundWindow()?.requestRender();
this.requestShellRender();
}
return;
}
const window = shell.foregroundWindow();
if (window && !shell.hasOverlay()) {
const rect = appViewportRect(window.heightMode);
const inside = x >= rect.x && x < rect.x + rect.width && y >= rect.y && y < rect.y + rect.height;
if (shell.getFocus() !== "window") {
shell.focusWindow(window.windowId);
this.requestShellRender();
}
if (inside && window.hitTest && (await window.hitTest(x - rect.x, y - rect.y))) {
this.appendLog(`mirror tap: ${window.title} at ${x - rect.x},${y - rect.y}`);
this.requestShellRender();
return;
}
}
await this.injectSyntheticRingInput("click", "watch");
}
/** A document arrived via Android's Share intent: open it as a new window. */
async openSharedTextDocument(text: string): Promise<void> {
this.appendLog(`shared text document received (${text.length} chars)`);
@@ -1410,7 +1591,8 @@ class DashboardController {
if (this.glassesLocked) {
const ringDoubleTap =
inputEvent.type === "double-click" &&
event.eventSource === EventSourceType.TOUCH_EVENT_FROM_RING;
(event.eventSource === EventSourceType.TOUCH_EVENT_FROM_RING ||
event.eventSource === EventSourceType.TOUCH_EVENT_FROM_WATCH);
const suspendedDisplayWake = inputEvent.type === "display-wake";
if (ringDoubleTap || suspendedDisplayWake) {
if (shell.isScreenOn()) {
@@ -1463,6 +1645,9 @@ class DashboardController {
outcome = { ...outcome, shell: true };
}
if (event.kind === "watch-gesture") {
this.appendLog(`watch-gesture ${eventLabel(event.kind, event.eventType)}`);
}
if (event.kind === "sys-event") {
this.lastSys = `${sourceName(event.eventSource)}/${eventName(event.eventType)}`;
this.appendLog(`sys-event ${this.lastSys}`);
@@ -1473,7 +1658,10 @@ class DashboardController {
) {
this.appendLog("display state invalidated by firmware exit event");
}
if (event.eventSource === EventSourceType.TOUCH_EVENT_FROM_RING) {
if (
event.eventSource === EventSourceType.TOUCH_EVENT_FROM_RING ||
event.eventSource === EventSourceType.TOUCH_EVENT_FROM_WATCH
) {
this.lastInput = eventName(event.eventType);
}
}
@@ -1813,7 +2001,7 @@ class DashboardController {
`still unsent after ${FRAME_TRANSMIT_BACKPRESSURE_TIMEOUT_MS}ms; shell render loop released`,
);
}
this.updateCompositePreview();
this.schedulePreviewUpdate();
}
private async handleWakeWord(keyword: string): Promise<void> {
@@ -1878,6 +2066,10 @@ class DashboardController {
clearInterval(this.previewTimer);
this.previewTimer = null;
}
if (this.previewTrailingTimer) {
clearTimeout(this.previewTrailingTimer);
this.previewTrailingTimer = null;
}
if (this.screenTimeoutTimer) {
clearInterval(this.screenTimeoutTimer);
this.screenTimeoutTimer = null;
@@ -1928,6 +2120,27 @@ class DashboardController {
* foreground, including worker apps the TS side never renders). Throttled
* to avoid rebuilding the bitmap faster than the phone UI needs it.
*/
private previewTrailingTimer: ReturnType<typeof setTimeout> | null = null;
private lastRecordCaptureAtMs = 0;
/**
* Refresh the preview now if the floor allows, otherwise once the floor
* expires — so the last frame of a burst always reaches the mirror instead
* of waiting for the safety-net poll.
*/
private schedulePreviewUpdate(): void {
if (this.previewTrailingTimer) return;
const wait = this.lastConnectedPreviewUpdateAtMs + CONNECTED_PREVIEW_MIN_UPDATE_MS - Date.now();
if (wait <= 0) {
this.updateCompositePreview();
return;
}
this.previewTrailingTimer = setTimeout(() => {
this.previewTrailingTimer = null;
this.updateCompositePreview();
}, wait);
}
private updateCompositePreview(): void {
if (!this.communicator) return;
// The connected foreground service intentionally keeps this controller
@@ -1947,9 +2160,8 @@ class DashboardController {
return;
}
this.lastConnectedPreviewUpdateAtMs = now;
// The recorder captures at the same cadence the phone-side preview is
// refreshed, so the GIF matches what the phone display showed.
if (this.screenRecordingActive) {
if (this.screenRecordingActive && now - this.lastRecordCaptureAtMs >= RECORDING_MIN_CAPTURE_MS) {
this.lastRecordCaptureAtMs = now;
this.communicator.recordScreenFrame();
}
const preview = this.communicator.getCompositePreview();
@@ -1973,10 +2185,37 @@ class DashboardController {
| "scroll-down"
| "long-press"
| "long-press-release"
| "wakeword",
| "wakeword"
| "swipe-left"
| "swipe-right"
| "swipe-up"
| "swipe-down",
origin: SyntheticInputOrigin = "ring",
): RawInputEvent {
const frameId = frameTimings.startFrame(`input:synthetic:${kind}`);
// The phone UI's test buttons stand in for the ring; the watch is its own
// source so the UI can give it a richer scheme (see InputSource).
const eventSource =
origin === "watch" ? EventSourceType.TOUCH_EVENT_FROM_WATCH : EventSourceType.TOUCH_EVENT_FROM_RING;
switch (kind) {
case "swipe-left":
case "swipe-right":
case "swipe-up":
case "swipe-down":
// Watch-only directional input; see WatchGestureType.
return {
kind: "watch-gesture",
containerName: "",
eventType: {
"swipe-left": WatchGestureType.SWIPE_LEFT,
"swipe-right": WatchGestureType.SWIPE_RIGHT,
"swipe-up": WatchGestureType.SWIPE_UP,
"swipe-down": WatchGestureType.SWIPE_DOWN,
}[kind],
eventSource: 0,
systemExitReasonCode: 0,
frameId,
};
case "wakeword":
// Same event the glasses report for the spoken wakeword (sid 0x07).
return {
@@ -1992,7 +2231,7 @@ class DashboardController {
kind: "sys-event",
containerName: "",
eventType: OsEventTypeList.RING_LONG_PRESS_EVENT,
eventSource: EventSourceType.TOUCH_EVENT_FROM_RING,
eventSource,
systemExitReasonCode: 0,
frameId,
};
@@ -2001,7 +2240,7 @@ class DashboardController {
kind: "sys-event",
containerName: "",
eventType: OsEventTypeList.RING_LONG_PRESS_RELEASE_EVENT,
eventSource: EventSourceType.TOUCH_EVENT_FROM_RING,
eventSource,
systemExitReasonCode: 0,
frameId,
};
@@ -2010,7 +2249,7 @@ class DashboardController {
kind: "sys-event",
containerName: "",
eventType: OsEventTypeList.CLICK_EVENT,
eventSource: EventSourceType.TOUCH_EVENT_FROM_RING,
eventSource,
systemExitReasonCode: 0,
frameId,
};
@@ -2019,7 +2258,7 @@ class DashboardController {
kind: "sys-event",
containerName: "",
eventType: OsEventTypeList.DOUBLE_CLICK_EVENT,
eventSource: EventSourceType.TOUCH_EVENT_FROM_RING,
eventSource,
systemExitReasonCode: 0,
frameId,
};
@@ -2028,7 +2267,7 @@ class DashboardController {
kind: "text-click",
containerName: "",
eventType: OsEventTypeList.SCROLL_TOP_EVENT,
eventSource: EventSourceType.TOUCH_EVENT_FROM_RING,
eventSource,
systemExitReasonCode: 0,
frameId,
};
@@ -2038,7 +2277,7 @@ class DashboardController {
kind: "text-click",
containerName: "",
eventType: OsEventTypeList.SCROLL_BOTTOM_EVENT,
eventSource: EventSourceType.TOUCH_EVENT_FROM_RING,
eventSource,
systemExitReasonCode: 0,
frameId,
};
@@ -2050,6 +2289,7 @@ class DashboardController {
for (const listener of this.listeners) {
listener(snapshot);
}
this.wearRemote?.schedulePublish();
}
}
+25
View File
@@ -3,6 +3,12 @@ export const EventSourceType = {
TOUCH_EVENT_FROM_GLASSES_R: 1,
TOUCH_EVENT_FROM_RING: 2,
TOUCH_EVENT_FROM_GLASSES_L: 3,
/**
* Synthetic: the Wear OS remote (app/g2/wear-remote.ts). Not a firmware
* value. Lets the UI give watch input its own, richer scheme (direct
* spatial selection) while ring input keeps the stock one.
*/
TOUCH_EVENT_FROM_WATCH: 4,
} as const;
export const EventSourceTypeName: Record<number, string> = {
@@ -10,6 +16,7 @@ export const EventSourceTypeName: Record<number, string> = {
1: "TOUCH_EVENT_FROM_GLASSES_R",
2: "TOUCH_EVENT_FROM_RING",
3: "TOUCH_EVENT_FROM_GLASSES_L",
4: "TOUCH_EVENT_FROM_WATCH",
};
/**
@@ -32,6 +39,24 @@ export const EvenAIStatusName: Record<number, string> = {
3: "EVEN_AI_EXIT",
};
/**
* Synthetic gestures from the Wear OS remote (RawInputEvent kind
* "watch-gesture"). Not a firmware enum: the glasses never send these.
*/
export const WatchGestureType = {
SWIPE_LEFT: 0,
SWIPE_RIGHT: 1,
SWIPE_UP: 2,
SWIPE_DOWN: 3,
} as const;
export const WatchGestureTypeName: Record<number, string> = {
0: "SWIPE_LEFT",
1: "SWIPE_RIGHT",
2: "SWIPE_UP",
3: "SWIPE_DOWN",
};
export const OsEventTypeList = {
CLICK_EVENT: 0,
SCROLL_TOP_EVENT: 1,
+490
View File
@@ -0,0 +1,490 @@
/**
* The Wear OS watch as an input device and status mirror for the glasses.
*
* Inbound, the watch sends ring-style gestures (tap, double-tap, hold,
* swipe/crown scrolls, "Hey Even") which feed the exact synthetic-ring path
* the phone UI's test buttons use, plus higher-level commands the ring has no
* way to express: launch an app, switch or close a window, wake/sleep/lock
* the display, send a spoken or typed query straight to the assistant, or
* type text into the foreground app.
*
* Outbound, the dashboard state (connection, battery, screen, lock, open
* windows, launchable apps) is mirrored into a Data Layer item so the watch
* UI can show it and offer the right actions; assistant replies and alerts
* stream to the watch as events so a query made from the wrist can be read
* from the wrist.
*
* Transport is app/native/wear-bridge.ts (Java FaceclawWearBridge); the
* message shapes are documented in wear/PROTOCOL.md.
*/
import { type AppDefinition } from "../apps/app-definition";
import { getInstalledEvenHubApps, installedEvenHubAppId } from "../apps/evenhub/installed-apps";
import { WEAR_PATHS, wearBridge, type WearMessage } from "../native/wear-bridge";
import {
DISPLAY_MODE_VALUES,
displayModeSetting,
onAnySettingChanged,
watchCanUnlockSetting,
watchMirrorAssistantSetting,
watchRemoteEnabledSetting,
} from "../ui/dashboard-settings";
import { shell, type AssistantActivityEvent } from "../ui/shell/shell";
import { voiceActivity } from "../ui/shell/voice-activity";
import { FACECLAW_VERSION } from "../version";
/** Protocol revision carried in the state item; bump on incompatible changes. */
export const WEAR_PROTOCOL_VERSION = 1;
export type WearRemoteInputKind =
| "click"
| "double-click"
| "scroll-up"
| "scroll-down"
| "long-press"
| "long-press-start"
| "long-press-release"
| "wakeword"
| "swipe-left"
| "swipe-right"
| "swipe-up"
| "swipe-down";
const INPUT_KINDS: readonly WearRemoteInputKind[] = [
"click",
"double-click",
"scroll-up",
"scroll-down",
"long-press",
"long-press-start",
"long-press-release",
"wakeword",
"swipe-left",
"swipe-right",
"swipe-up",
"swipe-down",
];
const COMMANDS = [
"launch-app",
"focus-window",
"close-window",
"sidebar",
"wake",
"sleep",
"lock",
"unlock",
"connect",
"disconnect",
"close-assistant",
"display-mode",
] as const;
type WearCommand = (typeof COMMANDS)[number];
const MAX_SCROLL_STEPS = 12;
const MAX_TEXT_LENGTH = 2000;
const STATE_PUBLISH_DEBOUNCE_MS = 150;
const STATE_REFRESH_INTERVAL_MS = 30_000;
const ASSISTANT_STREAM_MIN_INTERVAL_MS = 250;
/** What the dashboard controller lends the watch remote. */
export type WearRemoteHost = {
/** The launcher-grid apps; installed EvenHub packages are added dynamically. */
apps: readonly AppDefinition[];
injectInput: (kind: WearRemoteInputKind) => Promise<void>;
launchApp: (appId: string) => Promise<void>;
connect: () => Promise<void>;
disconnect: () => Promise<void>;
setGlassesLocked: (locked: boolean, reason: string) => void;
requestShellRender: () => void;
getState: () => {
phase: string;
status: string;
glassesLocked: boolean;
glassesWorn: boolean | null;
};
appendLog: (line: string) => void;
};
export class WearRemote {
private readonly active: boolean;
private publishTimer: ReturnType<typeof setTimeout> | null = null;
private watchReachable = false;
private watchName = "";
// Assistant text streams as deltas many times a second; the watch gets a
// snapshot every ASSISTANT_STREAM_MIN_INTERVAL_MS plus every phase change.
private assistantStreamTimer: ReturnType<typeof setTimeout> | null = null;
private assistantPendingText: string | null = null;
private lastAssistantSentAtMs = 0;
constructor(private readonly host: WearRemoteHost) {
this.active = wearBridge.isAvailable();
if (!this.active) {
host.appendLog("watch: Google Play services unavailable; watch remote disabled");
return;
}
wearBridge.onMessage((message) => {
void this.handleMessage(message).catch((error) => {
host.appendLog(`watch: ${message.path} failed: ${formatError(error)}`);
});
});
wearBridge.onWatchConnection((connection) => {
const changed = connection.reachable !== this.watchReachable || connection.watchName !== this.watchName;
this.watchReachable = connection.reachable;
this.watchName = connection.watchName;
if (changed) {
host.appendLog(
connection.reachable ? `watch: ${connection.watchName || "watch"} reachable` : "watch: no watch reachable",
);
}
// A watch that just came into range gets the current state at once.
if (connection.reachable) this.publishNow(true);
});
shell.onAssistantActivity((event) => this.forwardAssistantActivity(event));
shell.onAlertShown((text) => {
if (watchMirrorAssistantSetting.get()) {
wearBridge.sendEvent({ type: "alert", text });
}
});
voiceActivity.subscribe(() => this.schedulePublish());
onAnySettingChanged(() => this.schedulePublish());
// Catch-all refresh for state the controller does not announce (cheap:
// identical states are dropped on the Java side).
setInterval(() => this.schedulePublish(), STATE_REFRESH_INTERVAL_MS);
this.schedulePublish();
}
/** Whether a watch running the Faceclaw watch app is reachable right now. */
isWatchReachable(): boolean {
return this.watchReachable;
}
getWatchName(): string {
return this.watchName;
}
/** Mirror the dashboard state to the watch soon; coalesces bursts. */
schedulePublish(): void {
if (!this.active || this.publishTimer) return;
this.publishTimer = setTimeout(() => {
this.publishTimer = null;
this.publishNow(false);
}, STATE_PUBLISH_DEBOUNCE_MS);
}
private publishNow(force: boolean): void {
if (!this.active) return;
try {
wearBridge.publishState(this.buildState(), force);
} catch (error) {
this.host.appendLog(`watch: state publish failed: ${formatError(error)}`);
}
}
private buildState(): Record<string, unknown> {
const state = this.host.getState();
const battery = shell.getBatteryLevels();
const foregroundId = shell.foregroundWindow()?.windowId ?? null;
const foreground = shell.getForegroundApp();
return {
protocol: WEAR_PROTOCOL_VERSION,
version: FACECLAW_VERSION,
phase: state.phase,
status: state.status,
connected: state.phase === "connected" || state.phase === "charging",
screenOn: shell.isScreenOn(),
locked: state.glassesLocked,
worn: state.glassesWorn,
listening: voiceActivity.isActive(),
battery: battery.headset,
charging: battery.headsetCharging === true,
foreground: foreground ? { appId: foreground.appId, title: foreground.title } : null,
windows: shell.getWindows().map((window) => ({
windowId: window.windowId,
title: window.title,
appId: window.appId,
focused: window.windowId === foregroundId,
closeable: window.closeable,
acceptsText: typeof window.receiveTextInput === "function",
})),
apps: this.listApps(),
displayMode: displayModeSetting.get(),
remoteEnabled: watchRemoteEnabledSetting.get(),
canUnlock: watchCanUnlockSetting.get(),
mirrorAssistant: watchMirrorAssistantSetting.get(),
assistantAvailable: shell.isAssistantAvailable(),
};
}
/** Launchable apps, matching the launcher grid and the apps.launch tool. */
private listApps(): Array<{ appId: string; title: string }> {
const apps = this.host.apps.map((app) => ({ appId: app.appId, title: app.title }));
for (const installed of getInstalledEvenHubApps()) {
apps.push({ appId: installedEvenHubAppId(installed.packageId), title: installed.name });
}
return apps;
}
private async handleMessage(message: WearMessage): Promise<void> {
const seq = readNumber(message.payload.seq, 0);
const ack = (ok: boolean, text = "") => wearBridge.sendAck(message.nodeId, seq, ok, text);
if (message.path === WEAR_PATHS.stateRequest) {
this.publishNow(true);
ack(true);
return;
}
if (!watchRemoteEnabledSetting.get()) {
ack(false, "Watch control is turned off in Faceclaw's Settings > Watch.");
return;
}
switch (message.path) {
case WEAR_PATHS.input:
await this.handleInput(message.payload, ack);
return;
case WEAR_PATHS.command:
await this.handleCommand(message.payload, ack);
return;
case WEAR_PATHS.assistant: {
const text = readText(message.payload.text);
if (!text) {
ack(false, "Nothing to send.");
return;
}
if (!shell.isAssistantAvailable()) {
ack(false, "Set up the assistant in Faceclaw's Settings first.");
return;
}
this.host.appendLog(`watch: assistant query (${text.length} chars)`);
shell.sendToAssistant(text);
ack(true);
return;
}
case WEAR_PATHS.text: {
const text = readText(message.payload.text);
if (!text) {
ack(false, "Nothing to type.");
return;
}
const window = shell.foregroundWindow();
if (!window?.receiveTextInput) {
ack(false, `${window ? window.title : "The current app"} does not accept typed text.`);
return;
}
if (!shell.isScreenOn()) shell.wake("window");
this.host.appendLog(`watch: typed ${text.length} chars into ${window.title}`);
shell.sendTextToForegroundWindow(text);
ack(true);
return;
}
default:
ack(false, `Unknown message: ${message.path}`);
}
}
private async handleInput(payload: Record<string, unknown>, ack: (ok: boolean, text?: string) => void): Promise<void> {
const gesture = String(payload.gesture ?? "");
if (!(INPUT_KINDS as readonly string[]).includes(gesture)) {
ack(false, `Unknown gesture: ${gesture}`);
return;
}
const kind = gesture as WearRemoteInputKind;
const state = this.host.getState();
if (state.phase !== "connected" && state.phase !== "charging") {
ack(false, "The glasses are not connected.");
return;
}
// The lock only yields to a double-click, exactly as the ring's does
// (handled inside the controller); a dark display wakes on any watch-
// 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 steps = repeatable ? Math.min(MAX_SCROLL_STEPS, Math.max(1, Math.round(readNumber(payload.steps, 1)))) : 1;
for (let i = 0; i < steps; i++) {
await this.host.injectInput(kind);
}
ack(true);
}
private async handleCommand(payload: Record<string, unknown>, ack: (ok: boolean, text?: string) => void): Promise<void> {
const command = String(payload.command ?? "");
if (!(COMMANDS as readonly string[]).includes(command)) {
ack(false, `Unknown command: ${command}`);
return;
}
const state = this.host.getState();
const connected = state.phase === "connected" || state.phase === "charging";
this.host.appendLog(`watch: ${command}`);
switch (command as WearCommand) {
case "connect":
if (connected) {
ack(true, "Already connected.");
return;
}
ack(true, "Connecting...");
await this.host.connect();
return;
case "disconnect":
if (!connected && state.phase === "disconnected") {
ack(true, "Already disconnected.");
return;
}
ack(true, "Disconnecting...");
await this.host.disconnect();
return;
default:
break;
}
if (!connected) {
ack(false, "The glasses are not connected.");
return;
}
if (state.glassesLocked && command !== "unlock" && command !== "lock") {
ack(false, "The glasses are locked.");
return;
}
switch (command as WearCommand) {
case "launch-app": {
const appId = String(payload.appId ?? "").trim();
const app = this.listApps().find((entry) => entry.appId === appId);
if (!app) {
ack(false, `Unknown app: ${appId}`);
return;
}
shell.wake("window");
await this.host.launchApp(appId);
this.schedulePublish();
ack(true, `Opened ${app.title}.`);
return;
}
case "focus-window": {
const windowId = String(payload.windowId ?? "").trim();
const window = shell.getWindows().find((entry) => entry.windowId === windowId);
if (!window) {
ack(false, "That window is no longer open.");
return;
}
shell.wake("window");
shell.focusWindow(windowId);
this.host.requestShellRender();
this.schedulePublish();
ack(true);
return;
}
case "close-window": {
const windowId = String(payload.windowId ?? "").trim();
const window = shell.getWindows().find((entry) => entry.windowId === windowId);
if (!window) {
ack(false, "That window is no longer open.");
return;
}
if (!window.closeable) {
ack(false, `${window.title} cannot be closed.`);
return;
}
shell.closeWindow(windowId);
this.host.requestShellRender();
this.schedulePublish();
ack(true, `Closed ${window.title}.`);
return;
}
case "sidebar":
shell.wake("sidebar");
shell.yieldFocusToSidebar();
this.host.requestShellRender();
ack(true);
return;
case "wake":
if (!shell.wake("sidebar")) {
ack(true, "The display is already on.");
return;
}
this.host.requestShellRender();
ack(true);
return;
case "sleep":
if (!shell.isScreenOn()) {
ack(true, "The display is already off.");
return;
}
shell.sleep();
ack(true);
return;
case "lock":
this.host.setGlassesLocked(true, "locked from the watch");
this.schedulePublish();
ack(true);
return;
case "unlock":
if (!watchCanUnlockSetting.get()) {
ack(false, "Unlocking from the watch is turned off in Settings > Watch.");
return;
}
this.host.setGlassesLocked(false, "unlocked from the watch");
this.schedulePublish();
ack(true);
return;
case "close-assistant":
shell.closeAssistant();
ack(true);
return;
case "display-mode": {
const value = String(payload.value ?? "");
if (!(DISPLAY_MODE_VALUES as readonly string[]).includes(value)) {
ack(false, `Unknown display mode: ${value}`);
return;
}
displayModeSetting.set(value as (typeof DISPLAY_MODE_VALUES)[number]);
this.schedulePublish();
ack(true, `Display mode: ${value}`);
return;
}
default:
ack(false, `Unhandled command: ${command}`);
}
}
private forwardAssistantActivity(event: AssistantActivityEvent): void {
if (!watchMirrorAssistantSetting.get()) return;
if (event.phase === "streaming") {
// Coalesce: the newest text wins, sent no more often than the interval.
this.assistantPendingText = event.text;
if (this.assistantStreamTimer) return;
const wait = Math.max(0, ASSISTANT_STREAM_MIN_INTERVAL_MS - (Date.now() - this.lastAssistantSentAtMs));
this.assistantStreamTimer = setTimeout(() => {
this.assistantStreamTimer = null;
if (this.assistantPendingText === null) return;
this.sendAssistantEvent("streaming", this.assistantPendingText);
this.assistantPendingText = null;
}, wait);
return;
}
// A phase change supersedes any queued stream snapshot.
if (this.assistantStreamTimer) {
clearTimeout(this.assistantStreamTimer);
this.assistantStreamTimer = null;
}
this.assistantPendingText = null;
this.sendAssistantEvent(event.phase, event.text);
this.schedulePublish();
}
private sendAssistantEvent(phase: AssistantActivityEvent["phase"], text: string): void {
this.lastAssistantSentAtMs = Date.now();
wearBridge.sendEvent({ type: "assistant", phase, text });
}
}
function readNumber(value: unknown, fallback: number): number {
const numeric = typeof value === "number" ? value : Number(value);
return Number.isFinite(numeric) ? numeric : fallback;
}
function readText(value: unknown): string {
const text = typeof value === "string" ? value : "";
return text.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f]/g, "").trim().slice(0, MAX_TEXT_LENGTH);
}
function formatError(error: unknown): string {
return (error as Error)?.message ?? String(error);
}
+14
View File
@@ -533,6 +533,20 @@ export class GrayImage {
return baked;
}
/**
* Place this image into target at (dx, dy): raster via bitBlt, deferred
* draws carried over as deferred draws (translated), so firmware-text runs
* and cached glyphs stay on their cheap wire paths instead of being baked
* to raster. The composed-in draws render above target's earlier raster,
* matching the usual draw-above-own-raster rule.
*/
composeInto(target: GrayImage, dx: number, dy: number): void {
target.bitBlt(this, dx, dy);
for (const placed of this.drawList) {
target.drawList.push({ ...placed, x: placed.x + dx, y: placed.y + dy });
}
}
/** Rasterize this image's deferred draws into target, translated by (dx, dy). */
bakeDrawsInto(target: GrayImage, dx: number, dy: number): void {
for (const placed of this.drawList) {
+12
View File
@@ -89,6 +89,18 @@ export type RawInputEvent =
systemExitReasonCode: number;
frameId: number;
}
| {
/**
* Synthetic directional gesture from the Wear OS remote; `eventType` is
* a WatchGestureType (app/g2/events.ts). Never produced by Java.
*/
kind: "watch-gesture";
containerName: string;
eventType: number;
eventSource: number;
systemExitReasonCode: number;
frameId: number;
}
| {
/**
* Stock display-lifecycle wake observed after a ring or arm double tap
+178
View File
@@ -0,0 +1,178 @@
/**
* TS wrapper for the Java FaceclawWearBridge: the phone side of the Wear OS
* watch remote. Inbound watch messages arrive as (path, JSON) pairs on the
* main isolate's thread; outbound calls publish dashboard state and send
* messages to the watch. The semantic mapping (what a watch "click" does)
* lives in app/g2/wear-remote.ts; this file only crosses the Java boundary.
*
* Every call is a no-op when Google Play services is missing (the Wearable
* Data Layer is part of it), so the rest of the app never has to care.
*/
import { Utils } from "@nativescript/core";
declare const com: any;
/** Message paths shared with the watch app (wear/app/.../Protocol.kt). */
export const WEAR_PATHS = {
/** Watch -> phone: a ring-style gesture. */
input: "/faceclaw/input",
/** Watch -> phone: a shell command (launch app, wake, lock, ...). */
command: "/faceclaw/command",
/** Watch -> phone: a text query for the assistant. */
assistant: "/faceclaw/assistant",
/** Watch -> phone: text to type into the foreground app. */
text: "/faceclaw/text",
/** Watch -> phone: please re-publish the state item. */
stateRequest: "/faceclaw/state/request",
/** Phone -> watch: reply to any of the above. */
ack: "/faceclaw/ack",
/** Phone -> watch: assistant activity, alerts, voice-dialog transcripts. */
event: "/faceclaw/event",
/** Phone -> watch Data Layer item: the mirrored dashboard state. */
state: "/faceclaw/state",
} as const;
export type WearMessage = {
path: string;
/** Parsed JSON payload ({} when the watch sent none or it was malformed). */
payload: Record<string, unknown>;
nodeId: string;
};
export type WearWatchConnection = {
reachable: boolean;
watchName: string;
};
type MessageListener = (message: WearMessage) => void;
type ConnectionListener = (connection: WearWatchConnection) => void;
class WearBridge {
private java: any | null | undefined = undefined;
// The Java-side listener proxy must stay referenced or it gets GC'd.
private retainedListenerProxy: any = null;
private readonly messageListeners = new Set<MessageListener>();
private readonly connectionListeners = new Set<ConnectionListener>();
private lastConnection: WearWatchConnection = { reachable: false, watchName: "" };
private getJava(): any | null {
if (this.java !== undefined) return this.java;
if (!global.isAndroid) {
this.java = null;
return null;
}
try {
const context = Utils.android.getApplicationContext();
const bridge = context ? com.faceclaw.app.FaceclawWearBridge.getInstance(context) : null;
this.java = bridge && bridge.isAvailable() ? bridge : null;
} catch (error) {
console.warn("wear bridge unavailable", error);
this.java = null;
}
return this.java;
}
/** Whether the Wearable Data Layer exists on this phone (Play services). */
isAvailable(): boolean {
return this.getJava() !== null;
}
private ensureListener(): void {
if (this.retainedListenerProxy) return;
const java = this.getJava();
if (!java) return;
this.retainedListenerProxy = new com.faceclaw.app.FaceclawWearListener({
onMessage: (path: string, json: string, nodeId: string) => {
const message: WearMessage = {
path: String(path),
payload: parsePayload(String(json)),
nodeId: String(nodeId),
};
for (const listener of Array.from(this.messageListeners)) {
try {
listener(message);
} catch (error) {
console.warn("wear message listener failed", error);
}
}
},
onWatchConnection: (reachable: boolean, watchName: string) => {
this.lastConnection = { reachable: Boolean(reachable), watchName: String(watchName ?? "") };
for (const listener of Array.from(this.connectionListeners)) {
try {
listener(this.lastConnection);
} catch (error) {
console.warn("wear connection listener failed", error);
}
}
},
});
java.setListener(this.retainedListenerProxy);
}
/** Subscribe to watch messages. Registers the Java listener on first use. */
onMessage(listener: MessageListener): () => void {
this.messageListeners.add(listener);
this.ensureListener();
return () => {
this.messageListeners.delete(listener);
};
}
/** Subscribe to watch reachability; the current value is delivered immediately. */
onWatchConnection(listener: ConnectionListener): () => void {
this.connectionListeners.add(listener);
this.ensureListener();
listener(this.getWatchConnection());
return () => {
this.connectionListeners.delete(listener);
};
}
getWatchConnection(): WearWatchConnection {
const java = this.getJava();
if (!java) return { reachable: false, watchName: "" };
try {
return {
reachable: Boolean(java.isWatchReachable()),
watchName: String(java.getWatchName() ?? ""),
};
} catch {
return this.lastConnection;
}
}
/** Re-query reachable watches (e.g. when the phone UI wants a fresh answer). */
refreshWatchNodes(): void {
this.getJava()?.refreshWatchNodes();
}
/**
* Mirror the dashboard state to the watch. Unchanged states are dropped on
* the Java side unless `force` (a watch explicitly asked for a refresh).
*/
publishState(state: Record<string, unknown>, force = false): void {
this.getJava()?.publishState(JSON.stringify(state), force);
}
/** Send an event to every reachable watch. */
sendEvent(payload: Record<string, unknown>): void {
this.getJava()?.sendToWatch(WEAR_PATHS.event, JSON.stringify(payload));
}
/** Acknowledge a watch message; `seq` echoes the watch's sequence number. */
sendAck(nodeId: string, seq: number, ok: boolean, message = ""): void {
this.getJava()?.sendAck(nodeId, seq, ok, true, message);
}
}
function parsePayload(json: string): Record<string, unknown> {
try {
const parsed = JSON.parse(json);
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
} catch {
return {};
}
}
export const wearBridge = new WearBridge();
+8 -20
View File
@@ -1,4 +1,4 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" loaded="loaded" unloaded="unloaded">
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:rc="phone-ui" navigatingTo="navigatingTo" loaded="loaded" unloaded="unloaded">
<ActionBar title="Faceclaw">
<ActionItem text="{{ buttonLabel }}" tap="{{ onTap }}" isEnabled="{{ canRun }}" android.position="popup" />
<ActionItem text="Configure devices" tap="{{ onConfigureTap }}" isEnabled="{{ canRun }}" android.position="popup" />
@@ -11,7 +11,8 @@
<GridLayout>
<GridLayout rows="auto,*" visibility="{{ portraitLayoutVisibility }}">
<StackLayout row="0" visibility="{{ displayPreviewVisibility }}">
<Image src="{{ displayPreview }}" stretch="fill" height="{{ displayPreviewHeight }}" />
<Image src="{{ displayPreview }}" stretch="fill" height="{{ displayPreviewHeight }}"
tap="{{ onMirrorTap }}" doubleTap="{{ onMirrorDoubleTap }}" longPress="{{ onMirrorLongPress }}" swipe="{{ onMirrorSwipe }}" />
</StackLayout>
<GridLayout
row="0"
@@ -36,14 +37,7 @@
</StackLayout>
</StackLayout>
<StackLayout row="1">
<GridLayout rows="auto,auto,auto" columns="*,*,*" class="m-t-8">
<Button row="0" col="1" text="Swipe up" tap="{{ onSyntheticUpTap }}" />
<Button row="1" col="0" text="Double-click" tap="{{ onSyntheticLeftTap }}" />
<Button row="1" col="1" text="Long press" tap="{{ onSyntheticLongPressTap }}" />
<Button row="1" col="2" text="Click" tap="{{ onSyntheticRightTap }}" />
<Button row="0" col="2" text="Microphone" tap="{{ onSyntheticMicTap }}" />
<Button row="2" col="1" text="Swipe down" tap="{{ onSyntheticDownTap }}" />
</GridLayout>
<rc:remote-controls />
<Button text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
</StackLayout>
<Label row="2" text="{{ status }}" class="m-t-16" textWrap="true" />
@@ -65,13 +59,14 @@
<Button text="Allow unrestricted background usage" tap="{{ onAllowBackgroundUsageTap }}" class="-primary" />
</StackLayout>
</StackLayout>
<GridLayout row="1" rows="auto,auto,*" columns="*,260">
<GridLayout row="1" rows="auto,auto,*" columns="*,360">
<StackLayout row="0" col="0" visibility="{{ displayPreviewVisibility }}" horizontalAlignment="left">
<Image
src="{{ displayPreview }}"
stretch="fill"
width="{{ landscapeDisplayPreviewWidth }}"
height="{{ landscapeDisplayPreviewHeight }}" />
height="{{ landscapeDisplayPreviewHeight }}"
tap="{{ onMirrorTap }}" doubleTap="{{ onMirrorDoubleTap }}" longPress="{{ onMirrorLongPress }}" swipe="{{ onMirrorSwipe }}" />
</StackLayout>
<GridLayout
row="0"
@@ -84,14 +79,7 @@
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
</GridLayout>
<StackLayout row="0" col="1" class="m-l-16">
<GridLayout rows="auto,auto,auto" columns="*,*,*">
<Button row="0" col="1" text="Swipe up" tap="{{ onSyntheticUpTap }}" />
<Button row="1" col="0" text="Double-click" tap="{{ onSyntheticLeftTap }}" />
<Button row="1" col="1" text="Long press" tap="{{ onSyntheticLongPressTap }}" />
<Button row="1" col="2" text="Click" tap="{{ onSyntheticRightTap }}" />
<Button row="0" col="2" text="Microphone" tap="{{ onSyntheticMicTap }}" />
<Button row="2" col="1" text="Swipe down" tap="{{ onSyntheticDownTap }}" />
</GridLayout>
<rc:remote-controls />
<Button text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
</StackLayout>
<Label row="1" col="0" colSpan="2" text="{{ status }}" class="m-t-16" textWrap="true" />
+258 -2
View File
@@ -1,5 +1,28 @@
import { Application, Frame, ImageSource, Observable, Screen } from "@nativescript/core";
import { dashboardController } from "../g2/dashboard-controller";
import {
Application,
Dialogs,
Frame,
ImageSource,
Observable,
Screen,
SwipeDirection,
type GestureEventData,
type SwipeGestureEventData,
type TouchGestureEventData,
type View,
} from "@nativescript/core";
import { dashboardController, type MirrorTouchKind } from "../g2/dashboard-controller";
import { shell } from "../ui/shell/shell";
import {
brightnessSetting,
DISPLAY_MODE_VALUES,
displayModeLabel,
displayModeSetting,
onAnySettingChanged,
type BrightnessSetting,
type DisplayModeSetting,
} from "../ui/dashboard-settings";
import { getBooleanSetting, setBooleanSetting } from "../native/settings-store";
import { isValidMacAddress, loadDeviceAddresses } from "../g2/device-addresses";
import { isAutoReconnectSuppressed } from "../g2/reconnect-policy";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../graphics/image";
@@ -55,7 +78,10 @@ export class MainViewModel extends Observable {
this.firmwareWarningVisible = snapshot.firmwareWarningVisible;
this.screenRecordingActive = snapshot.screenRecordingActive;
this.batteryOptimizationWarningVisible = snapshot.batteryOptimizationWarningVisible;
this.refreshPadFocusLine();
});
// Brightness / display mode can change from the glasses' Settings app too.
onAnySettingChanged(() => this.refreshDisplayControls());
}
get status(): string {
@@ -601,6 +627,220 @@ export class MainViewModel extends Observable {
await dashboardController.injectSyntheticRingInput("wakeword");
}
// ---- the phone's own controller: touchpad, d-pad, mirror touch ----
//
// Everything here is the watch scheme (origin "watch"): spatial swipes,
// tap = select, double-tap / two fingers = back, hold = menu. The ring row
// above stays on the ring's own scheme.
private padPointers = 0;
private padTwoFingerDown = false;
/** What the next gesture lands on, as the watch pad shows it. */
get padFocusLine(): string {
if (this.phase !== "connected" && this.phase !== "charging") return "Glasses disconnected";
if (!shell.isScreenOn()) return "Display off";
const foreground = shell.getForegroundApp();
return foreground ? foreground.title : "Launcher";
}
private refreshPadFocusLine(): void {
this.notifyPropertyChange("padFocusLine", this.padFocusLine);
}
async onPadTap(): Promise<void> {
if (this.padTwoFingerDown) return;
await dashboardController.injectSyntheticRingInput("click", "watch");
this.refreshPadFocusLine();
}
async onPadDoubleTap(): Promise<void> {
await dashboardController.injectSyntheticRingInput("double-click", "watch");
this.refreshPadFocusLine();
}
async onPadLongPress(): Promise<void> {
await dashboardController.injectSyntheticRingInput("long-press", "watch");
this.refreshPadFocusLine();
}
async onPadSwipe(args: SwipeGestureEventData): Promise<void> {
await dashboardController.injectSyntheticRingInput(swipeKind(args.direction), "watch");
this.refreshPadFocusLine();
}
/** Two fingers down and up without moving: back (the watch's two-finger tap). */
async onPadTouch(args: TouchGestureEventData): Promise<void> {
const count = args.getPointerCount();
if (args.action === "down" || args.action === "move") {
this.padPointers = Math.max(this.padPointers, count);
if (count >= 2) this.padTwoFingerDown = true;
return;
}
if (args.action === "up" || args.action === "cancel") {
const twoFinger = this.padTwoFingerDown;
this.padPointers = 0;
if (twoFinger) {
// Let the single-tap recognizer's delayed tap see the flag first.
setTimeout(() => {
this.padTwoFingerDown = false;
}, 400);
if (args.action === "up") {
await dashboardController.injectSyntheticRingInput("double-click", "watch");
this.refreshPadFocusLine();
}
}
}
}
async onDpadUp(): Promise<void> {
await dashboardController.injectSyntheticRingInput("swipe-up", "watch");
this.refreshPadFocusLine();
}
async onDpadDown(): Promise<void> {
await dashboardController.injectSyntheticRingInput("swipe-down", "watch");
this.refreshPadFocusLine();
}
async onDpadLeft(): Promise<void> {
await dashboardController.injectSyntheticRingInput("swipe-left", "watch");
this.refreshPadFocusLine();
}
async onDpadRight(): Promise<void> {
await dashboardController.injectSyntheticRingInput("swipe-right", "watch");
this.refreshPadFocusLine();
}
async onDpadSelect(): Promise<void> {
await dashboardController.injectSyntheticRingInput("click", "watch");
this.refreshPadFocusLine();
}
async onBackTap(): Promise<void> {
await dashboardController.injectSyntheticRingInput("double-click", "watch");
this.refreshPadFocusLine();
}
async onMenuTap(): Promise<void> {
await dashboardController.injectSyntheticRingInput("long-press", "watch");
this.refreshPadFocusLine();
}
// ---- touching the mirror itself ----
get mirrorTouchEnabled(): boolean {
return getBooleanSetting(MIRROR_TOUCH_KEY, true);
}
onMirrorTouchChange(args: { value?: boolean; object?: { checked?: boolean } }): void {
const on = typeof args.value === "boolean" ? args.value : Boolean(args.object?.checked);
setBooleanSetting(MIRROR_TOUCH_KEY, on);
this.notifyPropertyChange("mirrorTouchEnabled", on);
}
private mirrorFraction(args: GestureEventData & { getX?: () => number; getY?: () => number }): { nx: number; ny: number } | null {
const view = args.object as View | undefined;
const size = view?.getActualSize?.();
if (!view || !size || !size.width || !size.height || !args.getX || !args.getY) return null;
// On Android the gesture's getX/getY are screen-absolute (in DIPs), not
// view-local; the view's own screen position makes them local.
const origin = view.getLocationOnScreen?.() ?? { x: 0, y: 0 };
const localX = args.getX() - origin.x;
const localY = args.getY() - origin.y;
return { nx: localX / size.width, ny: localY / size.height };
}
private async mirrorGesture(kind: MirrorTouchKind, args: GestureEventData): Promise<void> {
if (!this.mirrorTouchEnabled) return;
const at = this.mirrorFraction(args) ?? { nx: 0.5, ny: 0.5 };
await dashboardController.handleMirrorTouch(kind, at.nx, at.ny);
this.refreshPadFocusLine();
}
onMirrorTap(args: GestureEventData): Promise<void> {
return this.mirrorGesture("tap", args);
}
onMirrorDoubleTap(args: GestureEventData): Promise<void> {
return this.mirrorGesture("double-tap", args);
}
onMirrorLongPress(args: GestureEventData): Promise<void> {
return this.mirrorGesture("long-press", args);
}
onMirrorSwipe(args: SwipeGestureEventData): Promise<void> {
return this.mirrorGesture(swipeKind(args.direction), args);
}
// ---- display mode and brightness, beside the mirror ----
get displayModeLabel(): string {
return displayModeLabel(displayModeSetting.get()) + " ▾";
}
async onDisplayModeTap(): Promise<void> {
const current = displayModeSetting.get();
const options = DISPLAY_MODE_VALUES.map((value) => displayModeLabel(value) + (value === current ? " ✓" : ""));
const picked = await Dialogs.action({ title: "Display mode", cancelButtonText: "Cancel", actions: options });
const index = options.indexOf(picked);
if (index < 0) return;
const value = DISPLAY_MODE_VALUES[index] as DisplayModeSetting;
if (value !== current) displayModeSetting.set(value);
this.notifyPropertyChange("displayModeLabel", this.displayModeLabel);
}
get brightnessAuto(): boolean {
return brightnessSetting.get() === "auto";
}
get brightnessSliderEnabled(): boolean {
return !this.brightnessAuto;
}
/** The slider's position; while Auto, the last manual level (or 50). */
get brightnessPercent(): number {
const value = brightnessSetting.get();
if (value === "auto") return this.lastManualBrightness;
const numeric = parseInt(value, 10);
return Number.isFinite(numeric) ? numeric : 50;
}
private lastManualBrightness = 50;
onBrightnessChange(args: { value?: number; object?: { value?: number } }): void {
if (this.brightnessAuto) return;
const raw = typeof args.value === "number" ? args.value : Number(args.object?.value ?? NaN);
if (!Number.isFinite(raw)) return;
// The setting only has every tenth level; snap to the nearest.
const level = Math.min(100, Math.max(0, Math.round(raw / 10) * 10));
this.lastManualBrightness = level;
const value = String(level) as BrightnessSetting;
if (brightnessSetting.get() !== value) brightnessSetting.set(value);
}
onBrightnessAutoChange(args: { value?: boolean; object?: { checked?: boolean } }): void {
const on = typeof args.value === "boolean" ? args.value : Boolean(args.object?.checked);
if (on) {
if (brightnessSetting.get() !== "auto") {
this.lastManualBrightness = this.brightnessPercent;
brightnessSetting.set("auto");
}
} else if (brightnessSetting.get() === "auto") {
brightnessSetting.set(String(this.lastManualBrightness) as BrightnessSetting);
}
this.refreshDisplayControls();
}
private refreshDisplayControls(): void {
this.notifyPropertyChange("brightnessAuto", this.brightnessAuto);
this.notifyPropertyChange("brightnessSliderEnabled", this.brightnessSliderEnabled);
this.notifyPropertyChange("brightnessPercent", this.brightnessPercent);
this.notifyPropertyChange("displayModeLabel", this.displayModeLabel);
}
private appendLog(line: string): void {
const stamp = new Date().toISOString().slice(11, 19);
this.log = this.log ? `${this.log}\n[${stamp}] ${line}` : `[${stamp}] ${line}`;
@@ -621,3 +861,19 @@ export class MainViewModel extends Observable {
return `${sanitized.slice(0, 237)}...`;
}
}
const MIRROR_TOUCH_KEY = "phone.mirrorTouch";
/** NativeScript swipe direction -> the watch-scheme directional gesture. */
function swipeKind(direction: SwipeDirection): "swipe-up" | "swipe-down" | "swipe-left" | "swipe-right" {
switch (direction) {
case SwipeDirection.up:
return "swipe-up";
case SwipeDirection.down:
return "swipe-down";
case SwipeDirection.left:
return "swipe-left";
default:
return "swipe-right";
}
}
+47
View File
@@ -0,0 +1,47 @@
<!--
The phone's controller for the glasses: the same scheme as the watch pad
(tap = select, double-tap or two fingers = back, hold = menu, swipes
navigate), a d-pad for the same four directions, the display-mode picker
and brightness beside the mirror, and a compact ring simulator for the R1's
own scheme. Used by main-page.xml in both orientations; binds to the page's
MainViewModel.
-->
<StackLayout xmlns="http://schemas.nativescript.org/tns.xsd" class="remote-controls">
<GridLayout columns="auto,*,auto" class="display-controls">
<Button col="0" text="{{ displayModeLabel }}" tap="{{ onDisplayModeTap }}" class="mode-button" />
<GridLayout col="1" columns="auto,*" verticalAlignment="center" class="brightness">
<Label col="0" text="☀" class="brightness-icon" verticalAlignment="center" />
<Slider col="1" width="100%" minValue="0" maxValue="100" value="{{ brightnessPercent }}" valueChange="{{ onBrightnessChange }}" isEnabled="{{ brightnessSliderEnabled }}" />
</GridLayout>
<StackLayout col="2" orientation="horizontal" verticalAlignment="center" class="auto-toggle">
<Label text="Auto" verticalAlignment="center" />
<Switch checked="{{ brightnessAuto }}" checkedChange="{{ onBrightnessAutoChange }}" />
</StackLayout>
</GridLayout>
<GridLayout class="touchpad" tap="{{ onPadTap }}" doubleTap="{{ onPadDoubleTap }}" longPress="{{ onPadLongPress }}" swipe="{{ onPadSwipe }}" touch="{{ onPadTouch }}">
<Label text="{{ padFocusLine }}" class="pad-focus" horizontalAlignment="center" verticalAlignment="center" />
<Label text="● select ●● back ‒ menu" class="pad-legend" horizontalAlignment="center" verticalAlignment="bottom" />
<Button text="▲" tap="{{ onDpadUp }}" class="pad-dpad-button" horizontalAlignment="center" verticalAlignment="top" />
<Button text="▼" tap="{{ onDpadDown }}" class="pad-dpad-button pad-dpad-down" horizontalAlignment="center" verticalAlignment="bottom" />
<Button text="◀" tap="{{ onDpadLeft }}" class="pad-dpad-button" horizontalAlignment="left" verticalAlignment="center" />
<Button text="▶" tap="{{ onDpadRight }}" class="pad-dpad-button" horizontalAlignment="right" verticalAlignment="center" />
</GridLayout>
<GridLayout columns="*,*,*" class="action-row">
<Button col="0" text="Back" tap="{{ onBackTap }}" class="action-button" />
<Button col="1" text="Menu" tap="{{ onMenuTap }}" class="action-button" />
<Button col="2" text="Hey Even" tap="{{ onSyntheticMicTap }}" class="action-button" />
</GridLayout>
<GridLayout columns="auto,*,*,*,*,*,auto,auto" class="ring-row">
<Label col="0" text="Ring" class="ring-label" verticalAlignment="center" />
<Button col="1" text="▲" tap="{{ onSyntheticUpTap }}" class="ring-button" />
<Button col="2" text="▼" tap="{{ onSyntheticDownTap }}" class="ring-button" />
<Button col="3" text="●" tap="{{ onSyntheticRightTap }}" class="ring-button" />
<Button col="4" text="●●" tap="{{ onSyntheticLeftTap }}" class="ring-button" />
<Button col="5" text="‒" tap="{{ onSyntheticLongPressTap }}" class="ring-button" />
<Label col="6" text="Touch mirror" class="ring-label" verticalAlignment="center" />
<Switch col="7" checked="{{ mirrorTouchEnabled }}" checkedChange="{{ onMirrorTouchChange }}" />
</GridLayout>
</StackLayout>
+67
View File
@@ -223,6 +223,36 @@ export const timeFormatSetting = new ConfigSettingEnum<TimeFormat>({
description: "Whether the top-bar clock shows 24-hour or 12-hour time.",
});
/**
* How much of the 640x480 panel the UI uses. "576x288" is the stock band
* (sidebar + a 288px-tall window at the vertical position); "576x480" keeps
* the sidebar and gives every window the full height; "640x480" is the whole
* panel, with the sidebar an overlay that shows only while it has focus.
*/
export const DISPLAY_MODE_VALUES = ["576x288", "576x480", "640x480"] as const;
export type DisplayModeSetting = (typeof DISPLAY_MODE_VALUES)[number];
const DISPLAY_MODE_LABELS: Record<DisplayModeSetting, string> = {
"576x288": "Band · 576×288",
"576x480": "Tall · 576×480",
"640x480": "Full panel · 640×480",
};
export function displayModeLabel(value: DisplayModeSetting): string {
return DISPLAY_MODE_LABELS[value] ?? value;
}
export const displayModeSetting = new ConfigSettingEnum<DisplayModeSetting>({
id: "display-mode",
label: "Display mode",
storageKey: "display.mode",
defaultValue: "576x288",
values: DISPLAY_MODE_VALUES,
formatValue: displayModeLabel,
description:
"Band: the stock 576×288 window beside the sidebar. Tall: the sidebar plus full-height windows. Full panel: the whole 640×480 display; the sidebar overlays the app only while you are in it. Open apps reopen in the new size.",
});
export const brightnessSetting = new ConfigSettingEnum<BrightnessSetting>({
id: "brightness",
label: "Brightness",
@@ -252,6 +282,43 @@ export const lockScreenEnabledSetting = new ConfigSettingBoolean({
"Lock the glasses after they are taken off while the phone is locked. Unlocking the phone unlocks the glasses.",
});
// Wear OS watch remote (app/g2/wear-remote.ts, wear/). All three are read on
// every watch message, so a change applies immediately.
export const watchRemoteEnabledSetting = new ConfigSettingBoolean({
id: "watch-remote-enabled",
label: "Watch remote control",
storageKey: "watch.remoteEnabled",
defaultValue: true,
description:
"Accept input from the Faceclaw Wear OS app: spatial swipes, taps, holds, crown, voice queries and app commands. The ring's scheme is unaffected. Turn off to ignore the watch.",
});
export const watchCanUnlockSetting = new ConfigSettingBoolean({
id: "watch-can-unlock",
label: "Watch can unlock glasses",
storageKey: "watch.canUnlock",
defaultValue: true,
description:
"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({
id: "watch-wakes-display",
label: "Watch input wakes display",
storageKey: "watch.wakesDisplay",
defaultValue: true,
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.",
});
export const watchMirrorAssistantSetting = new ConfigSettingBoolean({
id: "watch-mirror-assistant",
label: "Mirror assistant to watch",
storageKey: "watch.mirrorAssistant",
defaultValue: true,
description: "Stream assistant replies and on-glasses alerts to the watch so they can be read from the wrist.",
});
export type VerticalPosition = "top" | "upper" | "middle" | "lower" | "bottom";
const VERTICAL_POSITION_LABELS: Record<VerticalPosition, string> = {
+39
View File
@@ -27,6 +27,7 @@ import {
assistantSkipConfirmationSetting,
batteryDisplayModeSetting,
brightnessSetting,
displayModeSetting,
elevenLabsApiKeySetting,
mapboxApiKeySetting,
openAiApiKeySetting,
@@ -48,7 +49,12 @@ import {
voiceProviderSetting,
screenTimeoutSetting,
wakeWordActionSetting,
watchCanUnlockSetting,
watchMirrorAssistantSetting,
watchRemoteEnabledSetting,
watchWakesDisplaySetting,
} from "../dashboard-settings";
import { wearBridge } from "../../native/wear-bridge";
import { SettingsPanelLayer, type SettingsSection } from "./settings-panel";
import { terminalFontPickerMenuItem, uiFontPickerMenuItem } from "../font-picker";
@@ -74,6 +80,8 @@ function settingsSections(): SettingsSection[] {
// Where min-height windows (and the sidebar) sit vertically on the
// screen; the dashboard controller repositions surfaces on change.
enumSettingMenuItem(verticalPositionSetting),
// Band / tall / full-panel; the dashboard controller reflows windows.
enumSettingMenuItem(displayModeSetting),
// Controls the top-bar battery indicators (icon vs percentage).
enumSettingMenuItem(batteryDisplayModeSetting),
// Controls the top-bar clock (24-hour vs 12-hour).
@@ -133,6 +141,18 @@ function settingsSections(): SettingsSection[] {
textSettingMenuItem(roamApiTokenSetting),
],
},
{
label: "Watch",
// Wear OS remote (wear/); the status line above the items says whether
// a watch running the companion app is currently reachable.
items: [
toggleSettingMenuItem(watchRemoteEnabledSetting),
toggleSettingMenuItem(watchWakesDisplaySetting),
toggleSettingMenuItem(watchCanUnlockSetting),
toggleSettingMenuItem(watchMirrorAssistantSetting),
],
renderDetail: renderWatchStatus,
},
{
label: "Developer",
items: [
@@ -260,6 +280,25 @@ function readBundledDoc(fileName: string): string {
}
}
function renderWatchStatus(args: { image: GrayImage; x: number; y: number; width: number }): number {
const { image, x, y, width } = args;
const font = getDefaultSmallFont();
let status: string;
if (!wearBridge.isAvailable()) {
status = "Google Play services is unavailable on this phone, so no watch can connect.";
} else {
const connection = wearBridge.getWatchConnection();
status = connection.reachable
? `Connected to ${connection.watchName || "a watch"}.`
: "No watch connected. Install the Faceclaw watch app (wear/ in the source tree) on a Wear OS watch paired with this phone.";
}
const lines = wrapText(font, status, width);
for (let i = 0; i < lines.length; i++) {
image.drawText(font, x, y + i * font.lineHeight, lines[i]!, 170);
}
return lines.length * font.lineHeight + 10;
}
function renderAbout(args: { image: GrayImage; x: number; y: number; width: number }): number {
const { image, x, y, width } = args;
const font = getDefaultSmallFont();
+13
View File
@@ -41,6 +41,9 @@ const NO_MENU = new MenuLayer(null, []);
* column, out to the sidebar). Third-level menus open as centered modals.
*/
export class SettingsPanelLayer implements Layer {
// Watch swipes map onto the two columns: right goes into a section's
// items, left comes back out (and out to the sidebar from the left column).
readonly acceptsDirectional = true;
private leftIndex = 0;
private rightIndex = 0;
private focus: "left" | "right" = "left";
@@ -185,14 +188,17 @@ export class SettingsPanelLayer implements Layer {
if (this.focus === "left") {
switch (event.type) {
case "scroll-up":
case "swipe-up":
this.leftIndex = (this.leftIndex + this.sections.length - 1) % this.sections.length;
this.resetRight();
return;
case "scroll-down":
case "swipe-down":
this.leftIndex = (this.leftIndex + 1) % this.sections.length;
this.resetRight();
return;
case "click":
case "swipe-right":
// Only enter sections that have something interactive on the right.
if (this.section().items.length) {
this.focus = "right";
@@ -200,6 +206,7 @@ export class SettingsPanelLayer implements Layer {
}
return;
case "double-click":
case "swipe-left":
shell.yieldFocusToSidebar();
return;
default:
@@ -210,18 +217,22 @@ export class SettingsPanelLayer implements Layer {
const items = this.section().items;
switch (event.type) {
case "scroll-up":
case "swipe-up":
if (items.length) this.rightIndex = (this.rightIndex + items.length - 1) % items.length;
return;
case "scroll-down":
case "swipe-down":
if (items.length) this.rightIndex = (this.rightIndex + 1) % items.length;
return;
case "click":
case "swipe-right":
if (items.length) {
const item = items[clamp(this.rightIndex, 0, items.length - 1)]!;
if (!isMenuItemDisabled(item)) await item.onSelect(ctx, NO_MENU);
}
return;
case "double-click":
case "swipe-left":
this.focus = "left";
return;
default:
@@ -242,6 +253,8 @@ export class SettingsPanelLayer implements Layer {
* layers (modal menus, the text editor) stack above it as before.
*/
export class SettingsDescriptionOverlayLayer implements Layer {
readonly acceptsDirectional = true;
constructor(private readonly panel: SettingsPanelLayer) {}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
+88 -7
View File
@@ -3,13 +3,35 @@ import { type Plane } from "../graphics/plane";
import { spanCurrent } from "../native/frame-timings";
import { type ConfigSettingString } from "./dashboard-settings";
/**
* Where an input came from. The ring and the glasses' arms are the stock
* sources; "watch" is the Wear OS remote, which components may treat with a
* richer scheme (see isWatchInput) — the ring's semantics are never changed
* by it.
*/
export type InputSource = "ring" | "left-arm" | "right-arm" | "watch";
export type DashboardInputEvent =
| { type: "click"; source: "ring" | "left-arm" | "right-arm" }
| { type: "double-click"; source: "ring" | "left-arm" | "right-arm" }
| { type: "scroll-up" }
| { type: "scroll-down" }
| { type: "long-press"; source: "ring" | "left-arm" | "right-arm" }
| { type: "long-press-release"; source: "ring" | "left-arm" | "right-arm" }
| { type: "click"; source: InputSource }
| { type: "double-click"; source: InputSource }
/** Ring scroll (or a watch crown turn, then tagged source "watch"). */
| { type: "scroll-up"; source?: InputSource }
| { type: "scroll-down"; source?: InputSource }
| { type: "long-press"; source: InputSource }
| { type: "long-press-release"; source: InputSource }
/**
* Spatial (four-way) input, which only a watch can produce: the ring's
* scroll is a one-dimensional cursor, these are directions. Components with
* a spatial meaning for them opt in with Layer.acceptsDirectional /
* ShellWindow.acceptsDirectional and must then handle all four; for the
* rest, directionalFallback turns up/down into scroll, right into "select"
* (click) and left into "back" (double-click), so a swipe always does
* something sensible.
*/
| { type: "swipe-up"; source: "watch" }
| { type: "swipe-down"; source: "watch" }
| { type: "swipe-left"; source: "watch" }
| { type: "swipe-right"; source: "watch" }
/**
* The stock display lifecycle woke while no EvenHub page was running. This
* is wake-only, unlike a normal double-click (which turns an on screen off).
@@ -24,6 +46,44 @@ export type DashboardInputEvent =
| { type: "wakeword" }
| { type: "unknown"; kind: string; eventSource: number; eventType: number };
/** True for input from the Wear OS remote (any type that carries a source). */
export function isWatchInput(event: DashboardInputEvent): boolean {
return "source" in event && event.source === "watch";
}
export type DirectionalInputEvent = Extract<
DashboardInputEvent,
{ type: "swipe-up" | "swipe-down" | "swipe-left" | "swipe-right" }
>;
export function isDirectionalInput(event: DashboardInputEvent): event is DirectionalInputEvent {
return (
event.type === "swipe-up" ||
event.type === "swipe-down" ||
event.type === "swipe-left" ||
event.type === "swipe-right"
);
}
/**
* The ring-vocabulary equivalent of a directional swipe: up/down scroll,
* right selects, left backs out.
*/
export function directionalFallback(event: DashboardInputEvent): DashboardInputEvent {
switch (event.type) {
case "swipe-up":
return { type: "scroll-up" };
case "swipe-down":
return { type: "scroll-down" };
case "swipe-right":
return { type: "click", source: "ring" };
case "swipe-left":
return { type: "double-click", source: "ring" };
default:
return event;
}
}
export type LayerActions = {
/** Ask for a dashboard repaint+transmit, e.g. when async data arrives. */
requestRender: () => void;
@@ -96,6 +156,17 @@ export interface Layer {
readonly paintOverBase?: boolean;
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage;
handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> | void;
/**
* True when handleInput gives swipe-left / swipe-right a meaning of its own.
* Otherwise the stack hands the layer directionalFallback(event) instead.
*/
readonly acceptsDirectional?: boolean;
/**
* A touch at (x, y) in this layer's own canvas coordinates, from the phone's
* mirror view. Return true if the layer acted on it (selected / opened what
* is there); false sends a plain select (click) instead.
*/
hitTest?(x: number, y: number, ctx: LayerContext): Promise<boolean> | boolean;
/** Called when the layer leaves the stack by any path (pop or clearToBase). */
onRemoved?(): void;
/**
@@ -195,7 +266,17 @@ export class LayerStack {
}
async handleInput(event: DashboardInputEvent): Promise<void> {
await this.layers[this.layers.length - 1]!.handleInput(event, this.ctx);
const top = this.layers[this.layers.length - 1]!;
const delivered = isDirectionalInput(event) && !top.acceptsDirectional ? directionalFallback(event) : event;
await top.handleInput(delivered, this.ctx);
}
/** Pass a mirror touch to the base layer when nothing is stacked on it. */
async hitTest(x: number, y: number): Promise<boolean> {
if (this.layers.length !== 1) return false;
const base = this.layers[0]!;
if (!base.hitTest) return false;
return await base.hitTest(x, y, this.ctx);
}
/** Hand text to the top layer; false if it doesn't take text input. */
+36 -4
View File
@@ -13,6 +13,7 @@ import {
minWindowTop,
SHELL_OPAQUE_BLACK,
SIDEBAR_WIDTH,
sidebarWidth,
TOP_BAR_HEIGHT,
windowTop,
type WindowHeightMode,
@@ -166,7 +167,11 @@ export class ShellChromeLayer implements Layer {
paint(): GrayImage {
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const state = this.getState();
this.drawSidebar(image, state);
// Full-panel mode: the strip is an overlay, present only while the user
// is in it (the window underneath keeps its full width the rest of the time).
if (sidebarWidth() > 0 || state.focus === "sidebar") {
this.drawSidebar(image, state);
}
this.drawTopBar(image, state);
return image;
}
@@ -176,6 +181,30 @@ export class ShellChromeLayer implements Layer {
// layer stack; the chrome itself never consumes events.
}
/**
* Which window's sidebar icon is under (x, y) on screen, if any — the same
* slot geometry drawSidebar uses, so a touch on the phone's mirror lands on
* the icon the mirror showed.
*/
windowIndexAt(x: number, y: number, windowCount: number): number | null {
if (x < 0 || x >= SIDEBAR_WIDTH || windowCount === 0) return null;
const variant = sidebarVariant(windowCount);
const rows = rowsPerColumn(variant);
const listTop = minWindowTop() + TOP_BAR_HEIGHT + LIST_MARGIN;
const itemStride = variant.iconSize + ICON_SPACING;
const lastVisible = Math.min(windowCount, this.scrollRow + rows * variant.columns);
for (let index = this.scrollRow; index < lastVisible; index++) {
const position = index - this.scrollRow;
const column = variant.columns - 1 - ((position / rows) | 0);
const slotY = listTop + (position % rows) * itemStride;
const left = columnLeft(variant, column);
if (x >= left && x < left + variant.columnWidth && y >= slotY - 2 && y < slotY + variant.iconSize + 2) {
return index;
}
}
return null;
}
private drawSidebar(image: GrayImage, state: ShellChromeState): void {
// The sidebar always occupies the min-height window band at the preferred
// vertical position: it never moves when the foreground window's height
@@ -266,13 +295,16 @@ export class ShellChromeLayer implements Layer {
// its height mode puts that (screen top for max height). It moves when
// the foreground switches to a window of a different height.
const barTop = windowTop(state.foregroundHeightMode);
image.fillRect(SIDEBAR_WIDTH, barTop, G2_LENS_WIDTH - SIDEBAR_WIDTH, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK);
image.drawLine(SIDEBAR_WIDTH, barTop + TOP_BAR_HEIGHT - 1, G2_LENS_WIDTH - 1, barTop + TOP_BAR_HEIGHT - 1, BORDER_VALUE);
// The bar spans the app viewport; with the sidebar overlaid (full-panel
// mode, sidebar focused) it still starts past the strip.
const barLeft = sidebarWidth() > 0 || state.focus === "sidebar" ? SIDEBAR_WIDTH : 0;
image.fillRect(barLeft, barTop, G2_LENS_WIDTH - barLeft, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK);
image.drawLine(barLeft, barTop + TOP_BAR_HEIGHT - 1, G2_LENS_WIDTH - 1, barTop + TOP_BAR_HEIGHT - 1, BORDER_VALUE);
const now = new Date();
const clock = `${WEEKDAYS[now.getDay()]} ${now.getDate()} ${MONTHS[now.getMonth()]} ` +
formatClockTime(now);
const clockX = SIDEBAR_WIDTH + 10;
const clockX = barLeft + 10;
const textY = barTop + Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0);
image.drawText(font, clockX, textY, clock, 210);
+32 -8
View File
@@ -1,15 +1,39 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../../graphics/image";
import { verticalPositionSetting } from "../dashboard-settings";
import { displayModeSetting, type DisplayModeSetting, verticalPositionSetting } from "../dashboard-settings";
/** Top bar: 24px notification icons plus a little padding. */
export const TOP_BAR_HEIGHT = 28;
/**
* Sidebar width. Leaves the app viewport exactly 576px wide — the surface
* width EvenHub apps expect. Icon column layout within the strip (one wide
* column vs. two narrow ones) is the chrome layer's business.
* Width of the sidebar strip as painted. Leaves the app viewport exactly
* 576px wide — the surface width EvenHub apps expect — except in the
* full-panel display mode, where the strip overlays the app (see
* sidebarWidth). Icon column layout within the strip (one wide column vs.
* two narrow ones) is the chrome layer's business.
*/
export const SIDEBAR_WIDTH = 64;
/** The Display > Display mode setting (see dashboard-settings.ts). */
export function displayMode(): DisplayModeSetting {
return displayModeSetting.get();
}
/**
* How much of the screen's width the sidebar takes away from app windows:
* the strip, or nothing in the full-panel mode (where the chrome paints the
* strip over the window while the sidebar has focus).
*/
export function sidebarWidth(): number {
return displayMode() === "640x480" ? 0 : SIDEBAR_WIDTH;
}
/**
* The height an app's requested mode actually gets: the band mode honours
* it, the taller modes give every window the whole screen.
*/
export function effectiveHeightMode(mode: WindowHeightMode): WindowHeightMode {
return displayMode() === "576x288" ? mode : "max";
}
/**
* X of the display's true horizontal centre, in app-viewport coordinates. The
* sidebar pushes the viewport to the right, so UI the wearer physically aims
@@ -17,7 +41,7 @@ export const SIDEBAR_WIDTH = 64;
* than use the viewport's own centre.
*/
export function screenCenterInViewportX(): number {
return Math.round(G2_LENS_WIDTH / 2) - SIDEBAR_WIDTH;
return Math.round(G2_LENS_WIDTH / 2) - sidebarWidth();
}
/**
@@ -43,7 +67,7 @@ export const MIN_WINDOW_MAX_TOP = G2_LENS_HEIGHT - MIN_WINDOW_HEIGHT;
/** Total height (top bar + content) of a window's band in the given mode. */
export function windowBandHeight(mode: WindowHeightMode): number {
switch (mode) {
switch (effectiveHeightMode(mode)) {
case "max":
return G2_LENS_HEIGHT;
case "medium":
@@ -89,7 +113,7 @@ export function windowTop(mode: WindowHeightMode): number {
/** App-content viewport size for a height mode (independent of vertical position). */
export function appViewportSize(mode: WindowHeightMode): { width: number; height: number } {
return {
width: G2_LENS_WIDTH - SIDEBAR_WIDTH,
width: G2_LENS_WIDTH - sidebarWidth(),
height: windowBandHeight(mode) - TOP_BAR_HEIGHT,
};
}
@@ -102,7 +126,7 @@ export function appViewportRect(mode: WindowHeightMode): {
height: number;
} {
return {
x: SIDEBAR_WIDTH,
x: sidebarWidth(),
y: windowTop(mode) + TOP_BAR_HEIGHT,
...appViewportSize(mode),
};
+22
View File
@@ -168,6 +168,9 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
title: options.title,
surfaceId: `window:${options.windowId}`,
closeable: options.closeable,
// The window's own LayerStack decides per layer whether a swipe is
// directional or falls back to click / double-click.
acceptsDirectional: true,
heightMode,
close: () => {
closed = true;
@@ -195,6 +198,16 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
await render(frameId);
},
requestRender,
relayout: () => {
stack.setBaseSize(appViewportSize(heightMode));
options.reconfigureSurface?.(heightMode);
requestRender();
},
hitTest: async (x, y) => {
const handled = await stack.hitTest(x, y);
if (handled) requestRender();
return handled;
},
receiveTextInput: options.receiveTextInput,
setForeground: (foreground) => {
options.setSurfaceVisible(foreground);
@@ -223,6 +236,15 @@ export class YieldAtRootLayer implements Layer {
return this.inner.paintOverBase;
}
/** Directional swipes reach the inner layer only if it understands them. */
get acceptsDirectional(): boolean | undefined {
return this.inner.acceptsDirectional;
}
hitTest(x: number, y: number, ctx: LayerContext): Promise<boolean> | boolean {
return this.inner.hitTest ? this.inner.hitTest(x, y, ctx) : false;
}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
return this.inner.paint(ctx, paintBelow);
}
+160 -17
View File
@@ -1,9 +1,20 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
import { singlePlane, type Plane } from "../../graphics/plane";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { EvenAIStatus, EventSourceType, OsEventTypeList } from "../../g2/events";
import { EvenAIStatus, EventSourceType, OsEventTypeList, WatchGestureType } from "../../g2/events";
import type { RawInputEvent } from "../../native/faceclaw-communicator";
import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, noopLayerActions } from "../layers";
import {
DashboardInputEvent,
directionalFallback,
type InputSource,
isDirectionalInput,
isWatchInput,
Layer,
LayerActions,
LayerContext,
LayerStack,
noopLayerActions,
} from "../layers";
import { MenuLayer, type MenuItem } from "../menu";
import { VoiceInputLayer, type VoiceSendTarget } from "./voice-input";
import { voiceActivity } from "./voice-activity";
@@ -62,6 +73,11 @@ export type ShellWindow = {
surfaceId: string;
/** Whether close menu entries (app menu default, shell escape menu) apply (the launcher is pinned). */
closeable: boolean;
/**
* True when the window gives swipe-left / swipe-right (watch directional
* input) a meaning; otherwise the shell forwards directionalFallback(event).
*/
acceptsDirectional?: boolean;
/**
* Window height: the standard 288px band ("min") or the full screen
* ("max", terminal views). Decides the surface rect and where the shell
@@ -79,6 +95,17 @@ export type ShellWindow = {
handleInput: (event: DashboardInputEvent, frameId: number) => Promise<void> | void;
/** Repaint and resubmit this window's surface. */
requestRender: () => void;
/**
* Re-measure against the current display mode (viewport size / band) and
* repaint. Windows without it (workers, whose canvas is fixed at open) are
* closed and relaunched by the controller instead.
*/
relayout?: () => void;
/**
* A touch from the phone's mirror at (x, y) in app-viewport coordinates.
* True if the window acted on it; otherwise the controller sends a select.
*/
hitTest?: (x: number, y: number) => Promise<boolean> | boolean;
/**
* Deliver a text string to the window (e.g. finalized voice input). Optional:
* only windows that consume typed text (the terminal) implement it.
@@ -104,7 +131,18 @@ export type ShellConfig = {
/** Which surfaces need re-rendering after an input event. */
export type ShellInputOutcome = { shell: boolean; window: boolean };
type FocusKind = "sidebar" | "window";
/**
* Assistant overlay activity, for mirrors outside the glasses (the watch).
* "streaming" carries the reply so far (replace semantics); "done" the final
* reply; "error" the message; "closed" fires when the overlay leaves the
* stack by any path.
*/
export type AssistantActivityEvent = {
phase: "thinking" | "streaming" | "done" | "error" | "closed";
text: string;
};
export type FocusKind = "sidebar" | "window";
const noopActions: LayerActions = noopLayerActions;
@@ -209,6 +247,8 @@ class Shell {
private activeVoiceLayer: VoiceInputLayer | null = null;
private assistantSession: AssistantSession | null = null;
private assistantLayer: AssistantLayer | null = null;
private readonly assistantActivityListeners = new Set<(event: AssistantActivityEvent) => void>();
private readonly alertListeners = new Set<(text: string) => void>();
private escapeMenuTimer: ReturnType<typeof setTimeout> | null = null;
private readonly actions: LayerActions = { ...noopActions };
private config: ShellConfig = {
@@ -217,10 +257,8 @@ class Shell {
requestShellRender: () => {},
onScreenStateChanged: () => {},
};
private readonly stack = new LayerStack(
new ShellChromeLayer(() => this.chromeState()),
this.actions,
);
private readonly chrome = new ShellChromeLayer(() => this.chromeState());
private readonly stack = new LayerStack(this.chrome, this.actions);
// Top-bar settings we mirror into the chrome; a change to either repaints
// the shell surface so the top bar reflects it immediately.
@@ -379,6 +417,22 @@ class Shell {
this.lastInputAtMs = nowMs;
}
/** Where input currently goes: the sidebar strip or the foreground window. */
getFocus(): FocusKind {
return this.focus;
}
/** True while a shell overlay (menu, dialog, voice input) is above the chrome. */
hasOverlay(): boolean {
return !this.stack.isAtBase();
}
/** The window whose sidebar icon is at screen (x, y), for mirror touches. */
windowAtSidebarPoint(x: number, y: number): ShellWindow | null {
const index = this.chrome.windowIndexAt(x, y, this.windows.length);
return index === null ? null : this.windows[index] ?? null;
}
/** Turn the screen on (if off) and set focus. Returns whether it was off. */
wake(focus: FocusKind, nowMs = Date.now()): boolean {
this.lastInputAtMs = nowMs;
@@ -572,7 +626,8 @@ class Shell {
const window = this.foregroundWindow();
if (window) {
// The window owns frameId from here (render or explicit finish).
await window.handleInput(event, frameId);
const delivered = isDirectionalInput(event) && !window.acceptsDirectional ? directionalFallback(event) : event;
await window.handleInput(delivered, frameId);
return { shell: false, window: true };
}
return { shell: false, window: false };
@@ -630,15 +685,25 @@ class Shell {
private handleSidebarInput(event: DashboardInputEvent): ShellInputOutcome {
switch (event.type) {
case "double-click":
// The ring's double-tap at the root turns the display off. For the
// watch, "back" at the root is simply the end of the road: it wakes
// the display on any gesture, so sleeping here would be a trap; the
// watch's Status screen turns the display off on purpose.
if (isWatchInput(event)) return { shell: false, window: false };
this.sleep();
return { shell: true, window: false };
case "scroll-up":
case "swipe-up":
this.moveSelection(-1);
return { shell: true, window: false };
case "scroll-down":
case "swipe-down":
this.moveSelection(1);
return { shell: true, window: false };
case "click":
case "swipe-right":
// Right: into the selected window (spatially, the window is to the
// sidebar's right). Left has nowhere further to go and is ignored.
if (this.windows.length) {
this.focus = "window";
// Repaint the window now so its selection highlight reflects focus
@@ -763,10 +828,41 @@ class Shell {
this.config.requestShellRender();
}
private isAssistantAvailable(): boolean {
isAssistantAvailable(): boolean {
return this.resolveAssistantConfiguration() !== null;
}
/** Observe assistant turns (see AssistantActivityEvent). */
onAssistantActivity(listener: (event: AssistantActivityEvent) => void): () => void {
this.assistantActivityListeners.add(listener);
return () => {
this.assistantActivityListeners.delete(listener);
};
}
/** Observe showAlert popups (mirrored to the watch). */
onAlertShown(listener: (text: string) => void): () => void {
this.alertListeners.add(listener);
return () => {
this.alertListeners.delete(listener);
};
}
private emitAssistantActivity(event: AssistantActivityEvent): void {
for (const listener of Array.from(this.assistantActivityListeners)) {
try {
listener(event);
} catch (error) {
console.warn("assistant activity listener failed", error);
}
}
}
/** Dismiss the assistant overlay (cancelling any in-flight turn), as Done would. */
closeAssistant(): void {
this.closeAssistantLayer();
}
private ensureAssistantSession(): AssistantSession | null {
const config = this.resolveAssistantConfiguration();
if (!config) return null;
@@ -834,6 +930,7 @@ class Shell {
// stop the turn and drop the reference so a later query starts clean.
this.assistantSession?.cancel();
if (this.assistantLayer === created) this.assistantLayer = null;
this.emitAssistantActivity({ phase: "closed", text: "" });
},
});
layer = created;
@@ -846,11 +943,23 @@ class Shell {
private runAssistantTurn(session: AssistantSession, layer: AssistantLayer, text: string): void {
layer.startTurn();
let replySoFar = "";
this.emitAssistantActivity({ phase: "thinking", text: "" });
session.sendUtterance(text, this.buildAssistantContext(), {
onTextDelta: (delta, textSoFar) => layer.onTextDelta(delta, textSoFar),
onTextDelta: (delta, textSoFar) => {
replySoFar = textSoFar;
layer.onTextDelta(delta, textSoFar);
this.emitAssistantActivity({ phase: "streaming", text: textSoFar });
},
onToolActivity: (label) => layer.onToolActivity(label),
onTurnDone: () => layer.onTurnDone(),
onError: (message) => layer.onError(message),
onTurnDone: () => {
layer.onTurnDone();
this.emitAssistantActivity({ phase: "done", text: replySoFar });
},
onError: (message) => {
layer.onError(message);
this.emitAssistantActivity({ phase: "error", text: message });
},
});
}
@@ -901,6 +1010,13 @@ class Shell {
/** Show a brief text popup on the lenses (assistant show_alert / notices). */
showAlert(text: string): void {
if (!this.screenOn) this.wake("sidebar");
for (const listener of Array.from(this.alertListeners)) {
try {
listener(text);
} catch (error) {
console.warn("alert listener failed", error);
}
}
const layer = new ShellAlertLayer(text, () => {
this.stack.popIfTop((top) => top === layer);
this.config.requestShellRender();
@@ -1024,9 +1140,9 @@ export function rawInputEventToInputEvent(event: RawInputEvent): DashboardInputE
source: eventSourceToString(event.eventSource),
};
} else if (event.eventType === OsEventTypeList.SCROLL_BOTTOM_EVENT) {
return { type: "scroll-down" };
return scrollEvent("scroll-down", event.eventSource);
} else if (event.eventType === OsEventTypeList.SCROLL_TOP_EVENT) {
return { type: "scroll-up" };
return scrollEvent("scroll-up", event.eventSource);
} else if (event.eventType === OsEventTypeList.RING_LONG_PRESS_EVENT) {
// CFW-forwarded long-press (replaces the firmware's force-quit dialog).
// The CFW gates this to the ring, so eventSource may be 0 (unknown);
@@ -1035,6 +1151,18 @@ export function rawInputEventToInputEvent(event: RawInputEvent): DashboardInputE
} else if (event.eventType === OsEventTypeList.RING_LONG_PRESS_RELEASE_EVENT) {
return { type: "long-press-release", source: eventSourceToString(event.eventSource) };
}
} else if (event.kind === "watch-gesture") {
// Synthetic, from the Wear OS remote (app/g2/wear-remote.ts); the glasses
// firmware never produces these.
if (event.eventType === WatchGestureType.SWIPE_LEFT) {
return { type: "swipe-left", source: "watch" };
} else if (event.eventType === WatchGestureType.SWIPE_RIGHT) {
return { type: "swipe-right", source: "watch" };
} else if (event.eventType === WatchGestureType.SWIPE_UP) {
return { type: "swipe-up", source: "watch" };
} else if (event.eventType === WatchGestureType.SWIPE_DOWN) {
return { type: "swipe-down", source: "watch" };
}
} else if (event.kind === "even-ai") {
// sid 0x07 EvenAIDataPackage; eventType carries eEvenAIStatus. Only the
// wakeword interests us -- ENTER means the user manually opened the stock
@@ -1048,9 +1176,9 @@ export function rawInputEventToInputEvent(event: RawInputEvent): DashboardInputE
return { type: "display-wake" };
} else if (event.kind === "text-click") {
if (event.eventType === OsEventTypeList.SCROLL_BOTTOM_EVENT) {
return { type: "scroll-down" };
return scrollEvent("scroll-down", event.eventSource);
} else if (event.eventType === OsEventTypeList.SCROLL_TOP_EVENT) {
return { type: "scroll-up" };
return scrollEvent("scroll-up", event.eventSource);
}
}
return {
@@ -1061,13 +1189,20 @@ export function rawInputEventToInputEvent(event: RawInputEvent): DashboardInputE
};
}
function eventSourceToString(eventSource: number): "ring" | "left-arm" | "right-arm" {
/** Scroll events only carry a source when it is the watch (the stock ones never needed one). */
function scrollEvent(type: "scroll-up" | "scroll-down", eventSource: number): DashboardInputEvent {
return eventSource === EventSourceType.TOUCH_EVENT_FROM_WATCH ? { type, source: "watch" } : { type };
}
function eventSourceToString(eventSource: number): InputSource {
if (eventSource === EventSourceType.TOUCH_EVENT_FROM_RING) {
return "ring";
} else if (eventSource === EventSourceType.TOUCH_EVENT_FROM_GLASSES_L) {
return "left-arm";
} else if (eventSource === EventSourceType.TOUCH_EVENT_FROM_GLASSES_R) {
return "right-arm";
} else if (eventSource === EventSourceType.TOUCH_EVENT_FROM_WATCH) {
return "watch";
}
return "ring";
}
@@ -1086,6 +1221,14 @@ export function inputEventToString(event: DashboardInputEvent): string {
return `Long press from ${event.source}`;
case "long-press-release":
return `Long press release from ${event.source}`;
case "swipe-left":
return `Swipe left from ${event.source}`;
case "swipe-right":
return `Swipe right from ${event.source}`;
case "swipe-up":
return `Swipe up from ${event.source}`;
case "swipe-down":
return `Swipe down from ${event.source}`;
case "display-wake":
return `Display wake`;
case "wakeword":
+6
View File
@@ -0,0 +1,6 @@
.gradle/
build/
local.properties
.idea/
*.iml
.kotlin/
+62
View File
@@ -0,0 +1,62 @@
# Watch ⇄ phone protocol
Transport: the Wearable Data Layer (Google Play services). Both apps share the
`com.faceclaw.app` application id and, for release builds, the signing key —
the Data Layer routes only between matching apps. Payloads are UTF-8 JSON
objects. Phone side: `App_Resources/.../FaceclawWearBridge.java` (transport),
`app/native/wear-bridge.ts` (JS wrapper), `app/g2/wear-remote.ts` (meaning).
Watch side: `app/src/main/kotlin/com/faceclaw/wear/Protocol.kt`, `PhoneLink.kt`.
Capabilities (`res/values/wear.xml` on each side): the phone advertises
`faceclaw_phone`, the watch `faceclaw_watch`. Each side finds the other with
`CapabilityClient.getCapability(…, FILTER_REACHABLE)`.
Every watch → phone message carries `seq` (monotonic per watch process) and is
answered on `/faceclaw/ack`.
## Watch → phone (MessageClient)
| 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/command` | `{command, …}` | `launch-app {appId}`, `focus-window {windowId}`, `close-window {windowId}`, `sidebar`, `wake`, `sleep`, `lock`, `unlock`, `connect`, `disconnect`, `close-assistant`. 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/text` | `{text}` | Type text into the foreground window (`receiveTextInput`, e.g. the terminal). Refused when the window doesn't take text. |
| `/faceclaw/state/request` | `{}` | Re-publish the state item even if unchanged. |
All of the above except `state/request` are refused with `ok:false` when the
phone's "Watch remote control" setting is off.
## Phone → watch
`/faceclaw/ack` (MessageClient, to the sender):
`{seq, ok, jsReady, message}`. `jsReady:false` means Play services started the
app process for the message but the JS dashboard isn't up (the user has not
opened Faceclaw since boot); the watch shows "Open Faceclaw on the phone".
`/faceclaw/event` (MessageClient, to every reachable watch):
- `{type:"assistant", phase, text}` — `phase` ∈ `thinking`, `streaming` (text so
far, replace semantics, ≤ 4/s), `done` (final text), `error` (message),
`closed` (overlay dismissed).
- `{type:"alert", text}` — a `glasses.show_alert` popup.
Both are gated by the phone's "Mirror assistant to watch" setting.
`/faceclaw/state` (DataClient item, keys `json` and `updatedAt`): the mirrored
dashboard state, re-sent whenever it changes (and at least every 30 s):
```json
{
"protocol": 1, "version": "…",
"phase": "connected", "status": "…", "connected": true,
"screenOn": true, "locked": false, "worn": true, "listening": false,
"battery": 78, "charging": false,
"foreground": {"appId": "music", "title": "Music"},
"windows": [{"windowId": "…", "title": "…", "appId": "…", "focused": true, "closeable": true, "acceptsText": false}],
"apps": [{"appId": "timer", "title": "Timer"}],
"remoteEnabled": true, "canUnlock": true, "mirrorAssistant": true,
"assistantAvailable": true
}
```
`apps` is the launcher grid plus installed EvenHub packages, i.e. exactly what
the assistant's `apps.launch` tool accepts.
+109
View File
@@ -0,0 +1,109 @@
# Faceclaw for Wear OS
A watch remote for Faceclaw: everything the Even R1 ring can do, plus the
things it can't. Runs on a Wear OS 3+ watch (API 30) paired with the phone
that runs Faceclaw. It is a remote, not a standalone app — without Faceclaw on
the phone it only tells you to install it.
## What it does
**The pad** (the home screen; the whole display is the touch surface):
| On the watch | On the glasses |
| --- | --- |
| tap | select |
| 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) |
| 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 |
| 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 |
| **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. |
| **Tap zones** mode | tap the top / bottom third to scroll, the middle to select — for when swiping is awkward |
The R1 ring's scheme is untouched: the ring only has up/down, tap, double-tap
and hold, so on the glasses it still works in the stock two-step way (pick a
launcher row, tap, pick the app). Watch input is tagged as its own source, so
the same screens give the watch the direct scheme above without the ring
ever seeing a difference.
**Side buttons** (when the app is in front): button 1 tap = select, hold =
long press; button 2 = back; button 3 = "Hey Even". You can also set
the watch's button shortcut to open Faceclaw.
**Bottom row buttons**: Assistant, Type into app, Apps, Status.
- **Assistant** — ask the assistant using the *watch's* microphone (system
speech recognition) or the Wear keyboard, and read the reply on the watch as
it streams, mirrored from the glasses overlay. The watch buzzes when the
reply finishes. "Hey Even" instead opens the glasses' own voice dialog, which
uses the glasses mic.
- **Type into app** — dictate or type text into the foreground app (the
terminal, for instance), the same path finalized voice input takes.
- **Apps** — the sidebar's open windows (tap to switch, × to close) and the
full launcher, including installed EvenHub apps.
- **Status** — connection and battery, display on/off, lock/unlock, connect /
disconnect, and whether Faceclaw is running on the phone; watch settings
(haptics, keep screen on, swipe direction, tap zones, horizontal swipe
actions, tip taps and their sensitivity, crown sensitivity).
The pad keeps the watch display awake while it is showing (Watch settings >
"Keep screen on", default on). Wear OS otherwise dozes within seconds of the
wrist dropping and freezes the app, so the remote would need a wake-up tap
before every gesture.
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 —
the ring only wakes it with a double-tap), forbid unlocking from the watch,
or stop mirroring assistant replies.
The watch buzzes differently when the phone refuses or doesn't answer a
gesture (glasses disconnected, locked, watch control off); the pill at the
bottom of the pad says why.
## Building and installing
The watch app is a separate Gradle project (Kotlin + Compose for Wear OS).
It needs the same Android SDK the phone build uses and a JDK 17+:
```bash
cd wear && JAVA_HOME=/path/to/jdk ANDROID_HOME=~/Library/Android/sdk ./gradlew :app:assembleDebug
```
The APK lands in `app/build/outputs/apk/debug/`. Install it on the watch over
adb (enable developer options on the watch, then ADB debugging and, for a
watch without USB, Wireless debugging / debug over Wi-Fi):
```bash
adb connect <watch-ip>:5555
adb -s <watch-ip>:5555 install -r app/build/outputs/apk/debug/app-debug.apk
```
Two things must match the phone app or the Data Layer silently won't route:
1. **Application id** `com.faceclaw.app` — already set in `app/build.gradle.kts`.
2. **Signing key.** Debug builds of both apps use the shared Android debug
keystore (`~/.android/debug.keystore`) on the machine that builds them, so
building both on the same computer just works. For release builds, sign the
watch APK with the same keystore as the phone APK.
There's no Play Store listing; sideload.
## Troubleshooting
- *"No phone connected"* — the watch has no Bluetooth link to any phone.
- *"Install Faceclaw on the phone"* — a phone is connected but no app there
advertises the `faceclaw_phone` capability: the phone build predates the
watch integration, or the app ids / signing keys differ.
- *"Open Faceclaw on the phone"* — the phone app is installed but its
dashboard isn't running (Play services started the process just for our
message). Open Faceclaw once; it keeps running with its foreground service
while connected to the glasses.
- *"The glasses are not connected"* — tap Status > Connect.
- Nothing happens and no message: check Settings > Watch on the phone.
Gestures the watch itself owns — the edge swipe-to-dismiss, the OS-level
double-pinch / "universal" gestures on some watches — are not available to
apps and aren't remapped here.
Protocol details: [PROTOCOL.md](PROTOCOL.md).
+67
View File
@@ -0,0 +1,67 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.compose")
}
android {
namespace = "com.faceclaw.wear"
compileSdk = 35
defaultConfig {
// Must equal the phone app's id (nativescript.config.ts): the Wearable
// Data Layer only routes between apps with the same package name and
// signing key.
applicationId = "com.faceclaw.app"
minSdk = 30
targetSdk = 35
versionCode = 1
versionName = "1.0.0"
}
buildTypes {
release {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
buildFeatures {
compose = true
buildConfig = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
}
dependencies {
val composeBom = platform("androidx.compose:compose-bom:2025.05.01")
implementation(composeBom)
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.foundation:foundation")
implementation("androidx.compose.runtime:runtime")
debugImplementation("androidx.compose.ui:ui-tooling")
implementation("androidx.wear.compose:compose-foundation:1.4.1")
implementation("androidx.wear.compose:compose-material:1.4.1")
implementation("androidx.wear.compose:compose-navigation:1.4.1")
implementation("androidx.activity:activity-compose:1.10.1")
implementation("androidx.core:core-ktx:1.16.0")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.9.2")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.9.2")
// RemoteInputIntentHelper: the system keyboard / voice / emoji text entry.
implementation("androidx.wear:wear-input:1.1.0")
implementation("com.google.android.gms:play-services-wearable:19.0.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.10.1")
}
+1
View File
@@ -0,0 +1 @@
# Nothing app-specific; Play services and Compose ship their own rules.
+35
View File
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-feature android:name="android.hardware.type.watch" />
<uses-permission android:name="android.permission.VIBRATE" />
<!-- Not standalone: the watch app is a remote for Faceclaw on the phone
and does nothing useful without it. -->
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Faceclaw">
<uses-library
android:name="com.google.android.wearable"
android:required="true" />
<meta-data
android:name="com.google.android.wearable.standalone"
android:value="false" />
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTask"
android:taskAffinity="">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
@@ -0,0 +1,179 @@
package com.faceclaw.wear
import android.content.Context
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.os.Handler
import android.os.Looper
import android.os.SystemClock
import android.util.Log
import kotlin.math.max
import kotlin.math.sqrt
/** How hard a fingertip tap has to hit before it counts. */
enum class TapSensitivity(val label: String, val threshold: Float, val maxActivity: Float) {
/** Only firm taps; most resistant to false positives. */
LOW("Low", 4.0f, 1.0f),
NORMAL("Normal", 2.6f, 1.4f),
/** Light taps; expect the odd stray click when moving about. */
HIGH("High", 1.7f, 1.9f);
fun next(): TapSensitivity = entries[(ordinal + 1) % entries.size]
}
/**
* Fingertip ("tip tap") gestures: tapping the index finger against the
* thumb sends a short, sharp acceleration impulse down the wrist. Wear OS
* keeps its own pinch gesture to itself, so this reads the linear
* acceleration sensor directly while the pad is showing and looks for brief
* spikes above a quiet baseline: an impulse that rises past the threshold
* and falls back within MAX_SPIKE_MS is a tap; anything longer is the arm
* moving. Taps are suppressed while the baseline activity is high (walking,
* gesturing), and a second tap inside the double-tap window makes a double.
*
* A heuristic, not a classifier: good enough for a deliberate tap with the
* wrist held still, tunable through TapSensitivity, and off in a toggle.
*/
class FingerTapDetector(
context: Context,
private val sensitivity: () -> TapSensitivity,
/** elapsedRealtime before which samples are ignored (the watch's own haptics). */
private val quietUntil: () -> Long,
/** False while the watch is off the wrist; taps then never fire. */
private val onBody: () -> Boolean,
private val onTap: () -> Unit,
private val onDoubleTap: () -> Unit,
) : SensorEventListener {
private val sensorManager: SensorManager? = context.getSystemService(SensorManager::class.java)
private val sensor: Sensor? = sensorManager?.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION)
?: sensorManager?.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
private val subtractGravity = sensor?.type == Sensor.TYPE_ACCELEROMETER
private val handler = Handler(Looper.getMainLooper())
private val gravity = floatArrayOf(0f, 0f, SensorManager.GRAVITY_EARTH)
/** Slow average of the magnitude outside spikes: how much the arm is moving. */
private var activity = 0f
private var inSpike = false
/** Last sample that counted as the arm moving; a tap needs stillness before it. */
private var lastMotionNs = 0L
private var spikeStartNs = 0L
private var refractoryUntilNs = 0L
private var lastTapNs = 0L
private var pendingSingle: Runnable? = null
private var running = false
val available: Boolean get() = sensor != null
/** Start listening; false when the watch has no usable accelerometer. */
fun start(): Boolean {
val manager = sensorManager ?: return false
val target = sensor ?: return false
if (running) return true
running = manager.registerListener(this, target, SAMPLING_PERIOD_US, handler)
Log.i(TAG, "tip-tap detector ${if (running) "started" else "failed to start"} on ${target.name}")
return running
}
fun stop() {
if (!running) return
running = false
sensorManager?.unregisterListener(this)
pendingSingle?.let { handler.removeCallbacks(it) }
pendingSingle = null
inSpike = false
}
override fun onSensorChanged(event: SensorEvent) {
var x = event.values[0]
var y = event.values[1]
var z = event.values[2]
if (subtractGravity) {
// Raw accelerometer fallback: strip a slowly tracked gravity vector.
gravity[0] += (x - gravity[0]) * GRAVITY_ALPHA
gravity[1] += (y - gravity[1]) * GRAVITY_ALPHA
gravity[2] += (z - gravity[2]) * GRAVITY_ALPHA
x -= gravity[0]
y -= gravity[1]
z -= gravity[2]
}
val magnitude = sqrt(x * x + y * y + z * z)
val now = event.timestamp
val level = sensitivity()
if (SystemClock.elapsedRealtime() < quietUntil() || !onBody()) {
// Our own vibration motor (or a desk being bumped): not a finger.
// Also forget any spike in progress so its tail can't complete it.
inSpike = false
refractoryUntilNs = now + REFRACTORY_NS
return
}
if (!inSpike) {
val still = activity < level.maxActivity && now - lastMotionNs > STILLNESS_BEFORE_TAP_NS
if (magnitude > level.threshold && still && now > refractoryUntilNs) {
inSpike = true
spikeStartNs = now
} else {
activity += (magnitude - activity) * ACTIVITY_ALPHA
if (magnitude > level.maxActivity) lastMotionNs = now
}
return
}
val durationNs = now - spikeStartNs
if (magnitude < level.threshold * SPIKE_END_FRACTION) {
inSpike = false
refractoryUntilNs = now + REFRACTORY_NS
if (durationNs <= MAX_SPIKE_NS) {
registerTap(now)
} else {
activity = max(activity, magnitude)
lastMotionNs = now
}
} else if (durationNs > MAX_SPIKE_NS) {
// Sustained acceleration is the arm moving, not a tap.
inSpike = false
refractoryUntilNs = now + REFRACTORY_NS
activity += (magnitude - activity) * MOVEMENT_ALPHA
lastMotionNs = now
}
}
override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) = Unit
private fun registerTap(nowNs: Long) {
val pending = pendingSingle
if (pending != null && nowNs - lastTapNs <= DOUBLE_TAP_WINDOW_NS) {
handler.removeCallbacks(pending)
pendingSingle = null
lastTapNs = 0L
onDoubleTap()
return
}
lastTapNs = nowNs
val fire = Runnable {
pendingSingle = null
onTap()
}
pendingSingle = fire
handler.postDelayed(fire, DOUBLE_TAP_WINDOW_MS)
}
private companion object {
const val TAG = "FaceclawWear"
/** 100 Hz: under the 200 Hz line that needs HIGH_SAMPLING_RATE_SENSORS. */
const val SAMPLING_PERIOD_US = 10_000
const val MAX_SPIKE_NS = 90_000_000L
/** The hand has to be still this long before an impulse can be a tap. */
const val STILLNESS_BEFORE_TAP_NS = 250_000_000L
const val REFRACTORY_NS = 140_000_000L
const val DOUBLE_TAP_WINDOW_MS = 380L
const val DOUBLE_TAP_WINDOW_NS = DOUBLE_TAP_WINDOW_MS * 1_000_000L
const val SPIKE_END_FRACTION = 0.5f
const val ACTIVITY_ALPHA = 0.04f
const val MOVEMENT_ALPHA = 0.3f
const val GRAVITY_ALPHA = 0.05f
}
}
@@ -0,0 +1,51 @@
package com.faceclaw.wear
import android.content.Context
import android.os.SystemClock
import android.os.VibrationEffect
import android.os.Vibrator
/** Short confirmations for sent gestures; each call is a no-op without a vibrator. */
class Haptics(context: Context, private val enabled: () -> Boolean) {
private val vibrator: Vibrator? = context.getSystemService(Vibrator::class.java)
@Volatile private var lastVibrationAt = 0L
/**
* elapsedRealtime until which the motion sensors will still be feeling
* our own buzz. The tip-tap detector ignores that window, or a click's
* confirmation would read as another fingertip tap.
*/
fun quietUntil(): Long = lastVibrationAt + VIBRATION_SETTLE_MS
/** A sent scroll step. */
fun tick() = play(VibrationEffect.EFFECT_TICK)
/** A sent click / command. */
fun click() = play(VibrationEffect.EFFECT_CLICK)
/** A sent double-click. */
fun doubleClick() = play(VibrationEffect.EFFECT_DOUBLE_CLICK)
/** The start of a hold. */
fun heavy() = play(VibrationEffect.EFFECT_HEAVY_CLICK)
/** The phone refused or did not answer; always plays. */
fun error() {
val v = vibrator ?: return
if (!v.hasVibrator()) return
lastVibrationAt = SystemClock.elapsedRealtime()
v.vibrate(VibrationEffect.createWaveform(longArrayOf(0, 40, 60, 40), -1))
}
private fun play(effect: Int) {
if (!enabled()) return
val v = vibrator ?: return
if (!v.hasVibrator()) return
lastVibrationAt = SystemClock.elapsedRealtime()
v.vibrate(VibrationEffect.createPredefined(effect))
}
private companion object {
const val VIBRATION_SETTLE_MS = 400L
}
}
@@ -0,0 +1,116 @@
package com.faceclaw.wear
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.KeyEvent
import android.view.WindowManager
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.launch
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import com.faceclaw.wear.ui.FaceclawWearApp
class MainActivity : ComponentActivity() {
private lateinit var link: PhoneLink
private lateinit var prefs: WatchPrefs
private lateinit var haptics: Haptics
// Side (stem) buttons: button 1 is click / hold, 2 double-click, 3 "Hey Even".
private val stemHandler = Handler(Looper.getMainLooper())
private var stemHoldRunnable: Runnable? = null
private var stemHoldSent = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
link = PhoneLink(this)
prefs = WatchPrefs(this)
haptics = Haptics(this) { prefs.prefs.value.haptics }
setContent {
FaceclawWearApp(link = link, prefsStore = prefs, haptics = haptics)
}
// A remote that dozes mid-gesture is no remote: hold the display while
// the app is in front (every screen, not just the pad), unless the
// user turned "Keep screen on" off.
lifecycleScope.launch {
prefs.prefs.collect { current ->
if (current.keepScreenOn) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
}
}
override fun onStart() {
super.onStart()
link.start()
}
override fun onStop() {
cancelStemHold()
link.stop()
super.onStop()
}
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_STEM_1 -> {
if (event.repeatCount == 0) {
cancelStemHold()
stemHoldSent = false
val runnable = Runnable {
stemHoldSent = true
haptics.heavy()
link.sendGesture(Gesture.LONG_PRESS_START)
}
stemHoldRunnable = runnable
stemHandler.postDelayed(runnable, STEM_HOLD_MS)
}
return true
}
KeyEvent.KEYCODE_STEM_2 -> {
if (event.repeatCount == 0) {
haptics.doubleClick()
link.sendGesture(Gesture.DOUBLE_CLICK)
}
return true
}
KeyEvent.KEYCODE_STEM_3 -> {
if (event.repeatCount == 0) {
haptics.click()
link.sendGesture(Gesture.WAKEWORD)
}
return true
}
}
return super.onKeyDown(keyCode, event)
}
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
if (keyCode == KeyEvent.KEYCODE_STEM_1) {
cancelStemHold()
if (stemHoldSent) {
stemHoldSent = false
haptics.click()
link.sendGesture(Gesture.LONG_PRESS_RELEASE)
} else {
haptics.click()
link.sendGesture(Gesture.CLICK)
}
return true
}
if (keyCode == KeyEvent.KEYCODE_STEM_2 || keyCode == KeyEvent.KEYCODE_STEM_3) return true
return super.onKeyUp(keyCode, event)
}
private fun cancelStemHold() {
stemHoldRunnable?.let { stemHandler.removeCallbacks(it) }
stemHoldRunnable = null
}
private companion object {
const val STEM_HOLD_MS = 450L
}
}
@@ -0,0 +1,55 @@
package com.faceclaw.wear
import android.content.Context
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.os.Handler
import android.os.Looper
import android.util.Log
/**
* Whether the watch is on a wrist, from the low-latency off-body sensor.
* The motion-sensor gestures (tip taps, wrist twists) only make sense on a
* wrist: on a desk, a buzzing phone next to the watch reads as a fingertip
* tap. Watches without the sensor are assumed worn.
*/
class OnBodyMonitor(context: Context) : SensorEventListener {
private val sensorManager: SensorManager? = context.getSystemService(SensorManager::class.java)
private val sensor: Sensor? = sensorManager?.getDefaultSensor(Sensor.TYPE_LOW_LATENCY_OFFBODY_DETECT)
private val handler = Handler(Looper.getMainLooper())
private var running = false
@Volatile
var onBody: Boolean = true
private set
fun start() {
val manager = sensorManager ?: return
val target = sensor ?: return
if (running) return
running = manager.registerListener(this, target, SensorManager.SENSOR_DELAY_NORMAL, handler)
}
fun stop() {
if (!running) return
running = false
sensorManager?.unregisterListener(this)
onBody = true
}
override fun onSensorChanged(event: SensorEvent) {
val worn = event.values.firstOrNull()?.let { it >= 0.5f } ?: true
if (worn != onBody) {
onBody = worn
Log.i(TAG, if (worn) "watch on wrist: motion gestures enabled" else "watch off wrist: motion gestures paused")
}
}
override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) = Unit
private companion object {
const val TAG = "FaceclawWear"
}
}
@@ -0,0 +1,335 @@
package com.faceclaw.wear
import android.content.Context
import android.net.Uri
import android.util.Log
import com.google.android.gms.common.api.ApiException
import com.google.android.gms.wearable.CapabilityClient
import com.google.android.gms.wearable.CapabilityInfo
import com.google.android.gms.wearable.DataClient
import com.google.android.gms.wearable.DataEvent
import com.google.android.gms.wearable.DataEventBuffer
import com.google.android.gms.wearable.DataItem
import com.google.android.gms.wearable.DataMapItem
import com.google.android.gms.wearable.MessageClient
import com.google.android.gms.wearable.MessageEvent
import com.google.android.gms.wearable.Node
import com.google.android.gms.wearable.Wearable
import com.google.android.gms.wearable.WearableStatusCodes
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.tasks.await
import org.json.JSONObject
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicLong
/** What we know about the phone and the Faceclaw app on it. */
data class LinkStatus(
/** A phone is connected to the watch at all (any node). */
val phoneReachable: Boolean = false,
/** That phone has Faceclaw installed (advertises the capability). */
val phoneAppInstalled: Boolean = false,
val phoneNodeId: String? = null,
val phoneName: String = "",
/**
* Whether the phone app's dashboard (the JS side) answered our last
* message; null until we have heard anything. False means Faceclaw is
* installed but not running, so the user has to open it.
*/
val appRunning: Boolean? = null,
val lastError: String? = null,
)
/** The assistant overlay as mirrored from the glasses. */
data class AssistantMirror(
/** idle | thinking | streaming | done | error */
val phase: String = "idle",
val text: String = "",
val updatedAt: Long = 0,
)
/** A transient message for the UI (ack failures, confirmations). */
data class Notice(val text: String, val isError: Boolean, val id: Long)
/**
* The watch's end of the Wearable Data Layer conversation with the phone:
* sends gestures/commands/text as messages, receives acks and events, and
* mirrors the phone's state item. Lives for the activity's lifetime
* (start()/stop() from onStart/onStop).
*/
class PhoneLink(context: Context) :
MessageClient.OnMessageReceivedListener,
DataClient.OnDataChangedListener,
CapabilityClient.OnCapabilityChangedListener {
private val appContext = context.applicationContext
private val messageClient = Wearable.getMessageClient(appContext)
private val dataClient = Wearable.getDataClient(appContext)
private val capabilityClient = Wearable.getCapabilityClient(appContext)
private val nodeClient = Wearable.getNodeClient(appContext)
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
private val nextSeq = AtomicLong(1)
private val pendingAcks = ConcurrentHashMap<Long, Job>()
private var noticeJob: Job? = null
private var started = false
private val _state = MutableStateFlow<PhoneState?>(null)
val state: StateFlow<PhoneState?> = _state.asStateFlow()
private val _link = MutableStateFlow(LinkStatus())
val link: StateFlow<LinkStatus> = _link.asStateFlow()
private val _assistant = MutableStateFlow(AssistantMirror())
val assistant: StateFlow<AssistantMirror> = _assistant.asStateFlow()
private val _events = MutableSharedFlow<PhoneEvent>(extraBufferCapacity = 32)
val events: SharedFlow<PhoneEvent> = _events.asSharedFlow()
private val _notice = MutableStateFlow<Notice?>(null)
val notice: StateFlow<Notice?> = _notice.asStateFlow()
fun start() {
if (started) return
started = true
messageClient.addListener(this)
dataClient.addListener(this)
capabilityClient.addListener(this, Protocol.CAPABILITY_PHONE)
refresh()
}
fun stop() {
if (!started) return
started = false
messageClient.removeListener(this)
dataClient.removeListener(this)
capabilityClient.removeListener(this, Protocol.CAPABILITY_PHONE)
}
/** Re-discover the phone, reload the cached state item, and ask for a fresh one. */
fun refresh() {
scope.launch {
findPhone()
loadStateItem()
if (_link.value.phoneAppInstalled) requestState()
}
}
// ---- outbound -----------------------------------------------------
fun sendGesture(gesture: Gesture, steps: Int = 1) {
send(Protocol.PATH_INPUT, JSONObject().put("gesture", gesture.wire).put("steps", steps))
}
fun sendCommand(command: String, vararg extras: Pair<String, String>) {
val body = JSONObject().put("command", command)
for ((key, value) in extras) body.put(key, value)
send(Protocol.PATH_COMMAND, body)
}
fun sendAssistantQuery(text: String) {
_assistant.value = AssistantMirror(phase = "thinking", text = "", updatedAt = System.currentTimeMillis())
send(Protocol.PATH_ASSISTANT, JSONObject().put("text", text))
}
fun sendText(text: String) {
send(Protocol.PATH_TEXT, JSONObject().put("text", text))
}
fun requestState() {
send(Protocol.PATH_STATE_REQUEST, JSONObject(), quiet = true)
}
fun clearAssistant() {
_assistant.value = AssistantMirror()
}
private fun send(path: String, body: JSONObject, quiet: Boolean = false) {
val seq = nextSeq.getAndIncrement()
body.put("seq", seq)
Log.d(TAG, "send $path $body")
val payload = body.toString().toByteArray(Charsets.UTF_8)
scope.launch {
var nodeId = _link.value.phoneNodeId
if (nodeId == null) {
findPhone()
nodeId = _link.value.phoneNodeId
}
if (nodeId == null) {
if (!quiet) showNotice("No phone connected.", isError = true)
return@launch
}
if (!_link.value.phoneAppInstalled) {
if (!quiet) showNotice("Faceclaw isn't installed on the phone.", isError = true)
return@launch
}
try {
val requestId = messageClient.sendMessage(nodeId, path, payload).await()
Log.d(TAG, "sent seq=$seq requestId=$requestId")
// The phone acks every message; silence means the app
// process never received it (or Play services dropped it).
val timeout = scope.launch {
delay(ACK_TIMEOUT_MS)
if (pendingAcks.remove(seq) != null) {
_link.update { it.copy(appRunning = it.appRunning ?: false) }
if (!quiet) showNotice("No reply from the phone.", isError = true)
}
}
pendingAcks[seq] = timeout
} catch (error: ApiException) {
Log.w(TAG, "send $path failed: ${error.statusCode}", error)
val message = when (error.statusCode) {
WearableStatusCodes.TARGET_NODE_NOT_CONNECTED -> "The phone is out of range."
else -> "Couldn't reach the phone (${error.statusCode})."
}
_link.update { it.copy(lastError = message) }
if (!quiet) showNotice(message, isError = true)
scope.launch { findPhone() }
} catch (error: Exception) {
Log.w(TAG, "send $path failed", error)
if (!quiet) showNotice("Couldn't reach the phone.", isError = true)
}
}
}
// ---- inbound ------------------------------------------------------
override fun onMessageReceived(event: MessageEvent) {
val json = String(event.data, Charsets.UTF_8)
Log.d(TAG, "recv ${event.path} $json")
when (event.path) {
Protocol.PATH_ACK -> Ack.parse(json)?.let { handleAck(it) }
Protocol.PATH_EVENT -> PhoneEvent.parse(json)?.let { handleEvent(it) }
}
}
private fun handleAck(ack: Ack) {
pendingAcks.remove(ack.seq)?.cancel()
_link.update { it.copy(appRunning = ack.jsReady, lastError = null) }
if (!ack.ok) {
showNotice(ack.message.ifBlank { "The phone refused that." }, isError = true)
} else if (ack.message.isNotBlank()) {
showNotice(ack.message, isError = false)
}
}
private fun handleEvent(event: PhoneEvent) {
when (event) {
is PhoneEvent.Assistant -> {
_assistant.update { current ->
when (event.phase) {
"thinking" -> AssistantMirror("thinking", "", System.currentTimeMillis())
"streaming" -> AssistantMirror("streaming", event.text, System.currentTimeMillis())
"done" -> AssistantMirror("done", event.text.ifBlank { current.text }, System.currentTimeMillis())
"error" -> AssistantMirror("error", event.text, System.currentTimeMillis())
"closed" -> AssistantMirror("idle", current.text, System.currentTimeMillis())
else -> current
}
}
}
is PhoneEvent.Alert -> showNotice(event.text, isError = false)
}
_events.tryEmit(event)
}
override fun onDataChanged(buffer: DataEventBuffer) {
for (event in buffer) {
if (event.type != DataEvent.TYPE_CHANGED) continue
val item = event.dataItem
if (item.uri.path == Protocol.PATH_STATE) applyStateItem(item)
}
}
override fun onCapabilityChanged(info: CapabilityInfo) {
scope.launch { findPhone() }
}
private fun applyStateItem(item: DataItem) {
val map = DataMapItem.fromDataItem(item).dataMap
val json = map.getString(Protocol.STATE_KEY_JSON) ?: return
val updatedAt = map.getLong(Protocol.STATE_KEY_UPDATED_AT, 0)
PhoneState.parse(json, updatedAt)?.let { parsed ->
_state.value = parsed
// A state item is only ever written by the running dashboard.
_link.update { it.copy(appRunning = true) }
}
}
private suspend fun loadStateItem() {
try {
val uri = Uri.Builder().scheme("wear").path(Protocol.PATH_STATE).build()
val items = dataClient.getDataItems(uri).await()
try {
for (item in items) applyStateItem(item)
} finally {
items.release()
}
} catch (error: Exception) {
Log.w(TAG, "state item load failed", error)
}
}
private suspend fun findPhone() {
try {
val info = capabilityClient
.getCapability(Protocol.CAPABILITY_PHONE, CapabilityClient.FILTER_REACHABLE)
.await()
val phone = pickNode(info.nodes)
if (phone != null) {
_link.update {
it.copy(
phoneReachable = true,
phoneAppInstalled = true,
phoneNodeId = phone.id,
phoneName = phone.displayName,
lastError = null,
)
}
return
}
val connected = nodeClient.connectedNodes.await()
val any = pickNode(connected.toSet())
_link.update {
it.copy(
phoneReachable = any != null,
phoneAppInstalled = false,
phoneNodeId = null,
phoneName = any?.displayName ?: "",
appRunning = null,
)
}
} catch (error: Exception) {
Log.w(TAG, "phone lookup failed", error)
_link.update { it.copy(lastError = error.message) }
}
}
private fun pickNode(nodes: Set<Node>): Node? =
nodes.firstOrNull { it.isNearby } ?: nodes.firstOrNull()
private fun showNotice(text: String, isError: Boolean) {
noticeJob?.cancel()
_notice.value = Notice(text, isError, System.nanoTime())
noticeJob = scope.launch {
delay(if (isError) NOTICE_ERROR_MS else NOTICE_INFO_MS)
_notice.value = null
}
}
companion object {
private const val TAG = "FaceclawWear"
private const val ACK_TIMEOUT_MS = 3000L
private const val NOTICE_INFO_MS = 1800L
private const val NOTICE_ERROR_MS = 3200L
}
}
@@ -0,0 +1,205 @@
package com.faceclaw.wear
import org.json.JSONObject
/**
* Wire format shared with the phone app. Mirror of app/native/wear-bridge.ts
* (paths) and app/g2/wear-remote.ts (payloads); see ../../PROTOCOL.md.
*/
object Protocol {
const val PROTOCOL_VERSION = 1
/** Advertised by the phone app so the watch can find it. */
const val CAPABILITY_PHONE = "faceclaw_phone"
const val PATH_INPUT = "/faceclaw/input"
const val PATH_COMMAND = "/faceclaw/command"
const val PATH_ASSISTANT = "/faceclaw/assistant"
const val PATH_TEXT = "/faceclaw/text"
const val PATH_STATE_REQUEST = "/faceclaw/state/request"
const val PATH_ACK = "/faceclaw/ack"
const val PATH_EVENT = "/faceclaw/event"
const val PATH_STATE = "/faceclaw/state"
const val STATE_KEY_JSON = "json"
const val STATE_KEY_UPDATED_AT = "updatedAt"
}
/** Ring-style gestures, as the phone's synthetic ring input understands them. */
enum class Gesture(val wire: String) {
CLICK("click"),
DOUBLE_CLICK("double-click"),
SCROLL_UP("scroll-up"),
SCROLL_DOWN("scroll-down"),
/** A complete short hold (press + release). */
LONG_PRESS("long-press"),
/** Finger down: the hold lasts until LONG_PRESS_RELEASE. */
LONG_PRESS_START("long-press-start"),
LONG_PRESS_RELEASE("long-press-release"),
/** The spoken "Hey Even": opens the glasses' own voice dialog. */
WAKEWORD("wakeword"),
/**
* Spatial (four-way) input the ring cannot produce. The glasses UI gives
* it a spatial meaning where one exists (grid rows and columns, panel
* columns, tracks) and otherwise treats up/down as scroll, right as select
* and left as back.
*/
SWIPE_UP("swipe-up"),
SWIPE_DOWN("swipe-down"),
SWIPE_LEFT("swipe-left"),
SWIPE_RIGHT("swipe-right"),
}
/** Shell commands; things the ring cannot express. */
object Command {
const val LAUNCH_APP = "launch-app"
const val FOCUS_WINDOW = "focus-window"
const val CLOSE_WINDOW = "close-window"
const val SIDEBAR = "sidebar"
const val WAKE = "wake"
const val SLEEP = "sleep"
const val LOCK = "lock"
const val UNLOCK = "unlock"
const val CONNECT = "connect"
const val DISCONNECT = "disconnect"
const val CLOSE_ASSISTANT = "close-assistant"
const val DISPLAY_MODE = "display-mode"
}
/** The glasses' display modes, mirroring the phone's Display > Display mode. */
enum class DisplayMode(val wire: String, val label: String) {
BAND("576x288", "Band · 576×288"),
TALL("576x480", "Tall · 576×480"),
FULL("640x480", "Full panel · 640×480");
fun next(): DisplayMode = entries[(ordinal + 1) % entries.size]
companion object {
fun fromWire(value: String): DisplayMode? = entries.firstOrNull { it.wire == value }
}
}
data class AppEntry(val appId: String, val title: String)
data class WindowEntry(
val windowId: String,
val title: String,
val appId: String,
val focused: Boolean,
val closeable: Boolean,
val acceptsText: Boolean,
)
/** The phone's mirrored dashboard state (Data Layer item /faceclaw/state). */
data class PhoneState(
val protocol: Int,
val version: String,
val phase: String,
val status: String,
val connected: Boolean,
val screenOn: Boolean,
val locked: Boolean,
val worn: Boolean?,
val listening: Boolean,
/** Display mode wire value ("576x288" | "576x480" | "640x480"). */
val displayMode: String,
val battery: Int?,
val charging: Boolean,
val foreground: AppEntry?,
val windows: List<WindowEntry>,
val apps: List<AppEntry>,
val remoteEnabled: Boolean,
val canUnlock: Boolean,
val mirrorAssistant: Boolean,
val assistantAvailable: Boolean,
val updatedAt: Long,
) {
companion object {
fun parse(json: String, updatedAt: Long): PhoneState? {
return try {
val o = JSONObject(json)
val foreground = o.optJSONObject("foreground")
PhoneState(
protocol = o.optInt("protocol", 1),
version = o.optString("version", ""),
phase = o.optString("phase", "disconnected"),
status = o.optString("status", ""),
connected = o.optBoolean("connected", false),
screenOn = o.optBoolean("screenOn", false),
locked = o.optBoolean("locked", false),
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", ""))
},
windows = o.optJSONArray("windows")?.let { array ->
(0 until array.length()).mapNotNull { index ->
val w = array.optJSONObject(index) ?: return@mapNotNull null
WindowEntry(
windowId = w.optString("windowId", ""),
title = w.optString("title", ""),
appId = w.optString("appId", ""),
focused = w.optBoolean("focused", false),
closeable = w.optBoolean("closeable", true),
acceptsText = w.optBoolean("acceptsText", false),
)
}
} ?: emptyList(),
apps = o.optJSONArray("apps")?.let { array ->
(0 until array.length()).mapNotNull { index ->
val a = array.optJSONObject(index) ?: return@mapNotNull null
AppEntry(a.optString("appId", ""), a.optString("title", ""))
}
} ?: emptyList(),
remoteEnabled = o.optBoolean("remoteEnabled", true),
canUnlock = o.optBoolean("canUnlock", true),
mirrorAssistant = o.optBoolean("mirrorAssistant", true),
assistantAvailable = o.optBoolean("assistantAvailable", false),
updatedAt = updatedAt,
)
} catch (error: Exception) {
null
}
}
}
}
/** The phone's reply to one of our messages. */
data class Ack(val seq: Long, val ok: Boolean, val jsReady: Boolean, val message: String) {
companion object {
fun parse(json: String): Ack? = try {
val o = JSONObject(json)
Ack(
seq = o.optLong("seq", 0),
ok = o.optBoolean("ok", false),
jsReady = o.optBoolean("jsReady", true),
message = o.optString("message", ""),
)
} catch (error: Exception) {
null
}
}
}
/** Phone -> watch events (/faceclaw/event). */
sealed class PhoneEvent {
/** phase: thinking | streaming | done | error | closed; text is the reply so far. */
data class Assistant(val phase: String, val text: String) : PhoneEvent()
data class Alert(val text: String) : PhoneEvent()
companion object {
fun parse(json: String): PhoneEvent? = try {
val o = JSONObject(json)
when (o.optString("type")) {
"assistant" -> Assistant(o.optString("phase", ""), o.optString("text", ""))
"alert" -> Alert(o.optString("text", ""))
else -> null
}
} catch (error: Exception) {
null
}
}
}
@@ -0,0 +1,119 @@
package com.faceclaw.wear
import android.content.Context
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
enum class CrownSensitivity(val label: String, val pixelsPerStep: Float) {
LOW("Low", 110f),
NORMAL("Normal", 60f),
HIGH("High", 30f);
fun next(): CrownSensitivity = entries[(ordinal + 1) % entries.size]
}
/** What a horizontal swipe on the pad does. */
enum class SwipeAction(val label: String) {
/** Sent as directional input; the glasses UI decides (see Gesture.SWIPE_LEFT). */
NAVIGATE("Navigate"),
SIDEBAR("Sidebar"),
DOUBLE_CLICK("Double-click"),
CLICK("Click"),
LONG_PRESS("Long press"),
WAKEWORD("“Hey Even”"),
NONE("Nothing");
fun next(): SwipeAction = entries[(ordinal + 1) % entries.size]
}
/** Watch-local preferences (nothing here is synced to the phone). */
data class Prefs(
/** Buzz on every gesture sent. */
val haptics: Boolean = true,
/**
* Keep the display awake while the pad is showing. Wear otherwise dozes
* within seconds of the wrist dropping and freezes the app, which is
* exactly when a remote wants to stay ready.
*/
val keepScreenOn: Boolean = true,
/** Swipe/crown direction follows the content (touch-scroll style) instead of the ring. */
val naturalScroll: Boolean = false,
/** Tap the top/bottom of the pad to scroll instead of swiping. */
val tapZones: Boolean = false,
val crownSensitivity: CrownSensitivity = CrownSensitivity.NORMAL,
val swipeLeft: SwipeAction = SwipeAction.NAVIGATE,
val swipeRight: SwipeAction = SwipeAction.NAVIGATE,
/**
* Fingertip (pinch) taps from the motion sensors; see FingerTapDetector.
* Off by default: on a wrist, ordinary hand movement produced phantom
* clicks in testing, and a phantom click opens things.
*/
val fingerTaps: Boolean = false,
val tapSensitivity: TapSensitivity = TapSensitivity.NORMAL,
/** Two quick wrist twists = back (double-click); see WristTwistDetector. */
val wristTwist: Boolean = true,
val twistSensitivity: TwistSensitivity = TwistSensitivity.NORMAL,
)
class WatchPrefs(context: Context) {
private val store = context.applicationContext.getSharedPreferences("faceclaw_wear", Context.MODE_PRIVATE)
private val _prefs = MutableStateFlow(load())
val prefs: StateFlow<Prefs> = _prefs.asStateFlow()
private fun load(): Prefs = Prefs(
haptics = store.getBoolean(KEY_HAPTICS, true),
keepScreenOn = store.getBoolean(KEY_KEEP_SCREEN_ON, true),
naturalScroll = store.getBoolean(KEY_NATURAL_SCROLL, false),
tapZones = store.getBoolean(KEY_TAP_ZONES, false),
crownSensitivity = store.getString(KEY_CROWN, null)
?.let { stored -> CrownSensitivity.entries.firstOrNull { it.name == stored } }
?: CrownSensitivity.NORMAL,
swipeLeft = store.getString(KEY_SWIPE_LEFT, null)
?.let { stored -> SwipeAction.entries.firstOrNull { it.name == stored } }
?: SwipeAction.NAVIGATE,
swipeRight = store.getString(KEY_SWIPE_RIGHT, null)
?.let { stored -> SwipeAction.entries.firstOrNull { it.name == stored } }
?: SwipeAction.NAVIGATE,
fingerTaps = store.getBoolean(KEY_FINGER_TAPS, false),
tapSensitivity = store.getString(KEY_TAP_SENSITIVITY, null)
?.let { stored -> TapSensitivity.entries.firstOrNull { it.name == stored } }
?: TapSensitivity.NORMAL,
wristTwist = store.getBoolean(KEY_WRIST_TWIST, true),
twistSensitivity = store.getString(KEY_TWIST_SENSITIVITY, null)
?.let { stored -> TwistSensitivity.entries.firstOrNull { it.name == stored } }
?: TwistSensitivity.NORMAL,
)
fun update(transform: (Prefs) -> Prefs) {
val next = transform(_prefs.value)
_prefs.value = next
store.edit()
.putBoolean(KEY_HAPTICS, next.haptics)
.putBoolean(KEY_KEEP_SCREEN_ON, next.keepScreenOn)
.putBoolean(KEY_NATURAL_SCROLL, next.naturalScroll)
.putBoolean(KEY_TAP_ZONES, next.tapZones)
.putString(KEY_CROWN, next.crownSensitivity.name)
.putString(KEY_SWIPE_LEFT, next.swipeLeft.name)
.putString(KEY_SWIPE_RIGHT, next.swipeRight.name)
.putBoolean(KEY_FINGER_TAPS, next.fingerTaps)
.putString(KEY_TAP_SENSITIVITY, next.tapSensitivity.name)
.putBoolean(KEY_WRIST_TWIST, next.wristTwist)
.putString(KEY_TWIST_SENSITIVITY, next.twistSensitivity.name)
.apply()
}
private companion object {
const val KEY_HAPTICS = "haptics"
const val KEY_KEEP_SCREEN_ON = "keepScreenOn"
const val KEY_NATURAL_SCROLL = "naturalScroll"
const val KEY_TAP_ZONES = "tapZones"
const val KEY_CROWN = "crownSensitivity"
const val KEY_SWIPE_LEFT = "swipeLeft"
const val KEY_SWIPE_RIGHT = "swipeRight"
const val KEY_FINGER_TAPS = "fingerTaps"
const val KEY_TAP_SENSITIVITY = "tapSensitivity"
const val KEY_WRIST_TWIST = "wristTwist"
const val KEY_TWIST_SENSITIVITY = "twistSensitivity"
}
}
@@ -0,0 +1,137 @@
package com.faceclaw.wear
import android.content.Context
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.os.Handler
import android.os.Looper
import android.os.SystemClock
import android.util.Log
import kotlin.math.abs
/** How fast the wrist has to turn before a twist counts. */
enum class TwistSensitivity(val label: String, val threshold: Float) {
/** Only a brisk flick; rad/s about the forearm. */
LOW("Low", 5.0f),
NORMAL("Normal", 3.6f),
HIGH("High", 2.6f);
fun next(): TwistSensitivity = entries[(ordinal + 1) % entries.size]
}
/**
* "Twist the wrist twice" = back. The gyroscope's x axis runs along the
* forearm on a watch, so a wrist twist (pronation / supination) is a burst of
* angular velocity about x. Two brisk twists in the same direction, each
* short and separated by 120–900 ms, fire the gesture; the wrist coming back
* between them spins the other way and is ignored. The direction is not
* fixed (away or toward), so it works on either wrist, and the twists must be
* quick: a slow arm rotation never crosses the rate threshold.
*
* Same status as FingerTapDetector: a heuristic with a toggle, not a
* classifier.
*/
class WristTwistDetector(
context: Context,
private val sensitivity: () -> TwistSensitivity,
/** elapsedRealtime before which samples are ignored (the watch's own haptics). */
private val quietUntil: () -> Long,
/** False while the watch is off the wrist; twists then never fire. */
private val onBody: () -> Boolean,
private val onDoubleTwist: () -> Unit,
) : SensorEventListener {
private val sensorManager: SensorManager? = context.getSystemService(SensorManager::class.java)
private val sensor: Sensor? = sensorManager?.getDefaultSensor(Sensor.TYPE_GYROSCOPE)
private val handler = Handler(Looper.getMainLooper())
private var inBurst = false
/** Slow average of |rate| outside bursts: how much the arm is rotating anyway. */
private var activity = 0f
private var lastMotionNs = 0L
private var burstStartNs = 0L
private var burstSign = 0
private var firstTwistNs = 0L
private var firstTwistSign = 0
private var running = false
val available: Boolean get() = sensor != null
fun start(): Boolean {
val manager = sensorManager ?: return false
val target = sensor ?: return false
if (running) return true
running = manager.registerListener(this, target, SAMPLING_PERIOD_US, handler)
Log.i(TAG, "wrist-twist detector ${if (running) "started" else "failed to start"}")
return running
}
fun stop() {
if (!running) return
running = false
sensorManager?.unregisterListener(this)
inBurst = false
firstTwistNs = 0L
}
override fun onSensorChanged(event: SensorEvent) {
val rate = event.values[0]
val now = event.timestamp
if (SystemClock.elapsedRealtime() < quietUntil() || !onBody()) {
inBurst = false
firstTwistNs = 0L
return
}
val threshold = sensitivity().threshold
if (!inBurst) {
val magnitude = abs(rate)
// A twist pair only starts from a still-ish wrist: general arm
// rotation (reaching, gesturing) produced same-sign burst pairs
// that read as the gesture.
val still = activity < threshold * ACTIVITY_FRACTION && now - lastMotionNs > STILLNESS_BEFORE_TWIST_NS
if (magnitude > threshold && (still || firstTwistNs != 0L)) {
inBurst = true
burstStartNs = now
burstSign = if (rate > 0) 1 else -1
} else {
activity += (magnitude - activity) * ACTIVITY_ALPHA
if (magnitude > threshold * ACTIVITY_FRACTION) lastMotionNs = now
}
return
}
// In a burst: wait for the rate to drop back under the threshold.
if (abs(rate) > threshold * BURST_END_FRACTION && (if (rate > 0) 1 else -1) == burstSign) return
inBurst = false
val duration = now - burstStartNs
if (duration > MAX_BURST_NS) return // a slow sweep, not a flick
val sinceFirst = now - firstTwistNs
if (firstTwistNs != 0L && burstSign == firstTwistSign && sinceFirst in MIN_GAP_NS..MAX_GAP_NS) {
firstTwistNs = 0L
onDoubleTwist()
} else if (firstTwistNs == 0L || sinceFirst > MAX_GAP_NS || burstSign != firstTwistSign) {
// The return twist (opposite sign) does not start a new pair; a
// fresh same-direction twist does.
if (firstTwistNs == 0L || sinceFirst > MAX_GAP_NS) {
firstTwistNs = now
firstTwistSign = burstSign
}
}
}
override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) = Unit
private companion object {
const val TAG = "FaceclawWear"
const val SAMPLING_PERIOD_US = 10_000
const val MAX_BURST_NS = 350_000_000L
const val MIN_GAP_NS = 120_000_000L
const val MAX_GAP_NS = 900_000_000L
const val BURST_END_FRACTION = 0.5f
const val ACTIVITY_ALPHA = 0.04f
const val ACTIVITY_FRACTION = 0.35f
const val STILLNESS_BEFORE_TWIST_NS = 300_000_000L
}
}
@@ -0,0 +1,128 @@
package com.faceclaw.wear.ui
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
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.Button
import androidx.wear.compose.material.ButtonDefaults
import androidx.wear.compose.material.Chip
import androidx.wear.compose.material.ChipDefaults
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.ListHeader
import androidx.wear.compose.material.PositionIndicator
import androidx.wear.compose.material.Scaffold
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.TimeText
import com.faceclaw.wear.Command
import com.faceclaw.wear.Haptics
import com.faceclaw.wear.PhoneLink
import com.faceclaw.wear.R
import com.faceclaw.wear.WindowEntry
/**
* The glasses' sidebar and launcher, on the wrist: open windows first (tap to
* bring one to the front, × to close it), then every launchable app.
*/
@Composable
fun AppsScreen(link: PhoneLink, haptics: Haptics, onDone: () -> Unit) {
val state by link.state.collectAsStateWithLifecycle()
val notice by link.notice.collectAsStateWithLifecycle()
val listState = rememberScalingLazyListState()
val windows = state?.windows ?: emptyList()
val apps = state?.apps ?: emptyList()
Scaffold(
timeText = { TimeText() },
positionIndicator = { PositionIndicator(scalingLazyListState = listState) },
) {
ScalingLazyColumn(
state = listState,
modifier = Modifier.fillMaxSize(),
) {
val onScreen = windows.filter { it.focused }
val others = windows.filter { !it.focused }
if (onScreen.isNotEmpty()) {
item { ListHeader { Text("On screen") } }
items(onScreen, key = { "w:" + it.windowId }) { window -> WindowRow(window, link, haptics, onDone) }
}
if (others.isNotEmpty()) {
item { ListHeader { Text("Also open") } }
items(others, key = { "w:" + it.windowId }) { window -> WindowRow(window, link, haptics, onDone) }
}
item { ListHeader { Text(if (apps.isEmpty()) "No app list yet" else "Launch") } }
items(apps, key = { "a:" + it.appId }) { app ->
Chip(
onClick = {
haptics.click()
link.sendCommand(Command.LAUNCH_APP, "appId" to app.appId)
onDone()
},
label = { Text(app.title, maxLines = 1, overflow = TextOverflow.Ellipsis) },
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
)
}
if (apps.isEmpty()) {
item {
Text(
"Open Faceclaw on the phone and connect the glasses.",
textAlign = androidx.compose.ui.text.style.TextAlign.Center,
style = androidx.wear.compose.material.MaterialTheme.typography.caption2,
)
}
}
}
NoticeOverlay(notice)
}
}
/** One open window: tap to bring it to the front, × to close it. */
@Composable
private fun WindowRow(window: WindowEntry, link: PhoneLink, haptics: Haptics, onDone: () -> Unit) {
Row(modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
Chip(
onClick = {
haptics.click()
link.sendCommand(Command.FOCUS_WINDOW, "windowId" to window.windowId)
onDone()
},
// The launcher's window is titled "Apps" on the glasses; here that
// would read as this very screen.
label = { Text(if (window.appId == "launcher") "Launcher" else window.title, maxLines = 1, overflow = TextOverflow.Ellipsis) },
secondaryLabel = if (window.acceptsText) ({ Text("takes typed text") }) else null,
colors = if (window.focused) ChipDefaults.primaryChipColors() else ChipDefaults.secondaryChipColors(),
modifier = Modifier.weight(1f),
)
if (window.closeable) {
Spacer(modifier = Modifier.width(4.dp))
Button(
onClick = {
haptics.click()
link.sendCommand(Command.CLOSE_WINDOW, "windowId" to window.windowId)
},
modifier = Modifier.size(32.dp),
colors = ButtonDefaults.secondaryButtonColors(),
) {
Icon(
painter = painterResource(R.drawable.ic_close),
contentDescription = "Close ${window.title}",
modifier = Modifier.size(16.dp),
)
}
}
}
}
@@ -0,0 +1,144 @@
package com.faceclaw.wear.ui
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
import androidx.wear.compose.material.Button
import androidx.wear.compose.material.ButtonDefaults
import androidx.wear.compose.material.Chip
import androidx.wear.compose.material.ChipDefaults
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.material.PositionIndicator
import androidx.wear.compose.material.Scaffold
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.TimeText
import com.faceclaw.wear.Command
import com.faceclaw.wear.Gesture
import com.faceclaw.wear.Haptics
import com.faceclaw.wear.PhoneLink
import com.faceclaw.wear.R
/**
* Ask the assistant from the wrist (watch speech recognition or keyboard) and
* read its reply here as it streams, mirrored from the glasses overlay. "Hey
* Even" instead uses the glasses' own microphone and voice dialog.
*/
@Composable
fun AssistantScreen(link: PhoneLink, haptics: Haptics) {
val state by link.state.collectAsStateWithLifecycle()
val mirror by link.assistant.collectAsStateWithLifecycle()
val notice by link.notice.collectAsStateWithLifecycle()
val listState = rememberScalingLazyListState()
val available = state?.assistantAvailable != false
val ask = rememberSpeechLauncher(
prompt = stringResource(R.string.speech_prompt_assistant),
onResult = { text -> haptics.click(); link.sendAssistantQuery(text) },
onUnavailable = { haptics.error() },
)
val type = rememberKeyboardLauncher(
label = stringResource(R.string.keyboard_label_assistant),
onResult = { text -> haptics.click(); link.sendAssistantQuery(text) },
onUnavailable = { haptics.error() },
)
// A finished reply deserves a nudge: the wrist may be down while it streams.
LaunchedEffect(mirror.phase, mirror.updatedAt) {
if (mirror.phase == "done" || mirror.phase == "error") haptics.doubleClick()
}
Scaffold(
timeText = { TimeText() },
positionIndicator = { PositionIndicator(scalingLazyListState = listState) },
) {
ScalingLazyColumn(state = listState, modifier = Modifier.fillMaxSize()) {
item {
Row(
modifier = Modifier.fillMaxWidth().padding(top = 6.dp),
horizontalArrangement = Arrangement.Center,
) {
Button(onClick = ask, modifier = Modifier.size(44.dp), enabled = available) {
Icon(painterResource(R.drawable.ic_mic), contentDescription = "Ask by voice", modifier = Modifier.size(22.dp))
}
Spacer(modifier = Modifier.size(10.dp))
Button(
onClick = type,
modifier = Modifier.size(44.dp),
colors = ButtonDefaults.secondaryButtonColors(),
enabled = available,
) {
Icon(painterResource(R.drawable.ic_keyboard), contentDescription = "Ask by keyboard", modifier = Modifier.size(22.dp))
}
}
}
item {
val label = when (mirror.phase) {
"thinking" -> "Thinking…"
"streaming" -> "Replying…"
"error" -> "Error"
"done" -> "Reply"
else -> if (available) "Ask something" else "Set up the assistant in Faceclaw's Settings"
}
Text(
label,
style = MaterialTheme.typography.caption1,
color = MaterialTheme.colors.onSurfaceVariant,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth().padding(top = 4.dp),
)
}
if (mirror.text.isNotBlank()) {
item {
Text(
mirror.text,
style = MaterialTheme.typography.body2,
modifier = Modifier.fillMaxWidth().padding(horizontal = 6.dp, vertical = 4.dp),
)
}
}
item {
Chip(
onClick = {
haptics.click()
link.sendGesture(Gesture.WAKEWORD)
},
label = { Text("“Hey Even” on glasses") },
secondaryLabel = { Text("uses the glasses mic") },
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
)
}
if (mirror.phase != "idle") {
item {
Chip(
onClick = {
haptics.click()
link.sendCommand(Command.CLOSE_ASSISTANT)
link.clearAssistant()
},
label = { Text(if (mirror.phase == "thinking" || mirror.phase == "streaming") "Cancel" else "Dismiss") },
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
)
}
}
}
NoticeOverlay(notice)
}
}
@@ -0,0 +1,109 @@
package com.faceclaw.wear.ui
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
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.material.Text
import com.faceclaw.wear.LinkStatus
import com.faceclaw.wear.Notice
import com.faceclaw.wear.PhoneState
/** A transient pill at the bottom of the screen: ack failures and confirmations. */
@Composable
fun NoticeOverlay(notice: Notice?) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) {
AnimatedVisibility(visible = notice != null, enter = fadeIn(), exit = fadeOut()) {
val current = notice ?: return@AnimatedVisibility
Text(
text = current.text,
style = MaterialTheme.typography.caption2,
color = if (current.isError) Color(0xFFFFB4A8) else MaterialTheme.colors.onSurface,
textAlign = TextAlign.Center,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
modifier = Modifier
.padding(horizontal = 28.dp, vertical = 18.dp)
.background(
if (current.isError) Color(0xFF4A1F1A) else Color(0xFF2A2A2A),
RoundedCornerShape(14.dp),
)
.padding(horizontal = 10.dp, vertical = 5.dp),
)
}
}
}
/** The pad's top line: how the glasses and phone are doing, in a few words. */
data class StatusLine(val text: String, val tone: StatusTone)
enum class StatusTone { GOOD, BUSY, OFF, PROBLEM }
fun statusLine(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.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,
)
}
}
@@ -0,0 +1,65 @@
package com.faceclaw.wear.ui
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.graphics.Color
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.wear.compose.material.Colors
import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.navigation.SwipeDismissableNavHost
import androidx.wear.compose.navigation.composable
import androidx.wear.compose.navigation.rememberSwipeDismissableNavController
import com.faceclaw.wear.Haptics
import com.faceclaw.wear.PhoneLink
import com.faceclaw.wear.WatchPrefs
object Routes {
const val REMOTE = "remote"
const val APPS = "apps"
const val ASSISTANT = "assistant"
const val STATUS = "status"
const val SETTINGS = "settings"
}
private val FaceclawColors = Colors(
primary = Color(0xFFB8D8FF),
primaryVariant = Color(0xFF7FB0F0),
secondary = Color(0xFFC9C9C9),
secondaryVariant = Color(0xFF8A8A8A),
onPrimary = Color(0xFF0B1A2E),
onSecondary = Color(0xFF101010),
)
/** Root: the remote pad, with every other screen a swipe-back away. */
@Composable
fun FaceclawWearApp(link: PhoneLink, prefsStore: WatchPrefs, haptics: Haptics) {
val prefs by prefsStore.prefs.collectAsStateWithLifecycle()
val navController = rememberSwipeDismissableNavController()
MaterialTheme(colors = FaceclawColors) {
SwipeDismissableNavHost(navController = navController, startDestination = Routes.REMOTE) {
composable(Routes.REMOTE) {
RemoteScreen(
link = link,
prefs = prefs,
haptics = haptics,
onOpenApps = { navController.navigate(Routes.APPS) },
onOpenAssistant = { navController.navigate(Routes.ASSISTANT) },
onOpenStatus = { navController.navigate(Routes.STATUS) },
)
}
composable(Routes.APPS) {
AppsScreen(link = link, haptics = haptics, onDone = { navController.popBackStack() })
}
composable(Routes.ASSISTANT) {
AssistantScreen(link = link, haptics = haptics)
}
composable(Routes.STATUS) {
StatusScreen(link = link, haptics = haptics, onOpenSettings = { navController.navigate(Routes.SETTINGS) })
}
composable(Routes.SETTINGS) {
SettingsScreen(prefs = prefs, store = prefsStore)
}
}
}
}
@@ -0,0 +1,384 @@
package com.faceclaw.wear.ui
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Arrangement
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.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.focusable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
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
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.input.rotary.onRotaryScrollEvent
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.wear.compose.material.Button
import androidx.wear.compose.material.ButtonDefaults
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.TimeText
import com.faceclaw.wear.Command
import com.faceclaw.wear.FingerTapDetector
import com.faceclaw.wear.Gesture
import com.faceclaw.wear.Haptics
import com.faceclaw.wear.OnBodyMonitor
import com.faceclaw.wear.PhoneLink
import com.faceclaw.wear.Prefs
import com.faceclaw.wear.R
import com.faceclaw.wear.SwipeAction
import com.faceclaw.wear.WristTwistDetector
import kotlinx.coroutines.delay
import kotlin.math.abs
private const val MAX_SWIPE_STEPS = 4
/** A two-finger swipe scrolls this many steps: a "page". */
private const val TWO_FINGER_SWIPE_STEPS = 3
private const val FLASH_MS = 160L
private const val ARROW_LIT_MS = 220L
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 =
* back, hold = long press (released when the finger lifts), two-finger tap =
* the hold menu ("right click"), swipes in four directions = spatial
* navigation (crown and two-finger vertical swipes = plain scrolling, a page
* 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
* the bottom reach the rest.
*/
@Composable
fun RemoteScreen(
link: PhoneLink,
prefs: Prefs,
haptics: Haptics,
onOpenApps: () -> Unit,
onOpenAssistant: () -> Unit,
onOpenStatus: () -> Unit,
) {
val state by link.state.collectAsStateWithLifecycle()
val linkStatus by link.link.collectAsStateWithLifecycle()
val notice by link.notice.collectAsStateWithLifecycle()
val currentPrefs by rememberUpdatedState(prefs)
val view = LocalView.current
var holding by remember { mutableStateOf(false) }
// Brief ring highlight acknowledging a sensor (tip-tap) gesture.
var flashUntil by remember { mutableStateOf(0L) }
var flashing by remember { mutableStateOf(false) }
// 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() }
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).
val padHeight = remember { floatArrayOf(1f) }
val keyboardToApp = rememberKeyboardLauncher(
label = stringResource(R.string.keyboard_label_app),
onResult = { text -> haptics.click(); link.sendText(text) },
onUnavailable = { haptics.error() },
)
fun scroll(gesture: Gesture, steps: Int) {
haptics.tick()
link.sendGesture(gesture, steps)
}
fun light(arrow: Arrow) {
litArrow = arrow
litTick = System.currentTimeMillis()
}
fun click() {
haptics.click()
link.sendGesture(Gesture.CLICK)
}
fun doubleClick() {
haptics.doubleClick()
link.sendGesture(Gesture.DOUBLE_CLICK)
}
/** Run a horizontal-swipe action; `left` says which way the finger went. */
fun perform(action: SwipeAction, left: Boolean) {
when (action) {
SwipeAction.NAVIGATE -> { haptics.click(); link.sendGesture(if (left) Gesture.SWIPE_LEFT else Gesture.SWIPE_RIGHT) }
SwipeAction.SIDEBAR -> { haptics.click(); link.sendCommand(Command.SIDEBAR) }
SwipeAction.DOUBLE_CLICK -> doubleClick()
SwipeAction.CLICK -> click()
SwipeAction.LONG_PRESS -> { haptics.heavy(); link.sendGesture(Gesture.LONG_PRESS) }
SwipeAction.WAKEWORD -> { haptics.click(); link.sendGesture(Gesture.WAKEWORD) }
SwipeAction.NONE -> Unit
}
}
/** Whether a vertical swipe means "up", honouring the natural-scroll preference. */
fun swipeIsUp(dy: Float): Boolean {
// Ring convention: swiping up means up. "Natural" flips it so the
// content follows the finger like a touch screen.
return if (currentPrefs.naturalScroll) dy > 0 else dy < 0
}
val callbacks = remember(link, haptics) {
TouchpadCallbacks(
onTap = { position ->
if (currentPrefs.tapZones) {
// Top third scrolls up, bottom third down, the middle clicks.
val zone = position.y / padHeight[0].coerceAtLeast(1f)
when {
zone < 1f / 3f -> scroll(Gesture.SCROLL_UP, 1)
zone > 2f / 3f -> scroll(Gesture.SCROLL_DOWN, 1)
else -> click()
}
} else {
click()
}
},
onDoubleTap = { _ -> doubleClick() },
// Two fingers = back as well: easier than timing a double-tap.
onTwoFingerTap = { doubleClick() },
onTwoFingerSwipe = { dx, dy ->
if (abs(dy) >= abs(dx)) {
scroll(if (swipeIsUp(dy)) Gesture.SCROLL_UP else Gesture.SCROLL_DOWN, TWO_FINGER_SWIPE_STEPS)
} else {
perform(if (dx < 0) currentPrefs.swipeLeft else currentPrefs.swipeRight, left = dx < 0)
}
},
onLongPressStart = {
holding = true
haptics.heavy()
link.sendGesture(Gesture.LONG_PRESS_START)
},
onLongPressEnd = {
holding = false
haptics.click()
link.sendGesture(Gesture.LONG_PRESS_RELEASE)
},
onSwipe = { dx, dy, _ ->
if (abs(dy) >= abs(dx)) {
// 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)
light(if (up) Arrow.UP else Arrow.DOWN)
scroll(if (up) Gesture.SWIPE_UP else Gesture.SWIPE_DOWN, 1)
} else {
light(if (dx < 0) Arrow.LEFT else Arrow.RIGHT)
perform(if (dx < 0) currentPrefs.swipeLeft else currentPrefs.swipeRight, left = dx < 0)
}
},
)
}
// Motion-sensor gestures only count on a wrist (see OnBodyMonitor).
val onBody = remember { OnBodyMonitor(view.context) }
DisposableEffect(onBody) {
onBody.start()
onDispose { onBody.stop() }
}
// Fingertip (pinch) taps from the motion sensors, only while the pad is up.
val fingerTapsEnabled = prefs.fingerTaps
DisposableEffect(fingerTapsEnabled, link, haptics) {
if (!fingerTapsEnabled) return@DisposableEffect onDispose { }
val detector = FingerTapDetector(
context = view.context,
sensitivity = { currentPrefs.tapSensitivity },
quietUntil = { haptics.quietUntil() },
onBody = { onBody.onBody },
onTap = { flashUntil = System.currentTimeMillis() + FLASH_MS; click() },
onDoubleTap = { flashUntil = System.currentTimeMillis() + FLASH_MS; doubleClick() },
)
detector.start()
onDispose { detector.stop() }
}
// Two quick wrist twists = back, from the gyroscope, only while the pad is up.
val wristTwistEnabled = prefs.wristTwist
DisposableEffect(wristTwistEnabled, link, haptics) {
if (!wristTwistEnabled) return@DisposableEffect onDispose { }
val detector = WristTwistDetector(
context = view.context,
sensitivity = { currentPrefs.twistSensitivity },
quietUntil = { haptics.quietUntil() },
onBody = { onBody.onBody },
onDoubleTwist = { flashUntil = System.currentTimeMillis() + FLASH_MS; doubleClick() },
)
detector.start()
onDispose { detector.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
}
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) {
if (notice?.isError == true) haptics.error()
}
Box(
modifier = Modifier
.fillMaxSize()
.onRotaryScrollEvent { event ->
// Clockwise (positive) scrolls down, as in every Wear list.
crownAccumulator += event.verticalScrollPixels
val threshold = currentPrefs.crownSensitivity.pixelsPerStep
var steps = 0
while (crownAccumulator >= threshold) { crownAccumulator -= threshold; steps++ }
while (crownAccumulator <= -threshold) { crownAccumulator += threshold; steps-- }
// Capped low: a fast twirl otherwise outruns the display.
if (steps > 0) { light(Arrow.DOWN); scroll(Gesture.SCROLL_DOWN, steps.coerceAtMost(2)) }
if (steps < 0) { light(Arrow.UP); scroll(Gesture.SCROLL_UP, (-steps).coerceAtMost(2)) }
true
}
.focusRequester(focusRequester)
.focusable()
.onSizeChanged { padHeight[0] = it.height.toFloat() }
.pointerInput(callbacks) { detectTouchpadGestures(callbacks) },
) {
// The pad: a ring with a d-pad arrow at each compass point (the one
// 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()
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 { "—" }
Text(
text = focus,
style = MaterialTheme.typography.title3,
color = if (holding) MaterialTheme.colors.primary else MaterialTheme.colors.onSurface,
textAlign = TextAlign.Center,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier
.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),
)
Row(
// Four 36dp buttons need 144dp; at this height the round
// display's chord is ~186dp wide, so 36dp margins keep every
// button inside the glass.
modifier = Modifier
.align(Alignment.BottomCenter)
.fillMaxWidth()
.padding(horizontal = 36.dp, vertical = 26.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
PadButton(icon = R.drawable.ic_assistant, description = "Assistant", onClick = onOpenAssistant)
PadButton(icon = R.drawable.ic_keyboard, description = "Type into app", onClick = keyboardToApp)
PadButton(icon = R.drawable.ic_apps, description = "Apps", onClick = onOpenApps)
PadButton(icon = R.drawable.ic_more, description = "Status and settings", onClick = onOpenStatus)
}
}
NoticeOverlay(notice)
}
}
@Composable
private fun ArrowGlyph(glyph: String, lit: Boolean, modifier: Modifier) {
Text(
text = glyph,
style = MaterialTheme.typography.caption1,
color = if (lit) MaterialTheme.colors.primary else Color(0xFF6E6E6E),
textAlign = TextAlign.Center,
modifier = modifier.size(ARROW_SIZE),
)
}
@Composable
private fun PadButton(icon: Int, description: String, onClick: () -> Unit) {
Button(
onClick = onClick,
modifier = Modifier.size(36.dp),
colors = ButtonDefaults.secondaryButtonColors(),
) {
Icon(
painter = painterResource(icon),
contentDescription = description,
modifier = Modifier.size(20.dp),
)
}
}
@@ -0,0 +1,170 @@
package com.faceclaw.wear.ui
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
import androidx.wear.compose.material.Chip
import androidx.wear.compose.material.ChipDefaults
import androidx.wear.compose.material.ListHeader
import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.material.PositionIndicator
import androidx.wear.compose.material.Scaffold
import androidx.wear.compose.material.Switch
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.TimeText
import androidx.wear.compose.material.ToggleChip
import com.faceclaw.wear.BuildConfig
import com.faceclaw.wear.Prefs
import com.faceclaw.wear.WatchPrefs
/** Watch-local preferences: feel of the pad and crown. */
@Composable
fun SettingsScreen(prefs: Prefs, store: WatchPrefs) {
val listState = rememberScalingLazyListState()
Scaffold(
timeText = { TimeText() },
positionIndicator = { PositionIndicator(scalingLazyListState = listState) },
) {
ScalingLazyColumn(state = listState, modifier = Modifier.fillMaxSize()) {
item { ListHeader { Text("Touchpad") } }
item {
ToggleChip(
checked = prefs.haptics,
onCheckedChange = { on -> store.update { it.copy(haptics = on) } },
label = { Text("Vibrate on input") },
toggleControl = { Switch(checked = prefs.haptics) },
modifier = Modifier.fillMaxWidth(),
)
}
item {
ToggleChip(
checked = prefs.keepScreenOn,
onCheckedChange = { on -> store.update { it.copy(keepScreenOn = on) } },
label = { Text("Keep screen on") },
secondaryLabel = { Text("while Faceclaw is in front") },
toggleControl = { Switch(checked = prefs.keepScreenOn) },
modifier = Modifier.fillMaxWidth(),
)
}
item {
ToggleChip(
checked = prefs.naturalScroll,
onCheckedChange = { on -> store.update { it.copy(naturalScroll = on) } },
label = { Text("Natural swipe") },
secondaryLabel = { Text(if (prefs.naturalScroll) "content follows finger" else "swipe up = scroll up (ring)") },
toggleControl = { Switch(checked = prefs.naturalScroll) },
modifier = Modifier.fillMaxWidth(),
)
}
item {
ToggleChip(
checked = prefs.tapZones,
onCheckedChange = { on -> store.update { it.copy(tapZones = on) } },
label = { Text("Tap zones") },
secondaryLabel = { Text("tap top/bottom to scroll") },
toggleControl = { Switch(checked = prefs.tapZones) },
modifier = Modifier.fillMaxWidth(),
)
}
item {
Chip(
onClick = { store.update { it.copy(swipeLeft = it.swipeLeft.next()) } },
label = { Text("Swipe left") },
secondaryLabel = { Text(prefs.swipeLeft.label) },
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
)
}
item {
Chip(
onClick = { store.update { it.copy(swipeRight = it.swipeRight.next()) } },
label = { Text("Swipe right") },
secondaryLabel = { Text(prefs.swipeRight.label) },
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
)
}
item { ListHeader { Text("Tip taps") } }
item {
ToggleChip(
checked = prefs.fingerTaps,
onCheckedChange = { on -> store.update { it.copy(fingerTaps = on) } },
label = { Text("Fingertip taps (experimental)") },
secondaryLabel = { Text("finger to thumb: select / double = back") },
toggleControl = { Switch(checked = prefs.fingerTaps) },
modifier = Modifier.fillMaxWidth(),
)
}
item {
Chip(
onClick = { store.update { it.copy(tapSensitivity = it.tapSensitivity.next()) } },
label = { Text("Tap sensitivity") },
secondaryLabel = { Text(prefs.tapSensitivity.label) },
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
enabled = prefs.fingerTaps,
)
}
item {
Text(
"Experimental: taps are read from the motion sensors while the pad is open, and ignored while the arm is moving.",
style = MaterialTheme.typography.caption3,
color = MaterialTheme.colors.onSurfaceVariant,
textAlign = TextAlign.Center,
)
}
item { ListHeader { Text("Wrist twist") } }
item {
ToggleChip(
checked = prefs.wristTwist,
onCheckedChange = { on -> store.update { it.copy(wristTwist = on) } },
label = { Text("Twist twice = back") },
secondaryLabel = { Text("two quick wrist flicks") },
toggleControl = { Switch(checked = prefs.wristTwist) },
modifier = Modifier.fillMaxWidth(),
)
}
item {
Chip(
onClick = { store.update { it.copy(twistSensitivity = it.twistSensitivity.next()) } },
label = { Text("Twist sensitivity") },
secondaryLabel = { Text(prefs.twistSensitivity.label) },
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
enabled = prefs.wristTwist,
)
}
item { ListHeader { Text("Crown") } }
item {
Chip(
onClick = { store.update { it.copy(crownSensitivity = it.crownSensitivity.next()) } },
label = { Text("Sensitivity") },
secondaryLabel = { Text(prefs.crownSensitivity.label) },
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
)
}
item { ListHeader { Text("Buttons") } }
item {
Text(
"Side button 1: tap = select, hold = long press.\nButton 2: back.\nButton 3: “Hey Even”.",
style = MaterialTheme.typography.caption2,
color = MaterialTheme.colors.onSurfaceVariant,
textAlign = TextAlign.Center,
)
}
item {
Text(
"Faceclaw watch v${BuildConfig.VERSION_NAME}",
style = MaterialTheme.typography.caption3,
color = MaterialTheme.colors.onSurfaceVariant,
textAlign = TextAlign.Center,
)
}
}
}
}
@@ -0,0 +1,171 @@
package com.faceclaw.wear.ui
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
import androidx.wear.compose.material.Chip
import androidx.wear.compose.material.ChipDefaults
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.ListHeader
import androidx.wear.compose.material.PositionIndicator
import androidx.wear.compose.material.Scaffold
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.TimeText
import com.faceclaw.wear.Command
import com.faceclaw.wear.DisplayMode
import com.faceclaw.wear.Haptics
import com.faceclaw.wear.PhoneLink
import com.faceclaw.wear.R
/** Glasses and phone status, with the connection / display / lock switches. */
@Composable
fun StatusScreen(link: PhoneLink, haptics: Haptics, onOpenSettings: () -> Unit) {
val state by link.state.collectAsStateWithLifecycle()
val linkStatus by link.link.collectAsStateWithLifecycle()
val notice by link.notice.collectAsStateWithLifecycle()
val listState = rememberScalingLazyListState()
val connected = state?.connected == true
Scaffold(
timeText = { TimeText() },
positionIndicator = { PositionIndicator(scalingLazyListState = listState) },
) {
ScalingLazyColumn(state = listState, modifier = Modifier.fillMaxSize()) {
item { ListHeader { Text("Glasses") } }
item {
val phaseLabel = when {
state == null -> "No status yet"
connected -> "Connected" + (state?.battery?.let { " · $it%" } ?: "") + if (state?.charging == true) " charging" else ""
state?.phase == "connecting" -> "Connecting…"
state?.phase == "disconnecting" -> "Disconnecting…"
else -> "Disconnected"
}
Chip(
onClick = {
haptics.click()
link.sendCommand(if (connected) Command.DISCONNECT else Command.CONNECT)
},
label = { Text(phaseLabel, maxLines = 1, overflow = TextOverflow.Ellipsis) },
secondaryLabel = { Text(if (connected) "tap to disconnect" else "tap to connect") },
colors = if (connected) ChipDefaults.primaryChipColors() else ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
enabled = linkStatus.appRunning != false,
)
}
item {
val on = state?.screenOn == true
Chip(
onClick = {
haptics.click()
link.sendCommand(if (on) Command.SLEEP else Command.WAKE)
},
label = { Text(if (on) "Display on" else "Display off") },
secondaryLabel = { Text(if (on) "tap to turn off" else "tap to wake") },
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
enabled = connected && state?.locked != true,
)
}
item {
val locked = state?.locked == true
Chip(
onClick = {
haptics.click()
link.sendCommand(if (locked) Command.UNLOCK else Command.LOCK)
},
label = { Text(if (locked) "Locked" else "Unlocked") },
secondaryLabel = {
Text(
when {
locked && state?.canUnlock == false -> "unlock from the phone"
locked -> "tap to unlock"
else -> "tap to lock"
},
)
},
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
enabled = connected && !(locked && state?.canUnlock == false),
)
}
item {
val mode = DisplayMode.fromWire(state?.displayMode ?: "") ?: DisplayMode.BAND
Chip(
onClick = {
haptics.click()
link.sendCommand(Command.DISPLAY_MODE, "value" to mode.next().wire)
},
label = { Text("Display mode") },
secondaryLabel = { Text(mode.label) },
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
enabled = connected,
)
}
state?.foreground?.let { foreground ->
item {
Chip(
onClick = { haptics.click(); link.sendCommand(Command.SIDEBAR) },
label = { Text("On screen: ${foreground.title}", maxLines = 1, overflow = TextOverflow.Ellipsis) },
secondaryLabel = { Text("tap to open the sidebar") },
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
enabled = connected,
)
}
}
item { ListHeader { Text("Phone") } }
item {
val phoneLabel = when {
!linkStatus.phoneReachable -> "No phone connected"
!linkStatus.phoneAppInstalled -> "Faceclaw not installed"
linkStatus.appRunning == false -> "Faceclaw not running"
else -> linkStatus.phoneName.ifBlank { "Phone" }
}
val detail = when {
!linkStatus.phoneReachable -> "check Bluetooth"
!linkStatus.phoneAppInstalled -> "install it on the phone"
linkStatus.appRunning == false -> "open it on the phone"
state?.version?.isNotBlank() == true -> "Faceclaw v${state?.version}"
else -> "tap to refresh"
}
Chip(
onClick = { haptics.click(); link.refresh() },
label = { Text(phoneLabel, maxLines = 1, overflow = TextOverflow.Ellipsis) },
secondaryLabel = { Text(detail) },
icon = { Icon(painterResource(R.drawable.ic_refresh), contentDescription = null, modifier = Modifier.size(20.dp)) },
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
)
}
if (state?.remoteEnabled == false) {
item {
Text(
"Watch control is turned off in Faceclaw's Settings > Watch.",
style = androidx.wear.compose.material.MaterialTheme.typography.caption2,
)
}
}
item {
Chip(
onClick = onOpenSettings,
label = { Text("Watch settings") },
icon = { Icon(painterResource(R.drawable.ic_settings), contentDescription = null, modifier = Modifier.size(20.dp)) },
colors = ChipDefaults.secondaryChipColors(),
modifier = Modifier.fillMaxWidth(),
)
}
}
NoticeOverlay(notice)
}
}
@@ -0,0 +1,82 @@
package com.faceclaw.wear.ui
import android.app.Activity
import android.app.RemoteInput
import android.content.ActivityNotFoundException
import android.content.Intent
import android.speech.RecognizerIntent
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberUpdatedState
import androidx.wear.input.RemoteInputIntentHelper
private const val REMOTE_INPUT_KEY = "faceclaw_text"
/**
* The watch's own speech recognizer (the system's, so it works with the
* wrist raised and no glasses mic involved). Returns a launcher; the
* recognized text arrives in onResult.
*/
@Composable
fun rememberSpeechLauncher(
prompt: String,
onResult: (String) -> Unit,
onUnavailable: () -> Unit,
): () -> Unit {
val currentOnResult = rememberUpdatedState(onResult)
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode != Activity.RESULT_OK) return@rememberLauncherForActivityResult
val text = result.data
?.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
?.firstOrNull()
?.trim()
if (!text.isNullOrEmpty()) currentOnResult.value(text)
}
return {
val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt)
try {
launcher.launch(intent)
} catch (error: ActivityNotFoundException) {
onUnavailable()
}
}
}
/**
* The Wear OS text entry sheet (keyboard / voice / handwriting, whatever the
* watch offers). Returns a launcher; the entered text arrives in onResult.
*/
@Composable
fun rememberKeyboardLauncher(
label: String,
onResult: (String) -> Unit,
onUnavailable: () -> Unit,
): () -> Unit {
val currentOnResult = rememberUpdatedState(onResult)
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode != Activity.RESULT_OK) return@rememberLauncherForActivityResult
val data = result.data ?: return@rememberLauncherForActivityResult
val text = RemoteInput.getResultsFromIntent(data)
?.getCharSequence(REMOTE_INPUT_KEY)
?.toString()
?.trim()
if (!text.isNullOrEmpty()) currentOnResult.value(text)
}
return {
val remoteInput = RemoteInput.Builder(REMOTE_INPUT_KEY)
.setLabel(label)
.setAllowFreeFormInput(true)
.build()
val intent = RemoteInputIntentHelper.createActionRemoteInputIntent()
RemoteInputIntentHelper.putRemoteInputsExtra(intent, listOf(remoteInput))
RemoteInputIntentHelper.putTitleExtra(intent, label)
try {
launcher.launch(intent)
} catch (error: ActivityNotFoundException) {
onUnavailable()
}
}
}
@@ -0,0 +1,105 @@
package com.faceclaw.wear.ui
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.waitForUpOrCancellation
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.PointerInputScope
import androidx.compose.ui.input.pointer.positionChanged
/** What the remote's touch surface can report. */
class TouchpadCallbacks(
val onTap: (position: Offset) -> Unit,
val onDoubleTap: (position: Offset) -> Unit,
val onTwoFingerTap: () -> Unit,
/** Two fingers travelled past touch slop; dx/dy are the primary finger's displacement. */
val onTwoFingerSwipe: (dx: Float, dy: Float) -> Unit,
val onLongPressStart: () -> Unit,
val onLongPressEnd: () -> Unit,
/** Finger travelled past touch slop; dx/dy are the total displacement. */
val onSwipe: (dx: Float, dy: Float, durationMs: Long) -> Unit,
)
/**
* One detector for everything the pad does, so a gesture is reported exactly
* once: tap, double-tap (a second tap inside the double-tap timeout), a hold
* (reported at the long-press timeout and again on release), a swipe, and a
* two-finger tap or swipe. Written as a single awaitEachGesture loop because the
* stock detectors would each claim the same finger.
*/
suspend fun PointerInputScope.detectTouchpadGestures(callbacks: TouchpadCallbacks) {
val longPressTimeout = viewConfiguration.longPressTimeoutMillis
val doubleTapTimeout = viewConfiguration.doubleTapTimeoutMillis
val slop = viewConfiguration.touchSlop
awaitEachGesture {
val down = awaitFirstDown()
down.consume()
val downTime = down.uptimeMillis
var maxPointers = 1
var moved = false
var longPressed = false
var displacement = Offset.Zero
var releaseTime = downTime
while (true) {
val remaining = if (longPressed || moved || maxPointers > 1) {
HOLD_POLL_MS
} else {
longPressTimeout - (System.currentTimeMillis() - wallClockAt(downTime))
}
val event = withTimeoutOrNull(remaining.coerceAtLeast(1L)) { awaitPointerEvent() }
if (event == null) {
if (!longPressed && !moved && maxPointers == 1) {
longPressed = true
callbacks.onLongPressStart()
}
continue
}
// Something above us (the system, a parent) took the gesture:
// Compose reports that as already-consumed changes. Drop it rather
// than mistaking the cancellation for a tap.
if (event.changes.any { it.isConsumed }) break
val pressedCount = event.changes.count { it.pressed }
if (pressedCount > maxPointers) maxPointers = pressedCount
val primary = event.changes.firstOrNull { it.id == down.id } ?: event.changes.first()
if (primary.positionChanged()) {
displacement = primary.position - down.position
if (!moved && !longPressed && displacement.getDistance() > slop) moved = true
}
for (change in event.changes) change.consume()
if (pressedCount > 0) continue
releaseTime = event.changes.maxOf { it.uptimeMillis }
val duration = releaseTime - downTime
when {
longPressed -> callbacks.onLongPressEnd()
maxPointers >= 2 -> if (moved) callbacks.onTwoFingerSwipe(displacement.x, displacement.y) else callbacks.onTwoFingerTap()
moved -> callbacks.onSwipe(displacement.x, displacement.y, duration)
else -> {
// A plain tap; give a second tap a chance to make it a double.
val second = withTimeoutOrNull(doubleTapTimeout) { awaitFirstDown() }
if (second == null) {
callbacks.onTap(down.position)
} else {
second.consume()
val up = waitForUpOrCancellation()
if (up != null) up.consume()
callbacks.onDoubleTap(down.position)
}
}
}
break
}
}
}
/** Poll interval while a hold or drag is in progress (no timeout semantics needed). */
private const val HOLD_POLL_MS = 60_000L
/**
* Pointer timestamps are SystemClock.uptimeMillis; map one to wall-clock so the
* remaining long-press time can be computed without a second clock.
*/
private fun wallClockAt(uptimeMillis: Long): Long =
System.currentTimeMillis() - (android.os.SystemClock.uptimeMillis() - uptimeMillis)
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M4,8h4L8,4L4,4v4zM10,20h4v-4h-4v4zM4,20h4v-4L4,16v4zM4,14h4v-4L4,10v4zM10,14h4v-4h-4v4zM16,4v4h4L20,4h-4zM10,8h4L14,4h-4v4zM16,14h4v-4h-4v4zM16,20h4v-4h-4v4z" />
</vector>
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M19,9l1.25,-2.75L23,5l-2.75,-1.25L19,1l-1.25,2.75L15,5l2.75,1.25L19,9zM11.5,9.5L9,4 6.5,9.5 1,12l5.5,2.5L9,20l2.5,-5.5L17,12l-5.5,-2.5zM19,15l-1.25,2.75L15,19l2.75,1.25L19,23l1.25,-2.75L23,19l-2.75,-1.25L19,15z" />
</vector>
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z" />
</vector>
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M20,5L4,5c-1.1,0 -1.99,0.9 -1.99,2L2,17c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,7c0,-1.1 -0.9,-2 -2,-2zM11,8h2v2h-2L11,8zM11,11h2v2h-2v-2zM8,8h2v2L8,10L8,8zM8,11h2v2L8,13v-2zM7,13L5,13v-2h2v2zM7,10L5,10L5,8h2v2zM16,17L8,17v-2h8v2zM16,13h-2v-2h2v2zM16,10h-2L14,8h2v2zM19,13h-2v-2h2v2zM19,10h-2L17,8h2v2z" />
</vector>
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<group android:scaleX="0.07382812"
android:scaleY="0.07382812"
android:translateX="16.2"
android:translateY="16.2">
<path
android:pathData="M843,511.86L843,512.96C843,513.22 842.8,513.43 842.55,513.46C809.18,516.58 783.07,543.69 783.07,577.86L783.07,714.8C783.07,724.37 781.06,733.6 777.43,742.03C767.08,766.1 743.59,783.6 716.27,783.6L647.07,783.6L646.59,783L377.41,445.68L377.41,783.6L307.73,783.6C270.84,783.6 240.93,753.7 240.93,716.8L240.93,577.86C240.93,543.69 214.82,516.58 181.45,513.46C181.2,513.43 181,513.22 181,512.96L181,511.86C181,511.61 181.19,511.4 181.45,511.37C214.69,508.14 240.67,480.35 240.67,446.26L240.67,307.2C240.67,297.91 242.57,289.05 246,281.01C256.18,257.14 279.87,240.39 307.47,240.39L377.13,240.39L377.41,240.74L646.59,578.07L646.59,240.39L716.53,240.39C753.42,240.39 783.33,270.3 783.33,307.2L783.33,446.26C783.33,480.35 809.31,508.14 842.55,511.37C842.81,511.4 843,511.61 843,511.86"
android:fillColor="#65ADF1"
android:fillType="nonZero"/>
</group>
</vector>
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M12,14c1.66,0 2.99,-1.34 2.99,-3L15,5c0,-1.66 -1.34,-3 -3,-3S9,3.34 9,5v6c0,1.66 1.34,3 3,3zM17.3,11c0,3 -2.54,5.1 -5.3,5.1S6.7,14 6.7,11L5,11c0,3.41 2.72,6.23 6,6.72L11,21h2v-3.28c3.28,-0.48 6,-3.3 6,-6.72h-1.7z" />
</vector>
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M6,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM18,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z" />
</vector>
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z" />
</vector>
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94 0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6 3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z" />
</vector>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#00000000</color>
</resources>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Faceclaw</string>
<string name="speech_prompt_assistant">Ask the assistant</string>
<string name="speech_prompt_app">Say what to type</string>
<string name="keyboard_label_assistant">Ask the assistant</string>
<string name="keyboard_label_app">Type into the app</string>
</resources>
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- The pad uses rightward swipes as input, so the system's whole-window
swipe-to-dismiss is off; the crown/home button leaves the app, and
inner screens still swipe back through SwipeDismissableNavHost. -->
<style name="Theme.Faceclaw" parent="@android:style/Theme.DeviceDefault">
<item name="android:windowSwipeToDismiss">false</item>
</style>
</resources>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Advertised over the Wearable Data Layer; the phone app targets its
messages at nodes with this capability (FaceclawWearBridge). -->
<resources>
<string-array name="android_wear_capabilities">
<item>faceclaw_watch</item>
</string-array>
</resources>
+9
View File
@@ -0,0 +1,9 @@
// Faceclaw watch app (Wear OS companion). A standalone Gradle project: it
// shares nothing with the NativeScript build except the applicationId and
// (for release builds) the signing key, both of which the Wearable Data
// Layer requires to match the phone app.
plugins {
id("com.android.application") version "8.7.3" apply false
id("org.jetbrains.kotlin.android") version "2.1.10" apply false
id("org.jetbrains.kotlin.plugin.compose") version "2.1.10" apply false
}
+4
View File
@@ -0,0 +1,4 @@
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
android.useAndroidX=true
android.nonTransitiveRClass=true
kotlin.code.style=official
Binary file not shown.
+7
View File
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored Executable
+240
View File
@@ -0,0 +1,240 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
+91
View File
@@ -0,0 +1,91 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
+16
View File
@@ -0,0 +1,16 @@
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "faceclaw-wear"
include(":app")