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

!23505 Accessibility ArkTS规范整改

Merge pull request !23505 from zhanghuiyu/master
...@@ -40,7 +40,7 @@ AccessibilityExtensionAbility为无障碍扩展服务框架,允许三方开发 ...@@ -40,7 +40,7 @@ AccessibilityExtensionAbility为无障碍扩展服务框架,允许三方开发
在已创建工程的ets文件夹下创建AccessibilityExtAbility文件夹,在该文件夹下创建AccessibilityExtAbility.ts文件,在新增的文件中加入以下代码: 在已创建工程的ets文件夹下创建AccessibilityExtAbility文件夹,在该文件夹下创建AccessibilityExtAbility.ts文件,在新增的文件中加入以下代码:
```typescript ```typescript
import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility'; import AccessibilityExtensionAbility, { AccessibilityEvent } from '@ohos.application.AccessibilityExtensionAbility';
class AccessibilityExtAbility extends AccessibilityExtensionAbility { class AccessibilityExtAbility extends AccessibilityExtensionAbility {
onConnect() { onConnect() {
...@@ -51,7 +51,7 @@ class AccessibilityExtAbility extends AccessibilityExtensionAbility { ...@@ -51,7 +51,7 @@ class AccessibilityExtAbility extends AccessibilityExtensionAbility {
console.info('AccessibilityExtAbility onDisconnect'); console.info('AccessibilityExtAbility onDisconnect');
} }
onAccessibilityEvent(accessibilityEvent) { onAccessibilityEvent(accessibilityEvent: AccessibilityEvent) {
console.info('AccessibilityExtAbility onAccessibilityEvent: ' + JSON.stringify(accessibilityEvent)); console.info('AccessibilityExtAbility onAccessibilityEvent: ' + JSON.stringify(accessibilityEvent));
} }
} }
...@@ -72,7 +72,7 @@ export default AccessibilityExtAbility; ...@@ -72,7 +72,7 @@ export default AccessibilityExtAbility;
相关无障碍事件可以在`onAccessibilityEvent()`方法中进行业务逻辑处理,具体事件可参考[AccessibilityEvent](../reference/apis/js-apis-application-accessibilityExtensionAbility.md#accessibilityevent)。此处以事件`pageStateUpdate`为例: 相关无障碍事件可以在`onAccessibilityEvent()`方法中进行业务逻辑处理,具体事件可参考[AccessibilityEvent](../reference/apis/js-apis-application-accessibilityExtensionAbility.md#accessibilityevent)。此处以事件`pageStateUpdate`为例:
```typescript ```typescript
onAccessibilityEvent(accessibilityEvent) { onAccessibilityEvent(accessibilityEvent: AccessibilityEvent) {
console.info('AccessibilityExtAbility onAccessibilityEvent: ' + JSON.stringify(accessibilityEvent)); console.info('AccessibilityExtAbility onAccessibilityEvent: ' + JSON.stringify(accessibilityEvent));
if (accessibilityEvent.eventType === 'pageStateUpdate') { if (accessibilityEvent.eventType === 'pageStateUpdate') {
console.info('AccessibilityExtAbility onAccessibilityEvent: pageStateUpdate'); console.info('AccessibilityExtAbility onAccessibilityEvent: pageStateUpdate');
......
...@@ -15,13 +15,14 @@ AccessibilityExtensionContext是AccessibilityExtensionAbility上下文环境, ...@@ -15,13 +15,14 @@ AccessibilityExtensionContext是AccessibilityExtensionAbility上下文环境,
在使用AccessibilityExtensionContext的功能前,需要通过AccessibilityExtensionAbility子类实例获取AccessibilityExtensionContex的实例。 在使用AccessibilityExtensionContext的功能前,需要通过AccessibilityExtensionAbility子类实例获取AccessibilityExtensionContex的实例。
```ts ```ts
import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility'; import AccessibilityExtensionAbility, {
let axContext; AccessibilityExtensionContext,
} from '@ohos.application.AccessibilityExtensionAbility';
let axContext: AccessibilityExtensionContext;
class EntryAbility extends AccessibilityExtensionAbility { class EntryAbility extends AccessibilityExtensionAbility {
onConnect(): void {
console.log('AxExtensionAbility onConnect');
axContext = this.context; axContext = this.context;
}
} }
``` ```
...@@ -99,6 +100,7 @@ setTargetBundleName(targetNames: Array\<string>): Promise\<void>; ...@@ -99,6 +100,7 @@ setTargetBundleName(targetNames: Array\<string>): Promise\<void>;
```ts ```ts
let targetNames = ['com.ohos.xyz']; let targetNames = ['com.ohos.xyz'];
try { try {
axContext.setTargetBundleName(targetNames).then(() => { axContext.setTargetBundleName(targetNames).then(() => {
console.info('set target bundle names success'); console.info('set target bundle names success');
...@@ -107,7 +109,7 @@ try { ...@@ -107,7 +109,7 @@ try {
}); });
} catch (exception) { } catch (exception) {
console.error(`failed to set target bundle names, because ${JSON.stringify(exception)}`); console.error(`failed to set target bundle names, because ${JSON.stringify(exception)}`);
}; }
``` ```
## AccessibilityExtensionContext.setTargetBundleName ## AccessibilityExtensionContext.setTargetBundleName
...@@ -128,9 +130,11 @@ setTargetBundleName(targetNames: Array\<string>, callback: AsyncCallback\<void>) ...@@ -128,9 +130,11 @@ setTargetBundleName(targetNames: Array\<string>, callback: AsyncCallback\<void>)
**示例:** **示例:**
```ts ```ts
import { BusinessError } from '@ohos.base';
let targetNames = ['com.ohos.xyz']; let targetNames = ['com.ohos.xyz'];
try { try {
axContext.setTargetBundleName(targetNames, (err, data) => { axContext.setTargetBundleName(targetNames, (err: BusinessError<void>) => {
if (err) { if (err) {
console.error(`failed to set target bundle names, because ${JSON.stringify(err)}`); console.error(`failed to set target bundle names, because ${JSON.stringify(err)}`);
return; return;
...@@ -139,7 +143,7 @@ try { ...@@ -139,7 +143,7 @@ try {
}); });
} catch (exception) { } catch (exception) {
console.error(`failed to set target bundle names, because ${JSON.stringify(exception)}`); console.error(`failed to set target bundle names, because ${JSON.stringify(exception)}`);
}; }
``` ```
## AccessibilityExtensionContext.getFocusElement ## AccessibilityExtensionContext.getFocusElement
...@@ -173,9 +177,11 @@ getFocusElement(isAccessibilityFocus?: boolean): Promise\<AccessibilityElement>; ...@@ -173,9 +177,11 @@ getFocusElement(isAccessibilityFocus?: boolean): Promise\<AccessibilityElement>;
**示例:** **示例:**
```ts ```ts
let focusElement; import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
let focusElement: AccessibilityElement;
try { try {
axContext.getFocusElement().then((data) => { axContext.getFocusElement().then((data: AccessibilityElement) => {
focusElement = data; focusElement = data;
console.log('get focus element success'); console.log('get focus element success');
}).catch((err: object) => { }).catch((err: object) => {
...@@ -211,9 +217,12 @@ getFocusElement(callback: AsyncCallback\<AccessibilityElement>): void; ...@@ -211,9 +217,12 @@ getFocusElement(callback: AsyncCallback\<AccessibilityElement>): void;
**示例:** **示例:**
```ts ```ts
let focusElement; import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
import { BusinessError } from '@ohos.base';
let focusElement: AccessibilityElement;
try { try {
axContext.getFocusElement((err, data) => { axContext.getFocusElement((err: BusinessError<void>, data: AccessibilityElement) => {
if (err) { if (err) {
console.error(`failed to get focus element, because ${JSON.stringify(err)}`); console.error(`failed to get focus element, because ${JSON.stringify(err)}`);
return; return;
...@@ -252,17 +261,21 @@ getFocusElement(isAccessibilityFocus: boolean, callback: AsyncCallback\<Accessib ...@@ -252,17 +261,21 @@ getFocusElement(isAccessibilityFocus: boolean, callback: AsyncCallback\<Accessib
**示例:** **示例:**
```ts ```ts
let focusElement; import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
import { BusinessError } from '@ohos.base';
let focusElement: AccessibilityElement;
let isAccessibilityFocus = true; let isAccessibilityFocus = true;
try { try {
axContext.getFocusElement(isAccessibilityFocus, (err, data) => { axContext.getFocusElement(isAccessibilityFocus, (err: BusinessError<void>, data: AccessibilityElement) => {
if (err) { if (err) {
console.error(`failed to get focus element, because ${JSON.stringify(err)}`); console.error(`failed to get focus element, because ${JSON.stringify(err)}`);
return; return;
} }
focusElement = data; focusElement = data;
console.info('get focus element success'); console.info('get focus element success');
}); });
} catch (exception) { } catch (exception) {
console.error(`failed to get focus element, because ${JSON.stringify(exception)}`); console.error(`failed to get focus element, because ${JSON.stringify(exception)}`);
} }
...@@ -298,9 +311,11 @@ getWindowRootElement(windowId?: number): Promise\<AccessibilityElement>; ...@@ -298,9 +311,11 @@ getWindowRootElement(windowId?: number): Promise\<AccessibilityElement>;
**示例:** **示例:**
```ts ```ts
let rootElement; import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
let rootElement: AccessibilityElement;
try { try {
axContext.getWindowRootElement().then((data) => { axContext.getWindowRootElement().then((data: AccessibilityElement) => {
rootElement = data; rootElement = data;
console.log('get root element of the window success'); console.log('get root element of the window success');
}).catch((err: object) => { }).catch((err: object) => {
...@@ -336,16 +351,20 @@ getWindowRootElement(callback: AsyncCallback\<AccessibilityElement>): void; ...@@ -336,16 +351,20 @@ getWindowRootElement(callback: AsyncCallback\<AccessibilityElement>): void;
**示例:** **示例:**
```ts ```ts
let rootElement; import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
import { BusinessError } from '@ohos.base';
let rootElement: AccessibilityElement;
try { try {
axContext.getWindowRootElement((err, data) => { axContext.getWindowRootElement((err: BusinessError<void>
, data: AccessibilityElement) => {
if (err) { if (err) {
console.error(`failed to get root element of the window, because ${JSON.stringify(err)}`); console.error(`failed to get root element of the window, because ${JSON.stringify(err)}`);
return; return;
} }
rootElement = data; rootElement = data;
console.info('get root element of the window success'); console.info('get root element of the window success');
}); });
} catch (exception) { } catch (exception) {
console.error(`failed to get root element of the window, because ${JSON.stringify(exception)}`); console.error(`failed to get root element of the window, because ${JSON.stringify(exception)}`);
} }
...@@ -377,17 +396,21 @@ getWindowRootElement(windowId: number, callback: AsyncCallback\<AccessibilityEle ...@@ -377,17 +396,21 @@ getWindowRootElement(windowId: number, callback: AsyncCallback\<AccessibilityEle
**示例:** **示例:**
```ts ```ts
let rootElement; import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
import { BusinessError } from '@ohos.base';
let rootElement: AccessibilityElement;
let windowId = 10; let windowId = 10;
try { try {
axContext.getWindowRootElement(windowId, (err, data) => { axContext.getWindowRootElement(windowId, (err: BusinessError<void>, data: AccessibilityElement) => {
if (err) { if (err) {
console.error(`failed to get root element of the window, because ${JSON.stringify(err)}`); console.error(`failed to get root element of the window, because ${JSON.stringify(err)}`);
return; return;
} }
rootElement = data; rootElement = data;
console.info('get root element of the window success'); console.info('get root element of the window success');
}); });
} catch (exception) { } catch (exception) {
console.error(`failed to get root element of the window, because ${JSON.stringify(exception)}`); console.error(`failed to get root element of the window, because ${JSON.stringify(exception)}`);
} }
...@@ -424,9 +447,11 @@ getWindows(displayId?: number): Promise\<Array\<AccessibilityElement>>; ...@@ -424,9 +447,11 @@ getWindows(displayId?: number): Promise\<Array\<AccessibilityElement>>;
**示例:** **示例:**
```ts ```ts
let windows; import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
let windows: AccessibilityElement[];
try { try {
axContext.getWindows().then((data) => { axContext.getWindows().then((data: AccessibilityElement[]) => {
windows = data; windows = data;
console.log('get windows success'); console.log('get windows success');
}).catch((err: object) => { }).catch((err: object) => {
...@@ -462,9 +487,12 @@ getWindows(callback: AsyncCallback\<Array\<AccessibilityElement>>): void; ...@@ -462,9 +487,12 @@ getWindows(callback: AsyncCallback\<Array\<AccessibilityElement>>): void;
**示例:** **示例:**
```ts ```ts
let windows; import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
import { BusinessError } from '@ohos.base';
let windows: AccessibilityElement[];
try { try {
axContext.getWindows((err, data) => { axContext.getWindows((err: BusinessError<void>, data: AccessibilityElement[]) => {
if (err) { if (err) {
console.error(`failed to get windows, because ${JSON.stringify(err)}`); console.error(`failed to get windows, because ${JSON.stringify(err)}`);
return; return;
...@@ -503,10 +531,13 @@ getWindows(displayId: number, callback: AsyncCallback\<Array\<AccessibilityEleme ...@@ -503,10 +531,13 @@ getWindows(displayId: number, callback: AsyncCallback\<Array\<AccessibilityEleme
**示例:** **示例:**
```ts ```ts
let windows; import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
import { BusinessError } from '@ohos.base';
let windows: AccessibilityElement[];
let displayId = 10; let displayId = 10;
try { try {
axContext.getWindows(displayId, (err, data) => { axContext.getWindows(displayId, (err: BusinessError<void>, data: AccessibilityElement[]) => {
if (err) { if (err) {
console.error(`failed to get windows, because ${JSON.stringify(err)}`); console.error(`failed to get windows, because ${JSON.stringify(err)}`);
return; return;
...@@ -552,7 +583,8 @@ injectGesture(gesturePath: GesturePath): Promise\<void>; ...@@ -552,7 +583,8 @@ injectGesture(gesturePath: GesturePath): Promise\<void>;
```ts ```ts
import GesturePath from '@ohos.accessibility.GesturePath'; import GesturePath from '@ohos.accessibility.GesturePath';
import GesturePoint from '@ohos.accessibility.GesturePoint'; import GesturePoint from '@ohos.accessibility.GesturePoint';
let gesturePath = new GesturePath.GesturePath(100);
let gesturePath: GesturePath.GesturePath = new GesturePath.GesturePath(100);
try { try {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
let gesturePoint = new GesturePoint.GesturePoint(100, i * 200); let gesturePoint = new GesturePoint.GesturePoint(100, i * 200);
...@@ -595,13 +627,14 @@ injectGesture(gesturePath: GesturePath, callback: AsyncCallback\<void>): void ...@@ -595,13 +627,14 @@ injectGesture(gesturePath: GesturePath, callback: AsyncCallback\<void>): void
```ts ```ts
import GesturePath from '@ohos.accessibility.GesturePath'; import GesturePath from '@ohos.accessibility.GesturePath';
import GesturePoint from '@ohos.accessibility.GesturePoint'; import GesturePoint from '@ohos.accessibility.GesturePoint';
let gesturePath = new GesturePath.GesturePath(100);
let gesturePath: GesturePath.GesturePath = new GesturePath.GesturePath(100);
try { try {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
let gesturePoint = new GesturePoint.GesturePoint(100, i * 200); let gesturePoint = new GesturePoint.GesturePoint(100, i * 200);
gesturePath.points.push(gesturePoint); gesturePath.points.push(gesturePoint);
} }
axContext.injectGesture(gesturePath, (err, data) => { axContext.injectGesture(gesturePath, (err) => {
if (err) { if (err) {
console.error(`failed to inject gesture, because ${JSON.stringify(err)}`); console.error(`failed to inject gesture, because ${JSON.stringify(err)}`);
return; return;
...@@ -635,8 +668,10 @@ attributeNames\<T extends keyof ElementAttributeValues>(): Promise\<Array\<T>>; ...@@ -635,8 +668,10 @@ attributeNames\<T extends keyof ElementAttributeValues>(): Promise\<Array\<T>>;
**示例:** **示例:**
```ts ```ts
let attributeNames; import { ElementAttributeKeys } from '@ohos.application.AccessibilityExtensionAbility';
rootElement.attributeNames().then((data) => {
let attributeNames: ElementAttributeKeys;
rootElement.attributeNames().then((data: ElementAttributeKeys) => {
console.log('get attribute names success'); console.log('get attribute names success');
attributeNames = data; attributeNames = data;
}).catch((err: object) => { }).catch((err: object) => {
...@@ -660,8 +695,11 @@ attributeNames\<T extends keyof ElementAttributeValues>(callback: AsyncCallback\ ...@@ -660,8 +695,11 @@ attributeNames\<T extends keyof ElementAttributeValues>(callback: AsyncCallback\
**示例:** **示例:**
```ts ```ts
let attributeNames; import { ElementAttributeKeys } from '@ohos.application.AccessibilityExtensionAbility';
rootElement.attributeNames((err, data) => { import { BusinessError } from '@ohos.base';
let attributeNames: ElementAttributeKeys[];
rootElement.attributeNames((err: BusinessError<void>, data: ElementAttributeKeys[]) => {
if (err) { if (err) {
console.error(`failed to get attribute names, because ${JSON.stringify(err)}`); console.error(`failed to get attribute names, because ${JSON.stringify(err)}`);
return; return;
...@@ -682,7 +720,7 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promi ...@@ -682,7 +720,7 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promi
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------------- | ---- | ---- | -------- | | ------------- | ---- | ---- | -------- |
| attributeName | T | 是 | 表示属性的名称。 | | attributeName | ElementAttributeKeys | 是 | 表示属性的名称。 |
**返回值:** **返回值:**
...@@ -701,10 +739,12 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promi ...@@ -701,10 +739,12 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promi
**示例:** **示例:**
```ts ```ts
let attributeName = 'name'; import { ElementAttributeKeys } from '@ohos.application.AccessibilityExtensionAbility';
let attributeValue;
let attributeName: ElementAttributeKeys = 'bundleName';
let attributeValue: string;
try { try {
rootElement.attributeValue(attributeName).then((data) => { rootElement.attributeValue(attributeName).then((data: string) => {
console.log('get attribute value by name success'); console.log('get attribute value by name success');
attributeValue = data; attributeValue = data;
}).catch((err: object) => { }).catch((err: object) => {
...@@ -727,7 +767,7 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T, ...@@ -727,7 +767,7 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T,
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------------- | ---------------------------------------- | ---- | ---------------------- | | ------------- | ---------------------------------------- | ---- | ---------------------- |
| attributeName | T | 是 | 表示属性的名称。 | | attributeName | ElementAttributeKeys | 是 | 表示属性的名称。 |
| callback | AsyncCallback&lt;ElementAttributeValues[T]&gt; | 是 | 回调函数,返回根据节点属性名称获取的属性值。 | | callback | AsyncCallback&lt;ElementAttributeValues[T]&gt; | 是 | 回调函数,返回根据节点属性名称获取的属性值。 |
**错误码:** **错误码:**
...@@ -741,10 +781,13 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T, ...@@ -741,10 +781,13 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T,
**示例:** **示例:**
```ts ```ts
let attributeValue; import { ElementAttributeKeys } from '@ohos.application.AccessibilityExtensionAbility';
let attributeName = 'name'; import { BusinessError } from '@ohos.base';
let attributeName: ElementAttributeKeys = 'bundleName';
let attributeValue: string;
try { try {
rootElement.attributeValue(attributeName, (err, data) => { rootElement.attributeValue(attributeName, (err: BusinessError<void>, data: string) => {
if (err) { if (err) {
console.error(`failed to get attribute value, because ${JSON.stringify(err)}`); console.error(`failed to get attribute value, because ${JSON.stringify(err)}`);
return; return;
...@@ -773,13 +816,13 @@ actionNames(): Promise\<Array\<string>>; ...@@ -773,13 +816,13 @@ actionNames(): Promise\<Array\<string>>;
**示例:** **示例:**
```ts ```ts
let actionNames; let actionNames: string[];
rootElement.actionNames().then((data) => { rootElement.actionNames().then((data: string[]) => {
console.log('get action names success'); console.log('get action names success');
actionNames = data; actionNames = data;
}).catch((err: object) => { }).catch((err: object) => {
console.error(`failed to get action names because ${JSON.stringify(err)}`); console.error(`failed to get action names because ${JSON.stringify(err)}`);
}); })
``` ```
### actionNames ### actionNames
...@@ -798,15 +841,15 @@ actionNames(callback: AsyncCallback\<Array\<string>>): void; ...@@ -798,15 +841,15 @@ actionNames(callback: AsyncCallback\<Array\<string>>): void;
**示例:** **示例:**
```ts ```ts
let actionNames; let actionNames: string[];
rootElement.actionNames((err, data) => { rootElement.actionNames((err: BusinessError<void>, data: string[]) => {
if (err) { if (err) {
console.error(`failed to get action names, because ${JSON.stringify(err)}`); console.error(`failed to get action names, because ${JSON.stringify(err)}`);
return; return;
} }
actionNames = data; actionNames = data;
console.info('get action names success'); console.info('get action names success');
}); })
``` ```
### performAction ### performAction
...@@ -840,8 +883,9 @@ performAction(actionName: string, parameters?: object): Promise\<void>; ...@@ -840,8 +883,9 @@ performAction(actionName: string, parameters?: object): Promise\<void>;
**示例:** **示例:**
```ts ```ts
let actionName = 'action';
try { try {
rootElement.performAction('action').then((data) => { rootElement.performAction(actionName).then(() => {
console.info('perform action success'); console.info('perform action success');
}).catch((err: object) => { }).catch((err: object) => {
console.error(`failed to perform action, because ${JSON.stringify(err)}`); console.error(`failed to perform action, because ${JSON.stringify(err)}`);
...@@ -876,8 +920,11 @@ performAction(actionName: string, callback: AsyncCallback\<void>): void; ...@@ -876,8 +920,11 @@ performAction(actionName: string, callback: AsyncCallback\<void>): void;
**示例:** **示例:**
```ts ```ts
import { BusinessError } from '@ohos.base';
let actionName = 'action';
try { try {
rootElement.performAction('action', (err, data) => { rootElement.performAction(actionName, (err:BusinessError) => {
if (err) { if (err) {
console.error(`failed to perform action, because ${JSON.stringify(err)}`); console.error(`failed to perform action, because ${JSON.stringify(err)}`);
return; return;
...@@ -915,12 +962,14 @@ performAction(actionName: string, parameters: object, callback: AsyncCallback\<v ...@@ -915,12 +962,14 @@ performAction(actionName: string, parameters: object, callback: AsyncCallback\<v
**示例:** **示例:**
```ts ```ts
import { BusinessError } from '@ohos.base';
let actionName = 'action'; let actionName = 'action';
let parameters = { let parameters = {
'setText': 'test text' 'setText': 'test text'
}; };
try { try {
rootElement.performAction(actionName, parameters, (err, data) => { rootElement.performAction(actionName, parameters, (err: BusinessError<void>) => {
if (err) { if (err) {
console.error(`failed to perform action, because ${JSON.stringify(err)}`); console.error(`failed to perform action, because ${JSON.stringify(err)}`);
return; return;
...@@ -955,11 +1004,10 @@ findElement(type: 'content', condition: string): Promise\<Array\<AccessibilityEl ...@@ -955,11 +1004,10 @@ findElement(type: 'content', condition: string): Promise\<Array\<AccessibilityEl
**示例:** **示例:**
```ts ```ts
let type = 'content';
let condition = 'keyword'; let condition = 'keyword';
let elements; let elements: AccessibilityElement[];
try { try {
rootElement.findElement(type, condition).then((data) => { rootElement.findElement('content', condition).then((data: AccessibilityElement[]) => {
elements = data; elements = data;
console.log('find element success'); console.log('find element success');
}).catch((err: object) => { }).catch((err: object) => {
...@@ -988,11 +1036,12 @@ findElement(type: 'content', condition: string, callback: AsyncCallback\<Array\< ...@@ -988,11 +1036,12 @@ findElement(type: 'content', condition: string, callback: AsyncCallback\<Array\<
**示例:** **示例:**
```ts ```ts
let type = 'content'; import { BusinessError } from '@ohos.base';
let condition = 'keyword'; let condition = 'keyword';
let elements; let elements: AccessibilityElement[];
try { try {
rootElement.findElement(type, condition, (err, data) => { rootElement.findElement('content', condition, (err: BusinessError<void>, data: AccessibilityElement[]) => {
if (err) { if (err) {
console.error(`failed to find element, because ${JSON.stringify(err)}`); console.error(`failed to find element, because ${JSON.stringify(err)}`);
return; return;
...@@ -1028,11 +1077,12 @@ findElement(type: 'focusType', condition: FocusType): Promise\<AccessibilityElem ...@@ -1028,11 +1077,12 @@ findElement(type: 'focusType', condition: FocusType): Promise\<AccessibilityElem
**示例:** **示例:**
```ts ```ts
let type = 'focusType'; import { FocusType } from '@ohos.application.AccessibilityExtensionAbility';
let condition = 'normal';
let element; let condition: FocusType = 'normal';
let element: AccessibilityElement;
try { try {
rootElement.findElement(type, condition).then((data) => { rootElement.findElement('focusType', condition).then((data: AccessibilityElement) => {
element = data; element = data;
console.log('find element success'); console.log('find element success');
}).catch((err: object) => { }).catch((err: object) => {
...@@ -1061,11 +1111,13 @@ findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback\<Ac ...@@ -1061,11 +1111,13 @@ findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback\<Ac
**示例:** **示例:**
```ts ```ts
let type = 'focusType'; import { FocusType } from '@ohos.application.AccessibilityExtensionAbility';
let condition = 'normal'; import { BusinessError } from '@ohos.base';
let element;
let condition: FocusType = 'normal';
let element: AccessibilityElement;
try { try {
rootElement.findElement(type, condition, (err, data) => { rootElement.findElement('focusType', condition, (err: BusinessError<void>, data: AccessibilityElement) => {
if (err) { if (err) {
console.error(`failed to find element, because ${JSON.stringify(err)}`); console.error(`failed to find element, because ${JSON.stringify(err)}`);
return; return;
...@@ -1101,11 +1153,12 @@ findElement(type: 'focusDirection', condition: FocusDirection): Promise\<Accessi ...@@ -1101,11 +1153,12 @@ findElement(type: 'focusDirection', condition: FocusDirection): Promise\<Accessi
**示例:** **示例:**
```ts ```ts
let type = 'focusDirection'; import { FocusDirection } from '@ohos.application.AccessibilityExtensionAbility';
let condition = 'up';
let element; let condition: FocusDirection = 'up';
let element: AccessibilityElement;
try { try {
rootElement.findElement(type, condition).then((data) => { rootElement.findElement('focusDirection', condition).then((data: AccessibilityElement) => {
element = data; element = data;
console.log('find element success'); console.log('find element success');
}).catch((err: object) => { }).catch((err: object) => {
...@@ -1134,11 +1187,13 @@ findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCa ...@@ -1134,11 +1187,13 @@ findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCa
**示例:** **示例:**
```ts ```ts
let type = 'focusDirection'; import { FocusDirection } from '@ohos.application.AccessibilityExtensionAbility';
let condition = 'up'; import { BusinessError } from '@ohos.base';
let elements;
let condition: FocusDirection = 'up';
let elements: AccessibilityElement;
try { try {
rootElement.findElement(type, condition, (err, data) => { rootElement.findElement('focusDirection', condition, (err: BusinessError<void>, data: AccessibilityElement) => {
if (err) { if (err) {
console.error(`failed to find element, because ${JSON.stringify(err)}`); console.error(`failed to find element, because ${JSON.stringify(err)}`);
return; return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册