forked from Blendman974/faceclaw
Many bug fixes
This commit is contained in:
1 parent
602520a840
commit
0d0b55c2da
9 files changed
+125
-25
No files matched your search
@@ -108,10 +108,10 @@ public class BleProtocol {
|
||||
public static byte[] buildImageRawData(ImageTileOptions tile, int sessionId, int totalSize, ImageFragment fragment, int magic) {
|
||||
List<byte[]> inner = new ArrayList<>();
|
||||
inner.add(encodeVarintField(1, tile.containerId));
|
||||
inner.add(encodeStringField(2, tile.name));
|
||||
//inner.add(encodeStringField(2, tile.name));
|
||||
inner.add(encodeVarintField(3, sessionId));
|
||||
inner.add(encodeVarintField(4, totalSize));
|
||||
inner.add(encodeVarintField(5, 0)); //compression
|
||||
//inner.add(encodeVarintField(5, 0)); //compression
|
||||
inner.add(encodeVarintField(6, fragment.index));
|
||||
inner.add(encodeVarintField(7, fragment.size));
|
||||
inner.add(encodeBytesField(8, fragment.data));
|
||||
|
||||
@@ -854,13 +854,15 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
if (!synchronizedCommits) {
|
||||
for (TileImagePlan plan : changedTiles) {
|
||||
for (BleProtocol.ImageFragment fragment : plan.fragments) {
|
||||
enqueueImageFragmentLocked(plan, fragment, fingerprint, updateId, messageNumber++, messageCount, nextTransportSeq++, true, true);
|
||||
boolean requestAck = fragment.index % 2 == 1;
|
||||
enqueueImageFragmentLocked(plan, fragment, fingerprint, updateId, messageNumber++, messageCount, nextTransportSeq++, requestAck, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (TileImagePlan plan : changedTiles) {
|
||||
for (int i = 0; i < plan.fragments.size() - 1; i++) {
|
||||
enqueueImageFragmentLocked(plan, plan.fragments.get(i), fingerprint, updateId, messageNumber++, messageCount, nextTransportSeq++, true, false);
|
||||
boolean requestAck = i % 2 == 1;
|
||||
enqueueImageFragmentLocked(plan, plan.fragments.get(i), fingerprint, updateId, messageNumber++, messageCount, nextTransportSeq++, requestAck, false);
|
||||
}
|
||||
}
|
||||
for (TileImagePlan plan : changedTiles) {
|
||||
@@ -884,7 +886,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
boolean requestAck,
|
||||
boolean isLast
|
||||
) {
|
||||
int magic = IMAGE_FRAGMENT_NO_ACK ? 0 : nextMagic();
|
||||
int magic = requestAck ? nextMagic() : 0;
|
||||
OutboundMessage message = new OutboundMessage(
|
||||
"image",
|
||||
"image " + plan.tile.name + "#" + fragment.index,
|
||||
|
||||
+14
-2
@@ -1,15 +1,19 @@
|
||||
package com.faceclaw.app;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.tns.NativeScriptActivity;
|
||||
|
||||
public class FaceclawForegroundService extends Service {
|
||||
@@ -102,7 +106,15 @@ public class FaceclawForegroundService extends Service {
|
||||
}
|
||||
|
||||
private int foregroundServiceType() {
|
||||
return ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE
|
||||
| ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE;
|
||||
int type = ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE;
|
||||
if (hasRecordAudioPermission()) {
|
||||
type |= ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
private boolean hasRecordAudioPermission() {
|
||||
return ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)
|
||||
== PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
}
|
||||
@@ -32,11 +32,25 @@
|
||||
|
||||
<!-- theme for action-bar -->
|
||||
<style name="NativeScriptToolbarStyleBase" parent="Widget.AppCompat.Toolbar">
|
||||
<item name="android:background">@color/ns_primary</item>
|
||||
<item name="theme">@style/ThemeOverlay.AppCompat.ActionBar</item>
|
||||
<item name="popupTheme">@style/ThemeOverlay.AppCompat</item>
|
||||
<item name="android:background">#424242</item>
|
||||
<item name="theme">@style/NativeScriptToolbarTheme</item>
|
||||
<item name="popupTheme">@style/NativeScriptToolbarPopupTheme</item>
|
||||
</style>
|
||||
|
||||
<style name="NativeScriptToolbarStyle" parent="NativeScriptToolbarStyleBase">
|
||||
</style>
|
||||
|
||||
<style name="NativeScriptToolbarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
|
||||
<item name="android:textColorPrimary">#FFFFFF</item>
|
||||
<item name="android:textColorSecondary">#FFFFFF</item>
|
||||
<item name="colorControlNormal">#FFFFFF</item>
|
||||
<item name="actionMenuTextColor">#FFFFFF</item>
|
||||
</style>
|
||||
|
||||
<style name="NativeScriptToolbarPopupTheme" parent="ThemeOverlay.AppCompat.Light">
|
||||
<item name="android:colorBackground">#FFFFFF</item>
|
||||
<item name="android:textColorPrimary">#222222</item>
|
||||
<item name="android:textColorSecondary">#555555</item>
|
||||
<item name="colorControlNormal">#222222</item>
|
||||
</style>
|
||||
</resources>
|
||||
+25
@@ -1,6 +1,30 @@
|
||||
@import '@nativescript/theme/css/core.css';
|
||||
@import '@nativescript/theme/css/default.css';
|
||||
|
||||
Page {
|
||||
background-color: #ffffff;
|
||||
color: #222222;
|
||||
}
|
||||
|
||||
ActionBar {
|
||||
background-color: #424242;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
ActionItem {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
TextField {
|
||||
background-color: #ffffff;
|
||||
color: #222222;
|
||||
}
|
||||
|
||||
.system-name-modal TextField {
|
||||
background-color: #ffffff;
|
||||
color: #222222;
|
||||
}
|
||||
|
||||
Button.-primary {
|
||||
font-size: 18;
|
||||
}
|
||||
@@ -9,6 +33,7 @@ Button.-primary {
|
||||
margin: 16;
|
||||
padding: 16;
|
||||
background-color: #f6f6f6;
|
||||
color: #222222;
|
||||
border-color: #222222;
|
||||
border-width: 1;
|
||||
border-radius: 8;
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
getDashboardNightscoutSettings,
|
||||
getDashboardSystemCardName,
|
||||
isDashboardVoiceControlEnabled,
|
||||
noteDashboardPhoneTextInput,
|
||||
receiveInput,
|
||||
resetDashboardSleepTimerAndWake,
|
||||
setDashboardBatteryLevels,
|
||||
@@ -203,6 +204,7 @@ class DashboardController {
|
||||
}
|
||||
|
||||
setActiveTextSettingValue(value: string): void {
|
||||
noteDashboardPhoneTextInput();
|
||||
switch (this.activeTextSettingEditorKind) {
|
||||
case "dashboard-name":
|
||||
this.setSystemCardName(value);
|
||||
@@ -252,12 +254,12 @@ class DashboardController {
|
||||
this.appendLog(
|
||||
`Using configured arms: R=${addresses.right} L=${addresses.left}${addresses.ring ? ` ring=${addresses.ring}` : ""}`,
|
||||
);
|
||||
startForegroundNotification("Connecting to the glasses");
|
||||
|
||||
let communicator: FaceclawCommunicatorBridge | null = null;
|
||||
|
||||
try {
|
||||
await ensureBlePermissions();
|
||||
startForegroundNotification("Connecting to the glasses");
|
||||
communicator = new FaceclawCommunicatorBridge({
|
||||
right: addresses.right,
|
||||
left: addresses.left,
|
||||
@@ -352,6 +354,7 @@ class DashboardController {
|
||||
this.screenTimeoutTimer = setInterval(() => {
|
||||
if (this.phase !== "connected" || !this.communicator) return;
|
||||
if (!applyDashboardScreenTimeout()) return;
|
||||
this.endTextSettingEdit();
|
||||
void this.requestRender("interval").catch((error) => {
|
||||
const message = this.formatError(error);
|
||||
this.appendLog(`screen timeout render failed: ${message}`);
|
||||
@@ -649,6 +652,9 @@ class DashboardController {
|
||||
private startVoiceControlIfEnabled(): void {
|
||||
if (!this.communicator) return;
|
||||
if (!isDashboardVoiceControlEnabled()) return;
|
||||
if (this.phase === "connected") {
|
||||
updateForegroundNotification("Connected");
|
||||
}
|
||||
voiceControlBridge.start();
|
||||
}
|
||||
|
||||
|
||||
+30
-1
@@ -1,7 +1,11 @@
|
||||
import { EventData, Observable, Page, ScrollView, TextField } from '@nativescript/core'
|
||||
import { Color, EventData, isAndroid, Observable, Page, ScrollView, TextField } from '@nativescript/core'
|
||||
import { MainViewModel } from './main-view-model'
|
||||
import { dashboardController } from './g2/dashboard-controller'
|
||||
|
||||
const SETTINGS_TEXT_COLOR = new Color('#222222')
|
||||
const SETTINGS_BACKGROUND_COLOR = new Color('#ffffff')
|
||||
const SETTINGS_PLACEHOLDER_COLOR = new Color('#666666')
|
||||
|
||||
export function navigatingTo(args: EventData) {
|
||||
const page = <Page>args.object
|
||||
page.bindingContext = new MainViewModel()
|
||||
@@ -44,9 +48,30 @@ function scrollToBottom(scrollView: ScrollView): void {
|
||||
}, 0)
|
||||
}
|
||||
|
||||
function applySettingsTextFieldContrast(textField: TextField): void {
|
||||
textField.color = SETTINGS_TEXT_COLOR
|
||||
textField.backgroundColor = SETTINGS_BACKGROUND_COLOR
|
||||
textField.placeholderColor = SETTINGS_PLACEHOLDER_COLOR
|
||||
|
||||
if (!isAndroid) {
|
||||
return
|
||||
}
|
||||
|
||||
const nativeTextField = (textField as TextField & { nativeView?: android.widget.EditText }).nativeView
|
||||
if (!nativeTextField) {
|
||||
return
|
||||
}
|
||||
|
||||
nativeTextField.setTextColor(android.graphics.Color.rgb(34, 34, 34))
|
||||
nativeTextField.setHintTextColor(android.graphics.Color.rgb(102, 102, 102))
|
||||
}
|
||||
|
||||
function focusSystemNameField(page: Page): void {
|
||||
setTimeout(() => {
|
||||
const textField = page.getViewById<TextField>('settingsTextField')
|
||||
if (textField) {
|
||||
applySettingsTextFieldContrast(textField)
|
||||
}
|
||||
textField?.focus()
|
||||
}, 0)
|
||||
}
|
||||
@@ -58,6 +83,10 @@ export function loaded(args: EventData) {
|
||||
|
||||
const model = page.bindingContext as MainViewModel | null
|
||||
const scrollView = page.getViewById<ScrollView>('logScrollView')
|
||||
const settingsTextField = page.getViewById<TextField>('settingsTextField')
|
||||
if (settingsTextField) {
|
||||
applySettingsTextFieldContrast(settingsTextField)
|
||||
}
|
||||
if (!model || !scrollView) {
|
||||
return
|
||||
}
|
||||
|
||||
+21
-13
@@ -92,7 +92,6 @@ const SYSTEM_CARD_ITEM_HEIGHT = 38;
|
||||
const SYSTEM_CARD_ITEM_GAP = 2;
|
||||
const BATTERY_ITEM_Y_OFFSET = 4;
|
||||
const TOP_LEFT_MENU_LAYOUT = { x: 8, y: 8, width: 272, height: 128 };
|
||||
const TOP_RIGHT_MENU_LAYOUT = { x: 296, y: 8, width: 272, height: 128 };
|
||||
|
||||
function rawInputEventToInputEvent(event: RawInputEvent): DashboardInputEvent {
|
||||
if (event.kind === "sys-event") {
|
||||
@@ -137,6 +136,16 @@ export async function receiveInput(event: RawInputEvent): Promise<void> {
|
||||
const inputEvent = rawInputEventToInputEvent(event);
|
||||
dashboardState.lastInputAtMs = Date.now();
|
||||
dashboardState.logLines.push(eventToString(inputEvent));
|
||||
if (!dashboardState.screenOn) {
|
||||
if (inputEvent.type === "double-click") {
|
||||
dashboardState.screenOn = true;
|
||||
dashboardState.tiledWakePaintPending = dashboardState.wakeMode === "tiled";
|
||||
if (dashboardLayers.isAtBase()) {
|
||||
dashboardLayers.push(createRootMenuLayer());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
await dashboardLayers.handleInput(inputEvent);
|
||||
}
|
||||
|
||||
@@ -165,6 +174,9 @@ export function setDashboardActions(actions: Partial<LayerActions>): void {
|
||||
}
|
||||
|
||||
export function drawDashboard(): GrayImage {
|
||||
if (!dashboardState.screenOn) {
|
||||
return new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||
}
|
||||
return dashboardLayers.paint();
|
||||
}
|
||||
|
||||
@@ -227,10 +239,13 @@ export function applyDashboardScreenTimeout(nowMs = Date.now()): boolean {
|
||||
if (timeoutMs === null || !dashboardState.screenOn) return false;
|
||||
if (nowMs - dashboardState.lastInputAtMs < timeoutMs) return false;
|
||||
dashboardState.screenOn = false;
|
||||
dashboardLayers.clearToBase();
|
||||
return true;
|
||||
}
|
||||
|
||||
export function noteDashboardPhoneTextInput(nowMs = Date.now()): void {
|
||||
dashboardState.lastInputAtMs = nowMs;
|
||||
}
|
||||
|
||||
export function resetDashboardSleepTimerAndWake(nowMs = Date.now()): boolean {
|
||||
dashboardState.lastInputAtMs = nowMs;
|
||||
if (dashboardState.screenOn) return false;
|
||||
@@ -399,15 +414,6 @@ class DashboardLayer implements Layer {
|
||||
}
|
||||
|
||||
handleInput(event: DashboardInputEvent, ctx: { stack: LayerStack }): void {
|
||||
if (!dashboardState.screenOn) {
|
||||
if (event.type === "double-click") {
|
||||
dashboardState.screenOn = true;
|
||||
dashboardState.tiledWakePaintPending = dashboardState.wakeMode === "tiled";
|
||||
ctx.stack.push(createRootMenuLayer());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.type === "click") {
|
||||
ctx.stack.push(createRootMenuLayer());
|
||||
return;
|
||||
@@ -415,6 +421,8 @@ class DashboardLayer implements Layer {
|
||||
|
||||
if (event.type === "double-click") {
|
||||
dashboardState.screenOn = false;
|
||||
ctx.stack.clearToBase();
|
||||
void dashboardActions.endTextSettingEdit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -424,6 +432,7 @@ class RootMenuLayer extends MenuLayer {
|
||||
if (event.type === "double-click") {
|
||||
dashboardState.screenOn = false;
|
||||
ctx.stack.clearToBase();
|
||||
void ctx.actions.endTextSettingEdit();
|
||||
return;
|
||||
}
|
||||
await super.handleInput(event, ctx);
|
||||
@@ -637,8 +646,7 @@ function createSystemCardSettingsMenuLayer(): MenuLayer {
|
||||
createSystemCardToggleItem("Show Android Notifications", "showAndroidNotifications"),
|
||||
createSystemCardToggleItem("Show Signal Strength", "showSignalStrength"),
|
||||
],
|
||||
TOP_RIGHT_MENU_LAYOUT,
|
||||
true,
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,10 @@ export class LayerStack {
|
||||
this.layers.splice(1);
|
||||
}
|
||||
|
||||
isAtBase(): boolean {
|
||||
return this.layers.length === 1;
|
||||
}
|
||||
|
||||
setActions(actions: Partial<LayerActions>): void {
|
||||
Object.assign(this.ctx.actions, actions);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user