diff --git a/entry/src/main/ets/common/AVPlayerUtil.ets b/entry/src/main/ets/common/AVPlayerUtil.ets index b3ce471b18d8d456f51b58b8b62e19cb040ff8bd..e34fe02a532e98919b2d93d1079b7d3419506d76 100644 --- a/entry/src/main/ets/common/AVPlayerUtil.ets +++ b/entry/src/main/ets/common/AVPlayerUtil.ets @@ -17,6 +17,8 @@ import { media } from '@kit.MediaKit'; import { common } from '@kit.AbilityKit'; import Logger from './Logger'; +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); + export class AVPlayerUtil { private surfaceId: string = ''; private avPlayer: media.AVPlayer | undefined = undefined; @@ -79,7 +81,7 @@ export class AVPlayerUtil { this.callBack = callBack; this.setAVPlayerCallback(); - let context = getContext(this) as common.UIAbilityContext; + let context = uiContext!.getHostContext()! as common.UIAbilityContext; let fileDescriptor = await context.resourceManager.getRawFd(url); let avFileDescriptor: media.AVFileDescriptor = { fd: fileDescriptor.fd, offset: fileDescriptor.offset, length: fileDescriptor.length }; diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 0702d292035b126055fc19f6456c3fd8d76eac76..e155f48b5ca1fcb49234c68f1c45212b0f5e41c1 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -34,8 +34,7 @@ export default class EntryAbility extends UIAbility { windowClass.setWindowLayoutFullScreen(true); let naviBarArea: window.AvoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); let area: window.AvoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); - AppStorage.setOrCreate('naviIndicatorHeight', px2vp(naviBarArea.bottomRect.height)); - AppStorage.setOrCreate('statusBarHeight', px2vp(area.topRect.height)); + windowStage.loadContent('pages/Index', (err) => { if (err.code) { @@ -43,6 +42,10 @@ export default class EntryAbility extends UIAbility { return; } hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + AppStorage.setOrCreate('naviIndicatorHeight', windowClass.getUIContext().px2vp(naviBarArea.bottomRect.height)); + AppStorage.setOrCreate('statusBarHeight', windowClass.getUIContext().px2vp(area.topRect.height)); + let uiContext: UIContext | undefined = windowStage.getMainWindowSync().getUIContext() + AppStorage.setOrCreate('uiContext', uiContext); }); } diff --git a/entry/src/main/ets/pages/Question.ets b/entry/src/main/ets/pages/Question.ets index e2904abbfe26652142e340f99fcb7608c86cb013..f634a630562685f67a0af7efd4dbf092604a78dc 100644 --- a/entry/src/main/ets/pages/Question.ets +++ b/entry/src/main/ets/pages/Question.ets @@ -30,7 +30,7 @@ export struct Question { let params: Array = this.navPathStack.getParamByName('Question') as Array if (params && params.length > 0) { this.questionTag = params[0]; - this.title =Constants.QUESTION_ARRAY[this.questionTag]; + this.title = Constants.QUESTION_ARRAY[this.questionTag]; } } diff --git a/entry/src/main/ets/pages/Question2Incorrect.ets b/entry/src/main/ets/pages/Question2Incorrect.ets index 45e2c1d87643bbb4be8fa7d6f0c23449f98973fb..a31ad73110a90912e1e9087fc94b8f619c1d61da 100644 --- a/entry/src/main/ets/pages/Question2Incorrect.ets +++ b/entry/src/main/ets/pages/Question2Incorrect.ets @@ -24,9 +24,8 @@ export function Question2IncorrectBuilder() { @Component export struct Question2Incorrect { @State aspect: number = 9 / 16; // default video height/width ratio value - @State xComponentWidth: number = px2vp(display.getDefaultDisplaySync().width); - @State xComponentHeight: number = px2vp(display.getDefaultDisplaySync().width * this.aspect); - // [StartExclude Question2_incorrect] + @State xComponentWidth: number = this.getUIContext().px2vp(display.getDefaultDisplaySync().width); + @State xComponentHeight: number = this.getUIContext().px2vp(display.getDefaultDisplaySync().width * this.aspect); private xComponentController: XComponentController = new XComponentController(); private player?: AVPlayerUtil; @@ -45,8 +44,8 @@ export struct Question2Incorrect { this.player.setSurfaceId(this.xComponentController.getXComponentSurfaceId()); this.player.initPlayer('testVideo2.mp4', (aspect: number) => { this.aspect = aspect; - this.xComponentHeight = px2vp(display.getDefaultDisplaySync().height); - this.xComponentWidth = px2vp(display.getDefaultDisplaySync().height * aspect); + this.xComponentHeight = this.getUIContext().px2vp(display.getDefaultDisplaySync().height); + this.xComponentWidth = this.getUIContext().px2vp(display.getDefaultDisplaySync().height * aspect); }); }) // [EndExclude Question2_incorrect] diff --git a/entry/src/main/ets/pages/Question4Correct.ets b/entry/src/main/ets/pages/Question4Correct.ets index 1cca5d65b10482b505c4aaa13e015203533158ea..92a2aad59a8c75ccb98f54a5b0f34e14eb04a051 100644 --- a/entry/src/main/ets/pages/Question4Correct.ets +++ b/entry/src/main/ets/pages/Question4Correct.ets @@ -74,7 +74,7 @@ export struct Question4Correct { .height(40) .width('100%') .onClick(() => { - promptAction.openCustomDialog({ + this.getUIContext().getPromptAction().openCustomDialog({ builder: () => { this.customDialogComp(); } diff --git a/entry/src/main/ets/pages/Question4Incorrect.ets b/entry/src/main/ets/pages/Question4Incorrect.ets index be7591b5411bad5189c1946a3b60844804050c09..ee6b8af7a24afdc7b9b34cdc1c31e7b37d282797 100644 --- a/entry/src/main/ets/pages/Question4Incorrect.ets +++ b/entry/src/main/ets/pages/Question4Incorrect.ets @@ -71,7 +71,7 @@ export struct Question4Incorrect { .height(40) .width('100%') .onClick(() => { - promptAction.openCustomDialog({ + this.getUIContext().getPromptAction().openCustomDialog({ builder: () => { this.customDialogComp(); } diff --git a/entry/src/main/ets/pages/Question7Correct.ets b/entry/src/main/ets/pages/Question7Correct.ets index 7851ff5f106aca96fd196780c78fe751ed81481e..6c1c20b3442720c672cb69bedc922b985443c029 100644 --- a/entry/src/main/ets/pages/Question7Correct.ets +++ b/entry/src/main/ets/pages/Question7Correct.ets @@ -23,7 +23,7 @@ export function Question7CorrectBuilder() { // [Start Question7_correct] @Component export struct Question7Correct { - private windowClass = (getContext(this) as common.UIAbilityContext).windowStage.getMainWindowSync(); + private windowClass = (this.getUIContext().getHostContext() as common.UIAbilityContext).windowStage.getMainWindowSync(); @State topSafeHeight: number = 0; @State windowStatus: WindowStatusType = window.WindowStatusType.FULL_SCREEN; @@ -32,13 +32,13 @@ export struct Question7Correct { this.windowStatus = this.windowClass.getWindowStatus(); if (this.windowStatus === window.WindowStatusType.FLOATING) { - this.topSafeHeight = px2vp(this.windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height); + this.topSafeHeight = this.getUIContext().px2vp(this.windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height); } this.windowClass.on('windowStatusChange', data => { if (data === window.WindowStatusType.FLOATING) { this.topSafeHeight = - px2vp(this.windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height); + this.getUIContext().px2vp(this.windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height); } else { this.topSafeHeight = 0; } @@ -64,7 +64,7 @@ export struct Question7Correct { top: this.topSafeHeight + 5 }) .onClick(() => { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: 'Action success' }); }) diff --git a/entry/src/main/ets/pages/Question7Incorrect.ets b/entry/src/main/ets/pages/Question7Incorrect.ets index 51dcd1cb125daa29fc553a59dc36d6e51c5df866..e60a4026e588e58bd24d7effd614341dcbce384e 100644 --- a/entry/src/main/ets/pages/Question7Incorrect.ets +++ b/entry/src/main/ets/pages/Question7Incorrect.ets @@ -23,7 +23,7 @@ export function Question7IncorrectBuilder() { // [Start Question7_incorrect] @Component export struct Question7Incorrect { - private windowClass = (getContext(this) as common.UIAbilityContext).windowStage.getMainWindowSync(); + private windowClass = (this.getUIContext().getHostContext() as common.UIAbilityContext).windowStage.getMainWindowSync(); aboutToAppear(): void { this.windowClass.setSpecificSystemBarEnabled('status', false); @@ -51,7 +51,7 @@ export struct Question7Incorrect { }) // [EndExclude Question7_incorrect] .onClick(() => { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: 'Action success' }); }) diff --git a/entry/src/main/ets/pages/Question8Correct.ets b/entry/src/main/ets/pages/Question8Correct.ets index 0cdccfb91fab705e3cfbade19e5a4244f69ad3e2..4d18e81ae7a6caaed2bc3e0db7870355489fa84f 100644 --- a/entry/src/main/ets/pages/Question8Correct.ets +++ b/entry/src/main/ets/pages/Question8Correct.ets @@ -23,7 +23,7 @@ export function Question8CorrectBuilder() { // [Start Question8_correct] @Component export struct Question8Correct { - private windowClass = (getContext(this) as common.UIAbilityContext).windowStage.getMainWindowSync(); + private windowClass = (this.getUIContext().getHostContext() as common.UIAbilityContext).windowStage.getMainWindowSync(); aboutToAppear(): void { this.windowClass.enableLandscapeMultiWindow();