diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index d95a8a6e548bd2dd95bedcac11e6cce59d4f619b..56d75f0282c99639d8710c53e8bb0591922624c0 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; +import { bundleManager, ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; import { display, window } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -55,12 +55,24 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('verticalBreakpoint', this.verticalBreakpoint); } } catch (error) { - hilog.error(0x0000, TAG, `updateBreakpoint catch err:`, (error as BusinessError).message); + hilog.error(0x0000, TAG, '%{public}s', `updateBreakpoint catch err:`, (error as BusinessError).message); } } 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}`); + } hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); } @@ -81,28 +93,32 @@ export default class EntryAbility extends UIAbility { statusBarContentColor: '#ffffff', }).then(() => { hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in setting the system bar properties.'); - }).catch((err: BusinessError) => { - hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. Cause:', err.message); + }).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((err: BusinessError) => { - hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. Cause:', err.message); + }).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}`); } - }).catch((err: BusinessError) => { - hilog.error(0x0000, TAG, `Failed to get main window. Cause:`, err.message); + }).catch((error: BusinessError) => { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to get main window. Cause code: ${error.code}, message: ${error.message}`); }); - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(0x0000, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + windowStage.loadContent('pages/Index', (error) => { + if (error.code) { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to load the content. Cause code: ${error.code}, message: ${error.message}`); return; } - hilog.info(0x0000, TAG, 'Succeeded in loading the content.'); + hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in loading the content.'); }); } diff --git a/entry/src/main/ets/liveview/LiveViewExtAbility.ets b/entry/src/main/ets/liveview/LiveViewExtAbility.ets index ed753c1f8a24de4a1f79a4d66eaaa495087bf75d..64b6efd104ca706ee66b8a3e495b322ba9c73b78 100644 --- a/entry/src/main/ets/liveview/LiveViewExtAbility.ets +++ b/entry/src/main/ets/liveview/LiveViewExtAbility.ets @@ -14,7 +14,7 @@ */ // [Start windowSizeListener] -import { AbilityConstant, UIExtensionContentSession, Want } from '@kit.AbilityKit'; +import { AbilityConstant, bundleManager, UIExtensionContentSession, Want } from '@kit.AbilityKit'; // [Start updateBreakPoint] import { display, window } from '@kit.ArkUI'; // [StartExclude updateBreakPoint] @@ -55,34 +55,37 @@ export default class LiveViewExtAbility extends LiveViewLockScreenExtensionAbili this.verticalBreakpoint = verticalBreakpoint; AppStorage.setOrCreate('verticalBreakpoint', this.verticalBreakpoint); } - hilog.info(0x0000, TAG, `updateBreakpoint ${verticalBreakpoint}`); + hilog.info(0x0000, TAG, '%{public}s', 'updateBreakpoint'); } catch (error) { - hilog.error(0x0000, TAG, `updateBreakpoint catch err:`, (error as BusinessError).message); + 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, 'LiveViewLockScreenExtAbility onCreate begin.'); + hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onCreate begin.'); } onForeground(): void { - hilog.info(0x0000, TAG, 'LiveViewLockScreenExtAbility onForeground begin.'); + hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onForeground begin.'); } onBackground(): void { - hilog.info(0x0000, TAG, 'LiveViewLockScreenExtAbility onBackground begin.'); + hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onBackground begin.'); } onDestroy(): void | Promise { - hilog.info(0x0000, TAG, 'LiveViewLockScreenExtAbility onDestroy begin.'); + 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, 'LiveViewLockScreenExtAbility onSessionCreate begin.'); + hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onSessionCreate begin.'); let param: Record = { 'session': session }; @@ -97,9 +100,22 @@ export default class LiveViewExtAbility extends LiveViewLockScreenExtensionAbili // Create state storage (for cross-page data sharing). let storage: LocalStorage = new LocalStorage(param); // Initialize event subscription. + let bundleName: string = ''; + try { + bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT).then((data) => { + hilog.info(0x0000, TAG, '%{public}s', 'getBundleInfoForSelf successfully.'); + bundleName = data.name; + }).catch((error: BusinessError) => { + hilog.error(0x0000, TAG, '%{public}s', + `getBundleInfoForSelf failed. code is ${error.code} message is ${error.message}`); + }); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `getBundleInfoForSelf failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); + } let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { events: ['live_view_lock_screen'], - publisherBundleName: 'com.example.mapliveviewsample', + publisherBundleName: bundleName, priority: 0 }; commonEventManager.createSubscriber(subscribeInfo, @@ -139,10 +155,10 @@ export default class LiveViewExtAbility extends LiveViewLockScreenExtensionAbili commonEventManager.unsubscribe(this.subscriber, () => { this.subscriber = null; }); - hilog.info(0x0000, TAG, 'LiveViewLockScreenExtAbility onSessionDestroy begin.'); + hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onSessionDestroy begin.'); } onConfigurationUpdate(): void { - hilog.info(0x0000, TAG, 'LiveViewLockScreenExtAbility onConfigurationUpdate begin.'); + hilog.info(0x0000, TAG, '%{public}s', 'LiveViewLockScreenExtAbility onConfigurationUpdate begin.'); } } \ No newline at end of file diff --git a/entry/src/main/ets/liveview/LockScreenPage.ets b/entry/src/main/ets/liveview/LockScreenPage.ets index 76679c63f4b4757a2f3a1c0a8611ede851c3ad5a..0047d527eeae5a23434f475906417c890529e9f6 100644 --- a/entry/src/main/ets/liveview/LockScreenPage.ets +++ b/entry/src/main/ets/liveview/LockScreenPage.ets @@ -43,5 +43,6 @@ struct Index { .width('100%') .height('100%') } + // [End layoutBasedOnVerticalBreakpoint] } \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 387c24af092a805fb6deddec51dac575d726c98c..f65c7bc090b9cf87dac644cc3a9eb0ddeb441351 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -15,12 +15,19 @@ import { LiveView } from '../utils/LiveView'; import { TrafficView } from '../view/TrafficView'; +import { promptAction } from '@kit.ArkUI'; @Entry @Component struct Index { aboutToAppear(): void { LiveView.getInstance().createLiveView(); + this.getUIContext().getPromptAction().showToast({ + message: $r('app.string.toast'), + duration: 2000, + showMode: promptAction.ToastShowMode.DEFAULT, + bottom: 180 + }); } build() { diff --git a/entry/src/main/ets/utils/LiveView.ets b/entry/src/main/ets/utils/LiveView.ets index fd4d4d28d1b3ca61c3f7c65e34e24687271ed7fc..be47d16e67c9896629023f82b3b6ddaf75402637 100644 --- a/entry/src/main/ets/utils/LiveView.ets +++ b/entry/src/main/ets/utils/LiveView.ets @@ -69,7 +69,7 @@ export class LiveView { // Prepare common event data let options: commonEventManager.CommonEventPublishData = { data: 'data', - bundleName: 'com.example.mapliveviewsample', + bundleName: AppStorage.get('bundleName'), parameters: { 'roadData': routeInfo.roadInfo } @@ -102,7 +102,7 @@ export class LiveView { if (this.updateInterval !== undefined) { clearInterval(this.updateInterval); this.updateInterval = undefined; - hilog.info(0x0000, TAG, 'Timer has been cleared'); + hilog.info(0x0000, TAG, '%{public}s', 'Timer has been cleared'); } // [End clearPeriodicUpdates] @@ -130,7 +130,7 @@ export class LiveView { let wantAgentInfo: wantAgent.WantAgentInfo = { wants: [ { - bundleName: 'com.example.mapliveviewsample', + bundleName: AppStorage.get('bundleName'), abilityName: 'EntryAbility' } ], @@ -163,5 +163,6 @@ export class LiveView { `Failed to Operation getWantAgent. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); } } + // [End startContinuousRunningTask] } \ No newline at end of file diff --git a/entry/src/main/ets/utils/LiveViewUtil.ets b/entry/src/main/ets/utils/LiveViewUtil.ets index 1616ebb8a76f2ffbafb04720dddeb21924e8991d..8d8d7fa1225100d9f1b1a26f8813583e5cdb5e48 100644 --- a/entry/src/main/ets/utils/LiveViewUtil.ets +++ b/entry/src/main/ets/utils/LiveViewUtil.ets @@ -18,8 +18,9 @@ import { BusinessError } from '@kit.BasicServicesKit'; // [Start createLiveView] import { liveViewManager } from '@kit.LiveViewKit'; // [StartExclude createLiveView] -import { RouteData } from '../model/RouteDataModel'; import { hilog } from '@kit.PerformanceAnalysisKit'; +import { Constants } from '../constant/Constant'; +import { RouteData } from '../model/RouteDataModel'; const TAG: string = '[LiveViewUtil]'; @@ -54,7 +55,7 @@ export class LiveViewUtil { } return true; } catch (error) { - hilog.error(0x0000, TAG, + hilog.error(0x0000, TAG, '%{public}s', `Failed to update live view. Cause code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}`); return false; } @@ -76,6 +77,7 @@ export class LiveViewUtil { }); return; } + // [End closeLiveView] private static async isLiveViewEnabled(): Promise { @@ -152,9 +154,10 @@ export class LiveViewUtil { } private static async buildWantAgent(): Promise { + // let bundleName:string='' const wantAgentInfo: wantAgent.WantAgentInfo = { wants: [{ - bundleName: 'com.example.mapliveviewsample', + bundleName: AppStorage.get('bundleName'), abilityName: 'EntryAbility' } as Want], actionType: wantAgent.OperationType.START_ABILITIES, diff --git a/entry/src/main/ets/view/TrafficInfoView.ets b/entry/src/main/ets/view/TrafficInfoView.ets index 63efea9afbf7b261764696ead7475a8534546063..7ca2b30b7925ad8ca586097cb0191b301fd76318 100644 --- a/entry/src/main/ets/view/TrafficInfoView.ets +++ b/entry/src/main/ets/view/TrafficInfoView.ets @@ -53,9 +53,9 @@ export struct TrafficInfoView { Column() { Button('开始导航') - .fontColor(this.isStart ? $r('sys.color.comp_background_emphasize') : Color.White) - .backgroundColor(this.isStart ? $r('sys.color.comp_background_secondary') : - $r('sys.color.comp_background_emphasize')) + .fontColor(this.isStart ? $r('sys.color.font_emphasize') : Color.White) + .backgroundColor(this.isStart ? $r('sys.color.comp_background_tertiary') : + $r('sys.color.background_emphasize')) .fontSize(12) .width(80) .height(30) @@ -64,9 +64,9 @@ export struct TrafficInfoView { LiveView.getInstance().createLiveView(); }) Button('结束导航') - .fontColor(!this.isStart ? $r('sys.color.comp_background_emphasize') : Color.White) - .backgroundColor(!this.isStart ? $r('sys.color.comp_background_secondary') : - $r('sys.color.comp_background_emphasize')) + .fontColor(!this.isStart ? $r('sys.color.font_emphasize') : Color.White) + .backgroundColor(!this.isStart ? $r('sys.color.comp_background_tertiary') : + $r('sys.color.background_emphasize')) .fontSize(12) .width(80) .height(30) diff --git a/entry/src/main/ets/view/TrafficView.ets b/entry/src/main/ets/view/TrafficView.ets index c41c0f8b7b8fdb6b8dadc764a23d27a813cd7b42..f5b1856f87e39451e20ff89163d31f533d446d50 100644 --- a/entry/src/main/ets/view/TrafficView.ets +++ b/entry/src/main/ets/view/TrafficView.ets @@ -125,14 +125,9 @@ export struct TrafficView { .objectFit(ImageFit.Contain) .height(new BreakpointType(70, 80, 80).getValue(this.horizontalBreakpoint)) } - .margin({ - left: new BreakpointType($r('sys.float.padding_level36'), $r('sys.float.padding_level12'), - $r('sys.float.padding_level16')).getValue(this.horizontalBreakpoint), - top: $r('sys.float.padding_level2'), - }) .width(new BreakpointType('100%', '40%', '30%').getValue(this.horizontalBreakpoint)) } - .padding({ + .margin({ left: new BreakpointType($r('sys.float.padding_level0'), $r('sys.float.padding_level12'), $r('sys.float.padding_level16')).getValue(this.horizontalBreakpoint), top: new BreakpointType($r('sys.float.padding_level0'), $r('sys.float.padding_level16'), @@ -170,23 +165,29 @@ export struct TrafficView { Blank() - if (this.horizontalBreakpoint !== Constants.BREAK_POINT_SM || - this.verticalBreakpoint !== Constants.BREAK_POINT_MD) { - Row() { - TrafficInfoView() + Row(){ + if (this.horizontalBreakpoint !== Constants.BREAK_POINT_SM || + this.verticalBreakpoint !== Constants.BREAK_POINT_MD) { + Row() { + TrafficInfoView() + } + .onSizeChange(() => { + this.isShow = false; + }) + .margin({ + left: new BreakpointType($r('sys.float.padding_level0'), $r('sys.float.padding_level12'), + $r('sys.float.padding_level16')).getValue(this.horizontalBreakpoint), + }) + .backgroundColor($r('sys.color.background_secondary')) + .width(new BreakpointType('100%', '50%', '30%').getValue(this.horizontalBreakpoint)) + .height(120) + .borderRadius({ + topLeft: 32, + topRight: 32, + }) } - .margin({ - left: new BreakpointType($r('sys.float.padding_level0'), $r('sys.float.padding_level12'), - $r('sys.float.padding_level16')).getValue(this.horizontalBreakpoint), - }) - .backgroundColor($r('sys.color.background_secondary')) - .width(new BreakpointType('100%', '50%', '30%').getValue(this.horizontalBreakpoint)) - .height(120) - .borderRadius({ - topLeft: 32, - topRight: 32, - }) } + .width('100%') } .bindSheet($$this.isShow, this.myBuilder(), { height: 90, diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 index 68b78dcf1af492ef04a3cce07a0966ad9d26c695..817c8c68fb464ed057443734a088bb225dd75ecc 100644 --- a/entry/src/main/module.json5 +++ b/entry/src/main/module.json5 @@ -6,6 +6,8 @@ "mainElement": "EntryAbility", "deviceTypes": [ "phone", + "tablet", + "2in1" ], "deliveryWithInstall": true, "installationFree": false, @@ -19,7 +21,7 @@ "label": "$string:EntryAbility_label", "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", - "exported": true, + "exported": false, "backgroundModes": [ 'location' ], diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 2a8552a445951c53c36427e3ef102a121c270495..603a5c9dbec86b6a6db63e5470ea65f5015dc526 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -63,6 +63,10 @@ { "name": "then", "value": "然后" + }, + { + "name": "toast", + "value": "提醒:锁屏沉浸实况窗须申请相关权限才可体验" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index 9eacc46fabe45623c5c8ec6c6ac36b0bf1a29d97..74e6b3c49b8a0fe4b78ba991e8d1009e85e407b6 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -63,6 +63,10 @@ { "name": "then", "value": "Then" + }, + { + "name": "toast", + "value": "Tip: You must apply for relevant permissions to experience the lock screen live view." } ] } \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index 2a8552a445951c53c36427e3ef102a121c270495..603a5c9dbec86b6a6db63e5470ea65f5015dc526 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -63,6 +63,10 @@ { "name": "then", "value": "然后" + }, + { + "name": "toast", + "value": "提醒:锁屏沉浸实况窗须申请相关权限才可体验" } ] } \ No newline at end of file