1/* 2 * Copyright (c) 2021 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 InputMethodSubtype from './@ohos.InputMethodSubtype'; 18 19/** 20 * Input method 21 * 22 * @since 6 23 * @syscap SystemCapability.MiscServices.InputMethodFramework 24 */ 25declare namespace inputMethod { 26 /** 27 * Keyboard max number 28 * @since 8 29 */ 30 const MAX_TYPE_NUM: number 31 32 /** 33 * Input method setting 34 * @since 8 35 * @deprecated since 9 36 * @useinstead ohos.inputMethod.getSetting 37 */ 38 function getInputMethodSetting(): InputMethodSetting; 39 40 /** 41 * Input method controller 42 * @since 6 43 * @deprecated since 9 44 * @useinstead ohos.inputMethod.getController 45 */ 46 function getInputMethodController(): InputMethodController; 47 48 /** 49 * Input method setting 50 * @since 9 51 * @returns { InputMethodSetting } the object of InputMethodSetting. 52 * @throws {BusinessError} 12800007 - settings extension error. 53 * @syscap SystemCapability.MiscServices.InputMethodFramework 54 */ 55 function getSetting(): InputMethodSetting; 56 57 /** 58 * Input method controller 59 * @since 9 60 * @returns { InputMethodController } the object of InputMethodController. 61 * @throws {BusinessError} 12800006 - input method controller error. 62 * @syscap SystemCapability.MiscServices.InputMethodFramework 63 */ 64 function getController(): InputMethodController; 65 66 /** 67 * Switch input method 68 * @permission ohos.permission.CONNECT_IME_ABILITY 69 * @param { InputMethodProperty } [target] - indicates the input method which will replace the current one. 70 * @param { AsyncCallback<boolean> } [callback] - the callback of switchInputMethod. 71 * @throws {BusinessError} 201 - permissions check fails. 72 * @throws {BusinessError} 401 - parameter error. 73 * @throws {BusinessError} 12800005 - configuration persisting error. 74 * @throws {BusinessError} 12800008 - input method manager service error. 75 * @syscap SystemCapability.MiscServices.InputMethodFramework 76 * @since 9 77 */ 78 function switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolean>): void; 79 80 /** 81 * Switch input method 82 * @permission ohos.permission.CONNECT_IME_ABILITY 83 * @param {InputMethodProperty} target - Indicates the input method which will replace the current one. 84 * @returns {Promise<boolean>} the promise returned by the function. 85 * @throws {BusinessError} 201 - permissions check fails. 86 * @throws {BusinessError} 401 - parameter error. 87 * @throws {BusinessError} 12800005 - configuration persisting error. 88 * @throws {BusinessError} 12800008 - input method manager service error. 89 * @syscap SystemCapability.MiscServices.InputMethodFramework 90 * @since 9 91 */ 92 function switchInputMethod(target: InputMethodProperty): Promise<boolean>; 93 94 /** 95 * Get current input method 96 * @since 9 97 * @returns { InputMethodProperty } the property of current inputmethod. 98 * @syscap SystemCapability.MiscServices.InputMethodFramework 99 */ 100 function getCurrentInputMethod(): InputMethodProperty; 101 102 /** 103 * Switch current input method subtype 104 * @permission ohos.permission.CONNECT_IME_ABILITY 105 * @param {InputMethodSubtype} target - Indicates the input method subtype which will replace the current one. 106 * @param {AsyncCallback<boolean>} callback - the callback of switchCurrentInputMethodSubtype. 107 * @throws {BusinessError} 201 - permissions check fails. 108 * @throws {BusinessError} 401 - parameter error. 109 * @throws {BusinessError} 12800005 - configuration persisting error. 110 * @throws {BusinessError} 12800008 - input method manager service error. 111 * @syscap SystemCapability.MiscServices.InputMethodFramework 112 * @since 9 113 */ 114 function switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback<boolean>): void; 115 116 /** 117 * Switch current input method subtype 118 * @permission ohos.permission.CONNECT_IME_ABILITY 119 * @param {InputMethodSubtype} target - Indicates the input method subtype which will replace the current one. 120 * @returns {Promise<boolean>} the promise returned by the function. 121 * @throws {BusinessError} 201 - permissions check fails. 122 * @throws {BusinessError} 401 - parameter error. 123 * @throws {BusinessError} 12800005 - configuration persisting error. 124 * @throws {BusinessError} 12800008 - input method manager service error. 125 * @syscap SystemCapability.MiscServices.InputMethodFramework 126 * @since 9 127 */ 128 function switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean>; 129 130 /** 131 * Get the current input method subtype 132 * @returns {InputMethodSubtype} the subtype of the current input method. 133 * @syscap SystemCapability.MiscServices.InputMethodFramework 134 * @since 9 135 */ 136 function getCurrentInputMethodSubtype(): InputMethodSubtype; 137 138 /** 139 * Switch input method and subtype 140 * @permission ohos.permission.CONNECT_IME_ABILITY 141 * @param {InputMethodProperty} inputMethodProperty - Indicates the target input method. 142 * @param {InputMethodSubtype} inputMethodSubtype - Indicates the target input method subtype. 143 * @param {AsyncCallback<boolean>} callback - the callback of switchCurrentInputMethodAndSubtype. 144 * @throws {BusinessError} 201 - permissions check fails. 145 * @throws {BusinessError} 401 - parameter error. 146 * @throws {BusinessError} 12800005 - configuration persisting error. 147 * @throws {BusinessError} 12800008 - input method manager service error. 148 * @syscap SystemCapability.MiscServices.InputMethodFramework 149 * @since 9 150 */ 151 function switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback<boolean>): void; 152 153 /** 154 * Switch input method and subtype. 155 * @permission ohos.permission.CONNECT_IME_ABILITY 156 * @param {InputMethodProperty} inputMethodProperty - Indicates the target input method. 157 * @param {InputMethodSubtype} inputMethodSubtype - Indicates the target input method subtype. 158 * @returns {Promise<boolean>} the promise returned by the function. 159 * @throws {BusinessError} 201 - permissions check fails. 160 * @throws {BusinessError} 401 - parameter error. 161 * @throws {BusinessError} 12800005 - configuration persisting error. 162 * @throws {BusinessError} 12800008 - input method manager service error. 163 * @syscap SystemCapability.MiscServices.InputMethodFramework 164 * @since 9 165 */ 166 function switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise<boolean>; 167 168 /** 169 * @since 8 170 */ 171 interface InputMethodSetting { 172 /** 173 * Subscribe input method or subtype change. 174 * @param {string} type - Indicates the event type. 175 * @param {(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void} callback - the callback of 'imeChange' 176 * @syscap SystemCapability.MiscServices.InputMethodFramework 177 * @since 9 178 */ 179 on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void; 180 181 /** 182 * Unsubscribe input method or subtype change. 183 * @param {string} type - Indicates the event type. 184 * @param {(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void} [callback] - the callback of 'imeChange', 185 * when subscriber unsubscribes all callback functions of event 'imeChange', this parameter can be left blank. 186 * @syscap SystemCapability.MiscServices.InputMethodFramework 187 * @since 9 188 */ 189 off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void; 190 191 /** 192 * List subtype of the specified input method. 193 * @param {InputMethodProperty} inputMethodProperty - the property of the specified inputmethod. 194 * @param {AsyncCallback<Array<InputMethodSubtype>>} callback - the callback of listInputMethodSubtype. 195 * @throws {BusinessError} 401 - parameter error. 196 * @throws {BusinessError} 12800001 - package manager error. 197 * @throws {BusinessError} 12800008 - input method manager service error. 198 * @syscap SystemCapability.MiscServices.InputMethodFramework 199 * @since 9 200 */ 201 listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback<Array<InputMethodSubtype>>): void; 202 203 /** 204 * List subtype of the specified input method. 205 * @param {InputMethodProperty} inputMethodProperty - Indicates the specified input method. 206 * @returns {Promise<Array<InputMethodSubtype>>} the promise returned by the function. 207 * @throws {BusinessError} 401 - parameter error. 208 * @throws {BusinessError} 12800001 - package manager error. 209 * @throws {BusinessError} 12800008 - input method manager service error. 210 * @syscap SystemCapability.MiscServices.InputMethodFramework 211 * @since 9 212 */ 213 listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Array<InputMethodSubtype>>; 214 215 /** 216 * List subtype of current input method 217 * @param {AsyncCallback<Array<InputMethodSubtype>>} callback - the callback of listCurrentInputMethodSubtype. 218 * @throws {BusinessError} 12800001 - package manager error. 219 * @throws {BusinessError} 12800008 - input method manager service error. 220 * @syscap SystemCapability.MiscServices.InputMethodFramework 221 * @since 9 222 */ 223 listCurrentInputMethodSubtype(callback: AsyncCallback<Array<InputMethodSubtype>>): void; 224 225 /** 226 * List subtype of current input method 227 * @returns {Promise<Array<InputMethodSubtype>>} the promise returned by the function. 228 * @throws {BusinessError} 12800001 - package manager error. 229 * @throws {BusinessError} 12800008 - input method manager service error. 230 * @syscap SystemCapability.MiscServices.InputMethodFramework 231 * @since 9 232 */ 233 listCurrentInputMethodSubtype(): Promise<Array<InputMethodSubtype>>; 234 235 /** 236 * List input methods 237 * @param {boolean} enable : 238 * If true, collect enabled input methods. 239 * If false, collect disabled input methods. 240 * @param {AsyncCallback<Array<InputMethodProperty>>} callback - the callback of getInputMethods. 241 * @throws {BusinessError} 401 - parameter error. 242 * @throws {BusinessError} 12800001 - package manager error. 243 * @throws {BusinessError} 12800008 - input method manager service error. 244 * @syscap SystemCapability.MiscServices.InputMethodFramework 245 * @since 9 246 */ 247 getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void; 248 249 /** 250 * List input methods 251 * @param {boolean} enable : 252 * If true, collect enabled input methods. 253 * If false, collect disabled input methods. 254 * @returns {Promise<Array<InputMethodProperty>>} the promise returned by the function. 255 * @throws {BusinessError} 401 - parameter error. 256 * @throws {BusinessError} 12800001 - package manager error. 257 * @throws {BusinessError} 12800008 - input method manager service error. 258 * @syscap SystemCapability.MiscServices.InputMethodFramework 259 * @since 9 260 */ 261 getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>>; 262 263 /** 264 * @since 8 265 * @deprecated since 9 266 * @useinstead ohos.inputMethod.InputMethodSetting.getInputMethods 267 */ 268 listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void; 269 /** 270 * @since 8 271 * @deprecated since 9 272 * @useinstead ohos.inputMethod.InputMethodSetting.getInputMethods 273 */ 274 listInputMethod(): Promise<Array<InputMethodProperty>>; 275 276 /** 277 * Show input method setting extension dialog 278 * @since 9 279 * @param {AsyncCallback<boolean>} callback - the callback of showOptionalInputMethods. 280 * @throws {BusinessError} 12800008 - input method manager service error. 281 * @syscap SystemCapability.MiscServices.InputMethodFramework 282 */ 283 showOptionalInputMethods(callback: AsyncCallback<boolean>): void; 284 285 /** 286 * Show input method setting extension dialog 287 * @since 9 288 * @returns { Promise<boolean> } the promise returned by the function. 289 * @throws {BusinessError} 12800008 - input method manager service error. 290 * @syscap SystemCapability.MiscServices.InputMethodFramework 291 */ 292 showOptionalInputMethods(): Promise<boolean>; 293 294 /** 295 * @since 8 296 * @deprecated since 9 297 * @useinstead ohos.inputMethod.InputMethodSetting.showOptionalInputMethods 298 */ 299 displayOptionalInputMethod(callback: AsyncCallback<void>): void; 300 301 /** 302 * @since 8 303 * @deprecated since 9 304 * @useinstead ohos.inputMethod.InputMethodSetting.showOptionalInputMethods 305 */ 306 displayOptionalInputMethod(): Promise<void>; 307 } 308 309 /** 310 * @since 6 311 */ 312 interface InputMethodController { 313 /** 314 * Stop input session 315 * @param {AsyncCallback<boolean>} callback - the callback of stopInputSession. 316 * @throws {BusinessError} 12800003 - input method client error. 317 * @throws {BusinessError} 12800008 - input method manager service error. 318 * @syscap SystemCapability.MiscServices.InputMethodFramework 319 * @since 9 320 */ 321 stopInputSession(callback: AsyncCallback<boolean>): void; 322 323 /** 324 * Stop input session 325 * @returns {Promise<boolean>} the promise returned by the function. 326 * @throws {BusinessError} 12800003 - input method client error. 327 * @throws {BusinessError} 12800008 - input method manager service error. 328 * @syscap SystemCapability.MiscServices.InputMethodFramework 329 * @since 9 330 */ 331 stopInputSession(): Promise<boolean>; 332 333 /** 334 * Stop input 335 * @since 6 336 * @deprecated since 9 337 * @useinstead ohos.inputMethod.InputMethodController.stopInputSession 338 * @syscap SystemCapability.MiscServices.InputMethodFramework 339 */ 340 stopInput(callback: AsyncCallback<boolean>): void; 341 342 /** 343 * Stop input 344 * @since 6 345 * @returns { Promise<boolean> } the promise returned by the function. 346 * @deprecated since 9 347 * @useinstead ohos.inputMethod.InputMethodController.stopInputSession 348 * @syscap SystemCapability.MiscServices.InputMethodFramework 349 */ 350 stopInput(): Promise<boolean>; 351 352 /** 353 * Show soft keyboard 354 * @permission ohos.permission.CONNECT_IME_ABILITY 355 * @param {AsyncCallback<void>} callback - the callback of showSoftKeyboard. 356 * @throws {BusinessError} 201 - permissions check fails. 357 * @throws {BusinessError} 12800003 - input method client error. 358 * @throws {BusinessError} 12800008 - input method manager service error. 359 * @syscap SystemCapability.MiscServices.InputMethodFramework 360 * @since 9 361 */ 362 showSoftKeyboard(callback: AsyncCallback<void>): void; 363 364 /** 365 * Show soft keyboard 366 * @permission ohos.permission.CONNECT_IME_ABILITY 367 * @returns {Promise<boolean>} the promise returned by the function. 368 * @throws {BusinessError} 201 - permissions check fails. 369 * @throws {BusinessError} 12800003 - input method client error. 370 * @throws {BusinessError} 12800008 - input method manager service error. 371 * @syscap SystemCapability.MiscServices.InputMethodFramework 372 * @since 9 373 */ 374 showSoftKeyboard():Promise<void>; 375 376 /** 377 * Hide soft keyboard 378 * @permission ohos.permission.CONNECT_IME_ABILITY 379 * @param {AsyncCallback<void>} callback - the callback of hideSoftKeyboard. 380 * @throws {BusinessError} 201 - permissions check fails. 381 * @throws {BusinessError} 12800003 - input method client error. 382 * @throws {BusinessError} 12800008 - input method manager service error. 383 * @syscap SystemCapability.MiscServices.InputMethodFramework 384 * @since 9 385 */ 386 hideSoftKeyboard(callback: AsyncCallback<void>): void; 387 388 /** 389 * Hide soft keyboard 390 * @permission ohos.permission.CONNECT_IME_ABILITY 391 * @returns {Promise<void>} the promise returned by the function. 392 * @throws {BusinessError} 201 - permissions check fails. 393 * @throws {BusinessError} 12800003 - input method client error. 394 * @throws {BusinessError} 12800008 - input method manager service error. 395 * @syscap SystemCapability.MiscServices.InputMethodFramework 396 * @since 9 397 */ 398 hideSoftKeyboard():Promise<void>; 399 } 400 401 /** 402 * input method property 403 * @since 8 404 */ 405 interface InputMethodProperty { 406 /** 407 * The name of input method 408 * @since 8 409 * @deprecated since 9 410 * @useinstead ohos.inputMethod.InputMethodProperty.name 411 * @syscap SystemCapability.MiscServices.InputMethodFramework 412 */ 413 readonly packageName: string; 414 415 /** 416 * The id of input method 417 * @since 8 418 * @deprecated since 9 419 * @useinstead ohos.inputMethod.InputMethodProperty.id 420 * @syscap SystemCapability.MiscServices.InputMethodFramework 421 */ 422 readonly methodId: string; 423 424 /** 425 * The name of input method 426 * @since 9 427 * @syscap SystemCapability.MiscServices.InputMethodFramework 428 */ 429 readonly name: string; 430 431 /** 432 * The id of input method 433 * @since 9 434 * @syscap SystemCapability.MiscServices.InputMethodFramework 435 */ 436 readonly id: string; 437 438 /** 439 * The label of input method 440 * @since 9 441 * @syscap SystemCapability.MiscServices.InputMethodFramework 442 */ 443 readonly label?: string; 444 445 /** 446 * The icon of input method 447 * @since 9 448 * @syscap SystemCapability.MiscServices.InputMethodFramework 449 */ 450 readonly icon?: string; 451 452 /** 453 * The icon id of input method 454 * @since 9 455 * @syscap SystemCapability.MiscServices.InputMethodFramework 456 */ 457 readonly iconId?: number; 458 459 /** 460 * The extra info of input method 461 * @since 9 462 * @syscap SystemCapability.MiscServices.InputMethodFramework 463 */ 464 extra: object; 465 } 466} 467 468export default inputMethod;