diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index eda7630558c3dc53bea1b4e17d3ff88330cee397..1a1855ebf7516ee5f93f2fbdaaaad9e84625bae1 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -23,13 +23,17 @@ import { WindowUtil } from '../utils/WindowUtil'; const DOMAIN = 0x0000; +// [Start WindowSizeChange] export default class EntryAbility extends UIAbility { + // [StartExclude WindowSizeChange] windowData?: window.Window; uiContext?: UIContext; cameraUtil?: CameraUtil = CameraUtil.getInstance(); windowUtil?: WindowUtil = WindowUtil.getInstance(); isFirstCreated: boolean = true; + // [EndExclude WindowSizeChange] onWindowSizeChange: (windowSize: window.Size) => void = (windowSize: window.Size) => { + // [StartExclude WindowSizeChange] this.setOrientation(this.uiContext!.px2vp(windowSize.width), this.uiContext!.px2vp(windowSize.height)); AppStorage.setOrCreate('windowSize', windowSize); let widthBp: WidthBreakpoint = this.uiContext!.getWindowWidthBreakpoint(); @@ -38,6 +42,7 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('heightBp', heightBp); let displayOrientation: display.Orientation = display.getDefaultDisplaySync().orientation; AppStorage.setOrCreate('displayOrientation', displayOrientation); + // [EndExclude WindowSizeChange] let isFront: boolean | undefined = AppStorage.get('isFront'); let surfaceId: string | undefined = AppStorage.get('surfaceId'); if (widthBp === WidthBreakpoint.WIDTH_MD && heightBp === HeightBreakpoint.HEIGHT_MD && @@ -45,16 +50,19 @@ export default class EntryAbility extends UIAbility { this.cameraUtil?.cameraShooting(surfaceId!, this.context!, camera.CameraPosition.CAMERA_POSITION_BACK); return; } + // [StartExclude WindowSizeChange] if (widthBp === WidthBreakpoint.WIDTH_SM && heightBp === HeightBreakpoint.HEIGHT_MD) { // When switching to a wide folding external screen, onForeground() will be triggered. return; } + // [EndExclude WindowSizeChange] if (isFront) { this.cameraUtil?.cameraShooting(surfaceId!, this.context!, camera.CameraPosition.CAMERA_POSITION_FRONT); } else { this.cameraUtil?.cameraShooting(surfaceId!, this.context!, camera.CameraPosition.CAMERA_POSITION_BACK); } } + // [StartExclude WindowSizeChange] setOrientation(width: number, height: number): void { // When the minimum value of window width and height is greater than the md breakpoint threshold, rotation is supported. @@ -74,18 +82,24 @@ export default class EntryAbility extends UIAbility { hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); } + // [EndExclude WindowSizeChange] onWindowStageCreate(windowStage: window.WindowStage): void { + // [StartExclude WindowSizeChange] // Main window is created, set main page for this ability hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); this.windowUtil!.setWindowStage(windowStage); + // [EndExclude WindowSizeChange] windowStage.loadContent('pages/Index', (err) => { + // [StartExclude WindowSizeChange] if (err.code) { hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); return; } hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + // [EndExclude WindowSizeChange] windowStage.getMainWindow().then((data: window.Window) => { + // [StartExclude WindowSizeChange] this.windowData = data; data.setWindowLayoutFullScreen(true); data.setWindowSystemBarEnable([]); @@ -99,16 +113,20 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('heightBp', heightBp); let displayOrientation: display.Orientation = display.getDefaultDisplaySync().orientation; AppStorage.setOrCreate('displayOrientation', displayOrientation); + // [EndExclude WindowSizeChange] // Monitor window size changes and update breakpoints. data.on('windowSizeChange', this.onWindowSizeChange); + // [StartExclude WindowSizeChange] let rect: window.Rect = data.getWindowProperties().windowRect; this.setOrientation(this.uiContext.px2vp(rect.width), this.uiContext.px2vp(rect.height)); AppStorage.setOrCreate('isBackground', false); + // [EndExclude WindowSizeChange] }).catch((err: BusinessError) => { hilog.error(0x0000, 'testTag', `Error occured, error code: ${err.code}, error message: ${err.message}`); }) }); } + // [StartExclude WindowSizeChange] onWindowStageDestroy(): void { // Main window is destroyed, release UI related resources @@ -136,4 +154,6 @@ export default class EntryAbility extends UIAbility { this.cameraUtil?.releaseCamera(); AppStorage.setOrCreate('isBackground', true); } -} \ No newline at end of file + // [EndExclude WindowSizeChange] +} +// [End WindowSizeChange] \ 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 418c208bb2ef61f29e3a4585fc7692336ef07121..38971b30371dd1d5cca6153f3aa8107fd31de11b 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -42,6 +42,7 @@ struct Index { 'ohos.permission.READ_IMAGEVIDEO', 'ohos.permission.WRITE_IMAGEVIDEO' ]; + // [Start FoldStatusChange] onFoldStatusChange: (foldStatus: display.FoldStatus) => void = (foldStatus: display.FoldStatus) => { if (foldStatus === display.FoldStatus.FOLD_STATUS_HALF_FOLDED) { let orientation: display.Orientation = display.getDefaultDisplaySync().orientation; @@ -66,6 +67,7 @@ struct Index { } } }; + // [End FoldStatusChange] aboutToAppear(): void { display.on('foldStatusChange', this.onFoldStatusChange); @@ -86,34 +88,44 @@ struct Index { build() { Navigation() { + // [Start CameraPage] Stack() { // Camera View. Column() { + // [Start SetSurfaceRotation] XComponent({ type: XComponentType.SURFACE, controller: this.xComponentController }) {} + // [StartExclude CameraPage] .onLoad(async () => { + // [StartExclude SetSurfaceRotation] this.surfaceId = this.xComponentController.getXComponentSurfaceId(); + // [EndExclude SetSurfaceRotation] // Set surface to lock direction when screen rotates. this.xComponentController.setXComponentSurfaceRotation({ lock: true }); }) + // [End SetSurfaceRotation] .onDestroy(() => { // Release camera session and streams. this.cameraUtil?.releaseCamera(); }) .width('100%') .height(this.isHalfFolded ? this.creaseRegion[0] : '100%') + // [EndExclude CameraPage] } + // [StartExclude CameraPage] .width('100%') .height(this.isHalfFolded ? this.creaseRegion[0] : '') .layoutWeight(this.isHalfFolded ? 0 : 1) .margin({ bottom: deviceInfo.productSeries !== 'VDE' && this.widthBp === WidthBreakpoint.WIDTH_SM ? 156 : 0 }) + // [EndExclude CameraPage] // Shooting button view. Stack() { // Setting view for sm. Column() { + // [StartExclude CameraPage] SettingButton({ imageButton: $r('app.media.icon_lighting'), text: $r('app.string.flashlight') @@ -126,21 +138,26 @@ struct Index { imageButton: $r('app.media.icon_setting'), text: $r('app.string.setting') }) + // [EndExclude CameraPage] } + // [StartExclude CameraPage] .width(this.heightBp === HeightBreakpoint.HEIGHT_MD ? 30 : 48) .height('100%') .margin({ right: 16 }) .padding({ top: this.heightBp === HeightBreakpoint.HEIGHT_MD ? 16 : 108 }) + // [EndExclude CameraPage] .visibility(this.widthBp === WidthBreakpoint.WIDTH_SM ? Visibility.Visible : Visibility.None) // Choose music for sm. Row() { + // [StartExclude CameraPage] Image($r('app.media.icon_close')) .width(this.heightBp === HeightBreakpoint.HEIGHT_MD ? 28 : 40) .height(this.heightBp === HeightBreakpoint.HEIGHT_MD ? 28 : 40) .position({ x: 16, y: 0 }) ChooseMusic() + // [EndExclude CameraPage] } .width('100%') .height(this.heightBp === HeightBreakpoint.HEIGHT_MD ? 28 : 40) @@ -153,7 +170,9 @@ struct Index { // Shooting button for sm. Column() { + // [StartExclude CameraPage] ShotAreaSm() + // [EndExclude CameraPage] } .visibility(this.widthBp === WidthBreakpoint.WIDTH_SM ? Visibility.Visible : Visibility.None) .height(this.heightBp === HeightBreakpoint.HEIGHT_MD ? 96 : 132) @@ -162,6 +181,7 @@ struct Index { // Setting view for md/lg. Column() { + // [StartExclude CameraPage] Column() { Image($r('app.media.icon_close')) .width(40) @@ -198,6 +218,7 @@ struct Index { .layoutWeight(1) .width('100%') .padding({ top: this.heightBp === HeightBreakpoint.HEIGHT_MD ? 72 : 60 }) + // [EndExclude CameraPage] } .width(this.widthBp === WidthBreakpoint.WIDTH_MD ? 144 : 152 ) .height('100%') @@ -206,23 +227,26 @@ struct Index { .position({ x: 0, y: 0 }) .alignItems(HorizontalAlign.Start) .visibility(this.widthBp === WidthBreakpoint.WIDTH_MD || this.widthBp === WidthBreakpoint.WIDTH_LG ? - Visibility.Visible : Visibility.None) + Visibility.Visible : Visibility.None) // Shooting button for md/lg. Column() { + // [StartExclude CameraPage] ShotArea() + // [EndExclude CameraPage] } .width(this.widthBp === WidthBreakpoint.WIDTH_LG && deviceInfo.productSeries === 'GRL' ? 132 : 92) .height('100%') .justifyContent(FlexAlign.Center) .padding({ right: this.widthBp === WidthBreakpoint.WIDTH_LG && deviceInfo.productSeries === 'GRL' ? 56 : 16 }) .visibility(this.widthBp === WidthBreakpoint.WIDTH_MD || this.widthBp === WidthBreakpoint.WIDTH_LG ? - Visibility.Visible : Visibility.None) + Visibility.Visible : Visibility.None) } .height('100%') .width('100%') .alignContent(Alignment.BottomEnd) .visibility(this.isHalfFolded ? Visibility.None : Visibility.Visible) + // [StartExclude CameraPage] // Half folded view. Stack() { @@ -298,11 +322,13 @@ struct Index { .height('100%') .alignContent(Alignment.BottomEnd) .visibility(this.isHalfFolded ? Visibility.Visible : Visibility.None) + // [EndExclude CameraPage] } .height('100%') .width('100%') .alignContent(this.widthBp === WidthBreakpoint.WIDTH_MD ? (this.isHalfFolded ? Alignment.Top : Alignment.Start) : - Alignment.Center) + Alignment.Center) + // [End CameraPage] } .height('100%') .width('100%') diff --git a/entry/src/main/ets/utils/CameraUtil.ets b/entry/src/main/ets/utils/CameraUtil.ets index 75f05b37bbedeeec70f2f88ab291ae87a386f652..61b439af77bca2aeb1067899cf2fa62b9bfabf70 100644 --- a/entry/src/main/ets/utils/CameraUtil.ets +++ b/entry/src/main/ets/utils/CameraUtil.ets @@ -137,6 +137,7 @@ export class CameraUtil { return 0; } + // [Start GetProfile] getProfile(profileArray: camera.Profile[]): camera.Profile { // Return profile based on breakpoint. let widthBp: WidthBreakpoint | undefined = AppStorage.get('widthBp'); @@ -164,6 +165,7 @@ export class CameraUtil { } return resProfile; } + // [End GetProfile] setPhotoOutputCb(): void { this.photoOutput!.on('photoAssetAvailable', async (err: BusinessError, photoAsset: photoAccessHelper.PhotoAsset): @@ -183,10 +185,11 @@ export class CameraUtil { }) } + // [Start Capture] capture(): void { let rotation: number = -1; // Obtain the angle of the gravity sensor during shooting and set the shooting rotation angle. - sensor.once(sensor.SensorId.GRAVITY, async (data: sensor.GravityResponse) => { + sensor.once(sensor.SensorId.GRAVITY, (data: sensor.GravityResponse) => { let degree: number = this.getCalDegree(data.x, data.y, data.z); let isFront: boolean | undefined = AppStorage.get('isFront'); if (degree >= 0 && (degree <= 30 || degree >= 300)) { @@ -220,6 +223,7 @@ export class CameraUtil { this.photoOutput?.capture(setting); }) } + // [End Capture] async releaseCamera(): Promise { if (this.photoSession) { @@ -278,6 +282,7 @@ export class CameraUtil { this.uiContext = uiContext; } + // [Start SetXComponentRect] setXComponentRect(windowSize: window.Size): void { let creaseRegion: number[] | undefined = AppStorage.get('creaseRegion'); // Initialize the width and height of the surface to match the full screen of the window. @@ -285,6 +290,7 @@ export class CameraUtil { surfaceWidth: windowSize.width, surfaceHeight: windowSize.height }; + // [StartExclude SetXComponentRect] // Set the width and height of the half folded page surface. if (AppStorage.get('isHalfFolded')) { rect.surfaceHeight = this.uiContext!.vp2px(creaseRegion![0]); @@ -292,6 +298,7 @@ export class CameraUtil { this.xComponentController!.setXComponentSurfaceRect(rect); return; } + // [EndExclude SetXComponentRect] let widthBp: WidthBreakpoint = this.uiContext!.getWindowWidthBreakpoint(); let heightBp: HeightBreakpoint = this.uiContext!.getWindowHeightBreakpoint(); let displayOrientation: display.Orientation = display.getDefaultDisplaySync().orientation; @@ -307,11 +314,13 @@ export class CameraUtil { rect.offsetY = 0; rect.surfaceWidth = windowSize.height / 4 * 3; } + // [StartExclude SetXComponentRect] // Landscape for tablet. else if (widthBp === WidthBreakpoint.WIDTH_LG && heightBp === HeightBreakpoint.HEIGHT_SM && deviceInfo.productSeries !== 'GRL') { rect.surfaceWidth = windowSize.height / 3 * 4; } + // [EndExclude SetXComponentRect] // Portrait for Mate XT G-mode. else if (widthBp === WidthBreakpoint.WIDTH_MD && heightBp === HeightBreakpoint.HEIGHT_LG && deviceInfo.productSeries === 'GRL') { @@ -322,12 +331,15 @@ export class CameraUtil { deviceInfo.productSeries === 'GRL') { rect.surfaceWidth = windowSize.height / 4 * 3; } + // [StartExclude SetXComponentRect] // Pura X external screen. else if (widthBp === WidthBreakpoint.WIDTH_SM && heightBp === HeightBreakpoint.HEIGHT_MD) {} + // [EndExclude SetXComponentRect] // Portrait for phone and tablet. else { rect.surfaceHeight = windowSize.width / 3 * 4; } this.xComponentController!.setXComponentSurfaceRect(rect); } + // [End SetXComponentRect] } \ No newline at end of file