From c564b9a7942e6481760d75262bc5c0b20d22ac0a Mon Sep 17 00:00:00 2001 From: Hollokin Date: Thu, 10 Nov 2022 13:56:39 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E8=BE=93=E5=85=A5=E6=B3=95=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E3=80=91inputmethod.md=E5=8F=8Ainputmethodengine.md?= =?UTF-8?q?=E9=83=A8=E5=88=86=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=8F=8A=E5=AF=B9=E5=A4=9A=E4=BD=99=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E8=BF=9B=E8=A1=8C=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hollokin --- .../reference/apis/js-apis-inputmethod.md | 40 +- .../apis/js-apis-inputmethodengine.md | 398 ++++++------------ 2 files changed, 166 insertions(+), 272 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md index 08383f51ff..aa285044a0 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @@ -126,7 +126,7 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolea ```js try{ - inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'}, (err, result) => { + inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}, (err, result) => { if (err) { console.error('switchInputMethod err: ' + JSON.stringify(err)); return; @@ -175,7 +175,7 @@ switchInputMethod(target: InputMethodProperty): Promise<boolean> ```js try { - inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'}).then((result) => { + inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}).then((result) => { if (result) { console.info('Success to switchInputMethod.'); } else { @@ -240,7 +240,14 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallb ```js let inputMethodSubtype = { id: "com.example.kikainput", - label: "ServiceExtAbility" + label: "ServiceExtAbility", + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} } try { inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype, (err, result) => { @@ -295,7 +302,14 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean& ```js let inputMethodSubtype = { id: "com.example.kikainput", - label: "ServiceExtAbility" + label: "ServiceExtAbility", + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} } try { inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype).then((result) => { @@ -363,12 +377,20 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp ```js let inputMethodProperty = { - packageName:"com.example.kikakeyboard", - methodId:"ServiceExtAbility" + packageName: "com.example.kikakeyboard", + methodId: "ServiceExtAbility", + extra: {} } let inputMethodSubProperty = { id: "com.example.kikainput", - label: "ServiceExtAbility" + label: "ServiceExtAbility", + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} } try { inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty, (err,result) => { @@ -873,7 +895,8 @@ listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: Async ```js let inputMethodProperty = { packageName:'com.example.kikakeyboard', - methodId:'com.example.kikakeyboard' + methodId:'com.example.kikakeyboard', + extra:{} } try { InputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => { @@ -923,6 +946,7 @@ listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Arr let inputMethodProperty = { packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', + extra:{} } try { InputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md index d98281b3b4..d441dc6801 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md @@ -1,6 +1,6 @@ # 输入法服务 -本模块的作用是拉通普通应用和输入法应用,功能包括:普通应用通过输入法应用进行文本输入、普通应用与输入法服务绑定、普通应用对输入法应用进行显示请求和隐藏请求、普通应用对输入法应用当前状态进行监听等等。 +本模块的作用是拉通输入法应用和其他三方应用(联系人、微信等),功能包括:将三方应用与输入法应用的服务进行绑定、三方应用通过输入法应用进行文本输入、三方应用对输入法应用进行显示键盘请求和隐藏键盘请求、三方应用对输入法应用当前状态进行监听等。 > **说明:** > @@ -69,7 +69,7 @@ getInputMethodAbility(): InputMethodAbility **示例:** ```js -let InputMethodAbility = inputMethodAbility.getInputMethodAbility(); +let InputMethodAbility = inputMethodEngine.getInputMethodAbility(); ``` ## inputMethodEngine.getKeyboardDelegate9+ @@ -89,7 +89,7 @@ getKeyboardDelegate(): KeyboardDelegate **示例:** ```js -let KeyboardDelegate = inputMethodAbility.getKeyboardDelegate(); +let KeyboardDelegate = inputMethodEngine.getKeyboardDelegate(); ``` ## inputMethodEngine.getInputMethodEngine(deprecated) @@ -183,8 +183,6 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC | type | string | 是 | 设置监听类型。
-type为‘inputStart’时表示订阅输入法绑定。 | | callback | [KeyboardController](#keyboardcontroller), [TextInputClient](#textinputclient) | 否 | 回调函数,返回取消订阅的KeyboardController和TextInputClient实例。 | - - **示例:** ```js @@ -193,98 +191,6 @@ inputMethodEngine.getInputMethodEngine().off('inputStart', (kbController, textIn }); ``` -### on('inputStop')9+ - -on(type: 'inputStop', callback: () => void): void - -订阅停止输入法应用事件。使用callback异步回调。 - -**系统能力:** SystemCapability.MiscServices.InputMethodFramework - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 设置监听类型。
-type为‘inputStop’时表示订阅停止输入法应用事件。 | -| callback | void | 是 | 回调函数。 | - -**示例:** - -```js -inputMethodEngine.getInputMethodEngine().on('inputStop', () => { - console.log('inputMethodEngine inputStop'); -}); -``` - -### off('inputStop')9+ - -off(type: 'inputStop', callback: () => void): void - -取消订阅停止输入法应用事件。使用callback异步回调。 - -**系统能力:** SystemCapability.MiscServices.InputMethodFramework - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 设置监听类型。
-type为‘inputStop’时表示订阅停止输入法应用事件。 | -| callback | void | 是 | 回调函数。 | - -**示例:** - -```js -inputMethodEngine.getInputMethodEngine().off('inputStop', () => { - console.log('inputMethodEngine delete inputStop notification.'); -}); -``` - -### on('setCallingWindow')9+ - -on(type: 'setCallingWindow', callback: (wid:number) => void): void - -订阅设置调用窗口事件。使用callback异步回调。 - -**系统能力:** SystemCapability.MiscServices.InputMethodFramework - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 设置监听类型。
-type为‘setCallingWindow’时表示订阅设置调用窗口事件。 | -| callback | number | 是 | 回调函数,返回调用方window id。 | - -**示例:** - -```js -inputMethodEngine.getInputMethodEngine().on('setCallingWindow', (wid) => { - console.log('inputMethodEngine setCallingWindow'); -}); -``` - -### off('setCallingWindow')9+ - -off(type: 'setCallingWindow', callback: (wid:number) => void): void - -取消订阅设置调用窗口事件。使用callback异步回调。 - -**系统能力:** SystemCapability.MiscServices.InputMethodFramework - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 设置监听类型。
-type为‘setCallingWindow’时表示订阅设置调用窗口事件。 | -| callback | number | 是 | 回调函数,返回调用方window id。 | - -**示例:** - -```js -inputMethodEngine.getInputMethodEngine().off('setCallingWindow', () => { - console.log('inputMethodEngine delete setCallingWindow notification.'); -}); -``` - ### on('keyboardShow'|'keyboardHide') on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void @@ -849,13 +755,11 @@ hide(): Promise<void> **示例:** ```js -async function InputMethodEngine() { - await KeyboardController.hide().then(() => { - console.info('hide success.'); - }).catch((err) => { - console.info('hide err: ' + JSON.stringify(err)); - }); -} +KeyboardController.hide().then(() => { + console.info('hide success.'); +}).catch((err) => { + console.info('hide err: ' + JSON.stringify(err)); +}); ``` ### hideKeyboard(deprecated) @@ -909,13 +813,11 @@ hideKeyboard(): Promise<void> **示例:** ```js -async function InputMethodEngine() { - await KeyboardController.hideKeyboard().then(() => { - console.info('hideKeyboard success.'); - }).catch((err) => { - console.info('hideKeyboard err: ' + JSON.stringify(err)); - }); -} +KeyboardController.hideKeyboard().then(() => { + console.info('hideKeyboard success.'); +}).catch((err) => { + console.info('hideKeyboard err: ' + JSON.stringify(err)); +}); ``` ## InputClient9+ @@ -951,7 +853,7 @@ sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void try { InputClient.sendKeyFunction(keyFunction, (err, result) => { if (err) { - console.error('sendKeyFunction err: ' + JSON.stringify(err)JSON.stringify(err)); + console.error('sendKeyFunction err: ' + JSON.stringify(err)); return; } if (result) { @@ -1084,17 +986,15 @@ getForward(length:number): Promise<string> **示例:** ```js -async function InputMethodAbility() { - let length = 1; - try { - await InputClient.getForward(length).then((text) => { - console.info('getForward resul: ' + text); - }).catch((err) => { - console.error('getForward err: ' + JSON.stringify(err)); - }); - } catch (err) { +let length = 1; +try { + InputClient.getForward(length).then((text) => { + console.info('getForward resul: ' + text); + }).catch((err) => { console.error('getForward err: ' + JSON.stringify(err)); - } + }); +} catch (err) { + console.error('getForward err: ' + JSON.stringify(err)); } ``` @@ -1171,17 +1071,15 @@ getBackward(length:number): Promise<string> **示例:** ```js -async function InputMethodAbility() { - let length = 1; - try { - await InputClient.getBackward(length).then((text) => { - console.info('getBackward result: ' + text); - }).catch((err) => { - console.error('getBackward err: ' + JSON.stringify(err)); - }); - } catch (err) { +let length = 1; +try { + InputClient.getBackward(length).then((text) => { + console.info('getBackward result: ' + text); + }).catch((err) => { console.error('getBackward err: ' + JSON.stringify(err)); - } + }); +} catch (err) { + console.error('getBackward err: ' + JSON.stringify(err)); } ``` @@ -1262,21 +1160,19 @@ deleteForward(length:number): Promise<boolean> **示例:** ```js -async function InputMethodAbility() { - let length = 1; - try { - await InputClient.deleteForward(length).then((result) => { - if (result) { - console.info('Success to deleteForward. '); - } else { - console.error('Failed to deleteForward. '); - } - }).catch((err) => { - console.error('deleteForward err: ' + JSON.stringify(err)); - }); - } catch (err) { +let length = 1; +try { + InputClient.deleteForward(length).then((result) => { + if (result) { + console.info('Success to deleteForward. '); + } else { + console.error('Failed to deleteForward. '); + } + }).catch((err) => { console.error('deleteForward err: ' + JSON.stringify(err)); - } + }); +} catch (err) { + console.error('deleteForward err: ' + JSON.stringify(err)); } ``` @@ -1357,18 +1253,16 @@ deleteBackward(length:number): Promise<boolean> **示例:** ```js -async function InputMethodAbility() { - let length = 1; - await InputClient.deleteBackward(length).then((result) => { - if (result) { - console.info('Success to deleteBackward. '); - } else { - console.error('Failed to deleteBackward. '); - } - }).catch((err) => { - console.error('deleteBackward err: ' + JSON.stringify(err)); - }); -} +let length = 1; +InputClient.deleteBackward(length).then((result) => { + if (result) { + console.info('Success to deleteBackward. '); + } else { + console.error('Failed to deleteBackward. '); + } +}).catch((err) => { + console.error('deleteBackward err: ' + JSON.stringify(err)); +}); ``` ### insertText9+ @@ -1443,20 +1337,18 @@ insertText(text:string): Promise<boolean> **示例:** ```js -async function InputMethodAbility() { - try { - await InputClient.insertText('test').then((result) => { - if (result) { - console.info('Success to insertText. '); - } else { - console.error('Failed to insertText. '); - } - }).catch((err) => { - console.error('insertText err: ' + JSON.stringify(err)); - }); - } catch (e) { +try { + InputClient.insertText('test').then((result) => { + if (result) { + console.info('Success to insertText. '); + } else { + console.error('Failed to insertText. '); + } + }).catch((err) => { console.error('insertText err: ' + JSON.stringify(err)); - } + }); +} catch (err) { + console.error('insertText err: ' + JSON.stringify(err)); } ``` @@ -1520,14 +1412,12 @@ getEditorAttribute(): Promise<EditorAttribute> **示例:** ```js -async function InputMethodEngine() { - await InputClient.getEditorAttribute().then((editorAttribute) => { - console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); - console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); - }).catch((err) => { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); - }); -} +InputClient.getEditorAttribute().then((editorAttribute) => { + console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); + console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); +}).catch((err) => { + console.error('getEditorAttribute err: ' + JSON.stringify(err)); +}); ``` ### moveCursor9+ @@ -1557,7 +1447,7 @@ moveCursor(direction: number, callback: AsyncCallback<void>): void ```js try { - InputClient.moveCursor(inputMethodAbility.CURSOR_xxx, (err) => { + InputClient.moveCursor(inputMethodEngine.CURSOR_xxx, (err) => { if (err) { console.error('moveCursor err: ' + JSON.stringify(err)); return; @@ -1600,20 +1490,14 @@ moveCursor(direction: number): Promise<void> **示例:** ```js -async function InputMethodAbility() { - try { - await InputClient.moveCursor(inputMethodEngine.CURSOR_xxx).then((err) => { - if (err) { - console.log('moveCursor err: ' + JSON.stringify(err)); - return; - } - console.log('moveCursor success'); - }).catch((err) => { - console.error('moveCursor success err: ' + JSON.stringify(err)); - }); - } catch (err) { - console.log('moveCursor err: ' + JSON.stringify(err)); - } +try { + InputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => { + console.log('moveCursor success'); + }).catch((err) => { + console.error('moveCursor success err: ' + JSON.stringify(err)); + }); +} catch (err) { + console.log('moveCursor err: ' + JSON.stringify(err)); } ``` @@ -1706,14 +1590,12 @@ getForward(length:number): Promise<string> **示例:** ```js -async function InputMethodEngine() { - let length = 1; - await TextInputClient.getForward(length).then((text) => { - console.info('getForward result---res: ' + text); - }).catch((err) => { - console.error('getForward err: ' + JSON.stringify(err)); - }); -} +let length = 1; +TextInputClient.getForward(length).then((text) => { + console.info('getForward result: ' + JSON.stringify(text)); +}).catch((err) => { + console.error('getForward err: ' + JSON.stringify(err)); +}); ``` ### getBackward(deprecated) @@ -1775,14 +1657,12 @@ getBackward(length:number): Promise<string> **示例:** ```js -async function InputMethodEngine() { - let length = 1; - await TextInputClient.getBackward(length).then((text) => { - console.info('getBackward result---res: ' + text); - }).catch((err) => { - console.error('getBackward err: ' + JSON.stringify(err)); - }); -} +let length = 1; +TextInputClient.getBackward(length).then((text) => { + console.info('getBackward result: ' + JSON.stringify(text)); +}).catch((err) => { + console.error('getBackward err: ' + JSON.stringify(err)); +}); ``` ### deleteForward(deprecated) @@ -1848,18 +1728,16 @@ deleteForward(length:number): Promise<boolean> **示例:** ```js -async function InputMethodEngine() { - let length = 1; - await TextInputClient.deleteForward(length).then((result) => { - if (result) { - console.info('Success to deleteForward. '); - } else { - console.error('Failed to deleteForward. '); - } - }).catch((err) => { - console.error('deleteForward err: ' + JSON.stringify(err)); - }); -} +let length = 1; +TextInputClient.deleteForward(length).then((result) => { + if (result) { + console.info('Succeed in deleting forward. '); + } else { + console.error('Failed to delete forward. '); + } +}).catch((err) => { + console.error('Failed to delete forward err: ' + JSON.stringify(err)); +}); ``` ### deleteBackward(deprecated) @@ -1925,18 +1803,16 @@ deleteBackward(length:number): Promise<boolean> **示例:** ```js -async function InputMethodEngine() { - let length = 1; - await TextInputClient.deleteBackward(length).then((result) => { - if (result) { - console.info('Success to deleteBackward. '); - } else { - console.error('Failed to deleteBackward. '); - } - }).catch((err) => { - console.error('deleteBackward err: ' + JSON.stringify(err)); - }); -} +let length = 1; +TextInputClient.deleteBackward(length).then((result) => { + if (result) { + console.info('Success to deleteBackward. '); + } else { + console.error('Failed to deleteBackward. '); + } +}).catch((err) => { + console.error('deleteBackward err: ' + JSON.stringify(err)); +}); ``` ### sendKeyFunction(deprecated) @@ -2000,17 +1876,15 @@ sendKeyFunction(action:number): Promise<boolean> **示例:** ```js -async function InputMethodEngine() { - await client.sendKeyFunction(keyFunction).then((result) => { - if (result) { - console.info('Success to sendKeyFunction. '); - } else { - console.error('Failed to sendKeyFunction. '); - } - }).catch((err) => { - console.error('sendKeyFunction err:' + JSON.stringify(err)); - }); -} +TextInputClient.sendKeyFunction(keyFunction).then((result) => { + if (result) { + console.info('Success to sendKeyFunction. '); + } else { + console.error('Failed to sendKeyFunction. '); + } +}).catch((err) => { + console.error('sendKeyFunction err:' + JSON.stringify(err)); +}); ``` ### insertText(deprecated) @@ -2075,17 +1949,15 @@ insertText(text:string): Promise<boolean> **示例:** ```js -async function InputMethodEngine() { - await TextInputClient.insertText('test').then((result) => { - if (result) { - console.info('Success to insertText. '); - } else { - console.error('Failed to insertText. '); - } - }).catch((err) => { - console.error('insertText err: ' + JSON.stringify(err)); - }); -} +TextInputClient.insertText('test').then((result) => { + if (result) { + console.info('Success to insertText. '); + } else { + console.error('Failed to insertText. '); + } +}).catch((err) => { + console.error('insertText err: ' + JSON.stringify(err)); +}); ``` ### getEditorAttribute(deprecated) @@ -2140,12 +2012,10 @@ getEditorAttribute(): Promise<EditorAttribute> **示例:** ```js -async function InputMethodEngine() { - await TextInputClient.getEditorAttribute().then((editorAttribute) => { - console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); - console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); - }).catch((err) => { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); - }); -} +TextInputClient.getEditorAttribute().then((editorAttribute) => { + console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); + console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); +}).catch((err) => { + console.error('getEditorAttribute err: ' + JSON.stringify(err)); +}); ``` \ No newline at end of file -- GitLab