diff --git a/build-profile.json5 b/build-profile.json5 index c033ce4278fb0641d84107c3c134047ac487368e..e8de1a3cb6ba71c60762653ebac9cfdc1cfa0132 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -5,7 +5,7 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.0(12)", + "compatibleSdkVersion": "5.0.4(16)", "runtimeOS": "HarmonyOS", } ], diff --git a/entry/src/main/ets/common/utils/MediaUtils.ets b/entry/src/main/ets/common/utils/MediaUtils.ets index 4e9b3bdc395b8d3d064d716019b5f0dc718c3b0d..174b316958450c85d9ce893e565ed79dad5413ff 100644 --- a/entry/src/main/ets/common/utils/MediaUtils.ets +++ b/entry/src/main/ets/common/utils/MediaUtils.ets @@ -18,7 +18,8 @@ import { photoAccessHelper } from '@kit.MediaLibraryKit'; import { fileIo } from '@kit.CoreFileKit'; import Logger from './Logger'; -let context = getContext(this) as common.Context; +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); +let context = uiContext?.getHostContext() as common.Context; interface Result { prefix: string, diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 8b1b5b5c5fd75e9c4aa90374b454618720f567ca..0c19c0b7f86749167ad263ccca785145e6edb4a4 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -37,6 +37,7 @@ export default class EntryAbility extends UIAbility { // Main window is created, set main page for this ability hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageCreate'); windowStage.loadContent('pages/Index', (err, data) => { + AppStorage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); if (err.code) { hilog.error(0x0000, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 0a9e1298f21f02600e7b9970a8e0633da1689489..23bfa07d1bae681d6ecbdf1134f794dc1e48af00 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -30,7 +30,8 @@ import { SettingDataObj } from '../common/Constants'; import DisplayCalculator from '../common/DisplayCalculator'; const TAG: string = 'UI indexPage'; -let context = getContext(this) as common.UIAbilityContext; +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); +let context = uiContext?.getHostContext() as common.UIAbilityContext; @Entry @Component @@ -82,15 +83,15 @@ struct Index { videoFrame: 0, referenceLineBol: false }; - private appContext: common.Context = getContext(this); + private appContext: common.Context = this.getUIContext().getHostContext()!; atManager = abilityAccessCtrl.createAtManager(); // Entry initialization function. async aboutToAppear() { await this.requestPermissionsFn(); let mDisplay = display.getDefaultDisplaySync(); - this.screenWidth = px2vp(mDisplay.width); - this.screenHeight = px2vp(mDisplay.height); + this.screenWidth = this.getUIContext().px2vp(mDisplay.width); + this.screenHeight = this.getUIContext().px2vp(mDisplay.height); this.initXComponentSize(); } diff --git a/entry/src/main/ets/views/ModeSwitchPage.ets b/entry/src/main/ets/views/ModeSwitchPage.ets index 1d7bc72bb5f9467f18ca517aded2e596392c83e7..29c614b3ff2d5ee98826f1096382fd179c4acf4f 100644 --- a/entry/src/main/ets/views/ModeSwitchPage.ets +++ b/entry/src/main/ets/views/ModeSwitchPage.ets @@ -27,7 +27,8 @@ import MediaUtils from '../common/utils/MediaUtils'; import { SettingDataObj } from '../common/Constants' import { Constants } from '../common/Constants' -let context = getContext(this) as common.UIAbilityContext; +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); +let context = uiContext?.getHostContext() as common.UIAbilityContext; interface PhotoSettings { quality: number, // Photo quality @@ -347,17 +348,17 @@ export struct ModeSwitchPage { Row() { if (this.modelBagCol === Constants.PHOTO) { Image(this.thumbnail || $r('app.media.camera_thumbnail_4x')) - .borderRadius(px2vp(Constants.ICON_SIZE / 2)) + .borderRadius(this.getUIContext().px2vp(Constants.ICON_SIZE / 2)) .syncLoad(true) .objectFit(ImageFit.Fill) - .width(px2vp(Constants.ICON_SIZE)) - .height(px2vp(Constants.ICON_SIZE)) + .width(this.getUIContext().px2vp(Constants.ICON_SIZE)) + .height(this.getUIContext().px2vp(Constants.ICON_SIZE)) } else { Image(this.thumbnail || $r('app.media.camera_thumbnail_4x')) - .borderRadius(px2vp(Constants.ICON_SIZE / 2)) + .borderRadius(this.getUIContext().px2vp(Constants.ICON_SIZE / 2)) .objectFit(ImageFit.Fill) - .width(px2vp(Constants.ICON_SIZE)) - .height(px2vp(Constants.ICON_SIZE)) + .width(this.getUIContext().px2vp(Constants.ICON_SIZE)) + .height(this.getUIContext().px2vp(Constants.ICON_SIZE)) } } .onClick(() => { @@ -382,16 +383,16 @@ export struct ModeSwitchPage { Row() { if (this.modelBagCol === Constants.PHOTO) { Image($r('app.media.camera_take_photo_4x')) - .width(px2vp(Constants.ICON_SIZE)) - .height(px2vp(Constants.ICON_SIZE)) + .width(this.getUIContext().px2vp(Constants.ICON_SIZE)) + .height(this.getUIContext().px2vp(Constants.ICON_SIZE)) .onClick(() => { // Countdown camera recording - default camera recording. this.countTakeVideoFn(); }) } else { Image($r('app.media.camera_take_video_4x')) - .width(px2vp(Constants.ICON_SIZE)) - .height(px2vp(Constants.ICON_SIZE)) + .width(this.getUIContext().px2vp(Constants.ICON_SIZE)) + .height(this.getUIContext().px2vp(Constants.ICON_SIZE)) .onClick(() => { // Countdown camera recording - default camera recording. this.countTakeVideoFn(); @@ -405,8 +406,8 @@ export struct ModeSwitchPage { Column() { Row() { Image($r('app.media.camera_switch_4x')) - .width(px2vp(Constants.ICON_SIZE)) - .height(px2vp(Constants.ICON_SIZE)) + .width(this.getUIContext().px2vp(Constants.ICON_SIZE)) + .height(this.getUIContext().px2vp(Constants.ICON_SIZE)) .onClick(async () => { // Switching cameras. this.cameraDeviceIndex ? this.cameraDeviceIndex = 0 : this.cameraDeviceIndex = 1; @@ -422,8 +423,8 @@ export struct ModeSwitchPage { Column() { // Video capture button. Image($r('app.media.camera_take_photo_4x')) - .width(px2vp(Constants.ICON_SIZE)) - .height(px2vp(Constants.ICON_SIZE)) + .width(this.getUIContext().px2vp(Constants.ICON_SIZE)) + .height(this.getUIContext().px2vp(Constants.ICON_SIZE)) .onClick(() => { cameraDemo.takePictureWithSettings(this.photoSettings); }) @@ -436,8 +437,8 @@ export struct ModeSwitchPage { // video stop button. Image($r('app.media.camera_pause_video_4x')) .size({ width: $r('app.float.video_stop_size'), height: $r('app.float.video_stop_size') }) - .width(px2vp(Constants.ICON_SIZE)) - .height(px2vp(Constants.ICON_SIZE)) + .width(this.getUIContext().px2vp(Constants.ICON_SIZE)) + .height(this.getUIContext().px2vp(Constants.ICON_SIZE)) .id('StopVideo') .onClick(() => { if (this.timer) { @@ -451,8 +452,8 @@ export struct ModeSwitchPage { }) } } - .width(px2vp(Constants.ICON_SIZE)) - .height(px2vp(Constants.ICON_SIZE)) + .width(this.getUIContext().px2vp(Constants.ICON_SIZE)) + .height(this.getUIContext().px2vp(Constants.ICON_SIZE)) }.position({ x: Constants.CAPTURE_X_POSITION, y: Constants.ICON_Y_POSITION }) } }