Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
zhangbo1_wd
2024-06-04 11:22:34 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
877cf36d4f2d51897a1b56af5117d3f5bf5e4fd4
877cf36d
1 parent
37274794
应用设置全屏。
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
45 deletions
sight_harmony/commons/wdKit/src/main/ets/utils/DeviceUtil.ets
sight_harmony/commons/wdKit/src/main/ets/utils/WindowModel.ets
sight_harmony/products/phone/src/main/ets/entryability/EntryAbility.ets
sight_harmony/commons/wdKit/src/main/ets/utils/DeviceUtil.ets
View file @
877cf36
...
...
@@ -98,4 +98,8 @@ export class DeviceUtil {
static isTablet(): boolean {
return deviceInfo.deviceType == 'tablet';
}
static is2in1(): boolean {
return deviceInfo.deviceType == '2in1';
}
}
...
...
sight_harmony/commons/wdKit/src/main/ets/utils/WindowModel.ets
View file @
877cf36
...
...
@@ -43,6 +43,9 @@ export class WindowModel {
return this.windowClass as window.Window
}
/**
* @deprecated 应用整体全屏,不需要再设置全屏与否了。
*/
setMainWindowFullScreen(fullScreen: boolean) {
if (deviceInfo.deviceType != "phone") {
return
...
...
@@ -140,6 +143,9 @@ export class WindowModel {
return this.windowClass?.getWindowProperties()
}
/**
* @deprecated 应用整体全屏,不需要再设置全屏与否了。
*/
setWindowLayoutFullScreen(isFullScreen: boolean) {
this.isFullScreen = isFullScreen
this.windowClass?.setWindowLayoutFullScreen(isFullScreen)
...
...
sight_harmony/products/phone/src/main/ets/entryability/EntryAbility.ets
View file @
877cf36
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import app from '@system.app';
import hilog from '@ohos.hilog';
import UIAbility from '@ohos.app.ability.UIAbility';
import Want from '@ohos.app.ability.Want';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';
import { DeviceUtil, EmitterEventId, EmitterUtils, WindowModel } from 'wdKit';
import { DeviceUtil, EmitterEventId, EmitterUtils,
Logger,
WindowModel } from 'wdKit';
import { ConfigurationConstant } from '@kit.AbilityKit';
import { StartupManager } from '../startupmanager/StartupManager';
import { UIContext } from '@ohos.arkui.UIContext';
let floatWindowClass: window.Window | null = null;
const TAG = 'EntryAbility'
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
StartupManager.sharedInstance().appOnCreate(want, launchParam, this.context)
hilog.info(0x0000, 'testTag', '%{public}s'
, 'Ability onCreate');
Logger.info(TAG
, 'Ability onCreate');
// 还没深色模式需求,暂直接不跟随系统。
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT);
...
...
@@ -32,13 +31,13 @@ export default class EntryAbility extends UIAbility {
}
onDestroy(): void {
hilog.info(0x0000, 'testTag', '%{public}s'
, 'Ability onDestroy');
Logger.info(TAG
, 'Ability onDestroy');
StartupManager.sharedInstance().appOnDestory()
}
onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s'
, 'Ability onWindowStageCreate');
Logger.info(TAG
, 'Ability onWindowStageCreate');
WindowModel.shared.setWindowStage(windowStage);
// 2. 获取布局避让遮挡的区域
const windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
...
...
@@ -57,72 +56,50 @@ export default class EntryAbility extends UIAbility {
// 音频悬浮窗初始移动位置604为ui高度
let initMoveY = vp2px(604)
// 在普通phone/折叠屏/tablet设备上以沉浸式(全屏)启动
if (DeviceUtil.isPhone() || DeviceUtil.isTablet()) {
// 设置窗口的布局是否为沉浸式布局
// 沉浸式布局是指布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
// 非沉浸式布局是指布局避让状态栏与导航栏,组件不会与其重叠。
// windowClass.setWindowLayoutFullScreen(true)
// 设置窗口全屏模式时窗口内导航栏、状态栏的属性
// windowClass.setWindowSystemBarProperties({
// statusBarContentColor: "#FFFFFF"
// })
// 设置启动时窗口的显示方向属性,
// 普通phone以PORTRAIT/竖屏显示模式启动
// 折叠屏和tablet是以AUTO_ROTATION_RESTRICTED/受开关控制的自动旋转模式启动
WindowModel.shared.setPreferredOrientation(window.Orientation.PORTRAIT)
.then(() => {
hilog.info(0x0000, 'testTag', 'setPreferredOrientation Succeeded');
})
.catch((err: Error) => {
hilog.error(0x0000, 'testTag',
`setPreferredOrientation catch, error error.name : ${err.name}, error.message:${err.message}`);
})
}
this.onWindowSetup(windowClass)
//../../../../../../features/wdLogin/src/main/ets/pages/launchPage/LaunchPage
windowStage.loadContent('pages/launchPage/LaunchPage', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s',
JSON.stringify(err) ?? '');
Logger.error(TAG, 'Failed to load the content. Cause: ' +
JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
Logger.info(TAG, 'Succeeded in loading the content. Data: ' +
JSON.stringify(data) ?? '');
});
// 1.创建悬浮窗
windowStage.createSubWindow('subWindow', (err: BusinessError, data) => {
let errCode: number = err.code;
if (errCode) {
console
.error('floatWindowClass Failed to create the subwindow. Cause: ' + JSON.stringify(err));
Logger
.error('floatWindowClass Failed to create the subwindow. Cause: ' + JSON.stringify(err));
return;
}
console
.info('floatWindowClass Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
Logger
.info('floatWindowClass Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
floatWindowClass = data;
AppStorage.setOrCreate('floatWindowClass', floatWindowClass);
// 2.悬浮窗窗口创建成功后,设置悬浮窗的位置、大小及相关属性等。
floatWindowClass.moveWindowTo(0, initMoveY, (err: BusinessError) => {
let errCode: number = err.code;
if (errCode) {
console
.error('floatWindowClass Failed to move the window. Cause:' + JSON.stringify(err));
Logger
.error('floatWindowClass Failed to move the window. Cause:' + JSON.stringify(err));
return;
}
console
.info('floatWindowClass Succeeded in moving the window.');
Logger
.info('floatWindowClass Succeeded in moving the window.');
});
// 3.为悬浮窗加载对应的目标页面。
floatWindowClass.setUIContent("pages/view/AudioComponent", (err: BusinessError) => {
let errCode: number = err.code;
if (errCode) {
console
.error('floatWindowClass Failed to load the content. Cause:' + JSON.stringify(err));
Logger
.error('floatWindowClass Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console
.info('floatWindowClass Succeeded in loading the content.');
Logger
.info('floatWindowClass Succeeded in loading the content.');
let color: string = 'rgba(0,0,0,0)';
try {
(floatWindowClass as window.Window).setWindowBackgroundColor(color);
} catch (exception) {
console.error('Failed to set the background color. Cause: ' + JSON.stringify(exception));
};
Logger.error('Failed to set the background color. Cause: ' + JSON.stringify(exception));
}
;
});
floatWindowClass.on('windowEvent', (data) => {
...
...
@@ -132,33 +109,68 @@ export default class EntryAbility extends UIAbility {
});
}
public async onWindowSetup(mainWindow: window.Window) {
// 在普通phone/折叠屏/tablet设备上以沉浸式(全屏)启动
if (DeviceUtil.isPhone() || DeviceUtil.isTablet()) {
// 设置窗口的布局是否为沉浸式布局
// 沉浸式布局是指布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
// 非沉浸式布局是指布局避让状态栏与导航栏,,组件不会与其重叠
mainWindow.setWindowLayoutFullScreen(true)
//设置窗口全屏模式时窗口内导航栏、状态栏的属性
mainWindow.setWindowSystemBarProperties({
//statusBarColor:'#000000'
statusBarContentColor: '#FFFFFF'
})
mainWindow.setSpecificSystemBarEnabled('status', true)
// 设置启动时窗口的显示方向属性,
// 普通phone以PORTRAIT/竖屏显示模式启动
// 折叠屏和tablet是以AUTO_ROTATION_RESTRICTED/受开关控制的自动旋转模式启动
WindowModel.shared.setPreferredOrientation(window.Orientation.PORTRAIT)
.then(() => {
Logger.info(TAG, 'setPreferredOrientation Succeeded');
})
.catch((err: Error) => {
Logger.info(TAG,
`setPreferredOrientation catch, error error.name : ${err.name}, error.message:${err.message}`);
})
} else if (DeviceUtil.is2in1()) {
// 2in1(PC)设备不支持旋转(无横竖屏模式),会以默认窗口(非全屏)显示模式启动Logger.info(TAG,`start at 2in1 window device )
Logger.info(TAG, 'start at 2in1 window device')
} else {
// 轻量级智能穿戴/lite wearable device
Logger.info(TAG, 'start at other type device')
}
}
destroyFloatWindow() {
(floatWindowClass as window.Window).destroyWindow((err: BusinessError) => {
let errCode: number = err.code;
if (errCode) {
console
.error('floatWindowClass Failed to destroy the window. Cause: ' + JSON.stringify(err));
Logger
.error('floatWindowClass Failed to destroy the window. Cause: ' + JSON.stringify(err));
return;
}
console
.info('floatWindowClass Succeeded in destroying the window.');
Logger
.info('floatWindowClass Succeeded in destroying the window.');
});
}
onWindowStageDestroy(): void {
// Main window is destroyed, release UI related resources
this.destroyFloatWindow()
hilog.info(0x0000, 'testTag', '%{public}s'
, 'Ability onWindowStageDestroy');
Logger.info(TAG
, 'Ability onWindowStageDestroy');
}
onForeground(): void {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s'
, 'Ability onForeground');
Logger.info(TAG
, 'Ability onForeground');
EmitterUtils.sendEmptyEvent(EmitterEventId.APP_ENTER_FOREGROUD)
}
onBackground(): void {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s'
, 'Ability onBackground');
Logger.info(TAG
, 'Ability onBackground');
EmitterUtils.sendEmptyEvent(EmitterEventId.APP_ENTER_BACKGROUD)
}
...
...
Please
register
or
login
to post a comment