1/* 2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { AsyncCallback } from './basic'; 17import { Callback } from './basic'; 18 19/** 20 * Accessibility 21 * @name Accessibility 22 * @since 7 23 * @syscap SystemCapability.BarrierFree.Accessibility.Core 24 */ 25declare namespace accessibility { 26 /** 27 * The type of the Ability app. 28 * @type { 'audible' | 'generic' | 'haptic' | 'spoken' | 'visual' } 29 * @syscap SystemCapability.BarrierFree.Accessibility.Core 30 * @since 7 31 */ 32 /** 33 * The type of the Ability app. 34 * @type { 'audible' | 'generic' | 'haptic' | 'spoken' | 'visual' | 'all' } 35 * @syscap SystemCapability.BarrierFree.Accessibility.Core 36 * @since 9 37 */ 38 type AbilityType = 'audible' | 'generic' | 'haptic' | 'spoken' | 'visual' | 'all'; 39 40 /** 41 * The action that the ability can execute. 42 * @syscap SystemCapability.BarrierFree.Accessibility.Core 43 * @since 7 44 */ 45 type Action = 'accessibilityFocus' | 'clearAccessibilityFocus' | 'focus' | 'clearFocus' | 'clearSelection' | 46 'click' | 'longClick' | 'cut' | 'copy' | 'paste' | 'select' | 'setText' | 'delete' | 47 'scrollForward' | 'scrollBackward' | 'setSelection'; 48 49 /** 50 * The type of the accessibility event. 51 * @syscap SystemCapability.BarrierFree.Accessibility.Core 52 * @since 7 53 */ 54 type EventType = 'accessibilityFocus' | 'accessibilityFocusClear' | 55 'click' | 'longClick' | 'focus' | 'select' | 'hoverEnter' | 'hoverExit' | 56 'textUpdate' | 'textSelectionUpdate' | 'scroll'; 57 58 /** 59 * The change type of the windowsChange event. 60 * @syscap SystemCapability.BarrierFree.Accessibility.Core 61 * @since 7 62 */ 63 type WindowUpdateType = 'add' | 'remove' | 'bounds' | 'active' | 'focus'; 64 65 /** 66 * The type of the ability state. 67 * @syscap SystemCapability.BarrierFree.Accessibility.Core 68 * @since 7 69 */ 70 type AbilityState = 'enable' | 'disable' | 'install'; 71 72 /** 73 * The ability that accessibility subsystem support. 74 * @syscap SystemCapability.BarrierFree.Accessibility.Core 75 * @since 7 76 */ 77 type Capability = 'retrieve' | 'touchGuide' | 'keyEventObserver' | 'zoom' | 'gesture'; 78 79 /** 80 * The granularity of text move. 81 * @syscap SystemCapability.BarrierFree.Accessibility.Core 82 * @since 7 83 */ 84 type TextMoveUnit = 'char' | 'word' | 'line' | 'page' | 'paragraph'; 85 86 /** 87 * Checks whether accessibility ability is enabled. 88 * @since 7 89 * @param callback Asynchronous callback interface. 90 * @syscap SystemCapability.BarrierFree.Accessibility.Core 91 * @returns Returns {@code true} if the accessibility is enabled; returns {@code false} otherwise. 92 */ 93 function isOpenAccessibility(callback: AsyncCallback<boolean>): void; 94 function isOpenAccessibility(): Promise<boolean>; 95 96 /** 97 * Checks touch browser ability (which is used by talkback) is enabled. 98 * @since 7 99 * @param callback Asynchronous callback interface. 100 * @syscap SystemCapability.BarrierFree.Accessibility.Vision 101 * @returns Returns {@code true} if the touch browser is enabled; returns {@code false} otherwise. 102 */ 103 function isOpenTouchGuide(callback: AsyncCallback<boolean>): void; 104 function isOpenTouchGuide(): Promise<boolean>; 105 106 /** 107 * Queries the list of accessibility abilities. 108 * @since 7 109 * @param abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken 110 * @param stateType The state of the accessibility ability. {@code AbilityState} eg.installed 111 * @syscap SystemCapability.BarrierFree.Accessibility.Core 112 * @returns Returns the list of abilityInfos. 113 * @deprecated since 9 114 * @useinstead ohos.accessibility#getAccessibilityExtensionList 115 */ 116 function getAbilityLists(abilityType: AbilityType, stateType: AbilityState, 117 callback: AsyncCallback<Array<AccessibilityAbilityInfo>>): void; 118 function getAbilityLists(abilityType: AbilityType, 119 stateType: AbilityState): Promise<Array<AccessibilityAbilityInfo>>; 120 121 122 /** 123 * Queries the list of accessibility abilities. 124 * @since 9 125 * @param abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken 126 * @param stateType The state of the accessibility ability. {@code AbilityState} eg.installed 127 * @syscap SystemCapability.BarrierFree.Accessibility.Core 128 * @returns Returns the list of abilityInfos. 129 * @throws { BusinessError } 401 - Input parameter error. 130 */ 131 function getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState): Promise<Array<AccessibilityAbilityInfo>>; 132 function getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState, callback: AsyncCallback<Array<AccessibilityAbilityInfo>>): void; 133 134 /** 135 * Send accessibility Event. 136 * @since 7 137 * @param event The object of the accessibility {@code EventInfo} . 138 * @param callback Asynchronous callback interface. 139 * @syscap SystemCapability.BarrierFree.Accessibility.Core 140 * @returns Returns {@code true} if success ; returns {@code false} otherwise. 141 * @deprecated since 9 142 * @useinstead ohos.accessibility#sendAccessibilityEvent 143 */ 144 function sendEvent(event: EventInfo, callback: AsyncCallback<void>): void; 145 function sendEvent(event: EventInfo): Promise<void>; 146 147 /** 148 * Send accessibility event. 149 * @since 9 150 * @param event The object of the accessibility {@code EventInfo} . 151 * @param callback Asynchronous callback interface. 152 * @syscap SystemCapability.BarrierFree.Accessibility.Core 153 * @returns Returns {@code true} if success ; returns {@code false} otherwise. 154 * @throws { BusinessError } 401 - Input parameter error. 155 */ 156 function sendAccessibilityEvent(event: EventInfo, callback: AsyncCallback<void>): void; 157 function sendAccessibilityEvent(event: EventInfo): Promise<void>; 158 159 /** 160 * Register the observer of the accessibility state changed. 161 * @since 7 162 * @param type state event type. 163 * @param callback Asynchronous callback interface. 164 * @syscap SystemCapability.BarrierFree.Accessibility.Core 165 * @returns Returns {@code true} if the register is success ; returns {@code false} otherwise. 166 * @throws { BusinessError } 401 - Input parameter error. 167 */ 168 function on(type: 'accessibilityStateChange', callback: Callback<boolean>): void; 169 170 /** 171 * Register the observer of the touchGuide state changed. 172 * @since 7 173 * @param type state event type. 174 * @param callback Asynchronous callback interface. 175 * @syscap SystemCapability.BarrierFree.Accessibility.Vision 176 * @returns Returns {@code true} if the register is success ; returns {@code false} otherwise. 177 * @throws { BusinessError } 401 - Input parameter error. 178 */ 179 function on(type: 'touchGuideStateChange', callback: Callback<boolean>): void; 180 181 /** 182 * Unregister the observer of the accessibility state changed. 183 * @since 7 184 * @param type state event type 185 * @param callback Asynchronous callback interface. 186 * @syscap SystemCapability.BarrierFree.Accessibility.Core 187 * @returns Returns {@code true} if the Unregister is success ; returns {@code false} otherwise. 188 * @throws { BusinessError } 401 - Input parameter error. 189 */ 190 function off(type: 'accessibilityStateChange', callback?: Callback<boolean>): void; 191 192 /** 193 * Unregister the observer of the touchGuide state changed. 194 * @since 7 195 * @param type state event type 196 * @param callback Asynchronous callback interface. 197 * @returns Returns {@code true} if the Unregister is success ; returns {@code false} otherwise. 198 * @throws { BusinessError } 401 - Input parameter error. 199 */ 200 function off(type: 'touchGuideStateChange', callback?: Callback<boolean>): void; 201 202 /** 203 * Get the captions manager. 204 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 205 * @since 8 206 * @returns Returns the captions manager. 207 */ 208 function getCaptionsManager(): CaptionsManager; 209 210 /** 211 * Indicates the captions manager. 212 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 213 * @since 8 214 */ 215 interface CaptionsManager { 216 /** 217 * Indicates whether captions are enabled. 218 */ 219 enabled: boolean; 220 /** 221 * Indicates the style of captions. 222 */ 223 style: CaptionsStyle; 224 225 /** 226 * Register the observer of the enable state. 227 * @throws { BusinessError } 401 - Input parameter error. 228 */ 229 on(type: 'enableChange', callback: Callback<boolean>): void; 230 231 /** 232 * Register the observer of the style. 233 * @throws { BusinessError } 401 - Input parameter error. 234 */ 235 on(type: 'styleChange', callback: Callback<CaptionsStyle>): void; 236 237 /** 238 * Unregister the observer of the enable state. 239 * @throws { BusinessError } 401 - Input parameter error. 240 */ 241 off(type: 'enableChange', callback?: Callback<boolean>): void; 242 243 /** 244 * Unregister the observer of the style. 245 * @throws { BusinessError } 401 - Input parameter error. 246 */ 247 off(type: 'styleChange', callback?: Callback<CaptionsStyle>): void; 248 } 249 250 /** 251 * Indicates the edge type of the captions font. 252 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 253 * @since 8 254 */ 255 type CaptionsFontEdgeType = 'none' | 'raised' | 'depressed' | 'uniform' | 'dropShadow'; 256 /** 257 * Indicates the font family of captions. 258 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 259 * @since 8 260 */ 261 type CaptionsFontFamily = 'default' | 'monospacedSerif' | 'serif' | 262 'monospacedSansSerif' | 'sansSerif' | 'casual' | 'cursive' | 'smallCapitals'; 263 /** 264 * Indicates the style of captions. 265 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 266 * @since 8 267 */ 268 interface CaptionsStyle { 269 /** 270 * Indicates the font family of captions. 271 */ 272 fontFamily: CaptionsFontFamily; 273 /** 274 * Indicates the font scaling of captions. 275 */ 276 fontScale: number; 277 /** 278 * Indicates the font color of captions. 279 */ 280 fontColor: number | string; 281 /** 282 * Indicates the edge type of the captions font. 283 */ 284 fontEdgeType: CaptionsFontEdgeType; 285 /** 286 * Indicates the background color of captions. 287 */ 288 backgroundColor: number | string; 289 /** 290 * Indicates the window color of captions. 291 */ 292 windowColor: number | string; 293 } 294 295 /** 296 * Indicates the info of accessibility. 297 * @syscap SystemCapability.BarrierFree.Accessibility.Core 298 * @since 7 299 */ 300 interface AccessibilityAbilityInfo { 301 /** 302 * The ability id. 303 * @since 7 304 */ 305 readonly id: string; 306 307 /* The ability name. 308 * @since 7 309 */ 310 readonly name: string; 311 312 /* The bundle name of the ability. 313 * @since 7 314 */ 315 readonly bundleName: string; 316 317 /* The target bundle name for the observation. 318 * @since 9 319 */ 320 readonly targetBundleNames: Array<string>; 321 322 /** 323 * The type of the ability. 324 * @since 7 325 */ 326 readonly abilityTypes: Array<AbilityType>; 327 328 /** 329 * The capabilities of the ability. 330 * @since 7 331 */ 332 readonly capabilities: Array<Capability>; 333 334 /** 335 * The description of the ability. 336 * @since 7 337 */ 338 readonly description: string; 339 340 /** 341 * The events which the accessibility ability wants to observe. 342 * @since 7 343 */ 344 readonly eventTypes: Array<EventType>; 345 346 } 347 348 /** 349 * Indicates the info of events. 350 * @syscap SystemCapability.BarrierFree.Accessibility.Core 351 * @since 7 352 */ 353 class EventInfo { 354 constructor(jsonObject); 355 /** 356 * The type of an accessibility event. 357 * @since 7 358 */ 359 type: EventType; 360 361 /** 362 * The type of the window change event. 363 * @since 7 364 */ 365 windowUpdateType?: WindowUpdateType; 366 367 /** 368 * The bundle name of the target application. 369 * @since 7 370 */ 371 bundleName: string; 372 373 /** 374 * The type of the event source component,such as button, chart. 375 * @since 7 376 */ 377 componentType?: string; 378 379 /** The page id of the event source. 380 * @since 7 381 */ 382 pageId ?: number; 383 384 /** 385 * The accessibility event description. 386 * @since 7 387 */ 388 description?: string; 389 390 /** 391 * The action that triggers the accessibility event, for example, clicking or focusing a view. 392 * @since 7 393 */ 394 triggerAction: Action; 395 396 /** 397 * The movement step used for reading texts. 398 * @since 7 399 */ 400 textMoveUnit?: TextMoveUnit; 401 402 /** 403 * The content list. 404 * @since 7 405 */ 406 contents?: Array<string>; 407 408 /** 409 * The content changed before. 410 * @since 7 411 */ 412 lastContent?: string; 413 414 /** 415 * The start index of listed items on the screen. 416 * @since 7 417 */ 418 beginIndex?: number; 419 420 /** 421 * The index of the current item on the screen. 422 * @since 7 423 */ 424 currentIndex?: number; 425 426 /** 427 * The end index of listed items on the screen. 428 * @since 7 429 */ 430 endIndex?: number; 431 432 /** 433 * The total of the items. 434 * @since 7 435 */ 436 itemCount?: number; 437 } 438} 439export default accessibility;