diff --git a/README.md b/README.md index 6e0b5f79a1314d1b778f62935d46368c4f1fe58c..1de218493770ec3a44c470d2e8d42fb8db7ea669 100644 --- a/README.md +++ b/README.md @@ -25,35 +25,6 @@ 4. 本Sample仅提供在本地创建、更新与结束实况窗的能力(不能后台更新,若要后台更新,请使用Push Kit)。若要使用Push Kit更新,可参考[推送实况窗消息服务](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/push-update-liveview),用已有服务器调用对应的REST API。 -## 工程目录 - -``` -├─entry/src/main/ets -│ ├───constant -│ │ └───Constant.ets // 常量 -│ ├───entryability -│ │ └───EntryAbility.ets // EntryAbility -│ ├───liveview -│ │ ├───LiveViewExtAbility.ets // 实况窗 -│ │ └───LockScreenPage.ets // 锁屏页面 -│ ├───model -│ │ └───RouteDataModel.ets // 导航数据Model -│ ├───pages -│ │ └───Index.ets // 主页面 -│ ├───utils -│ │ ├───BreakpointUtil.ets // 断点工具类 -│ │ ├───LiveView.ets // 实况窗类 -│ │ └───LiveViewUtil.ets // 实况窗工具类 -│ ├───view -│ │ ├───RoadView.ets // 道路 -│ │ ├───TrafficInfoView.ets // 导航信息 -│ │ └───TrafficView.ets // 导航页面 -│ └───viewmodel -│ └───RouteDataViewModel.ets // 导航数据ViewModel -└───entry/src/main/resources - -``` - ## 具体实现 1. HomePage主页面在创建后,创建实况窗和创建定时任务,每间隔固定时间调用liveViewManager.updateLiveView()接口更新实况窗,并通过commonEventManager.publish()接口传递新的参数给沉浸实况窗页面,实现实况窗和沉浸实况窗更新。 diff --git a/build-profile.json5 b/build-profile.json5 index 1e69556b3411622cb2e87a87389653bb34f1b148..246f563696a0a8ededa01b00995b75c8c71ae6ff 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -7,12 +7,6 @@ "signingConfig": "default", "compatibleSdkVersion": "5.0.0(12)", "runtimeOS": "HarmonyOS", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } } ], "buildModeSet": [ @@ -26,8 +20,8 @@ }, "modules": [ { - "name": "entry", - "srcPath": "./entry", + "name": "liveviewlockscreensample", + "srcPath": "./liveviewlockscreensample", "targets": [ { "name": "default", @@ -36,6 +30,10 @@ ] } ] + }, + { + "name": "liveviewlockscreenlibrary", + "srcPath": "./liveviewlockscreenlibrary", } ] } \ No newline at end of file diff --git a/entry/src/main/ets/view/TrafficInfoView.ets b/entry/src/main/ets/view/TrafficInfoView.ets deleted file mode 100644 index 63efea9afbf7b261764696ead7475a8534546063..0000000000000000000000000000000000000000 --- a/entry/src/main/ets/view/TrafficInfoView.ets +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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 { LiveView } from "../utils/LiveView" - -@Component -export struct TrafficInfoView { - @State private isStart: boolean = true; - - 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'), - 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_level16'), - }) - } - .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%') - } -} \ No newline at end of file diff --git a/entry/src/main/ets/view/TrafficView.ets b/entry/src/main/ets/view/TrafficView.ets deleted file mode 100644 index f5b1856f87e39451e20ff89163d31f533d446d50..0000000000000000000000000000000000000000 --- a/entry/src/main/ets/view/TrafficView.ets +++ /dev/null @@ -1,204 +0,0 @@ -/* - * 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 { Constants } from "../constant/Constant"; -import { LaneData } from "../model/RouteDataModel"; -import { TrafficInfoView } from "./TrafficInfoView"; -import { BreakpointType } from "../utils/BreakpointUtil"; - -@Component -export struct TrafficView { - @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; - - @Builder - myBuilder() { - Row() { - TrafficInfoView() - } - .backgroundColor($r('sys.color.background_secondary')) - .width('100%') - .height('100%') - } - - build() { - Column() { - Row() { - Column() { - 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(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), - }) - - 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)) - } - .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')) - .objectFit(ImageFit.Contain) - .height(80) - .position({ - top: 0, - left: this.horizontalBreakpoint === Constants.BREAK_POINT_MD ? '51%' : '31%', - }) - } - } - - 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(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) - - 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')) - .objectFit(ImageFit.Contain) - .width(new BreakpointType('20%', '20%', '10%').getValue(this.horizontalBreakpoint)) - .position({ - left: '70%', - top: 30 - }) - } - .width('100%') - .onClick(() => { - if (this.horizontalBreakpoint === Constants.BREAK_POINT_SM && - this.verticalBreakpoint === Constants.BREAK_POINT_MD) { - this.isShow = true; - } else { - this.isShow = false; - } - }) - } - - Blank() - - Row(){ - if (this.horizontalBreakpoint !== Constants.BREAK_POINT_SM || - this.verticalBreakpoint !== Constants.BREAK_POINT_MD) { - Row() { - TrafficInfoView() - } - .onSizeChange(() => { - this.isShow = false; - }) - .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) - .borderRadius({ - topLeft: 32, - topRight: 32, - }) - } - } - .width('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/media/background.png b/entry/src/main/resources/base/media/background.png deleted file mode 100644 index f939c9fa8cc8914832e602198745f592a0dfa34d..0000000000000000000000000000000000000000 Binary files a/entry/src/main/resources/base/media/background.png and /dev/null differ diff --git a/entry/src/main/resources/base/media/foreground.png b/entry/src/main/resources/base/media/foreground.png deleted file mode 100644 index 4483ddad1f079e1089d685bd204ee1cfe1d01902..0000000000000000000000000000000000000000 Binary files a/entry/src/main/resources/base/media/foreground.png and /dev/null differ diff --git a/entry/src/main/resources/base/media/layered_image.json b/entry/src/main/resources/base/media/layered_image.json deleted file mode 100644 index fb49920440fb4d246c82f9ada275e26123a2136a..0000000000000000000000000000000000000000 --- a/entry/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/entry/src/main/resources/base/profile/backup_config.json b/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100644 index 78f40ae7c494d71e2482278f359ec790ca73471a..0000000000000000000000000000000000000000 --- a/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json deleted file mode 100644 index 731cedf01ef9edcfa92e1a357b0f5f4b2794f305..0000000000000000000000000000000000000000 --- a/entry/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "src": [ - "liveview/LockScreenPage", - "pages/Index" - ] -} diff --git a/entry/src/main/resources/rawfile/traffic_md.svg b/entry/src/main/resources/rawfile/traffic_md.svg deleted file mode 100644 index 728e3192851034d51a9e3637390fed210dd34e17..0000000000000000000000000000000000000000 --- a/entry/src/main/resources/rawfile/traffic_md.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - Created with Pixso. - - - - - - - - - diff --git a/entry/src/main/resources/rawfile/traffic_sm.svg b/entry/src/main/resources/rawfile/traffic_sm.svg deleted file mode 100644 index cf2c74bfbc4ee0077503e27235dc97ffb5054543..0000000000000000000000000000000000000000 --- a/entry/src/main/resources/rawfile/traffic_sm.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - Created with Pixso. - - - - - - - - - diff --git a/liveviewlockscreenlibrary/Index.ets b/liveviewlockscreenlibrary/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a91d0a7d207c5d8fe9c7a6a70ee90a508dbd35e2 --- /dev/null +++ b/liveviewlockscreenlibrary/Index.ets @@ -0,0 +1,11 @@ +export { LiveViewLockScreenPage } from './src/main/ets/pages/LiveViewLockScreenPage'; + +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 diff --git a/liveviewlockscreenlibrary/build-profile.json5 b/liveviewlockscreenlibrary/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..312d38eb08629793b3484c7373213f22840c8d82 --- /dev/null +++ b/liveviewlockscreenlibrary/build-profile.json5 @@ -0,0 +1,28 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + } + ] +} diff --git a/liveviewlockscreenlibrary/consumer-rules.txt b/liveviewlockscreenlibrary/consumer-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/liveviewlockscreenlibrary/hvigorfile.ts b/liveviewlockscreenlibrary/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..42187071482d292588ad40babeda74f7b8d97a23 --- /dev/null +++ b/liveviewlockscreenlibrary/hvigorfile.ts @@ -0,0 +1,6 @@ +import { harTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/entry/obfuscation-rules.txt b/liveviewlockscreenlibrary/obfuscation-rules.txt similarity index 97% rename from entry/obfuscation-rules.txt rename to liveviewlockscreenlibrary/obfuscation-rules.txt index 46686c4feca708e7a0936210a2ddac65938089c6..272efb6ca3f240859091bbbfc7c5802d52793b0b 100644 --- a/entry/obfuscation-rules.txt +++ b/liveviewlockscreenlibrary/obfuscation-rules.txt @@ -19,4 +19,5 @@ -enable-property-obfuscation -enable-toplevel-obfuscation +-enable-filename-obfuscation -enable-export-obfuscation \ No newline at end of file diff --git a/entry/oh-package.json5 b/liveviewlockscreenlibrary/oh-package.json5 similarity index 57% rename from entry/oh-package.json5 rename to liveviewlockscreenlibrary/oh-package.json5 index 248c3b7541a589682a250f86a6d3ecf7414d2d6a..5487c70867e75e52d493bfb482a801be7c774da5 100644 --- a/entry/oh-package.json5 +++ b/liveviewlockscreenlibrary/oh-package.json5 @@ -1,10 +1,9 @@ { - "name": "entry", + "name": "liveviewlockscreenlibrary", "version": "1.0.0", "description": "Please describe the basic information.", - "main": "", + "main": "Index.ets", "author": "", - "license": "", + "license": "Apache-2.0", "dependencies": {} } - diff --git a/entry/src/main/ets/liveview/LockScreenPage.ets b/liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets similarity index 65% rename from entry/src/main/ets/liveview/LockScreenPage.ets rename to liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets index 76679c63f4b4757a2f3a1c0a8611ede851c3ad5a..b28ab1c4e6c3026c3657d9f0d469dc8812ccffd0 100644 --- a/entry/src/main/ets/liveview/LockScreenPage.ets +++ b/liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets @@ -13,19 +13,14 @@ * limitations under the License. */ -import { Constants } from '../constant/Constant'; import { LaneData } from '../model/RouteDataModel'; -import { BreakpointType } from '../utils/BreakpointUtil'; +import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem'; import { RoadView } from '../view/RoadView'; -let storage: LocalStorage = LocalStorage.getShared(); - -@Entry(storage) -@Component -struct Index { - // [Start layoutBasedOnVerticalBreakpoint] - @StorageLink('verticalBreakpoint') verticalBreakpoint: string = Constants.BREAK_POINT_SM; - @LocalStorageProp('laneData') roadInfo: LaneData | undefined = undefined; +@Entry +export struct LockScreenPage { + @StorageLink('liveViewLockScreenCurrentHeightBreakpoint') currentHeightBreakpoint: string = BreakpointTypeEnum.SM; + @StorageProp('liveViewLockScreenLaneData') roadInfo: LaneData | undefined = undefined; build() { Stack({ alignContent: Alignment.Top }) { @@ -36,12 +31,11 @@ struct Index { .width(80) .position({ // Layout based on vertical breakpoint. - right: new BreakpointType(25, 25, 75).getValue(this.verticalBreakpoint), + right: new BreakpointType({ sm: 75, md: 25, lg: 25, }).getValue(this.currentHeightBreakpoint), top: 25 }) } .width('100%') .height('100%') } - // [End layoutBasedOnVerticalBreakpoint] } \ No newline at end of file diff --git a/entry/src/main/ets/model/RouteDataModel.ets b/liveviewlockscreenlibrary/src/main/ets/model/RouteDataModel.ets similarity index 100% rename from entry/src/main/ets/model/RouteDataModel.ets rename to liveviewlockscreenlibrary/src/main/ets/model/RouteDataModel.ets diff --git a/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets b/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..07785c67bed6ecd77d990ffb6fbe42d30bfa376f --- /dev/null +++ b/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets @@ -0,0 +1,115 @@ +/* + * 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 { 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) + + 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')) + .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')) + } +} + +@Component +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: 175, + }); + + aboutToAppear(): void { + LiveView.getInstance(this.getUIContext().getHostContext()).createLiveView(); + this.customDialogController?.open(); + } + + build() { + Stack() { + Image($r('app.media.traffic_background')) + .width('110%') + .height('110%') + + TrafficView() + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/BreakpointSystem.ets b/liveviewlockscreenlibrary/src/main/ets/utils/BreakpointSystem.ets new file mode 100644 index 0000000000000000000000000000000000000000..b4b7552a4287db7c1b5468eaba626e7d8c4b2274 --- /dev/null +++ b/liveviewlockscreenlibrary/src/main/ets/utils/BreakpointSystem.ets @@ -0,0 +1,142 @@ +/* + * 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 type { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[BreakpointSystem]'; + +export enum BreakpointTypeEnum { + XS = 'xs', + SM = 'sm', + MD = 'md', + LG = 'lg', + XL = 'xl', +} + +export interface BreakpointTypes { + xs?: T; + sm: T; + md: T; + lg: T; + xl?: T; +} + +export class BreakpointType { + private xs: T; + private sm: T; + private md: T; + private lg: T; + private xl: T; + + public constructor(param: BreakpointTypes) { + this.xs = param.xs || param.sm; + this.sm = param.sm; + this.md = param.md; + this.lg = param.lg; + this.xl = param.xl || param.lg; + } + + public getValue(currentBreakpoint: string): T { + if (currentBreakpoint === BreakpointTypeEnum.XS) { + return this.xs; + } + if (currentBreakpoint === BreakpointTypeEnum.SM) { + return this.sm; + } + if (currentBreakpoint === BreakpointTypeEnum.MD) { + return this.md; + } + if (currentBreakpoint === BreakpointTypeEnum.XL) { + return this.xl; + } + return this.lg; + } +} + +export class BreakpointSystem { + private static instance: BreakpointSystem; + private currentWidthBreakpoint: BreakpointTypeEnum = BreakpointTypeEnum.MD; + private currentHeightBreakpoint: BreakpointTypeEnum = BreakpointTypeEnum.LG; + + private constructor() { + AppStorage.setOrCreate('liveViewLockScreenCurrentWidthBreakpoint', this.currentWidthBreakpoint); + AppStorage.setOrCreate('liveViewLockScreenCurrentHeightBreakpoint', this.currentHeightBreakpoint); + } + + public static getInstance(): BreakpointSystem { + if (!BreakpointSystem.instance) { + BreakpointSystem.instance = new BreakpointSystem(); + } + return BreakpointSystem.instance; + } + + public updateCurrentWidthBreakpoint(widthBreakpoint: BreakpointTypeEnum): void { + if (this.currentWidthBreakpoint !== widthBreakpoint) { + this.currentWidthBreakpoint = widthBreakpoint; + AppStorage.setOrCreate('liveViewLockScreenCurrentWidthBreakpoint', this.currentWidthBreakpoint); + } + } + + public updateCurrentHeightBreakpoint(heightBreakpoint: BreakpointTypeEnum): void { + if (this.currentHeightBreakpoint !== heightBreakpoint) { + this.currentHeightBreakpoint = heightBreakpoint; + AppStorage.setOrCreate('liveViewLockScreenCurrentHeightBreakpoint', this.currentHeightBreakpoint); + } + } + + public onWindowSizeChange(window: window.Window, uiContent: UIContext): void { + this.updateWidthHeightBp(window, uiContent); + } + + public updateWidthHeightBp(window: window.Window, uiContent: UIContext): 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 windowRatio: number = windowHeightVp / windowWidthVp; + let widthBp: BreakpointTypeEnum = BreakpointTypeEnum.SM; + let heightBp: BreakpointTypeEnum = BreakpointTypeEnum.LG; + + if (windowWidthVp < 320) { + widthBp = BreakpointTypeEnum.XS; + } else if (windowWidthVp >= 320 && windowWidthVp < 600) { + widthBp = BreakpointTypeEnum.SM; + } else if (windowWidthVp >= 600 && windowWidthVp < 840) { + widthBp = BreakpointTypeEnum.MD; + } else if (windowWidthVp >= 840 && windowWidthVp < 1440) { + widthBp = BreakpointTypeEnum.LG; + } else { + widthBp = BreakpointTypeEnum.XL; + } + this.updateCurrentWidthBreakpoint(widthBp); + + if (windowRatio < 0.8) { + heightBp = BreakpointTypeEnum.SM; + } else if (windowRatio > 1.2) { + heightBp = BreakpointTypeEnum.LG; + } else { + heightBp = BreakpointTypeEnum.MD; + } + this.updateCurrentHeightBreakpoint(heightBp) + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `UpdateBreakpoint fail. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); + } + } +} \ No newline at end of file diff --git a/entry/src/main/ets/constant/Constant.ets b/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets similarity index 37% rename from entry/src/main/ets/constant/Constant.ets rename to liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets index cb5fef1237ab98487f8c675038c9f9e257a19425..fb2b875e66b0b2aefec8e22ee754ec62805bcb49 100644 --- a/entry/src/main/ets/constant/Constant.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets @@ -13,8 +13,26 @@ * limitations under the License. */ -export class Constants { - public static readonly BREAK_POINT_SM: string = 'sm'; - public static readonly BREAK_POINT_MD: string = 'md'; - public static readonly BREAK_POINT_LG: string = 'lg'; +import { bundleManager } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[BundleNameUtil]'; + +export class BundleNameUtil { + public static getBundleName(): void { + try { + bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT).then((data) => { + hilog.info(0x0000, TAG, '%{public}s', 'getBundleInfoForSelf successfully.'); + AppStorage.setOrCreate('liveViewLockScreenBundleName', 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}`); + } + hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); + } } \ No newline at end of file diff --git a/entry/src/main/ets/utils/LiveView.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets similarity index 78% rename from entry/src/main/ets/utils/LiveView.ets rename to liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets index fd4d4d28d1b3ca61c3f7c65e34e24687271ed7fc..58162634924d11e4c5954bc1b982d3b6215e09c4 100644 --- a/entry/src/main/ets/utils/LiveView.ets +++ b/liveviewlockscreenlibrary/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 @@ -14,15 +14,11 @@ */ import { appManager, WantAgent, wantAgent } from '@kit.AbilityKit'; -// [Start startContinuousRunningTask] import { backgroundTaskManager } from '@kit.BackgroundTasksKit'; -// [StartExclude startContinuousRunningTask] -// [Start pushCommonEvent] import { BusinessError, commonEventManager } from '@kit.BasicServicesKit'; -// [StartExclude pushCommonEvent] import { hilog } from '@kit.PerformanceAnalysisKit'; import { RouteData } from '../model/RouteDataModel'; -import { LiveViewUtil } from '../utils/LiveViewUtil'; +import { LiveViewUtil } from './LiveViewUtil'; import { getRouteData } from '../viewmodel/RouteDataViewModel'; const TAG: string = '[LiveView]'; @@ -30,21 +26,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; } @@ -54,7 +50,6 @@ export class LiveView { // Initialize live view and start background tasks this.liveViewController.startLiveView(getRouteData()).then(() => { this.startContinuousRunningTask(); - // [Start getRunningProcessInfo] // Set up periodic state checking this.updateInterval = setInterval(() => { // Monitor application state changes @@ -62,14 +57,12 @@ export class LiveView { hilog.info(0x0000, TAG, '%{public}s', 'Success to getRunningProcessInformation'); // Handle background state if (data[0].state === appManager.ProcessState.STATE_BACKGROUND) { - // [StartExclude getRunningProcessInfo] let routeInfo: RouteData = getRouteData(); this.liveViewController.updateLiveView(routeInfo); - // [EndExclude pushCommonEvent] // Prepare common event data let options: commonEventManager.CommonEventPublishData = { data: 'data', - bundleName: 'com.example.mapliveviewsample', + bundleName: AppStorage.get('liveViewLockScreenBundleName'), parameters: { 'roadData': routeInfo.roadInfo } @@ -83,55 +76,49 @@ export class LiveView { hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in publishing commonEvent.') } }); - // [End pushCommonEvent] - // [EndExclude getRunningProcessInfo] } }).catch((error: BusinessError) => { hilog.error(0x0000, TAG, '%{public}s', `Failed to getRunningProcessInformation. code is ${error.code} message is ${error.message}`); }); }, 2000) - // [End getRunningProcessInfo] }) } // Cleanup method to stop all live view activities public finishLiveView() { - // [Start clearPeriodicUpdates] // Clear periodic updates if (this.updateInterval !== undefined) { clearInterval(this.updateInterval); this.updateInterval = undefined; - hilog.info(0x0000, TAG, 'Timer has been cleared'); + hilog.info(0x0000, TAG, '%{public}s', 'Timer has been cleared'); } - // [End clearPeriodicUpdates] // Shutdown live view components this.liveViewController.closeLiveView(); - // [Start stopBackgroundRunning] // Stop background tasks try { backgroundTaskManager.stopBackgroundRunning(this.context).then(() => { - console.info("Operation stopBackgroundRunning succeeded"); + hilog.info(0x0000, TAG, '%{public}s', 'Operation stopBackgroundRunning succeeded'); }).catch((error: BusinessError) => { - console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`); + hilog.error(0x0000, TAG, '%{public}s', + `Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`); }); } catch (error) { - console.error(`Operation stopBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); + hilog.error(0x0000, TAG, '%{public}s', + `Operation stopBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); } - // [End stopBackgroundRunning] } - // [EndExclude startContinuousRunningTask] // Internal method to manage background tasks private startContinuousRunningTask() { // Configure WantAgent for background operation let wantAgentInfo: wantAgent.WantAgentInfo = { wants: [ { - bundleName: 'com.example.mapliveviewsample', - abilityName: 'EntryAbility' + bundleName: AppStorage.get('liveViewLockScreenBundleName'), + abilityName: 'LiveviewlockscreensampleAbility' } ], actionType: wantAgent.OperationType.START_ABILITY, @@ -163,5 +150,4 @@ 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/liveview/LiveViewExtAbility.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets similarity index 39% rename from entry/src/main/ets/liveview/LiveViewExtAbility.ets rename to liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets index ed753c1f8a24de4a1f79a4d66eaaa495087bf75d..d0f441f64c82c7a59e000bd57e232165b423a9e4 100644 --- a/entry/src/main/ets/liveview/LiveViewExtAbility.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets @@ -1,105 +1,71 @@ /* -* 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. -*/ + * 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. + */ -// [Start windowSizeListener] -import { AbilityConstant, UIExtensionContentSession, Want } from '@kit.AbilityKit'; -// [Start updateBreakPoint] + +import { bundleManager, UIExtensionContentSession } from '@kit.AbilityKit'; import { display, window } from '@kit.ArkUI'; -// [StartExclude updateBreakPoint] -// [StartExclude windowSizeListener] -// [Start subscribeCommonEvent] -import { BusinessError, commonEventManager } from '@kit.BasicServicesKit'; -// [StartExclude subscribeCommonEvent] -import { LiveViewLockScreenExtensionAbility } from '@kit.LiveViewKit'; +import { BreakpointTypeEnum } from './BreakpointSystem'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { Constants } from '../constant/Constant'; +import { BusinessError, commonEventManager } from '@kit.BasicServicesKit'; import { LaneData } from '../model/RouteDataModel'; -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; - private verticalBreakpoint: string = ''; - - // [EndExclude updateBreakPoint] - // Distinguish page layout using vertical breakpoints. - private updateBreakPoint(windowSize: window.Size): void { - try { - let windowWidthVp: number = windowSize.width / display.getDefaultDisplaySync().densityPixels; - let windowHeightVp: number = windowSize.height / display.getDefaultDisplaySync().densityPixels; - let windowRatio: number = windowWidthVp / windowHeightVp; - let verticalBreakpoint: string = Constants.BREAK_POINT_SM; - // Vertical breakpoints are distinguished by aspect ratio. - if (windowRatio < 0.8) { - verticalBreakpoint = Constants.BREAK_POINT_SM; - } else if (windowRatio > 1.2) { - verticalBreakpoint = Constants.BREAK_POINT_LG; - } else { - verticalBreakpoint = Constants.BREAK_POINT_MD; - } - if (this.verticalBreakpoint !== verticalBreakpoint) { - this.verticalBreakpoint = verticalBreakpoint; - AppStorage.setOrCreate('verticalBreakpoint', this.verticalBreakpoint); - } - hilog.info(0x0000, TAG, `updateBreakpoint ${verticalBreakpoint}`); - } catch (error) { - hilog.error(0x0000, TAG, `updateBreakpoint catch err:`, (error as BusinessError).message); - } - } - // [End updateBreakPoint] - - onCreate(_launchParam: AbilityConstant.LaunchParam): void { - hilog.info(0x0000, TAG, 'LiveViewLockScreenExtAbility onCreate begin.'); - } +const TAG: string = '[LiveViewExtAbilityUtil]'; - onForeground(): void { - hilog.info(0x0000, TAG, 'LiveViewLockScreenExtAbility onForeground begin.'); - } +export class LiveViewExtAbilityUtil { + // Singleton pattern implementation + private static instance: LiveViewExtAbilityUtil; + private subscriber: commonEventManager.CommonEventSubscriber | null; - onBackground(): void { - hilog.info(0x0000, TAG, 'LiveViewLockScreenExtAbility onBackground begin.'); + // Private constructor for singleton pattern + private constructor() { + this.subscriber = null; } - onDestroy(): void | Promise { - hilog.info(0x0000, TAG, 'LiveViewLockScreenExtAbility onDestroy begin.'); + // Singleton accessor method + public static getInstance(): LiveViewExtAbilityUtil { + // Lazy initialization of the singleton instance + if (!LiveViewExtAbilityUtil.instance) { + LiveViewExtAbilityUtil.instance = new LiveViewExtAbilityUtil(); + } + return LiveViewExtAbilityUtil.instance; } - // [Start createLiveView] - // Core logic when creating UI session. - onSessionCreate(_want: Want, session: UIExtensionContentSession): void { - // [StartExclude createLiveView] - hilog.info(0x0000, TAG, 'LiveViewLockScreenExtAbility onSessionCreate begin.'); - let param: Record = { - 'session': session - }; - // [EndExclude windowSizeListener] + public setSession(session: UIExtensionContentSession): void { // Window size listener. const extensionWindow = session.getUIExtensionWindowProxy(); extensionWindow.on('windowSizeChange', (windowSize: window.Size) => { - this.updateBreakPoint(windowSize); + LiveViewExtAbilityUtil.updateBreakPoint(windowSize); }); - // [End windowSizeListener] - // [EndExclude subscribeCommonEvent] - // Create state storage (for cross-page data sharing). - let storage: LocalStorage = new LocalStorage(param); + // 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 subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { events: ['live_view_lock_screen'], - publisherBundleName: 'com.example.mapliveviewsample', + publisherBundleName: bundleName, priority: 0 }; commonEventManager.createSubscriber(subscribeInfo, @@ -122,27 +88,41 @@ 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('liveViewLockScreenLaneData', laneData); hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in receive commonEvent.'); } }); }) - // [End subscribeCommonEvent] - // [EndExclude createLiveView] - session.loadContent('liveview/LockScreenPage', storage); + session.loadContent('pages/LockScreen'); } - // [End createLiveView] + // Distinguish page layout using vertical breakpoints. + private static updateBreakPoint(windowSize: window.Size): void { + try { + let windowWidthVp: number = windowSize.width / display.getDefaultDisplaySync().densityPixels; + let windowHeightVp: number = windowSize.height / display.getDefaultDisplaySync().densityPixels; + let windowRatio: number = windowWidthVp / windowHeightVp; + let currentHeightBreakpoint: string = BreakpointTypeEnum.SM; + // Vertical breakpoints are distinguished by aspect ratio. + if (windowRatio < 0.8) { + currentHeightBreakpoint = BreakpointTypeEnum.SM; + } else if (windowRatio > 1.2) { + currentHeightBreakpoint = BreakpointTypeEnum.LG; + } else { + currentHeightBreakpoint = BreakpointTypeEnum.MD; + } + AppStorage.setOrCreate('liveViewLockScreenCurrentHeightBreakpoint', currentHeightBreakpoint); + hilog.info(0x0000, TAG, '%{public}s', 'updateBreakpoint'); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `updateBreakpoint catch. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`) + ; + } + } - // Cleanup operations when destroying UI session - onSessionDestroy(): void { + public destroySubscribe(): void { commonEventManager.unsubscribe(this.subscriber, () => { this.subscriber = null; }); - hilog.info(0x0000, TAG, 'LiveViewLockScreenExtAbility onSessionDestroy begin.'); - } - - onConfigurationUpdate(): void { - hilog.info(0x0000, TAG, 'LiveViewLockScreenExtAbility onConfigurationUpdate begin.'); } } \ No newline at end of file diff --git a/entry/src/main/ets/utils/LiveViewUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets similarity index 95% rename from entry/src/main/ets/utils/LiveViewUtil.ets rename to liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets index 1616ebb8a76f2ffbafb04720dddeb21924e8991d..bca604d42507fa55cf9ce3a7b128fb81217bdeb0 100644 --- a/entry/src/main/ets/utils/LiveViewUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets @@ -15,11 +15,9 @@ import { application, Want, wantAgent } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; -// [Start createLiveView] import { liveViewManager } from '@kit.LiveViewKit'; -// [StartExclude createLiveView] -import { RouteData } from '../model/RouteDataModel'; import { hilog } from '@kit.PerformanceAnalysisKit'; +import { RouteData } from '../model/RouteDataModel'; const TAG: string = '[LiveViewUtil]'; @@ -54,13 +52,12 @@ export class LiveViewUtil { } return true; } catch (error) { - hilog.error(0x0000, TAG, + hilog.error(0x0000, TAG, '%{public}s', `Failed to update live view. Cause code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}`); return false; } } - // [Start closeLiveView] // Close live view. public async closeLiveView() { // Ensure that the sequence is greater than the current live window page. @@ -76,7 +73,6 @@ export class LiveViewUtil { }); return; } - // [End closeLiveView] private static async isLiveViewEnabled(): Promise { return await liveViewManager.isLiveViewEnabled(); @@ -119,7 +115,6 @@ export class LiveViewUtil { } private async createPrimaryLiveVie(): Promise { - // [EndExclude createLiveView] // Construct live window request body. let liveView: liveViewManager.LiveView = { id: 0, @@ -147,15 +142,14 @@ export class LiveViewUtil { } } }; - // [End createLiveView] return liveView; } private static async buildWantAgent(): Promise { const wantAgentInfo: wantAgent.WantAgentInfo = { wants: [{ - bundleName: 'com.example.mapliveviewsample', - abilityName: 'EntryAbility' + bundleName: AppStorage.get('liveViewLockScreenBundleName'), + abilityName: 'LiveviewlockscreensampleAbility' } as Want], actionType: wantAgent.OperationType.START_ABILITIES, requestCode: 0, diff --git a/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets new file mode 100644 index 0000000000000000000000000000000000000000..5b756a6c5ddf983f39b1bf0250d0ad4d8097ee21 --- /dev/null +++ b/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets @@ -0,0 +1,71 @@ +/* + * 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 type { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +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}`); + }); + + 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 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); + }) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/view/RoadView.ets b/liveviewlockscreenlibrary/src/main/ets/view/RoadView.ets similarity index 95% rename from entry/src/main/ets/view/RoadView.ets rename to liveviewlockscreenlibrary/src/main/ets/view/RoadView.ets index dd5bec6163df874ccb185da4ef12353c5dcee5aa..8f6c76ff2dd02a8ac6344b6060896cd77fa1ea02 100644 --- a/entry/src/main/ets/view/RoadView.ets +++ b/liveviewlockscreenlibrary/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/liveviewlockscreenlibrary/src/main/ets/view/TrafficInfoView.ets b/liveviewlockscreenlibrary/src/main/ets/view/TrafficInfoView.ets new file mode 100644 index 0000000000000000000000000000000000000000..c68869306caa34b08f7d4e6f09068f558d746e6a --- /dev/null +++ b/liveviewlockscreenlibrary/src/main/ets/view/TrafficInfoView.ets @@ -0,0 +1,115 @@ +/* + * 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 { promptAction } from '@kit.ArkUI'; +import { LiveView } from '../utils/LiveView' + +@Component +export struct TrafficInfoView { + @State private isShowButton: boolean = false; + + build() { + Row() { + 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() { + 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(this.getUIContext().getHostContext()).createLiveView(); + this.getUIContext().getPromptAction().showToast({ + message: $r('app.string.toast'), + duration: 2000, + showMode: promptAction.ToastShowMode.DEFAULT, + bottom: 180 + }); + }) + 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(this.getUIContext().getHostContext()).finishLiveView(); + this.getUIContext().getPromptAction().showToast({ + message: $r('app.string.toast'), + duration: 2000, + showMode: promptAction.ToastShowMode.DEFAULT, + bottom: 180 + }); + }) + Blank() + } + .margin({ + top: 6, + }) + .width('100%') + } + } + .width('100%') + } +} \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/main/ets/view/TrafficView.ets b/liveviewlockscreenlibrary/src/main/ets/view/TrafficView.ets new file mode 100644 index 0000000000000000000000000000000000000000..07b2be912fcddab03e02eeb0d87fda5dedbb6968 --- /dev/null +++ b/liveviewlockscreenlibrary/src/main/ets/view/TrafficView.ets @@ -0,0 +1,346 @@ +/* + * 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 { 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; + @Prop lane: number = 2; + private uiContext: UIContext = this.getUIContext(); + private updateInterval: number | undefined; + + aboutToAppear(): void { + this.updateInterval = setInterval(() => { + if (this.lane === 2) { + this.lane = 1; + } else { + this.lane = 2; + } + }, 2000) + } + + aboutToDisappear(): void { + if (this.updateInterval !== undefined) { + clearInterval(this.updateInterval); + this.updateInterval = undefined; + } + } + + build() { + if (this.currentWidthBreakpoint !== BreakpointTypeEnum.SM || + this.currentHeightBreakpoint !== BreakpointTypeEnum.MD) { + Column() { + Row() { + Column() { + Column() { + Row() { + Image($r('app.media.big_arrow')) + .objectFit(ImageFit.Contain) + .height(new BreakpointType({ sm: 80, md: 70, lg: 70, }).getValue(this.currentWidthBreakpoint)) + 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({ sm: 0, md: 16, lg: 16, }).getValue(this.currentWidthBreakpoint), + topRight: new BreakpointType({ sm: 0, md: 16, lg: 16, }).getValue(this.currentWidthBreakpoint), + }) + .backgroundColor($r('app.color.Index_background_first')) + .width(new BreakpointType({ sm: '100%', md: '50%', lg: '30%', }).getValue(this.currentWidthBreakpoint)) + .padding({ + bottom: $r('sys.float.padding_level8'), + top: new BreakpointType({ + sm: $r('sys.float.padding_level16'), + md: $r('sys.float.padding_level0'), + lg: $r('sys.float.padding_level0'), + }).getValue(this.currentWidthBreakpoint), + left: new BreakpointType({ + sm: $r('sys.float.padding_level8'), + md: $r('sys.float.padding_level12'), + lg: $r('sys.float.padding_level16'), + }).getValue(this.currentWidthBreakpoint), + }) + + 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(25) + } + .borderRadius({ + bottomLeft: new BreakpointType({ sm: 0, md: 16, lg: 16, }).getValue(this.currentWidthBreakpoint), + bottomRight: new BreakpointType({ sm: 0, md: 16, lg: 16, }).getValue(this.currentWidthBreakpoint), + }) + .padding({ + bottom: $r('sys.float.padding_level2'), + top: $r('sys.float.padding_level2'), + }) + .width(new BreakpointType({ sm: '100%', md: '50%', lg: '30%', }).getValue(this.currentWidthBreakpoint)) + .backgroundColor($r('app.color.Index_background_second')) + + if (this.currentWidthBreakpoint !== BreakpointTypeEnum.SM) { + Image($r('app.media.traffic_info_speed')) + .objectFit(ImageFit.Contain) + .height(80) + .position({ + top: 0, + left: this.currentWidthBreakpoint === BreakpointTypeEnum.MD ? '51%' : '31%', + }) + } + } + + Row() { + if (this.currentWidthBreakpoint === BreakpointTypeEnum.SM) { + Image($r('app.media.traffic_info_speed')) + .objectFit(ImageFit.Contain) + .height(70) + } + Image($r('app.media.traffic_info_label')) + .objectFit(ImageFit.Contain) + .height(new BreakpointType({ sm: 70, md: 80, lg: 80, }).getValue(this.currentWidthBreakpoint)) + } + .width(new BreakpointType({ sm: '100%', md: '40%', lg: '30%', }).getValue(this.currentWidthBreakpoint)) + } + .margin({ + left: new BreakpointType({ + sm: $r('sys.float.padding_level0'), + md: $r('sys.float.padding_level12'), + lg: $r('sys.float.padding_level16'), + }).getValue(this.currentWidthBreakpoint), + top: new BreakpointType({ + sm: $r('sys.float.padding_level0'), + md: $r('sys.float.padding_level16'), + lg: $r('sys.float.padding_level16'), + }).getValue(this.currentWidthBreakpoint), + }) + } + .width('100%') + .justifyContent(FlexAlign.Start) + + Blank() + + Row() { + Stack({ alignContent: Alignment.Top }) { + if (this.lane === 2) { + Image($r('app.media.traffic_right')) + .width(new BreakpointType({ sm: '70%', md: '50%', lg: '30%', }).getValue(this.currentWidthBreakpoint)) + } else { + Image($r('app.media.traffic_left')) + .width(new BreakpointType({ sm: '70%', md: '50%', lg: '30%', }).getValue(this.currentWidthBreakpoint)) + } + + Image($rawfile('traffic_light.svg')) + .objectFit(ImageFit.Contain) + .width(new BreakpointType({ sm: '20%', md: '15%', lg: '10%', }).getValue(this.currentWidthBreakpoint)) + .position({ + left: '70%', + top: 30 + }) + } + .width('100%') + } + + Blank() + 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({ sm: '100%', md: '300vp', lg: '360vp', }).getValue(this.currentWidthBreakpoint)) + .borderColor($r('sys.color.comp_divider')) + .borderRadius({ + topLeft: $r('sys.float.corner_radius_level12'), + topRight: $r('sys.float.corner_radius_level12'), + bottomLeft: new BreakpointType({ + sm: $r('sys.float.padding_level0'), + md: $r('sys.float.corner_radius_level12'), + lg: $r('sys.float.corner_radius_level12'), + }).getValue(this.currentWidthBreakpoint), + bottomRight: new BreakpointType({ + sm: $r('sys.float.padding_level0'), + md: $r('sys.float.corner_radius_level12'), + lg: $r('sys.float.corner_radius_level12'), + }).getValue(this.currentWidthBreakpoint), + }) + .backgroundColor($r('app.color.traffic_info_background_color')) + .shadow(ShadowStyle.OUTER_DEFAULT_XS) + .position({ + bottom: 0, + left: new BreakpointType({ + sm: $r('sys.float.padding_level0'), + md: $r('sys.float.corner_radius_level12'), + lg: $r('sys.float.corner_radius_level16'), + }).getValue(this.currentWidthBreakpoint), + }) + .padding({ + bottom: new BreakpointType({ + sm: this.uiContext.px2vp(this.bottomRectHeight), + md: 0, + lg: 0, + }).getValue(this.currentWidthBreakpoint), + }) + .margin({ + bottom: new BreakpointType({ + sm: 0, + md: this.uiContext.px2vp(this.bottomRectHeight), + lg: this.uiContext.px2vp(this.bottomRectHeight), + }).getValue(this.currentWidthBreakpoint), + }) + } + .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) + .height(70) + .position({ + top: 16, + left: 16, + }) + + if (this.lane === 2) { + Image($r('app.media.traffic_right')) + .width('60%') + .offset({ + y: 15, + }) + } else { + Image($r('app.media.traffic_left')) + .width('60%') + .offset({ + y: 15, + }) + } + + Column() { + Image($r('app.media.turn_right_light_rectangle')) + .objectFit(ImageFit.Contain) + .width(40) + .height(25) + .margin({ + top: 8, + }) + + 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, + }) + } + .justifyContent(FlexAlign.Center) + .borderRadius(16) + .backgroundColor($r('sys.color.ohos_id_blur_style_component_thick_color')) + .position({ + top: 16, + right: 16 + }) + } + .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({ sm: '100%', md: '300vp', lg: '360vp', }).getValue(this.currentWidthBreakpoint)) + .borderColor($r('sys.color.comp_divider')) + .borderRadius({ + 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%') + } + .height('100%') + } + } +} \ No newline at end of file diff --git a/entry/src/main/ets/viewmodel/RouteDataViewModel.ets b/liveviewlockscreenlibrary/src/main/ets/viewmodel/RouteDataViewModel.ets similarity index 100% rename from entry/src/main/ets/viewmodel/RouteDataViewModel.ets rename to liveviewlockscreenlibrary/src/main/ets/viewmodel/RouteDataViewModel.ets diff --git a/liveviewlockscreenlibrary/src/main/module.json5 b/liveviewlockscreenlibrary/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..177ddf3161339cb9d2a0c00d837a9679eeece759 --- /dev/null +++ b/liveviewlockscreenlibrary/src/main/module.json5 @@ -0,0 +1,11 @@ +{ + "module": { + "name": "liveviewlockscreenlibrary", + "type": "har", + "deviceTypes": [ + "default", + "tablet", + "2in1" + ] + } +} diff --git a/entry/src/main/resources/base/element/color.json b/liveviewlockscreenlibrary/src/main/resources/base/element/color.json similarity index 36% rename from entry/src/main/resources/base/element/color.json rename to liveviewlockscreenlibrary/src/main/resources/base/element/color.json index a332bbb548865c29565271458a0bf38f4de1ed11..4ed1297740ee47753074ba509f9b1f40bddfb7d4 100644 --- a/entry/src/main/resources/base/element/color.json +++ b/liveviewlockscreenlibrary/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/liveviewlockscreenlibrary/src/main/resources/base/element/string.json similarity index 60% rename from entry/src/main/resources/base/element/string.json rename to liveviewlockscreenlibrary/src/main/resources/base/element/string.json index 2a8552a445951c53c36427e3ef102a121c270495..aa9d46ca0d04a5a5cdc85f6bbeabf3f4378e1010 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/liveviewlockscreenlibrary/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,30 @@ { "name": "then", "value": "然后" + }, + { + "name": "Continue", + "value": "继续导航" + }, + { + "name": "Finish", + "value": "停止导航" + }, + { + "name": "tip", + "value": "提示" + }, + { + "name": "tip_text", + "value": " 本案例已完成Pura X内外屏适配和实况窗功能开发,因涉及权限申请,仅做UI展示,具体开发请参考示例代码。" + }, + { + "name": "tip_get", + "value": "知道了" + }, + { + "name": "toast", + "value": "仅做功能原型展示,具体业务需自行实现。" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/base/media/big_arrow.png b/liveviewlockscreenlibrary/src/main/resources/base/media/big_arrow.png similarity index 100% rename from entry/src/main/resources/base/media/big_arrow.png rename to liveviewlockscreenlibrary/src/main/resources/base/media/big_arrow.png diff --git a/entry/src/main/resources/base/media/little_arrow.png b/liveviewlockscreenlibrary/src/main/resources/base/media/little_arrow.png similarity index 100% rename from entry/src/main/resources/base/media/little_arrow.png rename to liveviewlockscreenlibrary/src/main/resources/base/media/little_arrow.png diff --git a/entry/src/main/resources/base/media/traffic_background.png b/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_background.png similarity index 100% rename from entry/src/main/resources/base/media/traffic_background.png rename to liveviewlockscreenlibrary/src/main/resources/base/media/traffic_background.png diff --git a/entry/src/main/resources/base/media/traffic_info_label.png b/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_info_label.png similarity index 100% rename from entry/src/main/resources/base/media/traffic_info_label.png rename to liveviewlockscreenlibrary/src/main/resources/base/media/traffic_info_label.png diff --git a/entry/src/main/resources/base/media/traffic_info_speed.png b/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_info_speed.png similarity index 100% rename from entry/src/main/resources/base/media/traffic_info_speed.png rename to liveviewlockscreenlibrary/src/main/resources/base/media/traffic_info_speed.png diff --git a/entry/src/main/resources/base/media/traffic_left.png b/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_left.png similarity index 100% rename from entry/src/main/resources/base/media/traffic_left.png rename to liveviewlockscreenlibrary/src/main/resources/base/media/traffic_left.png diff --git a/entry/src/main/resources/base/media/traffic_light.svg b/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_light.svg similarity index 100% rename from entry/src/main/resources/base/media/traffic_light.svg rename to liveviewlockscreenlibrary/src/main/resources/base/media/traffic_light.svg diff --git a/entry/src/main/resources/base/media/traffic_right.png b/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_right.png similarity index 100% rename from entry/src/main/resources/base/media/traffic_right.png rename to liveviewlockscreenlibrary/src/main/resources/base/media/traffic_right.png diff --git a/liveviewlockscreenlibrary/src/main/resources/base/media/turn_right_light_rectangle.png b/liveviewlockscreenlibrary/src/main/resources/base/media/turn_right_light_rectangle.png new file mode 100644 index 0000000000000000000000000000000000000000..cd3bbc2f67d07b8f898d5fc777fe07e64fa8a247 Binary files /dev/null and b/liveviewlockscreenlibrary/src/main/resources/base/media/turn_right_light_rectangle.png differ diff --git a/entry/src/main/resources/dark/element/color.json b/liveviewlockscreenlibrary/src/main/resources/dark/element/color.json similarity index 39% rename from entry/src/main/resources/dark/element/color.json rename to liveviewlockscreenlibrary/src/main/resources/dark/element/color.json index 682f571ff1addde0e6bdf7a19820485847e81f09..79b11c2747aec33e710fd3a7b2b3c94dd9965499 100644 --- a/entry/src/main/resources/dark/element/color.json +++ b/liveviewlockscreenlibrary/src/main/resources/dark/element/color.json @@ -3,14 +3,6 @@ { "name": "start_window_background", "value": "#000000" - }, - { - "name": "xmark_foreground", - "value": "#E5FFFFFF" - }, - { - "name": "xmark_background", - "value": "#19FFFFFF" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/en_US/element/string.json b/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json similarity index 64% rename from entry/src/main/resources/en_US/element/string.json rename to liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json index 9eacc46fabe45623c5c8ec6c6ac36b0bf1a29d97..4d1556f1a8880625f4c04d873422a73eedf127c9 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json @@ -20,6 +20,14 @@ "name": "traffic_info_meter", "value": "800 meters" }, + { + "name": "traffic_info_smmd_first", + "value": "Turn right" + }, + { + "name": "traffic_info_smmd_second", + "value": "after 800m" + }, { "name": "traffic_info_first", "value": "1 hour 24 minutes" @@ -54,7 +62,7 @@ }, { "name": "live_view_primary_title_second", - "value": " meters" + "value": " m" }, { "name": "road_name", @@ -63,6 +71,30 @@ { "name": "then", "value": "Then" + }, + { + "name": "Continue", + "value": "Continue" + }, + { + "name": "Finish", + "value": "Finish" + }, + { + "name": "tip", + "value": "Tip" + }, + { + "name": "tip_text", + "value": "Permission is required to experience the lock screen immersive live window" + }, + { + "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/rawfile/traffic_light.svg b/liveviewlockscreenlibrary/src/main/resources/rawfile/traffic_light.svg similarity index 100% rename from entry/src/main/resources/rawfile/traffic_light.svg rename to liveviewlockscreenlibrary/src/main/resources/rawfile/traffic_light.svg diff --git a/entry/src/main/resources/rawfile/turn_right_dark_rectangle.png b/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_dark_rectangle.png similarity index 100% rename from entry/src/main/resources/rawfile/turn_right_dark_rectangle.png rename to liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_dark_rectangle.png diff --git a/entry/src/main/resources/rawfile/turn_right_light_rectangle.png b/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_light_rectangle.png similarity index 100% rename from entry/src/main/resources/rawfile/turn_right_light_rectangle.png rename to liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_light_rectangle.png diff --git a/entry/src/main/resources/rawfile/turn_right_light_square.png b/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_light_square.png similarity index 100% rename from entry/src/main/resources/rawfile/turn_right_light_square.png rename to liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_light_square.png diff --git a/entry/src/main/resources/rawfile/turn_straight_dark_rectangle.png b/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_straight_dark_rectangle.png similarity index 100% rename from entry/src/main/resources/rawfile/turn_straight_dark_rectangle.png rename to liveviewlockscreenlibrary/src/main/resources/rawfile/turn_straight_dark_rectangle.png diff --git a/entry/src/main/resources/rawfile/turn_straight_light_rectangle.png b/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_straight_light_rectangle.png similarity index 100% rename from entry/src/main/resources/rawfile/turn_straight_light_rectangle.png rename to liveviewlockscreenlibrary/src/main/resources/rawfile/turn_straight_light_rectangle.png diff --git a/entry/src/main/resources/zh_CN/element/string.json b/liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json similarity index 60% rename from entry/src/main/resources/zh_CN/element/string.json rename to liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json index 2a8552a445951c53c36427e3ef102a121c270495..aa9d46ca0d04a5a5cdc85f6bbeabf3f4378e1010 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/liveviewlockscreenlibrary/src/main/resources/zh_CN/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,30 @@ { "name": "then", "value": "然后" + }, + { + "name": "Continue", + "value": "继续导航" + }, + { + "name": "Finish", + "value": "停止导航" + }, + { + "name": "tip", + "value": "提示" + }, + { + "name": "tip_text", + "value": " 本案例已完成Pura X内外屏适配和实况窗功能开发,因涉及权限申请,仅做UI展示,具体开发请参考示例代码。" + }, + { + "name": "tip_get", + "value": "知道了" + }, + { + "name": "toast", + "value": "仅做功能原型展示,具体业务需自行实现。" } ] } \ No newline at end of file diff --git a/entry/build-profile.json5 b/liveviewlockscreensample/build-profile.json5 similarity index 90% rename from entry/build-profile.json5 rename to liveviewlockscreensample/build-profile.json5 index b695582d3680556f4cce2ec518f65720a9413ca3..808380f3b726e2036a3d6cf5fb9b0fd9513a8215 100644 --- a/entry/build-profile.json5 +++ b/liveviewlockscreensample/build-profile.json5 @@ -20,9 +20,6 @@ "targets": [ { "name": "default" - }, - { - "name": "ohosTest", } ] } \ No newline at end of file diff --git a/entry/hvigorfile.ts b/liveviewlockscreensample/hvigorfile.ts similarity index 100% rename from entry/hvigorfile.ts rename to liveviewlockscreensample/hvigorfile.ts diff --git a/liveviewlockscreensample/obfuscation-rules.txt b/liveviewlockscreensample/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/liveviewlockscreensample/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/liveviewlockscreensample/oh-package-lock.json5 b/liveviewlockscreensample/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0246ee2f885578d27fa3f93669b2d81e875c4fae --- /dev/null +++ b/liveviewlockscreensample/oh-package-lock.json5 @@ -0,0 +1,19 @@ +{ + "meta": { + "stableOrder": true, + "enableUnifiedLockfile": false + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "liveviewlockscreenlibrary@../liveviewlockscreenlibrary": "liveviewlockscreenlibrary@../liveviewlockscreenlibrary" + }, + "packages": { + "liveviewlockscreenlibrary@../liveviewlockscreenlibrary": { + "name": "liveviewlockscreenlibrary", + "version": "1.0.0", + "resolved": "../liveviewlockscreenlibrary", + "registryType": "local" + } + } +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh-package.json5 b/liveviewlockscreensample/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d1077b32ab36f3afdd14d29664f054fc38a8d963 --- /dev/null +++ b/liveviewlockscreensample/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "liveviewlockscreensample", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "liveviewlockscreenlibrary": "file:../liveviewlockscreenlibrary" + } +} \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets similarity index 37% rename from entry/src/main/ets/entryability/EntryAbility.ets rename to liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets index d95a8a6e548bd2dd95bedcac11e6cce59d4f619b..438ac2c685920cca7bef408b35c6979e5d8d693e 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets @@ -14,53 +14,16 @@ */ import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; -import { display, window } from '@kit.ArkUI'; -import { BusinessError } from '@kit.BasicServicesKit'; +import { window } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { Constants } from '../constant/Constant'; +import { BundleNameUtil, WindowUtil } from 'liveviewlockscreenlibrary' const TAG: string = '[EntryAbility]'; export default class EntryAbility extends UIAbility { - private horizontalBreakpoint: string = ''; - private verticalBreakpoint: string = ''; - - private updateBreakpoint(windowSize: window.Size): void { - try { - let windowWidthVp: number = windowSize.width / display.getDefaultDisplaySync().densityPixels; - let windowHeightVp: number = windowSize.height / display.getDefaultDisplaySync().densityPixels; - let windowRatio: number = windowWidthVp / windowHeightVp; - let horizontalBreakpoint: string = ''; - let verticalBreakpoint: string = ''; - if (windowWidthVp < 600) { - horizontalBreakpoint = Constants.BREAK_POINT_SM; - } else if (windowWidthVp < 840) { - horizontalBreakpoint = Constants.BREAK_POINT_MD; - } else { - horizontalBreakpoint = Constants.BREAK_POINT_LG; - } - if (this.horizontalBreakpoint !== horizontalBreakpoint) { - this.horizontalBreakpoint = horizontalBreakpoint; - AppStorage.setOrCreate('horizontalBreakpoint', this.horizontalBreakpoint); - } - if (windowRatio < 0.8) { - verticalBreakpoint = Constants.BREAK_POINT_SM; - } else if (windowRatio > 1.2) { - verticalBreakpoint = Constants.BREAK_POINT_LG; - } else { - verticalBreakpoint = Constants.BREAK_POINT_MD; - } - if (this.verticalBreakpoint !== verticalBreakpoint) { - this.verticalBreakpoint = verticalBreakpoint; - AppStorage.setOrCreate('verticalBreakpoint', this.verticalBreakpoint); - } - } catch (error) { - hilog.error(0x0000, TAG, `updateBreakpoint catch err:`, (error as BusinessError).message); - } - } - onCreate(): void { this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + BundleNameUtil.getBundleName(); hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); } @@ -71,38 +34,15 @@ export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageCreate'); - windowStage.getMainWindow().then((windowObj: window.Window) => { - try { - windowObj.on('windowSizeChange', (windowSize) => { - this.updateBreakpoint(windowSize); - }); - - windowObj.setWindowSystemBarProperties({ - statusBarContentColor: '#ffffff', - }).then(() => { - hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in setting the system bar properties.'); - }).catch((err: BusinessError) => { - hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. Cause:', err.message); - }); - - windowObj.setWindowLayoutFullScreen(true).then(() => { - hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in setting the window layout to full-screen mode'); - }).catch((err: BusinessError) => { - hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. Cause:', err.message); - }); - } catch (error) { + windowStage.loadContent('pages/Index', (error) => { + if (error.code) { hilog.error(0x0000, TAG, '%{public}s', - `onWindowStageCreate failed. Cause code: ${error.code}, message: ${error.message}`); - } - }).catch((err: BusinessError) => { - hilog.error(0x0000, TAG, `Failed to get main window. Cause:`, err.message); - }); - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(0x0000, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + `Failed to load the content. Cause code: ${error.code}, message: ${error.message}`); return; } - hilog.info(0x0000, TAG, 'Succeeded in loading the content.'); + WindowUtil.requestFullScreen(windowStage); + WindowUtil.registerBreakPoint(windowStage); + hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in loading the content.'); }); } diff --git a/liveviewlockscreensample/src/main/ets/liveview/LiveViewExtAbility.ets b/liveviewlockscreensample/src/main/ets/liveview/LiveViewExtAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..34340aff8f6b3a3c6ea9a707db009b4f5573e5b9 --- /dev/null +++ b/liveviewlockscreensample/src/main/ets/liveview/LiveViewExtAbility.ets @@ -0,0 +1,60 @@ +/* +* 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 { 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'; + +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.'); + } + + onForeground(): void { + hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onForeground begin.'); + } + + onBackground(): void { + hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onBackground begin.'); + } + + onDestroy(): void | Promise { + hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onDestroy begin.'); + } + + // 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); + } + + // Cleanup operations when destroying UI session + onSessionDestroy(): void { + LiveViewExtAbilityUtil.getInstance().destroySubscribe(); + hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onSessionDestroy begin.'); + } + + onConfigurationUpdate(): void { + hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onConfigurationUpdate begin.'); + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/liveviewlockscreensample/src/main/ets/pages/Index.ets similarity index 67% rename from entry/src/main/ets/pages/Index.ets rename to liveviewlockscreensample/src/main/ets/pages/Index.ets index 387c24af092a805fb6deddec51dac575d726c98c..99c28de999fd18a7a852b1d69395dd3b7e0dc6b7 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/liveviewlockscreensample/src/main/ets/pages/Index.ets @@ -13,24 +13,14 @@ * limitations under the License. */ -import { LiveView } from '../utils/LiveView'; -import { TrafficView } from '../view/TrafficView'; +import { LiveViewLockScreenPage } from 'liveviewlockscreenlibrary' @Entry @Component struct Index { - aboutToAppear(): void { - LiveView.getInstance().createLiveView(); - } - build() { Stack() { - Image($r('app.media.traffic_background')) - .width('110%') - .height('110%') - TrafficView() + LiveViewLockScreenPage() } - .width('100%') - .height('100%') } -} \ No newline at end of file +} diff --git a/entry/src/main/ets/utils/BreakpointUtil.ets b/liveviewlockscreensample/src/main/ets/pages/LockScreen.ets similarity index 52% rename from entry/src/main/ets/utils/BreakpointUtil.ets rename to liveviewlockscreensample/src/main/ets/pages/LockScreen.ets index 45751d306db3f8a8f49e065a8384793170a9cf80..9a31811ac4c78a9e50e2ecdebf54bec92bc88eba 100644 --- a/entry/src/main/ets/utils/BreakpointUtil.ets +++ b/liveviewlockscreensample/src/main/ets/pages/LockScreen.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 @@ -13,27 +13,13 @@ * limitations under the License. */ -import { Constants } from "../constant/Constant"; +import { LockScreenPage } from 'liveviewlockscreenlibrary' -export class BreakpointType { - private sm: T; - private md: T; - private lg: T; - - constructor(sm: T, md: T, lg: T) { - this.sm = sm; - this.md = md; - this.lg = lg; - } - - getValue(currentBreakpoint: string): T { - if (currentBreakpoint === Constants.BREAK_POINT_MD) { - return this.md; - } - if (currentBreakpoint === Constants.BREAK_POINT_LG) { - return this.lg; - } else { - return this.sm; +@Entry +struct LockScreen { + build() { + Stack() { + LockScreenPage() } } -} \ No newline at end of file +} diff --git a/entry/src/main/module.json5 b/liveviewlockscreensample/src/main/module.json5 similarity index 82% rename from entry/src/main/module.json5 rename to liveviewlockscreensample/src/main/module.json5 index 68b78dcf1af492ef04a3cce07a0966ad9d26c695..fca9f251ef7a501e5c91610ee798793572429b50 100644 --- a/entry/src/main/module.json5 +++ b/liveviewlockscreensample/src/main/module.json5 @@ -1,25 +1,27 @@ { "module": { - "name": "entry", - "type": "entry", + "name": "liveviewlockscreensample", + "type": "feature", "description": "$string:module_desc", "mainElement": "EntryAbility", "deviceTypes": [ "phone", + "tablet", + "2in1" ], "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", "abilities": [ { - "name": "EntryAbility", + "name": "LiveviewlockscreensampleAbility", "srcEntry": "./ets/entryability/EntryAbility.ets", "description": "$string:EntryAbility_desc", - "icon": "$media:layered_image", + "icon": "$media:startIcon", "label": "$string:EntryAbility_label", "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", - "exported": true, + "exported": false, "backgroundModes": [ 'location' ], @@ -35,7 +37,6 @@ ] } ], - // [Start addLiveViewLockScreenExtensionAbilityName] "extensionAbilities": [ { // Keep it consistent with LiveViewLockScreenExtensionAbility name in live view instance @@ -46,8 +47,6 @@ "exported": false } ], - // [End addLiveViewLockScreenExtensionAbilityName] - // [Start requestPermissions] "requestPermissions": [ { "name": "ohos.permission.KEEP_BACKGROUND_RUNNING", @@ -60,6 +59,5 @@ } }, ], - // [End requestPermissions] } } \ No newline at end of file diff --git a/entry/src/main/resources/base/media/startIcon.png b/liveviewlockscreensample/src/main/resources/base/media/startIcon.png similarity index 100% rename from entry/src/main/resources/base/media/startIcon.png rename to liveviewlockscreensample/src/main/resources/base/media/startIcon.png diff --git a/liveviewlockscreensample/src/main/resources/base/profile/main_pages.json b/liveviewlockscreensample/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..969d4a34698d8ead8cc85256c09ef4100b4a4f2a --- /dev/null +++ b/liveviewlockscreensample/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/Index", + "pages/LockScreen" + ] +}