提交 cb4606f0 编写于 作者: Z zhengjiangliang

doc文档示例代码整改

Change-Id: I575b55db46ebae64b56392192773eab0ff73ce08
Signed-off-by: Nzhengjiangliang <zhengjiangliang@huawei.com>
上级 edf2468e
...@@ -94,7 +94,7 @@ try { ...@@ -94,7 +94,7 @@ try {
displayClass = display.getDefaultDisplaySync(); displayClass = display.getDefaultDisplaySync();
} catch (exception) { } catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
}; }
``` ```
## display.getAllDisplays<sup>9+</sup> ## display.getAllDisplays<sup>9+</sup>
...@@ -204,25 +204,24 @@ hasPrivateWindow(displayId: number): boolean ...@@ -204,25 +204,24 @@ hasPrivateWindow(displayId: number): boolean
let displayClass = null; let displayClass = null;
try { try {
displayClass = display.getDefaultDisplaySync(); displayClass = display.getDefaultDisplaySync();
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
return;
};
let ret = undefined; let ret = undefined;
try { try {
ret = display.hasPrivateWindow(displayClass.id); ret = display.hasPrivateWindow(displayClass.id);
} catch (exception) { } catch (exception) {
console.error('Failed to check has privateWindow or not. Code: ' + JSON.stringify(exception)); console.error('Failed to check has privateWindow or not. Code: ' + JSON.stringify(exception));
}; }
if (ret == undefined) { if (ret == undefined) {
console.log("Failed to check has privateWindow or not."); console.log("Failed to check has privateWindow or not.");
} }
if (ret) { if (ret) {
console.log("There has privateWindow."); console.log("There has privateWindow.");
} else if (!ret) { } else if (!ret) {
console.log("There has no privateWindow."); console.log("There has no privateWindow.");
}; }
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
}
``` ```
## display.on('add'|'remove'|'change') ## display.on('add'|'remove'|'change')
...@@ -250,7 +249,7 @@ try { ...@@ -250,7 +249,7 @@ try {
display.on("add", callback); display.on("add", callback);
} catch (exception) { } catch (exception) {
console.error('Failed to register callback. Code: ' + JSON.stringify(exception)); console.error('Failed to register callback. Code: ' + JSON.stringify(exception));
}; }
``` ```
## display.off('add'|'remove'|'change') ## display.off('add'|'remove'|'change')
...@@ -275,7 +274,7 @@ try { ...@@ -275,7 +274,7 @@ try {
display.off("remove"); display.off("remove");
} catch (exception) { } catch (exception) {
console.error('Failed to unregister callback. Code: ' + JSON.stringify(exception)); console.error('Failed to unregister callback. Code: ' + JSON.stringify(exception));
}; }
``` ```
## display.getDefaultDisplay<sup>(deprecated)</sup> ## display.getDefaultDisplay<sup>(deprecated)</sup>
...@@ -450,17 +449,17 @@ getCutoutInfo(callback: AsyncCallback&lt;CutoutInfo&gt;): void ...@@ -450,17 +449,17 @@ getCutoutInfo(callback: AsyncCallback&lt;CutoutInfo&gt;): void
let displayClass = null; let displayClass = null;
try { try {
displayClass = display.getDefaultDisplaySync(); displayClass = display.getDefaultDisplaySync();
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
};
displayClass.getCutoutInfo((err, data) => { displayClass.getCutoutInfo((err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to get cutoutInfo. Code: ' + JSON.stringify(err)); console.error('Failed to get cutoutInfo. Code: ' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in getting cutoutInfo. data: ' + JSON.stringify(data)); console.info('Succeeded in getting cutoutInfo. data: ' + JSON.stringify(data));
}); });
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
}
``` ```
### getCutoutInfo<sup>9+</sup> ### getCutoutInfo<sup>9+</sup>
getCutoutInfo(): Promise&lt;CutoutInfo&gt; getCutoutInfo(): Promise&lt;CutoutInfo&gt;
...@@ -489,12 +488,14 @@ getCutoutInfo(): Promise&lt;CutoutInfo&gt; ...@@ -489,12 +488,14 @@ getCutoutInfo(): Promise&lt;CutoutInfo&gt;
let displayClass = null; let displayClass = null;
try { try {
displayClass = display.getDefaultDisplaySync(); displayClass = display.getDefaultDisplaySync();
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
};
let promise = displayClass.getCutoutInfo(); let promise = displayClass.getCutoutInfo();
promise.then((data) => { promise.then((data) => {
console.info('Succeeded in getting cutoutInfo. Data: ' + JSON.stringify(data)); console.info('Succeeded in getting cutoutInfo. Data: ' + JSON.stringify(data));
}); }).catch((err) => {
console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
}
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册