Rename the Teleprompt app to Files, improve its navigation and add support for images

This commit is contained in:
James Babcock committed 2026-07-25 21:33:58 -07:00
1 parent 8cc29acaea
commit 3c2f53ed75
15 files changed
+1035 -246

No files matched your search

+21
View File
@@ -18,6 +18,8 @@ export type DirectoryEntry = {
path: string;
isDirectory: boolean;
sizeBytes: number;
/** Last-modified time in epoch ms; 0 when unknown. */
modifiedMs: number;
};
export function hasAllFilesAccess(): boolean {
@@ -60,6 +62,7 @@ export function listDirectory(path: string): DirectoryEntry[] | null {
path: String(file.getAbsolutePath()),
isDirectory: Boolean(file.isDirectory()),
sizeBytes: Number(file.length()),
modifiedMs: Number(file.lastModified()),
});
}
entries.sort((a, b) => {
@@ -73,6 +76,24 @@ export function listDirectory(path: string): DirectoryEntry[] | null {
}
}
/** Stat a single path; null when it does not exist or cannot be checked. */
export function statPath(path: string): DirectoryEntry | null {
try {
const file = new java.io.File(path);
if (!file.exists()) return null;
return {
name: String(file.getName()),
path: String(file.getAbsolutePath()),
isDirectory: Boolean(file.isDirectory()),
sizeBytes: Number(file.length()),
modifiedMs: Number(file.lastModified()),
};
} catch (error) {
console.warn(`statPath failed for ${path}: ${error}`);
return null;
}
}
/** Write UTF-8 text to a file in the public Downloads directory; returns its path or null. */
export function writeTextToDownloads(filename: string, text: string): string | null {
try {
+48
View File
@@ -0,0 +1,48 @@
/**
* Image-file decoding for the on-glasses image viewer, backed by the Java
* ImageFileLoader (BitmapFactory handles PNG/JPEG/GIF/BMP/WebP/HEIC).
*/
import { GrayImage } from "../graphics/image";
import { toUint8Array } from "../util/array-util";
declare const com: any;
declare const global: any;
/** File extensions BitmapFactory can decode (no SVG). */
const DECODABLE_IMAGE = /\.(png|jpe?g|gif|bmp|webp|heic|heif)$/i;
export function isDecodableImageFile(name: string): boolean {
return DECODABLE_IMAGE.test(name);
}
/**
* Decode a gray packet ([widthLo, widthHi, heightLo, heightHi, pixels...],
* the format the Java helpers return) into a GrayImage; null when empty or
* malformed.
*/
export function grayImageFromPacket(raw: ArrayLike<number> | null | undefined): GrayImage | null {
const bytes = toUint8Array(raw);
if (bytes.length < 4) return null;
const width = bytes[0]! | (bytes[1]! << 8);
const height = bytes[2]! | (bytes[3]! << 8);
if (width <= 0 || height <= 0 || bytes.length < 4 + width * height) return null;
const image = new GrayImage(width, height, 0);
image.pixels.set(bytes.subarray(4, 4 + width * height));
return image;
}
/**
* Load an image file as grayscale, downscaled to fit maxWidth x maxHeight
* (aspect preserved, never upscaled); null when unreadable or undecodable.
*/
export function loadImageFileAsGray(path: string, maxWidth: number, maxHeight: number): GrayImage | null {
if (!global.isAndroid) return null;
try {
return grayImageFromPacket(
com.faceclaw.app.ImageFileLoader.loadGray(path, Math.round(maxWidth), Math.round(maxHeight)),
);
} catch (error) {
console.warn(`loadImageFileAsGray failed for ${path}: ${error}`);
return null;
}
}
+2 -9
View File
@@ -1,6 +1,6 @@
import { Utils } from "@nativescript/core";
import { GrayImage } from "../graphics/image";
import { toUint8Array } from "../util/array-util";
import { grayImageFromPacket } from "./image-files";
declare const com: any;
@@ -140,14 +140,7 @@ export class FaceclawMediaControllerBridge {
if (!global.isAndroid) return null;
this.ensureController();
if (!this.controller) return null;
const bytes = toUint8Array(this.controller.getAlbumArtGray(Math.round(maxSize)));
if (bytes.length < 4) return null;
const width = bytes[0]! | (bytes[1]! << 8);
const height = bytes[2]! | (bytes[3]! << 8);
if (width <= 0 || height <= 0 || bytes.length < 4 + width * height) return null;
const image = new GrayImage(width, height, 0);
image.pixels.set(bytes.subarray(4, 4 + width * height));
return image;
return grayImageFromPacket(this.controller.getAlbumArtGray(Math.round(maxSize)));
}
/** The player's queue (playlist), empty when the player exposes none. */
+1 -1
View File
@@ -29,7 +29,7 @@ async function handleShareIntent(intent: android.content.Intent): Promise<void>
return;
}
const { dashboardController } = await import("../g2/dashboard-controller");
await dashboardController.openTelepromptDocument(text);
await dashboardController.openSharedTextDocument(text);
}
function readPlainTextShare(intent: android.content.Intent): string | null {