提交 9f53c192 编写于 作者: G Gloria

update docs against 7984+8904

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 3bb157d3
# Display # Display
Provides APIs for managing displays, such as obtaining information about the default display, obtaining information about all displays, and listening for the addition and removal of displays. The **Display** module provides APIs for managing displays, such as obtaining information about the default display, obtaining information about all displays, and listening for the addition and removal of displays.
> **NOTE** > **NOTE**
> >
...@@ -14,11 +14,11 @@ import display from '@ohos.display'; ...@@ -14,11 +14,11 @@ import display from '@ohos.display';
## DisplayState ## DisplayState
Provides the state of a display. Enumerates the display states.
**System capability**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
| Name| Default Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| STATE_UNKNOWN | 0 | Unknown.| | STATE_UNKNOWN | 0 | Unknown.|
| STATE_OFF | 1 | The display is shut down.| | STATE_OFF | 1 | The display is shut down.|
...@@ -35,163 +35,169 @@ Describes the attributes of a display. ...@@ -35,163 +35,169 @@ Describes the attributes of a display.
**System capability**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
| Name| Type| Readable| Writable| Description| | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | ------------- | ----------------------------- | -------- | -------- | ------------------------------------------------------------ |
| id | number | Yes| No| ID of the display.| | id | number | Yes | No | ID of the display. |
| name | string | Yes| No| Name of the display.| | name | string | Yes | No | Name of the display. |
| alive | boolean | Yes| No| Whether the display is alive.| | alive | boolean | Yes | No | Whether the display is alive. |
| state | [DisplayState](#displaystate) | Yes| No| State of the display.| | state | [DisplayState](#displaystate) | Yes | No | State of the display. |
| refreshRate | number | Yes| No| Refresh rate of the display.| | refreshRate | number | Yes | No | Refresh rate of the display. |
| rotation | number | Yes| No| Screen rotation angle of the display.| | rotation | number | Yes | No | Screen rotation angle of the display. |
| width | number | Yes| No| Width of the display, in pixels.| | width | number | Yes | No | Width of the display, in pixels. |
| height | number | Yes| No| Height of the display, in pixels.| | height | number | Yes | No | Height of the display, in pixels. |
| densityDPI | number | Yes| No| Screen density of the display, in DPI.| | densityDPI | number | Yes | No | Screen density of the display, in DPI. |
| densityPixels | number | Yes| No| Screen density of the display, in pixels.| | densityPixels | number | Yes | No | Screen density of the display, in pixels. |
| scaledDensity | number | Yes| No| Scaling factor for fonts displayed on the display.| | scaledDensity | number | Yes | No | Scaling factor for fonts displayed on the display. |
| xDPI | number | Yes| No| Exact physical dots per inch of the screen in the horizontal direction.| | xDPI | number | Yes | No | Exact physical dots per inch of the screen in the horizontal direction. |
| yDPI | number | Yes| No| Exact physical dots per inch of the screen in the vertical direction.| | yDPI | number | Yes | No | Exact physical dots per inch of the screen in the vertical direction. |
## display.getDefaultDisplay ## display.getDefaultDisplay
getDefaultDisplay(callback: AsyncCallback&lt;Display&gt;): void getDefaultDisplay(callback: AsyncCallback&lt;Display&gt;): void
Obtains the default display object. Obtains the default display object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | Name| Type| Mandatory| Description|
| callback | AsyncCallback&lt;[Display](#display)&gt; | Yes| Callback used to return the default display object.| | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[Display](#display)&gt; | Yes| Callback used to return the default display object.|
**Example** **Example**
```js
var displayClass = null; ```js
display.getDefaultDisplay((err, data) => { var displayClass = null;
display.getDefaultDisplay((err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err)); console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data)); console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
displayClass = data; displayClass = data;
}); });
``` ```
## display.getDefaultDisplay ## display.getDefaultDisplay
getDefaultDisplay(): Promise&lt;Display&gt; getDefaultDisplay(): Promise&lt;Display&gt;
Obtains the default display object. Obtains the default display object. This API uses a promise to return the result.
**System capability**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ---------------------------------------------- | | ---------------------------------- | ---------------------------------------------- |
| Promise&lt;[Display](#display)&gt; | Promise used to return the default display object.| | Promise&lt;[Display](#display)&gt; | Promise used to return the default display object.|
**Example** **Example**
```js ```js
let promise = display.getDefaultDisplay(); var displayClass = null;
promise.then(() => { let promise = display.getDefaultDisplay();
console.log('getDefaultDisplay success'); promise.then((data) => {
}).catch((err) => { displayClass = data;
console.log('getDefaultDisplay fail: ' + JSON.stringify(err)); console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
}); }).catch((err) => {
``` console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err));
});
```
## display.getAllDisplay ## display.getAllDisplay
getAllDisplay(callback: AsyncCallback&lt;Array&lt;Display&gt;&gt;): void getAllDisplay(callback: AsyncCallback&lt;Array&lt;Display&gt;&gt;): void
Obtains all the display objects. Obtains all display objects. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------------------- | ---- | ------------------------------- | | -------- | ---------------------------------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[Display](#display)&gt;&gt; | Yes | Callback used to return all the display objects.| | callback | AsyncCallback&lt;Array&lt;[Display](#display)&gt;&gt; | Yes | Callback used to return all the display objects.|
**Example** **Example**
```js ```js
display.getAllDisplay((err, data) => { display.getAllDisplay((err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err)); console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data)) console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
}); });
``` ```
## display.getAllDisplay ## display.getAllDisplay
getAllDisplay(): Promise&lt;Array&lt;Display&gt;&gt; getAllDisplay(): Promise&lt;Array&lt;Display&gt;&gt;
Obtains all the display objects. Obtains all display objects. This API uses a promise to return the result.
**System capability**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------- | ------------------------------------------------------- | | ----------------------------------------------- | ------------------------------------------------------- |
| Promise&lt;Array&lt;[Display](#display)&gt;&gt; | Promise used to return all the display objects.| | Promise&lt;Array&lt;[Display](#display)&gt;&gt; | Promise used to return all the display objects.|
**Example** **Example**
```js ```js
let promise = display.getAllDisplay(); let promise = display.getAllDisplay();
promise.then(() => { promise.then((data) => {
console.log('getAllDisplay success'); console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err) => {
console.log('getAllDisplay fail: ' + JSON.stringify(err)); console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
}); });
``` ```
## display.on('add'|'remove'|'change') ## display.on('add'|'remove'|'change')
on(type: 'add'|'remove'|'change', callback: Callback&lt;number&gt;): void on(type: 'add'|'remove'|'change', callback: Callback&lt;number&gt;): void
Enables listening. Subscribes to display changes.
**System capability**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | Name| Type| Mandatory| Description|
| type | string | Yes| Listening type. The available values are as follows:<br>- **add**: listening for whether a display is added<br>- **remove**: listening for whether a display is removed<br>- **change**: listening for whether a display is changed| | -------- | -------- | -------- | -------- |
| callback | Callback&lt;number&gt; | Yes| Callback used to return the ID of the display.| | type | string | Yes| Event type.<br>- **add**, indicating the display addition event.<br>- **remove**, indicating the display removal event.<br>- **change**, indicating the display change event.|
| callback | Callback&lt;number&gt; | Yes| Callback used to return the ID of the display.|
**Example** **Example**
```js
var callback = (data) => { ```js
var callback = (data) => {
console.info('Listening enabled. Data: ' + JSON.stringify(data)) console.info('Listening enabled. Data: ' + JSON.stringify(data))
} }
display.on("add", callback); display.on("add", callback);
``` ```
## display.off('add'|'remove'|'change') ## display.off('add'|'remove'|'change')
off(type: 'add'|'remove'|'change', callback?: Callback&lt;number&gt;): void off(type: 'add'|'remove'|'change', callback?: Callback&lt;number&gt;): void
Disables listening. Unsubscribes from display changes.
**System capability**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | Name| Type| Mandatory| Description|
| type | string | Yes| Listening type. The available values are as follows:<br>- **add**: listening for whether a display is added<br>- **remove**: listening for whether a display is removed<br>- **change**: listening for whether a display is changed| | -------- | -------- | -------- | -------- |
| callback | Callback&lt;number&gt; | No| Callback used to return the ID of the display.| | type | string | Yes| Event type.<br>- **add**, indicating the display addition event.<br>- **remove**, indicating the display removal event.<br>- **change**, indicating the display change event.|
| callback | Callback&lt;number&gt; | No| Callback used to return the ID of the display.|
**Example** **Example**
```js ```js
display.off("remove"); display.off("remove");
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册