diff --git a/README.md b/README.md index 6e0b5f79a1314d1b778f62935d46368c4f1fe58c..0b0ac6703d96e2731e3824df56f6c0d7b8005e64 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,8 @@ 1.本示例仅支持标准系统上运行,支持设备:华为手机; -2.HarmonyOS系统:HarmonyOS 5.0.0 Developer Release及以上; +2.HarmonyOS系统:HarmonyOS 5.0.0 Release及以上; -3.DevEco Studio版本:DevEco Studio 5.0.0 Developer Release及以上; +3.DevEco Studio版本:DevEco Studio 5.0.0 Release及以上; -4.HarmonyOS SDK版本:HarmonyOS 5.0.0 Developer Release SDK及以上。 \ No newline at end of file +4.HarmonyOS SDK版本:HarmonyOS 5.0.0 Release SDK及以上。 \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 076f342e28d29016f3dfadeee3e7585e2c80e592..b4a95d250cf17f0c25ad72c0e72d5dbcef969b7e 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -77,7 +77,7 @@ struct TipDialog { } @Entry -export struct LiveViewLockScreenPage { +struct LiveViewLockScreenPage { private customDialogController: CustomDialogController = new CustomDialogController({ builder: TipDialog({ onConfirm: () => { @@ -97,7 +97,7 @@ export struct LiveViewLockScreenPage { }); aboutToAppear(): void { - LiveView.getInstance(this.getUIContext().getHostContext()).createLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext() as Context).createLiveView(); this.customDialogController?.open(); } diff --git a/entry/src/main/ets/utils/LiveView.ets b/entry/src/main/ets/utils/LiveView.ets index fda43bd4d4fcd0730aad00385c713b7e12c8a800..4ae821351bc65de69071bc65418187f50a23c8eb 100644 --- a/entry/src/main/ets/utils/LiveView.ets +++ b/entry/src/main/ets/utils/LiveView.ets @@ -30,18 +30,18 @@ const TAG: string = '[LiveView]'; export class LiveView { // Singleton pattern implementation private static instance: LiveView; - private context: Context | undefined; + private context: Context; private liveViewController: LiveViewUtil; private updateInterval: number | undefined; // Private constructor for singleton pattern - private constructor(context: Context | undefined) { + private constructor(context: Context) { this.context = context; - this.liveViewController = new LiveViewUtil(); + this.liveViewController = new LiveViewUtil(context); } // Singleton accessor method - public static getInstance(context: Context | undefined): LiveView { + public static getInstance(context: Context): LiveView { // Lazy initialization of the singleton instance if (!LiveView.instance) { LiveView.instance = new LiveView(context); diff --git a/entry/src/main/ets/utils/LiveViewUtil.ets b/entry/src/main/ets/utils/LiveViewUtil.ets index 1616ebb8a76f2ffbafb04720dddeb21924e8991d..eb060cfc71c7bd5f6155b74e5793b2aef8bb15fe 100644 --- a/entry/src/main/ets/utils/LiveViewUtil.ets +++ b/entry/src/main/ets/utils/LiveViewUtil.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { application, Want, wantAgent } from '@kit.AbilityKit'; +import { Want, wantAgent } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; // [Start createLiveView] import { liveViewManager } from '@kit.LiveViewKit'; @@ -24,17 +24,21 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = '[LiveViewUtil]'; export class LiveViewUtil { - private context = application.getApplicationContext(); + private context: Context; private defaultLiveView?: liveViewManager.LiveView; private sequence: number = 0; + public constructor(context: Context) { + this.context = context; + } + public async startLiveView(params: RouteData) { // Verify that the live view switch is turned on if (!await LiveViewUtil.isLiveViewEnabled()) { hilog.error(0x0000, TAG, '%{public}s', 'Live view is disabled.'); return; } - this.defaultLiveView = await this.createPrimaryLiveVie(); + this.defaultLiveView = await this.createPrimaryLiveView(); this.updateLiveViewInfo(params); return await liveViewManager.startLiveView(this.defaultLiveView); @@ -65,7 +69,7 @@ export class LiveViewUtil { public async closeLiveView() { // Ensure that the sequence is greater than the current live window page. this.sequence++; - this.defaultLiveView = await this.createPrimaryLiveVie(); + this.defaultLiveView = await this.createPrimaryLiveView(); await liveViewManager.stopLiveView(this.defaultLiveView).then(() => { this.sequence = 0; this.defaultLiveView = undefined; @@ -76,6 +80,7 @@ export class LiveViewUtil { }); return; } + // [End closeLiveView] private static async isLiveViewEnabled(): Promise { @@ -118,7 +123,7 @@ export class LiveViewUtil { this.defaultLiveView = liveView; } - private async createPrimaryLiveVie(): Promise { + private async createPrimaryLiveView(): Promise { // [EndExclude createLiveView] // Construct live window request body. let liveView: liveViewManager.LiveView = { diff --git a/entry/src/main/ets/view/TrafficInfoView.ets b/entry/src/main/ets/view/TrafficInfoView.ets index c68869306caa34b08f7d4e6f09068f558d746e6a..06439234029c08de6ba6f38761e100e218b63804 100644 --- a/entry/src/main/ets/view/TrafficInfoView.ets +++ b/entry/src/main/ets/view/TrafficInfoView.ets @@ -78,7 +78,7 @@ export struct TrafficInfoView { .width('40%') .onClick(() => { this.isShowButton = false; - LiveView.getInstance(this.getUIContext().getHostContext()).createLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext() as Context).createLiveView(); this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast'), duration: 2000, @@ -94,7 +94,7 @@ export struct TrafficInfoView { .width('40%') .onClick(() => { this.isShowButton = false; - LiveView.getInstance(this.getUIContext().getHostContext()).finishLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext() as Context).finishLiveView(); this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast'), duration: 2000,