zhenghy

页面全屏代码

@@ -82,4 +82,20 @@ export class DeviceUtil { @@ -82,4 +82,20 @@ export class DeviceUtil {
82 static getRandomUUIDForTraceID(): string { 82 static getRandomUUIDForTraceID(): string {
83 return util.generateRandomUUID().toUpperCase().replace(/-/g, '') 83 return util.generateRandomUUID().toUpperCase().replace(/-/g, '')
84 } 84 }
  85 +
  86 + /**
  87 + * 是否为phone设备(可折叠手机即便完全展开状态也返回true)
  88 + * @returns
  89 + */
  90 + static isPhone(): boolean {
  91 + return deviceInfo.deviceType == 'phone' || deviceInfo.deviceType == 'default';
  92 + }
  93 +
  94 + static isNotPhone(): boolean {
  95 + return !DeviceUtil.isPhone();
  96 + }
  97 +
  98 + static isTablet(): boolean {
  99 + return deviceInfo.deviceType == 'tablet';
  100 + }
85 } 101 }
@@ -4,7 +4,7 @@ import UIAbility from '@ohos.app.ability.UIAbility'; @@ -4,7 +4,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
4 import Want from '@ohos.app.ability.Want'; 4 import Want from '@ohos.app.ability.Want';
5 import window from '@ohos.window'; 5 import window from '@ohos.window';
6 import { BusinessError } from '@ohos.base'; 6 import { BusinessError } from '@ohos.base';
7 -import { EmitterEventId, EmitterUtils, WindowModel } from 'wdKit'; 7 +import { DeviceUtil, EmitterEventId, EmitterUtils, WindowModel } from 'wdKit';
8 import { ConfigurationConstant } from '@kit.AbilityKit'; 8 import { ConfigurationConstant } from '@kit.AbilityKit';
9 import { WDPushNotificationManager } from 'wdHwAbility/Index'; 9 import { WDPushNotificationManager } from 'wdHwAbility/Index';
10 import { StartupManager } from '../startupmanager/StartupManager'; 10 import { StartupManager } from '../startupmanager/StartupManager';
@@ -52,16 +52,30 @@ export default class EntryAbility extends UIAbility { @@ -52,16 +52,30 @@ export default class EntryAbility extends UIAbility {
52 console.info('floatWindowClass audioWidth' + audioWidth); 52 console.info('floatWindowClass audioWidth' + audioWidth);
53 53
54 54
55 - // let a = new WindowModel();  
56 - // 设置窗口的显示方向属性  
57 - WindowModel.shared.setPreferredOrientation(window.Orientation.PORTRAIT)  
58 - .then(() => {  
59 - hilog.info(0x0000, 'testTag', 'setPreferredOrientation Succeeded');  
60 - })  
61 - .catch((err: Error) => {  
62 - hilog.error(0x0000, 'testTag',  
63 - `setPreferredOrientation catch, error error.name : ${err.name}, error.message:${err.message}`);  
64 - }) 55 + // 在普通phone/折叠屏/tablet设备上以沉浸式(全屏)启动
  56 + if (DeviceUtil.isPhone() || DeviceUtil.isTablet()) {
  57 + // 设置窗口的布局是否为沉浸式布局
  58 + // 沉浸式布局是指布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
  59 + // 非沉浸式布局是指布局避让状态栏与导航栏,组件不会与其重叠。
  60 + // windowClass.setWindowLayoutFullScreen(true)
  61 + // 设置窗口全屏模式时窗口内导航栏、状态栏的属性
  62 + // windowClass.setWindowSystemBarProperties({
  63 + // statusBarContentColor: "#FFFFFF"
  64 + // })
  65 +
  66 + // 设置启动时窗口的显示方向属性,
  67 + // 普通phone以PORTRAIT/竖屏显示模式启动
  68 + // 折叠屏和tablet是以AUTO_ROTATION_RESTRICTED/受开关控制的自动旋转模式启动
  69 + WindowModel.shared.setPreferredOrientation(window.Orientation.PORTRAIT)
  70 + .then(() => {
  71 + hilog.info(0x0000, 'testTag', 'setPreferredOrientation Succeeded');
  72 + })
  73 + .catch((err: Error) => {
  74 + hilog.error(0x0000, 'testTag',
  75 + `setPreferredOrientation catch, error error.name : ${err.name}, error.message:${err.message}`);
  76 + })
  77 + }
  78 +
65 //../../../../../../features/wdLogin/src/main/ets/pages/launchPage/LaunchPage 79 //../../../../../../features/wdLogin/src/main/ets/pages/launchPage/LaunchPage
66 windowStage.loadContent('pages/launchPage/LaunchPage', (err, data) => { 80 windowStage.loadContent('pages/launchPage/LaunchPage', (err, data) => {
67 if (err.code) { 81 if (err.code) {
@@ -70,7 +84,7 @@ export default class EntryAbility extends UIAbility { @@ -70,7 +84,7 @@ export default class EntryAbility extends UIAbility {
70 } 84 }
71 hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); 85 hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
72 }); 86 });
73 - // 1.创建悬浮窗 87 + // 1.创建悬浮窗
74 // const config: window.Configuration = { 88 // const config: window.Configuration = {
75 // name: "floatWindow", windowType: window.WindowType.TYPE_FLOAT, ctx: this.context 89 // name: "floatWindow", windowType: window.WindowType.TYPE_FLOAT, ctx: this.context
76 // }; 90 // };