diff --git a/liveviewlockscreenlibrary/BuildProfile.ets b/liveviewlockscreenlibrary/BuildProfile.ets new file mode 100644 index 0000000000000000000000000000000000000000..3a501e5ddee8ea6d28961648fc7dd314a5304bd4 --- /dev/null +++ b/liveviewlockscreenlibrary/BuildProfile.ets @@ -0,0 +1,17 @@ +/** + * Use these variables when you tailor your ArkTS code. They must be of the const type. + */ +export const HAR_VERSION = '1.0.0'; +export const BUILD_MODE_NAME = 'debug'; +export const DEBUG = true; +export const TARGET_NAME = 'default'; + +/** + * BuildProfile Class is used only for compatibility purposes. + */ +export default class BuildProfile { + static readonly HAR_VERSION = HAR_VERSION; + static readonly BUILD_MODE_NAME = BUILD_MODE_NAME; + static readonly DEBUG = DEBUG; + static readonly TARGET_NAME = TARGET_NAME; +} \ No newline at end of file diff --git a/liveviewlockscreenlibrary/Index.ets b/liveviewlockscreenlibrary/Index.ets index 42bf4161c271e1b14d42a7ab98c982acc9bc3592..a91d0a7d207c5d8fe9c7a6a70ee90a508dbd35e2 100644 --- a/liveviewlockscreenlibrary/Index.ets +++ b/liveviewlockscreenlibrary/Index.ets @@ -1 +1,11 @@ -export { MainPage } from './src/main/ets/components/MainPage'; +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/entry/src/main/ets/liveview/LockScreenPage.ets b/liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets similarity index 98% rename from entry/src/main/ets/liveview/LockScreenPage.ets rename to liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets index 08db47770c144991e72cef327c3bba744ce5df6e..702675d935ed4b7523a96e546e596cfc1e2036fa 100644 --- a/entry/src/main/ets/liveview/LockScreenPage.ets +++ b/liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets @@ -21,7 +21,7 @@ let storage: LocalStorage = LocalStorage.getShared(); @Entry(storage) @Component -struct Index { +export struct LockScreenPage { // [Start layoutBasedOnVerticalBreakpoint] @StorageLink('currentHeightBreakpoint') currentHeightBreakpoint: string = BreakpointTypeEnum.SM; @LocalStorageProp('laneData') roadInfo: LaneData | undefined = undefined; 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/entry/src/main/ets/pages/Index.ets b/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets similarity index 96% rename from entry/src/main/ets/pages/Index.ets rename to liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets index 68f5e3729d3f5a95ec3519c734ec153ea60432c2..ab190b2d80b8ee582a44bef321ec810cb02b2538 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets @@ -17,9 +17,8 @@ import { promptAction } from '@kit.ArkUI'; import { LiveView } from '../utils/LiveView'; import { TrafficView } from '../view/TrafficView'; -@Entry @Component -struct Index { +export struct LiveViewLockScreenPage { aboutToAppear(): void { LiveView.getInstance().createLiveView(); this.getUIContext().getPromptAction().showToast({ diff --git a/entry/src/main/ets/utils/BreakpointSystem.ets b/liveviewlockscreenlibrary/src/main/ets/utils/BreakpointSystem.ets similarity index 99% rename from entry/src/main/ets/utils/BreakpointSystem.ets rename to liveviewlockscreenlibrary/src/main/ets/utils/BreakpointSystem.ets index d9fc82a6644e2d8e38d8df603ac4e447489cc9db..67c4df7c1793b4649c2ffa3b4cd3e6b39e138099 100644 --- a/entry/src/main/ets/utils/BreakpointSystem.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/BreakpointSystem.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/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets new file mode 100644 index 0000000000000000000000000000000000000000..d23bf70fa6c91b7b789b89907adce0527f159501 --- /dev/null +++ b/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets @@ -0,0 +1,38 @@ +/* +* 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 { 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('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}`); + } + 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 99% rename from entry/src/main/ets/utils/LiveView.ets rename to liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets index be47d16e67c9896629023f82b3b6ddaf75402637..3af3b5c062b7424f6495191caeb7768bd46a642c 100644 --- a/entry/src/main/ets/utils/LiveView.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets @@ -22,7 +22,7 @@ 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]'; diff --git a/entry/src/main/ets/liveview/LiveViewExtAbility.ets b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets similarity index 50% rename from entry/src/main/ets/liveview/LiveViewExtAbility.ets rename to liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets index 995e46fadffb2756e6f2f426546a17acac5e9eb3..0c677d0b785c3a221d1f546d915812daaddac1e3 100644 --- a/entry/src/main/ets/liveview/LiveViewExtAbility.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets @@ -1,102 +1,40 @@ /* -* 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, bundleManager, 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 { BusinessError, commonEventManager } from '@kit.BasicServicesKit'; import { LaneData } from '../model/RouteDataModel'; -import { BreakpointTypeEnum } from '../utils/BreakpointSystem'; - -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 currentHeightBreakpoint: 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 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; - } - if (this.currentHeightBreakpoint !== currentHeightBreakpoint) { - this.currentHeightBreakpoint = currentHeightBreakpoint; - AppStorage.setOrCreate('currentHeightBreakpoint', this.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}`) - ; - } - } - - // [End updateBreakPoint] - - 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.'); - } +const TAG: string = '[LiveViewExtAbilityUtil]'; - onBackground(): void { - hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onBackground begin.'); - } - - onDestroy(): void | Promise { - hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onDestroy begin.'); - } - - // [Start createLiveView] - // Core logic when creating UI session. - onSessionCreate(_want: Want, session: UIExtensionContentSession): void { - // [StartExclude createLiveView] - hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onSessionCreate begin.'); +export class LiveViewExtAbilityUtil { + public static setSession(session: UIExtensionContentSession): void { let param: Record = { 'session': session }; - // [EndExclude windowSizeListener] + // 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. @@ -125,10 +63,10 @@ export default class LiveViewExtAbility extends LiveViewLockScreenExtensionAbili `Failed to create subscriber. code is ${error.code} message is ${error.message}.`); return; } - this.subscriber = data; + hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in creating subscriber.'); // Event handling logic. - commonEventManager.subscribe(this.subscriber, + commonEventManager.subscribe(data, async (error: BusinessError, data: commonEventManager.CommonEventData) => { if (error) { hilog.error(0x0000, TAG, '%{public}s', @@ -143,22 +81,30 @@ export default class LiveViewExtAbility extends LiveViewLockScreenExtensionAbili } }); }) - // [End subscribeCommonEvent] - // [EndExclude createLiveView] - session.loadContent('liveview/LockScreenPage', storage); + session.loadContent('pages/LockScreen', storage); } - // [End createLiveView] - - // Cleanup operations when destroying UI session - onSessionDestroy(): void { - commonEventManager.unsubscribe(this.subscriber, () => { - this.subscriber = null; - }); - hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onSessionDestroy begin.'); - } - - onConfigurationUpdate(): void { - hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onConfigurationUpdate begin.'); + // 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('currentHeightBreakpoint', 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}`) + ; + } } } \ 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 100% rename from entry/src/main/ets/utils/LiveViewUtil.ets rename to liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets diff --git a/entry/src/main/ets/utils/WindowUtil.ets b/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets similarity index 98% rename from entry/src/main/ets/utils/WindowUtil.ets rename to liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets index 21c5847cdb7e53e4cac3e68b5075dd2ef72e2e63..1d55016c3a841ba777c155d716551bc64b812011 100644 --- a/entry/src/main/ets/utils/WindowUtil.ets +++ b/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.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/liveviewlockscreenlibrary/src/main/ets/view/RoadView.ets similarity index 100% rename from entry/src/main/ets/view/RoadView.ets rename to liveviewlockscreenlibrary/src/main/ets/view/RoadView.ets diff --git a/entry/src/main/ets/view/TrafficInfoView.ets b/liveviewlockscreenlibrary/src/main/ets/view/TrafficInfoView.ets similarity index 100% rename from entry/src/main/ets/view/TrafficInfoView.ets rename to liveviewlockscreenlibrary/src/main/ets/view/TrafficInfoView.ets diff --git a/entry/src/main/ets/view/TrafficView.ets b/liveviewlockscreenlibrary/src/main/ets/view/TrafficView.ets similarity index 100% rename from entry/src/main/ets/view/TrafficView.ets rename to liveviewlockscreenlibrary/src/main/ets/view/TrafficView.ets 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/entry/src/main/resources/base/element/color.json b/liveviewlockscreenlibrary/src/main/resources/base/element/color.json similarity index 100% rename from entry/src/main/resources/base/element/color.json rename to liveviewlockscreenlibrary/src/main/resources/base/element/color.json diff --git a/liveviewlockscreenlibrary/src/main/resources/base/element/float.json b/liveviewlockscreenlibrary/src/main/resources/base/element/float.json deleted file mode 100644 index 33ea22304f9b1485b5f22d811023701b5d4e35b6..0000000000000000000000000000000000000000 --- a/liveviewlockscreenlibrary/src/main/resources/base/element/float.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "float": [ - { - "name": "page_text_font_size", - "value": "50fp" - } - ] -} diff --git a/liveviewlockscreenlibrary/src/main/resources/base/element/string.json b/liveviewlockscreenlibrary/src/main/resources/base/element/string.json index f51a9c8461a55f6312ef950344e3145b7f82d607..dda579115ab8bbbf50d5005b6c75990ad6ed046b 100644 --- a/liveviewlockscreenlibrary/src/main/resources/base/element/string.json +++ b/liveviewlockscreenlibrary/src/main/resources/base/element/string.json @@ -1,8 +1,88 @@ { "string": [ { - "name": "page_show", - "value": "page from package" + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "锁屏沉浸实况窗" + }, + { + "name": "reason_background", + "value": "Background operation to update the live view" + }, + { + "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 分钟" + }, + { + "name": "traffic_info_second", + "value": "72.6公里·09:32·" + }, + { + "name": "traffic_info_third", + "value": "3" + }, + { + "name": "live_view_title", + "value": "导航中" + }, + { + "name": "live_view_background", + "value": "#ff0959F8" + }, + { + "name": "live_view_content", + "value": "content" + }, + { + "name": "meter", + "value": "米" + }, + { + "name": "live_view_primary_title_first", + "value": "" + }, + { + "name": "live_view_primary_title_second", + "value": "米后右转" + }, + { + "name": "road_name", + "value": "翠湖东路" + }, + { + "name": "then", + "value": "然后" + }, + { + "name": "toast", + "value": "提醒:锁屏沉浸实况窗须申请相关权限才可体验" + }, + { + "name": "Continue", + "value": "继续导航" + }, + { + "name": "Finish", + "value": "停止导航" } ] -} +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/background.png b/liveviewlockscreenlibrary/src/main/resources/base/media/background.png similarity index 100% rename from entry/src/main/resources/base/media/background.png rename to liveviewlockscreenlibrary/src/main/resources/base/media/background.png 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/foreground.png b/liveviewlockscreenlibrary/src/main/resources/base/media/foreground.png similarity index 100% rename from entry/src/main/resources/base/media/foreground.png rename to liveviewlockscreenlibrary/src/main/resources/base/media/foreground.png diff --git a/entry/src/main/resources/base/media/layered_image.json b/liveviewlockscreenlibrary/src/main/resources/base/media/layered_image.json similarity index 100% rename from entry/src/main/resources/base/media/layered_image.json rename to liveviewlockscreenlibrary/src/main/resources/base/media/layered_image.json 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/startIcon.png b/liveviewlockscreenlibrary/src/main/resources/base/media/startIcon.png similarity index 100% rename from entry/src/main/resources/base/media/startIcon.png rename to liveviewlockscreenlibrary/src/main/resources/base/media/startIcon.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/entry/src/main/resources/base/media/turn_right_light_rectangle.png b/liveviewlockscreenlibrary/src/main/resources/base/media/turn_right_light_rectangle.png similarity index 100% rename from entry/src/main/resources/base/media/turn_right_light_rectangle.png rename to liveviewlockscreenlibrary/src/main/resources/base/media/turn_right_light_rectangle.png diff --git a/entry/src/main/resources/base/profile/backup_config.json b/liveviewlockscreenlibrary/src/main/resources/base/profile/backup_config.json similarity index 100% rename from entry/src/main/resources/base/profile/backup_config.json rename to liveviewlockscreenlibrary/src/main/resources/base/profile/backup_config.json diff --git a/entry/src/main/resources/base/profile/main_pages.json b/liveviewlockscreenlibrary/src/main/resources/base/profile/main_pages.json similarity index 58% rename from entry/src/main/resources/base/profile/main_pages.json rename to liveviewlockscreenlibrary/src/main/resources/base/profile/main_pages.json index 731cedf01ef9edcfa92e1a357b0f5f4b2794f305..57e28d0cbcd79a53608a89b24cd2259350608df3 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/liveviewlockscreenlibrary/src/main/resources/base/profile/main_pages.json @@ -1,6 +1,6 @@ { "src": [ "liveview/LockScreenPage", - "pages/Index" + "pages/LiveViewLockScreenPage" ] } diff --git a/entry/src/main/resources/dark/element/color.json b/liveviewlockscreenlibrary/src/main/resources/dark/element/color.json similarity index 100% rename from entry/src/main/resources/dark/element/color.json rename to liveviewlockscreenlibrary/src/main/resources/dark/element/color.json diff --git a/entry/src/main/resources/en_US/element/string.json b/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json similarity index 100% rename from entry/src/main/resources/en_US/element/string.json rename to liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json 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/base/element/string.json b/liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json similarity index 100% rename from entry/src/main/resources/base/element/string.json rename to liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json diff --git a/liveviewlockscreenlibrary/src/ohosTest/ets/test/Ability.test.ets b/liveviewlockscreenlibrary/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100644 index 85c78f67579d6e31b5f5aeea463e216b9b141048..0000000000000000000000000000000000000000 --- a/liveviewlockscreenlibrary/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,35 +0,0 @@ -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; - -export default function abilityTest() { - describe('ActsAbilityTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }) - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }) - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }) - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }) - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }) - }) -} \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/ohosTest/ets/test/List.test.ets b/liveviewlockscreenlibrary/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index 794c7dc4ed66bd98fa3865e07922906e2fcef545..0000000000000000000000000000000000000000 --- a/liveviewlockscreenlibrary/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,5 +0,0 @@ -import abilityTest from './Ability.test'; - -export default function testsuite() { - abilityTest(); -} \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/test/List.test.ets b/liveviewlockscreenlibrary/src/test/List.test.ets deleted file mode 100644 index bb5b5c3731e283dd507c847560ee59bde477bbc7..0000000000000000000000000000000000000000 --- a/liveviewlockscreenlibrary/src/test/List.test.ets +++ /dev/null @@ -1,5 +0,0 @@ -import localUnitTest from './LocalUnit.test'; - -export default function testsuite() { - localUnitTest(); -} \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/test/LocalUnit.test.ets b/liveviewlockscreenlibrary/src/test/LocalUnit.test.ets deleted file mode 100644 index 165fc1615ee8618b4cb6a622f144a9a707eee99f..0000000000000000000000000000000000000000 --- a/liveviewlockscreenlibrary/src/test/LocalUnit.test.ets +++ /dev/null @@ -1,33 +0,0 @@ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; - -export default function localUnitTest() { - describe('localUnitTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }); - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }); - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }); - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }); - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }); - }); -} \ No newline at end of file diff --git a/entry/build-profile.json5 b/liveviewlockscreensample/build-profile.json5 similarity index 100% rename from entry/build-profile.json5 rename to liveviewlockscreensample/build-profile.json5 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/entry/obfuscation-rules.txt b/liveviewlockscreensample/obfuscation-rules.txt similarity index 100% rename from entry/obfuscation-rules.txt rename to liveviewlockscreensample/obfuscation-rules.txt diff --git a/liveviewlockscreensample/oh-package-lock.json5 b/liveviewlockscreensample/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3142a4d186e58aeedd0e4cf7e662f76251746c1e --- /dev/null +++ b/liveviewlockscreensample/oh-package-lock.json5 @@ -0,0 +1,18 @@ +{ + "meta": { + "stableOrder": true + }, + "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/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/.gitignore b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/BuildProfile.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/BuildProfile.ets new file mode 100644 index 0000000000000000000000000000000000000000..3a501e5ddee8ea6d28961648fc7dd314a5304bd4 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/BuildProfile.ets @@ -0,0 +1,17 @@ +/** + * Use these variables when you tailor your ArkTS code. They must be of the const type. + */ +export const HAR_VERSION = '1.0.0'; +export const BUILD_MODE_NAME = 'debug'; +export const DEBUG = true; +export const TARGET_NAME = 'default'; + +/** + * BuildProfile Class is used only for compatibility purposes. + */ +export default class BuildProfile { + static readonly HAR_VERSION = HAR_VERSION; + static readonly BUILD_MODE_NAME = BUILD_MODE_NAME; + static readonly DEBUG = DEBUG; + static readonly TARGET_NAME = TARGET_NAME; +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/Index.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a91d0a7d207c5d8fe9c7a6a70ee90a508dbd35e2 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/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/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/build-profile.json5 b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e6773f9f5d76a66d6d19fddc9c6ddb3f5621d3b1 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/build-profile.json5 @@ -0,0 +1,31 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] +} diff --git a/entry/src/main/ets/utils/BundleNameUtil.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/consumer-rules.txt similarity index 100% rename from entry/src/main/ets/utils/BundleNameUtil.ets rename to liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/consumer-rules.txt diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/hvigorfile.ts b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..42187071482d292588ad40babeda74f7b8d97a23 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/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/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/obfuscation-rules.txt b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/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/entry/oh-package.json5 b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/oh-package.json5 similarity index 57% rename from entry/oh-package.json5 rename to liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/oh-package.json5 index 248c3b7541a589682a250f86a6d3ecf7414d2d6a..5487c70867e75e52d493bfb482a801be7c774da5 100644 --- a/entry/oh-package.json5 +++ b/liveviewlockscreensample/oh_modules/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/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..702675d935ed4b7523a96e546e596cfc1e2036fa --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/liveview/LockScreenPage.ets @@ -0,0 +1,47 @@ +/* +* 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 { LaneData } from '../model/RouteDataModel'; +import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem'; +import { RoadView } from '../view/RoadView'; + +let storage: LocalStorage = LocalStorage.getShared(); + +@Entry(storage) +@Component +export struct LockScreenPage { + // [Start layoutBasedOnVerticalBreakpoint] + @StorageLink('currentHeightBreakpoint') currentHeightBreakpoint: string = BreakpointTypeEnum.SM; + @LocalStorageProp('laneData') roadInfo: LaneData | undefined = undefined; + + build() { + Stack({ alignContent: Alignment.Top }) { + RoadView({ laneNum: this.roadInfo?.laneNum }) + + Image($rawfile('traffic_light.svg')) + .objectFit(ImageFit.Contain) + .width(80) + .position({ + // Layout based on vertical breakpoint. + 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/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/model/RouteDataModel.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/model/RouteDataModel.ets new file mode 100644 index 0000000000000000000000000000000000000000..2f5416898231e07b897c70bd6983fb12f5ca1ee1 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/model/RouteDataModel.ets @@ -0,0 +1,25 @@ +/* +* 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. +*/ + +export interface LaneData { + laneNum: number, +} + +export interface RouteData { + // route information + roadInfo: LaneData, + distance: number, + roadName: Resource, +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab190b2d80b8ee582a44bef321ec810cb02b2538 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/pages/LiveViewLockScreenPage.ets @@ -0,0 +1,42 @@ +/* + * 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'; +import { TrafficView } from '../view/TrafficView'; + +@Component +export struct LiveViewLockScreenPage { + aboutToAppear(): void { + LiveView.getInstance().createLiveView(); + this.getUIContext().getPromptAction().showToast({ + message: $r('app.string.toast'), + duration: 2000, + showMode: promptAction.ToastShowMode.DEFAULT, + bottom: 180 + }); + } + + 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/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/BreakpointSystem.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/BreakpointSystem.ets new file mode 100644 index 0000000000000000000000000000000000000000..67c4df7c1793b4649c2ffa3b4cd3e6b39e138099 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/BreakpointSystem.ets @@ -0,0 +1,146 @@ +/* + * 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() { + } + + public static getInstance(): BreakpointSystem { + if (!BreakpointSystem.instance) { + BreakpointSystem.instance = new BreakpointSystem(); + } + return BreakpointSystem.instance; + } + + public updateCurrentWidthBreakpoint(widthBreakpoint: BreakpointTypeEnum): void { + hilog.info(0x0000, TAG, '%{public}s', `widthBreakpoint 1: ${widthBreakpoint}`); + if (this.currentWidthBreakpoint !== widthBreakpoint) { + hilog.info(0x0000, TAG, '%{public}s', `widthBreakpoint 2: ${widthBreakpoint}`); + this.currentWidthBreakpoint = widthBreakpoint; + AppStorage.setOrCreate('currentWidthBreakpoint', this.currentWidthBreakpoint); + } + } + + public updateCurrentHeightBreakpoint(heightBreakpoint: BreakpointTypeEnum): void { + hilog.info(0x0000, TAG, '%{public}s', `heightBreakpoint 1: ${heightBreakpoint}`); + if (this.currentHeightBreakpoint !== heightBreakpoint) { + hilog.info(0x0000, TAG, '%{public}s', `heightBreakpoint 2: ${heightBreakpoint}`); + this.currentHeightBreakpoint = heightBreakpoint; + AppStorage.setOrCreate('currentHeightBreakpoint', this.currentHeightBreakpoint); + } + } + + public onWindowSizeChange(window: window.Window): void { + this.updateWidthHeightBp(window); + } + + 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 = px2vp(windowWidth); + const windowHeightVp = 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; + } + hilog.info(0x0000, TAG, '%{public}s', `widthBp: ${widthBp}`); + this.updateCurrentWidthBreakpoint(widthBp); + + if (windowRatio < 0.8) { + heightBp = BreakpointTypeEnum.SM; + } else if (windowRatio > 1.2) { + heightBp = BreakpointTypeEnum.LG; + } else { + heightBp = BreakpointTypeEnum.MD; + } + hilog.info(0x0000, TAG, '%{public}s', `heightBp: ${heightBp}`); + this.updateCurrentHeightBreakpoint(heightBp) + } catch (error) { + const err: BusinessError = error as BusinessError; + hilog.error(0x0000, TAG, `UpdateBreakpoint fail, error code: ${err.code}, message: ${err.message}`); + } + } +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets new file mode 100644 index 0000000000000000000000000000000000000000..d23bf70fa6c91b7b789b89907adce0527f159501 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/BundleNameUtil.ets @@ -0,0 +1,38 @@ +/* +* 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 { 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('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}`); + } + hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); + } +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets new file mode 100644 index 0000000000000000000000000000000000000000..3af3b5c062b7424f6495191caeb7768bd46a642c --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/LiveView.ets @@ -0,0 +1,168 @@ +/* + * 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. + */ + +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 './LiveViewUtil'; +import { getRouteData } from '../viewmodel/RouteDataViewModel'; + +const TAG: string = '[LiveView]'; + +export class LiveView { + // Singleton pattern implementation + private static instance: LiveView; + private context: Context; + private liveViewController: LiveViewUtil; + private updateInterval: number | undefined; + + // Private constructor for singleton pattern + private constructor() { + this.context = getContext(this); + this.liveViewController = new LiveViewUtil(); + } + + // Singleton accessor method + public static getInstance(): LiveView { + // Lazy initialization of the singleton instance + if (!LiveView.instance) { + LiveView.instance = new LiveView(); + } + return LiveView.instance; + } + + // Main entry point to start live view functionality + public createLiveView() { + // 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 + appManager.getRunningProcessInformation().then((data: Array) => { + 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: AppStorage.get('bundleName'), + parameters: { + 'roadData': routeInfo.roadInfo + } + }; + // Publish system event for lock screen updates + commonEventManager.publish('live_view_lock_screen', options, (error: BusinessError) => { + if (error) { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to publish commonEvent. code is ${error.code} message is ${error.message}`); + } else { + 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, '%{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"); + }).catch((error: BusinessError) => { + console.error(`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}`); + } + // [End stopBackgroundRunning] + } + + // [EndExclude startContinuousRunningTask] + // Internal method to manage background tasks + private startContinuousRunningTask() { + // Configure WantAgent for background operation + let wantAgentInfo: wantAgent.WantAgentInfo = { + wants: [ + { + bundleName: AppStorage.get('bundleName'), + abilityName: 'EntryAbility' + } + ], + actionType: wantAgent.OperationType.START_ABILITY, + requestCode: 0, + actionFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] + }; + + try { + // Acquire WantAgent for background operations + wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => { + try { + hilog.info(0x0000, TAG, '%{public}s', 'Operation startBackgroundRunning begin.'); + // 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}`); + }); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to Operation startBackgroundRunning. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); + } + }); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `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/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets new file mode 100644 index 0000000000000000000000000000000000000000..0c677d0b785c3a221d1f546d915812daaddac1e3 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewExtAbilityUtil.ets @@ -0,0 +1,110 @@ +/* + * 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 { 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 { LaneData } from '../model/RouteDataModel'; + +const TAG: string = '[LiveViewExtAbilityUtil]'; + +export class LiveViewExtAbilityUtil { + public static setSession(session: UIExtensionContentSession): void { + let param: Record = { + 'session': session + }; + + // Window size listener. + const extensionWindow = session.getUIExtensionWindowProxy(); + extensionWindow.on('windowSizeChange', (windowSize: window.Size) => { + LiveViewExtAbilityUtil.updateBreakPoint(windowSize); + }); + + // 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: bundleName, + priority: 0 + }; + commonEventManager.createSubscriber(subscribeInfo, + (error: BusinessError, data: commonEventManager.CommonEventSubscriber) => { + if (error) { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to create subscriber. code is ${error.code} message is ${error.message}.`); + return; + } + + hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in creating subscriber.'); + // Event handling logic. + commonEventManager.subscribe(data, + async (error: BusinessError, data: commonEventManager.CommonEventData) => { + if (error) { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to subscribe commonEvent. code is ${error.code} message is ${error.message}.`); + return; + } + 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); + hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in receive commonEvent.'); + } + }); + }) + session.loadContent('pages/LockScreen', storage); + } + + // 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('currentHeightBreakpoint', 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}`) + ; + } + } +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets new file mode 100644 index 0000000000000000000000000000000000000000..6fe04960ff9c34a1afc666d5c77fcc094e1772f5 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/LiveViewUtil.ets @@ -0,0 +1,169 @@ +/* + * 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 { application, Want, wantAgent } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +// [Start createLiveView] +import { liveViewManager } from '@kit.LiveViewKit'; +// [StartExclude createLiveView] +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { RouteData } from '../model/RouteDataModel'; + +const TAG: string = '[LiveViewUtil]'; + +export class LiveViewUtil { + private context = application.getApplicationContext(); + private defaultLiveView?: liveViewManager.LiveView; + private sequence: number = 0; + + 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.updateLiveViewInfo(params); + + return await liveViewManager.startLiveView(this.defaultLiveView); + } + + public async updateLiveView(params: RouteData): Promise { + try { + // live view is disabled or default view is not init + if (!await LiveViewUtil.isLiveViewEnabled() || !this.defaultLiveView) { + hilog.error(0x0000, TAG, '%{public}s', 'updateLiveView, live view is disabled.'); + return false; + } + this.updateLiveViewInfo(params); + const result = await liveViewManager.updateLiveView(this.defaultLiveView); + if (result) { + hilog.info(0x0000, TAG, '%{public}s', 'updateLiveView.'); + } + return true; + } catch (error) { + 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. + this.sequence++; + this.defaultLiveView = await this.createPrimaryLiveVie(); + await liveViewManager.stopLiveView(this.defaultLiveView).then(() => { + this.sequence = 0; + this.defaultLiveView = undefined; + hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in stopping liveView, result: %{public}'); + }).catch((error: BusinessError) => { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to stop liveView. Cause code: ${error.code}, message: ${error.message}`); + }); + return; + } + + // [End closeLiveView] + + private static async isLiveViewEnabled(): Promise { + return await liveViewManager.isLiveViewEnabled(); + } + + private updateLiveViewInfo(params: RouteData) { + let liveView: liveViewManager.LiveView = this.defaultLiveView!; + if (params) { + liveView.sequence = this.sequence + this.sequence++; + liveView.liveViewData.capsule = { + 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)}`, + } + 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)}`; + liveView.liveViewData.primary.content = [{ text: this.context.resourceManager.getStringSync(params.roadName) }]; + liveView.liveViewData.primary.liveViewLockScreenAbilityName = 'LiveViewExtAbility'; + liveView.liveViewData.primary.liveViewLockScreenAbilityParameters = { '': '' }; + if (params.roadInfo.laneNum === 1) { + liveView.liveViewData.primary.layoutData = { + layoutType: liveViewManager.LayoutType.LAYOUT_TYPE_NAVIGATION, + currentNavigationIcon: 'turn_straight_light_rectangle.png', + navigationIcons: ['turn_straight_light_rectangle.png', 'turn_right_dark_rectangle.png'] + }; + } else { + liveView.liveViewData.primary.layoutData = { + layoutType: liveViewManager.LayoutType.LAYOUT_TYPE_NAVIGATION, + currentNavigationIcon: 'turn_right_light_rectangle.png', + navigationIcons: ['turn_straight_dark_rectangle.png', 'turn_right_light_rectangle.png'] + } + } + } + this.defaultLiveView = liveView; + } + + private async createPrimaryLiveVie(): Promise { + // [EndExclude createLiveView] + // Construct live window request body. + let liveView: liveViewManager.LiveView = { + id: 0, + sequence: this.sequence, + // Application scenarios of the live window. NAVIGATION: Navigation. + event: 'NAVIGATION', + liveViewData: { + // Live view capsule related parameters + capsule: { + 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), + }, + // 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) }], + // Add LiveViewLockScreenExtensionAbility name to build lock screen live view + liveViewLockScreenAbilityName: 'LiveViewExtAbility', + liveViewLockScreenAbilityParameters: { liveViewParameters: '' }, + keepTime: 0, + clickAction: await LiveViewUtil.buildWantAgent() + } + } + }; + // [End createLiveView] + return liveView; + } + + private static async buildWantAgent(): Promise { + // let bundleName:string='' + const wantAgentInfo: wantAgent.WantAgentInfo = { + wants: [{ + bundleName: AppStorage.get('bundleName'), + abilityName: 'EntryAbility' + } as Want], + actionType: wantAgent.OperationType.START_ABILITIES, + requestCode: 0, + actionFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] + }; + const agent: object = await wantAgent.getWantAgent(wantAgentInfo); + return agent; + } +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets new file mode 100644 index 0000000000000000000000000000000000000000..1d55016c3a841ba777c155d716551bc64b812011 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/utils/WindowUtil.ets @@ -0,0 +1,68 @@ +/* + * 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((err: BusinessError, data: window.Window) => { + if (err.code) { + 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((err: BusinessError, data: window.Window) => { + if (err.code) { + hilog.error(0x0000, TAG, `Failed to get main window: ${err.message}`); + return; + } + BreakpointSystem.getInstance().updateWidthHeightBp(data); + data.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(data)); + 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('bottomRectHeight', bottomRectHeight); + }) + } +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/view/RoadView.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/view/RoadView.ets new file mode 100644 index 0000000000000000000000000000000000000000..dd5bec6163df874ccb185da4ef12353c5dcee5aa --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/view/RoadView.ets @@ -0,0 +1,40 @@ +/* + * 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. + */ + +@Component +export struct RoadView { + @Prop laneNum: number = 1; + + build() { + Stack() { + Row() { + if (this.laneNum === 1) { + Image($r('app.media.traffic_left')) + .objectFit(ImageFit.Contain) + } else { + Image($r('app.media.traffic_right')) + .objectFit(ImageFit.Contain) + } + } + .width('80%') + .height('80%') + } + .backgroundImage($r("app.media.traffic_background")) + .backgroundImageSize(ImageSize.Cover) + .backgroundImagePosition(Alignment.Center) + .height('101%') + .width('101%') + } +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/view/TrafficInfoView.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/view/TrafficInfoView.ets new file mode 100644 index 0000000000000000000000000000000000000000..fbc067e8b9a0e5a8e9db2dcc64a5724a07c711b3 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/view/TrafficInfoView.ets @@ -0,0 +1,102 @@ +/* + * 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 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().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() + } + .margin({ + top: 6, + }) + .width('100%') + } + } + .width('100%') + } +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/view/TrafficView.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/view/TrafficView.ets new file mode 100644 index 0000000000000000000000000000000000000000..4f6924647f0c021e87f6c8d1024579b7fd638ae7 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/view/TrafficView.ets @@ -0,0 +1,321 @@ +/* + * 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 { LaneData } from "../model/RouteDataModel"; +import { BreakpointType, BreakpointTypeEnum } from "../utils/BreakpointSystem"; +import { TrafficInfoView } from "./TrafficInfoView"; +import { hilog } from "@kit.PerformanceAnalysisKit"; + +@Component +export struct TrafficView { + @StorageProp('bottomRectHeight') bottomRectHeight: number = 0; + @Watch('test') @StorageLink('currentWidthBreakpoint') currentWidthBreakpoint: string = BreakpointTypeEnum.SM; + @Watch('test') @StorageLink('currentHeightBreakpoint') currentHeightBreakpoint: string = BreakpointTypeEnum.LG; + @State roadInfo: LaneData | undefined = undefined; + @State isShowButton: boolean = false; + + test(changedPropertyName: string) { + hilog.info(0x0000, '[test]', '%{public}s', `widthBp: ${this.currentWidthBreakpoint}`); + hilog.info(0x0000, '[test]', '%{public}s', `heightBp: ${this.currentHeightBreakpoint}`); + } + + 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 }) { + Image($r('app.media.traffic_right')) + .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: px2vp(this.bottomRectHeight), + md: 0, + lg: 0, + }).getValue(this.currentWidthBreakpoint), + }) + .margin({ + bottom: new BreakpointType({ + sm: 0, + md: px2vp(this.bottomRectHeight), + lg: 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, + }) + + 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/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/viewmodel/RouteDataViewModel.ets b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/viewmodel/RouteDataViewModel.ets new file mode 100644 index 0000000000000000000000000000000000000000..920ea8d15db0ac01e6d6f8a0f52dfa23fd17f81f --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/ets/viewmodel/RouteDataViewModel.ets @@ -0,0 +1,39 @@ +/* + * 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 { RouteData } from '../model/RouteDataModel'; + +const LEFT_STATE: RouteData = { + roadInfo: { + laneNum: 1 + }, + distance: 800, + roadName: $r('app.string.road_name') +}; + +const RIGHT_STATE: RouteData = { + roadInfo: { + laneNum: 2 + }, + distance: 800, + roadName: $r('app.string.road_name') +}; + +let isLeftState: boolean = false; + +export const getRouteData = (): RouteData => { + isLeftState = !isLeftState; + return isLeftState ? LEFT_STATE : RIGHT_STATE; +}; \ No newline at end of file diff --git a/liveviewlockscreenlibrary/src/ohosTest/module.json5 b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/module.json5 similarity index 39% rename from liveviewlockscreenlibrary/src/ohosTest/module.json5 rename to liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/module.json5 index 1d3cce895506daf514ac8c6d14f0aa9de24fc8a7..177ddf3161339cb9d2a0c00d837a9679eeece759 100644 --- a/liveviewlockscreenlibrary/src/ohosTest/module.json5 +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/module.json5 @@ -1,13 +1,11 @@ { "module": { - "name": "liveviewlockscreenlibrary_test", - "type": "feature", + "name": "liveviewlockscreenlibrary", + "type": "har", "deviceTypes": [ "default", "tablet", "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false + ] } } diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/element/color.json b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..0784b8b676f1271e2980eede6ca82b9b8ff1c344 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/element/color.json @@ -0,0 +1,32 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "Index_background_first", + "value": "#000000" + }, + { + "name": "Index_background_second", + "value": "#303030" + }, + { + "name": "component_background_color", + "value": "#0C000000" + }, + { + "name": "traffic_info_line", + "value": "#33000000" + }, + { + "name": "traffic_info_background_color", + "value": "#F1F3F5" + }, + { + "name": "traffic_info_button", + "value": "#08000000" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/element/string.json similarity index 100% rename from entry/src/main/resources/zh_CN/element/string.json rename to liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/element/string.json diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/background.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/background.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/big_arrow.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/big_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..5e8ca5e5e2adfc67f2cfc31d1f68b4c75fce3b02 Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/big_arrow.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/foreground.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/foreground.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/layered_image.json b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/little_arrow.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/little_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..295126ca6cda13bf4a39e91e6fe85e8f52b69a29 Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/little_arrow.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/startIcon.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/startIcon.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_background.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_background.png new file mode 100644 index 0000000000000000000000000000000000000000..3cc57185978f8e630c99f80c057e75cbbfa486a8 Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_background.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_info_label.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_info_label.png new file mode 100644 index 0000000000000000000000000000000000000000..163a9c61c888350d6cbd7c9f771fbc36dde3f6bc Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_info_label.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_info_speed.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_info_speed.png new file mode 100644 index 0000000000000000000000000000000000000000..9e53c2ac851b5602371d79fc9449ea6f8805dd11 Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_info_speed.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_left.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_left.png new file mode 100644 index 0000000000000000000000000000000000000000..94ee73c185d6ff34abcee535077ca802b1911ce1 Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_left.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_light.svg b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_light.svg new file mode 100644 index 0000000000000000000000000000000000000000..eca422cc829ca2a38255e641d7205a4901a338fa --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_light.svg @@ -0,0 +1,41 @@ + + + Created with Pixso. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_right.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_right.png new file mode 100644 index 0000000000000000000000000000000000000000..36c2a5f3ea1d534921d5dcd48a38981d8e343115 Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/traffic_right.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/turn_right_light_rectangle.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/turn_right_light_rectangle.png new file mode 100644 index 0000000000000000000000000000000000000000..cd3bbc2f67d07b8f898d5fc777fe07e64fa8a247 Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/media/turn_right_light_rectangle.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/profile/backup_config.json b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/profile/main_pages.json b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..57e28d0cbcd79a53608a89b24cd2259350608df3 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "liveview/LockScreenPage", + "pages/LiveViewLockScreenPage" + ] +} diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/dark/element/color.json b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..05391e0022dd26d52165a8e4adde309dd7797837 --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/en_US/element/string.json @@ -0,0 +1,88 @@ +{ + "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" + }, + { + "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" + }, + { + "name": "traffic_info_second", + "value": "72.6km·09:32·" + }, + { + "name": "traffic_info_third", + "value": "3" + }, + { + "name": "live_view_title", + "value": "In navigation" + }, + { + "name": "live_view_background", + "value": "#ff0959F8" + }, + { + "name": "live_view_content", + "value": "content" + }, + { + "name": "meter", + "value": " meters" + }, + { + "name": "live_view_primary_title_first", + "value": "Turn right after " + }, + { + "name": "live_view_primary_title_second", + "value": " meters" + }, + { + "name": "road_name", + "value": "Cuihu East Road" + }, + { + "name": "then", + "value": "Then" + }, + { + "name": "toast", + "value": "Tip: You must apply for relevant permissions to experience the lock screen live view." + }, + { + "name": "Continue", + "value": "Continue" + }, + { + "name": "Finish", + "value": "Finish" + } + ] +} \ No newline at end of file diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/traffic_light.svg b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/traffic_light.svg new file mode 100644 index 0000000000000000000000000000000000000000..683a432651f7dbc91b854f5f94ec51df3c310ade --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/traffic_light.svg @@ -0,0 +1,12 @@ + + + Created with Pixso. + + + + + + + + + diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_dark_rectangle.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_dark_rectangle.png new file mode 100644 index 0000000000000000000000000000000000000000..41f78ea0b59d840cfe841594f054b33257e33933 Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_dark_rectangle.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_light_rectangle.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_light_rectangle.png new file mode 100644 index 0000000000000000000000000000000000000000..52dff1c8ba8c9e3c48c150d2939ca376e1832ae9 Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_light_rectangle.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_light_square.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_light_square.png new file mode 100644 index 0000000000000000000000000000000000000000..7941168e4f843aa2c850ba818d74fb63edee8a5d Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_right_light_square.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_straight_dark_rectangle.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_straight_dark_rectangle.png new file mode 100644 index 0000000000000000000000000000000000000000..076ad2ccb161331ccc25eb95c76af10068839500 Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_straight_dark_rectangle.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_straight_light_rectangle.png b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_straight_light_rectangle.png new file mode 100644 index 0000000000000000000000000000000000000000..c2177d04d55a2e64f4af52de19d19b6ebff2b521 Binary files /dev/null and b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/rawfile/turn_straight_light_rectangle.png differ diff --git a/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..dda579115ab8bbbf50d5005b6c75990ad6ed046b --- /dev/null +++ b/liveviewlockscreensample/oh_modules/liveviewlockscreenlibrary/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,88 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "锁屏沉浸实况窗" + }, + { + "name": "reason_background", + "value": "Background operation to update the live view" + }, + { + "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 分钟" + }, + { + "name": "traffic_info_second", + "value": "72.6公里·09:32·" + }, + { + "name": "traffic_info_third", + "value": "3" + }, + { + "name": "live_view_title", + "value": "导航中" + }, + { + "name": "live_view_background", + "value": "#ff0959F8" + }, + { + "name": "live_view_content", + "value": "content" + }, + { + "name": "meter", + "value": "米" + }, + { + "name": "live_view_primary_title_first", + "value": "" + }, + { + "name": "live_view_primary_title_second", + "value": "米后右转" + }, + { + "name": "road_name", + "value": "翠湖东路" + }, + { + "name": "then", + "value": "然后" + }, + { + "name": "toast", + "value": "提醒:锁屏沉浸实况窗须申请相关权限才可体验" + }, + { + "name": "Continue", + "value": "继续导航" + }, + { + "name": "Finish", + "value": "停止导航" + } + ] +} \ 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 71% rename from entry/src/main/ets/entryability/EntryAbility.ets rename to liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets index 92c277fb429bd88e21220539c6d1e0fb6f1199e9..ffee2663a804ca3402859f40d2a306af9a994657 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/liveviewlockscreensample/src/main/ets/entryability/EntryAbility.ets @@ -13,29 +13,17 @@ * limitations under the License. */ -import { bundleManager, ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; +import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; -import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { WindowUtil } from '../utils/WindowUtil'; +import { BundleNameUtil, WindowUtil } from 'liveviewlockscreenlibrary' const TAG: string = '[EntryAbility]'; export default class EntryAbility extends UIAbility { onCreate(): void { this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); - try { - bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT).then((data) => { - hilog.info(0x0000, TAG, '%{public}s', 'getBundleInfoForSelf successfully.'); - AppStorage.setOrCreate('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}`); - } + BundleNameUtil.getBundleName(); 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 new file mode 100644 index 0000000000000000000000000000000000000000..2bcea4c5a5fcd4ef9f94955a2e37f3e9d2d089a7 --- /dev/null +++ b/liveviewlockscreensample/src/main/ets/liveview/LiveViewExtAbility.ets @@ -0,0 +1,63 @@ +/* +* 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; + private currentHeightBreakpoint: string = ''; + + 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.setSession(session); + } + + // Cleanup operations when destroying UI session + onSessionDestroy(): void { + commonEventManager.unsubscribe(this.subscriber, () => { + this.subscriber = null; + }); + 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/liveviewlockscreensample/src/main/ets/pages/Index.ets b/liveviewlockscreensample/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..99c28de999fd18a7a852b1d69395dd3b7e0dc6b7 --- /dev/null +++ b/liveviewlockscreensample/src/main/ets/pages/Index.ets @@ -0,0 +1,26 @@ +/* + * 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 { LiveViewLockScreenPage } from 'liveviewlockscreenlibrary' + +@Entry +@Component +struct Index { + build() { + Stack() { + LiveViewLockScreenPage() + } + } +} diff --git a/liveviewlockscreensample/src/main/ets/pages/LockScreen.ets b/liveviewlockscreensample/src/main/ets/pages/LockScreen.ets new file mode 100644 index 0000000000000000000000000000000000000000..510685c5ca77db3dd260a03d141ba5d59432e426 --- /dev/null +++ b/liveviewlockscreensample/src/main/ets/pages/LockScreen.ets @@ -0,0 +1,28 @@ +/* + * 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 { LockScreenPage } from 'liveviewlockscreenlibrary' + +let storage: LocalStorage = LocalStorage.getShared(); + +@Entry(storage) +@Component +struct LockScreen { + build() { + Stack() { + LockScreenPage() + } + } +} diff --git a/entry/src/main/module.json5 b/liveviewlockscreensample/src/main/module.json5 similarity index 95% rename from entry/src/main/module.json5 rename to liveviewlockscreensample/src/main/module.json5 index 817c8c68fb464ed057443734a088bb225dd75ecc..40fc55d03e81c40daf38fd453cefeebec95f962b 100644 --- a/entry/src/main/module.json5 +++ b/liveviewlockscreensample/src/main/module.json5 @@ -1,6 +1,6 @@ { "module": { - "name": "entry", + "name": "liveviewlockscreensample", "type": "entry", "description": "$string:module_desc", "mainElement": "EntryAbility", @@ -14,7 +14,7 @@ "pages": "$profile:main_pages", "abilities": [ { - "name": "EntryAbility", + "name": "LiveViewLockScreenAbility", "srcEntry": "./ets/entryability/EntryAbility.ets", "description": "$string:EntryAbility_desc", "icon": "$media:layered_image", diff --git a/liveviewlockscreensample/src/main/resources/base/media/background.png b/liveviewlockscreensample/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/liveviewlockscreensample/src/main/resources/base/media/background.png differ diff --git a/liveviewlockscreensample/src/main/resources/base/media/foreground.png b/liveviewlockscreensample/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/liveviewlockscreensample/src/main/resources/base/media/foreground.png differ diff --git a/liveviewlockscreensample/src/main/resources/base/profile/backup_config.json b/liveviewlockscreensample/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/liveviewlockscreensample/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ 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 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" + ] +}