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

!10212 窗口子系统模块文档更新

Merge pull request !10212 from ZhengJiangliang/master
......@@ -11,7 +11,6 @@
import display from '@ohos.display';
```
## DisplayState
显示设备的状态枚举。
......@@ -65,61 +64,6 @@ import display from '@ohos.display';
| boundingRects | Array\<[Rect](#rect9)> | 是 | 否 | 挖孔、刘海等区域的边界矩形。 |
| waterfallDisplayAreaRects | [WaterfallDisplayAreaRects](#waterfalldisplayarearects9) | 是 | 否 | 瀑布屏曲面部分显示区域。 |
## display.getDefaultDisplay
getDefaultDisplay(callback: AsyncCallback&lt;Display&gt;): void
获取当前默认的display对象,使用callback异步回调。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[Display](#display)&gt; | 是 | 回调函数。返回当前默认的display对象。 |
**示例:**
```js
var displayClass = null;
display.getDefaultDisplay((err, data) => {
if (err.code) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
displayClass = data;
});
```
## display.getDefaultDisplay
getDefaultDisplay(): Promise&lt;Display&gt;
获取当前默认的display对象,使用Promise异步回调。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**返回值:**
| 类型 | 说明 |
| ---------------------------------- | ---------------------------------------------- |
| Promise&lt;[Display](#display)&gt; | Promise对象。返回当前默认的display对象。 |
**示例:**
```js
var displayClass = null;
let promise = display.getDefaultDisplay();
promise.then((data) => {
displayClass = data;
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.getDefaultDisplaySync<sup>9+</sup>
getDefaultDisplaySync(): Display
......@@ -134,15 +78,27 @@ getDefaultDisplaySync(): Display
| ------------------------------| ----------------------------------------------|
| [Display](#display) | 返回默认的display对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
var displayClass = display.getDefaultDisplaySync();
try {
let displayClass = display.getDefaultDisplaySync();
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
};
```
## display.getAllDisplay
## display.getAllDisplays<sup>9+</sup>
getAllDisplay(callback: AsyncCallback&lt;Array&lt;Display&gt;&gt;): void
getAllDisplays(callback: AsyncCallback&lt;Array&lt;Display&gt;&gt;): void
获取当前所有的display对象,使用callback异步回调。
......@@ -154,10 +110,20 @@ getAllDisplay(callback: AsyncCallback&lt;Array&lt;Display&gt;&gt;): void
| -------- | ---------------------------------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[Display](#display)&gt;&gt; | 是 | 回调函数。返回当前所有的display对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
display.getAllDisplay((err, data) => {
let displayClass = null;
display.getAllDisplays((err, data) => {
displayClass = data;
if (err.code) {
console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
return;
......@@ -166,9 +132,9 @@ display.getAllDisplay((err, data) => {
});
```
## display.getAllDisplay
## display.getAllDisplays<sup>9+</sup>
getAllDisplay(): Promise&lt;Array&lt;Display&gt;&gt;
getAllDisplays(): Promise&lt;Array&lt;Display&gt;&gt;
获取当前所有的display对象,使用Promise异步回调。
......@@ -180,11 +146,21 @@ getAllDisplay(): Promise&lt;Array&lt;Display&gt;&gt;
| ----------------------------------------------- | ------------------------------------------------------- |
| Promise&lt;Array&lt;[Display](#display)&gt;&gt; | Promise对象。返回当前所有的display对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
let promise = display.getAllDisplay();
let displayClass = null;
let promise = display.getAllDisplays();
promise.then((data) => {
displayClass = data;
console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
......@@ -195,7 +171,7 @@ promise.then((data) => {
hasPrivateWindow(displayId: number): boolean
查询指定display对象上是否有可见的隐私窗口。可通过[setPrivacyMode](js-apis-window.md#setprivacymode7)接口设置隐私窗口。隐私窗口内容将无法被截屏或录屏。
查询指定display对象上是否有可见的隐私窗口。可通过[setWindowPrivacyMode()](js-apis-window.md#setwindowprivacymode9)接口设置隐私窗口。隐私窗口内容将无法被截屏或录屏。
**系统接口:** 此接口为系统接口。
......@@ -213,20 +189,30 @@ hasPrivateWindow(displayId: number): boolean
| -------------------------------- |-----------------------------------------------------------------------|
|boolean | 查询的display对象上是否有可见的隐私窗口。<br>true表示此display对象上有可见的隐私窗口,false表示此display对象上没有可见的隐私窗口。</br> |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 1400003 | This window manager service work abnormally. |
**示例:**
```js
var displayClass = null;
display.getDefaultDisplay((err, data) => {
if (err.code) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err));
let displayClass = null;
try {
displayClass = display.getDefaultDisplaySync();
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
return;
}
console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
displayClass = data;
});
};
var ret = display.hasPrivateWindow(displayClass.id);
try {
let ret = display.hasPrivateWindow(displayClass.id);
} catch (exception) {
console.error('Failed to check has privateWindow or not. Code: ' + JSON.stringify(exception));
};
if (ret == undefined) {
console.log("Failed to check has privateWindow or not.");
}
......@@ -234,7 +220,7 @@ if (ret) {
console.log("There has privateWindow.");
} else if (!ret) {
console.log("There has no privateWindow.");
}
};
```
## display.on('add'|'remove'|'change')
......@@ -255,10 +241,14 @@ on(type: 'add'|'remove'|'change', callback: Callback&lt;number&gt;): void
**示例:**
```js
var callback = (data) => {
let callback = (data) => {
console.info('Listening enabled. Data: ' + JSON.stringify(data));
}
display.on("add", callback);
try {
display.on("add", callback);
} catch (exception) {
console.error('Failed to register callback. Code: ' + JSON.stringify(exception));
};
```
## display.off('add'|'remove'|'change')
......@@ -279,13 +269,139 @@ off(type: 'add'|'remove'|'change', callback?: Callback&lt;number&gt;): void
**示例:**
```js
display.off("remove");
try {
display.off("remove");
} catch (exception) {
console.error('Failed to unregister callback. Code: ' + JSON.stringify(exception));
};
```
## display.getDefaultDisplay<sup>(deprecated)</sup>
getDefaultDisplay(callback: AsyncCallback&lt;Display&gt;): void
获取当前默认的display对象,使用callback异步回调。
> **说明:**
>
> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getDefaultDisplaySync()](#displaygetdefaultdisplaysync9)。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[Display](#display)&gt; | 是 | 回调函数。返回当前默认的display对象。 |
**示例:**
```js
let displayClass = null;
display.getDefaultDisplay((err, data) => {
if (err.code) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
displayClass = data;
});
```
## display.getDefaultDisplay<sup>(deprecated)</sup>
getDefaultDisplay(): Promise&lt;Display&gt;
获取当前默认的display对象,使用Promise异步回调。
> **说明:**
>
> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getDefaultDisplaySync()](#displaygetdefaultdisplaysync9)。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**返回值:**
| 类型 | 说明 |
| ---------------------------------- | ---------------------------------------------- |
| Promise&lt;[Display](#display)&gt; | Promise对象。返回当前默认的display对象。 |
**示例:**
```js
let displayClass = null;
let promise = display.getDefaultDisplay();
promise.then((data) => {
displayClass = data;
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<sup>(deprecated)</sup>
getAllDisplay(callback: AsyncCallback&lt;Array&lt;Display&gt;&gt;): void
获取当前所有的display对象,使用callback异步回调。
> **说明:**
>
> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getAllDisplays()](#displaygetalldisplays9)。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[Display](#display)&gt;&gt; | 是 | 回调函数。返回当前所有的display对象。 |
**示例:**
```js
display.getAllDisplay((err, data) => {
if (err.code) {
console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
});
```
## display.getAllDisplay<sup>(deprecated)</sup>
getAllDisplay(): Promise&lt;Array&lt;Display&gt;&gt;
获取当前所有的display对象,使用Promise异步回调。
> **说明:**
>
> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getAllDisplays()](#displaygetalldisplays9-1)。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------- | ------------------------------------------------------- |
| Promise&lt;Array&lt;[Display](#display)&gt;&gt; | Promise对象。返回当前所有的display对象。 |
**示例:**
```js
let promise = display.getAllDisplay();
promise.then((data) => {
console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
});
```
## Display
屏幕实例。描述display对象的属性和方法。
下列API示例中都需先使用[getAllDisplay()](#displaygetalldisplay)[getDefaultDisplay()](#displaygetdefaultdisplay)[getDefaultDisplaySync()](#displaygetdefaultdisplaysync)中的任一方法获取到Display实例,再通过此实例调用对应方法。
下列API示例中都需先使用[getAllDisplays()](#displaygetalldisplays9)[getDefaultDisplaySync()](#displaygetdefaultdisplaysync9)中的任一方法获取到Display实例,再通过此实例调用对应方法。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
......@@ -312,20 +428,36 @@ getCutoutInfo(callback: AsyncCallback&lt;CutoutInfo&gt;): void
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;[CutoutInfo](#cutoutinfo9)&gt; | 是 | 回调函数。当获取信息成功,err为undefined,data为获取到的CutoutInfo对象;否则err为错误对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
try {
let displayClass = display.getDefaultDisplaySync();
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
};
displayClass.getCutoutInfo((err, data) => {
if (err.code) {
console.error('Failed to get cutoutInfo. Cause: ' + JSON.stringify(err));
console.error('Failed to get cutoutInfo. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in getting cutoutInfo. data: ' + JSON.stringify(data));
})
});
```
### getCutoutInfo<sup>9+</sup>
getCutoutInfo(): Promise&lt;CutoutInfo&gt;
......@@ -340,9 +472,23 @@ getCutoutInfo(): Promise&lt;CutoutInfo&gt;
| ------------------- | ------------------------- |
| Promise&lt;[CutoutInfo](#cutoutinfo9)&gt; | Promise对象,返回描述不可用屏幕区域的CutoutInfo对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
try {
let displayClass = display.getDefaultDisplaySync();
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
};
let promise = displayClass.getCutoutInfo();
promise.then((data) => {
console.info('Succeeded in getting cutoutInfo. Data: ' + JSON.stringify(data));
......
......@@ -28,6 +28,14 @@ getAllScreens(callback: AsyncCallback&lt;Array&lt;Screen&gt;&gt;): void
| -------- | --------------------------------------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[Screen](#screen)&gt;&gt; | 是 | 回调函数。返回当前获取的屏幕对象集合。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
......@@ -56,6 +64,14 @@ getAllScreens(): Promise&lt;Array&lt;Screen&gt;&gt;
| --------------------------------------------- | ----------------------------------------- |
| Promise&lt;Array&lt;[Screen](#screen)&gt;&gt; | Promise对象。返回当前获取的屏幕对象集合。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
......@@ -87,10 +103,14 @@ on(eventType: 'connect' | 'disconnect' | 'change', callback: Callback&lt;number&
**示例:**
```js
var callback = (data) => {
try {
let callback = (data) => {
console.info('Register the callback for screen changes. Data: ' + JSON.stringify(data))
};
screen.on('connect', callback);
} catch (exception) {
console.error('Failed to register the callback for screen changes. Code: ' + JSON.stringify(exception));
};
screen.on("connect", callback);
```
## screen.off('connect' | 'disconnect' | 'change')
......@@ -111,10 +131,14 @@ off(eventType: 'connect' | 'disconnect' | 'change', callback?: Callback&lt;numbe
**示例:**
```js
var callback = (data) => {
try {
let callback = (data) => {
console.info('Unregister the callback for screen changes. Data: ' + JSON.stringify(data))
};
screen.off('connect', callback);
} catch (exception) {
console.error('Failed to register the callback for screen changes. Code: ' + JSON.stringify(exception));
};
screen.off("connect", callback);
```
## screen.makeExpand
......@@ -132,18 +156,30 @@ makeExpand(options:Array&lt;ExpandOption&gt;, callback: AsyncCallback&lt;number&
| options | Array&lt;[ExpandOption](#expandoption)&gt; | 是 | 设置扩展屏幕的参数集合。 |
| callback | Callback&lt;number&gt; | 是 | 回调函数。返回扩展屏幕的群组id。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
var groupId = null;
screen.makeExpand([{screenId: 0, startX: 0, startY: 0}, {screenId: 1, startX: 1080, startY: 0}], (err, data) => {
try {
let groupId = null;
screen.makeExpand([{screenId: 0, startX: 0, startY: 0}, {screenId: 1, startX: 1080, startY: 0}], (err, data) => {
if (err.code) {
console.error('Failed to make screens as expand-screen. Cause:' + JSON.stringify(err));
console.error('Failed to make screens as expand-screen. Code:' + JSON.stringify(err));
return;
}
groupId = data;
console.info('Succeeded in making screens as expand-screen.Data:' + JSON.stringify(data));
});
console.info('Succeeded in making screens as expand-screen. Data: ' + JSON.stringify(data));
});
} catch (exception) {
console.error('Failed to make screens as expand-screen. Code: ' + JSON.stringify(exception));
};
```
## screen.makeExpand
......@@ -166,14 +202,26 @@ makeExpand(options:Array&lt;ExpandOption&gt;): Promise&lt;number&gt;
| --------------------- | ----------------------------------- |
| Promise&lt;number&gt; | Promise对象。返回扩展屏幕的群组id。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
screen.makeExpand([{screenId: 0, startX: 0, startY: 0}, {screenId: 1, startX: 1080, startY: 0}]).then((data) => {
console.info('Succeeded in making screens as expand-screen.Data:' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to make screens as expand-screen. Cause:' + JSON.stringify(err));
});
try {
screen.makeExpand([{screenId: 0, startX: 0, startY: 0}, {screenId: 1, startX: 1080, startY: 0}]).then((data) => {
console.info('Succeeded in making screens as expand-screen. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to make screens as expand-screen. Code:' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to make screens as expand-screen. Code: ' + JSON.stringify(exception));
};
```
## screen.makeMirror
......@@ -192,18 +240,30 @@ makeMirror(mainScreen:number, mirrorScreen:Array&lt;number&gt;, callback: AsyncC
| mirrorScreen | Array&lt;number&gt; | 是 | 镜像屏幕id集合。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数。返回镜像屏幕的群组id。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
var mainScreenId = 0;
var mirrorScreenIds = [1, 2, 3];
screen.makeMirror(mainScreenId, mirrorScreenIds, (err, data) => {
let mainScreenId = 0;
let mirrorScreenIds = [1, 2, 3];
try {
screen.makeMirror(mainScreenId, mirrorScreenIds, (err, data) => {
if (err.code) {
console.error('Failed to make screens as mirror-screen.Cause:' + JSON.stringify(err));
console.error('Failed to make screens as mirror-screen. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in making screens as mirror-screen.Data:' + JSON.stringify(data));
});
console.info('Succeeded in making screens as mirror-screen. Data: ' + JSON.stringify(data));
});
} catch (exception) {
console.error('Failed to make screens as mirror-screen. Code: ' + JSON.stringify(exception));
};
```
## screen.makeMirror
......@@ -227,16 +287,28 @@ makeMirror(mainScreen:number, mirrorScreen:Array&lt;number&gt;): Promise&lt;numb
| --------------------- | ----------------------------------- |
| Promise&lt;number&gt; | Promise对象。返回镜像屏幕的群组id。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
var mainScreenId = 0;
var mirrorScreenIds = [1, 2, 3];
screen.makeMirror(mainScreenId, mirrorScreenIds).then((data) => {
console.info('Succeeded in making screens as mirror-screen.Data:' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to make screens as mirror-screen.Cause:' + JSON.stringify(err));
});
let mainScreenId = 0;
let mirrorScreenIds = [1, 2, 3];
try {
screen.makeMirror(mainScreenId, mirrorScreenIds).then((data) => {
console.info('Succeeded in making screens as mirror-screen. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to make screens as mirror-screen. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to make screens as mirror-screen. Code: ' + JSON.stringify(exception));
};
```
## screen.createVirtualScreen
......@@ -256,24 +328,36 @@ createVirtualScreen(options:VirtualScreenOption, callback: AsyncCallback&lt;Scre
| options | [VirtualScreenOption](#virtualscreenoption) | 是 | 用于创建虚拟屏幕的参数。 |
| callback | AsyncCallback&lt;[Screen](#screen)&gt; | 是 | 回调函数,返回创建的虚拟屏幕对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
var screenClass = null;
screen.createVirtualScreen({
let screenClass = null;
try {
screen.createVirtualScreen({
name: 'screen01',
width: 1080,
height: 2340,
density: 2,
surfaceId: ''
}, (err, data) => {
}, (err, data) => {
if (err.code) {
console.error('Failed to create virtual screen.Cause:' + JSON.stringify(err));
console.error('Failed to create virtual screen. Code: ' + JSON.stringify(err));
return;
}
screenClass = data;
console.info('Succeeded in creating virtual screen.Data:' + JSON.stringify(data));
});
console.info('Succeeded in creating virtual screen. Data: ' + JSON.stringify(data));
});
} catch (exception) {
console.error('Failed to create virtual screen. Code: ' + JSON.stringify(exception));
};
```
## screen.createVirtualScreen
......@@ -298,22 +382,34 @@ createVirtualScreen(options:VirtualScreenOption): Promise&lt;Screen&gt;
| -------------------------------- | ------------------------------------- |
| Promise&lt;[Screen](#screen)&gt; | Promise对象。返回创建的虚拟屏幕对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
var screenClass = null;
screen.createVirtualScreen({
let screenClass = null;
try {
screen.createVirtualScreen({
name: 'screen01',
width: 1080,
height: 2340,
density: 2,
surfaceId: ''
}).then((data) => {
}).then((data) => {
screenClass = data;
console.info('Succeeded in creating virtual screen.Data:' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to create virtual screen.Cause:' + JSON.stringify(err));
});
console.info('Succeeded in creating virtual screen. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to create virtual screen. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to create virtual screen. Code: ' + JSON.stringify(exception));
};
```
## screen.destroyVirtualScreen
......@@ -331,17 +427,29 @@ destroyVirtualScreen(screenId:number, callback: AsyncCallback&lt;void&gt;): void
| screenId | number | 是 | 屏幕的id。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当销毁虚拟屏幕成功,err为undefined,否则为错误对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------------- |
| 1400002 | This operation is not access. |
**示例:**
```js
var screenId = 1;
screen.destroyVirtualScreen(screenId, (err,data) => {
let screenId = 1;
try {
screen.destroyVirtualScreen(screenId, (err,data) => {
if (err.code) {
console.error('Failed to destroy virtual screen.Cause:' + JSON.stringify(err));
console.error('Failed to destroy virtual screen. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in destroying virtual screen.');
});
});
} catch (exception) {
console.error('Failed to destroy virtual screen. Code: ' + JSON.stringify(exception));
};
```
## screen.destroyVirtualScreen
......@@ -364,15 +472,27 @@ destroyVirtualScreen(screenId:number): Promise&lt;void&gt;
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------------- |
| 1400002 | This operation is not access. |
**示例:**
```js
var screenId = 1;
screen.destroyVirtualScreen(screenId).then((data) => {
let screenId = 1;
try {
screen.destroyVirtualScreen(screenId).then((data) => {
console.info('Succeeded in destroying virtual screen.');
}).catch((err) => {
console.error('Failed to destroy virtual screen.Cause:' + JSON.stringify(err));
});
}).catch((err) => {
console.error('Failed to destroy virtual screen. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to destroy virtual screen. Code: ' + JSON.stringify(exception));
};
```
## screen.setVirtualScreenSurface
......@@ -393,18 +513,30 @@ setVirtualScreenSurface(screenId:number, surfaceId: string, callback: AsyncCallb
| surfaceId | string | 是 | surface的id。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当设置虚拟屏幕surface成功,err为undefined,否则为错误对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
var screenId = 1;
var surfaceId = '2048';
screen.setVirtualScreenSurface(screenId, surfaceId, (err,data) => {
let screenId = 1;
let surfaceId = '2048';
try {
screen.setVirtualScreenSurface(screenId, surfaceId, (err,data) => {
if (err.code) {
console.error('Failed to Set surface for the virtual screen.Cause:' + JSON.stringify(err));
console.error('Failed to Set surface for the virtual screen. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting surface for the virtual screen.');
});
});
} catch (exception) {
console.error('Failed to Set surface for the virtual screen. Code: ' + JSON.stringify(exception));
};
```
## screen.setVirtualScreenSurface
......@@ -430,16 +562,28 @@ setVirtualScreenSurface(screenId:number, surfaceId: string): Promise&lt;void&gt;
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------- |
| 1400001 | This is invalid screen. |
**示例:**
```js
var screenId = 1;
var surfaceId = '2048';
screen.setVirtualScreenSurface(screenId, surfaceId).then((data) => {
let screenId = 1;
let surfaceId = '2048';
try {
screen.setVirtualScreenSurface(screenId, surfaceId).then((data) => {
console.info('Succeeded in setting surface for the virtual screen.');
}).catch((err) => {
console.error('Failed to Set surface for the virtual screen.Cause:' + JSON.stringify(err));
});
}).catch((err) => {
console.error('Failed to Set surface for the virtual screen. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to Set surface for the virtual screen. Code: ' + JSON.stringify(exception));
};
```
## screen.isScreenRotationLocked
......@@ -515,12 +659,16 @@ setScreenRotationLocked(isLocked: boolean): Promise&lt;void&gt;
**示例:**
```js
var isLocked = false;
screen.setScreenRotationLocked(isLocked).then((data) => {
let isLocked = false;
try {
screen.setScreenRotationLocked(isLocked).then((data) => {
console.info('Succeeded in setting whether to lock screen rotation');
}).catch((err) => {
console.error('Failed to set whether to lock screen rotation. Cause:' + JSON.stringify(err));
});
}).catch((err) => {
console.error('Failed to set whether to lock screen rotation. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set whether to lock screen rotation. Code: ' + JSON.stringify(exception));
};
```
## screen.setScreenRotationLocked
......@@ -541,14 +689,18 @@ setScreenRotationLocked(isLocked: boolean, callback: AsyncCallback&lt;void&gt;):
**示例:**
```js
var isLocked = false;
screen.setScreenRotationLocked(isLocked, (err, data) => {
let isLocked = false;
try {
screen.setScreenRotationLocked(isLocked, (err, data) => {
if (err.code) {
console.error('Failed to set whether to lock screen rotation. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting whether to lock screen rotation.');
});
});
} catch (exception) {
console.error('Failed to set whether to lock screen rotation. Code: ' + JSON.stringify(exception));
};
```
## ExpandOption
......@@ -606,16 +758,28 @@ setOrientation(orientation: Orientation, callback: AsyncCallback&lt;void&gt;): v
| orientation | [Orientation](#orientation) | 是 | 屏幕方向。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当设置屏幕方向成功,err为undefined,否则为错误对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 1400003 | This window manager service work abnormally. |
**示例:**
```js
screenClass.setOrientation(screen.Orientation.VERTICAL, (err, data) => {
try {
screenClass.setOrientation(screen.Orientation.VERTICAL, (err, data) => {
if (err.code) {
console.error('Failed to setOrientation VERTICAL. Cause: ' + JSON.stringify(err));
console.error('Failed to set Orientation VERTICAL. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting Orientation VERTICAL. data: ' + JSON.stringify(data));
})
});
} catch (exception) {
console.error('Failed to set Orientation VERTICAL. Code: ' + JSON.stringify(exception));
};
```
### setOrientation
......@@ -636,15 +800,27 @@ setOrientation(orientation: Orientation): Promise&lt;void&gt;
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 1400003 | This window manager service work abnormally. |
**示例:**
```js
let promise = screenClass.setOrientation(screen.Orientation.VERTICAL);
promise.then((data) => {
try {
let promise = screenClass.setOrientation(screen.Orientation.VERTICAL);
promise.then((data) => {
console.info('Succeeded in setting Orientation VERTICAL. Data: ' + JSON.stringify(data));
}).catch((err) => {
}).catch((err) => {
console.error('Failed to set Orientation VERTICAL. Cause: ' + JSON.stringify(err));
})
});
} catch (exception) {
console.error('Failed to set Orientation VERTICAL. Code: ' + JSON.stringify(exception));
};
```
### setScreenActiveMode
......@@ -660,17 +836,29 @@ setScreenActiveMode(modeIndex: number, callback: AsyncCallback&lt;void&gt;): voi
| modeIndex | number | 是 | 模式索引。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当设置屏幕当前显示模式成功,err为undefined,否则为错误对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 1400003 | This window manager service work abnormally. |
**示例:**
```js
var modeIndex = 0;
screenClass.setScreenActiveMode(modeIndex, (err, data) => {
let modeIndex = 0;
try {
screenClass.setScreenActiveMode(modeIndex, (err, data) => {
if (err.code) {
console.error('Failed to set ScreenActiveMode 0. Cause: ' + JSON.stringify(err));
console.error('Failed to set ScreenActiveMode 0. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting ScreenActiveMode 0. data: ' + JSON.stringify(data));
})
});
} catch (exception) {
console.error('Failed to set ScreenActiveMode 0. Code: ' + JSON.stringify(exception));
};
```
### setScreenActiveMode
......@@ -691,16 +879,28 @@ setScreenActiveMode(modeIndex: number): Promise&lt;void&gt;
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 1400003 | This window manager service work abnormally. |
**示例:**
```js
var modeIndex = 0;
let promise = screenClass.setScreenActiveMode(modeIndex);
promise.then((data) => {
let modeIndex = 0;
try {
let promise = screenClass.setScreenActiveMode(modeIndex);
promise.then((data) => {
console.info('Succeeded in setting ScreenActiveMode 0. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to set ScreenActiveMode 0. Cause: ' + JSON.stringify(err));
})
}).catch((err) => {
console.error('Failed to set ScreenActiveMode 0. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set ScreenActiveMode 0. Code: ' + JSON.stringify(exception));
};
```
### setDensityDpi
......@@ -716,17 +916,29 @@ setDensityDpi(densityDpi: number, callback: AsyncCallback&lt;void&gt;): void;
| densityDpi | number | 是 | 像素密度。支持的输入范围为80-640。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当设置屏幕的像素密度成功,err为undefined,否则为错误对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 1400003 | This window manager service work abnormally. |
**示例:**
```js
var densityDpi = 320;
screenClass.setDensityDpi(densityDpi, (err, data) => {
let densityDpi = 320;
try {
screenClass.setDensityDpi(densityDpi, (err, data) => {
if (err.code) {
console.error('Failed to set DensityDpi 320. Cause: ' + JSON.stringify(err));
console.error('Failed to set DensityDpi 320. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeed in setting DensityDpi 320. data: ' + JSON.stringify(data));
})
});
} catch (exception) {
console.error('Failed to set DensityDpi 320. Code: ' + JSON.stringify(exception));
};
```
### setDensityDpi
......@@ -747,16 +959,28 @@ setDensityDpi(densityDpi: number): Promise&lt;void&gt;
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:**
以下错误码的详细介绍请参见[屏幕错误码](../errorcodes/errorcode-display.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 1400003 | This window manager service work abnormally. |
**示例:**
```js
var densityDpi = 320;
var promise = screenClass.setDensityDpi(densityDpi);
promise.then((data) => {
let densityDpi = 320;
try {
let promise = screenClass.setDensityDpi(densityDpi);
promise.then((data) => {
console.info('Succeeded in setting DensityDpi 320. Data: ' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to set DensityDpi 320. Cause: ' + JSON.stringify(err));
})
}).catch((err) => {
console.error('Failed to set DensityDpi 320. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set DensityDpi 320. Code: ' + JSON.stringify(exception));
};
```
## Orientation
......
......@@ -73,7 +73,7 @@ save(options: ScreenshotOptions, callback: AsyncCallback&lt;image.PixelMap&gt;):
**示例:**
```js
var screenshotOptions = {
let screenshotOptions = {
"screenRect": {
"left": 200,
"top": 100,
......@@ -85,14 +85,18 @@ save(options: ScreenshotOptions, callback: AsyncCallback&lt;image.PixelMap&gt;):
"rotation": 0,
"displayId": 0
};
try {
screenshot.save(screenshotOptions, (err, pixelMap) => {
if (err) {
console.log('Failed to save screenshot: ' + JSON.stringify(err));
console.log('Failed to save screenshot. Code: ' + JSON.stringify(err));
return;
}
console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
pixelMap.release(); // PixelMap使用完后及时释放内存
});
} catch (exception) {
console.error('Failed to save screenshot. Code: ' + JSON.stringify(exception));
};
```
## screenshot.save
......@@ -114,14 +118,18 @@ save(callback: AsyncCallback&lt;image.PixelMap&gt;): void
**示例:**
```js
try {
screenshot.save((err, pixelMap) => {
if (err) {
console.log('Failed to save screenshot: ' + JSON.stringify(err));
console.log('Failed to save screenshot. Code: ' + JSON.stringify(err));
return;
}
console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
pixelMap.release(); // PixelMap使用完后及时释放内存
});
} catch (exception) {
console.error('Failed to save screenshot. Code: ' + JSON.stringify(exception));
};
```
## screenshot.save
......@@ -149,7 +157,7 @@ save(options?: ScreenshotOptions): Promise&lt;image.PixelMap&gt;
**示例:**
```js
var screenshotOptions = {
let screenshotOptions = {
"screenRect": {
"left": 200,
"top": 100,
......@@ -161,11 +169,15 @@ save(options?: ScreenshotOptions): Promise&lt;image.PixelMap&gt;
"rotation": 0,
"displayId": 0
};
try {
let promise = screenshot.save(screenshotOptions);
promise.then((pixelMap) => {
console.log('Succeeded in saving sreenshot. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
pixelMap.release(); // PixelMap使用完后及时释放内存
}).catch((err) => {
console.log('Failed to save screenshot: ' + JSON.stringify(err));
console.log('Failed to save screenshot. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to save screenshot. Code: ' + JSON.stringify(exception));
};
```
因为 它太大了无法显示 source diff 。你可以改为 查看blob
# 屏幕错误码
## 1400001 无效虚拟屏
### 错误信息
This is invalid screen.
### 错误描述
当操作无效的虚拟屏时,会报此错误码。
### 可能原因
1. 虚拟屏未创建。
2. 虚拟屏已销毁。
### 处理步骤
1. 在操作虚拟屏前,检查该虚拟屏是否已经存在,确保已创建该虚拟屏。
2. 在操作虚拟屏前,检查虚拟屏是否已被销毁,确保其未被销毁,再进行相关操作。
## 1400002 无权限操作
### 错误信息
This operation is not access.
### 错误描述
当对无操作权限的对象进行操作时,会报此错误码。
### 可能原因
操作了其它进程的虚拟屏对象。
### 处理步骤
请检查是否非法操作了别的进程的对象,删除相关非法操作。
## 1400003 系统服务工作异常
### 错误信息
This window manager service work abnormally.
### 错误描述
当系统服务工作异常时,会报此错误码。
### 可能原因
1. 窗口内部服务没有正常启动。
2. 底层图形图像合成渲染异常。
### 处理步骤
系统服务内部工作异常,请稍候重试,或者重启设备尝试。
# 窗口错误码
## 1300001 重复操作
### 错误信息
This is repeat operation.
### 错误描述
当进行某些重复操作时,系统会报此错误码。
### 可能原因
创建的窗口已经存在时,再次创建该窗口会报错。
### 处理步骤
在创建窗口前,检查该窗口是否已经存在,确保为首次创建该窗口。
## 1300002 窗口状态异常
### 错误信息
This window state is abnormal.
### 错误描述
当窗口状态异常,如已被销毁时,操作该窗口,会报此错误码。
### 可能原因
操作窗口时,该窗口已被销毁。
### 处理步骤
在对窗口进行操作前,检查该窗口是否存在,确保其未被销毁,再进行相关操作。
## 1300003 系统服务工作异常
### 错误信息
This window manager service work abnormally.
### 错误描述
当系统服务工作异常时,会报此错误码。
### 可能原因
窗口内部服务没有正常启动。
### 处理步骤
系统服务内部工作异常,请稍候重试,或者重启设备尝试。
## 1300004 无权限操作
### 错误信息
This operation is not access.
### 错误描述
当对无操作权限的对象进行操作时,会报此错误码。
### 可能原因
操作了其它进程的窗口对象。
### 处理步骤
请检查是否非法操作了别的进程的对象,删除相关操作。
## 1300005 WindowStage异常
### 错误信息
This window stage is abnormal.
### 错误描述
当WindowStage异常,如已被销毁时,操作该WindowStage,会报此错误码。
### 可能原因
操作WindowStage时,该WindowStage已被销毁。
### 处理步骤
在对WindowStage进行操作前,检查该WindowStage是否存在,若已被销毁,请释放该WindowStage下的窗口。
## 1300006 窗口上下文异常
### 错误信息
This window context is abnormal.
### 错误描述
当窗口上下文异常,如已被销毁时,操作该窗口上下文,会报此错误码。
### 可能原因
操作窗口上下文时,该窗口上下文已被销毁。
### 处理步骤
在对窗口上下文进行操作前,检查该窗口上下文是否存在,确保其未被销毁,再进行相关操作。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册