未验证 提交 2bf6da9a 编写于 作者: O openharmony_ci 提交者: Gitee

!2349 Done! 1957:add windowmanager doc

Merge pull request !2349 from wusongqing/TR1957
上级 9b418403 70af6f5e
master E0523 OpenHarmony-3.1-API8-SDK-Public OpenHarmony-3.2-Beta1 OpenHarmony-3.2-Beta2 OpenHarmony-3.2-Beta3 OpenHarmony-3.2-Beta4 OpenHarmony-3.2-Beta5 OpenHarmony-3.2-Release OpenHarmony-4.0-Beta1 OpenHarmony-4.0-Beta2 OpenHarmony_filemanager_develop_20220505 OpenHarmony_filemanager_develop_20220614 TR4270 bak_OpenHarmony-4.0-Beta1_20230529 docs-modify feature_IDL_20220811 monthly_20220614 monthly_20220816 monthly_20221018 monthly_20230815 revert-merge-17651-master revert-merge-19334-OpenHarmony-4.0-Beta1 revert-merge-19586-master revert-merge-20613-master revert-merge-21757-OpenHarmony-4.0-Beta2 revert-merge-21765-OpenHarmony-4.0-Beta2 revert-merge-23766-master revert-merge-5580-master update_master_0323 weekly_20220406 weekly_20220412 weekly_20220419 weekly_20220426 weekly_20220503 weekly_20220510 weekly_20220524 weekly_20220531 weekly_20220607 weekly_20220614 weekly_20220621 weekly_20220628 weekly_20220705 weekly_20220712 weekly_20220719 weekly_20220726 weekly_20220802 weekly_20220809 weekly_20220816 weekly_20220823 weekly_20220830 weekly_20220906 weekly_20220913 weekly_20220920 weekly_20220927 weekly_20221004 weekly_20221011 weekly_20221018 weekly_20221025 weekly_20221101 weekly_20221108 weekly_20221115 weekly_20221122 weekly_20221129 weekly_20221206 weekly_20221213 weekly_20221220 weekly_20221227 weekly_20230103 weekly_20230110 weekly_20230117 weekly_20230124 weekly_20230131 weekly_20230207 weekly_20230214 weekly_20230221 weekly_20230228 weekly_20230307 weekly_20230314 weekly_20230321 weekly_20230328 weekly_20230404 weekly_20230411 weekly_20230418 weekly_20230425 weekly_20230502 weekly_20230509 weekly_20230516 weekly_20230523 weekly_20230530 weekly_20230606 weekly_20230613 weekly_20230619 weekly_20230626 weekly_20230627 weekly_20230704 weekly_20230712 weekly_20230725 weekly_20230801 weekly_20230808 weekly_20230815 weekly_20230822 weekly_20230829 weekly_20230905 OpenHarmony-v4.0-Beta2 OpenHarmony-v4.0-Beta1 OpenHarmony-v3.2.3-Release OpenHarmony-v3.2.2-Release OpenHarmony-v3.2.1-Release OpenHarmony-v3.2-Release OpenHarmony-v3.2-Beta5 OpenHarmony-v3.2-Beta4 OpenHarmony-v3.2-Beta3 OpenHarmony-v3.2-Beta2 OpenHarmony-v3.2-Beta1 OpenHarmony-v3.1.7-Release OpenHarmony-v3.1.6-Release OpenHarmony-v3.1.5-Release OpenHarmony-v3.1.4-Release OpenHarmony-v3.1.3-Release OpenHarmony-v3.1.2-Release OpenHarmony-v3.1.1-Release OpenHarmony-v3.1-Release
无相关合并请求
......@@ -20,6 +20,7 @@
- [Data Management](database/Readme-EN.md)
- [Device](device/Readme-EN.md)
- [DFX](dfx/Readme-EN.md)
- [Window Manager](windowmanager/Readme-EN.md)
- Tools
- [DevEco Studio \(OpenHarmony\) User Guide](quick-start/deveco-studio-user-guide-for-openharmony.md)
- Hands-On Tutorials
......
# Window Manager
* Window
* [Window Overview](window-overview.md)
* [Window Development](window-guidelines.md)
* Display
* [Display Overview](display-overview.md)
* [Display Development](display-guidelines.md)
* Screenshot
* [Screenshot Overview](screenshot-overview.md)
* [Screenshot Development](screenshot-guidelines.md)
# Display Development
## When to Use
An application can obtain the default display object or all display objects by calling the **Display** APIs.
## Available APIs
For details about the APIs, see [Display](../reference/apis/js-apis-display.md).
### How to Develop
Call **getDefaultDisplay(): Promise<Display>** to obtain the default display object. An example code snippet is as follows:
```js
import display from '@ohos.display' // Import the module.
let disp; // disp is used to save the default display object.
display.getDefaultDisplay().then((disp) => {
console.log('display.getDefaultDisplay success, display :' + JSON.stringify(disp));
}, (err) => {
console.log('display.getDefaultDisplay failed, error : ' + JSON.stringify(err));
})
```
# Display Overview
The **Display** APIs present the window layout of an application. The display attributes include the display ID, name, active status, state, refresh rate, rotation angle, width, height, pixel density, font scaling factor, and exact physical dots per inch.
## Basic Concepts
**Display**: a screen visible to an application. It can be used as a window container. It is an abstract concept that is different from a physical screen.
# Screenshot Development
## When to Use
You can specify a display device to take screenshots, with screenshot parameters specified.
## Available APIs
For details about the APIs, see [Screenshot](../reference/apis/js-apis-screenshot.md).
## How to Develop
Call **save(options?: ScreenshotOptions): Promise<image.PixelMap>** to take a screenshot. In this API, **options** is a predefined screenshot parameter. If **options** is unspecified, the entire screen is captured by default. An example code snippet is as follows:
```js
import screenshot from '@ohos.screenshot' // Import the module.
// Set screenshot parameters.
var ScreenshotOptions = {
"screenRect": {
"left": 200,
"top": 100,
"width": 200,
"height": 200},
"imageSize": {
"width": 300,
"height": 300},
"rotation": 0
};
let image; // image is used to save the screenshot.
screenshot.save(ScreenshotOptions).then((image) => {
console.log('screenshot.save success, screenshot image :' + JSON.stringify(image));
}, (err) => {
console.log('screenshot.save failed, error : ' + JSON.stringify(err));
})
```
# Screenshot Overview
The screenshot APIs, with parameters, enable you to take screenshots on display devices.
## Basic Concepts
Screenshot: provides the screenshot capability.
# Window Development
# When to Use
The interface layer of the window runs in the application process. It loads the page layout and provides APIs.
By calling these APIs, you can create and destroy a window, set the position and size of a window, and enter the immersive mode (full-screen mode).
## Available APIs
For details about the APIs, see [Window](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-window.md).
**Table 1** Main window APIs
| API | Description |
| :----------------------------------------------------------- | :--------------------------------------------- |
| create(id: string, type: WindowType, callback: AsyncCallback\<Window>): void | Creates a subwindow. |
| moveTo(x: number, y: number): Promise\<void> | Moves the window position. A positive value of **x** indicates that the window moves to the right, and a positive value of **y** indicates that the window moves downwards.|
| resetSize(width: number, height: number): Promise\<void> | Changes the window size. |
| hide(): Promise\<void> | Hides the window. |
| destroy(): Promise\<void> | Destroys the window. |
## How to Develop
### Creating a Main Window
Currently, the main window is automatically created when the application is started. The declaration period, hiding, and destruction of the main window are managed by the application.
###Creating a Subwindow
You can call **create** to create a subwindow. The sample code is as follows:
```
import window from '@ohos.window';
var windowClass = null;
let promise = window.create("subWindow", window.WindowType.TYPE_APP);
promise.then((data)=> {
windowClass = data;
console.info('SubWindow created. Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err));
});
```
### Obtaining a Window Object
- Call **getTopWindow** to obtain the top window of the application. The sample code is as follows:
```
var windowClass = null;
let promise = window.getTopWindow();
promise.then((data)=> {
windowClass = data;
console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
})
```
- You can also call **find** to obtain created subwindows in the application. The sample code is as follows:
```
var windowClass = null;
let promise = window.find("subWindow");
promise.then((data)=> {
windowClass = data;
console.info('window found. Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.error('Failed to find the Window. Cause: ' + JSON.stringify(err));
});
```
### Hiding and Destroying a Window
After a window object is obtained, you can call **hide** and **destroy** to hide and destroy the window object, respectively. The sample code is as follows:
```
let promise = windowClass.hide();
promise.then((data)=> {
console.info('window hidden. Data: ' + JSON.stringify(data))
windowClass.destroy((err, data) => {
if (err.code) {
console.error('Failed to destroy the window. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in destroying the window. Data: ' + JSON.stringify(data))
})
}).catch((err)=>{
console.error('Failed to hide the window. Cause: ' + JSON.stringify(err));
})
```
### Enabling the Full-Screen Mode
After a window object is obtained,
- call **setFullScreen** to enable the full-screen mode for the window.
The sample code is as follows:
```
import window from '@ohos.window';
.onClick(async () => {
try {
const win = await window.getTopWindow()
await win.setFullScreen(true)
} catch (err) {
console.log(`setFullScreen fail, code = ${err.code}`)
}
})
```
For the complete code, see [immersive](https://gitee.com/openharmony/windowmanager/tree/master/AppDemo/window/immersive).
# Window Overview
The Window Manager subsystem provides basic capabilities of window and display management. It is the basis for UI display.
The Window Manager subsystem enables multiple applications to use the same physical screen for display and interaction. For each application, you only need to implement the interaction interface in the allocated display area. A window acts as a display container of the application interface, and the Window Manager subsystem organizes the interaction interfaces into a form visible to end users.
## Basic Concepts
**Immersive**
The colors of the application interface, status bar, and navigation bar are the same to achieve the visual integrity.
## Working Principles
To display a UI on a screen, the application and system need to request a window object from the Window Manager subsystem. This object generally represents a rectangular area on the screen and has attributes such as the position, width, height, and overlay layer. The object also loads the root node of the UI framework in the interface. The UI of the application is loaded and displayed in the window through the root node.
## Constraints
Except the **on** and **off** APIs used for callback subscription and unsubscription, all other window APIs are asynchronous interfaces.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部