diff --git a/commons/base/Index.ets b/commons/base/Index.ets index 396165d76aea900335e1c37f4ecd81a3d61f15b8..3a628f1e047874e4bf21574a212a7b319942ad6b 100644 --- a/commons/base/Index.ets +++ b/commons/base/Index.ets @@ -1 +1 @@ -export { WindowInfo, WindowUtil } from './src/main/ets/utils/WindowUtil'; +export { ImmersiveType, WindowInfo, WindowUtil } from './src/main/ets/utils/WindowUtil'; diff --git a/commons/base/src/main/ets/utils/WindowUtil.ets b/commons/base/src/main/ets/utils/WindowUtil.ets index 3b0367ed311e2ca2d4130d6342b4f3e42bd1fed6..727370be1a1cca7bcc5c41e73a780753a8099a73 100644 --- a/commons/base/src/main/ets/utils/WindowUtil.ets +++ b/commons/base/src/main/ets/utils/WindowUtil.ets @@ -229,6 +229,7 @@ export class WindowUtil { // [EndExclude updateBreakpoint] // [EndExclude WindowSizeChange] // [EndExclude getWindowAvoidArea] + AppStorage.setOrCreate('mainWindowInfo', this.mainWindowInfo); } catch (error) { let err = error as BusinessError; hilog.error(0x0000, `TestLog`, `Failed to update window info. Code: ${err.code}, message: ${err.message}`); diff --git a/features/home/src/main/ets/pages/Home.ets b/features/home/src/main/ets/pages/Home.ets index 10917108b4ecfd71b6fa6208314f39d3f2361476..795dcc8818461bc7298faded9bc9d2302c1b1d7c 100644 --- a/features/home/src/main/ets/pages/Home.ets +++ b/features/home/src/main/ets/pages/Home.ets @@ -157,7 +157,7 @@ export struct Home { }) .padding({ bottom: this.mainWindowInfo.widthBp === WidthBreakpoint.WIDTH_LG ? 0 : - AppStorage.get('naviIndicatorHeight') as number - 10 + this.getUIContext().px2vp(this.mainWindowInfo.AvoidNavigationIndicator?.bottomRect.height) }) } .width('100%') diff --git a/features/home/src/main/ets/pages/OptionPage.ets b/features/home/src/main/ets/pages/OptionPage.ets index 756f3695062ede770336e8569546c6642fa5f49e..3eb08ed08923037941b8d01676004953e4fd3c3f 100644 --- a/features/home/src/main/ets/pages/OptionPage.ets +++ b/features/home/src/main/ets/pages/OptionPage.ets @@ -236,7 +236,7 @@ export struct OptionPage { .height('100%') .padding({ top: this.mainWindowInfo.widthBp === WidthBreakpoint.WIDTH_SM && - this.mainWindowInfo.heightBp === HeightBreakpoint.HEIGHT_MD ? 16 : AppStorage.get('statusBarHeight') + this.mainWindowInfo.heightBp === HeightBreakpoint.HEIGHT_MD ? 16 : this.getUIContext().px2vp(this.mainWindowInfo.AvoidSystem?.topRect.height) }) } } \ No newline at end of file diff --git a/features/stockdetail/src/main/ets/pages/StockDetailsPage.ets b/features/stockdetail/src/main/ets/pages/StockDetailsPage.ets index 84d5d101e2d308cc1adc64573bf89ef4b101301d..84f0ee48189255f6d1dff68232bd79fbf41419c3 100644 --- a/features/stockdetail/src/main/ets/pages/StockDetailsPage.ets +++ b/features/stockdetail/src/main/ets/pages/StockDetailsPage.ets @@ -38,7 +38,6 @@ export struct StockDetailsPage { @State closeInfoCarousel: boolean = false; private scroller: Scroller = new Scroller(); private cardList: number[] = [1, 2, 3]; - private windowClass: window.Window = AppStorage.get('windowClass')!; private isHiding: boolean = false; @Provide('isFirstBulletBox') isFirstBulletBox: boolean = true; @Provide('popUpBoxIsShow') @Watch('bindSheetMonitor') popUpBoxIsShow: boolean = false; @@ -61,14 +60,6 @@ export struct StockDetailsPage { } } - isOverlayMethod(statusBarColor: string): void { - let SystemBarProperties: window.SystemBarProperties; - SystemBarProperties = { statusBarColor: statusBarColor }; - this.windowClass.setWindowSystemBarProperties(SystemBarProperties).catch((err: BusinessError) => { - hilog.error(0x0000, 'StockDetailsView', - `setWindowSystemBarProperties failed, error code=${err.code}, message=${err.message}`); - }); - } @Builder myBuilder() { @@ -101,7 +92,6 @@ export struct StockDetailsPage { Column() { // Stock details information StockDetailsInfo({ stockInForm: this.stockInForm }) - // Stock Notification Row() { Row() { @@ -344,7 +334,7 @@ export struct StockDetailsPage { .backgroundColor(Color.White) .padding({ top: this.mainWindowInfo.widthBp === WidthBreakpoint.WIDTH_SM && - this.mainWindowInfo.heightBp === HeightBreakpoint.HEIGHT_MD ? 0 : AppStorage.get('statusBarHeight') + this.mainWindowInfo.heightBp === HeightBreakpoint.HEIGHT_MD ? 0 : this.getUIContext().px2vp(this.mainWindowInfo.AvoidSystem?.topRect.height) }) .onBackPressed(() => { if (this.tabletMode === NavigationMode.Stack) { diff --git a/products/phone/src/main/ets/entryability/EntryAbility.ets b/products/phone/src/main/ets/entryability/EntryAbility.ets index e4aa5787748db79d2109e7dee3da920099d6d723..566160efe4cb1d1b1537bd4f25deb7b308cbbfe5 100644 --- a/products/phone/src/main/ets/entryability/EntryAbility.ets +++ b/products/phone/src/main/ets/entryability/EntryAbility.ets @@ -18,22 +18,11 @@ import { resourceManager } from '@kit.LocalizationKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { window } from '@kit.ArkUI'; import Logger from '@ohos/commons/src/main/ets/utils/Logger'; -import { WindowInfo, WindowUtil } from '@ohos/commons'; +import { ImmersiveType, WindowUtil } from '@ohos/commons'; export default class EntryAbility extends UIAbility { windowUtil?: WindowUtil private windowObj?: window.Window; - private windowStage?: window.WindowStage; - private onWindowSizeChange: (windowSize: window.Size) => void = () => { - this.windowUtil!.updateWindowInfo(); - let mainWindowInfo: WindowInfo | undefined = this.windowUtil?.mainWindowInfo; - AppStorage.setOrCreate('mainWindowInfo', mainWindowInfo); - // Application adaptation for horizontal and vertical screen switching. - this.windowObj?.setPreferredOrientation(window.Orientation.FOLLOW_DESKTOP).catch((err: BusinessError) => { - Logger.error('EntryAbility', '%{public}s', `setPreferredOrientation failed, code : ${err.code}, message : ${err.message}`); - }); - this.immersionFuc(this.windowStage!); - }; private windowStatusChange: (WindowStatusType: window.WindowStatusType) => void = (WindowStatusType: window.WindowStatusType) => { if (WindowStatusType === window.WindowStatusType.FLOATING || @@ -74,7 +63,6 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('windowUtil', this.windowUtil); let context = this.context; - this.windowStage = windowStage; let resourceManager: resourceManager.ResourceManager = context.resourceManager; AppStorage.setOrCreate('resourceManager', resourceManager); windowStage.loadContent('pages/Index', (err, data) => { @@ -84,9 +72,6 @@ export default class EntryAbility extends UIAbility { } Logger.info('EntryAbility', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - // Immersive Adaptation - this.immersionFuc(windowStage); - const isWindowAvailable = canIUse('SystemCapability.Window.SessionManager'); if (isWindowAvailable) { // Determine the current application window mode. @@ -100,22 +85,14 @@ export default class EntryAbility extends UIAbility { } else { Logger.info('Window not by this device.'); } - windowStage.getMainWindow().then((data: window.Window) => { - try { - this.windowObj = data; - data.on('windowSizeChange', this.onWindowSizeChange); - } catch (error) { - Logger.error(`GetUIContext failed. Cause code: ${err.code}, message: ${err.message}`); - } - }).catch((err: BusinessError) => { - Logger.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); - }); // Application adaptation for horizontal and vertical screen switching. this.windowObj?.setPreferredOrientation(window.Orientation.FOLLOW_DESKTOP).catch((err: BusinessError) => { Logger.error('EntryAbility', '%{public}s', `setPreferredOrientation failed, code : ${err.code}, message : ${err.message}`); }); this.windowUtil!.setUIContext(); + this.windowUtil!.setImmersiveType(ImmersiveType.IMMERSIVE); + this.windowUtil!.setWindowOrientation(window.Orientation.FOLLOW_DESKTOP); this.windowUtil!.updateWindowInfo(); }); @@ -135,26 +112,4 @@ export default class EntryAbility extends UIAbility { // Ability has back to background Logger.info('EntryAbility', '%{public}s', 'Ability onBackground'); } - - /** - * Page immersion. - */ - immersionFuc(windowStage: window.WindowStage): void { - try { - let windowClass: window.Window = windowStage.getMainWindowSync(); - windowClass.setWindowLayoutFullScreen(true).catch((err: BusinessError) => { - Logger.error(`SetWindowLayoutFullScreen failed. Cause code: ${err.code}, message: ${err.message}`); - }); - let navigationBarArea: window.AvoidArea = - windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); - let area: window.AvoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); - AppStorage.setOrCreate('naviIndicatorHeight', - windowClass.getUIContext().px2vp(navigationBarArea.bottomRect.height)); - AppStorage.setOrCreate('statusBarHeight', windowClass.getUIContext().px2vp(area.topRect.height)); - AppStorage.setOrCreate('windowClass', windowClass); - } catch (error) { - let err = error as BusinessError; - Logger.error('EntryAbility', `immersionFuc failed, error code: ${err.code}, message: ${err.message}`); - } - } } \ No newline at end of file diff --git a/products/phone/src/main/ets/splitScreenAbility/SplitScreenAbility.ets b/products/phone/src/main/ets/splitScreenAbility/SplitScreenAbility.ets index 62c806a94c5796368ba30af47923586c61a22cbc..e29c10025e5e330de45c6101e167c49ccb795891 100644 --- a/products/phone/src/main/ets/splitScreenAbility/SplitScreenAbility.ets +++ b/products/phone/src/main/ets/splitScreenAbility/SplitScreenAbility.ets @@ -18,7 +18,7 @@ import { resourceManager } from '@kit.LocalizationKit'; import { BusinessError, emitter } from '@kit.BasicServicesKit'; import { window } from '@kit.ArkUI'; import Logger from '@ohos/commons/src/main/ets/utils/Logger'; -import { WindowUtil } from '@ohos/commons'; +import { ImmersiveType, WindowUtil } from '@ohos/commons'; // [Start SplitAbility] let eventData: emitter.EventData = { @@ -106,8 +106,6 @@ export default class SplitScreenAbility extends UIAbility { } Logger.info('SplitScreenAbility', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - // Immersive Adaptation - this.immersionFuc(windowStage); const isWindowAvailable = canIUse('SystemCapability.Window.SessionManager'); if (isWindowAvailable) { @@ -124,6 +122,8 @@ export default class SplitScreenAbility extends UIAbility { } }); this.windowUtil!.setUIContext(); + this.windowUtil!.setImmersiveType(ImmersiveType.IMMERSIVE); + this.windowUtil!.setWindowOrientation(window.Orientation.FOLLOW_DESKTOP); this.windowUtil!.updateWindowInfo(); } @@ -141,28 +141,6 @@ export default class SplitScreenAbility extends UIAbility { // Ability has back to background Logger.info('SplitScreenAbility', '%{public}s', 'Ability onBackground'); } - - /** - * Page immersion. - */ - immersionFuc(windowStage: window.WindowStage): void { - try { - let windowClass: window.Window = windowStage.getMainWindowSync(); - windowClass.setWindowLayoutFullScreen(true).catch((err: BusinessError) => { - Logger.error(`SetWindowLayoutFullScreen failed. Cause code: ${err.code}, message: ${err.message}`); - }); - let navigationBarArea: window.AvoidArea = - windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); - let area: window.AvoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); - AppStorage.setOrCreate('naviIndicatorHeight', - windowClass.getUIContext().px2vp(navigationBarArea.bottomRect.height)); - AppStorage.setOrCreate('statusBarHeight', windowClass.getUIContext().px2vp(area.topRect.height)); - AppStorage.setOrCreate('windowClass', windowClass); - } catch (error) { - let err = error as BusinessError; - Logger.error('SplitScreenAbility', `immersionFuc failed, error code=${err.code}, message=${err.message}`); - } - } // [EndExclude SplitAbility] } // [End SplitAbility] \ No newline at end of file diff --git a/products/phone/src/main/module.json5 b/products/phone/src/main/module.json5 index 11428e570af9ffbda1f5e53d0b27992284991dc9..aa018c8e95054667adf99499818fbf1a247a0a13 100644 --- a/products/phone/src/main/module.json5 +++ b/products/phone/src/main/module.json5 @@ -38,7 +38,7 @@ } ], "minWindowHeight": 600, - "minWindowWidth": 840 + "minWindowWidth": 1080 }, { "name": "SplitScreenAbility",