harmony 鸿蒙Input Method Framework ChangeLog

  • 2023-02-03
  • 浏览 (478)

Input Method Framework ChangeLog

cl.inputmethod_frameworks.1 API Error Information Return Method Change

The internal APIs of the following modules used service logic return values to indicate error information, which did not comply with the error code specifications of OpenHarmony. Therefore, they are modified in API version 9 and later.

  • Input method framework module: system API, @ohos.inputmethod.d.ts

  • Input method service module: system API, @ohos.inputmethodengine.d.ts

  • Input method ExtentionAbility module: system API, @ohos.inputmethodextensionability.d.ts

  • Input method ExtentionContext module: system API, @ohos.inputmethodextensioncontext.d.ts

  • Input method subtype module: system API, @ohos.inputMethodSubtype.d.ts

Asynchronous API: An error message is returned via AsyncCallback or the error object of Promise.

Synchronous API: An error message is returned via an exception.

Change Impacts

The application developed based on earlier versions needs to adapt the method for returning API error information. Otherwise, the original service logic will be affected.

Key API/Component Changes

Error code processing is added for the following APIs: - getSetting(): InputMethodSetting; - getController(): InputMethodController; - switchInputMethod(target: InputMethodProperty, callback: AsyncCallback): void; - switchInputMethod(target: InputMethodProperty): Promise; - switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback): void; - switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise; - switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback): void; - switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise; - listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback>): void; - listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise>; - listCurrentInputMethodSubtype(callback: AsyncCallback>): void; - listCurrentInputMethodSubtype(): Promise>; - getInputMethods(enable: boolean, callback: AsyncCallback>): void; - getInputMethods(enable: boolean): Promise>; - showOptionalInputMethods(callback: AsyncCallback): void; - showOptionalInputMethods(): Promise; - stopInputSession(callback: AsyncCallback): void; - stopInputSession(): Promise; - showSoftKeyboard(callback: AsyncCallback): void; - showSoftKeyboard():Promise; - hideSoftKeyboard(callback: AsyncCallback): void; - hideSoftKeyboard():Promise; - hide(callback: AsyncCallback): void; - hide(): Promise; - onCreate(want: Want): void; - onDestroy(): void; In InputClient: - sendKeyFunction(action: number, callback: AsyncCallback): void; - sendKeyFunction(action: number): Promise; - deleteForward(length: number, callback: AsyncCallback): void; - deleteForward(length: number): Promise; - deleteBackward(length: number, callback: AsyncCallback): void; - deleteBackward(length: number): Promise; - insertText(text: string, callback: AsyncCallback): void; - insertText(text: string): Promise; - getForward(length: number, callback: AsyncCallback): void; - getForward(length: number): Promise; - getBackward(length: number, callback: AsyncCallback): void; - getBackward(length: number): Promise; - getEditorAttribute(callback: AsyncCallback): void; - getEditorAttribute(): Promise; - moveCursor(direction: number, callback: AsyncCallback): void; - moveCursor(direction: number): Promise; In InputMethodExtensionAbility: - onCreate(want: Want): void; - onDestroy(): void;

Adaptation Guide

The following uses showOptionalInputMethods as an example for asynchronous APIs:

Callback mode:

import inputMethod from '@ohos.inputmethod';
let inputMethodSetting = inputMethod.getSetting();
try {
    inputMethodSetting.showOptionalInputMethods((err, data) => {
        if (err !== undefined) {
            console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
            return;
        }
        console.info('Succeeded in showing optionalInputMethods.');
    });
} catch (err) {
    console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
}

Promise mode:

import inputMethod from '@ohos.inputmethod';
let inputMethodSetting = inputMethod.getSetting();
inputMethodSetting.showOptionalInputMethods().then((data) => {
    console.info('Succeeded in showing optionalInputMethods.');
}).catch((err) => {
    console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
})

cl.inputmethod_frameworks.2 Deprecation of Some APIs

