forked from Blendman974/faceclaw
Add keyboard-input button to the phone home screen
This commit is contained in:
1 parent
00dd546b1c
commit
aef6194687
12 files changed
+574
-85
No files matched your search
@@ -39,7 +39,12 @@ function cleanupPage(page: Page): void {
|
||||
setPageState(page, undefined)
|
||||
}
|
||||
|
||||
function applySettingsTextFieldContrast(textField: TextField): void {
|
||||
/**
|
||||
* Readable colours for the light editor panels in both themes. selectAllOnFocus
|
||||
* suits replacing an existing setting value; a message being composed keeps
|
||||
* its caret where the user taps.
|
||||
*/
|
||||
function applySettingsTextFieldContrast(textField: TextField, selectAllOnFocus = true): void {
|
||||
textField.color = SETTINGS_TEXT_COLOR
|
||||
textField.backgroundColor = SETTINGS_BACKGROUND_COLOR
|
||||
textField.placeholderColor = SETTINGS_PLACEHOLDER_COLOR
|
||||
@@ -57,7 +62,7 @@ function applySettingsTextFieldContrast(textField: TextField): void {
|
||||
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)
|
||||
nativeTextField.setSelectAllOnFocus(selectAllOnFocus)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,6 +88,22 @@ function focusTextEditor(page: Page): void {
|
||||
}, 0)
|
||||
}
|
||||
|
||||
/** The keyboard dialog closed on the glasses (sent, discarded, or screen off). */
|
||||
function dismissKeyboardInputKeyboard(page: Page): void {
|
||||
page.getViewById<TextField>('keyboardInputField')?.dismissSoftInput()
|
||||
}
|
||||
|
||||
/** The keyboard dialog opened: bring up the IME on its field right away. */
|
||||
function focusKeyboardInput(page: Page): void {
|
||||
setTimeout(() => {
|
||||
const textField = page.getViewById<TextField>('keyboardInputField')
|
||||
if (textField) {
|
||||
applySettingsTextFieldContrast(textField, false)
|
||||
textField.focus()
|
||||
}
|
||||
}, 0)
|
||||
}
|
||||
|
||||
export function loaded(args: EventData) {
|
||||
const page = args.object as Page
|
||||
cleanupPage(page)
|
||||
@@ -121,6 +142,12 @@ export function loaded(args: EventData) {
|
||||
} else {
|
||||
dismissTextEditorKeyboard(page)
|
||||
}
|
||||
} else if (propertyArgs.propertyName === 'keyboardInputActive') {
|
||||
if (model.keyboardInputActive) {
|
||||
focusKeyboardInput(page)
|
||||
} else {
|
||||
dismissKeyboardInputKeyboard(page)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -131,6 +158,9 @@ export function loaded(args: EventData) {
|
||||
if (model.isTextSettingEditorActive) {
|
||||
focusTextEditor(page)
|
||||
}
|
||||
if (model.keyboardInputActive) {
|
||||
focusKeyboardInput(page)
|
||||
}
|
||||
}
|
||||
|
||||
export function unloaded(args: EventData) {
|
||||
|
||||
@@ -146,5 +146,31 @@
|
||||
checkedChange="{{ onTextSettingToggleChange }}" />
|
||||
</GridLayout>
|
||||
</StackLayout>
|
||||
<!-- Keyboard-input panel (the keyboard button beside the mic button):
|
||||
the phone's end of the keyboard dialog on the glasses
|
||||
(ui/shell/keyboard-input.ts). Same placement and collapsing rules
|
||||
as the setting editor above. The IME's send key goes to whichever
|
||||
destination is highlighted on the glasses; the buttons pick one
|
||||
directly. -->
|
||||
<StackLayout
|
||||
class="system-name-modal"
|
||||
visibility="{{ keyboardInputVisibility }}"
|
||||
horizontalAlignment="stretch"
|
||||
verticalAlignment="bottom">
|
||||
<Label text="Keyboard input" class="h2" />
|
||||
<TextField
|
||||
id="keyboardInputField"
|
||||
text="{{ keyboardInputText }}"
|
||||
hint="Type a message"
|
||||
textChange="{{ onKeyboardInputTextChange }}"
|
||||
returnPress="{{ onKeyboardInputReturnPress }}"
|
||||
returnKeyType="send" />
|
||||
<!-- Wraps onto a second line when the labels don't fit side by side. -->
|
||||
<FlexboxLayout flexWrap="wrap" class="m-t-8">
|
||||
<Button text="{{ keyboardInputPrimaryTargetLabel }}" tap="{{ onKeyboardInputPrimarySendTap }}" visibility="{{ keyboardInputPrimaryTargetVisibility }}" flexGrow="1" class="-primary" />
|
||||
<Button text="{{ keyboardInputSecondaryTargetLabel }}" tap="{{ onKeyboardInputSecondarySendTap }}" visibility="{{ keyboardInputSecondaryTargetVisibility }}" flexGrow="1" />
|
||||
<Button text="Discard" tap="{{ onKeyboardInputDiscardTap }}" flexGrow="1" />
|
||||
</FlexboxLayout>
|
||||
</StackLayout>
|
||||
</GridLayout>
|
||||
</Page>
|
||||
@@ -56,6 +56,9 @@ export class MainViewModel extends Observable {
|
||||
private _activeTextEditorToggleLabel = "";
|
||||
private _activeTextEditorToggleValue = false;
|
||||
private _activeTextEditorToggleVisible = false;
|
||||
private _keyboardInputActive = false;
|
||||
private _keyboardInputTargets: ReadonlyArray<{ id: string; label: string }> = [];
|
||||
private _keyboardInputText = "";
|
||||
private _evenAppConflictMessage = "";
|
||||
private _evenAppConflictWarningVisible = false;
|
||||
private _firmwareWarningMessage = "";
|
||||
@@ -103,6 +106,9 @@ export class MainViewModel extends Observable {
|
||||
this.activeTextEditorToggleLabel = snapshot.activeTextEditorToggleLabel;
|
||||
this.activeTextEditorToggleValue = snapshot.activeTextEditorToggleValue;
|
||||
this.activeTextEditorToggleVisible = snapshot.activeTextEditorToggleVisible;
|
||||
// Targets before active: the panel's buttons are labelled when it appears.
|
||||
this.keyboardInputTargets = snapshot.keyboardInputTargets;
|
||||
this.keyboardInputActive = snapshot.keyboardInputActive;
|
||||
this.evenAppConflictMessage = snapshot.evenAppConflictMessage;
|
||||
this.evenAppConflictWarningVisible = snapshot.evenAppConflictWarningVisible;
|
||||
this.firmwareWarningMessage = snapshot.firmwareWarningMessage;
|
||||
@@ -466,6 +472,100 @@ export class MainViewModel extends Observable {
|
||||
return this.isTextSettingEditorActive ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
// ---- keyboard-input panel (the keyboard button beside the mic button) ----
|
||||
//
|
||||
// The dialog lives on the glasses (ui/shell/keyboard-input.ts); this panel
|
||||
// is the phone's end of it: the text field the IME types into and a send
|
||||
// button per destination. The field's text is the panel's own state, never
|
||||
// echoed back from the controller (see setActiveTextSettingValue for why);
|
||||
// it is cleared whenever a dialog opens or closes.
|
||||
|
||||
get keyboardInputActive(): boolean {
|
||||
return this._keyboardInputActive;
|
||||
}
|
||||
|
||||
set keyboardInputActive(value: boolean) {
|
||||
if (this._keyboardInputActive === value) return;
|
||||
this._keyboardInputActive = value;
|
||||
this.keyboardInputText = "";
|
||||
this.notifyPropertyChange("keyboardInputActive", value);
|
||||
this.notifyPropertyChange("keyboardInputVisibility", this.keyboardInputVisibility);
|
||||
this.notifyPropertyChange("controlsVisibility", this.controlsVisibility);
|
||||
}
|
||||
|
||||
get keyboardInputVisibility(): "visible" | "collapse" {
|
||||
return this._keyboardInputActive ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get keyboardInputText(): string {
|
||||
return this._keyboardInputText;
|
||||
}
|
||||
|
||||
set keyboardInputText(value: string) {
|
||||
if (this._keyboardInputText === value) return;
|
||||
this._keyboardInputText = value;
|
||||
this.notifyPropertyChange("keyboardInputText", value);
|
||||
}
|
||||
|
||||
set keyboardInputTargets(value: ReadonlyArray<{ id: string; label: string }>) {
|
||||
this._keyboardInputTargets = value;
|
||||
this.notifyPropertyChange("keyboardInputPrimaryTargetLabel", this.keyboardInputPrimaryTargetLabel);
|
||||
this.notifyPropertyChange("keyboardInputPrimaryTargetVisibility", this.keyboardInputPrimaryTargetVisibility);
|
||||
this.notifyPropertyChange("keyboardInputSecondaryTargetLabel", this.keyboardInputSecondaryTargetLabel);
|
||||
this.notifyPropertyChange("keyboardInputSecondaryTargetVisibility", this.keyboardInputSecondaryTargetVisibility);
|
||||
}
|
||||
|
||||
// The glasses menu has at most two destinations (assistant, app), so the
|
||||
// panel has a fixed pair of buttons rather than a repeater.
|
||||
get keyboardInputPrimaryTargetLabel(): string {
|
||||
return this._keyboardInputTargets[0]?.label ?? "";
|
||||
}
|
||||
|
||||
get keyboardInputPrimaryTargetVisibility(): "visible" | "collapse" {
|
||||
return this._keyboardInputTargets[0] ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get keyboardInputSecondaryTargetLabel(): string {
|
||||
return this._keyboardInputTargets[1]?.label ?? "";
|
||||
}
|
||||
|
||||
get keyboardInputSecondaryTargetVisibility(): "visible" | "collapse" {
|
||||
return this._keyboardInputTargets[1] ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
onKeyboardTap(): void {
|
||||
dashboardController.startKeyboardInput();
|
||||
}
|
||||
|
||||
onKeyboardInputTextChange(args: { value?: string; object?: { text?: string } }): void {
|
||||
dashboardController.setKeyboardInputText(args.object?.text ?? args.value ?? "");
|
||||
}
|
||||
|
||||
/** The IME's send key: the destination highlighted on the glasses. */
|
||||
onKeyboardInputReturnPress(args: { object?: { text?: string } }): void {
|
||||
// Commit the field's actual text at send-time, in case the final
|
||||
// keystroke's textChange hadn't landed yet.
|
||||
const text = args?.object?.text;
|
||||
if (typeof text === "string") {
|
||||
dashboardController.setKeyboardInputText(text);
|
||||
}
|
||||
dashboardController.sendKeyboardInput();
|
||||
}
|
||||
|
||||
onKeyboardInputPrimarySendTap(): void {
|
||||
const target = this._keyboardInputTargets[0];
|
||||
if (target) dashboardController.sendKeyboardInput(target.id);
|
||||
}
|
||||
|
||||
onKeyboardInputSecondarySendTap(): void {
|
||||
const target = this._keyboardInputTargets[1];
|
||||
if (target) dashboardController.sendKeyboardInput(target.id);
|
||||
}
|
||||
|
||||
onKeyboardInputDiscardTap(): void {
|
||||
dashboardController.discardKeyboardInput();
|
||||
}
|
||||
|
||||
get evenAppConflictMessage(): string {
|
||||
return this._evenAppConflictMessage;
|
||||
}
|
||||
@@ -1016,7 +1116,7 @@ export class MainViewModel extends Observable {
|
||||
private _controlsTab: ControlsTab = lastControlsTab;
|
||||
|
||||
get controlsVisibility(): "visible" | "collapse" {
|
||||
return this.isTextSettingEditorActive ? "collapse" : "visible";
|
||||
return this.isTextSettingEditorActive || this._keyboardInputActive ? "collapse" : "visible";
|
||||
}
|
||||
|
||||
get settingsTabVisibility(): "visible" | "collapse" {
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
scheme as the watch pad - tap = select, double-tap or two fingers = back,
|
||||
hold = menu, swipes navigate), and Ring (a touchpad on the ring's own
|
||||
scheme: vertical swipes scroll, tap/double-tap/hold = click/double-click/
|
||||
long-press). Tap-then-hold on either pad is the G2 system-menu gesture. The narrow mic button at the tab bar's right edge fires the
|
||||
wakeword without changing the selected tab. Used by main-page.xml in both
|
||||
orientations; binds to the page's MainViewModel, which collapses the whole
|
||||
area while a text setting is being edited (keyboard-input mode).
|
||||
long-press). Tap-then-hold on either pad is the G2 system-menu gesture. The
|
||||
narrow mic and keyboard buttons at the tab bar's right edge fire the
|
||||
wakeword / open the keyboard dialog without changing the selected tab. Used
|
||||
by main-page.xml in both orientations; binds to the page's MainViewModel,
|
||||
which collapses the whole area while a text setting is being edited or the
|
||||
keyboard dialog is up (keyboard-input mode).
|
||||
|
||||
The root is a rows="auto,*" grid so the active section can use the leftover
|
||||
height (the Watch face centers in it); the three sections share the star
|
||||
@@ -17,15 +19,18 @@
|
||||
<!-- rows="auto" everywhere below: a rows-less GridLayout's implicit row
|
||||
acts as star, and this component sits in a bounded (star-row) parent,
|
||||
where that would balloon the first grid to fill all remaining height. -->
|
||||
<GridLayout row="0" rows="auto" columns="*,*,*,auto" class="controls-tab-bar">
|
||||
<GridLayout row="0" rows="auto" columns="*,*,*,auto,auto" class="controls-tab-bar">
|
||||
<Button col="0" text="Settings" tap="{{ onSettingsTabTap }}" class="{{ settingsTabClass }}" />
|
||||
<Button col="1" text="Watch" tap="{{ onWatchTabTap }}" class="{{ watchTabClass }}" />
|
||||
<Button col="2" text="Ring" tap="{{ onRingTabTap }}" class="{{ ringTabClass }}" />
|
||||
<!-- A Button can't hold an image, so this is a button-styled tile. The
|
||||
<!-- A Button can't hold an image, so these are button-styled tiles. The
|
||||
explicit star row makes the cell fill the tile's height so the icon's
|
||||
center alignment has room to work in. -->
|
||||
<GridLayout col="3" rows="*" tap="{{ onSyntheticMicTap }}" class="tab-button tab-mic-button">
|
||||
<Image src="res://ic_tab_mic" class="tab-mic-icon" verticalAlignment="center" horizontalAlignment="center" />
|
||||
<GridLayout col="3" rows="*" tap="{{ onSyntheticMicTap }}" class="tab-button tab-icon-button">
|
||||
<Image src="res://ic_tab_mic" class="tab-icon" verticalAlignment="center" horizontalAlignment="center" />
|
||||
</GridLayout>
|
||||
<GridLayout col="4" rows="*" tap="{{ onKeyboardTap }}" class="tab-button tab-icon-button">
|
||||
<Image src="res://ic_tab_keyboard" class="tab-icon" verticalAlignment="center" horizontalAlignment="center" />
|
||||
</GridLayout>
|
||||
</GridLayout>
|
||||
|
||||
|
||||
Reference in new issue
Block a user