js-apis-accessibility-config.md 11.2 KB
Newer Older
E
ester.zhou 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
# System Accessibility Configuration

The **config** module allows you to configure system accessibility features, including accessibility extension, high-contrast text, mouse buttons, and captions.

> **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 provided by this module are system APIs.

## Modules to Import

```typescript
import config from "@ohos.accessibility.config";
```

## Attributes

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

| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| highContrastText | [Config](#config)\<boolean>| Yes| Yes| Whether to enable high-contrast text.|
| invertColor | [Config](#config)\<boolean>| Yes| Yes| Whether to enable color inversion.|
| daltonizationColorFilter | [Config](#config)&lt;[DaltonizationColorFilter](#daltonizationcolorfilter)&gt;| Yes| Yes| Configuration of the daltonization filter.|
| contentTimeout | [Config](#config)\<number>| Yes| Yes| Recommended duration for content display. The value ranges from 0 to 5000, in milliseconds.|
| animationOff | [Config](#config)\<boolean>| Yes| Yes| Whether to enable animation.|
| brightnessDiscount | [Config](#config)\<number>| Yes| Yes| Brightness discount. The value ranges from 0 to 1.0.|
| mouseKey | [Config](#config)\<boolean>| Yes| Yes| Whether to enable the mouse button feature.|
| mouseAutoClick | [Config](#config)\<number>| Yes| Yes| Interval for the automatic mouse clicks. The value ranges from 0 to 5000, in milliseconds.|
| shortkey | [Config](#config)\<boolean>| Yes| Yes| Whether to enable the accessibility extension shortcut key.|
| shortkeyTarget | [Config](#config)\<string>| Yes| Yes| Target application for the accessibility extension shortcut key. The value format is bundleName/abilityName.|
| captions | [Config](#config)\<boolean>| Yes| Yes| Whether to enable captions.|
| captionsStyle | [Config](#config)\<[accessibility.CaptionsStyle](./js-apis-accessibility.md#captionsstyle8)>| Yes| Yes| Captions style.|

## enableAbility

enableAbility(name: string, capability: Array&lt;[accessibility.Capability](./js-apis-accessibility.md#capability)&gt;): Promise&lt;void&gt;;

Enables an accessibility extension ability. This API uses a promise to return the result.

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the accessibility extension ability. The format is bundleName/abilityName.|
| capability | Array&lt;[accessibility.Capability](./js-apis-accessibility.md#capability)&gt;) | Yes| Capability of the accessibility extension ability.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the execution result.|

**Example**

  ```typescript
  config.enableAbility("com.ohos.example/axExtension", ['retrieve'])
      .then(() => {
        console.info('enable succeed');
      }).catch((error) => {
        console.error('enable failed');
      });
  ```

## enableAbility

enableAbility(name: string, capability: Array&lt;[accessibility.Capability](./js-apis-accessibility.md#capability)&gt;, callback: AsyncCallback&lt;void&gt;): void;

Enables an accessibility extension ability. This API uses an asynchronous callback to return the result.

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the accessibility extension ability. The format is bundleName/abilityName.|
| capability | Array&lt;[accessibility.Capability](./js-apis-accessibility.md#capability)&gt; | Yes| Capability of the accessibility extension ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the execution result.|

**Example**

  ```typescript
  config.enableAbility("com.ohos.example/axExtension", ['retrieve'], (err, data) => {
      if (err) {
          console.error('enable failed');
          return;
      }
      console.info('enable succeed');
    })
  ```

## disableAbility

disableAbility(name: string): Promise&lt;void&gt;;

Disables an accessibility extension ability. This API uses a promise to return the result.

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the accessibility extension ability. The format is bundleName/abilityName.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the execution result.|

**Example**

  ```typescript
  config.disableAbility("com.ohos.example/axExtension")
      .then(() => {
        console.info('disable succeed');
      }).catch((error) => {
        console.error('disable failed');
      });
  ```

## disableAbility

disableAbility(name: string, callback: AsyncCallback&lt;void&gt;): void;

Disables an accessibility extension ability. This API uses an asynchronous callback to return the result.

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the accessibility extension ability. The format is bundleName/abilityName.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the execution result.|

**Example**

  ```typescript
  config.disableAbility("com.ohos.example/axExtension", (err, data) => {
      if (err) {
          console.error('disable failed');
          return;
      }
      console.info('disable succeed');
    })
  ```

## on('enableAbilityListsStateChanged')

on(type: 'enableAbilityListsStateChanged', callback: Callback&lt;void&gt;): void;

Adds a listener for changes in the list of enabled accessibility extension abilities.

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Listening type. The value is fixed at **'enableAbilityListsStateChanged'**, indicating that the changes in the list of enabled accessibility extension abilities.|
| callback | Callback&lt;void&gt; | Yes| Callback invoked when the list of enabled accessibility extension abilities changes.|

**Example**

  ```typescript
  config.on('enableAbilityListsStateChanged',() => {
      console.info('ax extension ability enable list changed');
  });
  ```

## off('enableAbilityListsStateChanged')

off(type: 'enableAbilityListsStateChanged', callback?: Callback&lt;void&gt;): void;

Cancels the listener for changes in the list of enabled accessibility extension abilities.

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type |  string | No| Listening type. The value is fixed at **'enableAbilityListsStateChanged'**, indicating that the changes in the list of enabled accessibility extension abilities.|
| callback | Callback&lt;void&gt; | No| Callback invoked when the list of enabled accessibility extension abilities changes.|

**Example**

  ```typescript
  config.off('enableAbilityListsStateChanged');
  ```

## Config

Implements configuration, acquisition, and listening for attributes.

### set

set(value: T): Promise&lt;void&gt;;

Sets this attribute. This API uses a promise to return the result.

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | T | Yes| Attribute value to set.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the execution result.|

**Example**

  ```typescript
  config.highContrastText.set(true)
      .then(() => {
        console.info('highContrastText set succeed');
      }).catch((error) => {
        console.error('highContrastText set failed');
      });
  ```

### set

set(value: T, callback: AsyncCallback&lt;void&gt;): void;

Sets this attribute. This API uses an asynchronous callback to return the result.

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | T | Yes| Attribute value to set.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the execution result.|

**Example**

  ```typescript
  config.highContrastText.set(true, (err, data) => {
      if (err) {
          console.error('highContrastText set failed');
          return;
      }
      console.info('highContrastText set succeed');
    })
  ```

### get

get(): Promise&lt;T&gt;;

Obtains the value of this attribute. This API uses a promise to return the result.

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

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;T&gt; | Promise used to return the attribute value.|

**Example**

  ```typescript
  config.highContrastText.get()
      .then((value) => {
        console.info('highContrastText get succeed');
      }).catch((error) => {
        console.error('highContrastText get failed');
      });
  ```

### get

get(callback: AsyncCallback&lt;T&gt;): void;

Obtains the value of this attribute. This API uses an asynchronous callback to return the result.

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the attribute value.|

**Example**

  ```typescript
  config.highContrastText.get((err, data) => {
      if (err) {
          console.error('highContrastText get failed');
          return;
      }
      console.info('highContrastText get succeed');
    })
  ```

### on

on(callback: Callback&lt;T&gt;): void;

Adds a listener for attribute changes.

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | Callback&lt;T&gt; | Yes| Callback invoked when the attribute changes.|

**Example**

  ```typescript
  config.highContrastText.on(() => {
      console.info('highContrastText changed');
  });
  ```

### off

off(callback?: Callback&lt;T&gt;): void;

Cancels the listener for attribute changes.

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | Callback&lt;T&gt; | No| Callback invoked when the attribute changes.|

**Example**

  ```typescript
  config.highContrastText.off();
  ```

## DaltonizationColorFilter

Enumerates the daltonization filters.

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

| Name| Description|
| -------- | -------- |
| Normal | Filter for normal users.|
| Protanomaly | Filter for protanomaly.|
| Deuteranomaly | Filter for deuteranomaly.|
| Tritanomaly  | Filter for tritanomaly.|