Deprecated APIs: - getInputMethodSetting(): InputMethodSetting; - getInputMethodController(): InputMethodController; - listInputMethod(callback: AsyncCallback>): void; - listInputMethod(): Promise>; - displayOptionalInputMethod(callback: AsyncCallback): void; - displayOptionalInputMethod(): Promise; - stopInput(callback: AsyncCallback): void; - stopInput(): Promise; interface InputMethodProperty: - readonly packageName: string; - readonly methodId: string; - getInputMethodEngine(): InputMethodEngine; - createKeyboardDelegate(): KeyboardDelegate; - hideKeyboard(callback: AsyncCallback): void; - hideKeyboard(): Promise;

Substitute APIs: - getSetting(): InputMethodSetting; - getController(): InputMethodController; - getInputMethods(enable: boolean, callback: AsyncCallback>): void; - getInputMethods(enable: boolean): Promise>; - showOptionalInputMethods(callback: AsyncCallback): void; - showOptionalInputMethods(): Promise; - stopInputSession(callback: AsyncCallback): void; - stopInputSession(): Promise; interface InputMethodProperty: - readonly name: string; - readonly id: string; - getInputMethodAbility(): InputMethodAbility; - getKeyboardDelegate(): KeyboardDelegate; - hide(callback: AsyncCallback): void; - hide(): Promise;

NOTE

  • Use the getInputMethodAbility() API to obtain an InputMethodAbility object, and do not use getInputMethodEngine() to obtain an InputMethodEngine object.
  • Use methods in InputMethodAbility, and do not use methods in InputMethodEngine.
  • Use the on(‘inputStart’) method in InputMethodAbility to obtain a KeyboardController instance and an InputClient instance, and do not use the on(‘inputStart’) method in InputMethodEngine to obtain a TextInputClient instance.

Before:

inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => {
    let keyboardController = kbController;
    let textInputClient = textClient;  // Obtain a TextInputClient instance.
});

After:

inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => {
    let keyboardController = kbController;
    let inputClient = client;  // // Obtain an InputClient instance.
});

cl.inputmethod_frameworks.3 Change of Some APIs

Before change: - listInputMethod(enable: boolean, callback: AsyncCallback>): void; - listInputMethod(enable: boolean): Promise>; - terminateSelf(callback: AsyncCallback): void; - terminateSelf(): Promise;

After change: - getInputMethods(enable: boolean, callback: AsyncCallback>): void; - getInputMethods(enable: boolean): Promise>; - destroy(callback: AsyncCallback): void; - destroy(): Promise;

Deleted APIs in API version 9: - startAbility(want: Want, callback: AsyncCallback): void; - startAbility(want: Want, options: StartOptions, callback: AsyncCallback): void; - startAbility(want: Want, options?: StartOptions): Promise;

Added APIs: - on(type: ‘imeChange’, callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void; - off(type: ‘imeChange’, callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void; - interface InputMethodProperty: - readonly label?: string; - readonly icon?: string; - readonly iconId?: number; - extra: object;

  • interface InputMethodAbility:
    • on(type: ‘setSubtype’, callback: (inputMethodSubtype: InputMethodSubtype) => void): void;
    • off(type: ‘setSubtype’, callback?: (inputMethodSubtype: InputMethodSubtype) => void): void;

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Account Subsystem ChangeLog

harmony 鸿蒙ChangeLog of JS API Changes in the Multimedia Subsystem

harmony 鸿蒙Device Manager ChangeLog

harmony 鸿蒙USB Manager ChangeLog

harmony 鸿蒙DSoftBus Subsystem ChangeLog

harmony 鸿蒙File Management Subsystem ChangeLog

harmony 鸿蒙Globalization Subsystem ChangeLog

harmony 鸿蒙Multimodal Input ChangeLog

harmony 鸿蒙Power Subsystem ChangeLog

harmony 鸿蒙Upload and Download Subsystem ChangeLog

0  赞