From 0942fc43693e16d8b4ebfe1e54968ed9b349bae2 Mon Sep 17 00:00:00 2001 From: kuangning <2540487435@qq.com> Date: Wed, 7 May 2025 15:30:59 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9Aapi=E5=8D=87=E7=BA=A7=E8=87=B316?= =?UTF-8?q?=EF=BC=8C=E5=BA=9F=E5=BC=83api=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 2 +- entry/src/main/ets/entryability/EntryAbility.ets | 1 + entry/src/main/ets/mode/CameraService.ets | 6 ++++-- entry/src/main/ets/pages/EditPage.ets | 4 ++-- entry/src/main/ets/pages/Index.ets | 8 ++++---- entry/src/main/ets/views/ModeComponent.ets | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/build-profile.json5 b/build-profile.json5 index cde2069..651829e 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/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 58891ad..8486004 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -48,6 +48,7 @@ export default class EntryAbility extends UIAbility { }); this.requestPermissionsFn(); windowStage.loadContent('pages/Index', (err, data) => { + AppStorage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); if (err.code) { Logger.info(TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; diff --git a/entry/src/main/ets/mode/CameraService.ets b/entry/src/main/ets/mode/CameraService.ets index a72acb8..7831756 100644 --- a/entry/src/main/ets/mode/CameraService.ets +++ b/entry/src/main/ets/mode/CameraService.ets @@ -25,6 +25,8 @@ import { Constants } from '../common/Constants'; const TAG: string = 'CameraService'; +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); + export class SliderValue { min: number = 1; max: number = 6; @@ -309,7 +311,7 @@ class CameraService { async saveCameraPhoto(asset: photoAccessHelper.PhotoAsset) { Logger.info('saveCameraPhoto'); try { - let context = getContext(this); + let context = uiContext?.getHostContext(); let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); @@ -694,7 +696,7 @@ class CameraService { initFd(): number { Logger.info(TAG, 'initFd is called'); - let filesDir = getContext().filesDir; + let filesDir = uiContext?.getHostContext()!.filesDir; let filePath = filesDir + `/${Date.now()}.mp4`; AppStorage.setOrCreate('filePath', filePath); let file: fileIo.File = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); diff --git a/entry/src/main/ets/pages/EditPage.ets b/entry/src/main/ets/pages/EditPage.ets index b82ed45..8cd2886 100644 --- a/entry/src/main/ets/pages/EditPage.ets +++ b/entry/src/main/ets/pages/EditPage.ets @@ -81,7 +81,7 @@ struct EditPage { let curPhotoAsset = GlobalContext.get().getT('photoAsset'); this.photoUri = curPhotoAsset.uri; let requestImageParams: RequestImageParams = { - context: getContext(), + context: this.getUIContext().getHostContext(), photoAsset: curPhotoAsset, callback: this.photoBufferCallback }; @@ -105,7 +105,7 @@ struct EditPage { Logger.info(TAG, 'back onClick'); // delete video file when router back fileIo.unlink(this.videoUri); - router.back(); + this.getUIContext().getRouter().back(); }) .width(Constants.BACK_ICON_SIZE) .height(Constants.BACK_ICON_SIZE) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 6ab5473..6d19405 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -93,8 +93,8 @@ struct Index { color: Color.Black }) // The width and height of the surface are opposite to those of the Xcomponent. - .width(px2vp(Constants.X_COMPONENT_SURFACE_HEIGHT)) - .height(px2vp(Constants.X_COMPONENT_SURFACE_WIDTH)) + .width(this.getUIContext().px2vp(Constants.X_COMPONENT_SURFACE_HEIGHT)) + .height(this.getUIContext().px2vp(Constants.X_COMPONENT_SURFACE_WIDTH)) } // Exposure frame and focus frame. FocusComponent({ @@ -106,8 +106,8 @@ struct Index { FocusAreaComponent({ focusPointBol: $focusPointBol, focusPointVal: $focusPointVal, - xComponentWidth: px2vp(Constants.X_COMPONENT_SURFACE_HEIGHT), - xComponentHeight: px2vp(Constants.X_COMPONENT_SURFACE_WIDTH) + xComponentWidth: this.getUIContext().px2vp(Constants.X_COMPONENT_SURFACE_HEIGHT), + xComponentHeight: this.getUIContext().px2vp(Constants.X_COMPONENT_SURFACE_WIDTH) }) // slide SlideComponent() diff --git a/entry/src/main/ets/views/ModeComponent.ets b/entry/src/main/ets/views/ModeComponent.ets index ad2480a..9c171fe 100644 --- a/entry/src/main/ets/views/ModeComponent.ets +++ b/entry/src/main/ets/views/ModeComponent.ets @@ -55,7 +55,7 @@ export struct ModeComponent { onJumpClick(): void { GlobalContext.get().setObject('sceneMode', this.sceneMode); - router.pushUrl({ url: 'pages/EditPage' }, router.RouterMode.Single, (err) => { + this.getUIContext().getRouter().pushUrl({ url: 'pages/EditPage' }, router.RouterMode.Single, (err) => { if (err) { Logger.error(TAG, `Invoke pushUrl failed, code is ${err.code}, message is ${err.message}`); return; -- Gitee