UI changes, system status icons

This commit is contained in:
James Babcock committed 2026-04-27 03:05:53 -07:00
1 parent 6e442e7faa
commit b5273715ae
14 files changed
+830 -236

No files matched your search

+30 -1
View File
@@ -19,6 +19,12 @@ export type HeadsetBatteryState = {
chargingStatus: number;
};
export type FrameMetrics = {
paintMs: number;
transmitMs: number;
tileCount: number;
};
export type RawInputEvent =
| {
kind: "list-click";
@@ -51,6 +57,11 @@ function toJavaByteArray(bytes: Uint8Array): number[] {
return out;
}
function nonNegativeNumber(value: number): number {
const numeric = Number(value);
return Number.isFinite(numeric) ? Math.max(0, numeric) : 0;
}
export class FaceclawCommunicatorBridge {
private readonly communicator: any;
private readonly listenerProxy: any;
@@ -59,6 +70,7 @@ export class FaceclawCommunicatorBridge {
private readonly ringListeners = new Set<(event: RawInputEvent) => void>();
private readonly batteryListeners = new Set<(state: HeadsetBatteryState) => void>();
private readonly evenAppConflictListeners = new Set<(message: string) => void>();
private readonly frameMetricsListeners = new Set<(metrics: FrameMetrics) => void>();
constructor(addresses: { right: string; left: string; ring?: string }) {
const context = Utils.android.getApplicationContext();
@@ -117,6 +129,16 @@ export class FaceclawCommunicatorBridge {
listener(String(message));
}
},
onFrameMetrics: (paintMs: number, transmitMs: number, tileCount: number) => {
const metrics = {
paintMs: nonNegativeNumber(paintMs),
transmitMs: nonNegativeNumber(transmitMs),
tileCount: nonNegativeNumber(tileCount),
};
for (const listener of this.frameMetricsListeners) {
listener(metrics);
}
},
});
this.communicator.setListener(this.listenerProxy);
}
@@ -146,11 +168,16 @@ export class FaceclawCommunicatorBridge {
return () => this.evenAppConflictListeners.delete(listener);
}
onFrameMetrics(listener: (metrics: FrameMetrics) => void): () => void {
this.frameMetricsListeners.add(listener);
return () => this.frameMetricsListeners.delete(listener);
}
async start(): Promise<void> {
this.communicator.start();
}
async submitDashboardImage(tileBmps: Uint8Array[], fingerprint: string): Promise<void> {
async submitDashboardImage(tileBmps: Uint8Array[], fingerprint: string, forceTiledCommit = false, paintMs = -1): Promise<void> {
if (tileBmps.length !== 4) {
throw new Error(`expected 4 dashboard tiles, got ${tileBmps.length}`);
}
@@ -160,6 +187,8 @@ export class FaceclawCommunicatorBridge {
toJavaByteArray(tileBmps[2]!),
toJavaByteArray(tileBmps[3]!),
fingerprint,
forceTiledCommit,
Math.round(nonNegativeNumber(paintMs)),
);
}
+12 -13
View File
@@ -1,8 +1,9 @@
import { ImageSource, Screen, Utils } from "@nativescript/core";
import { ImageSource } from "@nativescript/core";
import { type GrayImage } from "../graphics/image";
const PREVIEW_BRIGHTEN_GAMMA = 0.7;
const PREVIEW_COLOR_LUT = buildPreviewColorLookup();
export function grayImageToPreviewSource(image: GrayImage): ImageSource | null {
if (!global.isAndroid) {
@@ -11,8 +12,7 @@ export function grayImageToPreviewSource(image: GrayImage): ImageSource | null {
const colors = Array.create("int", image.width * image.height) as number[];
for (let i = 0; i < image.pixels.length; i++) {
const gray = brightenForPreview(image.pixels[i] ?? 0);
colors[i] = (255 << 24) | (gray << 16) | (gray << 8) | gray;
colors[i] = PREVIEW_COLOR_LUT[image.pixels[i] ?? 0]!;
}
const bitmap = android.graphics.Bitmap.createBitmap(
@@ -21,16 +21,15 @@ export function grayImageToPreviewSource(image: GrayImage): ImageSource | null {
image.height,
android.graphics.Bitmap.Config.ARGB_8888,
);
const targetWidth = Math.max(1, Math.round(Utils.layout.toDevicePixels(Screen.mainScreen.widthDIPs)));
const targetHeight = Math.max(1, Math.round((targetWidth * image.height) / image.width));
const scaledBitmap =
bitmap.getWidth() === targetWidth && bitmap.getHeight() === targetHeight
? bitmap
: android.graphics.Bitmap.createScaledBitmap(bitmap, targetWidth, targetHeight, false);
return new ImageSource(scaledBitmap);
return new ImageSource(bitmap);
}
function brightenForPreview(gray: number): number {
const normalized = Math.max(0, Math.min(255, gray)) / 255;
return Math.max(0, Math.min(255, Math.round(255 * Math.pow(normalized, PREVIEW_BRIGHTEN_GAMMA))));
function buildPreviewColorLookup(): number[] {
const colors: number[] = [];
for (let gray = 0; gray <= 255; gray++) {
const normalized = gray / 255;
const preview = Math.max(0, Math.min(255, Math.round(255 * Math.pow(normalized, PREVIEW_BRIGHTEN_GAMMA))));
colors[gray] = (255 << 24) | (preview << 16) | (preview << 8) | preview;
}
return colors;
}
+54
View File
@@ -0,0 +1,54 @@
import { Utils } from "@nativescript/core";
import { GrayImage } from "../graphics/image";
declare const com: any;
const ICON_SIZE = 24;
const ICON_CACHE_MS = 5_000;
let cachedIcons: GrayImage[] = [];
let cachedAtMs = 0;
export function readSystemStatusIcons(): GrayImage[] {
if (!global.isAndroid) return [];
const now = Date.now();
if (now - cachedAtMs < ICON_CACHE_MS) {
return cachedIcons.map(cloneGrayImage);
}
const context = Utils.android.getApplicationContext();
if (!context) return [];
const bytes = toUint8Array(
com.faceclaw.app.FaceclawSystemStatusIconProvider.getSystemStatusIconGrays(context, ICON_SIZE),
);
const iconByteLength = ICON_SIZE * ICON_SIZE;
const iconCount = Math.floor(bytes.length / iconByteLength);
const icons: GrayImage[] = [];
for (let index = 0; index < iconCount; index++) {
const icon = new GrayImage(ICON_SIZE, ICON_SIZE, 0);
icon.pixels.set(bytes.subarray(index * iconByteLength, (index + 1) * iconByteLength));
icons.push(icon);
}
cachedIcons = icons;
cachedAtMs = now;
return icons.map(cloneGrayImage);
}
function toUint8Array(bytes: ArrayLike<number> | null | undefined): Uint8Array {
if (!bytes) return new Uint8Array(0);
const out = new Uint8Array(bytes.length);
for (let i = 0; i < bytes.length; i++) {
out[i] = bytes[i]! & 0xff;
}
return out;
}
function cloneGrayImage(image: GrayImage): GrayImage {
const clone = new GrayImage(image.width, image.height, 0);
clone.pixels.set(image.pixels);
return clone;
}