From ef50001aa43bcde61147b63bf1f7ed295ea2b292 Mon Sep 17 00:00:00 2001 From: zhengjiangliang Date: Tue, 18 Oct 2022 19:52:46 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=A0=81=E6=95=B4=E6=94=B9?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E6=A0=BC=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I33f1c5fe32603eefb1d51dba1a56f0f0e54315e7 Signed-off-by: zhengjiangliang --- .../reference/apis/js-apis-display.md | 14 +- .../reference/apis/js-apis-screen.md | 4 +- .../reference/apis/js-apis-window.md | 125 ++++++++---------- .../reference/errorcodes/errorcode-display.md | 33 +++-- .../reference/errorcodes/errorcode-window.md | 66 +++++---- 5 files changed, 131 insertions(+), 111 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-display.md b/zh-cn/application-dev/reference/apis/js-apis-display.md index 91d9a4e985..16f4b444df 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-display.md +++ b/zh-cn/application-dev/reference/apis/js-apis-display.md @@ -89,8 +89,9 @@ getDefaultDisplaySync(): Display **示例:** ```js +let displayClass = null; try { - let displayClass = display.getDefaultDisplaySync(); + displayClass = display.getDefaultDisplaySync(); } catch (exception) { console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); }; @@ -208,8 +209,9 @@ try { return; }; +let ret = undefined; try { - let ret = display.hasPrivateWindow(displayClass.id); + ret = display.hasPrivateWindow(displayClass.id); } catch (exception) { console.error('Failed to check has privateWindow or not. Code: ' + JSON.stringify(exception)); }; @@ -243,7 +245,7 @@ on(type: 'add'|'remove'|'change', callback: Callback<number>): void ```js let callback = (data) => { console.info('Listening enabled. Data: ' + JSON.stringify(data)); -} +}; try { display.on("add", callback); } catch (exception) { @@ -445,8 +447,9 @@ getCutoutInfo(callback: AsyncCallback<CutoutInfo>): void **示例:** ```js +let displayClass = null; try { - let displayClass = display.getDefaultDisplaySync(); + displayClass = display.getDefaultDisplaySync(); } catch (exception) { console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); }; @@ -483,8 +486,9 @@ getCutoutInfo(): Promise<CutoutInfo> **示例:** ```js +let displayClass = null; try { - let displayClass = display.getDefaultDisplaySync(); + displayClass = display.getDefaultDisplaySync(); } catch (exception) { console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); }; diff --git a/zh-cn/application-dev/reference/apis/js-apis-screen.md b/zh-cn/application-dev/reference/apis/js-apis-screen.md index 52ba0e627b..b74622b0c9 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-screen.md +++ b/zh-cn/application-dev/reference/apis/js-apis-screen.md @@ -39,7 +39,7 @@ getAllScreens(callback: AsyncCallback<Array<Screen>>): void **示例:** ```js -var screenClass = null; +let screenClass = null; screen.getAllScreens((err, data) => { if (err.code) { console.error('Failed to get all screens . Cause: ' + JSON.stringify(err)); @@ -75,7 +75,7 @@ getAllScreens(): Promise<Array<Screen>> **示例:** ```js -var screenClass = null; +let screenClass = null; let promise = screen.getAllScreens(); promise.then((data) => { screenClass = data[0]; diff --git a/zh-cn/application-dev/reference/apis/js-apis-window.md b/zh-cn/application-dev/reference/apis/js-apis-window.md index 0d28afc2ae..80b944a73d 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-window.md +++ b/zh-cn/application-dev/reference/apis/js-apis-window.md @@ -592,6 +592,7 @@ minimizeAll(id: number): Promise<void> import display from '@ohos.display' import window from '@ohos.window' +let displayClass = null; try { displayClass = display.getDefaultDisplaySync(); } catch (exception) { @@ -923,7 +924,7 @@ create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback&l ```js let windowClass = null; - window.create(this.context, 'alertWindow', window.WindowType.TYPE_SYSTEM_ALERT, (err, data) => { +window.create(this.context, 'alertWindow', window.WindowType.TYPE_SYSTEM_ALERT, (err, data) => { if (err.code) { console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); return; @@ -998,13 +999,13 @@ find(id: string, callback: AsyncCallback<Window>): void ```js let windowClass = null; - window.find('alertWindow', (err, data) => { - if (err.code) { - console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); - return; - } - windowClass = data; - console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); +window.find('alertWindow', (err, data) => { + if (err.code) { + console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); + return; + } + windowClass = data; + console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); }); ``` @@ -1038,7 +1039,7 @@ find(id: string): Promise<Window> let windowClass = null; let promise = window.find('alertWindow'); promise.then((data)=> { - windowClass = data; + windowClass = data; console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); @@ -1105,7 +1106,7 @@ getTopWindow(): Promise<Window> let windowClass = null; let promise = window.getTopWindow(); promise.then((data)=> { - windowClass = data; + windowClass = data; console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); @@ -2354,25 +2355,20 @@ loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void **示例:** ```ts -class myAbility extends Ability { - storage : LocalStorage - onWindowStageCreate(windowStage) { - this.storage = new LocalStorage(); - this.storage.setOrCreate('storageSimpleProp',121); - console.log('onWindowStageCreate'); - try { - windowStage.loadContent('pages/page2',this.storage,(err) => { - if (err.code) { - console.error('Failed to load the content. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in loading the content.'); - }); - } catch (exception) { - console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); - }; - } -} +let storage = new LocalStorage(); +storage.setOrCreate('storageSimpleProp',121); +console.log('onWindowStageCreate'); +try { + windowClass.loadContent('pages/page2', storage, (err) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content.'); + }); +} catch (exception) { + console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); +}; ``` ### loadContent9+ @@ -2410,26 +2406,19 @@ loadContent(path: string, storage: LocalStorage): Promise<void> **示例:** ```ts -class myAbility extends Ability { - storage : LocalStorage - onWindowStageCreate(windowStage) { - this.storage = new LocalStorage(); - this.storage.setOrCreate('storageSimpleProp',121); - console.log('onWindowStageCreate'); - let windowClass = null; - try { - let promise = windowStage.loadContent('pages/page2',this.storage); - promise.then(()=> { - windowClass = data; - console.info('Succeeded in loading the content.'); - }).catch((err)=>{ - console.error('Failed to load the content. Cause:' + JSON.stringify(err)); - }); - } catch (exception) { - console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); - }; - } -} +let storage = new LocalStorage(); +storage.setOrCreate('storageSimpleProp',121); +console.log('onWindowStageCreate'); +try { + let promise = windowClass.loadContent('pages/page2', storage); + promise.then(() => { + console.info('Succeeded in loading the content.'); + }).catch((err) => { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + }); +} catch (exception) { + console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); +}; ``` ### isWindowShowing9+ @@ -2725,7 +2714,7 @@ off(type: 'screenshot', callback?: Callback<void>): void ```js let callback = ()=>{ console.info('screenshot happened'); -} +}; try { windowClass.on('screenshot', callback); } catch (exception) { @@ -3751,13 +3740,13 @@ snapshot(callback: AsyncCallback<image.PixelMap>): void **示例:** ```js -windowClass.snapshot((err, data) => { +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()); - data.release(); // PixelMap使用完后及时释放内存 + pixelMap.release(); // PixelMap使用完后及时释放内存 }); ``` @@ -3861,9 +3850,9 @@ scale(scaleOptions: ScaleOptions): void let obj : window.ScaleOptions = { x : 2.0, y : 1.0, - pivotX = 0.5; - pivotY = 0.5; -} + pivotX : 0.5, + pivotY : 0.5 +}; try { windowClass.scale(obj); } catch (exception) { @@ -3903,9 +3892,9 @@ let obj : window.RotateOptions = { x : 1.0, y : 1.0, z : 45.0, - pivotX = 0.5; - pivotY = 0.5; -} + pivotX : 0.5, + pivotY : 0.5 +}; try { windowClass.rotate(obj); } catch (exception) { @@ -3945,7 +3934,7 @@ let obj : window.TranslateOptions = { x : 100.0, y : 0.0, z : 0.0 -} +}; try { windowClass.translate(obj); } catch (exception) { @@ -3983,7 +3972,7 @@ try { ```js let controller = windowClass.getTransitionController(); // 获取属性转换控制器 controller.animationForHidden = (context : window.TransitionContext) => { - let toWindow = context.toWindow + let toWindow = context.toWindow; animateTo({ duration: 1000, // 动画时长 tempo: 0.5, // 播放速率 @@ -3999,7 +3988,7 @@ controller.animationForHidden = (context : window.TransitionContext) => { x : 100.0, y : 0.0, z : 0.0 - } + }; toWindow.translate(obj); // 设置动画过程中的属性转换 console.info('toWindow translate end'); } @@ -4114,7 +4103,7 @@ setBackdropBlurStyle(blurStyle: BlurStyle): void ```js try { - windowClass.setBackdropBlurStyle(window.BlurType.THIN); + windowClass.setBackdropBlurStyle(window.BlurStyle.THIN); } catch (exception) { console.error('Failed to set backdrop blur style. Cause: ' + JSON.stringify(exception)); }; @@ -6537,7 +6526,7 @@ completeTransition(isCompleted: boolean): void ```js let controller = windowClass.getTransitionController(); controller.animationForShown = (context : window.TransitionContext) => { - let toWindow = context.toWindow + let toWindow = context.toWindow; animateTo({ duration: 1000, // 动画时长 tempo: 0.5, // 播放速率 @@ -6550,7 +6539,7 @@ controller.animationForShown = (context : window.TransitionContext) => { x : 100.0, y : 0.0, z : 0.0 - } + }; toWindow.translate(obj); console.info('toWindow translate end'); } @@ -6589,7 +6578,7 @@ animationForShown(context: TransitionContext): void ```js let controller = windowClass.getTransitionController(); controller.animationForShown = (context : window.TransitionContext) => { - let toWindow = context.toWindow + let toWindow = context.toWindow; animateTo({ duration: 1000, // 动画时长 tempo: 0.5, // 播放速率 @@ -6605,7 +6594,7 @@ controller.animationForShown = (context : window.TransitionContext) => { x : 100.0, y : 0.0, z : 0.0 - } + }; toWindow.translate(obj); console.info('toWindow translate end'); } @@ -6635,7 +6624,7 @@ animationForHidden(context: TransitionContext): void ```js let controller = windowClass.getTransitionController(); controller.animationForHidden = (context : window.TransitionContext) => { - let toWindow = context.toWindow + let toWindow = context.toWindow; animateTo({ duration: 1000, // 动画时长 tempo: 0.5, // 播放速率 @@ -6651,7 +6640,7 @@ controller.animationForHidden = (context : window.TransitionContext) => { x : 100.0, y : 0.0, z : 0.0 - } + }; toWindow.translate(obj); console.info('toWindow translate end'); } diff --git a/zh-cn/application-dev/reference/errorcodes/errorcode-display.md b/zh-cn/application-dev/reference/errorcodes/errorcode-display.md index 2d19ab6593..166bb9d68f 100755 --- a/zh-cn/application-dev/reference/errorcodes/errorcode-display.md +++ b/zh-cn/application-dev/reference/errorcodes/errorcode-display.md @@ -1,34 +1,43 @@ # 屏幕错误码 ## 1400001 无效虚拟屏 -### 错误信息 +**错误信息**
This is invalid screen. -### 错误描述 + +**错误描述**
当操作无效的虚拟屏时,会报此错误码。 -### 可能原因 + +**可能原因** 1. 虚拟屏未创建。 2. 虚拟屏已销毁。 -### 处理步骤 + +**处理步骤** 1. 在操作虚拟屏前,检查该虚拟屏是否已经存在,确保已创建该虚拟屏。 2. 在操作虚拟屏前,检查虚拟屏是否已被销毁,确保其未被销毁,再进行相关操作。 ## 1400002 无权限操作 -### 错误信息 +**错误信息**
This operation is not access. -### 错误描述 + +**错误描述**
当对无操作权限的对象进行操作时,会报此错误码。 -### 可能原因 + +**可能原因**
操作了其它进程的虚拟屏对象。 -### 处理步骤 + +**处理步骤**
请检查是否非法操作了别的进程的对象,删除相关非法操作。 ## 1400003 系统服务工作异常 -### 错误信息 +**错误信息**
This window manager service work abnormally. -### 错误描述 + +**错误描述**
当系统服务工作异常时,会报此错误码。 -### 可能原因 + +**可能原因** 1. 窗口内部服务没有正常启动。 2. 底层图形图像合成渲染异常。 -### 处理步骤 + +**处理步骤**
系统服务内部工作异常,请稍候重试,或者重启设备尝试。 diff --git a/zh-cn/application-dev/reference/errorcodes/errorcode-window.md b/zh-cn/application-dev/reference/errorcodes/errorcode-window.md index f55c63a902..3239f04eb5 100755 --- a/zh-cn/application-dev/reference/errorcodes/errorcode-window.md +++ b/zh-cn/application-dev/reference/errorcodes/errorcode-window.md @@ -1,61 +1,79 @@ # 窗口错误码 ## 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. -### 错误描述 + +**错误描述**
当窗口上下文异常,如已被销毁时,操作该窗口上下文,会报此错误码。 -### 可能原因 + +**可能原因**
操作窗口上下文时,该窗口上下文已被销毁。 -### 处理步骤 + +**处理步骤**
在对窗口上下文进行操作前,检查该窗口上下文是否存在,确保其未被销毁,再进行相关操作。 -- GitLab