forked from Blendman974/faceclaw
EvenHub phone UI: add top bar, add open icon
This commit is contained in:
1 parent
c6949fde3b
commit
e879c58d9c
9 files changed
+284
-30
No files matched your search
+123
-13
@@ -1,14 +1,24 @@
|
|||||||
package com.faceclaw.app
|
package com.faceclaw.app
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.content.Context
|
||||||
import android.content.MutableContextWrapper
|
import android.content.MutableContextWrapper
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.Typeface
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.text.TextUtils
|
||||||
|
import android.util.TypedValue
|
||||||
|
import android.view.Gravity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import java.util.HashMap
|
import java.util.HashMap
|
||||||
@@ -34,6 +44,12 @@ import java.util.HashMap
|
|||||||
* the chosen WebView to the top of the overlay); hiding sends it back behind.
|
* the chosen WebView to the top of the overlay); hiding sends it back behind.
|
||||||
* All view work happens on the main thread (callers are on the NS/JS thread).
|
* All view work happens on the main thread (callers are on the NS/JS thread).
|
||||||
*
|
*
|
||||||
|
* Layout: the activity is edge-to-edge, so the overlay tracks the window
|
||||||
|
* insets itself. A top bar (the shown app's name and a close button) sits
|
||||||
|
* under the status bar, and the WebViews fill the area between it and the
|
||||||
|
* navigation bar / keyboard. That area is the same whether or not the overlay
|
||||||
|
* is shown, so showing an app doesn't resize (and re-lay-out) its page.
|
||||||
|
*
|
||||||
* Timer keep-alive: when the phone screen turns off, Chromium heavily throttles
|
* Timer keep-alive: when the phone screen turns off, Chromium heavily throttles
|
||||||
* the page's own setTimeout/setInterval (intensive background throttling clamps
|
* the page's own setTimeout/setInterval (intensive background throttling clamps
|
||||||
* them to ~1/sec), so timer-driven apps (e.g. snake's game loop) slow to a
|
* them to ~1/sec), so timer-driven apps (e.g. snake's game loop) slow to a
|
||||||
@@ -71,8 +87,13 @@ import java.util.HashMap
|
|||||||
*/
|
*/
|
||||||
class FaceclawEvenHubWebViewHost {
|
class FaceclawEvenHubWebViewHost {
|
||||||
private var overlay: FrameLayout? = null
|
private var overlay: FrameLayout? = null
|
||||||
|
/** Holds the WebViews, inside [overlay] below the top bar. */
|
||||||
|
private var stack: FrameLayout? = null
|
||||||
|
private var titleView: TextView? = null
|
||||||
private var overlayActivity: Activity? = null
|
private var overlayActivity: Activity? = null
|
||||||
private var shown = false
|
private var shown = false
|
||||||
|
private var shownTitle = ""
|
||||||
|
private var onClose: Runnable? = null
|
||||||
|
|
||||||
private val mainHandler = Handler(Looper.getMainLooper())
|
private val mainHandler = Handler(Looper.getMainLooper())
|
||||||
private val webViews: MutableList<WebView> = ArrayList()
|
private val webViews: MutableList<WebView> = ArrayList()
|
||||||
@@ -139,6 +160,12 @@ class FaceclawEvenHubWebViewHost {
|
|||||||
|
|
||||||
private const val TICK_JS = "window.__fcTick?__fcTick():null"
|
private const val TICK_JS = "window.__fcTick?__fcTick():null"
|
||||||
|
|
||||||
|
/** Top bar height, below the status bar (Material toolbar height). */
|
||||||
|
private const val BAR_HEIGHT_DP = 56f
|
||||||
|
|
||||||
|
/** Matches the NativeScript ActionBar (NativeScriptToolbarStyle). */
|
||||||
|
private val BAR_COLOR = Color.parseColor("#424242")
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun getInstance(): FaceclawEvenHubWebViewHost {
|
fun getInstance(): FaceclawEvenHubWebViewHost {
|
||||||
@@ -152,36 +179,112 @@ class FaceclawEvenHubWebViewHost {
|
|||||||
val existing = overlay
|
val existing = overlay
|
||||||
if (existing != null && overlayActivity === activity && existing.parent != null) return existing
|
if (existing != null && overlayActivity === activity && existing.parent != null) return existing
|
||||||
val content = activity.findViewById<ViewGroup>(android.R.id.content)
|
val content = activity.findViewById<ViewGroup>(android.R.id.content)
|
||||||
|
(existing?.parent as ViewGroup?)?.removeView(existing)
|
||||||
val created = FrameLayout(activity)
|
val created = FrameLayout(activity)
|
||||||
if (existing != null) {
|
created.setBackgroundColor(Color.BLACK)
|
||||||
(existing.parent as ViewGroup?)?.removeView(existing)
|
val createdStack = FrameLayout(activity)
|
||||||
for (web in webViews) {
|
created.addView(createdStack, FrameLayout.LayoutParams(
|
||||||
existing.removeView(web)
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
||||||
rebaseContext(web, activity)
|
val bar = buildTopBar(activity)
|
||||||
created.addView(web, FrameLayout.LayoutParams(
|
created.addView(bar, FrameLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP))
|
||||||
}
|
for (web in webViews) {
|
||||||
|
(web.parent as ViewGroup?)?.removeView(web)
|
||||||
|
rebaseContext(web, activity)
|
||||||
|
createdStack.addView(web, FrameLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
||||||
|
}
|
||||||
|
// Insets are passed on unconsumed: before API 30 a consuming child
|
||||||
|
// would starve its later siblings (the NativeScript UI) of them.
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(created) { _, insets ->
|
||||||
|
applyInsets(bar, createdStack, insets)
|
||||||
|
insets
|
||||||
}
|
}
|
||||||
overlay = created
|
overlay = created
|
||||||
|
stack = createdStack
|
||||||
overlayActivity = activity
|
overlayActivity = activity
|
||||||
// index 0 = behind the NativeScript content view (raised again below if shown).
|
// index 0 = behind the NativeScript content view (raised again below if shown).
|
||||||
content.addView(created, 0, FrameLayout.LayoutParams(
|
content.addView(created, 0, FrameLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
||||||
|
ViewCompat.requestApplyInsets(created)
|
||||||
if (shown) created.bringToFront()
|
if (shown) created.bringToFront()
|
||||||
return created
|
return created
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The bar across the top of a shown app: the app's name, then a close button. */
|
||||||
|
private fun buildTopBar(activity: Activity): LinearLayout {
|
||||||
|
val bar = LinearLayout(activity)
|
||||||
|
bar.orientation = LinearLayout.HORIZONTAL
|
||||||
|
bar.gravity = Gravity.CENTER_VERTICAL
|
||||||
|
bar.setBackgroundColor(BAR_COLOR)
|
||||||
|
// Swallow touches so they don't fall through to the WebViews.
|
||||||
|
bar.isClickable = true
|
||||||
|
|
||||||
|
val title = TextView(activity)
|
||||||
|
title.text = shownTitle
|
||||||
|
title.setTextColor(Color.WHITE)
|
||||||
|
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f)
|
||||||
|
title.typeface = Typeface.create("sans-serif-medium", Typeface.NORMAL)
|
||||||
|
title.maxLines = 1
|
||||||
|
title.ellipsize = TextUtils.TruncateAt.END
|
||||||
|
bar.addView(title, LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f).apply {
|
||||||
|
marginStart = dp(activity, 16f)
|
||||||
|
marginEnd = dp(activity, 12f)
|
||||||
|
})
|
||||||
|
|
||||||
|
val close = TextView(activity)
|
||||||
|
close.text = "\u2715"
|
||||||
|
close.setTextColor(Color.WHITE)
|
||||||
|
close.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f)
|
||||||
|
close.gravity = Gravity.CENTER
|
||||||
|
close.contentDescription = "Close"
|
||||||
|
val ripple = TypedValue()
|
||||||
|
if (activity.theme.resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, ripple, true)) {
|
||||||
|
close.setBackgroundResource(ripple.resourceId)
|
||||||
|
}
|
||||||
|
close.setOnClickListener { onClose?.run() }
|
||||||
|
val closeSize = dp(activity, 48f)
|
||||||
|
bar.addView(close, LinearLayout.LayoutParams(closeSize, closeSize).apply {
|
||||||
|
marginEnd = dp(activity, 4f)
|
||||||
|
})
|
||||||
|
titleView = title
|
||||||
|
return bar
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the bar under the status bar (its background filling in behind it)
|
||||||
|
* and the WebViews between the bar and the navigation bar or keyboard.
|
||||||
|
*/
|
||||||
|
private fun applyInsets(bar: View, webStack: View, insets: WindowInsetsCompat) {
|
||||||
|
val bars = insets.getInsets(
|
||||||
|
WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
|
||||||
|
val ime = insets.getInsets(WindowInsetsCompat.Type.ime())
|
||||||
|
val barHeight = dp(bar.context, BAR_HEIGHT_DP)
|
||||||
|
bar.setPadding(bars.left, bars.top, bars.right, 0)
|
||||||
|
bar.layoutParams = (bar.layoutParams as FrameLayout.LayoutParams).apply {
|
||||||
|
height = bars.top + barHeight
|
||||||
|
}
|
||||||
|
webStack.layoutParams = (webStack.layoutParams as FrameLayout.LayoutParams).apply {
|
||||||
|
setMargins(bars.left, bars.top + barHeight, bars.right, maxOf(bars.bottom, ime.bottom))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun dp(context: Context, value: Float): Int {
|
||||||
|
return TypedValue.applyDimension(
|
||||||
|
TypedValue.COMPLEX_UNIT_DIP, value, context.resources.displayMetrics).toInt()
|
||||||
|
}
|
||||||
|
|
||||||
private fun rebaseContext(web: WebView, activity: Activity) {
|
private fun rebaseContext(web: WebView, activity: Activity) {
|
||||||
(web.context as? MutableContextWrapper)?.baseContext = activity
|
(web.context as? MutableContextWrapper)?.baseContext = activity
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add a WebView to the host, full-size and rendering, hidden behind the UI. */
|
/** Add a WebView to the host, full-size and rendering, hidden behind the UI. */
|
||||||
fun attach(activity: Activity, web: WebView) {
|
fun attach(activity: Activity, web: WebView) {
|
||||||
val o = ensureOverlay(activity)
|
ensureOverlay(activity)
|
||||||
rebaseContext(web, activity)
|
rebaseContext(web, activity)
|
||||||
web.visibility = View.VISIBLE
|
web.visibility = View.VISIBLE
|
||||||
if (web.parent == null) {
|
if (web.parent == null) {
|
||||||
o.addView(web, FrameLayout.LayoutParams(
|
stack!!.addView(web, FrameLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
||||||
}
|
}
|
||||||
// resumeTimers() is process-global; make sure nothing left timers paused.
|
// resumeTimers() is process-global; make sure nothing left timers paused.
|
||||||
@@ -215,9 +318,15 @@ class FaceclawEvenHubWebViewHost {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Bring an app's WebView to the front of [activity] so it is visible on the phone. */
|
/**
|
||||||
fun showOnPhone(activity: Activity?, web: WebView) {
|
* Bring an app's WebView to the front of [activity] so it is visible on the
|
||||||
|
* phone, titled [title]. The top bar's close button runs [onClose].
|
||||||
|
*/
|
||||||
|
fun showOnPhone(activity: Activity?, web: WebView, title: String, onClose: Runnable) {
|
||||||
val o = if (activity != null) ensureOverlay(activity) else overlay ?: return
|
val o = if (activity != null) ensureOverlay(activity) else overlay ?: return
|
||||||
|
shownTitle = title
|
||||||
|
this.onClose = onClose
|
||||||
|
titleView?.text = title
|
||||||
web.bringToFront()
|
web.bringToFront()
|
||||||
o.bringToFront()
|
o.bringToFront()
|
||||||
shown = true
|
shown = true
|
||||||
@@ -226,6 +335,7 @@ class FaceclawEvenHubWebViewHost {
|
|||||||
/** Send the overlay back behind the NativeScript UI. */
|
/** Send the overlay back behind the NativeScript UI. */
|
||||||
fun hideOnPhone() {
|
fun hideOnPhone() {
|
||||||
shown = false
|
shown = false
|
||||||
|
onClose = null
|
||||||
val o = overlay ?: return
|
val o = overlay ?: return
|
||||||
val content = o.parent as ViewGroup?
|
val content = o.parent as ViewGroup?
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
@@ -242,7 +352,7 @@ class FaceclawEvenHubWebViewHost {
|
|||||||
fun detach(web: WebView) {
|
fun detach(web: WebView) {
|
||||||
webViews.remove(web)
|
webViews.remove(web)
|
||||||
tickers.remove(web)?.stop()
|
tickers.remove(web)?.stop()
|
||||||
overlay?.removeView(web)
|
stack?.removeView(web)
|
||||||
web.destroy()
|
web.destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,5 +30,23 @@ class PreviewBitmapUtil private constructor() {
|
|||||||
val colors = PreviewPalette.expand(bytes, 0, width * height, brightenGamma, green)
|
val colors = PreviewPalette.expand(bytes, 0, width * height, brightenGamma, green)
|
||||||
return Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888)
|
return Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A white-on-transparent bitmap of an 8bpp glasses icon (gray becomes
|
||||||
|
* alpha; black, which the glasses show as unlit, is transparent), for
|
||||||
|
* showing glasses artwork on the phone's dark action bar.
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun whiteIconFromGray(gray: ByteBuffer?, width: Int, height: Int): Bitmap {
|
||||||
|
if (gray == null || width <= 0 || height <= 0 || gray.remaining() < width * height) {
|
||||||
|
throw IllegalArgumentException("invalid gray icon buffer")
|
||||||
|
}
|
||||||
|
val bytes = ByteArray(width * height)
|
||||||
|
gray.get(bytes)
|
||||||
|
val colors = IntArray(width * height) { i ->
|
||||||
|
((bytes[i].toInt() and 0xff) shl 24) or 0x00ffffff
|
||||||
|
}
|
||||||
|
return Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+13
-2
@@ -16,8 +16,9 @@ ActionItem {
|
|||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The main page's custom titleView: title left, connection status and the
|
/* The main page's custom titleView: title left; the EvenHub app icon,
|
||||||
* warning triangle right-aligned beside the overflow menu. */
|
* connection status and the warning triangle right-aligned beside the
|
||||||
|
* overflow menu. */
|
||||||
.action-bar-title {
|
.action-bar-title {
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
font-size: 18;
|
font-size: 18;
|
||||||
@@ -32,6 +33,16 @@ ActionItem {
|
|||||||
vertical-align: center;
|
vertical-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The foreground EvenHub app's icon (opens its phone UI); the padding widens
|
||||||
|
* the tap target. */
|
||||||
|
.action-bar-app-icon {
|
||||||
|
width: 32;
|
||||||
|
height: 32;
|
||||||
|
padding: 5.5;
|
||||||
|
margin-right: 8;
|
||||||
|
vertical-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
/* The emoji brings its own yellow; the padding widens the tap target. */
|
/* The emoji brings its own yellow; the padding widens the tap target. */
|
||||||
.action-bar-warning {
|
.action-bar-warning {
|
||||||
font-size: 18;
|
font-size: 18;
|
||||||
|
|||||||
@@ -6,11 +6,12 @@
|
|||||||
*
|
*
|
||||||
* Glasses-first: launching does NOT take over the phone screen. The phone
|
* Glasses-first: launching does NOT take over the phone screen. The phone
|
||||||
* stays on the Faceclaw dashboard; an app's phone UI is shown on demand
|
* stays on the Faceclaw dashboard; an app's phone UI is shown on demand
|
||||||
* (window menu -> "Show phone UI"), overlaying the dashboard, and the Back
|
* (window menu -> "Show phone UI", or the app-icon button in the phone's
|
||||||
* button returns to it. Apps are kept alive until explicitly closed (no memory
|
* action bar while the app is foreground on the glasses), overlaying the
|
||||||
* eviction yet).
|
* dashboard, and the Back button or the overlay's close button returns to it.
|
||||||
|
* Apps are kept alive until explicitly closed (no memory eviction yet).
|
||||||
*/
|
*/
|
||||||
import { Application } from "@nativescript/core";
|
import { Application, type ImageSource } from "@nativescript/core";
|
||||||
import { type AppContext } from "../app-definition";
|
import { type AppContext } from "../app-definition";
|
||||||
import {
|
import {
|
||||||
appFilesDirPath,
|
appFilesDirPath,
|
||||||
@@ -23,6 +24,8 @@ import { EvenHubSession } from "./session";
|
|||||||
import { createEvenHubWindow } from "./evenhub-window";
|
import { createEvenHubWindow } from "./evenhub-window";
|
||||||
import { createEvenHubWebView, type EvenHubWebView } from "./webview";
|
import { createEvenHubWebView, type EvenHubWebView } from "./webview";
|
||||||
import { shell } from "../../ui/shell/shell";
|
import { shell } from "../../ui/shell/shell";
|
||||||
|
import { GrayImage } from "../../graphics/image";
|
||||||
|
import { grayImageToWhiteIconSource } from "../../native/gray-image-preview";
|
||||||
import {
|
import {
|
||||||
readEvenHubPackageManifest,
|
readEvenHubPackageManifest,
|
||||||
installedEvenHubAppId,
|
installedEvenHubAppId,
|
||||||
@@ -36,12 +39,31 @@ type RunningApp = {
|
|||||||
packageId: string;
|
packageId: string;
|
||||||
session: EvenHubSession;
|
session: EvenHubSession;
|
||||||
webView: EvenHubWebView;
|
webView: EvenHubWebView;
|
||||||
|
/** The app's icon for the phone action bar, rendered on first use. */
|
||||||
|
phoneIcon?: ImageSource | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** The phone action bar's button for opening the foreground app's phone UI. */
|
||||||
|
export type PhoneUiButton = { windowId: string; title: string; icon: ImageSource | null };
|
||||||
|
|
||||||
|
/** Pixel size the action-bar icon is rendered at (~21dp at xxhdpi). */
|
||||||
|
const PHONE_ICON_SIZE = 63;
|
||||||
|
|
||||||
const running = new Map<string, RunningApp>();
|
const running = new Map<string, RunningApp>();
|
||||||
let nextSerial = 1;
|
let nextSerial = 1;
|
||||||
let phoneShownWindowId: string | null = null;
|
let phoneShownWindowId: string | null = null;
|
||||||
let backHandlerRegistered = false;
|
let backHandlerRegistered = false;
|
||||||
|
const phoneShownListeners = new Set<() => void>();
|
||||||
|
|
||||||
|
/** Called whenever an app's phone UI is shown or hidden. Returns an unsubscribe. */
|
||||||
|
export function onPhoneShownChanged(listener: () => void): () => void {
|
||||||
|
phoneShownListeners.add(listener);
|
||||||
|
return () => phoneShownListeners.delete(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
function notifyPhoneShownChanged(): void {
|
||||||
|
for (const listener of phoneShownListeners) listener();
|
||||||
|
}
|
||||||
|
|
||||||
/** Intercept Android Back while an app's phone UI is overlaying the dashboard. */
|
/** Intercept Android Back while an app's phone UI is overlaying the dashboard. */
|
||||||
function ensureBackHandler(): void {
|
function ensureBackHandler(): void {
|
||||||
@@ -112,6 +134,7 @@ async function startApp(
|
|||||||
if (phoneShownWindowId === windowId) {
|
if (phoneShownWindowId === windowId) {
|
||||||
webView.hideOnPhone();
|
webView.hideOnPhone();
|
||||||
phoneShownWindowId = null;
|
phoneShownWindowId = null;
|
||||||
|
notifyPhoneShownChanged();
|
||||||
}
|
}
|
||||||
webView.destroy();
|
webView.destroy();
|
||||||
cleanup?.();
|
cleanup?.();
|
||||||
@@ -205,15 +228,35 @@ export function showOnPhone(windowId: string): void {
|
|||||||
const app = running.get(windowId);
|
const app = running.get(windowId);
|
||||||
if (!app) return;
|
if (!app) return;
|
||||||
if (phoneShownWindowId && phoneShownWindowId !== windowId) hidePhone();
|
if (phoneShownWindowId && phoneShownWindowId !== windowId) hidePhone();
|
||||||
app.webView.showOnPhone();
|
app.webView.showOnPhone(hidePhone);
|
||||||
phoneShownWindowId = windowId;
|
phoneShownWindowId = windowId;
|
||||||
|
notifyPhoneShownChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the phone to the dashboard (Back, or the shown app closing). */
|
/** Return the phone to the dashboard (Back, the close button, or the shown app closing). */
|
||||||
export function hidePhone(): void {
|
export function hidePhone(): void {
|
||||||
if (!phoneShownWindowId) return;
|
if (!phoneShownWindowId) return;
|
||||||
running.get(phoneShownWindowId)?.webView.hideOnPhone();
|
running.get(phoneShownWindowId)?.webView.hideOnPhone();
|
||||||
phoneShownWindowId = null;
|
phoneShownWindowId = null;
|
||||||
|
notifyPhoneShownChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The foreground glasses window, when it is an EvenHub app whose phone UI
|
||||||
|
* isn't showing: the phone action bar then offers a button to show it.
|
||||||
|
*/
|
||||||
|
export function phoneUiButton(): PhoneUiButton | null {
|
||||||
|
const window = shell.foregroundWindow();
|
||||||
|
const app = window ? running.get(window.windowId) : undefined;
|
||||||
|
if (!window || !app || phoneShownWindowId === app.windowId) return null;
|
||||||
|
if (app.phoneIcon === undefined) {
|
||||||
|
// The same artwork as the glasses sidebar (installed icon, else the
|
||||||
|
// generic package icon), drawn white.
|
||||||
|
const image = new GrayImage(PHONE_ICON_SIZE, PHONE_ICON_SIZE, 0);
|
||||||
|
window.drawIcon(image, 0, 0, PHONE_ICON_SIZE);
|
||||||
|
app.phoneIcon = grayImageToWhiteIconSource(image);
|
||||||
|
}
|
||||||
|
return { windowId: app.windowId, title: window.title, icon: app.phoneIcon };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function runningAppCount(): number {
|
export function runningAppCount(): number {
|
||||||
|
|||||||
@@ -22,11 +22,13 @@ import { FACECLAW_VERSION } from "../../version";
|
|||||||
|
|
||||||
declare const android: any;
|
declare const android: any;
|
||||||
declare const com: any;
|
declare const com: any;
|
||||||
|
declare const java: any;
|
||||||
|
|
||||||
export type EvenHubWebView = {
|
export type EvenHubWebView = {
|
||||||
evaluateJs: (js: string) => void;
|
evaluateJs: (js: string) => void;
|
||||||
destroy: () => void;
|
destroy: () => void;
|
||||||
showOnPhone: () => void;
|
/** Show the app's phone UI; `onClose` runs when its top bar's close button is tapped. */
|
||||||
|
showOnPhone: (onClose: () => void) => void;
|
||||||
hideOnPhone: () => void;
|
hideOnPhone: () => void;
|
||||||
/** The native android.webkit.WebView, for the host. */
|
/** The native android.webkit.WebView, for the host. */
|
||||||
native: unknown;
|
native: unknown;
|
||||||
@@ -118,8 +120,13 @@ export function createEvenHubWebView(session: EvenHubSession): EvenHubWebView {
|
|||||||
console.warn(`evenhub webview destroy failed: ${error}`);
|
console.warn(`evenhub webview destroy failed: ${error}`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
showOnPhone: () =>
|
showOnPhone: (onClose: () => void) =>
|
||||||
nativeHost.showOnPhone(Application.android?.foregroundActivity ?? Application.android?.startActivity ?? null, webView),
|
nativeHost.showOnPhone(
|
||||||
|
Application.android?.foregroundActivity ?? Application.android?.startActivity ?? null,
|
||||||
|
webView,
|
||||||
|
session.manifest.name,
|
||||||
|
new java.lang.Runnable({ run: onClose }),
|
||||||
|
),
|
||||||
hideOnPhone: () => nativeHost.hideOnPhone(),
|
hideOnPhone: () => nativeHost.hideOnPhone(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,14 @@ import {
|
|||||||
installedEvenHubPackageId,
|
installedEvenHubPackageId,
|
||||||
uninstallEvenHubPackage,
|
uninstallEvenHubPackage,
|
||||||
} from "../apps/evenhub/installed-apps";
|
} from "../apps/evenhub/installed-apps";
|
||||||
import { closeRunningPackage, launchInstalledPackage } from "../apps/evenhub/manager";
|
import {
|
||||||
|
closeRunningPackage,
|
||||||
|
launchInstalledPackage,
|
||||||
|
onPhoneShownChanged,
|
||||||
|
phoneUiButton,
|
||||||
|
showOnPhone as showEvenHubPhoneUi,
|
||||||
|
type PhoneUiButton,
|
||||||
|
} from "../apps/evenhub/manager";
|
||||||
import { openEvenHubStoreForPackage } from "../apps/evenhub";
|
import { openEvenHubStoreForPackage } from "../apps/evenhub";
|
||||||
import { isInstalledPackagePresent } from "../apps/evenhub/updates";
|
import { isInstalledPackagePresent } from "../apps/evenhub/updates";
|
||||||
import { wearerVerificationOptions } from "../apps/microphones/speakers";
|
import { wearerVerificationOptions } from "../apps/microphones/speakers";
|
||||||
@@ -133,6 +140,11 @@ export type DashboardSnapshot = {
|
|||||||
* nothing is paired, so "Disconnected" would be the wrong label.
|
* nothing is paired, so "Disconnected" would be the wrong label.
|
||||||
*/
|
*/
|
||||||
previewMode: boolean;
|
previewMode: boolean;
|
||||||
|
/**
|
||||||
|
* The foreground glasses window's EvenHub phone UI, when it can be opened
|
||||||
|
* (the action bar's app-icon button); null otherwise.
|
||||||
|
*/
|
||||||
|
evenHubPhoneUi: PhoneUiButton | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
type DashboardListener = (snapshot: DashboardSnapshot) => void;
|
type DashboardListener = (snapshot: DashboardSnapshot) => void;
|
||||||
@@ -361,6 +373,8 @@ class DashboardController {
|
|||||||
launchApp: (appId) => this.launchApp(appId),
|
launchApp: (appId) => this.launchApp(appId),
|
||||||
requestShellRender: () => this.requestShellRender(),
|
requestShellRender: () => this.requestShellRender(),
|
||||||
});
|
});
|
||||||
|
// The action bar's EvenHub phone-UI button hides while that UI is showing.
|
||||||
|
onPhoneShownChanged(() => this.emit());
|
||||||
shell.configure({
|
shell.configure({
|
||||||
actions: {
|
actions: {
|
||||||
...sharedActions,
|
...sharedActions,
|
||||||
@@ -1025,9 +1039,15 @@ class DashboardController {
|
|||||||
fontsMissingWarningVisible: this.fontsMissingWarningVisible,
|
fontsMissingWarningVisible: this.fontsMissingWarningVisible,
|
||||||
alarmReliabilityMessage: this.alarmReliabilityMessage,
|
alarmReliabilityMessage: this.alarmReliabilityMessage,
|
||||||
previewMode: this.isPreviewDisplayActive(),
|
previewMode: this.isPreviewDisplayActive(),
|
||||||
|
evenHubPhoneUi: phoneUiButton(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Overlay an EvenHub app's phone UI (the action bar's app-icon button). */
|
||||||
|
showEvenHubPhoneUi(windowId: string): void {
|
||||||
|
showEvenHubPhoneUi(windowId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message to show in place of the display preview, or "" to show the preview.
|
* Message to show in place of the display preview, or "" to show the preview.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -27,3 +27,21 @@ export function grayImageToPreviewSource(image: GrayImage): ImageSource | null {
|
|||||||
);
|
);
|
||||||
return new ImageSource(bitmap);
|
return new ImageSource(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A glasses icon as a white-on-transparent phone image (gray becomes alpha),
|
||||||
|
* for the dark action bar.
|
||||||
|
*/
|
||||||
|
export function grayImageToWhiteIconSource(image: GrayImage): ImageSource | null {
|
||||||
|
if (!global.isAndroid) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const baked = image.withDrawsBaked();
|
||||||
|
const bitmap = com.faceclaw.app.PreviewBitmapUtil.whiteIconFromGray(
|
||||||
|
copyToJavaByteBuffer(baked.pixels),
|
||||||
|
baked.width,
|
||||||
|
baked.height,
|
||||||
|
);
|
||||||
|
return new ImageSource(bitmap);
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:rc="phone-ui" 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>
|
<ActionBar>
|
||||||
<!-- Custom titleView: app title on the left; connection status and the
|
<!-- Custom titleView: app title on the left; the foreground EvenHub
|
||||||
warning-triangle indicator right-aligned beside the overflow menu. -->
|
app's phone-UI button, connection status and the warning-triangle
|
||||||
<GridLayout columns="auto,*,auto,auto" width="100%" verticalAlignment="center">
|
indicator right-aligned beside the overflow menu. -->
|
||||||
|
<GridLayout columns="auto,*,auto,auto,auto" width="100%" verticalAlignment="center">
|
||||||
<Label col="0" text="Faceclaw" class="action-bar-title" />
|
<Label col="0" text="Faceclaw" class="action-bar-title" />
|
||||||
<Label col="2" text="{{ connectionStatusLabel }}" tap="{{ onConnectionStatusTap }}" class="action-bar-status" />
|
<Image col="2" src="{{ evenHubPhoneUiIcon }}" tap="{{ onEvenHubPhoneUiTap }}" visibility="{{ evenHubPhoneUiVisibility }}" class="action-bar-app-icon" />
|
||||||
<Label col="3" text="⚠️" tap="{{ onWarningIconTap }}" visibility="{{ warningIconVisibility }}" class="action-bar-warning" />
|
<Label col="3" text="{{ connectionStatusLabel }}" tap="{{ onConnectionStatusTap }}" class="action-bar-status" />
|
||||||
|
<Label col="4" text="⚠️" tap="{{ onWarningIconTap }}" visibility="{{ warningIconVisibility }}" class="action-bar-warning" />
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
<ActionItem text="{{ buttonLabel }}" tap="{{ onTap }}" isEnabled="{{ connectItemEnabled }}" visibility="{{ glassesMenuItemsVisibility }}" android.position="popup" />
|
<ActionItem text="{{ buttonLabel }}" tap="{{ onTap }}" isEnabled="{{ connectItemEnabled }}" visibility="{{ glassesMenuItemsVisibility }}" android.position="popup" />
|
||||||
<ActionItem text="Pair glasses" tap="{{ onPairGlassesTap }}" isEnabled="{{ canRun }}" android.position="popup" />
|
<ActionItem text="Pair glasses" tap="{{ onPairGlassesTap }}" isEnabled="{{ canRun }}" android.position="popup" />
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import { isAutoReconnectSuppressed, resumeAutoReconnect } from "../g2/reconnect-
|
|||||||
import { isPreviewOnlyMode } from "./onboarding-state";
|
import { isPreviewOnlyMode } from "./onboarding-state";
|
||||||
import { formatErrorMessage } from "../util/format-error";
|
import { formatErrorMessage } from "../util/format-error";
|
||||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../graphics/image";
|
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../graphics/image";
|
||||||
|
import { type PhoneUiButton } from "../apps/evenhub/manager";
|
||||||
|
|
||||||
const LENS_ASPECT_RATIO = G2_LENS_WIDTH / G2_LENS_HEIGHT;
|
const LENS_ASPECT_RATIO = G2_LENS_WIDTH / G2_LENS_HEIGHT;
|
||||||
|
|
||||||
@@ -63,6 +64,7 @@ export class MainViewModel extends RemoteControlsViewModel {
|
|||||||
private _alarmReliabilityMessage = "";
|
private _alarmReliabilityMessage = "";
|
||||||
private _warningsModalVisible = false;
|
private _warningsModalVisible = false;
|
||||||
private _previewMode = false;
|
private _previewMode = false;
|
||||||
|
private _evenHubPhoneUi: PhoneUiButton | null = null;
|
||||||
private _phase: "disconnected" | "connecting" | "connected" | "charging" | "disconnecting" = "disconnected";
|
private _phase: "disconnected" | "connecting" | "connected" | "charging" | "disconnecting" = "disconnected";
|
||||||
|
|
||||||
// A new view model is built on every navigation to the main page; these
|
// A new view model is built on every navigation to the main page; these
|
||||||
@@ -112,6 +114,7 @@ export class MainViewModel extends RemoteControlsViewModel {
|
|||||||
this.batteryOptimizationWarningVisible = snapshot.batteryOptimizationWarningVisible;
|
this.batteryOptimizationWarningVisible = snapshot.batteryOptimizationWarningVisible;
|
||||||
this.fontsMissingWarningVisible = snapshot.fontsMissingWarningVisible;
|
this.fontsMissingWarningVisible = snapshot.fontsMissingWarningVisible;
|
||||||
this.alarmReliabilityMessage = snapshot.alarmReliabilityMessage;
|
this.alarmReliabilityMessage = snapshot.alarmReliabilityMessage;
|
||||||
|
this.evenHubPhoneUi = snapshot.evenHubPhoneUi;
|
||||||
this.refreshPadFocusLine();
|
this.refreshPadFocusLine();
|
||||||
}));
|
}));
|
||||||
// Brightness / display mode can change from the glasses' Settings app too.
|
// Brightness / display mode can change from the glasses' Settings app too.
|
||||||
@@ -773,6 +776,28 @@ export class MainViewModel extends RemoteControlsViewModel {
|
|||||||
return this._warningsModalVisible ? "visible" : "collapse";
|
return this._warningsModalVisible ? "visible" : "collapse";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set evenHubPhoneUi(value: PhoneUiButton | null) {
|
||||||
|
const current = this._evenHubPhoneUi;
|
||||||
|
if (current?.windowId === value?.windowId && current?.icon === value?.icon) return;
|
||||||
|
this._evenHubPhoneUi = value;
|
||||||
|
this.notifyPropertyChange("evenHubPhoneUiIcon", this.evenHubPhoneUiIcon);
|
||||||
|
this.notifyPropertyChange("evenHubPhoneUiVisibility", this.evenHubPhoneUiVisibility);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The foreground EvenHub app's icon, which opens its phone UI when tapped. */
|
||||||
|
get evenHubPhoneUiIcon(): ImageSource | null {
|
||||||
|
return this._evenHubPhoneUi?.icon ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
get evenHubPhoneUiVisibility(): "visible" | "collapse" {
|
||||||
|
return this._evenHubPhoneUi?.icon ? "visible" : "collapse";
|
||||||
|
}
|
||||||
|
|
||||||
|
onEvenHubPhoneUiTap(): void {
|
||||||
|
const windowId = this._evenHubPhoneUi?.windowId;
|
||||||
|
if (windowId) dashboardController.showEvenHubPhoneUi(windowId);
|
||||||
|
}
|
||||||
|
|
||||||
onWarningIconTap(): void {
|
onWarningIconTap(): void {
|
||||||
this.setWarningsModalVisible(true);
|
this.setWarningsModalVisible(true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user