未验证 提交 715fe5ca 编写于 作者: O openharmony_ci 提交者: Gitee

!12568 翻译完成:12317 master:windowmanager使用最新接口

Merge pull request !12568 from wusongqing/TR12317
# Window # @ohos.window
The **Window** module provides basic window management capabilities, such as creating and destroying the current window, setting properties for the current window, and managing and scheduling windows. The **Window** module provides basic window management capabilities, such as creating and destroying the current window, setting properties for the current window, and managing and scheduling windows.
...@@ -46,17 +46,15 @@ Enumerates the window types. ...@@ -46,17 +46,15 @@ Enumerates the window types.
## Configuration<sup>9+</sup> ## Configuration<sup>9+</sup>
Defines the parameters used for creating a subwindow. Defines the parameters for creating a subwindow or system window.
An asynchronous callback is used when a system window is created in the case that [ServiceExtensionContext](js-apis-service-extension-context.md) is used as the context.
**System capability**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ---------- | -------------------------- | -- | ----------------------------------- | | ---------- | -------------------------- | -- | ----------------------------------- |
| name | string | Yes| Name of the subwindow. | | name | string | Yes| Name of the window. |
| windowType | [WindowType](#windowtype7) | Yes| Type of the subwindow. | | windowType | [WindowType](#windowtype7) | Yes| Type of the window. |
| ctx | BaseContext | No| Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-service-extension-context.md).<br> If this parameter is not set, no context is used. | | ctx | BaseContext | No| Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md). If this parameter is not set, no context is used.<br>A system window is created when **Context** is [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md).|
| displayId | number | No| ID of the current physical screen. If this parameter is not set, the default value **-1** is used.| | displayId | number | No| ID of the current physical screen. If this parameter is not set, the default value **-1** is used.|
| parentId | number | No| ID of the parent window. If this parameter is not set, the default value **-1** is used. | | parentId | number | No| ID of the parent window. If this parameter is not set, the default value **-1** is used. |
...@@ -302,7 +300,7 @@ Describes the translation parameters. ...@@ -302,7 +300,7 @@ Describes the translation parameters.
createWindow(config: Configuration, callback: AsyncCallback&lt;Window&gt;): void createWindow(config: Configuration, callback: AsyncCallback&lt;Window&gt;): void
Creates a subwindow. This API uses an asynchronous callback to return the result. Creates a subwindow or system window. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
...@@ -310,8 +308,8 @@ Creates a subwindow. This API uses an asynchronous callback to return the result ...@@ -310,8 +308,8 @@ Creates a subwindow. This API uses an asynchronous callback to return the result
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------------------------------------- | -- | --------------------------------- | | -------- | -------------------------------------- | -- | --------------------------------- |
| config | [Configuration](#configuration9) | Yes| Current application context. | | config | [Configuration](#configuration9) | Yes| Parameters used for creating the window. |
| callback | AsyncCallback&lt;[Window](#window)&gt; | Yes| Callback used to return the subwindow created.| | callback | AsyncCallback&lt;[Window](#window)&gt; | Yes| Callback used to return the window created.|
**Error codes** **Error codes**
...@@ -346,7 +344,7 @@ try { ...@@ -346,7 +344,7 @@ try {
createWindow(config: Configuration): Promise&lt;Window&gt; createWindow(config: Configuration): Promise&lt;Window&gt;
Creates a subwindow. This API uses a promise to return the result. Creates a subwindow or system window. This API uses a promise to return the result.
**System capability**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
...@@ -354,13 +352,13 @@ Creates a subwindow. This API uses a promise to return the result. ...@@ -354,13 +352,13 @@ Creates a subwindow. This API uses a promise to return the result.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | -------------------------------- | -- | ------------------ | | ------ | -------------------------------- | -- | ------------------ |
| config | [Configuration](#configuration9) | Yes| Current application context.| | config | [Configuration](#configuration9) | Yes| Parameters used for creating the window.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------------------------------- | ------------------------------------ | | -------------------------------- | ------------------------------------ |
| Promise&lt;[Window](#window)&gt; | Promise used to return the subwindow created.| | Promise&lt;[Window](#window)&gt; | Promise used to return the window created.|
**Error codes** **Error codes**
...@@ -393,7 +391,7 @@ try { ...@@ -393,7 +391,7 @@ try {
findWindow(name: string): Window findWindow(name: string): Window
Finds a window based on the ID. Finds a window based on the name.
**System capability**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
...@@ -432,7 +430,7 @@ Obtains the top window of the current application. This API uses an asynchronous ...@@ -432,7 +430,7 @@ Obtains the top window of the current application. This API uses an asynchronous
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------------------------------------- | -- | ---------------------------------------- | | -------- | -------------------------------------- | -- | ---------------------------------------- |
| ctx | BaseContext | Yes| Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).| | ctx | BaseContext | Yes| Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).|
| callback | AsyncCallback&lt;[Window](#window)&gt; | Yes| Callback used to return the top window obtained.| | callback | AsyncCallback&lt;[Window](#window)&gt; | Yes| Callback used to return the top window obtained.|
**Error codes** **Error codes**
...@@ -474,7 +472,7 @@ Obtains the top window of the current application. This API uses a promise to re ...@@ -474,7 +472,7 @@ Obtains the top window of the current application. This API uses a promise to re
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ----------- | ---- | ------------------------------------------------------------ | | ------ | ----------- | ---- | ------------------------------------------------------------ |
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).| | ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).|
**Return value** **Return value**
...@@ -899,7 +897,7 @@ promise.then((data)=> { ...@@ -899,7 +897,7 @@ promise.then((data)=> {
create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void
Creates a subwindow in the FA model or a system window in the stage model. This API uses an asynchronous callback to return the result. Creates a subwindow (in API version 8) or a system window (from API version 9). This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> >
...@@ -911,7 +909,7 @@ Creates a subwindow in the FA model or a system window in the stage model. This ...@@ -911,7 +909,7 @@ Creates a subwindow in the FA model or a system window in the stage model. This
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-service-extension-context.md).| | ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md).|
| id | string | Yes | Window ID. | | id | string | Yes | Window ID. |
| type | [WindowType](#windowtype7) | Yes | Window type. | | type | [WindowType](#windowtype7) | Yes | Window type. |
| callback | AsyncCallback&lt;[Window](#window)&gt; | Yes | Callback used to return the subwindow created. | | callback | AsyncCallback&lt;[Window](#window)&gt; | Yes | Callback used to return the subwindow created. |
...@@ -935,7 +933,7 @@ window.create(this.context, 'alertWindow', window.WindowType.TYPE_SYSTEM_ALERT, ...@@ -935,7 +933,7 @@ window.create(this.context, 'alertWindow', window.WindowType.TYPE_SYSTEM_ALERT,
create(ctx: BaseContext, id: string, type: WindowType): Promise&lt;Window&gt; create(ctx: BaseContext, id: string, type: WindowType): Promise&lt;Window&gt;
Creates a subwindow in the FA model or a system window in the stage model. This API uses a promise to return the result. Creates a subwindow (in API version 8) or a system window (from API version 9). This API uses a promise to return the result.
> **NOTE** > **NOTE**
> >
...@@ -947,7 +945,7 @@ Creates a subwindow in the FA model or a system window in the stage model. This ...@@ -947,7 +945,7 @@ Creates a subwindow in the FA model or a system window in the stage model. This
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------------------------- | ---- | ------------------------------------------------------------ | | ------ | ------------------------- | ---- | ------------------------------------------------------------ |
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-service-extension-context.md).| | ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md).|
| id | string | Yes | Window ID. | | id | string | Yes | Window ID. |
| type | [WindowType](#windowtype7) | Yes | Window type. | | type | [WindowType](#windowtype7) | Yes | Window type. |
...@@ -1123,7 +1121,7 @@ Obtains the top window of the current application. This API uses an asynchronous ...@@ -1123,7 +1121,7 @@ Obtains the top window of the current application. This API uses an asynchronous
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).| | ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).|
| callback | AsyncCallback&lt;[Window](#window)&gt; | Yes | Callback used to return the top window obtained. | | callback | AsyncCallback&lt;[Window](#window)&gt; | Yes | Callback used to return the top window obtained. |
**Example** **Example**
...@@ -1156,7 +1154,7 @@ Obtains the top window of the current application. This API uses a promise to re ...@@ -1156,7 +1154,7 @@ Obtains the top window of the current application. This API uses a promise to re
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ----------- | ---- | ------------------------------------------------------------ | | ------ | ----------- | ---- | ------------------------------------------------------------ |
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).| | ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).|
**Return value** **Return value**
...@@ -1983,7 +1981,7 @@ Sets whether to display the status bar and navigation bar in this window. This A ...@@ -1983,7 +1981,7 @@ Sets whether to display the status bar and navigation bar in this window. This A
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ---------------------------- | -- | --------- | | -------- | ---------------------------- | -- | --------- |
| names | Array<'status'\|'navigation'> | Yes | Whether to display the status bar and navigation bar.<br>For example, to display the status bar and navigation bar, set this parameter to **['status', 'navigation']**. By default, they are not displayed.| | names | Array<'status'\|'navigation'> | Yes| Whether to display the status bar and navigation bar.<br>For example, to display the status bar and navigation bar, set this parameter to **['status', 'navigation']**. By default, they are not displayed.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Error codes** **Error codes**
...@@ -3723,41 +3721,6 @@ try { ...@@ -3723,41 +3721,6 @@ try {
### snapshot<sup>9+</sup> ### snapshot<sup>9+</sup>
snapshot(callback: AsyncCallback&lt;image.PixelMap&gt;): void
Captures this window. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------------------------------------ | --------- | ----------------------------------- |
| callback | AsyncCallback&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md).
| ID | Error Message |
| ------- | ------------------------------ |
| 1300002 | This window state is abnormal. |
**Example**
```js
windowClass.snapshot((err, pixelMap) => {
if (err.code) {
console.error('Failed to snapshot window. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
pixelMap.release(); // Release the memory in time after the PixelMap is used.
});
```
### snapshot<sup>9+</sup>
snapshot(): Promise&lt;image.PixelMap&gt; snapshot(): Promise&lt;image.PixelMap&gt;
Captures this window. This API uses a promise to return the result. Captures this window. This API uses a promise to return the result.
...@@ -4078,7 +4041,6 @@ try { ...@@ -4078,7 +4041,6 @@ try {
} catch (exception) { } catch (exception) {
console.error('Failed to set backdrop blur. Cause: ' + JSON.stringify(exception)); console.error('Failed to set backdrop blur. Cause: ' + JSON.stringify(exception));
} }
``` ```
### setBackdropBlurStyle<sup>9+</sup> ### setBackdropBlurStyle<sup>9+</sup>
...@@ -6697,7 +6659,6 @@ controller.animationForShown = (context : window.TransitionContext) => { ...@@ -6697,7 +6659,6 @@ controller.animationForShown = (context : window.TransitionContext) => {
); );
console.info('complete transition end'); console.info('complete transition end');
}; };
``` ```
### animationForHidden<sup>9+</sup> ### animationForHidden<sup>9+</sup>
...@@ -6744,4 +6705,5 @@ controller.animationForHidden = (context : window.TransitionContext) => { ...@@ -6744,4 +6705,5 @@ controller.animationForHidden = (context : window.TransitionContext) => {
) )
console.info('complete transition end'); console.info('complete transition end');
}; };
``` ```
\ No newline at end of file
...@@ -20,21 +20,19 @@ The table below lists the common APIs used for application window development. F ...@@ -20,21 +20,19 @@ The table below lists the common APIs used for application window development. F
| Instance| API| Description| | Instance| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| Window static method| create(id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void | Creates a subwindow.<br>This API can be used only in the FA model.| | Window static method| createWindow(config: Configuration, callback: AsyncCallback\<Window>): void | Creates a subwindow.<br>**config** specifies the parameters used for creating the window.|
| Window static method| getTopWindow(callback: AsyncCallback&lt;Window&gt;): void | Obtains the top window of the current application.<br>This API can be used only in the FA model.| | Window static method| findWindow(id: string, callback: AsyncCallback&lt;Window&gt;): void | Finds a window based on the ID.|
| Window static method| find(id: string, callback: AsyncCallback&lt;Window&gt;): void | Finds a window based on the ID.| | Window | SetUIContent(path: string, callback: AsyncCallback&lt;void&gt;): void | Loads the page content to this window.|
| Window | loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void | Loads the page content to this window.| | Window | moveWindowTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void | Moves this window.|
| Window | moveTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void | Moves this window.| | Window | setWindowBackgroundColor(color: string, callback: AsyncCallback&lt;void&gt;): void | Sets the background color for this window.|
| Window | setBackgroundColor(color: string, callback: AsyncCallback&lt;void&gt;): void | Sets the background color for this window.| | Window | setWindowBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void | Sets the brightness for this window.|
| Window | setBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void | Sets the brightness for this window.| | Window | resize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void | Changes the window size.|
| Window | resetSize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void | Changes the window size.| | Window | setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void | Sets whether to enable the full-screen mode for the window layout. |
| Window | setFullScreen(isFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void | Sets whether to enable the full-screen mode for this window.| | Window | setWindowSystemBarEnable(names: Array&lt;'status'\|'navigation'&gt;): Promise&lt;void&gt; | Sets whether to display the status bar and navigation bar in this window.|
| Window | setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void | Sets whether to enable the full-screen mode for the window layout. | | Window | setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback&lt;void&gt;): void | Sets the properties of the status bar and navigation bar in this window.<br>**systemBarProperties**: properties of the status bar and navigation bar.|
| Window | setSystemBarEnable(names: Array&lt;'status'\|'navigation'&gt;): Promise&lt;void&gt; | Sets whether to display the status bar and navigation bar in this window.| | Window | showWindow(callback: AsyncCallback\<void>): void | Shows this window.|
| Window | setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback&lt;void&gt;): void | Sets the properties of the status bar and navigation bar in this window.<br>**systemBarProperties**: properties of the status bar and navigation bar.|
| Window | show(callback: AsyncCallback\<void>): void | Shows this window.|
| Window | on(type: 'touchOutside', callback: Callback&lt;void&gt;): void | Enables listening for click events outside this window.| | Window | on(type: 'touchOutside', callback: Callback&lt;void&gt;): void | Enables listening for click events outside this window.|
| Window | destroy(callback: AsyncCallback&lt;void&gt;): void | Destroys this window.| | Window | destroyWindow(callback: AsyncCallback&lt;void&gt;): void | Destroys this window.|
## Setting the Subwindow of an Application ## Setting the Subwindow of an Application
...@@ -46,16 +44,16 @@ You can create a subwindow, such as a dialog box, and set its properties. ...@@ -46,16 +44,16 @@ You can create a subwindow, such as a dialog box, and set its properties.
1. Create or obtain a subwindow. 1. Create or obtain a subwindow.
- Call **window.create** to create a subwindow. - Call **window.createWindow** to create a subwindow.
- Call **window.getTopWindow** to obtain the top window – subwindow. - Call **window.findWindow** to find an available subwindow.
- Call **window.find** to find an available subwindow.
```js
```js
import window from '@ohos.window'; import window from '@ohos.window';
let windowClass = null; let windowClass = null;
// Method 1: Create a subwindow. // Method 1: Create a subwindow.
window.create("subWindow", window.WindowType.TYPE_APP, (err, data) => { let config = {name: "subWindow", windowType: window.WindowType.TYPE_APP, ctx: this.context};
window.createWindow(config, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err)); console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err));
return; return;
...@@ -63,17 +61,8 @@ You can create a subwindow, such as a dialog box, and set its properties. ...@@ -63,17 +61,8 @@ You can create a subwindow, such as a dialog box, and set its properties.
console.info('Succeeded in creating subWindow. Data: ' + JSON.stringify(data)); console.info('Succeeded in creating subWindow. Data: ' + JSON.stringify(data));
windowClass = data; windowClass = data;
}); });
// Method 2: Obtain a subwindow. // Method 2: Find a subwindow.
window.getTopWindow((err, data) => { window.findWindow("subWindow", (err, data) => {
if (err.code) {
console.error('Failed to get the subWindow. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in getting subWindow. Data: ' + JSON.stringify(data));
windowClass = data;
});
// Method 3: Find a subwindow.
window.find("subWindow", (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to find the subWindow. Cause: ' + JSON.stringify(err)); console.error('Failed to find the subWindow. Cause: ' + JSON.stringify(err));
return; return;
...@@ -81,15 +70,15 @@ You can create a subwindow, such as a dialog box, and set its properties. ...@@ -81,15 +70,15 @@ You can create a subwindow, such as a dialog box, and set its properties.
console.info('Succeeded in finding subWindow. Data: ' + JSON.stringify(data)); console.info('Succeeded in finding subWindow. Data: ' + JSON.stringify(data));
windowClass = data; windowClass = data;
}); });
``` ```
2. Set the properties of the subwindow. 2. Set the properties of the subwindow.
After the subwindow is created, you can set its properties, such as the size, position, background color, and brightness. After the subwindow is created, you can set its properties, such as the size, position, background color, and brightness.
```js ```js
// Move the subwindow. // Move the subwindow.
windowClass.moveTo(300, 300, (err) => { windowClass.moveWindowTo(300, 300, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to move the window. Cause:' + JSON.stringify(err)); console.error('Failed to move the window. Cause:' + JSON.stringify(err));
return; return;
...@@ -97,7 +86,7 @@ You can create a subwindow, such as a dialog box, and set its properties. ...@@ -97,7 +86,7 @@ You can create a subwindow, such as a dialog box, and set its properties.
console.info('Succeeded in moving the window.'); console.info('Succeeded in moving the window.');
}); });
// Change the size of the subwindow. // Change the size of the subwindow.
windowClass.resetSize(500, 1000, (err) => { windowClass.resize(500, 500, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); console.error('Failed to change the window size. Cause:' + JSON.stringify(err));
return; return;
...@@ -108,18 +97,18 @@ You can create a subwindow, such as a dialog box, and set its properties. ...@@ -108,18 +97,18 @@ You can create a subwindow, such as a dialog box, and set its properties.
3. Load content for the subwindow and show it. 3. Load content for the subwindow and show it.
Call **loadContent** and **show** to load and display the content in the subwindow. Call **SetUIContent** and **showWindow** to load and display the content in the subwindow.
```js ```js
// Load the page content to the subwindow. // Load the page content to the subwindow.
windowClass.loadContent("pages/page2", (err) => { windowClass.SetUIContent("pages/page2", (err) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); console.error('Failed to load the content. Cause: ' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in loading the content.'); console.info('Succeeded in loading the content.');
// Show the subwindow. // Show the subwindow.
windowClass.show((err) => { windowClass.showWindow((err) => {
if (err.code) { if (err.code) {
console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
return; return;
...@@ -131,11 +120,11 @@ You can create a subwindow, such as a dialog box, and set its properties. ...@@ -131,11 +120,11 @@ You can create a subwindow, such as a dialog box, and set its properties.
4. Destroy the subwindow. 4. Destroy the subwindow.
When the subwindow is no longer needed, you can call **destroy()** to destroy it. When the subwindow is no longer needed, you can call **destroyWindow** to destroy it.
```js ```js
// Call destroy() to destroy the subwindow when it is no longer needed. // Call destroy() to destroy the subwindow when it is no longer needed.
windowClass.destroy((err) => { windowClass.destroyWindow((err) => {
if (err.code) { if (err.code) {
console.error('Failed to destroy the subwindow. Cause:' + JSON.stringify(err)); console.error('Failed to destroy the subwindow. Cause:' + JSON.stringify(err));
return; return;
...@@ -158,14 +147,14 @@ To create a better video watching and gaming experience, you can use the immersi ...@@ -158,14 +147,14 @@ To create a better video watching and gaming experience, you can use the immersi
> >
> The immersive window feature can be implemented only after the main window is obtained. > The immersive window feature can be implemented only after the main window is obtained.
> >
> Ensure that the top window of the application is the main window. You can use **window.getTopWindow** to obtain the main window. > Ensure that the top window of the application is the main window. You can use **window.getLastWindow** to obtain the main window.
```js ```js
import window from '@ohos.window'; import window from '@ohos.window';
let mainWindowClass = null; let mainWindowClass = null;
// Obtain the main window. // Obtain the main window.
window.getTopWindow((err, data) => { window.getLastWindow((err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to get the subWindow. Cause: ' + JSON.stringify(err)); console.error('Failed to get the subWindow. Cause: ' + JSON.stringify(err));
return; return;
...@@ -177,32 +166,23 @@ To create a better video watching and gaming experience, you can use the immersi ...@@ -177,32 +166,23 @@ To create a better video watching and gaming experience, you can use the immersi
2. Implement the immersive effect. You can use any of the following methods: 2. Implement the immersive effect. You can use any of the following methods:
- Method 1: Call **setFullScreen** to set the main window to be displayed in full screen. In this case, the navigation bar and status bar are hidden. - Method 1: Call **setWindowSystemBarEnable** to hide the navigation bar and status bar.
- Method 2: Call **setSystemBarEnable** to hide the navigation bar and status bar. - Method 2: Call **setWindowLayoutFullScreen** to enable the full-screen mode for the main window layout. Call **setSystemProperties** to set the opacity, background color, text color, and highlighted icon of the navigation bar and status bar to ensure that their display effect is consistent with that of the main window.
- Method 3: Call **setLayoutFullScreen** to enable the full-screen mode for the main window layout. Call **setSystemProperties** to set the opacity, background color, text color, and highlighted icon of the navigation bar and status bar to ensure that their display effect is consistent with that of the main window.
```js ```js
// Use method 1 to implement the immersive effect. // Use method 1 to implement the immersive effect.
let isFullScreen = true;
mainWindowClass.setFullScreen(isFullScreen, (err) => {
if (err.code) {
console.error('Failed to enable the full-screen mode. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in enabling the full-screen mode.');
});
// Use method 2 to implement the immersive effect.
let names = []; let names = [];
mainWindowClass.setSystemBarEnable(names, (err) => { mainWindowClass.setWindowSystemBarEnable(names, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err)); console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in setting the system bar to be visible.'); console.info('Succeeded in setting the system bar to be visible.');
}); });
// Use method 3 to implement the immersive effect. // Use method 2 to implement the immersive effect.
let isLayoutFullScreen = true; let isLayoutFullScreen = true;
mainWindowClass.setLayoutFullScreen(isLayoutFullScreen, (err) => { mainWindowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
return; return;
...@@ -216,7 +196,7 @@ To create a better video watching and gaming experience, you can use the immersi ...@@ -216,7 +196,7 @@ To create a better video watching and gaming experience, you can use the immersi
statusBarContentColor: '#ffffff', statusBarContentColor: '#ffffff',
navigationBarContentColor: '#ffffff' navigationBarContentColor: '#ffffff'
}; };
mainWindowClass.setSystemBarProperties(sysBarProps, (err) => { mainWindowClass.setWindowSystemBarProperties(sysBarProps, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
return; return;
...@@ -227,18 +207,18 @@ To create a better video watching and gaming experience, you can use the immersi ...@@ -227,18 +207,18 @@ To create a better video watching and gaming experience, you can use the immersi
3. Load content for the immersive window and show it. 3. Load content for the immersive window and show it.
Call **loadContent** and **show** to load and display the content in the immersive window. Call **SetUIContent** and **showWindow** to load and display the content in the immersive window.
```js ```js
// Load the page content to the immersive window. // Load the page content to the immersive window.
mainWindowClass.loadContent("pages/page3", (err) => { mainWindowClass.SetUIContent("pages/page3", (err) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); console.error('Failed to load the content. Cause: ' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in loading the content.'); console.info('Succeeded in loading the content.');
// Show the immersive window. // Show the immersive window.
mainWindowClass.show((err) => { mainWindowClass.showWindow((err) => {
if (err.code) { if (err.code) {
console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
return; return;
......
...@@ -32,20 +32,19 @@ The table below lists the common APIs used for application window development. F ...@@ -32,20 +32,19 @@ The table below lists the common APIs used for application window development. F
| WindowStage | getMainWindow(callback: AsyncCallback&lt;Window&gt;): void | Obtains the main window of this window stage.<br>This API can be used only in the stage model.| | WindowStage | getMainWindow(callback: AsyncCallback&lt;Window&gt;): void | Obtains the main window of this window stage.<br>This API can be used only in the stage model.|
| WindowStage | loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void | Loads the page content to the main window in this window stage.<br>This API can be used only in the stage model.| | WindowStage | loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void | Loads the page content to the main window in this window stage.<br>This API can be used only in the stage model.|
| WindowStage | createSubWindow(name: string, callback: AsyncCallback&lt;Window&gt;): void | Creates a subwindow.<br>This API can be used only in the stage model.| | WindowStage | createSubWindow(name: string, callback: AsyncCallback&lt;Window&gt;): void | Creates a subwindow.<br>This API can be used only in the stage model.|
| Window static method| create(ctx: Context, id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void | Creates a subwindow.<br>- **ctx**: application context.<br>- **type**: window type.| | Window static method| createWindow(config: Configuration, callback: AsyncCallback\<Window>): void | Creates a system window.<br>**config** specifies the parameters used for creating the window.|
| Window | loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void | Loads the page content to this window.| | Window | setUIContent(path: string, callback: AsyncCallback&lt;void&gt;): void | Loads the page content to this window.|
| Window | setBackgroundColor(color: string, callback: AsyncCallback&lt;void&gt;): void | Sets the background color for this window.| | Window | setWindowBackgroundColor(color: string, callback: AsyncCallback&lt;void&gt;): void | Sets the background color for this window.|
| Window | setBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void | Sets the brightness for this window.| | Window | setWindowBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void | Sets the brightness for this window.|
| Window | setTouchable(isTouchable: boolean, callback: AsyncCallback&lt;void&gt;): void | Sets whether this window is touchable.| | Window | setWindowTouchable(isTouchable: boolean, callback: AsyncCallback&lt;void&gt;): void | Sets whether this window is touchable.|
| Window | moveTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void | Moves this window.| | Window | moveWindowTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void | Moves this window.|
| Window | resetSize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void | Changes the window size.| | Window | resize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void | Changes the window size.|
| Window | setFullScreen(isFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void | Sets whether to enable the full-screen mode for this window.| | Window | setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void | Sets whether to enable the full-screen mode for the window layout. |
| Window | setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void | Sets whether to enable the full-screen mode for the window layout. | | Window | setWindowSystemBarEnable(names: Array&lt;'status'\|'navigation'&gt;): Promise&lt;void&gt; | Sets whether to display the status bar and navigation bar in this window.|
| Window | setSystemBarEnable(names: Array&lt;'status'\|'navigation'&gt;): Promise&lt;void&gt; | Sets whether to display the status bar and navigation bar in this window.| | Window | setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback&lt;void&gt;): void | Sets the properties of the status bar and navigation bar in this window.<br>**systemBarProperties**: properties of the status bar and navigation bar.|
| Window | setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback&lt;void&gt;): void | Sets the properties of the status bar and navigation bar in this window.<br>**systemBarProperties**: properties of the status bar and navigation bar.| | Window | showWindow(callback: AsyncCallback\<void>): void | Shows this window.|
| Window | show(callback: AsyncCallback\<void>): void | Shows this window.|
| Window | on(type: 'touchOutside', callback: Callback&lt;void&gt;): void | Enables listening for click events outside this window.| | Window | on(type: 'touchOutside', callback: Callback&lt;void&gt;): void | Enables listening for click events outside this window.|
| Window | destroy(callback: AsyncCallback&lt;void&gt;): void | Destroys this window.| | Window | destroyWindow(callback: AsyncCallback&lt;void&gt;): void | Destroys this window.|
## Setting the Main Window of an Application ## Setting the Main Window of an Application
...@@ -56,16 +55,12 @@ In the stage model, the main window of an application is created and maintained ...@@ -56,16 +55,12 @@ In the stage model, the main window of an application is created and maintained
### How to Develop ### How to Develop
1. Obtain the main window. 1. Obtain the main window.
Call **getMainWindow** to obtain the main window of the application. Call **getMainWindow** to obtain the main window of the application.
2. Set the properties of the main window. 2. Set the properties of the main window.
You can set multiple properties of the main window, such as the background color, brightness, and whether the main window is touchable. The code snippet below uses the **touchable** property as an example. You can set multiple properties of the main window, such as the background color, brightness, and whether the main window is touchable. The code snippet below uses the **touchable** property as an example.
3. Load content for the main window. 3. Load content for the main window.
Call **loadContent** to load the page content to the main window. Call **loadContent** to load the page content to the main window.
```ts ```ts
...@@ -84,7 +79,7 @@ class MainAbility extends Ability { ...@@ -84,7 +79,7 @@ class MainAbility extends Ability {
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
// 2. Set the touchable property of the main window. // 2. Set the touchable property of the main window.
let isTouchable = true; let isTouchable = true;
windowClass.setTouchable(isTouchable, (err) => { windowClass.setWindowTouchable(isTouchable, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err));
return; return;
...@@ -113,22 +108,17 @@ You can create an application subwindow, such as a dialog box, and set its prope ...@@ -113,22 +108,17 @@ You can create an application subwindow, such as a dialog box, and set its prope
### How to Develop ### How to Develop
1. Create a subwindow. 1. Create a subwindow.
Call **createSubWindow** to create a subwindow. Call **createSubWindow** to create a subwindow.
2. Set the properties of the subwindow. 2. Set the properties of the subwindow.
After the subwindow is created, you can set its properties, such as the size, position, background color, and brightness. After the subwindow is created, you can set its properties, such as the size, position, background color, and brightness.
3. Load content for the subwindow and show it. 3. Load content for the subwindow and show it.
Call **setUIContent** and **showWindow** to load and display the content in the subwindow.
Call **loadContent** and **show** to load and display the content in the subwindow.
4. Destroy the subwindow. 4. Destroy the subwindow.
When the subwindow is no longer needed, you can call **destroyWindow** to destroy it.
When the subwindow is no longer needed, you can call **destroy** to destroy it.
```ts ```ts
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
...@@ -145,14 +135,14 @@ You can create an application subwindow, such as a dialog box, and set its prope ...@@ -145,14 +135,14 @@ You can create an application subwindow, such as a dialog box, and set its prope
sub_windowClass = data; sub_windowClass = data;
console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
// 2. Set the position, size, and other properties of the subwindow. // 2. Set the position, size, and other properties of the subwindow.
sub_windowClass.moveTo(300, 300, (err) => { sub_windowClass.moveWindowTo(300, 300, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to move the window. Cause:' + JSON.stringify(err)); console.error('Failed to move the window. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in moving the window.'); console.info('Succeeded in moving the window.');
}); });
sub_windowClass.resetSize(500, 1000, (err) => { sub_windowClass.resize(500, 500, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); console.error('Failed to change the window size. Cause:' + JSON.stringify(err));
return; return;
...@@ -160,14 +150,14 @@ You can create an application subwindow, such as a dialog box, and set its prope ...@@ -160,14 +150,14 @@ You can create an application subwindow, such as a dialog box, and set its prope
console.info('Succeeded in changing the window size.'); console.info('Succeeded in changing the window size.');
}); });
// 3. Load the page content to the subwindow. // 3. Load the page content to the subwindow.
sub_windowClass.loadContent("pages/page3", (err) => { sub_windowClass.setUIContent("pages/page3", (err) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err)); console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in loading the content.'); console.info('Succeeded in loading the content.');
// 3. Show the subwindow. // 3. Show the subwindow.
sub_windowClass.show((err) => { sub_windowClass.showWindow((err) => {
if (err.code) { if (err.code) {
console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
return; return;
...@@ -180,7 +170,7 @@ You can create an application subwindow, such as a dialog box, and set its prope ...@@ -180,7 +170,7 @@ You can create an application subwindow, such as a dialog box, and set its prope
destroySubWindow() { destroySubWindow() {
// 4. Destroy the subwindow when it is no longer needed (depending on the service logic). // 4. Destroy the subwindow when it is no longer needed (depending on the service logic).
sub_windowClass.destroy((err) => { sub_windowClass.destroyWindow((err) => {
if (err.code) { if (err.code) {
console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err));
return; return;
...@@ -211,19 +201,15 @@ To create a better video watching and gaming experience, you can use the immersi ...@@ -211,19 +201,15 @@ To create a better video watching and gaming experience, you can use the immersi
### How to Develop ### How to Develop
1. Obtain the main window. 1. Obtain the main window.
Call **getMainWindow** to obtain the main window of the application. Call **getMainWindow** to obtain the main window of the application.
2. Implement the immersive effect. You can use any of the following methods: 2. Implement the immersive effect. You can use any of the following methods:
- Method 1: Call **setFullScreen** to set the main window to be displayed in full screen. In this case, the navigation bar and status bar are hidden. - Method 1: Call **setWindowSystemBarEnable** to hide the navigation bar and status bar.
- Method 2: Call **setSystemBarEnable** to hide the navigation bar and status bar. - Method 2: Call **setWindowLayoutFullScreen** to enable the full-screen mode for the main window layout. Call **setWindowSystemBarProperties** to set the opacity, background color, text color, and highlighted icon of the navigation bar and status bar to ensure that their display effect is consistent with that of the main window.
- Method 3: Call **setLayoutFullScreen** to enable the full-screen mode for the main window layout. Call **setSystemProperties** to set the opacity, background color, text color, and highlighted icon of the navigation bar and status bar to ensure that their display effect is consistent with that of the main window.
3. Load content for the immersive window and show it. 3. Load content for the immersive window and show it.
Call **loadContent** to load the content to the immersive window. Call **loadContent** to load the content to the immersive window.
```ts ```ts
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
...@@ -240,26 +226,17 @@ To create a better video watching and gaming experience, you can use the immersi ...@@ -240,26 +226,17 @@ To create a better video watching and gaming experience, you can use the immersi
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
// 2. Use method 1 to implement the immersive effect. // 2. Use method 1 to implement the immersive effect.
let isFullScreen = true;
windowClass.setFullScreen(isFullScreen, (err) => {
if (err.code) {
console.error('Failed to enable the full-screen mode. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in enabling the full-screen mode.');
});
// 2. Use method 2 to implement the immersive effect.
let names = []; let names = [];
windowClass.setSystemBarEnable(names, (err) => { windowClass.setWindowSystemBarEnable(names, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err)); console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in setting the system bar to be visible.'); console.info('Succeeded in setting the system bar to be visible.');
}); });
// 2. Use method 3 to implement the immersive effect. // 2. Use method 2 to implement the immersive effect.
let isLayoutFullScreen = true; let isLayoutFullScreen = true;
windowClass.setLayoutFullScreen(isLayoutFullScreen, (err) => { windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
return; return;
...@@ -273,7 +250,7 @@ To create a better video watching and gaming experience, you can use the immersi ...@@ -273,7 +250,7 @@ To create a better video watching and gaming experience, you can use the immersi
statusBarContentColor: '#ffffff', statusBarContentColor: '#ffffff',
navigationBarContentColor: '#ffffff' navigationBarContentColor: '#ffffff'
}; };
windowClass.setSystemBarProperties(sysBarProps, (err) => { windowClass.setWindowSystemBarProperties(sysBarProps, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
return; return;
...@@ -302,13 +279,12 @@ A floating window is created based on an existing task. It is always displayed i ...@@ -302,13 +279,12 @@ A floating window is created based on an existing task. It is always displayed i
### How to Develop ### How to Develop
1. Apply for permissions. 1. Apply for permissions.
To create a floating window (of the **WindowType.TYPE_FLOAT** type), you must configure the **ohos.permission.SYSTEM_FLOAT_WINDOW** permission in the **requestPermissions** field of the **module.json5** file. For more configuration information, see [module.json5 Configuration File](../quick-start/module-configuration-file.md).
To create a floating window (of the **WindowType.TYPE_FLOAT** type), you must configure the **ohos.permission.SYSTEM_FLOAT_WINDOW** permission in the **requestPermissions** field of the **module.json5** file. For details about the file, see [Application Package Structure Configuration File](../quick-start/stage-structure.md).
> **NOTE** > **NOTE**
> >
> If the task for creating the floating window is reclaimed by the system, the floating window will no longer be displayed. If you want the floating window to be displayed in such a case, apply for a [continuous task](../task-management/background-task-overview.md). > If the task for creating the floating window is reclaimed by the system, the floating window will no longer be displayed. If you want the floating window to be displayed in such a case, apply for a [continuous task](../task-management/background-task-overview.md).
```json ```json
{ {
"module": { "module": {
...@@ -324,24 +300,21 @@ A floating window is created based on an existing task. It is always displayed i ...@@ -324,24 +300,21 @@ A floating window is created based on an existing task. It is always displayed i
} }
] ]
} }
} }
``` ```
2. Create a floating window. 2. Create a floating window.
Call **window.createWindow** to create a floating window.
Call **window.create** to create a floating window.
3. Set properties for the floating window. 3. Set properties for the floating window.
After the floating window is created, you can set its properties, such as the size, position, background color, and brightness. After the floating window is created, you can set its properties, such as the size, position, background color, and brightness.
4. Load content for the floating window and show it. 4. Load content for the floating window and show it.
Call **setUIContent** and **showWindow** to load and display the content in the floating window.
Call **loadContent** and **show** to load and display the content in the floating window.
5. Destroy the floating window. 5. Destroy the floating window.
When the floating window is no longer needed, you can call **destroy** to destroy it. When the floating window is no longer needed, you can call **destroyWindow** to destroy it.
```ts ```ts
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
...@@ -352,7 +325,8 @@ A floating window is created based on an existing task. It is always displayed i ...@@ -352,7 +325,8 @@ A floating window is created based on an existing task. It is always displayed i
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
// 2. Create a floating window. // 2. Create a floating window.
let windowClass = null; let windowClass = null;
window.create(this.context, "floatWindow", window.WindowType.TYPE_FLOAT, (err, data) => { let config = {name: "floatWindow", windowType: window.WindowType.TYPE_FLOAT, ctx: this.context};
window.createWindow(config, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to create the floatWindow. Cause: ' + JSON.stringify(err)); console.error('Failed to create the floatWindow. Cause: ' + JSON.stringify(err));
return; return;
...@@ -360,14 +334,14 @@ A floating window is created based on an existing task. It is always displayed i ...@@ -360,14 +334,14 @@ A floating window is created based on an existing task. It is always displayed i
console.info('Succeeded in creating the floatWindow. Data: ' + JSON.stringify(data)); console.info('Succeeded in creating the floatWindow. Data: ' + JSON.stringify(data));
windowClass = data; windowClass = data;
// 3. Set the position, size, and properties of the floating window. // 3. Set the position, size, and properties of the floating window.
windowClass.moveTo(300, 300, (err) => { windowClass.moveWindowTo(300, 300, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to move the window. Cause:' + JSON.stringify(err)); console.error('Failed to move the window. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in moving the window.'); console.info('Succeeded in moving the window.');
}); });
windowClass.resetSize(500, 1000, (err) => { windowClass.resize(500, 500, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); console.error('Failed to change the window size. Cause:' + JSON.stringify(err));
return; return;
...@@ -375,14 +349,14 @@ A floating window is created based on an existing task. It is always displayed i ...@@ -375,14 +349,14 @@ A floating window is created based on an existing task. It is always displayed i
console.info('Succeeded in changing the window size.'); console.info('Succeeded in changing the window size.');
}); });
// 4. Load the page content to the floating window. // 4. Load the page content to the floating window.
windowClass.loadContent("pages/page4", (err) => { windowClass.setUIContent("pages/page4", (err) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err)); console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in loading the content.'); console.info('Succeeded in loading the content.');
// 4. Show the floating window. // 4. Show the floating window.
windowClass.show((err) => { windowClass.showWindow((err) => {
if (err.code) { if (err.code) {
console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
return; return;
...@@ -391,7 +365,7 @@ A floating window is created based on an existing task. It is always displayed i ...@@ -391,7 +365,7 @@ A floating window is created based on an existing task. It is always displayed i
}); });
}); });
// 5. Destroy the floating window when it is no longer needed (depending on the service logic). // 5. Destroy the floating window when it is no longer needed (depending on the service logic).
windowClass.destroy((err) => { windowClass.destroyWindow((err) => {
if (err.code) { if (err.code) {
console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err));
return; return;
...@@ -401,4 +375,6 @@ A floating window is created based on an existing task. It is always displayed i ...@@ -401,4 +375,6 @@ A floating window is created based on an existing task. It is always displayed i
}); });
} }
}; };
``` ```
\ No newline at end of file
<!--no_check-->
\ No newline at end of file
...@@ -15,14 +15,14 @@ For details, see [Window](../reference/apis/js-apis-window.md). ...@@ -15,14 +15,14 @@ For details, see [Window](../reference/apis/js-apis-window.md).
| Instance| API| Description| | Instance| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| Window static method| create(ctx: Context, id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void | Creates a system window when **ctx** is [ServiceExtensionContext](../reference/apis/js-apis-service-extension-context.md).<br>- **ctx**: application context. <br>- **type**: window type.| | Window static method| createWindow(config: Configuration, callback: AsyncCallback\<Window>): void | Creates a subwindow or system window.<br>**config** specifies the parameters used for creating the window.|
| Window | resetSize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void | Changes the window size.| | Window | resize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void | Changes the window size.|
| Window | moveTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void | Moves this window.| | Window | moveWindowTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void | Moves this window.|
| Window | loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void | Loads the page content to this window.| | Window | SetUIContent(path: string, callback: AsyncCallback&lt;void&gt;): void | Loads the page content to this window.|
| Window | show(callback: AsyncCallback\<void>): void | Shows this window.| | Window | showWindow(callback: AsyncCallback\<void>): void | Shows this window.|
| Window | on(type: 'touchOutside', callback: Callback&lt;void&gt;): void | Enables listening for click events outside this window.| | Window | on(type: 'touchOutside', callback: Callback&lt;void&gt;): void | Enables listening for click events outside this window.|
| Window | hide (callback: AsyncCallback\<void>): void | Hides this window. This is a system API.| | Window | hide (callback: AsyncCallback\<void>): void | Hides this window. This is a system API.|
| Window | destroy(callback: AsyncCallback&lt;void&gt;): void | Destroys this window.| | Window | destroyWindow(callback: AsyncCallback&lt;void&gt;): void | Destroys this window.|
## How to Develop ## How to Develop
...@@ -33,7 +33,7 @@ This section uses the volume bar as an example to describe the steps for system ...@@ -33,7 +33,7 @@ This section uses the volume bar as an example to describe the steps for system
1. Create a system window. 1. Create a system window.
In the case of [ServiceExtensionContext](../reference/apis/js-apis-service-extension-context.md), call **window.create** to create a system window of the volume bar type. In the case of [ServiceExtensionContext](../reference/apis/js-apis-inner-application-serviceExtensionContext.md), call **window.createWindow** to create a system window of the volume bar type.
2. Set the properties of the system window. 2. Set the properties of the system window.
...@@ -41,11 +41,11 @@ This section uses the volume bar as an example to describe the steps for system ...@@ -41,11 +41,11 @@ This section uses the volume bar as an example to describe the steps for system
3. Load content for the system window and show it. 3. Load content for the system window and show it.
You can call **loadContent** and **show** to load and display the content in the volume bar window. You can call **SetUIContent** and **showWindow** to load and display the content in the volume bar window.
4. Hide or destroy the system window. 4. Hide or destroy the system window.
When the volume bar window is no longer needed, you can call **hide** or **destroy** to hide or destroy it. When the volume bar window is no longer needed, you can call **hide** or **destroyWindow** to hide or destroy it.
```ts ```ts
import ExtensionContext from '@ohos.application.ServiceExtensionAbility'; import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
...@@ -57,7 +57,8 @@ export default class ServiceExtensionAbility1 extends ExtensionContext { ...@@ -57,7 +57,8 @@ export default class ServiceExtensionAbility1 extends ExtensionContext {
globalThis.abilityWant = want; globalThis.abilityWant = want;
// 1. Create a volume bar window. // 1. Create a volume bar window.
let windowClass = null; let windowClass = null;
window.create(this.context, "volume", window.WindowType.TYPE_VOLUME_OVERLAY, (err, data) => { let config = {name: "volume", windowType: window.WindowType.TYPE_VOLUME_OVERLAY, ctx: this.context};
window.createWindow(config, (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to create the volume window. Cause:' + JSON.stringify(err)); console.error('Failed to create the volume window. Cause:' + JSON.stringify(err));
return; return;
...@@ -65,14 +66,14 @@ export default class ServiceExtensionAbility1 extends ExtensionContext { ...@@ -65,14 +66,14 @@ export default class ServiceExtensionAbility1 extends ExtensionContext {
console.info('Succeeded in creating the volume window.') console.info('Succeeded in creating the volume window.')
windowClass = data; windowClass = data;
// 2. Change the size and position of the volume bar window, or set its properties such as the background color and brightness. // 2. Change the size and position of the volume bar window, or set its properties such as the background color and brightness.
windowClass.moveTo(300, 300, (err) => { windowClass.moveWindowTo(300, 300, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to move the window. Cause:' + JSON.stringify(err)); console.error('Failed to move the window. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in moving the window.'); console.info('Succeeded in moving the window.');
}); });
windowClass.resetSize(500, 1000, (err) => { windowClass.resize(500, 500, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); console.error('Failed to change the window size. Cause:' + JSON.stringify(err));
return; return;
...@@ -80,14 +81,14 @@ export default class ServiceExtensionAbility1 extends ExtensionContext { ...@@ -80,14 +81,14 @@ export default class ServiceExtensionAbility1 extends ExtensionContext {
console.info('Succeeded in changing the window size.'); console.info('Succeeded in changing the window size.');
}); });
// 3. Load the page content to the volume bar window. // 3. Load the page content to the volume bar window.
windowClass.loadContent("pages/page_volume", (err) => { windowClass.setUIContent("pages/page_volume", (err) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err)); console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in loading the content.'); console.info('Succeeded in loading the content.');
// 3. Show the volume bar window. // 3. Show the volume bar window.
windowClass.show((err) => { windowClass.showWindow((err) => {
if (err.code) { if (err.code) {
console.error('Failed to show the window. Cause:' + JSON.stringify(err)); console.error('Failed to show the window. Cause:' + JSON.stringify(err));
return; return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册