diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 76d975f7811ad311c25d197ac30d1dd98e02d3ea..424c6aaf47ee6bf4ac9aeda17a863033bbf1a51a 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -32,9 +32,17 @@ export default class EntryAbility extends UIAbility { windowUtil?: WindowUtil = WindowUtil.getInstance(); isFirstCreated: boolean = true; // [EndExclude WindowSizeChange] + // [Start Bp2] + // [Start SelectCamera2] + // [Start SelectCamera4] + // [Start Preview2] onWindowSizeChange: (windowSize: window.Size) => void = (windowSize: window.Size) => { + // [StartExclude SelectCamera4] // [StartExclude WindowSizeChange] + // [StartExclude SelectCamera2] + // [StartExclude Preview2] this.setOrientation(this.uiContext!.px2vp(windowSize.width), this.uiContext!.px2vp(windowSize.height)); + // [StartExclude Bp2] AppStorage.setOrCreate('windowSize', windowSize); let widthBp: WidthBreakpoint = this.uiContext!.getWindowWidthBreakpoint(); AppStorage.setOrCreate('widthBp', widthBp); @@ -45,25 +53,36 @@ export default class EntryAbility extends UIAbility { // [EndExclude WindowSizeChange] let isFront: boolean | undefined = AppStorage.get('isFront'); let surfaceId: string | undefined = AppStorage.get('surfaceId'); + // [EndExclude SelectCamera4] // In the trifold M state, select the back camera. + // [EndExclude Preview2] if (widthBp === WidthBreakpoint.WIDTH_MD && heightBp === HeightBreakpoint.HEIGHT_MD && deviceInfo.productSeries === 'GRL') { this.cameraUtil?.cameraShooting(surfaceId!, this.context!, camera.CameraPosition.CAMERA_POSITION_BACK); return; } + // [StartExclude SelectCamera4] // [StartExclude WindowSizeChange] + // [StartExclude Preview2] if (widthBp === WidthBreakpoint.WIDTH_SM && heightBp === HeightBreakpoint.HEIGHT_MD) { // When switching to a wide folding external screen, onForeground() will be triggered. return; } // [EndExclude WindowSizeChange] + // [EndExclude SelectCamera2] + // [EndExclude Preview2] 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); } + // [EndExclude SelectCamera4] + // [EndExclude Bp2] } + // [End SelectCamera2] // [StartExclude WindowSizeChange] + // [End SelectCamera4] + // [End Preview2] 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,6 +93,7 @@ export default class EntryAbility extends UIAbility { } } + // [StartExclude Bp2] onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); @@ -83,23 +103,29 @@ export default class EntryAbility extends UIAbility { hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); } + // [EndExclude Bp2] // [EndExclude WindowSizeChange] onWindowStageCreate(windowStage: window.WindowStage): void { + // [StartExclude Bp2] // [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] + // [EndExclude Bp2] windowStage.loadContent('pages/Index', (err) => { + // [StartExclude Bp2] // [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 Bp2] // [EndExclude WindowSizeChange] windowStage.getMainWindow().then((data: window.Window) => { + // [StartExclude Bp2] // [StartExclude WindowSizeChange] this.windowData = data; data.setWindowLayoutFullScreen(true); @@ -118,9 +144,10 @@ export default class EntryAbility extends UIAbility { // Monitor window size changes and update breakpoints. data.on('windowSizeChange', this.onWindowSizeChange); // [StartExclude WindowSizeChange] + AppStorage.setOrCreate('isBackground', false); + // [EndExclude Bp2] 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}`); @@ -128,6 +155,7 @@ export default class EntryAbility extends UIAbility { }); } // [StartExclude WindowSizeChange] + // [End Bp2] onWindowStageDestroy(): void { // Main window is destroyed, release UI related resources diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index f37da75414c6db974d79d7c3601d9e359650eb50..db56c0d8b6d2f5f01525e15ddc324d5538aa5b24 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -70,17 +70,23 @@ struct Index { } // [End FoldStatusChange] + // [Start SelectCamera1] aboutToAppear(): void { + // [StartExclude SelectCamera1] display.on('foldStatusChange', this.onFoldStatusChange); + // [EndExclude SelectCamera1] // Apply to the user for permission to access the camera and gallery. abilityAccessCtrl.createAtManager().requestPermissionsFromUser(this.context, this.permissions).then(() => { setTimeout(() => { // After obtaining permission, load the camera preview stream and ensure it is consistent with the aspect ratio of the surface. + // [StartExclude SelectCamera1] this.cameraUtil?.setSurfaceProfile(this.xComponentController, this.getUIContext()); + // [EndExclude SelectCamera1] this.cameraUtil?.cameraShooting(this.surfaceId, this.context!, camera.CameraPosition.CAMERA_POSITION_BACK); }, 200); }) } + // [End SelectCamera1] aboutToDisappear(): void { display.off('foldStatusChange'); @@ -89,23 +95,29 @@ struct Index { build() { Navigation() { + // [Start Bp1] // [Start CameraPage] Stack() { // Camera View. Column() { // [Start SetSurfaceRotation] + // [Start Preview3] XComponent({ type: XComponentType.SURFACE, controller: this.xComponentController }) {} + // [StartExclude Bp1] // [StartExclude CameraPage] .onLoad(() => { + // [StartExclude Preview3] // [StartExclude SetSurfaceRotation] this.surfaceId = this.xComponentController.getXComponentSurfaceId(); + // [EndExclude Preview3] // [EndExclude SetSurfaceRotation] // Set surface to lock direction when screen rotates. this.xComponentController.setXComponentSurfaceRotation({ lock: true }); }) + // [End Preview3] // [End SetSurfaceRotation] .onDestroy(() => { // Release camera session and streams. @@ -114,18 +126,22 @@ struct Index { .width('100%') .height(this.isHalfFolded ? this.creaseRegion[0] : '100%') // [EndExclude CameraPage] + // [EndExclude Bp1] } // [StartExclude CameraPage] .width('100%') .height(this.isHalfFolded ? this.creaseRegion[0] : '') .layoutWeight(this.isHalfFolded ? 0 : 1) + // [StartExclude Bp1] .margin({ bottom: deviceInfo.productSeries !== 'VDE' && this.widthBp === WidthBreakpoint.WIDTH_SM ? 156 : 0 }) // [EndExclude CameraPage] + // [EndExclude Bp1] // Shooting button view. Stack() { // Setting view for sm. Column() { + // [StartExclude Bp1] // [StartExclude CameraPage] SettingButton({ imageButton: $r('app.media.icon_lighting'), @@ -140,6 +156,7 @@ struct Index { text: $r('app.string.setting') }) // [EndExclude CameraPage] + // [EndExclude Bp1] } // [StartExclude CameraPage] .width(this.heightBp === HeightBreakpoint.HEIGHT_MD ? 30 : 48) @@ -151,6 +168,7 @@ struct Index { // Choose music for sm. Row() { + // [StartExclude Bp1] // [StartExclude CameraPage] Image($r('app.media.icon_close')) .width(this.heightBp === HeightBreakpoint.HEIGHT_MD ? 28 : 40) @@ -159,6 +177,7 @@ struct Index { ChooseMusic() // [EndExclude CameraPage] + // [EndExclude Bp1] } .width('100%') .height(this.heightBp === HeightBreakpoint.HEIGHT_MD ? 28 : 40) @@ -171,9 +190,11 @@ struct Index { // Shooting button for sm. Column() { + // [StartExclude Bp1] // [StartExclude CameraPage] ShotAreaSm() // [EndExclude CameraPage] + // [EndExclude Bp1] } .visibility(this.widthBp === WidthBreakpoint.WIDTH_SM ? Visibility.Visible : Visibility.None) .height(this.heightBp === HeightBreakpoint.HEIGHT_MD ? 96 : 132) @@ -182,6 +203,7 @@ struct Index { // Setting view for md/lg. Column() { + // [StartExclude Bp1] // [StartExclude CameraPage] Column() { Image($r('app.media.icon_close')) @@ -220,6 +242,7 @@ struct Index { .width('100%') .padding({ top: this.heightBp === HeightBreakpoint.HEIGHT_MD ? 72 : 60 }) // [EndExclude CameraPage] + // [EndExclude Bp1] } .width(this.widthBp === WidthBreakpoint.WIDTH_MD ? 144 : 152) .height('100%') @@ -232,9 +255,11 @@ struct Index { // Shooting button for md/lg. Column() { + // [StartExclude Bp1] // [StartExclude CameraPage] ShotArea() // [EndExclude CameraPage] + // [EndExclude Bp1] } .width(this.widthBp === WidthBreakpoint.WIDTH_LG && deviceInfo.productSeries === 'GRL' ? 132 : 92) .height('100%') @@ -248,6 +273,7 @@ struct Index { .alignContent(Alignment.BottomEnd) .visibility(this.isHalfFolded ? Visibility.None : Visibility.Visible) // [StartExclude CameraPage] + // [StartExclude Bp1] // Half folded view. Stack() { @@ -324,12 +350,14 @@ struct Index { .alignContent(Alignment.BottomEnd) .visibility(this.isHalfFolded ? Visibility.Visible : Visibility.None) // [EndExclude CameraPage] + // [EndExclude Bp1] } .height('100%') .width('100%') .alignContent(this.widthBp === WidthBreakpoint.WIDTH_MD ? (this.isHalfFolded ? Alignment.Top : Alignment.Start) : Alignment.Center) // [End CameraPage] + // [End Bp1] } .height('100%') .width('100%') diff --git a/entry/src/main/ets/utils/CameraUtil.ets b/entry/src/main/ets/utils/CameraUtil.ets index dc338862bcf03bfe2abe82803e99bb1af3de5555..4e99eda66a9c4c8200f1be1d3a08825f7d4df5a1 100644 --- a/entry/src/main/ets/utils/CameraUtil.ets +++ b/entry/src/main/ets/utils/CameraUtil.ets @@ -107,7 +107,9 @@ export class CameraUtil { return; } + // [Start SelectCamera3] getCamera(cameras: Array, cameraPosition: camera.CameraPosition): number { + // [StartExclude SelectCamera3] let widthBp: WidthBreakpoint | undefined = AppStorage.get('widthBp'); let heightBp: HeightBreakpoint | undefined = AppStorage.get('heightBp'); // Three fold M-mode cannot use the front camera. @@ -115,6 +117,7 @@ export class CameraUtil { deviceInfo.productSeries === 'GRL') { cameraPosition = camera.CameraPosition.CAMERA_POSITION_BACK; } + // [EndExclude SelectCamera3] // Choose front or rear camera. for (let i: number = 0; i < cameras.length; ++i) { if (cameras[i].cameraPosition === cameraPosition) { @@ -136,6 +139,7 @@ export class CameraUtil { } return 0; } + // [End SelectCamera3] // [Start GetProfile] getProfile(profileArray: camera.Profile[]): camera.Profile { @@ -282,6 +286,7 @@ export class CameraUtil { this.uiContext = uiContext; } + // [Start Preview1] // [Start SetXComponentRect] setXComponentRect(windowSize: window.Size): void { let creaseRegion: number[] | undefined = AppStorage.get('creaseRegion'); @@ -290,6 +295,7 @@ export class CameraUtil { surfaceWidth: windowSize.width, surfaceHeight: windowSize.height }; + // [StartExclude Preview1] // [StartExclude SetXComponentRect] // Set the width and height of the half folded page surface. if (AppStorage.get('isHalfFolded')) { @@ -299,6 +305,7 @@ export class CameraUtil { return; } // [EndExclude SetXComponentRect] + // [EndExclude Preview1] let widthBp: WidthBreakpoint = this.uiContext!.getWindowWidthBreakpoint(); let heightBp: HeightBreakpoint = this.uiContext!.getWindowHeightBreakpoint(); let displayOrientation: display.Orientation = display.getDefaultDisplaySync().orientation; @@ -342,4 +349,5 @@ export class CameraUtil { this.xComponentController!.setXComponentSurfaceRect(rect); } // [End SetXComponentRect] + // [End Preview1] } \ No newline at end of file