UI improvements

Menus can paginate and be taller than quarter-screen. Text config
setting editor selects all on enter, exits on confirm. Notification
icons are displayed on the notifications-list and single-notification
pages.
This commit is contained in:
James Babcock committed 2026-07-04 15:02:09 -07:00
1 parent 049824f489
commit d2a942f5a3
11 files changed
+223 -26

No files matched your search

@@ -183,6 +183,31 @@ public class FaceclawMediaNotificationListenerService extends NotificationListen
return out.toByteArray();
}
/**
* Grayscale icon (iconSize*iconSize bytes) for one active notification,
* identified by its key; empty array when the notification or its icon is
* unavailable. Shares the extraction/scaling pipeline with the tray icon
* strip above.
*/
public static byte[] getNotificationIconGrayForKey(String key, int iconSize) {
FaceclawMediaNotificationListenerService service = activeService;
int size = Math.max(1, Math.min(96, iconSize));
if (service == null) {
return new byte[0];
}
StatusBarNotification statusBarNotification = findActiveNotificationByKey(service, key);
if (statusBarNotification == null || statusBarNotification.getNotification() == null) {
return new byte[0];
}
Drawable drawable = loadNotificationIcon(service, statusBarNotification.getNotification());
if (drawable == null) {
return new byte[0];
}
ByteArrayOutputStream out = new ByteArrayOutputStream(size * size);
appendIconGrayBytes(drawable, size, out, service, -1, statusBarNotification.getPackageName());
return out.toByteArray();
}
public static String getActiveNotificationsJson(int maxNotifications) {
FaceclawMediaNotificationListenerService service = activeService;
int limit = Math.max(0, Math.min(100, maxNotifications));
@@ -484,6 +509,9 @@ public class FaceclawMediaNotificationListenerService extends NotificationListen
* runs at most once per icon-cache refresh on tiny bitmaps.
*/
private static void dumpIconDebugPng(FaceclawMediaNotificationListenerService service, int index, String packageName, Bitmap bitmap) {
if (index < 0) {
return;
}
try {
java.io.File dir = new java.io.File(service.getExternalFilesDir(null), "debug-icons");
if (!dir.exists() && !dir.mkdirs()) {
+18
View File
@@ -16,6 +16,7 @@ import { voiceControlBridge } from "../native/voice-control";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
import {
applyDashboardScreenTimeout,
closeDashboardTextSettingEditor,
dashboardState,
drawDashboard,
noteDashboardPhoneTextInput,
@@ -530,6 +531,23 @@ class DashboardController {
}
}
/**
* Finish the active edit from the phone side (e.g. the IME's done key):
* ends the edit session and navigates the glasses out of the edit page.
*/
finishActiveTextSettingEdit(): void {
if (!this.activeTextSetting) return;
this.endTextSettingEdit();
if (!closeDashboardTextSettingEditor()) return;
if (this.phase === "connected" && this.communicator) {
void this.requestRender("interval").catch((error) => {
this.appendLog(`edit close render failed: ${this.formatError(error)}`);
});
} else {
this.updateDisplayPreviewFromImage(drawDashboard());
}
}
private updateTextSetting(setting: ConfigSettingString, value: string): void {
if (setting.get() !== value) {
setting.set(value);
+59 -3
View File
@@ -9,9 +9,16 @@ const ICON_CACHE_MS = 5_000;
let cachedIcons: GrayImage[] = [];
let cachedAtMs = 0;
const keyedIconCache = new Map<string, { icon: GrayImage | null; atMs: number }>();
const KEYED_ICON_CACHE_MAX = 128;
let notificationListenerProxy: any | null = null;
const notificationPostedListeners = new Set<(notificationKey: string) => void>();
function invalidateIconCaches(): void {
cachedAtMs = 0;
keyedIconCache.clear();
}
export type AndroidNotificationAction = {
index: number;
title: string;
@@ -84,6 +91,55 @@ export function readActiveNotificationIcons(maxIcons: number, allowStale: boolea
return { icons: icons.map(icon => icon.clone()), stale: false };
}
export type NotificationIconResult = {
icon: GrayImage | null;
/** True when the icon came from an expired (or empty) cache under allowStale. */
stale: boolean;
};
/**
* Icon for one notification, identified by its key, with the same allow-stale
* contract as readActiveNotificationIcons: an allowStale call never blocks on
* the notification listener service, and stale=true asks the caller to repaint
* with allowStale=false once the current frame is done. A null icon with
* stale=false is definitive (notification gone or icon unavailable) and is
* cached too, so failing icons do not refetch every paint.
*/
export function readNotificationIconByKey(key: string, allowStale: boolean): NotificationIconResult {
if (!global.isAndroid || !key) return { icon: null, stale: false };
const now = Date.now();
const cached = keyedIconCache.get(key);
if (cached && now - cached.atMs < ICON_CACHE_MS) {
return { icon: cached.icon?.clone() ?? null, stale: false };
}
if (allowStale) {
return { icon: cached?.icon?.clone() ?? null, stale: true };
}
const bytes = spanCurrent("fetch-notification-icon", () =>
toUint8Array(
com.faceclaw.app.FaceclawMediaNotificationListenerService.getNotificationIconGrayForKey(
key,
ICON_SIZE,
),
),
);
let icon: GrayImage | null = null;
if (bytes.length >= ICON_SIZE * ICON_SIZE) {
icon = new GrayImage(ICON_SIZE, ICON_SIZE, 0);
icon.pixels.set(bytes.subarray(0, ICON_SIZE * ICON_SIZE));
}
keyedIconCache.delete(key);
keyedIconCache.set(key, { icon, atMs: now });
while (keyedIconCache.size > KEYED_ICON_CACHE_MAX) {
const oldestKey = keyedIconCache.keys().next().value;
if (oldestKey === undefined) break;
keyedIconCache.delete(oldestKey);
}
return { icon: icon?.clone() ?? null, stale: false };
}
export function readActiveNotifications(maxNotifications = 50): AndroidNotification[] {
if (!global.isAndroid || maxNotifications <= 0) return [];
try {
@@ -104,7 +160,7 @@ export function readActiveNotifications(maxNotifications = 50): AndroidNotificat
export function invokeNotificationAction(notificationKey: string, actionIndex: number): boolean {
if (!global.isAndroid || !notificationKey) return false;
cachedAtMs = 0;
invalidateIconCaches();
return Boolean(
com.faceclaw.app.FaceclawMediaNotificationListenerService.invokeNotificationAction(
notificationKey,
@@ -115,7 +171,7 @@ export function invokeNotificationAction(notificationKey: string, actionIndex: n
export function dismissNotification(notificationKey: string): boolean {
if (!global.isAndroid || !notificationKey) return false;
cachedAtMs = 0;
invalidateIconCaches();
return Boolean(
com.faceclaw.app.FaceclawMediaNotificationListenerService.dismissNotification(notificationKey),
);
@@ -161,7 +217,7 @@ function ensureNotificationPostedListener(): void {
if (!global.isAndroid || notificationListenerProxy) return;
notificationListenerProxy = new com.faceclaw.app.FaceclawNotificationListener({
onNotificationPosted: (notificationKey: string) => {
cachedAtMs = 0;
invalidateIconCaches();
const key = String(notificationKey);
const listeners = Array.from(notificationPostedListeners);
setTimeout(() => {
+3
View File
@@ -74,6 +74,9 @@ function applySettingsTextFieldContrast(textField: TextField): void {
nativeTextField.setTextColor(android.graphics.Color.rgb(34, 34, 34))
nativeTextField.setHintTextColor(android.graphics.Color.rgb(102, 102, 102))
// Editing an existing value usually means replacing it: select all on focus
// so typing starts fresh but the current value stays visible.
nativeTextField.setSelectAllOnFocus(true)
}
function focusSystemNameField(page: Page): void {
+1
View File
@@ -71,6 +71,7 @@
id="settingsTextField"
text="{{ activeTextSettingValue }}"
textChange="{{ onTextSettingTextChange }}"
returnPress="{{ onTextSettingReturnPress }}"
autocorrect="false"
autocapitalizationType="words"
returnKeyType="done" />
+4
View File
@@ -295,6 +295,10 @@ export class MainViewModel extends Observable {
dashboardController.setActiveTextSettingValue(args.object?.text ?? args.value ?? "");
}
onTextSettingReturnPress(): void {
dashboardController.finishActiveTextSettingEdit();
}
onOpenEvenAppSettingsTap(): void {
dashboardController.openEvenAppSettings();
}
+6 -3
View File
@@ -1,5 +1,6 @@
import { ApplicationSettings } from "@nativescript/core";
import { getDefaultSmallFont } from "~/graphics/bdffont";
import { wrapText } from "~/graphics/textwrap";
import { drawRightValueMenuItem, drawToggleMenuItem, MenuItem, MenuLayer } from "./menu";
import { DashboardInputEvent, Layer, type LayerContext } from "./layers";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "~/graphics/image";
@@ -403,7 +404,7 @@ function truncateSetting(value: string, maxLength = 22): string {
return text.length <= maxLength ? text : `${text.slice(0, Math.max(0, maxLength - 3))}...`;
}
class EditTextSettingLayer implements Layer {
export class EditTextSettingLayer implements Layer {
constructor(private readonly setting: ConfigSettingString) {}
paint(): GrayImage {
@@ -411,8 +412,10 @@ class EditTextSettingLayer implements Layer {
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
image.drawRect(12, 12, G2_LENS_WIDTH - 24, G2_LENS_HEIGHT - 24, 52);
image.drawText(font, 22, 16, this.setting.glassesEditTitle, 220);
image.drawText(font, 22, 52, "Look at the phone app", 200);
image.drawText(font, 22, 70, "to type a value.", 200);
const message = wrapText(font, "Look at the phone app to type a value.", G2_LENS_WIDTH - 48);
for (let index = 0; index < message.length; index++) {
image.drawText(font, 22, 52 + index * 14, message[index]!, 200);
}
image.drawText(font, 22, 110, truncateSetting(this.setting.get(), 52), 220);
image.drawText(font, 22, 252, "Double-click to go back", 110);
return image;
+10 -2
View File
@@ -5,7 +5,7 @@ import { mediaControllerBridge } from "../native/media-controller";
import { nightscoutBridge } from "../native/nightscout-bridge";
import { EventSourceType, OsEventTypeList } from "../g2/events";
import { getDashboardPlugin, type DashboardPluginCardBounds, type DashboardPluginState } from "./dashboard-plugins";
import { isNightscoutSettingsConfigured, screenTimeoutSettingToMs, screenTimeoutSetting, type DashboardSlotId, DashboardPluginId, bottomRightSlotSetting, bottomLeftSlotSetting, dashboardSlotIds } from "./dashboard-settings";
import { EditTextSettingLayer, isNightscoutSettingsConfigured, screenTimeoutSettingToMs, screenTimeoutSetting, type DashboardSlotId, DashboardPluginId, bottomRightSlotSetting, bottomLeftSlotSetting, dashboardSlotIds } from "./dashboard-settings";
import { Layer, LayerActions, LayerStack, type DashboardInputEvent, type LayerContext } from "./layers";
import { SingleNotificationLayer } from "./notifications";
import { TelepromptLayer } from "./apps/teleprompt";
@@ -51,7 +51,7 @@ const dashboardActions: LayerActions = {
playBuzzerNote: () => {},
};
const dashboardFont = getDefaultSmallFont();
export const TOP_LEFT_MENU_LAYOUT = { x: 8, y: 8, width: 272, height: 128 };
export const TOP_LEFT_MENU_LAYOUT = { x: 8, y: 8, width: 272 };
function rawInputEventToInputEvent(event: RawInputEvent): DashboardInputEvent {
if (event.kind === "sys-event") {
@@ -136,6 +136,14 @@ export function setDashboardActions(actions: Partial<LayerActions>): void {
dashboardLayers.setActions(actions);
}
/**
* Close the glasses-side text-setting edit page, e.g. when the user finishes
* typing on the phone. Returns whether the display changed.
*/
export function closeDashboardTextSettingEditor(): boolean {
return dashboardLayers.popIfTop((layer) => layer instanceof EditTextSettingLayer);
}
export function drawDashboard(): GrayImage {
if (!dashboardState.screenOn) {
return new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
+9
View File
@@ -57,6 +57,15 @@ export class LayerStack {
}
}
/** Pop the top layer only if it matches; returns whether a layer was popped. */
popIfTop(predicate: (layer: Layer) => boolean): boolean {
if (this.layers.length > 1 && predicate(this.layers[this.layers.length - 1]!)) {
this.layers.pop();
return true;
}
return false;
}
clearToBase(): void {
this.layers.splice(1);
}
+53 -12
View File
@@ -1,14 +1,18 @@
import { GrayImage } from "../graphics/image";
import { G2_LENS_HEIGHT, GrayImage } from "../graphics/image";
import { wrapText } from "../graphics/textwrap";
import { getDefaultSmallFont, type BdfFont } from "../graphics/bdffont";
import { clamp } from "../util/numeric-util";
import { DashboardInputEvent, Layer, LayerContext, PaintBelow } from "./layers";
const DEFAULT_MENU_X = 8;
const DEFAULT_MENU_Y = 8;
const DEFAULT_MENU_WIDTH = 272;
const DEFAULT_MENU_HEIGHT = 128;
// Menus grow with their item count, from half the screen (matching the old
// fixed quarter-screen-era look) up to the full screen, then scroll.
const DEFAULT_MENU_MIN_HEIGHT = G2_LENS_HEIGHT / 2 - 2 * DEFAULT_MENU_Y;
const MENU_TITLE_HEIGHT = 16;
const MENU_ROW_HEIGHT = 20;
const MENU_BODY_PADDING = 8;
const MENU_HIGHLIGHT_Y_OFFSET = 0;
const MENU_TOGGLE_SWITCH_Y_OFFSET = 1;
const MENU_HIGHLIGHT_HEIGHT = MENU_ROW_HEIGHT - 1;
@@ -19,7 +23,10 @@ export type MenuLayout = {
x: number;
y: number;
width: number;
height: number;
/** Smallest box to draw even when items don't fill it. Default: top half of the screen. */
minHeight?: number;
/** Height cap before the menu starts scrolling. Default: the full screen. */
maxHeight?: number;
};
export type MenuItemRenderArgs = {
@@ -78,6 +85,7 @@ export function drawRightValueMenuItem(
export class MenuLayer implements Layer {
private selectedIndex = 0;
private scrollRow = 0;
constructor(
private readonly title: string | null,
@@ -86,14 +94,24 @@ export class MenuLayer implements Layer {
x: DEFAULT_MENU_X,
y: DEFAULT_MENU_Y,
width: DEFAULT_MENU_WIDTH,
height: DEFAULT_MENU_HEIGHT,
},
public readonly paintOverBase = false,
) {}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
const font = getDefaultSmallFont();
const { x, y, width, height } = this.layout;
const { x, y, width } = this.layout;
const chromeTop = (this.title ? MENU_TITLE_HEIGHT : 0) + MENU_BODY_PADDING;
const minHeight = this.layout.minHeight ?? DEFAULT_MENU_MIN_HEIGHT;
const maxHeight = Math.min(
this.layout.maxHeight ?? G2_LENS_HEIGHT - y - DEFAULT_MENU_Y,
G2_LENS_HEIGHT - y,
);
const contentHeight = chromeTop + this.items.length * MENU_ROW_HEIGHT + MENU_BODY_PADDING;
const height = clamp(contentHeight, Math.min(minHeight, maxHeight), maxHeight);
const visibleRowCount = Math.max(1, ((height - chromeTop - MENU_BODY_PADDING) / MENU_ROW_HEIGHT) | 0);
this.clampScrollToSelection(visibleRowCount);
const image = paintBelow();
image.fillRoundedRect(x, y, width, height, 0);
image.drawRoundedRect(x, y, width, height, 72);
@@ -101,20 +119,21 @@ export class MenuLayer implements Layer {
image.drawText(font, x + 12, y + 8, this.title, 220);
}
const bodyY = y + (this.title ? MENU_TITLE_HEIGHT : 0) + 8;
for (let index = 0; index < this.items.length; index++) {
const bodyY = y + chromeTop;
const lastVisibleRow = Math.min(this.items.length, this.scrollRow + visibleRowCount);
for (let index = this.scrollRow; index < lastVisibleRow; index++) {
const item = this.items[index]!;
const y = bodyY + index * MENU_ROW_HEIGHT;
const rowY = bodyY + (index - this.scrollRow) * MENU_ROW_HEIGHT;
const selected = index === this.selectedIndex;
if (selected) {
image.fillRoundedRect(x + 12, y + MENU_HIGHLIGHT_Y_OFFSET, width - 24, MENU_HIGHLIGHT_HEIGHT, MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL);
image.drawRoundedRect(x + 12, y + MENU_HIGHLIGHT_Y_OFFSET, width - 24, MENU_HIGHLIGHT_HEIGHT, MENU_HIGHLIGHT_SELECTED_BORDER_STROKE);
image.fillRoundedRect(x + 12, rowY + MENU_HIGHLIGHT_Y_OFFSET, width - 24, MENU_HIGHLIGHT_HEIGHT, MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL);
image.drawRoundedRect(x + 12, rowY + MENU_HIGHLIGHT_Y_OFFSET, width - 24, MENU_HIGHLIGHT_HEIGHT, MENU_HIGHLIGHT_SELECTED_BORDER_STROKE);
}
if (item.render) {
item.render({
image,
x: x + 22,
y,
y: rowY,
width: width - 44,
height: MENU_ROW_HEIGHT - 3,
selected,
@@ -122,13 +141,35 @@ export class MenuLayer implements Layer {
ctx,
});
} else {
image.drawText(font, x + 22, y + 3, item.label, selected ? 255 : 200);
image.drawText(font, x + 22, rowY + 3, item.label, selected ? 255 : 200);
}
}
if (this.items.length > visibleRowCount) {
this.drawScrollbar(image, x + width - 7, bodyY, visibleRowCount);
}
return image;
}
private clampScrollToSelection(visibleRowCount: number): void {
if (this.selectedIndex < this.scrollRow) {
this.scrollRow = this.selectedIndex;
} else if (this.selectedIndex >= this.scrollRow + visibleRowCount) {
this.scrollRow = this.selectedIndex - visibleRowCount + 1;
}
this.scrollRow = clamp(this.scrollRow, 0, Math.max(0, this.items.length - visibleRowCount));
}
private drawScrollbar(image: GrayImage, trackX: number, trackY: number, visibleRowCount: number): void {
const trackHeight = visibleRowCount * MENU_ROW_HEIGHT - 4;
image.fillRect(trackX, trackY, 3, trackHeight, 30);
const thumbHeight = Math.max(8, (trackHeight * visibleRowCount / this.items.length) | 0);
const maxScrollRow = this.items.length - visibleRowCount;
const thumbY = trackY + (((trackHeight - thumbHeight) * this.scrollRow / maxScrollRow) | 0);
image.fillRect(trackX, thumbY, 3, thumbHeight, 120);
}
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
if (!this.items.length) {
if (event.type === "double-click") {
+32 -6
View File
@@ -7,9 +7,11 @@ import {
dismissNotification,
invokeNotificationAction,
readActiveNotifications,
readNotificationIconByKey,
type AndroidNotification,
type AndroidNotificationAction,
} from "../native/notification-icons";
import { noteStaleDataUsed, renderPassAllowsStaleData } from "../util/render-freshness";
import { type DashboardInputEvent, type Layer, type LayerContext, type PaintBelow } from "./layers";
const PAGE_X = 12;
@@ -18,11 +20,23 @@ const LIST_TOP = 38;
const LIST_BOTTOM = G2_LENS_HEIGHT;
const CARD_X = 20;
const CARD_WIDTH = G2_LENS_WIDTH - 40;
const CARD_TEXT_WIDTH = CARD_WIDTH - 24;
const ICON_SIZE = 24;
const ICON_TEXT_GAP = 8;
const CARD_TEXT_X = 10 + ICON_SIZE + ICON_TEXT_GAP;
const CARD_TEXT_WIDTH = CARD_WIDTH - CARD_TEXT_X - 14;
const LINE_HEIGHT = 14;
const CARD_GAP = 6;
const MAX_NOTIFICATIONS = 50;
/** Icon for a paint pass: allow-stale, reporting staleness to the render loop. */
function iconForNotification(key: string): GrayImage | null {
const { icon, stale } = readNotificationIconByKey(key, renderPassAllowsStaleData());
if (stale) {
noteStaleDataUsed();
}
return icon;
}
type CardLayout = {
notification: AndroidNotification;
height: number;
@@ -69,7 +83,10 @@ export class NotificationsListLayer implements Layer {
for (let index = 0; index < layouts.length; index++) {
const layout = layouts[index]!;
if (cursorY + layout.height >= LIST_TOP && cursorY <= LIST_BOTTOM) {
drawNotificationCard(image, font, layout, CARD_X, cursorY, CARD_WIDTH, index === selectedIndex);
// Icons are only resolved for cards actually drawn, so a long list
// does not fetch icons for everything below the fold.
const icon = iconForNotification(layout.notification.key);
drawNotificationCard(image, font, layout, CARD_X, cursorY, CARD_WIDTH, index === selectedIndex, icon);
}
cursorY += layout.height + CARD_GAP;
if (cursorY > LIST_BOTTOM + 80) break;
@@ -139,7 +156,7 @@ export class SingleNotificationLayer implements Layer {
const menu = buildDetailMenu(notification);
this.selectedMenuIndex = clamp(this.selectedMenuIndex, 0, Math.max(0, menu.length - 1));
drawDetailContent(image, font, notification);
drawDetailContent(image, font, notification, iconForNotification(notification.key));
drawDetailMenu(image, font, menu, this.selectedMenuIndex);
return image;
}
@@ -230,14 +247,18 @@ function drawNotificationCard(
y: number,
width: number,
selected: boolean,
icon: GrayImage | null,
): void {
const fill = selected ? 15 : 0;
const stroke = selected ? 110 : 38;
image.fillRoundedRect(x, y, width, layout.height, fill, 8);
image.drawRoundedRect(x, y, width, layout.height, stroke, 8);
if (icon) {
image.bitBlt(icon, x + 10, y + 8);
}
for (let index = 0; index < layout.lines.length; index++) {
const value = index === 0 ? 140 : selected ? 235 : 185;
image.drawText(font, x + 10, y + 7 + index * LINE_HEIGHT, layout.lines[index]!, value);
image.drawText(font, x + CARD_TEXT_X, y + 7 + index * LINE_HEIGHT, layout.lines[index]!, value);
}
}
@@ -254,11 +275,16 @@ function scrollForSelected(layouts: CardLayout[], selectedIndex: number, viewpor
return clamp(centered | 0, 0, maxScroll);
}
function drawDetailContent(image: GrayImage, font: BdfFont, notification: AndroidNotification): void {
function drawDetailContent(image: GrayImage, font: BdfFont, notification: AndroidNotification, icon: GrayImage | null): void {
const contentX = 24;
const contentWidth = 360;
image.drawText(font, PAGE_X + 12, PAGE_Y + 9, "Notification", 220);
image.drawText(font, contentX, 42, `${notification.appName || notification.packageName} ${formatRelativeTime(notification.postTime)}`, 150);
let appLineX = contentX;
if (icon) {
image.bitBlt(icon, contentX, 36);
appLineX = contentX + ICON_SIZE + ICON_TEXT_GAP;
}
image.drawText(font, appLineX, 42, `${notification.appName || notification.packageName} ${formatRelativeTime(notification.postTime)}`, 150);
const lines: string[] = [];
lines.push(...wrapText(font, notification.title || "(untitled)", contentWidth));