diff --git a/en/application-dev/reference/apis/js-apis-display.md b/en/application-dev/reference/apis/js-apis-display.md index dd7e82d3265847efcef897ba444739935dc2baf4..5ca404121fdaf677c863f8a23f338c20bd75e136 100644 --- a/en/application-dev/reference/apis/js-apis-display.md +++ b/en/application-dev/reference/apis/js-apis-display.md @@ -1,9 +1,8 @@ # Display -> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. - ## Modules to Import ``` @@ -11,24 +10,19 @@ import display from '@ohos.display'; ``` -## Required Permissions - -None - - ## DisplayState Provides the state of a display. | Name| Default Value| Description| | -------- | -------- | -------- | -| STATE_UNKNOWN | 0 | Unknown.| -| STATE_OFF | 1 | The display is shut down.| -| STATE_ON | 2 | The display is powered on.| -| STATE_DOZE | 3 | The display is in sleep mode.| -| STATE_DOZE_SUSPEND | 4 | The display is in sleep mode, and the CPU is suspended.| -| STATE_VR | 5 | The display is in VR mode.| -| STATE_ON_SUSPEND | 6 | The display is powered on, and the CPU is suspended.| +| STATE_UNKNOWN | 0 | Unknown.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| STATE_OFF | 1 | The display is shut down.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| STATE_ON | 2 | The display is powered on.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| STATE_DOZE | 3 | The display is in sleep mode.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| STATE_DOZE_SUSPEND | 4 | The display is in sleep mode, and the CPU is suspended.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| STATE_VR | 5 | The display is in VR mode.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| STATE_ON_SUSPEND | 6 | The display is powered on, and the CPU is suspended.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| ## Display @@ -37,31 +31,33 @@ Describes the attributes of a display. | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| id | number | Yes| No| ID of the display.| -| name | string | Yes| No| Name of the display.| -| alive | boolean | Yes| No| Whether the display is alive.| -| state | [DisplayState](#displaystate) | Yes| No| State of the display.| -| refreshRate | number | Yes| No| Refresh rate of the display.| -| rotation | number | Yes| No| Screen rotation angle of the display.| -| width | number | Yes| No| Width 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.| -| densityPixels | number | Yes| No| Screen density of the display, in pixels.| -| 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.| -| yDPI | number | Yes| No| Exact physical dots per inch of the screen in the vertical direction.| +| id | number | Yes| No| ID of the display.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| name | string | Yes| No| Name of the display.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| alive | boolean | Yes| No| Whether the display is alive.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| state | [DisplayState](#DisplayState) | Yes| No| State of the display.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| refreshRate | number | Yes| No| Refresh rate of the display.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| rotation | number | Yes| No| Screen rotation angle of the display.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| width | number | Yes| No| Width of the display, in pixels.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| height | number | Yes| No| Height of the display, in pixels.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| densityDPI | number | Yes| No| Screen density of the display, in DPI.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| densityPixels | number | Yes| No| Screen density of the display, in pixels.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| scaledDensity | number | Yes| No| Scaling factor for fonts displayed on the display.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| xDPI | number | Yes| No| Exact physical dots per inch of the screen in the horizontal direction.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| +| yDPI | number | Yes| No| Exact physical dots per inch of the screen in the vertical direction.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core| ## display.getDefaultDisplay -getDefaultDisplay(callback: AsyncCallback<Display>): void; +getDefaultDisplay(callback: AsyncCallback<Display>): void Obtains the default display object. +**System capabilities**: SystemCapability.WindowManager.WindowManager.Core + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<[Display](#display)> | Yes| Callback used to return the attributes of the default display.| + | callback | AsyncCallback<[Display](#Display)> | Yes| Callback used to return the default display object.| - Example ``` @@ -76,19 +72,47 @@ Obtains the default display object. }); ``` +## display.getDefaultDisplay + +getDefaultDisplay(): Promise<Display> + +Obtains the default display object. + +**System capabilities**: SystemCapability.WindowManager.WindowManager.Core + +- Return value + + | Type| Description| + | ---------------------------------- | ---------------------------------------------- | + | Promise<[Display](#Display)> | Promise used to return the default display object.| + +- Example + + ``` + let promise = display.getDefaultDisplay(); + promise.then(() => { + console.log('getDefaultDisplay success'); + }).catch((err) => { + console.log('getDefaultDisplay fail: ' + JSON.stringify(err)); + }); + ``` ## display.getAllDisplay -getAllDisplay(callback: AsyncCallback<Array<Display>>): void; +getAllDisplay(callback: AsyncCallback<Array<Display>>): void Obtains all the display objects. +**System capabilities**: SystemCapability.WindowManager.WindowManager.Core + - Parameters + | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<Array<[Display](#display)>> | Yes| Callback used to return the attributes of all displays.| + | -------- | ---------------------------------------------------- | ---- | ------------------------------- | + | callback | AsyncCallback<Array<[Display](Display)>> | Yes| Callback used to return all the display objects.| - Example + ``` display.getAllDisplay((err, data) => { if (err) { @@ -99,13 +123,39 @@ Obtains all the display objects. }); ``` +## display.getAllDisplay + +getAllDisplay(): Promise<Array<Display>> + +Obtains all the display objects. + +**System capabilities**: SystemCapability.WindowManager.WindowManager.Core + +- Return value + + | Type| Description| + | ----------------------------------------------- | ------------------------------------------------------- | + | Promise<Array<[Display](#Display)>> | Promise used to return an array containing all the display objects.| + +- Example + + ``` + let promise = display.getAllDisplay(); + promise.then(() => { + console.log('getAllDisplay success'); + }).catch((err) => { + console.log('getAllDisplay fail: ' + JSON.stringify(err)); + }); + ``` ## display.on('add'|'remove'|'change') -on(type: 'add'|'remove'|'change', callback: Callback<number>): void; +on(type: 'add'|'remove'|'change', callback: Callback<number>): void Enables listening. +**System capabilities**: SystemCapability.WindowManager.WindowManager.Core + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -124,10 +174,12 @@ Enables listening. ## display.off('add'|'remove'|'change') -off(type: 'add'|'remove'|'change', callback?: Callback<number>): void; +off(type: 'add'|'remove'|'change', callback?: Callback<number>): void Disables listening. +**System capabilities**: SystemCapability.WindowManager.WindowManager.Core + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- |