js-apis-application-accessibilityExtensionAbility.md 6.7 KB
Newer Older
E
ester.zhou 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Accessibility Extension Ability

The **AccessibilityExtensionAbility** module is based on the ExtensionAbility framework and provides the **AccessibilityExtensionAbility**.

>**NOTE**
>
>The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
>The APIs of this module can be used only in the stage model.

## Modules to Import

```ts
import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility'
```

17 18 19 20 21 22 23 24
## Attributes

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

| Name  | Type | Readable | Writable | Description           |
| --------- | -------- | ---- | ---- | ------------------------- |
| context | [AccessibilityExtensionContext](js-apis-accessibility-extension-context.md) | Yes | No | Context of the accessibility extension ability. |

E
ester.zhou 已提交
25 26 27 28 29 30 31 32 33 34
## AccessibilityEvent

Defines an accessibility event.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

### Attributes

| Name       | Type                                    | Readable  | Writable  | Description        |
| --------- | ---------------------------------------- | ---- | ---- | ---------- |
35
| eventType | [EventType](js-apis-accessibility.md#eventtype) \| [WindowUpdateType](js-apis-accessibility.md#windowupdatetype) \| [TouchGuideType](#touchguidetype) \| [GestureType](#gesturetype) \| [PageUpdateType](#pageupdatetype) | Yes   | No   | Event type.   |
E
ester.zhou 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
| target    | AccessibilityElement                     | Yes   | No   | Target component where the event occurs.|
| timeStamp | number                                   | Yes   | No   | Timestamp of the event.    |

## GesturePath

Defines a gesture path.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

### Attributes

| Name          | Type                                    | Readable  | Writable  | Description    |
| ------------ | ---------------------------------------- | ---- | ---- | ------ |
| points       | Array<[GesturePoint](gesturepoint)> | Yes   | Yes   | An array of gesture touch points. |
| durationTime | number                                   | Yes   | Yes   | Total time consumed by the gesture.|

## GesturePoint

Defines a gesture touch point.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

### Attributes

| Name       | Type  | Readable  | Writable  | Description     |
| --------- | ------ | ---- | ---- | ------- |
| positionX | number | Yes   | Yes   | X-coordinate of the touch point.|
| positionY | number | Yes   | Yes   | Y-coordinate of the touch point.|

## GestureType

Enumerates gesture types.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

| Name           | Description          |
| ------------- | ------------ |
| left          | Left gesture.    |
| leftThenRight | Left-then-right gesture.|
| leftThenUp    | Left-then-up gesture.|
| leftThenDown  | Left-then-down gesture.|
| right         | Right gesture.    |
| rightThenLeft | Right-then-left gesture.|
| rightThenUp   | Right-then-up gesture.|
| rightThenDown | Right-then-down gesture.|
| up            | Up gesture.    |
| upThenLeft    | Up-then-left gesture.|
| upThenRight   | Up-then-right gesture.|
| upThenDown    | Up-then-down gesture.|
| down          | Down gesture.    |
| downThenLeft  | Down-then-left gesture.|
| downThenRight | Down-then-right gesture.|
| downThenUp    | Down-then-up gesture.|

## PageUpdateType

Enumerates the page refresh types.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

| Name               | Description       |
| ----------------- | --------- |
| pageContentUpdate | Update of the page content.|
| pageStateUpdate   | Update of the page status.|

## TouchGuideType

Enumerates the touch guide event types.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

| Name        | Description          |
| ---------- | ------------ |
| touchBegin | A touch starts in touch guide mode.|
| touchEnd   | A touch ends in touch guide mode.|

## AccessibilityExtensionAbility.onConnect

onConnect(): void;

Called when the **AccessibilityExtensionAbility** is enabled and connected to the system service. In this API, you can initialize service logic. This API can be overridden as required.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

None

**Example**

```ts
onConnect(): void {
    console.log("AxExtensionAbility onConnect");
}
```

## AccessibilityExtensionAbility.onDisconnect

onDisconnect(): void;

Called when the **AccessibilityExtensionAbility** is disabled and disconnected from the system service. In this API, you can implement the service logic of resource release and exit. This API can be overridden as required.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

None

**Example**

```ts
onDisconnect(): void {
    console.log("AxExtensionAbility onDisconnect");
}
```

## AccessibilityExtensionAbility.onAccessibilityEvent

onAccessibilityEvent(event: AccessibilityEvent): void;

Called when an event that matches the specified bundle and event type occurs. In this API, you can implement event-specific service logic. Generally, this API needs to be overridden.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name  | Type                                    | Mandatory  | Description             |
| ----- | ---------------------------------------- | ---- | --------------- |
164
| event | [AccessibilityEvent](#accessibilityevent) | Yes   | Accessibility event. No value is returned.|
E
ester.zhou 已提交
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188

**Example**

```ts
onAccessibilityEvent(event: AccessibilityEvent): void {
    console.log("AxExtensionAbility onAccessibilityEvent");
    if (event.eventType == 'click') {
        console.log("AxExtensionAbility onAccessibilityEvent: click");
    }
}
```

## AccessibilityExtensionAbility.onKeyEvent

onKeyEvent(keyEvent: inputEventClient.KeyEvent): boolean;

Called when a physical key is pressed. In this API, you can determine whether to intercept the key event based on the service.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name     | Type                                    | Mandatory  | Description                     |
| -------- | ---------------------------------------- | ---- | ----------------------- |
189
| keyEvent | [KeyEvent](js-apis-keyevent.md#KeyEvent) | Yes   | Key event. If **true** is returned, the key is intercepted.|
E
ester.zhou 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202

**Example**

```ts
onKeyEvent(keyEvent: inputEventClient.KeyEvent): boolean {
    console.log("AxExtensionAbility onKeyEvent");
    if (keyEvent.keyCode == 22) {
        console.log("AxExtensionAbility onKeyEvent: intercept 22");
        return true;
    }
    return false;
}
```