• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 输入法框架changeLog
2
3## cl.inputmethod_frameworks.1 API错误信息返回方式变更
4
5下列模块内部接口使用业务逻辑返回值表示错误信息,不符合OpenHarmony接口错误码规范。在API9进行变更。
6
7 - 输入法框架模块:系统接口,@ohos.inputmethod.d.ts
8
9 - 输入法服务模块:系统接口,@ohos.inputmethodengine.d.ts
10
11 - 输入法ExtentionAbility模块:系统接口,@ohos.inputmethodextensionability.d.ts
12
13 - 输入法ExtentionContext模块:系统接口,@ohos.inputmethodextensioncontext.d.ts
14
15 - 输入法子类型模块:系统接口,@ohos.inputMethodSubtype.d.ts
16
17异步接口:通过AsyncCallback或Promise的error对象返回错误信息。
18
19同步接口:通过抛出异常的方式返回错误信息。
20
21**变更影响**
22
23基于此前版本开发的应用,需适配接口的错误信息返回方式,否则会影响原有业务逻辑。
24
25**关键接口/组件变更**
26
27在以下接口增加错误码处理:
28  - getSetting(): InputMethodSetting;
29  - getController(): InputMethodController;
30  - switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolean>): void;
31  - switchInputMethod(target: InputMethodProperty): Promise<boolean>;
32  - switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback<boolean>): void;
33  - switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean>;
34  - switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback<boolean>): void;
35  - switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise<boolean>;
36  - listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback<Array<InputMethodSubtype>>): void;
37  - listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Array<InputMethodSubtype>>;
38  - listCurrentInputMethodSubtype(callback: AsyncCallback<Array<InputMethodSubtype>>): void;
39  - listCurrentInputMethodSubtype(): Promise<Array<InputMethodSubtype>>;
40  - getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void;
41  - getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>>;
42  - showOptionalInputMethods(callback: AsyncCallback<boolean>): void;
43  - showOptionalInputMethods(): Promise<boolean>;
44  - stopInputSession(callback: AsyncCallback<boolean>): void;
45  - stopInputSession(): Promise<boolean>;
46  - showSoftKeyboard(callback: AsyncCallback<void>): void;
47  - showSoftKeyboard():Promise<void>;
48  - hideSoftKeyboard(callback: AsyncCallback<void>): void;
49  - hideSoftKeyboard():Promise<void>;
50  - hide(callback: AsyncCallback<void>): void;
51  - hide(): Promise<void>;
52  - onCreate(want: Want): void;
53  - onDestroy(): void;
54  InputClient 接口下:
55  - sendKeyFunction(action: number, callback: AsyncCallback<boolean>): void;
56  - sendKeyFunction(action: number): Promise<boolean>;
57  - deleteForward(length: number, callback: AsyncCallback<boolean>): void;
58  - deleteForward(length: number): Promise<boolean>;
59  - deleteBackward(length: number, callback: AsyncCallback<boolean>): void;
60  - deleteBackward(length: number): Promise<boolean>;
61  - insertText(text: string, callback: AsyncCallback<boolean>): void;
62  - insertText(text: string): Promise<boolean>;
63  - getForward(length: number, callback: AsyncCallback<string>): void;
64  - getForward(length: number): Promise<string>;
65  - getBackward(length: number, callback: AsyncCallback<string>): void;
66  - getBackward(length: number): Promise<string>;
67  - getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void;
68  - getEditorAttribute(): Promise<EditorAttribute>;
69  - moveCursor(direction: number, callback: AsyncCallback<void>): void;
70  - moveCursor(direction: number): Promise<void>;
71  InputMethodExtensionAbility 类下:
72  - onCreate(want: Want): void;
73  - onDestroy(): void;
74
75**适配指导**
76
77异步接口以showOptionalInputMethods为例,示例代码如下:
78
79callback回调:
80
81```js
82import inputMethod from '@ohos.inputmethod';
83let inputMethodSetting = inputMethod.getSetting();
84try {
85    inputMethodSetting.showOptionalInputMethods((err, data) => {
86        if (err !== undefined) {
87            console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
88            return;
89        }
90        console.info('Succeeded in showing optionalInputMethods.');
91    });
92} catch (err) {
93    console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
94}
95```
96
97Promise回调:
98
99```js
100import inputMethod from '@ohos.inputmethod';
101let inputMethodSetting = inputMethod.getSetting();
102inputMethodSetting.showOptionalInputMethods().then((data) => {
103    console.info('Succeeded in showing optionalInputMethods.');
104}).catch((err) => {
105    console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
106})
107```
108
109## cl.inputmethod_frameworks.2 API部分接口废弃
110
111以下接口标记废除:
112  - getInputMethodSetting(): InputMethodSetting;
113  - getInputMethodController(): InputMethodController;
114  - listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void;
115  - listInputMethod(): Promise<Array<InputMethodProperty>>;
116  - displayOptionalInputMethod(callback: AsyncCallback<void>): void;
117  - displayOptionalInputMethod(): Promise<void>;
118  - stopInput(callback: AsyncCallback<boolean>): void;
119  - stopInput(): Promise<boolean>;
120  interface InputMethodProperty:
121    - readonly packageName: string;
122	- readonly methodId: string;
123  - getInputMethodEngine(): InputMethodEngine;
124  - createKeyboardDelegate(): KeyboardDelegate;
125  - hideKeyboard(callback: AsyncCallback<void>): void;
126  - hideKeyboard(): Promise<void>;
127
128替代接口如下:
129  - getSetting(): InputMethodSetting;
130  - getController(): InputMethodController;
131  - getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void;
132  - getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>>;
133  - showOptionalInputMethods(callback: AsyncCallback<boolean>): void;
134  - showOptionalInputMethods(): Promise<boolean>;
135  - stopInputSession(callback: AsyncCallback<boolean>): void;
136  - stopInputSession(): Promise<boolean>;
137  interface InputMethodProperty:
138    - readonly name: string;
139	- readonly id: string;
140  - getInputMethodAbility(): InputMethodAbility;
141  - getKeyboardDelegate(): KeyboardDelegate;
142  - hide(callback: AsyncCallback<void>): void;
143  - hide(): Promise<void>;
144
145**特别注意:**
146    使用getInputMethodAbility()接口获取到InputMethodAbility对象,代替使用getInputMethodEngine()接口获取InputMethodEngine对象。
147	使用InputMethodAbility中的方法,不要再使用InputMethodEngine中的方法。
148	使用InputMethodAbility中的on('inputStart')方法,获取到KeyboardController实例与InputClient实例,不要再使用InputMethodEngine中的on('inputStart')方法去获取TextInputClient实例。
149之前:
150
151```js
152inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => {
153    let keyboardController = kbController;
154    let textInputClient = textClient;  // 获取到TextInputClient实例
155});
156```
157
158之后:
159```js
160inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => {
161    let keyboardController = kbController;
162    let inputClient = client;  // // 获取到InputClient实例
163});
164```
165
166## cl.inputmethod_frameworks.3 API部分接口变更
167
168变更前:
169  - listInputMethod(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void;
170  - listInputMethod(enable: boolean): Promise<Array<InputMethodProperty>>;
171  - terminateSelf(callback: AsyncCallback<void>): void;
172  - terminateSelf(): Promise<void>;
173
174变更后:
175  - getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void;
176  - getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>>;
177  - destroy(callback: AsyncCallback<void>): void;
178  - destroy(): Promise<void>;
179
180删除API9接口:
181  - startAbility(want: Want, callback: AsyncCallback<void>): void;
182  - startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void;
183  - startAbility(want: Want, options?: StartOptions): Promise<void>;
184
185其他新增接口:
186  - on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void;
187  - off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void;
188  - interface InputMethodProperty:
189    - readonly label?: string;
190	- readonly icon?: string;
191	- readonly iconId?: number;
192	- extra: object;
193
194  - interface InputMethodAbility:
195    - on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => void): void;
196    - off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => void): void;