From 79b4aeb87c27c965c54d212d3da07a6f1aaba34f Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Thu, 12 Jun 2025 11:04:09 +0800 Subject: [PATCH 01/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/utils/BreakpointUtil.ets | 2 +- entry/src/main/ets/utils/LiveView.ets | 2 +- entry/src/main/ets/view/RoadView.ets | 2 +- entry/src/main/ets/view/TrafficInfoView.ets | 2 +- entry/src/main/ets/view/TrafficView.ets | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/entry/src/main/ets/utils/BreakpointUtil.ets b/entry/src/main/ets/utils/BreakpointUtil.ets index 45751d3..826f5ae 100644 --- a/entry/src/main/ets/utils/BreakpointUtil.ets +++ b/entry/src/main/ets/utils/BreakpointUtil.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { Constants } from "../constant/Constant"; +import { Constants } from '../constant/Constant'; export class BreakpointType { private sm: T; diff --git a/entry/src/main/ets/utils/LiveView.ets b/entry/src/main/ets/utils/LiveView.ets index fd4d4d2..71f183b 100644 --- a/entry/src/main/ets/utils/LiveView.ets +++ b/entry/src/main/ets/utils/LiveView.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/entry/src/main/ets/view/RoadView.ets b/entry/src/main/ets/view/RoadView.ets index dd5bec6..8f6c76f 100644 --- a/entry/src/main/ets/view/RoadView.ets +++ b/entry/src/main/ets/view/RoadView.ets @@ -31,7 +31,7 @@ export struct RoadView { .width('80%') .height('80%') } - .backgroundImage($r("app.media.traffic_background")) + .backgroundImage($r('app.media.traffic_background')) .backgroundImageSize(ImageSize.Cover) .backgroundImagePosition(Alignment.Center) .height('101%') diff --git a/entry/src/main/ets/view/TrafficInfoView.ets b/entry/src/main/ets/view/TrafficInfoView.ets index 63efea9..cc91902 100644 --- a/entry/src/main/ets/view/TrafficInfoView.ets +++ b/entry/src/main/ets/view/TrafficInfoView.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { LiveView } from "../utils/LiveView" +import { LiveView } from '../utils/LiveView' @Component export struct TrafficInfoView { diff --git a/entry/src/main/ets/view/TrafficView.ets b/entry/src/main/ets/view/TrafficView.ets index f5b1856..5163588 100644 --- a/entry/src/main/ets/view/TrafficView.ets +++ b/entry/src/main/ets/view/TrafficView.ets @@ -13,10 +13,10 @@ * limitations under the License. */ -import { Constants } from "../constant/Constant"; -import { LaneData } from "../model/RouteDataModel"; -import { TrafficInfoView } from "./TrafficInfoView"; -import { BreakpointType } from "../utils/BreakpointUtil"; +import { Constants } from '../constant/Constant'; +import { LaneData } from '../model/RouteDataModel'; +import { TrafficInfoView } from './TrafficInfoView'; +import { BreakpointType } from '../utils/BreakpointUtil'; @Component export struct TrafficView { -- Gitee From 37c3f51caf2299f2d78ef0100c760c9ff857a148 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Mon, 16 Jun 2025 17:44:28 +0800 Subject: [PATCH 02/27] =?UTF-8?q?UX=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/entryability/EntryAbility.ets | 4 + entry/src/main/ets/pages/Index.ets | 78 +++- entry/src/main/ets/view/TrafficInfoView.ets | 128 +++--- entry/src/main/ets/view/TrafficView.ets | 394 +++++++++++------- .../main/resources/base/element/color.json | 28 +- .../main/resources/base/element/string.json | 30 +- .../base/media/turn_right_light_rectangle.png | Bin 0 -> 1091 bytes .../main/resources/dark/element/color.json | 8 - .../main/resources/en_US/element/string.json | 30 +- .../main/resources/zh_CN/element/string.json | 30 +- 10 files changed, 516 insertions(+), 214 deletions(-) create mode 100644 entry/src/main/resources/base/media/turn_right_light_rectangle.png diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index d95a8a6..0593706 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -75,6 +75,10 @@ export default class EntryAbility extends UIAbility { try { windowObj.on('windowSizeChange', (windowSize) => { this.updateBreakpoint(windowSize); + const type: window.AvoidAreaType = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; + const avoidArea: window.AvoidArea = windowObj.getWindowAvoidArea(type); + const bottomRectHeight: number = avoidArea.bottomRect.height; + AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight); }); windowObj.setWindowSystemBarProperties({ diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 387c24a..de0d46f 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -13,14 +13,87 @@ * limitations under the License. */ +import { hilog } from '@kit.PerformanceAnalysisKit'; import { LiveView } from '../utils/LiveView'; import { TrafficView } from '../view/TrafficView'; +const TAG = '[LiveViewLockScreenPage]'; + +@CustomDialog +struct TipDialog { + public controller?: CustomDialogController; + public onConfirm: () => void = () => { + }; + + build() { + Column() { + Row() { + Text($r('app.string.tip')) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .lineHeight(27) + .fontColor($r('app.color.tip')) + } + .height(56) + .width('100%') + .justifyContent(FlexAlign.Center) + .alignItems(VerticalAlign.Center) + + Text($r('app.string.tip_text')) + .fontSize(16) + .fontWeight(FontWeight.Medium) + .lineHeight(21) + .fontColor($r('app.color.tip')) + + Row() { + Text($r('app.string.tip_get')) + .width('100%') + .height(40) + .fontColor($r('app.color.tip_text')) + .textAlign(TextAlign.Center) + .onClick(() => { + hilog.info(0x0000, TAG, 'Button-clicking callback'); + this.onConfirm(); + }) + } + .height(56) + .width('100%') + .margin({ top: 8 }) + .padding({ left: 16, right: 16 }) + .alignItems(VerticalAlign.Top) + .justifyContent(FlexAlign.Center) + } + .width('100%') + .height('100%') + .alignItems(HorizontalAlign.Center) + .borderRadius(32) + .backgroundColor($r('app.color.tip_background')) + } +} + @Entry -@Component -struct Index { +export struct LiveViewLockScreenPage { + private customDialogController: CustomDialogController = new CustomDialogController({ + builder: TipDialog({ + onConfirm: () => { + this.customDialogController?.close(); + } + }), + cancel: () => { + }, + onWillDismiss: (dismissDialogAction: DismissDialogAction) => { + dismissDialogAction.dismiss() + }, + alignment: DialogAlignment.Center, + autoCancel: true, + cornerRadius: 32, + width: 338, + height: 141 + }); + aboutToAppear(): void { LiveView.getInstance().createLiveView(); + this.customDialogController?.open(); } build() { @@ -28,6 +101,7 @@ struct Index { Image($r('app.media.traffic_background')) .width('110%') .height('110%') + TrafficView() } .width('100%') diff --git a/entry/src/main/ets/view/TrafficInfoView.ets b/entry/src/main/ets/view/TrafficInfoView.ets index cc91902..f874b06 100644 --- a/entry/src/main/ets/view/TrafficInfoView.ets +++ b/entry/src/main/ets/view/TrafficInfoView.ets @@ -12,76 +12,90 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { LiveView } from '../utils/LiveView' @Component export struct TrafficInfoView { - @State private isStart: boolean = true; + @State private isShowButton: boolean = false; build() { Row() { - Column() { - Text($r('app.string.traffic_info_first')) - .fontWeight(FontWeight.Bold) - .alignSelf(ItemAlign.Start) - .fontSize($r('sys.float.padding_level12')) - .margin({ - top: $r('sys.float.padding_level8'), + if (this.isShowButton === false) { + Column() { + Text($r('app.string.traffic_info_first')) + .fontColor(Color.Black) + .fontWeight(FontWeight.Bold) + .alignSelf(ItemAlign.Start) + .fontSize($r('sys.float.padding_level12')) + .margin({ + left: $r('sys.float.padding_level12'), + }) + Row() { + Text($r('app.string.traffic_info_second')) + .fontColor(Color.Grey) + .fontWeight(FontWeight.Bold) + .alignSelf(ItemAlign.Start) + .fontSize($r('sys.float.padding_level8')) + Image($r('app.media.traffic_light')) + .height($r('sys.float.padding_level8')) + Text($r('app.string.traffic_info_third')) + .fontColor(Color.Grey) + .fontWeight(FontWeight.Bold) + .alignSelf(ItemAlign.Start) + .fontSize($r('sys.float.padding_level8')) + } + .padding({ + top: $r('sys.float.padding_level4'), left: $r('sys.float.padding_level12'), + bottom: $r('sys.float.padding_level12'), }) + } + .alignItems(HorizontalAlign.Start) + + Column() { + SymbolGlyph($r('sys.symbol.arrow_right_and_square')) + .fontColor([Color.Black]) + .fontSize(25) + .margin(10) + } + .onClick(() => { + this.isShowButton = true; + }) + .backgroundColor($r('app.color.component_background_color')) + .borderRadius(32) + .position({ + right: 16, + }) + } else { Row() { - Text($r('app.string.traffic_info_second')) - .fontColor(Color.Grey) - .fontWeight(FontWeight.Bold) - .alignSelf(ItemAlign.Start) - .fontSize($r('sys.float.padding_level8')) - Image($r('app.media.traffic_light')) - .height($r('sys.float.padding_level8')) - Text($r('app.string.traffic_info_third')) - .fontColor(Color.Grey) - .fontWeight(FontWeight.Bold) - .alignSelf(ItemAlign.Start) - .fontSize($r('sys.float.padding_level8')) + Blank() + Button($r('app.string.Continue')) + .fontColor($r('sys.color.font_emphasize')) + .backgroundColor($r('app.color.traffic_info_button')) + .fontSize(16) + .width('40%') + .onClick(() => { + this.isShowButton = false; + LiveView.getInstance().createLiveView(); + }) + Blank() + Button($r('app.string.Finish')) + .fontColor($r('sys.color.warning')) + .backgroundColor($r('app.color.traffic_info_button')) + .fontSize(16) + .width('40%') + .onClick(() => { + this.isShowButton = false; + LiveView.getInstance().finishLiveView(); + }) + Blank() } - .padding({ - top: $r('sys.float.padding_level4'), - left: $r('sys.float.padding_level12'), - bottom: $r('sys.float.padding_level16'), + .margin({ + top: 6, }) + .width('100%') } - .alignItems(HorizontalAlign.Start) - - Column() { - Button('开始导航') - .fontColor(this.isStart ? $r('sys.color.comp_background_emphasize') : Color.White) - .backgroundColor(this.isStart ? $r('sys.color.comp_background_secondary') : - $r('sys.color.comp_background_emphasize')) - .fontSize(12) - .width(80) - .height(30) - .onClick(() => { - this.isStart = true; - LiveView.getInstance().createLiveView(); - }) - Button('结束导航') - .fontColor(!this.isStart ? $r('sys.color.comp_background_emphasize') : Color.White) - .backgroundColor(!this.isStart ? $r('sys.color.comp_background_secondary') : - $r('sys.color.comp_background_emphasize')) - .fontSize(12) - .width(80) - .height(30) - .onClick(() => { - this.isStart = false; - LiveView.getInstance().finishLiveView(); - }) - .margin({ - top: $r('sys.float.padding_level4') - }) - } - .position({ - top: 10, - right: 16, - }) } .width('100%') } diff --git a/entry/src/main/ets/view/TrafficView.ets b/entry/src/main/ets/view/TrafficView.ets index 5163588..8a82296 100644 --- a/entry/src/main/ets/view/TrafficView.ets +++ b/entry/src/main/ets/view/TrafficView.ets @@ -14,191 +14,305 @@ */ import { Constants } from '../constant/Constant'; -import { LaneData } from '../model/RouteDataModel'; -import { TrafficInfoView } from './TrafficInfoView'; import { BreakpointType } from '../utils/BreakpointUtil'; +import { TrafficInfoView } from './TrafficInfoView'; @Component export struct TrafficView { + @StorageProp('bottomRectHeight') bottomRectHeight: number = 0; @StorageLink('horizontalBreakpoint') horizontalBreakpoint: string = Constants.BREAK_POINT_SM; @StorageLink('verticalBreakpoint') verticalBreakpoint: string = Constants.BREAK_POINT_SM; - @State roadInfo: LaneData | undefined = undefined; - @State isShow: boolean = false; + @Prop lane: number = 2; + private updateInterval: number | undefined; + + aboutToAppear(): void { + this.updateInterval = setInterval(() => { + if (this.lane === 2) { + this.lane = 1; + } else { + this.lane = 2; + } + }, 2000) + } - @Builder - myBuilder() { - Row() { - TrafficInfoView() + aboutToDisappear(): void { + if (this.updateInterval !== undefined) { + clearInterval(this.updateInterval); + this.updateInterval = undefined; } - .backgroundColor($r('sys.color.background_secondary')) - .width('100%') - .height('100%') } build() { - Column() { - Row() { - Column() { + if (this.horizontalBreakpoint !== Constants.BREAK_POINT_SM || + this.verticalBreakpoint !== Constants.BREAK_POINT_MD) { + Column() { + Row() { Column() { - Row() { - Image($r('app.media.big_arrow')) - .objectFit(ImageFit.Contain) - .height(new BreakpointType(80, 70, 70).getValue(this.horizontalBreakpoint)) - Column() { - Text($r('app.string.traffic_info_meter')) - .fontColor(Color.White) - .fontWeight(FontWeight.Bold) - .alignSelf(ItemAlign.Start) - .fontSize(40) - .margin({ - top: $r('sys.float.padding_level8'), - left: $r('sys.float.padding_level8'), - }) - Text($r('app.string.road_name')) + Column() { + Row() { + Image($r('app.media.big_arrow')) + .objectFit(ImageFit.Contain) + .height(new BreakpointType(80, 70, 70,).getValue(this.horizontalBreakpoint)) + Column() { + Text($r('app.string.traffic_info_meter')) + .fontColor(Color.White) + .fontWeight(FontWeight.Bold) + .alignSelf(ItemAlign.Start) + .fontSize(40) + .margin({ + top: $r('sys.float.padding_level8'), + left: $r('sys.float.padding_level8'), + }) + Text($r('app.string.road_name')) + .fontColor(Color.White) + .fontWeight(FontWeight.Regular) + .alignSelf(ItemAlign.Start) + .fontSize(24) + .margin({ + left: $r('sys.float.padding_level8'), + }) + } + } + .borderRadius({ + topLeft: new BreakpointType(0, 16, 16,).getValue(this.horizontalBreakpoint), + topRight: new BreakpointType(0, 16, 16,).getValue(this.horizontalBreakpoint), + }) + .backgroundColor($r('app.color.Index_background_first')) + .width(new BreakpointType('100%', '50%', '30%',).getValue(this.horizontalBreakpoint)) + .padding({ + bottom: $r('sys.float.padding_level8'), + top: new BreakpointType($r('sys.float.padding_level16'), $r('sys.float.padding_level0'), + $r('sys.float.padding_level0'),).getValue(this.horizontalBreakpoint), + left: new BreakpointType($r('sys.float.padding_level8'), $r('sys.float.padding_level12'), + $r('sys.float.padding_level16'),).getValue(this.horizontalBreakpoint), + }) + + Row() { + Text($r('app.string.then')) .fontColor(Color.White) .fontWeight(FontWeight.Regular) .alignSelf(ItemAlign.Start) - .fontSize(24) + .fontSize(22) .margin({ left: $r('sys.float.padding_level8'), + right: $r('sys.float.padding_level2'), }) + Image($r('app.media.little_arrow')) + .objectFit(ImageFit.Contain) + .height(25) } - } - .borderRadius({ - topLeft: new BreakpointType(0, 16, 16).getValue(this.horizontalBreakpoint), - topRight: new BreakpointType(0, 16, 16).getValue(this.horizontalBreakpoint), - }) - .backgroundColor($r('app.color.Index_background_first')) - .width(new BreakpointType('100%', '50%', '30%').getValue(this.horizontalBreakpoint)) - .padding({ - bottom: $r('sys.float.padding_level8'), - top: new BreakpointType(this.verticalBreakpoint === Constants.BREAK_POINT_MD ? - ('sys.float.padding_level8') : $r('sys.float.padding_level16'), $r('sys.float.padding_level0'), - $r('sys.float.padding_level0')).getValue(this.horizontalBreakpoint), - left: new BreakpointType($r('sys.float.padding_level8'), $r('sys.float.padding_level12'), - $r('sys.float.padding_level16')).getValue(this.horizontalBreakpoint), - }) + .borderRadius({ + bottomLeft: new BreakpointType(0, 16, 16,).getValue(this.horizontalBreakpoint), + bottomRight: new BreakpointType(0, 16, 16,).getValue(this.horizontalBreakpoint), + }) + .padding({ + bottom: $r('sys.float.padding_level2'), + top: $r('sys.float.padding_level2'), + }) + .width(new BreakpointType('100%', '50%', '30%',).getValue(this.horizontalBreakpoint)) + .backgroundColor($r('app.color.Index_background_second')) - Row() { - Text($r('app.string.then')) - .fontColor(Color.White) - .fontWeight(FontWeight.Regular) - .alignSelf(ItemAlign.Start) - .fontSize(22) - .margin({ - left: $r('sys.float.padding_level8'), - right: $r('sys.float.padding_level2'), - }) - Image($r('app.media.little_arrow')) - .objectFit(ImageFit.Contain) - .height(new BreakpointType(25, 25, 25).getValue(this.horizontalBreakpoint)) + if (this.horizontalBreakpoint !== Constants.BREAK_POINT_SM) { + Image($r('app.media.traffic_info_speed')) + .objectFit(ImageFit.Contain) + .height(80) + .position({ + top: 0, + left: this.horizontalBreakpoint === Constants.BREAK_POINT_MD ? '51%' : '31%', + }) + } } - .borderRadius({ - bottomLeft: new BreakpointType(0, 16, 16).getValue(this.horizontalBreakpoint), - bottomRight: new BreakpointType(0, 16, 16).getValue(this.horizontalBreakpoint), - }) - .padding({ - bottom: $r('sys.float.padding_level2'), - top: $r('sys.float.padding_level2'), - }) - .width(new BreakpointType('100%', '50%', '30%').getValue(this.horizontalBreakpoint)) - .backgroundColor($r('app.color.Index_background_second')) - if (this.horizontalBreakpoint !== Constants.BREAK_POINT_SM) { - Image($r('app.media.traffic_info_speed')) + Row() { + if (this.horizontalBreakpoint === Constants.BREAK_POINT_SM) { + Image($r('app.media.traffic_info_speed')) + .objectFit(ImageFit.Contain) + .height(70) + } + Image($r('app.media.traffic_info_label')) .objectFit(ImageFit.Contain) - .height(80) - .position({ - top: 0, - left: this.horizontalBreakpoint === Constants.BREAK_POINT_MD ? '51%' : '31%', - }) + .height(new BreakpointType(70, 80, 80,).getValue(this.horizontalBreakpoint)) } + .width(new BreakpointType('100%', '40%', '30%',).getValue(this.horizontalBreakpoint)) } + .margin({ + left: new BreakpointType($r('sys.float.padding_level0'), $r('sys.float.padding_level12'), + $r('sys.float.padding_level16'),).getValue(this.horizontalBreakpoint), + top: new BreakpointType($r('sys.float.padding_level0'), $r('sys.float.padding_level16'), + $r('sys.float.padding_level16'),).getValue(this.horizontalBreakpoint), + }) + } + .width('100%') + .justifyContent(FlexAlign.Start) - Row() { - if (this.horizontalBreakpoint === Constants.BREAK_POINT_SM) { - Image($r('app.media.traffic_info_speed')) - .objectFit(ImageFit.Contain) - .height(70) + Blank() + + Row() { + Stack({ alignContent: Alignment.Top }) { + if (this.lane === 2) { + Image($r('app.media.traffic_right')) + .width(new BreakpointType('70%', '50%', '30%',).getValue(this.horizontalBreakpoint)) + } else { + Image($r('app.media.traffic_left')) + .width(new BreakpointType('70%', '50%', '30%',).getValue(this.horizontalBreakpoint)) } - Image($r('app.media.traffic_info_label')) + + Image($rawfile('traffic_light.svg')) .objectFit(ImageFit.Contain) - .height(new BreakpointType(70, 80, 80).getValue(this.horizontalBreakpoint)) + .width(new BreakpointType('20%', '15%', '10%',).getValue(this.horizontalBreakpoint)) + .position({ + left: '70%', + top: 30 + }) } - .width(new BreakpointType('100%', '40%', '30%').getValue(this.horizontalBreakpoint)) + .width('100%') } - .margin({ - left: new BreakpointType($r('sys.float.padding_level0'), $r('sys.float.padding_level12'), - $r('sys.float.padding_level16')).getValue(this.horizontalBreakpoint), - top: new BreakpointType($r('sys.float.padding_level0'), $r('sys.float.padding_level16'), - $r('sys.float.padding_level16')).getValue(this.horizontalBreakpoint), - }) - } - .width('100%') - .justifyContent(FlexAlign.Start) - Blank() + Blank() + Blank() - Row() { - Stack({ alignContent: Alignment.Top }) { - Image($r('app.media.traffic_right')) - .width(new BreakpointType(this.verticalBreakpoint === Constants.BREAK_POINT_MD ? '35%' : '70%', '50%', - '30%').getValue(this.horizontalBreakpoint)) - Image($rawfile('traffic_light.svg')) + Row() { + Column() { + Divider() + .strokeWidth(4) + .color($r('app.color.traffic_info_line')) + .width($r('sys.float.padding_level24')) + .lineCap(LineCapStyle.Round) + .margin({ + top: $r('sys.float.padding_level3'), + bottom: $r('sys.float.padding_level7') + }) + + TrafficInfoView() + } + .height(100) + .width(new BreakpointType('100%', '300vp', '360vp',).getValue(this.horizontalBreakpoint)) + .borderColor($r('sys.color.comp_divider')) + .borderRadius({ + topLeft: $r('sys.float.corner_radius_level12'), + topRight: $r('sys.float.corner_radius_level12'), + bottomLeft: new BreakpointType($r('sys.float.padding_level0'), $r('sys.float.corner_radius_level12'), + $r('sys.float.corner_radius_level12'),).getValue(this.horizontalBreakpoint), + bottomRight: new BreakpointType($r('sys.float.padding_level0'), $r('sys.float.corner_radius_level12'), + $r('sys.float.corner_radius_level12'),).getValue(this.horizontalBreakpoint), + }) + .backgroundColor($r('app.color.traffic_info_background_color')) + .shadow(ShadowStyle.OUTER_DEFAULT_XS) + .position({ + bottom: 0, + left: new BreakpointType($r('sys.float.padding_level0'), $r('sys.float.corner_radius_level12'), + $r('sys.float.corner_radius_level16'),).getValue(this.horizontalBreakpoint), + }) + .padding({ + bottom: new BreakpointType(px2vp(this.bottomRectHeight), 0, 0,).getValue(this.horizontalBreakpoint), + }) + .margin({ + bottom: new BreakpointType(0, px2vp(this.bottomRectHeight), + px2vp(this.bottomRectHeight),).getValue(this.horizontalBreakpoint), + }) + } + .width('100%') + } + .width('100%') + .height('100%') + .backgroundImage($r('app.media.traffic_background')) + .backgroundImageSize(ImageSize.Cover) + .backgroundImagePosition(Alignment.Center) + } else { + Column() { + Stack() { + Image($r('app.media.traffic_info_speed')) .objectFit(ImageFit.Contain) - .width(new BreakpointType('20%', '20%', '10%').getValue(this.horizontalBreakpoint)) + .height(70) .position({ - left: '70%', - top: 30 + top: 16, + left: 16, }) - } - .width('100%') - .onClick(() => { - if (this.horizontalBreakpoint === Constants.BREAK_POINT_SM && - this.verticalBreakpoint === Constants.BREAK_POINT_MD) { - this.isShow = true; + + if (this.lane === 2) { + Image($r('app.media.traffic_right')) + .width('60%') + .offset({ + y: 15, + }) } else { - this.isShow = false; + Image($r('app.media.traffic_left')) + .width('60%') + .offset({ + y: 15, + }) } - }) - } - Blank() + Column() { + Image($r('app.media.turn_right_light_rectangle')) + .objectFit(ImageFit.Contain) + .width(40) + .height(25) + .margin({ + top: 8, + }) - Row(){ - if (this.horizontalBreakpoint !== Constants.BREAK_POINT_SM || - this.verticalBreakpoint !== Constants.BREAK_POINT_MD) { - Row() { - TrafficInfoView() + Text($r('app.string.traffic_info_smmd_first')) + .fontColor(Color.Black) + .alignSelf(ItemAlign.Start) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .margin({ + left: 16, + right: 16, + top: 8, + bottom: 8, + }) + Text($r('app.string.traffic_info_smmd_second')) + .fontColor(Color.Black) + .alignSelf(ItemAlign.Start) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .margin({ + left: 16, + right: 16, + bottom: 8, + }) } - .onSizeChange(() => { - this.isShow = false; + .justifyContent(FlexAlign.Center) + .borderRadius(16) + .backgroundColor($r('sys.color.ohos_id_blur_style_component_thick_color')) + .position({ + top: 16, + right: 16 }) - .margin({ - left: new BreakpointType($r('sys.float.padding_level0'), $r('sys.float.padding_level12'), - $r('sys.float.padding_level16')).getValue(this.horizontalBreakpoint), - }) - .backgroundColor($r('sys.color.background_secondary')) - .width(new BreakpointType('100%', '50%', '30%').getValue(this.horizontalBreakpoint)) - .height(120) + } + .width('100%') + + Blank() + + Row() { + Column() { + Divider() + .strokeWidth(4) + .color($r('app.color.traffic_info_line')) + .width($r('sys.float.padding_level24')) + .lineCap(LineCapStyle.Round) + .margin({ + top: $r('sys.float.padding_level3'), + bottom: $r('sys.float.padding_level7') + }) + + TrafficInfoView() + } + .height(100) + .width(new BreakpointType('100%', '300vp', '360vp',).getValue(this.horizontalBreakpoint)) + .borderColor($r('sys.color.comp_divider')) .borderRadius({ - topLeft: 32, - topRight: 32, + topLeft: $r('sys.float.corner_radius_level12'), + topRight: $r('sys.float.corner_radius_level12'), }) + .backgroundColor($r('app.color.traffic_info_background_color')) + .shadow(ShadowStyle.OUTER_DEFAULT_XS) } + .width('100%') } - .width('100%') + .height('100%') } - .bindSheet($$this.isShow, this.myBuilder(), { - height: 90, - width: 440, - preferType: SheetType.BOTTOM, - showClose: false, - }) - .width('100%') - .height('100%') - .backgroundImage($r('app.media.traffic_background')) - .backgroundImageSize(ImageSize.Cover) - .backgroundImagePosition(Alignment.Center) } } \ No newline at end of file diff --git a/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json index a332bbb..4ed1297 100644 --- a/entry/src/main/resources/base/element/color.json +++ b/entry/src/main/resources/base/element/color.json @@ -13,12 +13,32 @@ "value": "#303030" }, { - "name": "xmark_foreground", - "value": "#E5000000" + "name": "component_background_color", + "value": "#0C000000" }, { - "name": "xmark_background", - "value": "#19000000" + "name": "traffic_info_line", + "value": "#33000000" + }, + { + "name": "traffic_info_background_color", + "value": "#F1F3F5" + }, + { + "name": "traffic_info_button", + "value": "#08000000" + }, + { + "name": "tip", + "value": "#000000" + }, + { + "name": "tip_background", + "value": "#ffffff" + }, + { + "name": "tip_text", + "value": "#0A57F7" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 2a8552a..46b8d3a 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -14,12 +14,20 @@ }, { "name": "reason_background", - "value": "Background operation to update the live view" + "value": "后台更新实况窗数据" }, { "name": "traffic_info_meter", "value": "800米" }, + { + "name": "traffic_info_smmd_first", + "value": "800米" + }, + { + "name": "traffic_info_smmd_second", + "value": "后右转" + }, { "name": "traffic_info_first", "value": "1 小时 24 分钟" @@ -63,6 +71,26 @@ { "name": "then", "value": "然后" + }, + { + "name": "Continue", + "value": "继续导航" + }, + { + "name": "Finish", + "value": "停止导航" + }, + { + "name": "tip", + "value": "提示" + }, + { + "name": "tip_text", + "value": "申请锁屏沉浸实况窗权限可完整体验该功能" + }, + { + "name": "tip_get", + "value": "知道了" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/base/media/turn_right_light_rectangle.png b/entry/src/main/resources/base/media/turn_right_light_rectangle.png new file mode 100644 index 0000000000000000000000000000000000000000..cd3bbc2f67d07b8f898d5fc777fe07e64fa8a247 GIT binary patch literal 1091 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7xzrVBzv~aSW-5dwct0u5`Fa%ftOG zQ%byN^IdYXvgEJyP}Ed0^yLaFQwg?-VY1x)nbAH$LX7j?&84Zg+B$w*%HMwN+4ILN z*ZTk6Ecv<9qOrAqKKDbHy5sKmx818NlsRAaX8o=hjp^?NA0_Pj%=cmA*UzgT8R(UN zEqhWOt2fJHg8O~edr?OeOYX523Cj3RasHZn5J~e95kD7CTz^zbIK$ zuOINE+rGMcas-enUcU47eVso7=Wab};j-`8yE^~N^ZtMPw*LJUUcPJhzq5zY8Ci;i~c{&AS+`zF2rztp$T<$GV-3)LB%4|(%m^uNg;lls-={T~ijE<5^9 z?4Ql~l3%<3Ek4A*BKo5gcl|oQov-Z!e>j#3uiscZ&#(JO$iw!lzHjm$p8xFe)9roV zA^x?qZ`}W8DVHf&E?QS`_sBl6e=_$q%l|TS*&oPDvgfY<^S Date: Mon, 16 Jun 2025 18:33:04 +0800 Subject: [PATCH 03/27] =?UTF-8?q?UX=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 7 ++++++- entry/src/main/ets/view/TrafficInfoView.ets | 13 +++++++++++++ entry/src/main/resources/base/element/string.json | 6 +++++- entry/src/main/resources/en_US/element/string.json | 4 ++++ entry/src/main/resources/zh_CN/element/string.json | 6 +++++- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index de0d46f..1e0e6ca 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -39,11 +39,16 @@ struct TipDialog { .justifyContent(FlexAlign.Center) .alignItems(VerticalAlign.Center) + Blank() + Text($r('app.string.tip_text')) .fontSize(16) .fontWeight(FontWeight.Medium) .lineHeight(21) .fontColor($r('app.color.tip')) + .margin({ left: 16, right: 16 }) + + Blank() Row() { Text($r('app.string.tip_get')) @@ -88,7 +93,7 @@ export struct LiveViewLockScreenPage { autoCancel: true, cornerRadius: 32, width: 338, - height: 141 + height: 175, }); aboutToAppear(): void { diff --git a/entry/src/main/ets/view/TrafficInfoView.ets b/entry/src/main/ets/view/TrafficInfoView.ets index f874b06..6cccda4 100644 --- a/entry/src/main/ets/view/TrafficInfoView.ets +++ b/entry/src/main/ets/view/TrafficInfoView.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +import { promptAction } from '@kit.ArkUI'; import { LiveView } from '../utils/LiveView' @Component @@ -78,6 +79,12 @@ export struct TrafficInfoView { .onClick(() => { this.isShowButton = false; LiveView.getInstance().createLiveView(); + this.getUIContext().getPromptAction().showToast({ + message: $r('app.string.toast'), + duration: 2000, + showMode: promptAction.ToastShowMode.DEFAULT, + bottom: 180 + }); }) Blank() Button($r('app.string.Finish')) @@ -88,6 +95,12 @@ export struct TrafficInfoView { .onClick(() => { this.isShowButton = false; LiveView.getInstance().finishLiveView(); + this.getUIContext().getPromptAction().showToast({ + message: $r('app.string.toast'), + duration: 2000, + showMode: promptAction.ToastShowMode.DEFAULT, + bottom: 180 + }); }) Blank() } diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 46b8d3a..aa9d46c 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -86,11 +86,15 @@ }, { "name": "tip_text", - "value": "申请锁屏沉浸实况窗权限可完整体验该功能" + "value": " 本案例已完成Pura X内外屏适配和实况窗功能开发,因涉及权限申请,仅做UI展示,具体开发请参考示例代码。" }, { "name": "tip_get", "value": "知道了" + }, + { + "name": "toast", + "value": "仅做功能原型展示,具体业务需自行实现。" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index a12041f..4d1556f 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -91,6 +91,10 @@ { "name": "tip_get", "value": "I get" + }, + { + "name": "toast", + "value": "Just a functional prototype—you’ll need to implement the business logic yourself." } ] } \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index 46b8d3a..aa9d46c 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -86,11 +86,15 @@ }, { "name": "tip_text", - "value": "申请锁屏沉浸实况窗权限可完整体验该功能" + "value": " 本案例已完成Pura X内外屏适配和实况窗功能开发,因涉及权限申请,仅做UI展示,具体开发请参考示例代码。" }, { "name": "tip_get", "value": "知道了" + }, + { + "name": "toast", + "value": "仅做功能原型展示,具体业务需自行实现。" } ] } \ No newline at end of file -- Gitee From ffd2821e80fe5c05b873b6415ae5553a6669fc72 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Wed, 25 Jun 2025 15:15:37 +0800 Subject: [PATCH 04/27] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=9F=E5=BC=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/liveview/LiveViewExtAbility.ets | 11 ++++------- entry/src/main/ets/liveview/LockScreenPage.ets | 8 +++----- entry/src/main/ets/pages/Index.ets | 2 +- entry/src/main/ets/utils/LiveView.ets | 11 ++++++----- entry/src/main/ets/view/TrafficInfoView.ets | 4 ++-- entry/src/main/ets/view/TrafficView.ets | 8 +++++--- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/entry/src/main/ets/liveview/LiveViewExtAbility.ets b/entry/src/main/ets/liveview/LiveViewExtAbility.ets index ed753c1..4f754eb 100644 --- a/entry/src/main/ets/liveview/LiveViewExtAbility.ets +++ b/entry/src/main/ets/liveview/LiveViewExtAbility.ets @@ -60,6 +60,7 @@ export default class LiveViewExtAbility extends LiveViewLockScreenExtensionAbili hilog.error(0x0000, TAG, `updateBreakpoint catch err:`, (error as BusinessError).message); } } + // [End updateBreakPoint] onCreate(_launchParam: AbilityConstant.LaunchParam): void { @@ -83,9 +84,6 @@ export default class LiveViewExtAbility extends LiveViewLockScreenExtensionAbili onSessionCreate(_want: Want, session: UIExtensionContentSession): void { // [StartExclude createLiveView] hilog.info(0x0000, TAG, 'LiveViewLockScreenExtAbility onSessionCreate begin.'); - let param: Record = { - 'session': session - }; // [EndExclude windowSizeListener] // Window size listener. const extensionWindow = session.getUIExtensionWindowProxy(); @@ -94,8 +92,7 @@ export default class LiveViewExtAbility extends LiveViewLockScreenExtensionAbili }); // [End windowSizeListener] // [EndExclude subscribeCommonEvent] - // Create state storage (for cross-page data sharing). - let storage: LocalStorage = new LocalStorage(param); + // Initialize event subscription. let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { events: ['live_view_lock_screen'], @@ -122,14 +119,14 @@ export default class LiveViewExtAbility extends LiveViewLockScreenExtensionAbili hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in subscribe commonEvent success.'); if (data.parameters) { let laneData = data.parameters['roadData'] as LaneData; - storage.setOrCreate('laneData', laneData); + AppStorage.setOrCreate('laneData', laneData); hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in receive commonEvent.'); } }); }) // [End subscribeCommonEvent] // [EndExclude createLiveView] - session.loadContent('liveview/LockScreenPage', storage); + session.loadContent('liveview/LockScreenPage'); } // [End createLiveView] diff --git a/entry/src/main/ets/liveview/LockScreenPage.ets b/entry/src/main/ets/liveview/LockScreenPage.ets index 76679c6..866d801 100644 --- a/entry/src/main/ets/liveview/LockScreenPage.ets +++ b/entry/src/main/ets/liveview/LockScreenPage.ets @@ -18,14 +18,11 @@ import { LaneData } from '../model/RouteDataModel'; import { BreakpointType } from '../utils/BreakpointUtil'; import { RoadView } from '../view/RoadView'; -let storage: LocalStorage = LocalStorage.getShared(); - -@Entry(storage) -@Component +@Entry struct Index { // [Start layoutBasedOnVerticalBreakpoint] @StorageLink('verticalBreakpoint') verticalBreakpoint: string = Constants.BREAK_POINT_SM; - @LocalStorageProp('laneData') roadInfo: LaneData | undefined = undefined; + @StorageProp('laneData') roadInfo: LaneData | undefined = undefined; build() { Stack({ alignContent: Alignment.Top }) { @@ -43,5 +40,6 @@ struct Index { .width('100%') .height('100%') } + // [End layoutBasedOnVerticalBreakpoint] } \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 1e0e6ca..076f342 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -97,7 +97,7 @@ export struct LiveViewLockScreenPage { }); aboutToAppear(): void { - LiveView.getInstance().createLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext()).createLiveView(); this.customDialogController?.open(); } diff --git a/entry/src/main/ets/utils/LiveView.ets b/entry/src/main/ets/utils/LiveView.ets index 71f183b..fda43bd 100644 --- a/entry/src/main/ets/utils/LiveView.ets +++ b/entry/src/main/ets/utils/LiveView.ets @@ -30,21 +30,21 @@ const TAG: string = '[LiveView]'; export class LiveView { // Singleton pattern implementation private static instance: LiveView; - private context: Context; + private context: Context | undefined; private liveViewController: LiveViewUtil; private updateInterval: number | undefined; // Private constructor for singleton pattern - private constructor() { - this.context = getContext(this); + private constructor(context: Context | undefined) { + this.context = context; this.liveViewController = new LiveViewUtil(); } // Singleton accessor method - public static getInstance(): LiveView { + public static getInstance(context: Context | undefined): LiveView { // Lazy initialization of the singleton instance if (!LiveView.instance) { - LiveView.instance = new LiveView(); + LiveView.instance = new LiveView(context); } return LiveView.instance; } @@ -163,5 +163,6 @@ export class LiveView { `Failed to Operation getWantAgent. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); } } + // [End startContinuousRunningTask] } \ No newline at end of file diff --git a/entry/src/main/ets/view/TrafficInfoView.ets b/entry/src/main/ets/view/TrafficInfoView.ets index 6cccda4..c688693 100644 --- a/entry/src/main/ets/view/TrafficInfoView.ets +++ b/entry/src/main/ets/view/TrafficInfoView.ets @@ -78,7 +78,7 @@ export struct TrafficInfoView { .width('40%') .onClick(() => { this.isShowButton = false; - LiveView.getInstance().createLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext()).createLiveView(); this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast'), duration: 2000, @@ -94,7 +94,7 @@ export struct TrafficInfoView { .width('40%') .onClick(() => { this.isShowButton = false; - LiveView.getInstance().finishLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext()).finishLiveView(); this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast'), duration: 2000, diff --git a/entry/src/main/ets/view/TrafficView.ets b/entry/src/main/ets/view/TrafficView.ets index 8a82296..4fb2851 100644 --- a/entry/src/main/ets/view/TrafficView.ets +++ b/entry/src/main/ets/view/TrafficView.ets @@ -23,6 +23,7 @@ export struct TrafficView { @StorageLink('horizontalBreakpoint') horizontalBreakpoint: string = Constants.BREAK_POINT_SM; @StorageLink('verticalBreakpoint') verticalBreakpoint: string = Constants.BREAK_POINT_SM; @Prop lane: number = 2; + private uiContext: UIContext = this.getUIContext(); private updateInterval: number | undefined; aboutToAppear(): void { @@ -204,11 +205,12 @@ export struct TrafficView { $r('sys.float.corner_radius_level16'),).getValue(this.horizontalBreakpoint), }) .padding({ - bottom: new BreakpointType(px2vp(this.bottomRectHeight), 0, 0,).getValue(this.horizontalBreakpoint), + bottom: new BreakpointType(this.uiContext.px2vp(this.bottomRectHeight), 0, + 0,).getValue(this.horizontalBreakpoint), }) .margin({ - bottom: new BreakpointType(0, px2vp(this.bottomRectHeight), - px2vp(this.bottomRectHeight),).getValue(this.horizontalBreakpoint), + bottom: new BreakpointType(0, this.uiContext.px2vp(this.bottomRectHeight), + this.uiContext.px2vp(this.bottomRectHeight),).getValue(this.horizontalBreakpoint), }) } .width('100%') -- Gitee From 37282c338698dcc56a2d04670c8413f3260b86e0 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Wed, 9 Jul 2025 10:12:32 +0800 Subject: [PATCH 05/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- entry/src/main/ets/pages/Index.ets | 2 +- entry/src/main/ets/utils/LiveView.ets | 8 ++++---- entry/src/main/ets/utils/LiveViewUtil.ets | 15 ++++++++++----- entry/src/main/ets/view/TrafficInfoView.ets | 4 ++-- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6e0b5f7..0b0ac67 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,8 @@ 1.本示例仅支持标准系统上运行,支持设备:华为手机; -2.HarmonyOS系统:HarmonyOS 5.0.0 Developer Release及以上; +2.HarmonyOS系统:HarmonyOS 5.0.0 Release及以上; -3.DevEco Studio版本:DevEco Studio 5.0.0 Developer Release及以上; +3.DevEco Studio版本:DevEco Studio 5.0.0 Release及以上; -4.HarmonyOS SDK版本:HarmonyOS 5.0.0 Developer Release SDK及以上。 \ No newline at end of file +4.HarmonyOS SDK版本:HarmonyOS 5.0.0 Release SDK及以上。 \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 076f342..78957cc 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -97,7 +97,7 @@ export struct LiveViewLockScreenPage { }); aboutToAppear(): void { - LiveView.getInstance(this.getUIContext().getHostContext()).createLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext() as Context).createLiveView(); this.customDialogController?.open(); } diff --git a/entry/src/main/ets/utils/LiveView.ets b/entry/src/main/ets/utils/LiveView.ets index fda43bd..4ae8213 100644 --- a/entry/src/main/ets/utils/LiveView.ets +++ b/entry/src/main/ets/utils/LiveView.ets @@ -30,18 +30,18 @@ const TAG: string = '[LiveView]'; export class LiveView { // Singleton pattern implementation private static instance: LiveView; - private context: Context | undefined; + private context: Context; private liveViewController: LiveViewUtil; private updateInterval: number | undefined; // Private constructor for singleton pattern - private constructor(context: Context | undefined) { + private constructor(context: Context) { this.context = context; - this.liveViewController = new LiveViewUtil(); + this.liveViewController = new LiveViewUtil(context); } // Singleton accessor method - public static getInstance(context: Context | undefined): LiveView { + public static getInstance(context: Context): LiveView { // Lazy initialization of the singleton instance if (!LiveView.instance) { LiveView.instance = new LiveView(context); diff --git a/entry/src/main/ets/utils/LiveViewUtil.ets b/entry/src/main/ets/utils/LiveViewUtil.ets index 1616ebb..eb060cf 100644 --- a/entry/src/main/ets/utils/LiveViewUtil.ets +++ b/entry/src/main/ets/utils/LiveViewUtil.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { application, Want, wantAgent } from '@kit.AbilityKit'; +import { Want, wantAgent } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; // [Start createLiveView] import { liveViewManager } from '@kit.LiveViewKit'; @@ -24,17 +24,21 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = '[LiveViewUtil]'; export class LiveViewUtil { - private context = application.getApplicationContext(); + private context: Context; private defaultLiveView?: liveViewManager.LiveView; private sequence: number = 0; + public constructor(context: Context) { + this.context = context; + } + public async startLiveView(params: RouteData) { // Verify that the live view switch is turned on if (!await LiveViewUtil.isLiveViewEnabled()) { hilog.error(0x0000, TAG, '%{public}s', 'Live view is disabled.'); return; } - this.defaultLiveView = await this.createPrimaryLiveVie(); + this.defaultLiveView = await this.createPrimaryLiveView(); this.updateLiveViewInfo(params); return await liveViewManager.startLiveView(this.defaultLiveView); @@ -65,7 +69,7 @@ export class LiveViewUtil { public async closeLiveView() { // Ensure that the sequence is greater than the current live window page. this.sequence++; - this.defaultLiveView = await this.createPrimaryLiveVie(); + this.defaultLiveView = await this.createPrimaryLiveView(); await liveViewManager.stopLiveView(this.defaultLiveView).then(() => { this.sequence = 0; this.defaultLiveView = undefined; @@ -76,6 +80,7 @@ export class LiveViewUtil { }); return; } + // [End closeLiveView] private static async isLiveViewEnabled(): Promise { @@ -118,7 +123,7 @@ export class LiveViewUtil { this.defaultLiveView = liveView; } - private async createPrimaryLiveVie(): Promise { + private async createPrimaryLiveView(): Promise { // [EndExclude createLiveView] // Construct live window request body. let liveView: liveViewManager.LiveView = { diff --git a/entry/src/main/ets/view/TrafficInfoView.ets b/entry/src/main/ets/view/TrafficInfoView.ets index c688693..0643923 100644 --- a/entry/src/main/ets/view/TrafficInfoView.ets +++ b/entry/src/main/ets/view/TrafficInfoView.ets @@ -78,7 +78,7 @@ export struct TrafficInfoView { .width('40%') .onClick(() => { this.isShowButton = false; - LiveView.getInstance(this.getUIContext().getHostContext()).createLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext() as Context).createLiveView(); this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast'), duration: 2000, @@ -94,7 +94,7 @@ export struct TrafficInfoView { .width('40%') .onClick(() => { this.isShowButton = false; - LiveView.getInstance(this.getUIContext().getHostContext()).finishLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext() as Context).finishLiveView(); this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast'), duration: 2000, -- Gitee From c0e289190f0974d696e5975857bf7580b87eb901 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Wed, 9 Jul 2025 10:34:25 +0800 Subject: [PATCH 06/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/pages/LiveViewLockScreenPage.ets | 2 +- .../src/main/ets/utils/LiveView.ets | 8 ++++---- .../src/main/ets/utils/LiveViewUtil.ets | 14 +++++++++----- .../src/main/ets/view/TrafficInfoView.ets | 4 ++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets b/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets index 07785c6..979c9f0 100644 --- a/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets +++ b/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets @@ -97,7 +97,7 @@ export struct LiveViewLockScreenPage { }); aboutToAppear(): void { - LiveView.getInstance(this.getUIContext().getHostContext()).createLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext() as Context).createLiveView(); this.customDialogController?.open(); } diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets index 5816263..5bda868 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets @@ -26,18 +26,18 @@ const TAG: string = '[LiveView]'; export class LiveView { // Singleton pattern implementation private static instance: LiveView; - private context: Context | undefined; + private context: Context; private liveViewController: LiveViewUtil; private updateInterval: number | undefined; // Private constructor for singleton pattern - private constructor(context: Context | undefined) { + private constructor(context: Context) { this.context = context; - this.liveViewController = new LiveViewUtil(); + this.liveViewController = new LiveViewUtil(context); } // Singleton accessor method - public static getInstance(context: Context | undefined): LiveView { + public static getInstance(context: Context): LiveView { // Lazy initialization of the singleton instance if (!LiveView.instance) { LiveView.instance = new LiveView(context); diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets index bca604d..3caa4fc 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { application, Want, wantAgent } from '@kit.AbilityKit'; +import { Want, wantAgent } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { liveViewManager } from '@kit.LiveViewKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -22,17 +22,21 @@ import { RouteData } from '../model/RouteDataModel'; const TAG: string = '[LiveViewUtil]'; export class LiveViewUtil { - private context = application.getApplicationContext(); + private context: Context; private defaultLiveView?: liveViewManager.LiveView; private sequence: number = 0; + public constructor(context: Context) { + this.context = context; + } + public async startLiveView(params: RouteData) { // Verify that the live view switch is turned on if (!await LiveViewUtil.isLiveViewEnabled()) { hilog.error(0x0000, TAG, '%{public}s', 'Live view is disabled.'); return; } - this.defaultLiveView = await this.createPrimaryLiveVie(); + this.defaultLiveView = await this.createPrimaryLiveView(); this.updateLiveViewInfo(params); return await liveViewManager.startLiveView(this.defaultLiveView); @@ -62,7 +66,7 @@ export class LiveViewUtil { public async closeLiveView() { // Ensure that the sequence is greater than the current live window page. this.sequence++; - this.defaultLiveView = await this.createPrimaryLiveVie(); + this.defaultLiveView = await this.createPrimaryLiveView(); await liveViewManager.stopLiveView(this.defaultLiveView).then(() => { this.sequence = 0; this.defaultLiveView = undefined; @@ -114,7 +118,7 @@ export class LiveViewUtil { this.defaultLiveView = liveView; } - private async createPrimaryLiveVie(): Promise { + private async createPrimaryLiveView(): Promise { // Construct live window request body. let liveView: liveViewManager.LiveView = { id: 0, diff --git a/liveviewlockscreenlibrary/src/main/ets/view/TrafficInfoView.ets b/liveviewlockscreenlibrary/src/main/ets/view/TrafficInfoView.ets index c688693..0643923 100644 --- a/liveviewlockscreenlibrary/src/main/ets/view/TrafficInfoView.ets +++ b/liveviewlockscreenlibrary/src/main/ets/view/TrafficInfoView.ets @@ -78,7 +78,7 @@ export struct TrafficInfoView { .width('40%') .onClick(() => { this.isShowButton = false; - LiveView.getInstance(this.getUIContext().getHostContext()).createLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext() as Context).createLiveView(); this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast'), duration: 2000, @@ -94,7 +94,7 @@ export struct TrafficInfoView { .width('40%') .onClick(() => { this.isShowButton = false; - LiveView.getInstance(this.getUIContext().getHostContext()).finishLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext() as Context).finishLiveView(); this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast'), duration: 2000, -- Gitee From 83da038143ac877ef5ac15c9beec2032c6137d35 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Wed, 9 Jul 2025 10:46:26 +0800 Subject: [PATCH 07/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/utils/LiveViewUtil.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entry/src/main/ets/utils/LiveViewUtil.ets b/entry/src/main/ets/utils/LiveViewUtil.ets index eb060cf..75fd2c8 100644 --- a/entry/src/main/ets/utils/LiveViewUtil.ets +++ b/entry/src/main/ets/utils/LiveViewUtil.ets @@ -159,7 +159,7 @@ export class LiveViewUtil { private static async buildWantAgent(): Promise { const wantAgentInfo: wantAgent.WantAgentInfo = { wants: [{ - bundleName: 'com.example.mapliveviewsample', + bundleName: '', abilityName: 'EntryAbility' } as Want], actionType: wantAgent.OperationType.START_ABILITIES, -- Gitee From fa2ef5c968650d08f65c56004e010aa684b7b4c5 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Sun, 13 Jul 2025 17:56:53 +0800 Subject: [PATCH 08/27] =?UTF-8?q?ohos=E5=BC=80=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liveviewlockscreenlibrary/Index.ets | 2 + .../main/ets/LiveViewLockScreenController.ets | 23 ++++ .../src/main/ets/common/Constants.ets | 21 ++++ .../src/main/ets/liveview/LockScreenPage.ets | 6 +- .../src/main/ets/utils/BreakpointSystem.ets | 19 ++-- .../src/main/ets/utils/BundleNameUtil.ets | 3 +- .../src/main/ets/utils/LiveView.ets | 5 +- .../main/ets/utils/LiveViewExtAbilityUtil.ets | 5 +- .../src/main/ets/utils/LiveViewUtil.ets | 3 +- .../src/main/ets/utils/WindowUtil.ets | 102 ++++++++++-------- .../src/main/ets/view/TrafficView.ets | 14 +-- .../src/main/module.json5 | 2 +- .../main/ets/entryability/EntryAbility.ets | 8 +- .../src/main/module.json5 | 5 +- 14 files changed, 144 insertions(+), 74 deletions(-) create mode 100644 liveviewlockscreenlibrary/src/main/ets/LiveViewLockScreenController.ets create mode 100644 liveviewlockscreenlibrary/src/main/ets/common/Constants.ets diff --git a/liveviewlockscreenlibrary/Index.ets b/liveviewlockscreenlibrary/Index.ets index a91d0a7..8f9f674 100644 --- a/liveviewlockscreenlibrary/Index.ets +++ b/liveviewlockscreenlibrary/Index.ets @@ -1,5 +1,7 @@ export { LiveViewLockScreenPage } from './src/main/ets/pages/LiveViewLockScreenPage'; +export { LiveViewLockScreenController } from './src/main/ets/LiveViewLockScreenController'; + export { LockScreenPage } from './src/main/ets/liveview/LockScreenPage'; export { BreakpointSystem, BreakpointTypeEnum } from './src/main/ets/utils/BreakpointSystem'; diff --git a/liveviewlockscreenlibrary/src/main/ets/LiveViewLockScreenController.ets b/liveviewlockscreenlibrary/src/main/ets/LiveViewLockScreenController.ets new file mode 100644 index 0000000..15a25fe --- /dev/null +++ b/liveviewlockscreenlibrary/src/main/ets/LiveViewLockScreenController.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { window } from "@kit.ArkUI"; +import { WindowUtil } from "./utils/WindowUtil"; + +export class LiveViewLockScreenController { + public static initWindowConfig(windowStage: window.WindowStage): void { + WindowUtil.initialize(windowStage); + } +} \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/main/ets/common/Constants.ets b/liveviewlockscreenlibrary/src/main/ets/common/Constants.ets new file mode 100644 index 0000000..a7800f3 --- /dev/null +++ b/liveviewlockscreenlibrary/src/main/ets/common/Constants.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class Constants { + /* + * AppStorage key prefix. + */ + public static readonly KEY_PREFIX: string = 'liveviewlockscreen'; +} \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets b/liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets index b28ab1c..608ef24 100644 --- a/liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets +++ b/liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets @@ -13,14 +13,16 @@ * limitations under the License. */ +import { Constants } from '../common/Constants'; import { LaneData } from '../model/RouteDataModel'; import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem'; import { RoadView } from '../view/RoadView'; @Entry export struct LockScreenPage { - @StorageLink('liveViewLockScreenCurrentHeightBreakpoint') currentHeightBreakpoint: string = BreakpointTypeEnum.SM; - @StorageProp('liveViewLockScreenLaneData') roadInfo: LaneData | undefined = undefined; + @StorageLink(Constants.KEY_PREFIX + 'CurrentHeightBreakpoint') currentHeightBreakpoint: string = + BreakpointTypeEnum.SM; + @StorageLink(Constants.KEY_PREFIX + 'LaneData') roadInfo: LaneData | undefined = undefined; build() { Stack({ alignContent: Alignment.Top }) { diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/BreakpointSystem.ets b/liveviewlockscreenlibrary/src/main/ets/utils/BreakpointSystem.ets index b4b7552..a978596 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/BreakpointSystem.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/BreakpointSystem.ets @@ -16,6 +16,7 @@ import { window } from '@kit.ArkUI'; import type { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; +import { Constants } from '../common/Constants'; const TAG: string = '[BreakpointSystem]'; @@ -73,8 +74,8 @@ export class BreakpointSystem { private currentHeightBreakpoint: BreakpointTypeEnum = BreakpointTypeEnum.LG; private constructor() { - AppStorage.setOrCreate('liveViewLockScreenCurrentWidthBreakpoint', this.currentWidthBreakpoint); - AppStorage.setOrCreate('liveViewLockScreenCurrentHeightBreakpoint', this.currentHeightBreakpoint); + AppStorage.setOrCreate(Constants.KEY_PREFIX + 'CurrentWidthBreakpoint', this.currentWidthBreakpoint); + AppStorage.setOrCreate(Constants.KEY_PREFIX + 'CurrentHeightBreakpoint', this.currentHeightBreakpoint); } public static getInstance(): BreakpointSystem { @@ -87,28 +88,28 @@ export class BreakpointSystem { public updateCurrentWidthBreakpoint(widthBreakpoint: BreakpointTypeEnum): void { if (this.currentWidthBreakpoint !== widthBreakpoint) { this.currentWidthBreakpoint = widthBreakpoint; - AppStorage.setOrCreate('liveViewLockScreenCurrentWidthBreakpoint', this.currentWidthBreakpoint); + AppStorage.setOrCreate(Constants.KEY_PREFIX + 'CurrentWidthBreakpoint', this.currentWidthBreakpoint); } } public updateCurrentHeightBreakpoint(heightBreakpoint: BreakpointTypeEnum): void { if (this.currentHeightBreakpoint !== heightBreakpoint) { this.currentHeightBreakpoint = heightBreakpoint; - AppStorage.setOrCreate('liveViewLockScreenCurrentHeightBreakpoint', this.currentHeightBreakpoint); + AppStorage.setOrCreate(Constants.KEY_PREFIX + 'CurrentHeightBreakpoint', this.currentHeightBreakpoint); } } - public onWindowSizeChange(window: window.Window, uiContent: UIContext): void { - this.updateWidthHeightBp(window, uiContent); + public onWindowSizeChange(window: window.Window): void { + this.updateWidthHeightBp(window); } - public updateWidthHeightBp(window: window.Window, uiContent: UIContext): void { + public updateWidthHeightBp(window: window.Window): void { try { const mainWindow: window.WindowProperties = window.getWindowProperties(); const windowWidth: number = mainWindow.windowRect.width; const windowHeight: number = mainWindow.windowRect.height; - const windowWidthVp = uiContent.px2vp(windowWidth); - const windowHeightVp = uiContent.px2vp(windowHeight); + const windowWidthVp = window.getUIContext().px2vp(windowWidth); + const windowHeightVp = window.getUIContext().px2vp(windowHeight); const windowRatio: number = windowHeightVp / windowWidthVp; let widthBp: BreakpointTypeEnum = BreakpointTypeEnum.SM; let heightBp: BreakpointTypeEnum = BreakpointTypeEnum.LG; diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets index fb2b875..389e672 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets @@ -16,6 +16,7 @@ import { bundleManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; +import { Constants } from '../common/Constants'; const TAG: string = '[BundleNameUtil]'; @@ -24,7 +25,7 @@ export class BundleNameUtil { try { bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT).then((data) => { hilog.info(0x0000, TAG, '%{public}s', 'getBundleInfoForSelf successfully.'); - AppStorage.setOrCreate('liveViewLockScreenBundleName', data.name); + AppStorage.setOrCreate(Constants.KEY_PREFIX + 'BundleName', data.name); }).catch((error: BusinessError) => { hilog.error(0x0000, TAG, '%{public}s', `getBundleInfoForSelf failed. code is ${error.code} message is ${error.message}`); diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets index 5bda868..2b35019 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets @@ -17,6 +17,7 @@ import { appManager, WantAgent, wantAgent } from '@kit.AbilityKit'; import { backgroundTaskManager } from '@kit.BackgroundTasksKit'; import { BusinessError, commonEventManager } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; +import { Constants } from '../common/Constants'; import { RouteData } from '../model/RouteDataModel'; import { LiveViewUtil } from './LiveViewUtil'; import { getRouteData } from '../viewmodel/RouteDataViewModel'; @@ -62,7 +63,7 @@ export class LiveView { // Prepare common event data let options: commonEventManager.CommonEventPublishData = { data: 'data', - bundleName: AppStorage.get('liveViewLockScreenBundleName'), + bundleName: AppStorage.get(Constants.KEY_PREFIX + 'BundleName'), parameters: { 'roadData': routeInfo.roadInfo } @@ -117,7 +118,7 @@ export class LiveView { let wantAgentInfo: wantAgent.WantAgentInfo = { wants: [ { - bundleName: AppStorage.get('liveViewLockScreenBundleName'), + bundleName: AppStorage.get(Constants.KEY_PREFIX + 'BundleName'), abilityName: 'LiveviewlockscreensampleAbility' } ], diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets index d0f441f..8d6c9f4 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets @@ -19,6 +19,7 @@ import { display, window } from '@kit.ArkUI'; import { BreakpointTypeEnum } from './BreakpointSystem'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { BusinessError, commonEventManager } from '@kit.BasicServicesKit'; +import { Constants } from '../common/Constants'; import { LaneData } from '../model/RouteDataModel'; const TAG: string = '[LiveViewExtAbilityUtil]'; @@ -88,7 +89,7 @@ export class LiveViewExtAbilityUtil { hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in subscribe commonEvent success.'); if (data.parameters) { let laneData = data.parameters['roadData'] as LaneData; - AppStorage.setOrCreate('liveViewLockScreenLaneData', laneData); + AppStorage.setOrCreate(Constants.KEY_PREFIX + 'LaneData', laneData); hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in receive commonEvent.'); } }); @@ -111,7 +112,7 @@ export class LiveViewExtAbilityUtil { } else { currentHeightBreakpoint = BreakpointTypeEnum.MD; } - AppStorage.setOrCreate('liveViewLockScreenCurrentHeightBreakpoint', currentHeightBreakpoint); + AppStorage.setOrCreate(Constants.KEY_PREFIX + 'CurrentHeightBreakpoint', currentHeightBreakpoint); hilog.info(0x0000, TAG, '%{public}s', 'updateBreakpoint'); } catch (error) { hilog.error(0x0000, TAG, '%{public}s', diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets index 3caa4fc..d4af808 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets @@ -17,6 +17,7 @@ import { Want, wantAgent } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { liveViewManager } from '@kit.LiveViewKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; +import { Constants } from '../common/Constants'; import { RouteData } from '../model/RouteDataModel'; const TAG: string = '[LiveViewUtil]'; @@ -152,7 +153,7 @@ export class LiveViewUtil { private static async buildWantAgent(): Promise { const wantAgentInfo: wantAgent.WantAgentInfo = { wants: [{ - bundleName: AppStorage.get('liveViewLockScreenBundleName'), + bundleName: AppStorage.get(Constants.KEY_PREFIX + 'BundleName'), abilityName: 'LiveviewlockscreensampleAbility' } as Want], actionType: wantAgent.OperationType.START_ABILITIES, diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets index 5b756a6..ea299f5 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets @@ -16,56 +16,72 @@ import { window } from '@kit.ArkUI'; import type { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; +import { Constants } from '../common/Constants'; import { BreakpointSystem } from './BreakpointSystem'; const TAG: string = '[WindowUtil]'; export class WindowUtil { - public static requestFullScreen(windowStage: window.WindowStage): void { - windowStage.getMainWindow((error: BusinessError, data: window.Window) => { - if (error.code) { - hilog.error(0x0000, TAG, '%{public}s', - `Failed to getMainWindow. Cause code: ${error.code}, message: ${error.message}`); - return; - } - const windowObj: window.Window = data; - try { - windowObj.setWindowSystemBarProperties({ - statusBarContentColor: '#ffffff', - }).then(() => { - hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in setting the system bar properties.'); - }).catch((error: BusinessError) => { - hilog.error(0x0000, TAG, '%{public}s', - `Failed to set the window layout to full-screen mode. Cause code: ${error.code}, message: ${error.message}`); - }); + private static windowClass?: window.Window; - windowObj.setWindowLayoutFullScreen(true).then(() => { - hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in setting the window layout to full-screen mode'); - }).catch((error: BusinessError) => { - hilog.error(0x0000, TAG, '%{public}s', - `Failed to set the window layout to full-screen mode. Cause code: ${error.code}, message: ${error.message}`); - }); - } catch (error) { - hilog.error(0x0000, TAG, '%{public}s', - `onWindowStageCreate failed. Cause code: ${error.code}, message: ${error.message}`); - } - }); + public static initialize(windowStage: window.WindowStage) { + try { + WindowUtil.windowClass = windowStage.getMainWindowSync(); + const uiContext: UIContext = WindowUtil.windowClass.getUIContext(); + AppStorage.setOrCreate(Constants.KEY_PREFIX + 'UIContext', uiContext); + WindowUtil.registerBreakPoint(WindowUtil.windowClass); + WindowUtil.requestFullScreen(WindowUtil.windowClass); + } catch (err) { + hilog.error(0x0000, TAG, `WindowUtil initialize failed. Cause: ${err.code} ${err.message}`); + } + } + + private static registerBreakPoint(windowClass: window.Window) { + try { + BreakpointSystem.getInstance().onWindowSizeChange(windowClass); + windowClass.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(windowClass)); + + const navIndicatorAvoidArea: window.AvoidArea = + windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); + WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR, navIndicatorAvoidArea); + windowClass.on('avoidAreaChange', (avoidAreaOption) => { + WindowUtil.setAvoidArea(avoidAreaOption.type, avoidAreaOption.area); + }); + } catch (e) { + const error = e as BusinessError; + hilog.error(0x0000, TAG, + `Get windowAvoidArea or Register windowSizeChange failed. code: ${error.code}, message: ${error.message}`); + } } - public static registerBreakPoint(windowStage: window.WindowStage) { - windowStage.getMainWindow((error: BusinessError, data: window.Window) => { - if (error.code) { - hilog.error(0x0000, TAG, `Failed to get main window. Cause code: ${error.code}, message: ${error.message}`); - return; - } - let uiContext: UIContext = data.getUIContext(); - BreakpointSystem.getInstance().updateWidthHeightBp(data, uiContext); - data.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(data, uiContext)); - const windowObj: window.Window = data; - const type: window.AvoidAreaType = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; - const avoidArea: window.AvoidArea = windowObj.getWindowAvoidArea(type); - const bottomRectHeight: number = avoidArea.bottomRect.height; - AppStorage.setOrCreate('liveViewLockScreenBottomRectHeight', bottomRectHeight); - }) + // Get status indicator height. + private static setAvoidArea(type: window.AvoidAreaType, area: window.AvoidArea) { + if (type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { + AppStorage.setOrCreate(Constants.KEY_PREFIX + 'NaviIndicatorHeight', + WindowUtil.windowClass?.getUIContext().px2vp(area.bottomRect.height)); + } + } + + private static requestFullScreen(windowClass: window.Window): void { + try { + windowClass.setWindowSystemBarProperties({ + statusBarContentColor: '#ffffff', + }).then(() => { + hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in setting the system bar properties.'); + }).catch((error: BusinessError) => { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to set the window layout to full-screen mode. Cause code: ${error.code}, message: ${error.message}`); + }); + + windowClass.setWindowLayoutFullScreen(true).then(() => { + hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in setting the window layout to full-screen mode'); + }).catch((error: BusinessError) => { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to set the window layout to full-screen mode. Cause code: ${error.code}, message: ${error.message}`); + }); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `onWindowStageCreate failed. Cause code: ${error.code}, message: ${error.message}`); + } } } \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/main/ets/view/TrafficView.ets b/liveviewlockscreenlibrary/src/main/ets/view/TrafficView.ets index 07b2be9..e7d0cd1 100644 --- a/liveviewlockscreenlibrary/src/main/ets/view/TrafficView.ets +++ b/liveviewlockscreenlibrary/src/main/ets/view/TrafficView.ets @@ -13,14 +13,16 @@ * limitations under the License. */ +import { Constants } from '../common/Constants'; import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem'; import { TrafficInfoView } from './TrafficInfoView'; @Component export struct TrafficView { - @StorageProp('liveViewLockScreenBottomRectHeight') bottomRectHeight: number = 0; - @StorageLink('liveViewLockScreenCurrentWidthBreakpoint') currentWidthBreakpoint: string = BreakpointTypeEnum.SM; - @StorageLink('liveViewLockScreenCurrentHeightBreakpoint') currentHeightBreakpoint: string = BreakpointTypeEnum.LG; + @StorageLink(Constants.KEY_PREFIX + 'NaviIndicatorHeight') naviIndicatorHeight: number = 0; + @StorageLink(Constants.KEY_PREFIX + 'CurrentWidthBreakpoint') currentWidthBreakpoint: string = BreakpointTypeEnum.SM; + @StorageLink(Constants.KEY_PREFIX + 'CurrentHeightBreakpoint') currentHeightBreakpoint: string = + BreakpointTypeEnum.LG; @Prop lane: number = 2; private uiContext: UIContext = this.getUIContext(); private updateInterval: number | undefined; @@ -226,7 +228,7 @@ export struct TrafficView { }) .padding({ bottom: new BreakpointType({ - sm: this.uiContext.px2vp(this.bottomRectHeight), + sm: this.uiContext.px2vp(this.naviIndicatorHeight), md: 0, lg: 0, }).getValue(this.currentWidthBreakpoint), @@ -234,8 +236,8 @@ export struct TrafficView { .margin({ bottom: new BreakpointType({ sm: 0, - md: this.uiContext.px2vp(this.bottomRectHeight), - lg: this.uiContext.px2vp(this.bottomRectHeight), + md: this.uiContext.px2vp(this.naviIndicatorHeight), + lg: this.uiContext.px2vp(this.naviIndicatorHeight), }).getValue(this.currentWidthBreakpoint), }) } diff --git a/liveviewlockscreenlibrary/src/main/module.json5 b/liveviewlockscreenlibrary/src/main/module.json5 index 177ddf3..15413a6 100644 --- a/liveviewlockscreenlibrary/src/main/module.json5 +++ b/liveviewlockscreenlibrary/src/main/module.json5 @@ -8,4 +8,4 @@ "2in1" ] } -} +} \ No newline at end of file diff --git a/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets b/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets index 438ac2c..ff42a32 100644 --- a/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets +++ b/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets @@ -13,16 +13,15 @@ * limitations under the License. */ -import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; +import { UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { BundleNameUtil, WindowUtil } from 'liveviewlockscreenlibrary' +import { BundleNameUtil, LiveViewLockScreenController } from 'liveviewlockscreenlibrary' const TAG: string = '[EntryAbility]'; export default class EntryAbility extends UIAbility { onCreate(): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); BundleNameUtil.getBundleName(); hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); } @@ -40,8 +39,7 @@ export default class EntryAbility extends UIAbility { `Failed to load the content. Cause code: ${error.code}, message: ${error.message}`); return; } - WindowUtil.requestFullScreen(windowStage); - WindowUtil.registerBreakPoint(windowStage); + LiveViewLockScreenController.initWindowConfig(windowStage); hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in loading the content.'); }); } diff --git a/liveviewlockscreensample/src/main/module.json5 b/liveviewlockscreensample/src/main/module.json5 index fca9f25..585ce7e 100644 --- a/liveviewlockscreensample/src/main/module.json5 +++ b/liveviewlockscreensample/src/main/module.json5 @@ -9,8 +9,9 @@ "tablet", "2in1" ], - "deliveryWithInstall": true, + "deliveryWithInstall": false, "installationFree": false, + "pages": "$profile:main_pages", "abilities": [ { @@ -21,7 +22,7 @@ "label": "$string:EntryAbility_label", "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", - "exported": false, + "exported": true, "backgroundModes": [ 'location' ], -- Gitee From 31b8a7bbf7f1f12ad1ab8e99f87137bfdda4ecb2 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Mon, 14 Jul 2025 10:31:00 +0800 Subject: [PATCH 09/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/LiveViewLockScreenController.ets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liveviewlockscreenlibrary/src/main/ets/LiveViewLockScreenController.ets b/liveviewlockscreenlibrary/src/main/ets/LiveViewLockScreenController.ets index 15a25fe..e7e1aa5 100644 --- a/liveviewlockscreenlibrary/src/main/ets/LiveViewLockScreenController.ets +++ b/liveviewlockscreenlibrary/src/main/ets/LiveViewLockScreenController.ets @@ -13,8 +13,8 @@ * limitations under the License. */ -import { window } from "@kit.ArkUI"; -import { WindowUtil } from "./utils/WindowUtil"; +import { window } from '@kit.ArkUI'; +import { WindowUtil } from './utils/WindowUtil'; export class LiveViewLockScreenController { public static initWindowConfig(windowStage: window.WindowStage): void { -- Gitee From 68a2d80ad1a27f1e8bd8accc43bf4ec31680fb19 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Mon, 14 Jul 2025 18:57:28 +0800 Subject: [PATCH 10/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liveviewlockscreenlibrary/Index.ets | 14 ++--- liveviewlockscreenlibrary/README.md | 25 +++++---- .../main/ets/LiveViewLockScreenController.ets | 15 ++++++ .../IndexComponent.ets} | 2 +- .../LockScreenComponent.ets} | 4 +- .../src/main/ets/utils/BundleNameUtil.ets | 2 +- .../main/ets/utils/LiveViewExtAbilityUtil.ets | 53 +++++++++++-------- .../main/resources/base/element/string.json | 50 ++++++----------- .../main/resources/en_US/element/string.json | 16 ------ .../main/resources/zh_CN/element/string.json | 16 ------ .../main/ets/entryability/EntryAbility.ets | 4 +- .../main/ets/liveview/LiveViewExtAbility.ets | 11 ++-- .../src/main/ets/pages/Index.ets | 6 +-- .../src/main/ets/pages/LockScreen.ets | 6 +-- .../main/resources/base/element/string.json | 20 +++++++ .../resources/base/profile/main_pages.json | 2 +- 16 files changed, 118 insertions(+), 128 deletions(-) rename liveviewlockscreenlibrary/src/main/ets/{pages/LiveViewLockScreenPage.ets => component/IndexComponent.ets} (98%) rename liveviewlockscreenlibrary/src/main/ets/{liveview/LockScreenPage.ets => component/LockScreenComponent.ets} (96%) create mode 100644 liveviewlockscreensample/src/main/resources/base/element/string.json diff --git a/liveviewlockscreenlibrary/Index.ets b/liveviewlockscreenlibrary/Index.ets index 8f9f674..3b29927 100644 --- a/liveviewlockscreenlibrary/Index.ets +++ b/liveviewlockscreenlibrary/Index.ets @@ -1,13 +1,5 @@ -export { LiveViewLockScreenPage } from './src/main/ets/pages/LiveViewLockScreenPage'; +export { IndexComponent } from './src/main/ets/component/IndexComponent'; -export { LiveViewLockScreenController } from './src/main/ets/LiveViewLockScreenController'; +export { LockScreenComponent } from './src/main/ets/component/LockScreenComponent'; -export { LockScreenPage } from './src/main/ets/liveview/LockScreenPage'; - -export { BreakpointSystem, BreakpointTypeEnum } from './src/main/ets/utils/BreakpointSystem'; - -export { BundleNameUtil } from './src/main/ets/utils/BundleNameUtil'; - -export { LiveViewExtAbilityUtil } from './src/main/ets/utils/LiveViewExtAbilityUtil'; - -export { WindowUtil } from './src/main/ets/utils/WindowUtil'; \ No newline at end of file +export { LiveViewLockScreenController } from './src/main/ets/LiveViewLockScreenController'; \ No newline at end of file diff --git a/liveviewlockscreenlibrary/README.md b/liveviewlockscreenlibrary/README.md index f52c07b..8adb757 100644 --- a/liveviewlockscreenlibrary/README.md +++ b/liveviewlockscreenlibrary/README.md @@ -17,7 +17,7 @@ ohpm install @ohos_samples/liveviewlockscreenlibrary ``` { "dependencies": { - "@ohos_samples/liveviewlockscreenlibrary": "^1.0.0" + "@ohos_samples/liveviewlockscreenlibrary": "^1.0.1" } } ``` @@ -28,17 +28,24 @@ ohpm install @ohos_samples/liveviewlockscreenlibrary import { LiveViewLockScreenPage, BundleNameUtil, WindowUtil } from '@ohos_samples/liveviewlockscreenlibrary'; ``` -按需在文件中使用导出模块即可,其中LiveViewLockScreenPage是整个sample的入口页面,进入Sample后如果有实况窗和锁屏沉浸实况窗权限,会自动创建实况窗和锁屏沉浸实况窗;点击停止导航,会关闭实况窗和锁屏沉浸实况窗,点击继续导航,会重新创建实况窗和锁屏沉浸实况窗。BundleNameUtil封装了获取包名的功能;WindowUtil封装了沉浸式、设备断点判断、避让区域计算等窗口能力。示例如下: +按需在文件中使用导出模块即可,其中IndexComponent是整个sample的入口页面,进入Sample后如果有实况窗和锁屏沉浸实况窗权限,会自动创建实况窗和锁屏沉浸实况窗LockScreenComponent;点击停止导航,会关闭实况窗和锁屏沉浸实况窗,点击继续导航,会重新创建实况窗和锁屏沉浸实况窗。LiveViewLockScreenController封装了获取包名的功能,已经沉浸式、设备断点判断、避让区域计算等窗口能力。示例如下: ``` -// Page.ets -import { LiveViewLockScreenPage } from '@ohos_samples/liveviewlockscreenlibrary'; +// Index.ets +import { IndexComponent } from '@ohos_samples/liveviewlockscreenlibrary'; Stack() { - LiveViewLockScreenPage() + IndexComponent() +} + +// LockScreen.ets +import { LockScreenComponent } from '@ohos_samples/liveviewlockscreenlibrary'; +Stack() { + LockScreenComponent() } // EntryAbility.ets -import { BundleNameUtil, WindowUtil } from '@ohos_samples/liveviewlockscreenlibrary'; -BundleNameUtil.getBundleName(); -WindowUtil.requestFullScreen(windowStage); -WindowUtil.registerBreakPoint(windowStage); +import { LiveViewLockScreenController } from '@ohos_samples/liveviewlockscreenlibrary'; +LiveViewLockScreenController.saveBundleName() +LiveViewLockScreenController.initWindowConfig(windowStage); +LiveViewLockScreenController.initLiveView(session); +LiveViewLockScreenController.destroyLLiveView(); ``` \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/main/ets/LiveViewLockScreenController.ets b/liveviewlockscreenlibrary/src/main/ets/LiveViewLockScreenController.ets index e7e1aa5..fe6ef8a 100644 --- a/liveviewlockscreenlibrary/src/main/ets/LiveViewLockScreenController.ets +++ b/liveviewlockscreenlibrary/src/main/ets/LiveViewLockScreenController.ets @@ -13,11 +13,26 @@ * limitations under the License. */ +import { UIExtensionContentSession } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; +import { BundleNameUtil } from './utils/BundleNameUtil'; +import { LiveViewExtAbilityUtil } from './utils/LiveViewExtAbilityUtil'; import { WindowUtil } from './utils/WindowUtil'; export class LiveViewLockScreenController { public static initWindowConfig(windowStage: window.WindowStage): void { WindowUtil.initialize(windowStage); } + + public static saveBundleName(): void { + BundleNameUtil.saveBundleName(); + } + + public static initLiveView(session: UIExtensionContentSession): void { + LiveViewExtAbilityUtil.getInstance().setSession(session); + } + + public static destroyLLiveView(): void { + LiveViewExtAbilityUtil.getInstance().destroySubscribe(); + } } \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets b/liveviewlockscreenlibrary/src/main/ets/component/IndexComponent.ets similarity index 98% rename from liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets rename to liveviewlockscreenlibrary/src/main/ets/component/IndexComponent.ets index 979c9f0..8b216d0 100644 --- a/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets +++ b/liveviewlockscreenlibrary/src/main/ets/component/IndexComponent.ets @@ -77,7 +77,7 @@ struct TipDialog { } @Component -export struct LiveViewLockScreenPage { +export struct IndexComponent { private customDialogController: CustomDialogController = new CustomDialogController({ builder: TipDialog({ onConfirm: () => { diff --git a/liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets b/liveviewlockscreenlibrary/src/main/ets/component/LockScreenComponent.ets similarity index 96% rename from liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets rename to liveviewlockscreenlibrary/src/main/ets/component/LockScreenComponent.ets index 608ef24..2655cbc 100644 --- a/liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets +++ b/liveviewlockscreenlibrary/src/main/ets/component/LockScreenComponent.ets @@ -18,8 +18,8 @@ import { LaneData } from '../model/RouteDataModel'; import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem'; import { RoadView } from '../view/RoadView'; -@Entry -export struct LockScreenPage { +@Component +export struct LockScreenComponent { @StorageLink(Constants.KEY_PREFIX + 'CurrentHeightBreakpoint') currentHeightBreakpoint: string = BreakpointTypeEnum.SM; @StorageLink(Constants.KEY_PREFIX + 'LaneData') roadInfo: LaneData | undefined = undefined; diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets index 389e672..ca7a838 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets @@ -21,7 +21,7 @@ import { Constants } from '../common/Constants'; const TAG: string = '[BundleNameUtil]'; export class BundleNameUtil { - public static getBundleName(): void { + public static saveBundleName(): void { try { bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT).then((data) => { hilog.info(0x0000, TAG, '%{public}s', 'getBundleInfoForSelf successfully.'); diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets index 8d6c9f4..5b1612a 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets @@ -16,11 +16,11 @@ import { bundleManager, UIExtensionContentSession } from '@kit.AbilityKit'; import { display, window } from '@kit.ArkUI'; -import { BreakpointTypeEnum } from './BreakpointSystem'; -import { hilog } from '@kit.PerformanceAnalysisKit'; import { BusinessError, commonEventManager } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; import { Constants } from '../common/Constants'; import { LaneData } from '../model/RouteDataModel'; +import { BreakpointTypeEnum } from './BreakpointSystem'; const TAG: string = '[LiveViewExtAbilityUtil]'; @@ -45,29 +45,25 @@ export class LiveViewExtAbilityUtil { public setSession(session: UIExtensionContentSession): void { // Window size listener. - const extensionWindow = session.getUIExtensionWindowProxy(); - extensionWindow.on('windowSizeChange', (windowSize: window.Size) => { + session.getUIExtensionWindowProxy().on('windowSizeChange', (windowSize: window.Size) => { LiveViewExtAbilityUtil.updateBreakPoint(windowSize); }); + LiveViewExtAbilityUtil.getInstance().createSubscriber() + } + + public destroySubscribe(): void { + commonEventManager.unsubscribe(this.subscriber, () => { + this.subscriber = null; + }); + } + private createSubscriber(): void { // Initialize event subscription. - let bundleName: string = ''; - try { - bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT).then((data) => { - hilog.info(0x0000, TAG, '%{public}s', 'getBundleInfoForSelf successfully.'); - bundleName = data.name; - }).catch((error: BusinessError) => { - hilog.error(0x0000, TAG, '%{public}s', - `getBundleInfoForSelf failed. code is ${error.code} message is ${error.message}`); - }); - } catch (error) { - hilog.error(0x0000, TAG, '%{public}s', - `getBundleInfoForSelf failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); - } + let bundleName: string = LiveViewExtAbilityUtil.getBundleName(); let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { events: ['live_view_lock_screen'], publisherBundleName: bundleName, - priority: 0 + priority: 0, }; commonEventManager.createSubscriber(subscribeInfo, (error: BusinessError, data: commonEventManager.CommonEventSubscriber) => { @@ -94,7 +90,6 @@ export class LiveViewExtAbilityUtil { } }); }) - session.loadContent('pages/LockScreen'); } // Distinguish page layout using vertical breakpoints. @@ -121,9 +116,21 @@ export class LiveViewExtAbilityUtil { } } - public destroySubscribe(): void { - commonEventManager.unsubscribe(this.subscriber, () => { - this.subscriber = null; - }); + private static getBundleName(): string { + let bundleName: string = ''; + try { + bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT).then((data) => { + bundleName = data.name; + hilog.info(0x0000, TAG, '%{public}s', 'getBundleInfoForSelf successfully.'); + }).catch((error: BusinessError) => { + hilog.error(0x0000, TAG, '%{public}s', + `getBundleInfoForSelf failed. code is ${error.code} message is ${error.message}`); + }); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `getBundleInfoForSelf failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); + } + hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); + return bundleName; } } \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/main/resources/base/element/string.json b/liveviewlockscreenlibrary/src/main/resources/base/element/string.json index aa9d46c..72d047e 100644 --- a/liveviewlockscreenlibrary/src/main/resources/base/element/string.json +++ b/liveviewlockscreenlibrary/src/main/resources/base/element/string.json @@ -1,40 +1,24 @@ { "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "锁屏沉浸实况窗" - }, - { - "name": "reason_background", - "value": "后台更新实况窗数据" - }, { "name": "traffic_info_meter", - "value": "800米" + "value": "800 meters" }, { "name": "traffic_info_smmd_first", - "value": "800米" + "value": "Turn right" }, { "name": "traffic_info_smmd_second", - "value": "后右转" + "value": "after 800m" }, { "name": "traffic_info_first", - "value": "1 小时 24 分钟" + "value": "1 hour 24 minutes" }, { "name": "traffic_info_second", - "value": "72.6公里·09:32·" + "value": "72.6km·09:32·" }, { "name": "traffic_info_third", @@ -42,7 +26,7 @@ }, { "name": "live_view_title", - "value": "导航中" + "value": "In navigation" }, { "name": "live_view_background", @@ -54,47 +38,47 @@ }, { "name": "meter", - "value": "米" + "value": " meters" }, { "name": "live_view_primary_title_first", - "value": "" + "value": "Turn right after " }, { "name": "live_view_primary_title_second", - "value": "米后右转" + "value": " m" }, { "name": "road_name", - "value": "翠湖东路" + "value": "Cuihu East Road" }, { "name": "then", - "value": "然后" + "value": "Then" }, { "name": "Continue", - "value": "继续导航" + "value": "Continue" }, { "name": "Finish", - "value": "停止导航" + "value": "Finish" }, { "name": "tip", - "value": "提示" + "value": "Tip" }, { "name": "tip_text", - "value": " 本案例已完成Pura X内外屏适配和实况窗功能开发,因涉及权限申请,仅做UI展示,具体开发请参考示例代码。" + "value": "Permission is required to experience the lock screen immersive live window" }, { "name": "tip_get", - "value": "知道了" + "value": "I get" }, { "name": "toast", - "value": "仅做功能原型展示,具体业务需自行实现。" + "value": "Just a functional prototype—you’ll need to implement the business logic yourself." } ] } \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json b/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json index 4d1556f..72d047e 100644 --- a/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json +++ b/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json @@ -1,21 +1,5 @@ { "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "LiveViewLockScreen" - }, - { - "name": "reason_background", - "value": "Background operation to update the live view" - }, { "name": "traffic_info_meter", "value": "800 meters" diff --git a/liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json b/liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json index aa9d46c..5e29f68 100644 --- a/liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json +++ b/liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json @@ -1,21 +1,5 @@ { "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "锁屏沉浸实况窗" - }, - { - "name": "reason_background", - "value": "后台更新实况窗数据" - }, { "name": "traffic_info_meter", "value": "800米" diff --git a/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets b/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets index ff42a32..9dbdcfc 100644 --- a/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets +++ b/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets @@ -16,13 +16,13 @@ import { UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { BundleNameUtil, LiveViewLockScreenController } from 'liveviewlockscreenlibrary' +import { LiveViewLockScreenController } from 'liveviewlockscreenlibrary' const TAG: string = '[EntryAbility]'; export default class EntryAbility extends UIAbility { onCreate(): void { - BundleNameUtil.getBundleName(); + LiveViewLockScreenController.saveBundleName() hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); } diff --git a/liveviewlockscreensample/src/main/ets/liveview/LiveViewExtAbility.ets b/liveviewlockscreensample/src/main/ets/liveview/LiveViewExtAbility.ets index 34340af..b31d759 100644 --- a/liveviewlockscreensample/src/main/ets/liveview/LiveViewExtAbility.ets +++ b/liveviewlockscreensample/src/main/ets/liveview/LiveViewExtAbility.ets @@ -14,18 +14,14 @@ */ import { AbilityConstant, UIExtensionContentSession, Want } from '@kit.AbilityKit'; -import { commonEventManager } from '@kit.BasicServicesKit'; import { LiveViewLockScreenExtensionAbility } from '@kit.LiveViewKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { LiveViewExtAbilityUtil } from 'liveviewlockscreenlibrary'; +import { LiveViewLockScreenController } from 'liveviewlockscreenlibrary'; const TAG: string = '[LiveViewExtAbility]'; // Main class for lock screen live view extension, handles live view presentation on lock screen. export default class LiveViewExtAbility extends LiveViewLockScreenExtensionAbility { - // Common event subscriber for handling system events. - private subscriber: commonEventManager.CommonEventSubscriber | null = null; - onCreate(_launchParam: AbilityConstant.LaunchParam): void { hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onCreate begin.'); } @@ -45,12 +41,13 @@ export default class LiveViewExtAbility extends LiveViewLockScreenExtensionAbili // Core logic when creating UI session. onSessionCreate(_want: Want, session: UIExtensionContentSession): void { hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onSessionCreate begin.'); - LiveViewExtAbilityUtil.getInstance().setSession(session); + LiveViewLockScreenController.initLiveView(session); + session.loadContent('pages/LockScreen'); } // Cleanup operations when destroying UI session onSessionDestroy(): void { - LiveViewExtAbilityUtil.getInstance().destroySubscribe(); + LiveViewLockScreenController.destroyLLiveView(); hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onSessionDestroy begin.'); } diff --git a/liveviewlockscreensample/src/main/ets/pages/Index.ets b/liveviewlockscreensample/src/main/ets/pages/Index.ets index 99c28de..8292b27 100644 --- a/liveviewlockscreensample/src/main/ets/pages/Index.ets +++ b/liveviewlockscreensample/src/main/ets/pages/Index.ets @@ -13,14 +13,14 @@ * limitations under the License. */ -import { LiveViewLockScreenPage } from 'liveviewlockscreenlibrary' +import { IndexComponent } from 'liveviewlockscreenlibrary' @Entry @Component struct Index { build() { Stack() { - LiveViewLockScreenPage() + IndexComponent() } } -} +} \ No newline at end of file diff --git a/liveviewlockscreensample/src/main/ets/pages/LockScreen.ets b/liveviewlockscreensample/src/main/ets/pages/LockScreen.ets index 9a31811..0331471 100644 --- a/liveviewlockscreensample/src/main/ets/pages/LockScreen.ets +++ b/liveviewlockscreensample/src/main/ets/pages/LockScreen.ets @@ -13,13 +13,13 @@ * limitations under the License. */ -import { LockScreenPage } from 'liveviewlockscreenlibrary' +import { LockScreenComponent } from 'liveviewlockscreenlibrary' @Entry struct LockScreen { build() { Stack() { - LockScreenPage() + LockScreenComponent() } } -} +} \ No newline at end of file diff --git a/liveviewlockscreensample/src/main/resources/base/element/string.json b/liveviewlockscreensample/src/main/resources/base/element/string.json new file mode 100644 index 0000000..a105fe4 --- /dev/null +++ b/liveviewlockscreensample/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "LiveViewLockScreen" + }, + { + "name": "reason_background", + "value": "Background operation to update the live view" + } + ] +} \ No newline at end of file diff --git a/liveviewlockscreensample/src/main/resources/base/profile/main_pages.json b/liveviewlockscreensample/src/main/resources/base/profile/main_pages.json index 969d4a3..576646d 100644 --- a/liveviewlockscreensample/src/main/resources/base/profile/main_pages.json +++ b/liveviewlockscreensample/src/main/resources/base/profile/main_pages.json @@ -3,4 +3,4 @@ "pages/Index", "pages/LockScreen" ] -} +} \ No newline at end of file -- Gitee From 7c4ed8462c61b331e8404a94ffc736fa33181ef0 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Mon, 14 Jul 2025 19:03:46 +0800 Subject: [PATCH 11/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 1 + 1 file changed, 1 insertion(+) diff --git a/build-profile.json5 b/build-profile.json5 index 246f563..e000b4c 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -5,6 +5,7 @@ { "name": "default", "signingConfig": "default", + "targetSdkVersion": "5.0.0(12)", "compatibleSdkVersion": "5.0.0(12)", "runtimeOS": "HarmonyOS", } -- Gitee From 709699f6545eefccd891b2d1bfbd14bce400836e Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Mon, 14 Jul 2025 19:17:38 +0800 Subject: [PATCH 12/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/README.md b/README.md index dd00d1c..aae69db 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,62 @@ 4. 本Sample仅提供在本地创建、更新与结束实况窗的能力(不能后台更新,若要后台更新,请使用Push Kit)。若要使用Push Kit更新,可参考[推送实况窗消息服务](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/push-update-liveview),用已有服务器调用对应的REST API。 +### 工程目录 + +``` +LiveViewLockScreen +├── liveviewlockscreenlibrary +│ ├── src/main +│ │ ├── ets +│ │ │ ├── common +│ │ │ │ └── Constants.ets // 公共常量 +│ │ │ ├── component +│ │ │ │ ├── IndexComponent.ets // 首页列表组件 +│ │ │ │ └── LockScreenComponent.ets // 锁屏实况窗组件 +│ │ │ ├── model +│ │ │ │ └── RouteDataModel.ets // 路线数据模型 +│ │ │ ├── utils +│ │ │ │ ├── BreakpointSystem.ets // 断点系统工具 +│ │ │ │ ├── BundleNameUtil.ets // 包名工具 +│ │ │ │ ├── LiveView.ets // 实况窗逻辑 +│ │ │ │ ├── LiveViewExtAbilityUtil.ets // 实况窗扩展 Ability 工具 +│ │ │ │ ├── LiveViewUtil.ets // 实况窗工具 +│ │ │ │ └── WindowUtil.ets // 窗口工具 +│ │ │ ├── view +│ │ │ │ ├── RoadView.ets // 道路显示 View +│ │ │ │ ├── TrafficInfoView.ets // 交通信息 View +│ │ │ │ └── TrafficView.ets // 实时路况 View +│ │ │ ├── viewmodel +│ │ │ │ └── RouteDataViewModel.ets // 路线数据 ViewModel +│ │ │ └── LiveViewLockScreenController.ets // 全局控制器 +│ │ ├── resources +│ │ └── module.json5 +│ ├── CHANGELOG.md +│ ├── Index.ets +│ ├── LICENSE +│ ├── README.md +│ ├── build-profile.json5 +│ ├── consumer-rules.txt +│ ├── hvigorfile.ts +│ ├── obfuscation-rules.txt +│ └── oh-package.json5 +└── liveviewlockscreensample +├── src/main +│ ├── ets +│ │ ├── entryability +│ │ │ └── EntryAbility.ets // 应用入口 Ability +│ │ ├── liveview +│ │ │ └── LiveViewExtAbility.ets // 实况窗扩展 Ability +│ │ └── pages +│ │ ├── Index.ets // 首页(调用库组件演示) +│ │ └── LockScreen.ets // 锁屏实况窗页 +│ └── resources +├── build-profile.json5 +├── hvigorfile.ts +├── obfuscation-rules.txt +└── oh-package.json5 +``` + ## 具体实现 1. HomePage主页面在创建后,创建实况窗和创建定时任务,每间隔固定时间调用liveViewManager.updateLiveView()接口更新实况窗,并通过commonEventManager.publish()接口传递新的参数给沉浸实况窗页面,实现实况窗和沉浸实况窗更新。 -- Gitee From 8f3061ec3e33b30d0411f26aa1023eba7f4c887e Mon Sep 17 00:00:00 2001 From: Fe26 Date: Tue, 15 Jul 2025 07:18:34 +0000 Subject: [PATCH 13/27] update liveviewlockscreenlibrary/build-profile.json5. Signed-off-by: Fe26 --- liveviewlockscreenlibrary/build-profile.json5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liveviewlockscreenlibrary/build-profile.json5 b/liveviewlockscreenlibrary/build-profile.json5 index 312d38e..cda3307 100644 --- a/liveviewlockscreenlibrary/build-profile.json5 +++ b/liveviewlockscreenlibrary/build-profile.json5 @@ -8,7 +8,7 @@ "arkOptions": { "obfuscation": { "ruleOptions": { - "enable": true, + "enable": false, "files": [ "./obfuscation-rules.txt" ] -- Gitee From b5e78135c15a4a18c60ad5e4fce02a3f49821520 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Tue, 15 Jul 2025 20:09:21 +0800 Subject: [PATCH 14/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liveviewlockscreenlibrary/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liveviewlockscreenlibrary/README.md b/liveviewlockscreenlibrary/README.md index 8adb757..905bad5 100644 --- a/liveviewlockscreenlibrary/README.md +++ b/liveviewlockscreenlibrary/README.md @@ -17,7 +17,7 @@ ohpm install @ohos_samples/liveviewlockscreenlibrary ``` { "dependencies": { - "@ohos_samples/liveviewlockscreenlibrary": "^1.0.1" + "@ohos_samples/liveviewlockscreenlibrary": "^1.0.0" } } ``` -- Gitee From 9a5d4dbe6ee58daf45d7b4ffe5bdd2e867925145 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Thu, 17 Jul 2025 16:19:21 +0800 Subject: [PATCH 15/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/base/element/color.json | 4 ---- .../src/main/ets/entryability/EntryAbility.ets | 2 +- .../src/main/resources/base/element/color.json | 8 ++++++++ .../src/main/resources/dark/element/color.json | 0 4 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 liveviewlockscreensample/src/main/resources/base/element/color.json rename {liveviewlockscreenlibrary => liveviewlockscreensample}/src/main/resources/dark/element/color.json (100%) diff --git a/liveviewlockscreenlibrary/src/main/resources/base/element/color.json b/liveviewlockscreenlibrary/src/main/resources/base/element/color.json index 4ed1297..b8a7c85 100644 --- a/liveviewlockscreenlibrary/src/main/resources/base/element/color.json +++ b/liveviewlockscreenlibrary/src/main/resources/base/element/color.json @@ -1,9 +1,5 @@ { "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, { "name": "Index_background_first", "value": "#000000" diff --git a/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets b/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets index 9dbdcfc..fe2416c 100644 --- a/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets +++ b/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets @@ -22,7 +22,7 @@ const TAG: string = '[EntryAbility]'; export default class EntryAbility extends UIAbility { onCreate(): void { - LiveViewLockScreenController.saveBundleName() + LiveViewLockScreenController.saveBundleName(); hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); } diff --git a/liveviewlockscreensample/src/main/resources/base/element/color.json b/liveviewlockscreensample/src/main/resources/base/element/color.json new file mode 100644 index 0000000..3c71296 --- /dev/null +++ b/liveviewlockscreensample/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/main/resources/dark/element/color.json b/liveviewlockscreensample/src/main/resources/dark/element/color.json similarity index 100% rename from liveviewlockscreenlibrary/src/main/resources/dark/element/color.json rename to liveviewlockscreensample/src/main/resources/dark/element/color.json -- Gitee From 846eb47d0f4da25167d373e9e42591199c9bfa24 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Thu, 17 Jul 2025 16:51:20 +0800 Subject: [PATCH 16/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liveviewlockscreenlibrary/README.md | 27 ++++++++++++++++--- .../main/ets/utils/LiveViewExtAbilityUtil.ets | 2 +- .../src/main/ets/utils/LiveViewUtil.ets | 2 +- .../main/ets/entryability/EntryAbility.ets | 2 +- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/liveviewlockscreenlibrary/README.md b/liveviewlockscreenlibrary/README.md index 905bad5..2d01649 100644 --- a/liveviewlockscreenlibrary/README.md +++ b/liveviewlockscreenlibrary/README.md @@ -44,8 +44,27 @@ Stack() { // EntryAbility.ets import { LiveViewLockScreenController } from '@ohos_samples/liveviewlockscreenlibrary'; -LiveViewLockScreenController.saveBundleName() -LiveViewLockScreenController.initWindowConfig(windowStage); -LiveViewLockScreenController.initLiveView(session); -LiveViewLockScreenController.destroyLLiveView(); +onCreate(): void { + LiveViewLockScreenController.saveBundleName(); +} +onWindowStageCreate(windowStage: window.WindowStage): void { + windowStage.loadContent('pages/Index', (error) => { + if (error.code) { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to load the content. Cause code: ${error.code}, message: ${error.message}`); + return; + } + LiveViewLockScreenController.initWindowConfig(windowStage); + hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in loading the content.'); + }); +} + +// LiveViewExtAbility.ets +onSessionCreate(_want: Want, session: UIExtensionContentSession): void { + LiveViewLockScreenController.initLiveView(session); + session.loadContent('pages/LockScreen'); +} +onSessionDestroy(): void { + LiveViewLockScreenController.destroyLLiveView(); +} ``` \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets index 5b1612a..c9a1f74 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets @@ -48,7 +48,7 @@ export class LiveViewExtAbilityUtil { session.getUIExtensionWindowProxy().on('windowSizeChange', (windowSize: window.Size) => { LiveViewExtAbilityUtil.updateBreakPoint(windowSize); }); - LiveViewExtAbilityUtil.getInstance().createSubscriber() + LiveViewExtAbilityUtil.getInstance().createSubscriber(); } public destroySubscribe(): void { diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets index d4af808..23b382d 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets @@ -121,7 +121,7 @@ export class LiveViewUtil { private async createPrimaryLiveView(): Promise { // Construct live window request body. - let liveView: liveViewManager.LiveView = { + const liveView: liveViewManager.LiveView = { id: 0, sequence: this.sequence, // Application scenarios of the live window. NAVIGATION: Navigation. diff --git a/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets b/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets index fe2416c..defc176 100644 --- a/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets +++ b/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets @@ -16,7 +16,7 @@ import { UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { LiveViewLockScreenController } from 'liveviewlockscreenlibrary' +import { LiveViewLockScreenController } from 'liveviewlockscreenlibrary'; const TAG: string = '[EntryAbility]'; -- Gitee From 8c9a0b74f8b6f4ffffbb3cc66829434cdd113396 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Thu, 17 Jul 2025 17:22:53 +0800 Subject: [PATCH 17/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liveviewlockscreenlibrary/src/main/module.json5 | 12 ++++++++++++ .../src/main/resources/base/element/string.json | 4 ++++ liveviewlockscreensample/src/main/module.json5 | 12 ------------ .../src/main/resources/base/element/string.json | 4 ---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/liveviewlockscreenlibrary/src/main/module.json5 b/liveviewlockscreenlibrary/src/main/module.json5 index 15413a6..7f423a5 100644 --- a/liveviewlockscreenlibrary/src/main/module.json5 +++ b/liveviewlockscreenlibrary/src/main/module.json5 @@ -6,6 +6,18 @@ "default", "tablet", "2in1" + ], + "requestPermissions": [ + { + "name": "ohos.permission.KEEP_BACKGROUND_RUNNING", + "reason": "$string:reason_background", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + }, ] } } \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/main/resources/base/element/string.json b/liveviewlockscreenlibrary/src/main/resources/base/element/string.json index 72d047e..b989469 100644 --- a/liveviewlockscreenlibrary/src/main/resources/base/element/string.json +++ b/liveviewlockscreenlibrary/src/main/resources/base/element/string.json @@ -1,5 +1,9 @@ { "string": [ + { + "name": "reason_background", + "value": "Background operation to update the live view" + }, { "name": "traffic_info_meter", "value": "800 meters" diff --git a/liveviewlockscreensample/src/main/module.json5 b/liveviewlockscreensample/src/main/module.json5 index 585ce7e..0f83c86 100644 --- a/liveviewlockscreensample/src/main/module.json5 +++ b/liveviewlockscreensample/src/main/module.json5 @@ -48,17 +48,5 @@ "exported": false } ], - "requestPermissions": [ - { - "name": "ohos.permission.KEEP_BACKGROUND_RUNNING", - "reason": "$string:reason_background", - "usedScene": { - "abilities": [ - "EntryAbility" - ], - "when": "always" - } - }, - ], } } \ No newline at end of file diff --git a/liveviewlockscreensample/src/main/resources/base/element/string.json b/liveviewlockscreensample/src/main/resources/base/element/string.json index a105fe4..a218cd8 100644 --- a/liveviewlockscreensample/src/main/resources/base/element/string.json +++ b/liveviewlockscreensample/src/main/resources/base/element/string.json @@ -11,10 +11,6 @@ { "name": "EntryAbility_label", "value": "LiveViewLockScreen" - }, - { - "name": "reason_background", - "value": "Background operation to update the live view" } ] } \ No newline at end of file -- Gitee From 4c98ca6c32c72d6f2216657fa2d86e6df1e3cb3d Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Thu, 17 Jul 2025 17:33:27 +0800 Subject: [PATCH 18/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/en_US/element/string.json | 4 ++++ .../src/main/resources/zh_CN/element/string.json | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json b/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json index 72d047e..b989469 100644 --- a/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json +++ b/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json @@ -1,5 +1,9 @@ { "string": [ + { + "name": "reason_background", + "value": "Background operation to update the live view" + }, { "name": "traffic_info_meter", "value": "800 meters" diff --git a/liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json b/liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json index 5e29f68..73631fa 100644 --- a/liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json +++ b/liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json @@ -1,5 +1,9 @@ { "string": [ + { + "name": "reason_background", + "value": "后台运行更新实况窗" + }, { "name": "traffic_info_meter", "value": "800米" -- Gitee From d105779512ec871015958cabf7c971abfd9205bd Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Thu, 17 Jul 2025 19:30:44 +0800 Subject: [PATCH 19/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liveviewlockscreenlibrary/src/main/module.json5 | 3 --- 1 file changed, 3 deletions(-) diff --git a/liveviewlockscreenlibrary/src/main/module.json5 b/liveviewlockscreenlibrary/src/main/module.json5 index 7f423a5..25a6c5b 100644 --- a/liveviewlockscreenlibrary/src/main/module.json5 +++ b/liveviewlockscreenlibrary/src/main/module.json5 @@ -12,9 +12,6 @@ "name": "ohos.permission.KEEP_BACKGROUND_RUNNING", "reason": "$string:reason_background", "usedScene": { - "abilities": [ - "EntryAbility" - ], "when": "always" } }, -- Gitee From c013d1d391faaf2ac2534ad313bbf27cb10475b3 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Thu, 17 Jul 2025 19:34:05 +0800 Subject: [PATCH 20/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets index 2b35019..b35ba8e 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets @@ -115,7 +115,7 @@ export class LiveView { // Internal method to manage background tasks private startContinuousRunningTask() { // Configure WantAgent for background operation - let wantAgentInfo: wantAgent.WantAgentInfo = { + const wantAgentInfo: wantAgent.WantAgentInfo = { wants: [ { bundleName: AppStorage.get(Constants.KEY_PREFIX + 'BundleName'), -- Gitee From cadfb911db30ffa9a7e44cb944102a5e044310e9 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Thu, 17 Jul 2025 20:25:06 +0800 Subject: [PATCH 21/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liveviewlockscreenlibrary/README.md | 7 ++++- .../main/ets/utils/LiveViewExtAbilityUtil.ets | 11 ++++++-- .../src/main/ets/utils/LiveViewUtil.ets | 28 +++++++++++++------ .../src/main/ets/utils/WindowUtil.ets | 11 ++++++-- .../main/ets/liveview/LiveViewExtAbility.ets | 8 +++++- 5 files changed, 48 insertions(+), 17 deletions(-) diff --git a/liveviewlockscreenlibrary/README.md b/liveviewlockscreenlibrary/README.md index 2d01649..8ab112f 100644 --- a/liveviewlockscreenlibrary/README.md +++ b/liveviewlockscreenlibrary/README.md @@ -62,7 +62,12 @@ onWindowStageCreate(windowStage: window.WindowStage): void { // LiveViewExtAbility.ets onSessionCreate(_want: Want, session: UIExtensionContentSession): void { LiveViewLockScreenController.initLiveView(session); - session.loadContent('pages/LockScreen'); + try { + session.loadContent('pages/LockScreen'); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `Session load content fail. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); + } } onSessionDestroy(): void { LiveViewLockScreenController.destroyLLiveView(); diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets index c9a1f74..487fd04 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets @@ -45,9 +45,14 @@ export class LiveViewExtAbilityUtil { public setSession(session: UIExtensionContentSession): void { // Window size listener. - session.getUIExtensionWindowProxy().on('windowSizeChange', (windowSize: window.Size) => { - LiveViewExtAbilityUtil.updateBreakPoint(windowSize); - }); + try { + session.getUIExtensionWindowProxy().on('windowSizeChange', (windowSize: window.Size) => { + LiveViewExtAbilityUtil.updateBreakPoint(windowSize); + }); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `Session update break point failed. code: ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); + } LiveViewExtAbilityUtil.getInstance().createSubscriber(); } diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets index 23b382d..596c32a 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets @@ -92,13 +92,12 @@ export class LiveViewUtil { type: liveViewManager.CapsuleType.CAPSULE_TYPE_TEXT, status: 1, icon: 'turn_right_light_square.png', - backgroundColor: this.context.resourceManager.getStringSync($r('app.string.live_view_background').id), - title: `${params.distance}${this.context.resourceManager.getStringSync($r('app.string.meter').id)}`, + backgroundColor: this.getStringSync($r('app.string.live_view_background').id), + title: `${params.distance}${this.getStringSync($r('app.string.meter').id)}`, } liveView.liveViewData.primary.title = - `${this.context.resourceManager.getStringSync($r('app.string.live_view_primary_title_first') - .id)}${params.distance}${this.context.resourceManager.getStringSync($r('app.string.live_view_primary_title_second') - .id)}`; + `${this.getStringSync($r('app.string.live_view_primary_title_first') + .id)}${params.distance}${this.getStringSync($r('app.string.live_view_primary_title_second').id)}`; liveView.liveViewData.primary.content = [{ text: this.context.resourceManager.getStringSync(params.roadName) }]; liveView.liveViewData.primary.liveViewLockScreenAbilityName = 'LiveViewExtAbility'; liveView.liveViewData.primary.liveViewLockScreenAbilityParameters = { '': '' }; @@ -132,13 +131,13 @@ export class LiveViewUtil { type: liveViewManager.CapsuleType.CAPSULE_TYPE_TEXT, status: 1, icon: 'turn_right_light_square.png', - backgroundColor: this.context.resourceManager.getStringSync($r('app.string.live_view_background').id), - title: this.context.resourceManager.getStringSync($r('app.string.live_view_title').id), + backgroundColor: this.getStringSync($r('app.string.live_view_background').id), + title: this.getStringSync($r('app.string.live_view_title').id), }, // Live view card related parameters primary: { - title: this.context.resourceManager.getStringSync($r('app.string.live_view_title').id), - content: [{ text: this.context.resourceManager.getStringSync($r('app.string.live_view_content').id) }], + title: this.getStringSync($r('app.string.live_view_title').id), + content: [{ text: this.getStringSync($r('app.string.live_view_content').id) }], // Add LiveViewLockScreenExtensionAbility name to build lock screen live view liveViewLockScreenAbilityName: 'LiveViewExtAbility', liveViewLockScreenAbilityParameters: { liveViewParameters: '' }, @@ -163,4 +162,15 @@ export class LiveViewUtil { const agent: object = await wantAgent.getWantAgent(wantAgentInfo); return agent; } + + private getStringSync(resId: number): string { + let stringSyn: string = ''; + try { + stringSyn = this.context.resourceManager.getStringSync(resId); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `Get string failed. code: ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); + } + return stringSyn; + } } \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets index ea299f5..5483c97 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets @@ -56,9 +56,14 @@ export class WindowUtil { // Get status indicator height. private static setAvoidArea(type: window.AvoidAreaType, area: window.AvoidArea) { - if (type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { - AppStorage.setOrCreate(Constants.KEY_PREFIX + 'NaviIndicatorHeight', - WindowUtil.windowClass?.getUIContext().px2vp(area.bottomRect.height)); + try { + if (type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { + AppStorage.setOrCreate(Constants.KEY_PREFIX + 'NaviIndicatorHeight', + WindowUtil.windowClass?.getUIContext().px2vp(area.bottomRect.height)); + } + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `Get windowAvoidArea or Register windowSizeChange failed. code: ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); } } diff --git a/liveviewlockscreensample/src/main/ets/liveview/LiveViewExtAbility.ets b/liveviewlockscreensample/src/main/ets/liveview/LiveViewExtAbility.ets index b31d759..6b94c02 100644 --- a/liveviewlockscreensample/src/main/ets/liveview/LiveViewExtAbility.ets +++ b/liveviewlockscreensample/src/main/ets/liveview/LiveViewExtAbility.ets @@ -14,6 +14,7 @@ */ import { AbilityConstant, UIExtensionContentSession, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import { LiveViewLockScreenExtensionAbility } from '@kit.LiveViewKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { LiveViewLockScreenController } from 'liveviewlockscreenlibrary'; @@ -42,7 +43,12 @@ export default class LiveViewExtAbility extends LiveViewLockScreenExtensionAbili onSessionCreate(_want: Want, session: UIExtensionContentSession): void { hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onSessionCreate begin.'); LiveViewLockScreenController.initLiveView(session); - session.loadContent('pages/LockScreen'); + try { + session.loadContent('pages/LockScreen'); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `Session load content fail. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); + } } // Cleanup operations when destroying UI session -- Gitee From 37101d9086571a162d0cddfa465b2f0997280029 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Thu, 17 Jul 2025 20:32:49 +0800 Subject: [PATCH 22/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liveviewlockscreenlibrary/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/liveviewlockscreenlibrary/README.md b/liveviewlockscreenlibrary/README.md index 8ab112f..d8b25d5 100644 --- a/liveviewlockscreenlibrary/README.md +++ b/liveviewlockscreenlibrary/README.md @@ -60,6 +60,7 @@ onWindowStageCreate(windowStage: window.WindowStage): void { } // LiveViewExtAbility.ets +import { LiveViewLockScreenController } from 'liveviewlockscreenlibrary'; onSessionCreate(_want: Want, session: UIExtensionContentSession): void { LiveViewLockScreenController.initLiveView(session); try { -- Gitee From f190b24630dbd5a6f2ed9b2adb3b743603d2e78d Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Thu, 17 Jul 2025 20:54:22 +0800 Subject: [PATCH 23/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/utils/LiveViewUtil.ets | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets index 596c32a..fca43da 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets @@ -40,7 +40,12 @@ export class LiveViewUtil { this.defaultLiveView = await this.createPrimaryLiveView(); this.updateLiveViewInfo(params); - return await liveViewManager.startLiveView(this.defaultLiveView); + try { + await liveViewManager.startLiveView(this.defaultLiveView); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to start live view. Cause code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}`); + } } public async updateLiveView(params: RouteData): Promise { @@ -76,11 +81,23 @@ export class LiveViewUtil { hilog.error(0x0000, TAG, '%{public}s', `Failed to stop liveView. Cause code: ${error.code}, message: ${error.message}`); }); - return; } private static async isLiveViewEnabled(): Promise { - return await liveViewManager.isLiveViewEnabled(); + try { + liveViewManager.isLiveViewEnabled().then((isEnabled: boolean) => { + hilog.info(0x0000, TAG, '%{public}s', + 'Succeeded in checking whether liveView is enabled.'); + return isEnabled; + }).catch((error: BusinessError) => { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to check whether liveView is enabled. Cause code: ${error.code}, message: ${error.message}`); + }); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to check whether liveView is enabled. Cause code: ${error.code}, message: ${error.message}`); + } + return true; } private updateLiveViewInfo(params: RouteData) { -- Gitee From 7b2daa34e147dfcaafb48383b1021c3533127354 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Fri, 18 Jul 2025 10:32:55 +0800 Subject: [PATCH 24/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/utils/LiveViewUtil.ets | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets index fca43da..4a76ac2 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets @@ -115,7 +115,7 @@ export class LiveViewUtil { liveView.liveViewData.primary.title = `${this.getStringSync($r('app.string.live_view_primary_title_first') .id)}${params.distance}${this.getStringSync($r('app.string.live_view_primary_title_second').id)}`; - liveView.liveViewData.primary.content = [{ text: this.context.resourceManager.getStringSync(params.roadName) }]; + liveView.liveViewData.primary.content = [{ text: this.getResourceStringSync(params.roadName) }]; liveView.liveViewData.primary.liveViewLockScreenAbilityName = 'LiveViewExtAbility'; liveView.liveViewData.primary.liveViewLockScreenAbilityParameters = { '': '' }; if (params.roadInfo.laneNum === 1) { @@ -190,4 +190,15 @@ export class LiveViewUtil { } return stringSyn; } + + private getResourceStringSync(resource: Resource): string { + let stringSyn: string = ''; + try { + stringSyn = this.context.resourceManager.getStringSync(resource); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `Get string failed. code: ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); + } + return stringSyn; + } } \ No newline at end of file -- Gitee From 46824ee230b7f13ebe78a6b03e7691f6e262ebe2 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Fri, 18 Jul 2025 11:01:06 +0800 Subject: [PATCH 25/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/utils/LiveView.ets | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets index b35ba8e..1754a60 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets @@ -100,12 +100,14 @@ export class LiveView { // Stop background tasks try { - backgroundTaskManager.stopBackgroundRunning(this.context).then(() => { - hilog.info(0x0000, TAG, '%{public}s', 'Operation stopBackgroundRunning succeeded'); - }).catch((error: BusinessError) => { - hilog.error(0x0000, TAG, '%{public}s', - `Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`); - }); + if (canIUse('SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask')) { + backgroundTaskManager.stopBackgroundRunning(this.context).then(() => { + hilog.info(0x0000, TAG, '%{public}s', 'Operation stopBackgroundRunning succeeded'); + }).catch((error: BusinessError) => { + hilog.error(0x0000, TAG, '%{public}s', + `Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`); + }); + } } catch (error) { hilog.error(0x0000, TAG, '%{public}s', `Operation stopBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); @@ -135,12 +137,14 @@ export class LiveView { // Required background resource types const list: string[] = ['location']; // Request background running permission - backgroundTaskManager.startBackgroundRunning(this.context, list, wantAgentObj).then(() => { - hilog.info(0x0000, TAG, '%{public}s', 'Operation startBackgroundRunning succeeded.'); - }).catch((error: BusinessError) => { - hilog.error(0x0000, TAG, '%{public}s', - `Failed to Operation startBackgroundRunning. code is ${error.code} message is ${error.message}`); - }); + if (canIUse('SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask')) { + backgroundTaskManager.startBackgroundRunning(this.context, list, wantAgentObj).then(() => { + hilog.info(0x0000, TAG, '%{public}s', 'Operation startBackgroundRunning succeeded.'); + }).catch((error: BusinessError) => { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to Operation startBackgroundRunning. code is ${error.code} message is ${error.message}`); + }); + } } catch (error) { hilog.error(0x0000, TAG, '%{public}s', `Failed to Operation startBackgroundRunning. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); -- Gitee From af94a0094c8a7ae2d645db1d6d5c4058f641e7eb Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Fri, 18 Jul 2025 11:16:11 +0800 Subject: [PATCH 26/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/utils/LiveViewUtil.ets | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets index 4a76ac2..48f2da3 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets @@ -166,7 +166,7 @@ export class LiveViewUtil { return liveView; } - private static async buildWantAgent(): Promise { + private static async buildWantAgent(): Promise { const wantAgentInfo: wantAgent.WantAgentInfo = { wants: [{ bundleName: AppStorage.get(Constants.KEY_PREFIX + 'BundleName'), @@ -176,8 +176,13 @@ export class LiveViewUtil { requestCode: 0, actionFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; - const agent: object = await wantAgent.getWantAgent(wantAgentInfo); - return agent; + try { + return await wantAgent.getWantAgent(wantAgentInfo); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to build WantAgent. code: ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); + return undefined; + } } private getStringSync(resId: number): string { -- Gitee From 12e9a287d8d237532cf874039f8cbcc8684cee53 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Fri, 18 Jul 2025 11:35:16 +0800 Subject: [PATCH 27/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets | 6 +++--- .../src/main/ets/utils/LiveViewUtil.ets | 6 +++--- liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets index 1754a60..488d507 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets @@ -47,7 +47,7 @@ export class LiveView { } // Main entry point to start live view functionality - public createLiveView() { + public createLiveView(): void { // Initialize live view and start background tasks this.liveViewController.startLiveView(getRouteData()).then(() => { this.startContinuousRunningTask(); @@ -87,7 +87,7 @@ export class LiveView { } // Cleanup method to stop all live view activities - public finishLiveView() { + public finishLiveView(): void { // Clear periodic updates if (this.updateInterval !== undefined) { clearInterval(this.updateInterval); @@ -115,7 +115,7 @@ export class LiveView { } // Internal method to manage background tasks - private startContinuousRunningTask() { + private startContinuousRunningTask(): void { // Configure WantAgent for background operation const wantAgentInfo: wantAgent.WantAgentInfo = { wants: [ diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets index 48f2da3..d359743 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets @@ -31,7 +31,7 @@ export class LiveViewUtil { this.context = context; } - public async startLiveView(params: RouteData) { + public async startLiveView(params: RouteData): Promise { // Verify that the live view switch is turned on if (!await LiveViewUtil.isLiveViewEnabled()) { hilog.error(0x0000, TAG, '%{public}s', 'Live view is disabled.'); @@ -69,7 +69,7 @@ export class LiveViewUtil { } // Close live view. - public async closeLiveView() { + public async closeLiveView(): Promise { // Ensure that the sequence is greater than the current live window page. this.sequence++; this.defaultLiveView = await this.createPrimaryLiveView(); @@ -100,7 +100,7 @@ export class LiveViewUtil { return true; } - private updateLiveViewInfo(params: RouteData) { + private updateLiveViewInfo(params: RouteData): void { let liveView: liveViewManager.LiveView = this.defaultLiveView!; if (params) { liveView.sequence = this.sequence diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets index 5483c97..8d01e90 100644 --- a/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets @@ -24,7 +24,7 @@ const TAG: string = '[WindowUtil]'; export class WindowUtil { private static windowClass?: window.Window; - public static initialize(windowStage: window.WindowStage) { + public static initialize(windowStage: window.WindowStage): void { try { WindowUtil.windowClass = windowStage.getMainWindowSync(); const uiContext: UIContext = WindowUtil.windowClass.getUIContext(); @@ -36,7 +36,7 @@ export class WindowUtil { } } - private static registerBreakPoint(windowClass: window.Window) { + private static registerBreakPoint(windowClass: window.Window): void { try { BreakpointSystem.getInstance().onWindowSizeChange(windowClass); windowClass.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(windowClass)); @@ -55,7 +55,7 @@ export class WindowUtil { } // Get status indicator height. - private static setAvoidArea(type: window.AvoidAreaType, area: window.AvoidArea) { + private static setAvoidArea(type: window.AvoidAreaType, area: window.AvoidArea): void { try { if (type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { AppStorage.setOrCreate(Constants.KEY_PREFIX + 'NaviIndicatorHeight', -- Gitee