From 31208419796f1e66060625bd76949811422bc449 Mon Sep 17 00:00:00 2001 From: "OWNEROR-41FNVD0\\lenovo" Date: Thu, 8 May 2025 15:02:15 +0800 Subject: [PATCH] =?UTF-8?q?=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 --- .../main/ets/entryability/EntryAbility.ets | 2 +- entry/src/main/ets/pages/Index.ets | 33 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 3c54dc8..78b0b23 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -46,7 +46,7 @@ export default class EntryAbility extends UIAbility { onForeground(): void { // Ability has brought to foreground - fromBack(); + fromBack(this.context); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); } diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index c4a3179..d796fd9 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -44,6 +44,7 @@ import { import display from '@ohos.display'; import { curves } from '@kit.ArkUI'; import { sensor } from '@kit.SensorServiceKit'; +import { Context } from '@ohos.arkui.UIContext'; let cameraPosition = 0; let surfaceId = ''; @@ -51,7 +52,6 @@ let zoomRatioRange: number[] = []; let isVideo = false; let qualityLevel: number = 0; let storage = new LocalStorage(); -let context = getContext(this); let videoUri: string; let foldAbleStatus: number = 0; let currentFov: number = 1; @@ -83,9 +83,10 @@ struct XComponentPage { textTimerController: TextTimerController = new TextTimerController(); @State rotation: number = 0; @State isShowZoom: boolean = false; + @State context: Context = this.getUIContext().getHostContext()!; onPageShow(): void { - filePreview.closePreview(context); + filePreview.closePreview(this.context); } async aboutToAppear() { @@ -105,7 +106,7 @@ struct XComponentPage { this.rotation = camera.ImageRotation.ROTATION_90; } }) - abilityAccessCtrl.createAtManager().requestPermissionsFromUser(context, this.permissions).then(() => { + abilityAccessCtrl.createAtManager().requestPermissionsFromUser(this.context, this.permissions).then(() => { setTimeout(async () => { if (this.isFoldAble) { foldAbleStatus = display.getFoldStatus(); @@ -123,11 +124,11 @@ struct XComponentPage { surfaceHeight: this.isFoldAble && foldAbleStatus === FoldStatus.FOLD_STATUS_EXPANDED ? 1400 : display.getDefaultDisplaySync().width * (this.isPhoto ? 4 / 3 : 16 / 9) }) - cameraShooting(isVideo, cameraPosition, surfaceId, context, foldAbleStatus); + cameraShooting(isVideo, cameraPosition, surfaceId, this.context, foldAbleStatus); }, 500) }) } - zoomRatioRange = await cameraShooting(isVideo, cameraPosition, surfaceId, context, foldAbleStatus); + zoomRatioRange = await cameraShooting(isVideo, cameraPosition, surfaceId, this.context, foldAbleStatus); }, 200); }); @@ -158,7 +159,7 @@ struct XComponentPage { .animation({ curve: curves.springMotion() }) .onClick(() => { this.isStabilization = !this.isStabilization; - videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, context, foldAbleStatus); + videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, this.context, foldAbleStatus); isVideo = true; }); Image(this.isMovingPhoto ? $r('app.media.live_photo_on') : $r('app.media.live_photo_off')) @@ -237,7 +238,7 @@ struct XComponentPage { action: (): void => { qualityLevel = 0; stopRecordPreview(); - videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, context, + videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, this.context, foldAbleStatus); } }, @@ -246,7 +247,7 @@ struct XComponentPage { action: (): void => { qualityLevel = 1; stopRecordPreview(); - videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, context, + videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, this.context, foldAbleStatus); } } @@ -361,7 +362,7 @@ struct XComponentPage { isVideo = false; stopRecordPreview(); this.Initialize(); - cameraShooting(isVideo, cameraPosition, surfaceId, context, foldAbleStatus); + cameraShooting(isVideo, cameraPosition, surfaceId, this.context, foldAbleStatus); } }) Text($r('app.string.Video')) @@ -374,7 +375,7 @@ struct XComponentPage { releaseCamera(); // 1080P this.Initialize(); - videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, context, + videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, this.context, foldAbleStatus); isVideo = true; } @@ -398,7 +399,7 @@ struct XComponentPage { .animation({ curve: curves.springMotion() }) .onClick(() => { if (this.photoUri !== '') { - this.currentPic ? previewPhoto(context) : previewVideo(context, videoUri); + this.currentPic ? previewPhoto(this.context) : previewVideo(this.context, videoUri); } }) Stack() { @@ -429,7 +430,7 @@ struct XComponentPage { this.flashPic = $r('app.media.ic_camera_public_flash_off'); videoUri = await stopRecord(); stopRecordPreview(); - videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, context, + videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, this.context, foldAbleStatus); setTimeout(() => { this.getThumbnail(); @@ -446,10 +447,10 @@ struct XComponentPage { cameraPosition = cameraPosition === 1 ? 0 : 1 if (this.isPhoto) { - cameraShooting(isVideo, cameraPosition, surfaceId, context, foldAbleStatus); + cameraShooting(isVideo, cameraPosition, surfaceId, this.context, foldAbleStatus); } else { stopRecordPreview(); - videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, context, + videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, this.context, foldAbleStatus); } this.Initialize(); @@ -503,7 +504,7 @@ struct XComponentPage { fetchColumns: [], predicates: predicates }; - let photoHelper = photoAccessHelper.getPhotoAccessHelper(context); + let photoHelper = photoAccessHelper.getPhotoAccessHelper(this.context); let fetchResult: photoAccessHelper.FetchResult = await photoHelper.getAssets(fetchOptions); if (fetchResult !== undefined) { @@ -513,7 +514,7 @@ struct XComponentPage { } } -export async function fromBack(): Promise { +export async function fromBack(context: Context): Promise { storage.setOrCreate('flashPic', $r('app.media.ic_camera_public_flash_off')); storage.setOrCreate('zoom', 1); currentFov = 1; -- Gitee