提交 c5df33c2 编写于 作者: E ester.zhou

Update docs (12415)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 f201cf69
# Input Method Subtype
# @ohos.inputmethodsubtype
The **inputMethodEngine** module provides APIs for managing the attributes of input method subtypes. Different attribute settings result in different subtypes.
The **inputMethodSubtype** module provides APIs for managing the attributes of input method subtypes. Different attribute settings result in different subtypes.
> **NOTE**
>
......
# Input Method Framework
# @ohos.inputmethod
The **inputMethod** module provides an input method framework, which can be used to hide the keyboard, obtain the list of installed input methods, display the dialog box for input method selection, and more.
>**NOTE**
> **NOTE**
>
>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
```js
import inputMethod from '@ohos.inputmethod';
```
......@@ -31,14 +31,14 @@ Describes the input method application attributes.
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| name<sup>9+</sup> | string | Yes| No| Internal name of the input method.|
| id<sup>9+</sup> | string | Yes| No| Unique ID of the input method.|
| label<sup>9+</sup> | string | Yes| No| External display name of the input method.|
| icon<sup>9+</sup> | string | Yes| No| Icon of the input method.|
| iconId<sup>9+</sup> | number | Yes| No| Icon ID of the input method.|
| extra<sup>9+</sup> | object | Yes| No| Extra information about the input method.|
| packageName<sup>(deprecated)</sup> | string | Yes| No| Name of the input method package.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name**.|
| methodId<sup>(deprecated)</sup> | string | Yes| No| Unique ID of the input method.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.|
| name<sup>9+</sup> | string | Yes| No| Internal name of the input method. Mandatory.|
| id<sup>9+</sup> | string | Yes| No| Unique ID of the input method. Mandatory.|
| label<sup>9+</sup> | string | Yes| No| External display name of the input method. Optional.|
| icon<sup>9+</sup> | string | Yes| No| Icon of the input method. Optional.|
| iconId<sup>9+</sup> | number | Yes| No| Icon ID of the input method. Optional.|
| extra<sup>9+</sup> | object | Yes| Yes| Extra information about the input method. Mandatory.|
| packageName<sup>(deprecated)</sup> | string | Yes| No| Name of the input method package. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name**.|
| methodId<sup>(deprecated)</sup> | string | Yes| No| Unique ID of the input method. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.|
## inputMethod.getController<sup>9+</sup>
......@@ -102,7 +102,7 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolea
Switches to another input method. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -120,25 +120,33 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
let im = inputMethod.getCurrentInputMethod();
let prop = {
packageName: im.packageName,
methodId: im.methodId,
name: im.packageName,
id: im.methodId,
extra: {}
}
try{
inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}, (err, result) => {
if (err) {
console.error('switchInputMethod err: ' + JSON.stringify(err));
inputMethod.switchInputMethod(prop, (err, result) => {
if (err !== undefined) {
console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to switchInputMethod.(callback)');
console.info('Succeeded in switching inputmethod.');
} else {
console.error('Failed to switchInputMethod.(callback)');
console.error('Failed to switchInputMethod.');
}
});
} catch(err) {
console.error('switchInputMethod err: ' + JSON.stringify(err));
console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
}
```
## inputMethod.switchInputMethod<sup>9+</sup>
......@@ -146,7 +154,7 @@ switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt;
Switches to another input method. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -169,23 +177,31 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
let im = inputMethod.getCurrentInputMethod();
let prop = {
packageName: im.packageName,
methodId: im.methodId,
name: im.packageName,
id: im.methodId,
extra: {}
}
try {
inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}).then((result) => {
inputMethod.switchInputMethod(prop).then((result) => {
if (result) {
console.info('Success to switchInputMethod.');
console.info('Succeeded in switching inputmethod.');
} else {
console.error('Failed to switchInputMethod.');
}
}).catch((err) => {
console.error('switchInputMethod err: ' + JSON.stringify(err));
console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
})
} catch(err) {
console.error('switchInputMethod err: ' + JSON.stringify(err));
console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
}
```
......@@ -215,7 +231,7 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallb
Switches to another subtype of the current input method. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -233,36 +249,35 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
let inputMethodSubtype = {
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}
try {
inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype, (err, result) => {
if (err) {
console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err));
inputMethod.switchCurrentInputMethodSubtype({
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}, (err, result) => {
if (err !== undefined) {
console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to switchCurrentInputMethodSubtype.(callback)');
console.info('Succeeded in switching currentInputMethodSubtype.');
} else {
console.error('Failed to switchCurrentInputMethodSubtype.(callback)');
console.error('Failed to switchCurrentInputMethodSubtype');
}
});
} catch(err) {
console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err));
console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
}
```
......@@ -272,7 +287,7 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise&lt;boolean&
Switches to another subtype of the current input method. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -295,34 +310,33 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
let inputMethodSubtype = {
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}
try {
inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype).then((result) => {
inputMethod.switchCurrentInputMethodSubtype({
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}).then((result) => {
if (result) {
console.info('Success to switchCurrentInputMethodSubtype.');
console.info('Succeeded in switching currentInputMethodSubtype.');
} else {
console.error('Failed to switchCurrentInputMethodSubtype.');
}
}).catch((err) => {
console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err));
console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
})
} catch(err) {
console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err));
console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
}
```
......@@ -352,7 +366,7 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp
Switches to a specified subtype of a specified input method. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -371,41 +385,43 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
let im = inputMethod.getCurrentInputMethod();
let inputMethodProperty = {
packageName: "com.example.kikakeyboard",
methodId: "ServiceExtAbility",
extra: {}
}
let inputMethodSubProperty = {
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
packageName: im.packageName,
methodId: im.methodId,
name: im.packageName,
id: im.methodId,
extra: {}
}
try {
inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty, (err,result) => {
if (err) {
console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err));
inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, {
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}, (err,result) => {
if (err !== undefined) {
console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to switchCurrentInputMethodAndSubtype.(callback)');
console.info('Succeeded in switching currentInputMethodAndSubtype.');
} else {
console.error('Failed to switchCurrentInputMethodAndSubtype.(callback)');
console.error('Failed to switchCurrentInputMethodAndSubtype.');
}
});
} catch (err) {
console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err));
console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
}
```
......@@ -415,7 +431,7 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp
Switches to a specified subtype of a specified input method. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -439,39 +455,41 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
let im = inputMethod.getCurrentInputMethod();
let inputMethodProperty = {
packageName: "com.example.kikakeyboard",
methodId: "ServiceExtAbility",
extra: {}
}
let inputMethodSubProperty = {
id: "com.example.kikakeyboard",
label: "ServiceExtAbility",
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
packageName: im.packageName,
methodId: im.methodId,
name: im.packageName,
id: im.methodId,
extra: {}
}
try {
inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty).then((result) => {
inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, {
id: im.packageName,
label: im.methodId,
name: "",
mode: "upper",
locale: "",
language: "",
icon: "",
iconId: 0,
extra: {}
}).then((result) => {
if (result) {
console.info('Success to switchCurrentInputMethodAndSubtype.');
console.info('Succeeded in switching currentInputMethodAndSubtype.');
} else {
console.error('Failed to switchCurrentInputMethodAndSubtype.');
}
}).catch((err) => {
console.error('switchCurrentInputMethodAndSubtype err: ' + err);
console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
})
} catch(err) {
console.error('switchCurrentInputMethodAndSubtype err: ' + err);
console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
}
```
......@@ -548,25 +566,25 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800003 | Input method client error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
try {
inputMethodController.stopInputSession((error, result) => {
if (error) {
console.error('stopInputSession err: ' + JSON.stringify(error));
if (error !== undefined) {
console.error('Failed to stopInputSession: ' + JSON.stringify(error));
return;
}
if (result) {
console.info('Success to stopInputSession.(callback)');
console.info('Succeeded in stopping inputSession.');
} else {
console.error('Failed to stopInputSession.(callback)');
console.error('Failed to stopInputSession.');
}
});
} catch(error) {
console.error('stopInputSession err: ' + JSON.stringify(error));
console.error('Failed to stopInputSession: ' + JSON.stringify(error));
}
```
......@@ -591,7 +609,7 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800003 | Input method client error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
......@@ -599,15 +617,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
try {
inputMethodController.stopInputSession().then((result) => {
if (result) {
console.info('Success to stopInputSession.');
console.info('Succeeded in stopping inputSession.');
} else {
console.error('Failed to stopInputSession.');
}
}).catch((err) => {
console.error('stopInputSession err: ' + JSON.stringify(err));
console.error('Failed to stopInputSession: ' + JSON.stringify(err));
})
} catch(err) {
console.error('stopInputSession err: ' + JSON.stringify(err));
console.error('Failed to stopInputSession: ' + JSON.stringify(err));
}
```
......@@ -617,7 +635,7 @@ showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
Shows this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -634,16 +652,16 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800003 | Input method client error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
inputMethodController.showSoftKeyboard((err) => {
if (err === undefined) {
console.info('showSoftKeyboard success');
console.info('Succeeded in showing softKeyboard.');
} else {
console.error('showSoftKeyboard failed because : ' + JSON.stringify(err));
console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err));
}
})
```
......@@ -654,7 +672,7 @@ showSoftKeyboard(): Promise&lt;void&gt;
Shows this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -671,15 +689,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800003 | Input method client error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
inputMethodController.showSoftKeyboard().then(async (err) => {
console.log('showSoftKeyboard success');
inputMethodController.showSoftKeyboard().then(() => {
console.log('Succeeded in showing softKeyboard.');
}).catch((err) => {
console.error('showSoftKeyboard err: ' + JSON.stringify(err));
console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err));
});
```
......@@ -689,7 +707,7 @@ hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
Hides this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -706,16 +724,16 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800003 | Input method client error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
inputMethodController.hideSoftKeyboard((err) => {
if (err === undefined) {
console.info('hideSoftKeyboard success');
console.info('Succeeded in hiding softKeyboard.');
} else {
console.error('hideSoftKeyboard failed because : ' + JSON.stringify(err));
console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err));
}
})
```
......@@ -726,7 +744,7 @@ hideSoftKeyboard(): Promise&lt;void&gt;
Hides this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -743,15 +761,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800003 | Input method client error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
inputMethodController.hideSoftKeyboard().then(async (err) => {
console.log('hideSoftKeyboard success');
inputMethodController.hideSoftKeyboard().then(() => {
console.log('Succeeded in hiding softKeyboard.');
}).catch((err) => {
console.error('hideSoftKeyboard err: ' + JSON.stringify(err));
console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err));
});
```
......@@ -777,14 +795,14 @@ Ends this input session. The invoking of this API takes effect only after the in
```js
inputMethodController.stopInput((error, result) => {
if (error) {
console.error('failed to stopInput because: ' + JSON.stringify(error));
if (error !== undefined) {
console.error('Failed to stopInput: ' + JSON.stringify(error));
return;
}
if (result) {
console.info('Success to stopInput.(callback)');
console.info('Succeeded in stopping input.');
} else {
console.error('Failed to stopInput.(callback)');
console.error('Failed to stopInput.');
}
});
```
......@@ -812,12 +830,12 @@ Ends this input session. The invoking of this API takes effect only after the in
```js
inputMethodController.stopInput().then((result) => {
if (result) {
console.info('Success to stopInput.');
console.info('Succeeded in stopping input.');
} else {
console.error('Failed to stopInput.');
}
}).catch((err) => {
console.error('stopInput err: ' + err);
console.error('Failed to stopInput: ' + err);
})
```
......@@ -891,26 +909,28 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800001 | Package manager error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
let inputMethodProperty = {
packageName:'com.example.kikakeyboard',
methodId:'com.example.kikakeyboard',
packageName: 'com.example.kikakeyboard',
methodId: 'com.example.kikakeyboard',
name: 'com.example.kikakeyboard',
id: 'com.example.kikakeyboard',
extra:{}
}
try {
inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => {
if (err) {
console.error('listInputMethodSubtype failed: ' + JSON.stringify(err));
if (err !== undefined) {
console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
return;
}
console.log('listInputMethodSubtype success');
console.log('Succeeded in listing inputMethodSubtype.');
});
} catch (err) {
console.error('listInputMethodSubtype failed: ' + JSON.stringify(err));
console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
}
```
......@@ -941,24 +961,26 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800001 | Package manager error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
let inputMethodProperty = {
packageName:'com.example.kikakeyboard',
methodId:'com.example.kikakeyboard',
packageName: 'com.example.kikakeyboard',
methodId: 'com.example.kikakeyboard',
name: 'com.example.kikakeyboard',
id: 'com.example.kikakeyboard',
extra:{}
}
try {
inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => {
console.info('listInputMethodSubtype success');
console.info('Succeeded in listing inputMethodSubtype.');
}).catch((err) => {
console.error('listInputMethodSubtype err: ' + JSON.stringify(err));
console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
})
} catch(err) {
console.error('listInputMethodSubtype err: ' + JSON.stringify(err));
console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
}
```
......@@ -983,21 +1005,21 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800001 | Package manager error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
try {
inputMethodSetting.listCurrentInputMethodSubtype((err, data) => {
if (err) {
console.error('listCurrentInputMethodSubtype failed: ' + JSON.stringify(err));
if (err !== undefined) {
console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
return;
}
console.log('listCurrentInputMethodSubtype success');
console.log('Succeeded in listing currentInputMethodSubtype.');
});
} catch(err) {
console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err));
console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
}
```
......@@ -1022,19 +1044,19 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800001 | Package manager error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
try {
inputMethodSetting.listCurrentInputMethodSubtype().then((data) => {
console.info('listCurrentInputMethodSubtype success');
console.info('Succeeded in listing currentInputMethodSubtype.');
}).catch((err) => {
console.error('listCurrentInputMethodSubtype err: ' + err);
console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
})
} catch(err) {
console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err));
console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
}
```
......@@ -1060,21 +1082,21 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800001 | Package manager error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
try {
inputMethodSetting.getInputMethods(true, (err,data) => {
if (err) {
console.error('getInputMethods failed: ' + JSON.stringify(err));
if (err !== undefined) {
console.error('Failed to getInputMethods: ' + JSON.stringify(err));
return;
}
console.log('getInputMethods success');
console.log('Succeeded in getting inputMethods.');
});
} catch (err) {
console.error('getInputMethods failed: ' + JSON.stringify(err));
console.error('Failed to getInputMethods: ' + JSON.stringify(err));
}
```
......@@ -1099,7 +1121,7 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800001 | Package manager error. |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Return value**
......@@ -1112,12 +1134,12 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
try {
inputMethodSetting.getInputMethods(true).then((data) => {
console.info('getInputMethods success');
console.info('Succeeded in getting inputMethods.');
}).catch((err) => {
console.error('getInputMethods err: ' + JSON.stringify(err));
console.error('Failed to getInputMethods: ' + JSON.stringify(err));
})
} catch(err) {
console.error('getInputMethods err: ' + JSON.stringify(err));
console.error('Failed to getInputMethods: ' + JSON.stringify(err));
}
```
......@@ -1127,7 +1149,7 @@ showOptionalInputMethods(callback: AsyncCallback&lt;boolean&gt;): void
Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -1143,21 +1165,21 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
try {
inputMethodSetting.showOptionalInputMethods((err, data) => {
if (err) {
console.error('showOptionalInputMethods failed: ' + JSON.stringify(err));
if (err !== undefined) {
console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
return;
}
console.info('showOptionalInputMethods success');
console.info('Succeeded in showing optionalInputMethods.');
});
} catch (err) {
console.error('showOptionalInputMethods failed: ' + JSON.stringify(err));
console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
}
```
......@@ -1167,7 +1189,7 @@ showOptionalInputMethods(): Promise&lt;boolean&gt;
Displays a dialog box for selecting an input method. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -1183,15 +1205,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
| Error Code ID| Error Message |
| -------- | -------------------------------------- |
| 12800008 | Input method settings extension error. |
| 12800008 | Input method manager service error. |
**Example**
```js
inputMethodSetting.showOptionalInputMethods().then((data) => {
console.info('displayOptionalInputMethod success.');
console.info('Succeeded in showing optionalInputMethods.');
}).catch((err) => {
console.error('displayOptionalInputMethod err: ' + err);
console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
})
```
......@@ -1217,11 +1239,11 @@ Obtains a list of installed input methods. This API uses an asynchronous callbac
```js
inputMethodSetting.listInputMethod((err,data) => {
if (err) {
console.error('listInputMethod failed because: ' + JSON.stringify(err));
if (err !== undefined) {
console.error('Failed to listInputMethod: ' + JSON.stringify(err));
return;
}
console.log('listInputMethod success');
console.log('Succeeded in listing inputMethod.');
});
```
......@@ -1247,9 +1269,9 @@ Obtains a list of installed input methods. This API uses a promise to return the
```js
inputMethodSetting.listInputMethod().then((data) => {
console.info('listInputMethod success');
console.info('Succeeded in listing inputMethod.');
}).catch((err) => {
console.error('listInputMethod err: ' + JSON.stringify(err));
console.error('Failed to listInputMethod: ' + JSON.stringify(err));
})
```
......@@ -1275,11 +1297,11 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono
```js
inputMethodSetting.displayOptionalInputMethod((err) => {
if (err) {
console.error('displayOptionalInputMethod failed because: ' + JSON.stringify(err));
if (err !== undefined) {
console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
return;
}
console.info('displayOptionalInputMethod success');
console.info('Succeeded in displaying optionalInputMethod.');
});
```
......@@ -1305,8 +1327,8 @@ Displays a dialog box for selecting an input method. This API uses a promise to
```js
inputMethodSetting.displayOptionalInputMethod().then(() => {
console.info('displayOptionalInputMethod success');
console.info('Succeeded in displaying optionalInputMethod.');
}).catch((err) => {
console.error('displayOptionalInputMethod err: ' + err);
console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
})
```
# Input Method Engine
# @ohos.inputmethodengine
The **inputMethodEngine** module streamlines the interaction between input methods and applications. By calling APIs of this module, applications can be bound to input method services to accept text input through the input methods, request the keyboard to display or hide, listen for the input method status, and much more.
......@@ -137,7 +137,7 @@ Obtains a **KeyboardDelegate** instance.
**Example**
```js
let KeyboardDelegate = inputMethodEngine.createKeyboardDelegate();
let keyboardDelegate = inputMethodEngine.createKeyboardDelegate();
```
## InputMethodEngine
......@@ -162,9 +162,9 @@ Enables listening for the input method binding event. This API uses an asynchron
**Example**
```js
inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textInputClient) => {
KeyboardController = kbController;
TextInputClient = textInputClient;
inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => {
let keyboardController = kbController;
let textInputClient = textClient;
});
```
......@@ -229,18 +229,14 @@ Disables listening for a keyboard event. This API uses an asynchronous callback
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event. |
| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.|
| callback | () => void | No | Callback used to return the result.|
**Example**
```js
inputMethodEngine.getInputMethodEngine().off('keyboardShow', () => {
console.log('inputMethodEngine delete keyboardShow notification.');
});
inputMethodEngine.getInputMethodEngine().off('keyboardHide', () => {
console.log('inputMethodEngine delete keyboardHide notification.');
});
inputMethodEngine.getInputMethodEngine().off('keyboardShow');
inputMethodEngine.getInputMethodEngine().off('keyboardHide');
```
## InputMethodAbility
......@@ -265,9 +261,9 @@ Enables listening for the input method binding event. This API uses an asynchron
**Example**
```js
inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, inputClient) => {
KeyboardController = kbController;
InputClient = inputClient;
inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => {
let keyboardController = kbController;
let inputClient = client;
});
```
......@@ -289,9 +285,7 @@ Cancels listening for the input method binding event. This API uses an asynchron
**Example**
```js
inputMethodEngine.getInputMethodAbility().off('inputStart', (kbController, inputClient) => {
console.log('delete inputStart notification.');
});
inputMethodEngine.getInputMethodAbility().off('inputStart');
```
### on('inputStop')<sup>9+</sup>
......@@ -390,7 +384,7 @@ inputMethodEngine.getInputMethodAbility().off('setCallingWindow', () => {
on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
Enables listening for an input method event. This API uses an asynchronous callback to return the result.
Enables listening for a keyboard event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -398,7 +392,7 @@ Enables listening for an input method event. This API uses an asynchronous callb
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event. |
| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.|
| callback | () => void | Yes | Callback used to return the result. |
**Example**
......@@ -416,7 +410,7 @@ inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => {
off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
Disables listening for an input method event. This API uses an asynchronous callback to return the result.
Disables listening for a keyboard event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.InputMethodFramework
......@@ -602,14 +596,14 @@ Enables listening for the text selection change event. This API uses an asynchro
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>The value **'selectionChange'** indicates the text selection change event.|
| callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | Yes | Callback used to return the text selection information.<br>- **oldBegin**: start of the selected text before the change.<br>- **oldEnd**: end of the selected text before the change.<br>- **newBegin**: start of the selected text after the change.<br>- **newEnd**: end of the selected text after the change.|
**Example**
**Example**
```js
inputMethodEngine.getKeyboardDelegate().on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
......@@ -652,14 +646,14 @@ Enables listening for the text change event. This API uses an asynchronous callb
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>The value **'textChange'** indicates the text change event.|
| callback | (text: string) => void | Yes | Callback used to return the text content. |
**Example**
**Example**
```js
inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => {
......@@ -719,12 +713,12 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
**Example**
```js
KeyboardController.hide((err) => {
if (err === undefined) {
console.error('hide err: ' + JSON.stringify(err));
keyboardController.hide((err) => {
if (err !== undefined) {
console.error('Failed to hide keyboard: ' + JSON.stringify(err));
return;
}
console.log('hide success.');
console.log('Succeeded in hiding keyboard.');
});
```
......@@ -753,10 +747,10 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
**Example**
```js
KeyboardController.hide().then(() => {
console.info('hide success.');
keyboardController.hide().then(() => {
console.info('Succeeded in hiding keyboard.');
}).catch((err) => {
console.info('hide err: ' + JSON.stringify(err));
console.info('Failed to hide keyboard: ' + JSON.stringify(err));
});
```
......@@ -781,12 +775,12 @@ Hides the keyboard. This API uses an asynchronous callback to return the result.
**Example**
```js
KeyboardController.hideKeyboard((err) => {
if (err === undefined) {
console.error('hideKeyboard err: ' + JSON.stringify(err));
keyboardController.hideKeyboard((err) => {
if (err !== undefined) {
console.error('Failed to hide Keyboard: ' + JSON.stringify(err));
return;
}
console.log('hideKeyboard success.');
console.log('Succeeded in hiding keyboard.');
});
```
......@@ -811,10 +805,10 @@ Hides the keyboard. This API uses a promise to return the result.
**Example**
```js
KeyboardController.hideKeyboard().then(() => {
console.info('hideKeyboard success.');
keyboardController.hideKeyboard().then(() => {
console.info('Succeeded in hiding keyboard.');
}).catch((err) => {
console.info('hideKeyboard err: ' + JSON.stringify(err));
console.info('Failed to hide Keyboard: ' + JSON.stringify(err));
});
```
......@@ -850,13 +844,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
let action = 1;
try {
InputClient.sendKeyFunction(action, (err, result) => {
if (err) {
console.error('sendKeyFunction err: ' + JSON.stringify(err));
inputClient.sendKeyFunction(action, (err, result) => {
if (err !== undefined) {
console.error('Failed to sendKeyFunction: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to sendKeyFunction. ');
console.info('Succeeded in sending key function. ');
} else {
console.error('Failed to sendKeyFunction. ');
}
......@@ -899,17 +893,17 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
let action = 1;
try {
InputClient.sendKeyFunction(action).then((result) => {
inputClient.sendKeyFunction(action).then((result) => {
if (result) {
console.info('Success to sendKeyFunction. ');
console.info('Succeeded in sending key function. ');
} else {
console.error('Failed to sendKeyFunction. ');
}
}).catch((err) => {
console.error('sendKeyFunction err:' + JSON.stringify(err));
console.error('Failed to sendKeyFunction:' + JSON.stringify(err));
});
} catch (err) {
console.error('sendKeyFunction err: ' + JSON.stringify(err));
console.error('Failed to sendKeyFunction: ' + JSON.stringify(err));
}
```
......@@ -942,15 +936,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
let length = 1;
try {
InputClient.getForward(length, (err, text) => {
if (err) {
console.error('getForward err: ' + JSON.stringify(err));
inputClient.getForward(length, (err, text) => {
if (err !== undefined) {
console.error('Failed to getForward: ' + JSON.stringify(err));
return;
}
console.log('getForward result: ' + text);
console.log('Succeeded in getting forward, text: ' + text);
});
} catch (err) {
console.error('getForward err: ' + JSON.stringify(err));
console.error('Failed to getForward: ' + JSON.stringify(err));
}
```
......@@ -988,13 +982,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
let length = 1;
try {
InputClient.getForward(length).then((text) => {
console.info('getForward resul: ' + text);
inputClient.getForward(length).then((text) => {
console.info('Succeeded in getting forward, text: ' + text);
}).catch((err) => {
console.error('getForward err: ' + JSON.stringify(err));
console.error('Failed to getForward: ' + JSON.stringify(err));
});
} catch (err) {
console.error('getForward err: ' + JSON.stringify(err));
console.error('Failed to getForward: ' + JSON.stringify(err));
}
```
......@@ -1027,15 +1021,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
let length = 1;
try {
InputClient.getBackward(length, (err, text) => {
if (err) {
console.error('getBackward result: ' + JSON.stringify(err));
inputClient.getBackward(length, (err, text) => {
if (err !== undefined) {
console.error('Failed to getForward: ' + JSON.stringify(err));
return;
}
console.log('getBackward result---text: ' + text);
console.log('Succeeded in getting backward, text: ' + text);
});
} catch (err) {
console.error('getBackward result: ' + JSON.stringify(err));
console.error('Failed to getForward: ' + JSON.stringify(err));
}
```
......@@ -1073,13 +1067,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
let length = 1;
try {
InputClient.getBackward(length).then((text) => {
console.info('getBackward result: ' + text);
inputClient.getBackward(length).then((text) => {
console.info('Succeeded in getting backward, text: ' + text);
}).catch((err) => {
console.error('getBackward err: ' + JSON.stringify(err));
console.error('Failed to getForward: ' + JSON.stringify(err));
});
} catch (err) {
console.error('getBackward err: ' + JSON.stringify(err));
console.error('Failed to getForward: ' + JSON.stringify(err));
}
```
......@@ -1112,19 +1106,19 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
let length = 1;
try {
InputClient.deleteForward(length, (err, result) => {
if (err) {
console.error('deleteForward result: ' + JSON.stringify(err));
inputClient.deleteForward(length, (err, result) => {
if (err !== undefined) {
console.error('Failed to delete forward: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to deleteForward. ');
console.info('Succeeded in deleting forward. ');
} else {
console.error('Failed to deleteForward. ');
console.error('Failed to delete forward: ' + JSON.stringify(err));
}
});
} catch (err) {
console.error('deleteForward result: ' + JSON.stringify(err));
console.error('Failed to delete forward: ' + JSON.stringify(err));
}
```
......@@ -1162,17 +1156,17 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
let length = 1;
try {
InputClient.deleteForward(length).then((result) => {
inputClient.deleteForward(length).then((result) => {
if (result) {
console.info('Success to deleteForward. ');
console.info('Succeeded in deleting forward. ');
} else {
console.error('Failed to deleteForward. ');
console.error('Failed to delete Forward. ');
}
}).catch((err) => {
console.error('deleteForward err: ' + JSON.stringify(err));
console.error('Failed to delete Forward: ' + JSON.stringify(err));
});
} catch (err) {
console.error('deleteForward err: ' + JSON.stringify(err));
console.error('Failed to delete Forward: ' + JSON.stringify(err));
}
```
......@@ -1205,15 +1199,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
let length = 1;
try {
InputClient.deleteBackward(length, (err, result) => {
if (err) {
console.error('deleteBackward err: ' + JSON.stringify(err));
inputClient.deleteBackward(length, (err, result) => {
if (err !== undefined) {
console.error('Failed to delete Backward: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to deleteBackward. ');
console.info('Succeeded in deleting backward. ');
} else {
console.error('Failed to deleteBackward. ');
console.error('Failed to delete Backward: ' + JSON.stringify(err));
}
});
} catch (err) {
......@@ -1254,14 +1248,14 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
let length = 1;
InputClient.deleteBackward(length).then((result) => {
inputClient.deleteBackward(length).then((result) => {
if (result) {
console.info('Success to deleteBackward. ');
console.info('Succeeded in deleting backward. ');
} else {
console.error('Failed to deleteBackward. ');
}
}).catch((err) => {
console.error('deleteBackward err: ' + JSON.stringify(err));
console.error('Failed to deleteBackward: ' + JSON.stringify(err));
});
```
......@@ -1292,13 +1286,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
**Example**
```js
InputClient.insertText('test', (err, result) => {
if (err) {
console.error('insertText err: ' + JSON.stringify(err));
inputClient.insertText('test', (err, result) => {
if (err !== undefined) {
console.error('Failed to insertText: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to insertText. ');
console.info('Succeeded in inserting text. ');
} else {
console.error('Failed to insertText. ');
}
......@@ -1338,17 +1332,17 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
try {
InputClient.insertText('test').then((result) => {
inputClient.insertText('test').then((result) => {
if (result) {
console.info('Success to insertText. ');
console.info('Succeeded in inserting text. ');
} else {
console.error('Failed to insertText. ');
}
}).catch((err) => {
console.error('insertText err: ' + JSON.stringify(err));
console.error('Failed to insertText: ' + JSON.stringify(err));
});
} catch (err) {
console.error('insertText err: ' + JSON.stringify(err));
console.error('Failed to insertText: ' + JSON.stringify(err));
}
```
......@@ -1377,9 +1371,9 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
**Example**
```js
InputClient.getEditorAttribute((err, editorAttribute) => {
if (err) {
console.error('getEditorAttribute err: ' + JSON.stringify(err));
inputClient.getEditorAttribute((err, editorAttribute) => {
if (err !== undefined) {
console.error('Failed to getEditorAttribute: ' + JSON.stringify(err));
return;
}
console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
......@@ -1412,11 +1406,11 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
**Example**
```js
InputClient.getEditorAttribute().then((editorAttribute) => {
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));
console.error('Failed to getEditorAttribute: ' + JSON.stringify(err));
});
```
......@@ -1447,15 +1441,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
try {
InputClient.moveCursor(inputMethodEngine.CURSOR_xxx, (err) => {
if (err) {
console.error('moveCursor err: ' + JSON.stringify(err));
inputClient.moveCursor(inputMethodEngine.CURSOR_UP, (err) => {
if (err !== undefined) {
console.error('Failed to moveCursor: ' + JSON.stringify(err));
return;
}
console.info('moveCursor success');
console.info('Succeeded in moving cursor.');
});
} catch (err) {
console.error('moveCursor err: ' + JSON.stringify(err));
console.error('Failed to moveCursor: ' + JSON.stringify(err));
}
```
......@@ -1491,13 +1485,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e
```js
try {
InputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => {
console.log('moveCursor success');
inputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => {
console.log('Succeeded in moving cursor.');
}).catch((err) => {
console.error('moveCursor success err: ' + JSON.stringify(err));
console.error('Failed to moveCursor: ' + JSON.stringify(err));
});
} catch (err) {
console.log('moveCursor err: ' + JSON.stringify(err));
console.log('Failed to moveCursor: ' + JSON.stringify(err));
}
```
......@@ -1554,12 +1548,12 @@ Obtains the specific-length text before the cursor. This API uses an asynchronou
```js
let length = 1;
TextInputClient.getForward(length, (err, text) => {
if (err === undefined) {
console.error('getForward err: ' + JSON.stringify(err));
textInputClient.getForward(length, (err, text) => {
if (err !== undefined) {
console.error('Failed to getForward: ' + JSON.stringify(err));
return;
}
console.log('getForward result---text: ' + text);
console.log('Succeeded in getting forward, text: ' + text);
});
```
......@@ -1591,10 +1585,10 @@ Obtains the specific-length text before the cursor. This API uses a promise to r
```js
let length = 1;
TextInputClient.getForward(length).then((text) => {
console.info('getForward result: ' + JSON.stringify(text));
textInputClient.getForward(length).then((text) => {
console.info('Succeeded in getting forward, text: ' + text);
}).catch((err) => {
console.error('getForward err: ' + JSON.stringify(err));
console.error('Failed to getForward: ' + JSON.stringify(err));
});
```
......@@ -1621,12 +1615,12 @@ Obtains the specific-length text after the cursor. This API uses an asynchronous
```js
let length = 1;
TextInputClient.getBackward(length, (err, text) => {
if (err === undefined) {
console.error('getBackward err: ' + JSON.stringify(err));
textInputClient.getBackward(length, (err, text) => {
if (err !== undefined) {
console.error('Failed to getBackward: ' + JSON.stringify(err));
return;
}
console.log('getBackward result---text: ' + text);
console.log('Succeeded in getting borward, text: ' + text);
});
```
......@@ -1658,10 +1652,10 @@ Obtains the specific-length text after the cursor. This API uses a promise to re
```js
let length = 1;
TextInputClient.getBackward(length).then((text) => {
console.info('getBackward result: ' + JSON.stringify(text));
textInputClient.getBackward(length).then((text) => {
console.info('Succeeded in getting backward: ' + JSON.stringify(text));
}).catch((err) => {
console.error('getBackward err: ' + JSON.stringify(err));
console.error('Failed to getBackward: ' + JSON.stringify(err));
});
```
......@@ -1688,13 +1682,13 @@ Deletes the fixed-length text before the cursor. This API uses an asynchronous c
```js
let length = 1;
TextInputClient.deleteForward(length, (err, result) => {
if (err === undefined) {
console.error('deleteForward err: ' + JSON.stringify(err));
textInputClient.deleteForward(length, (err, result) => {
if (err !== undefined) {
console.error('Failed to deleteForward: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to deleteForward. ');
console.info('Succeeded in deleting forward. ');
} else {
console.error('Failed to deleteForward. ');
}
......@@ -1729,14 +1723,14 @@ Deletes the fixed-length text before the cursor. This API uses a promise to retu
```js
let length = 1;
TextInputClient.deleteForward(length).then((result) => {
textInputClient.deleteForward(length).then((result) => {
if (result) {
console.info('Succeed in deleting forward. ');
console.info('Succeeded in deleting forward. ');
} else {
console.error('Failed to delete forward. ');
}
}).catch((err) => {
console.error('Failed to delete forward err: ' + JSON.stringify(err));
console.error('Failed to delete forward: ' + JSON.stringify(err));
});
```
......@@ -1763,13 +1757,13 @@ Deletes the fixed-length text after the cursor. This API uses an asynchronous ca
```js
let length = 1;
TextInputClient.deleteBackward(length, (err, result) => {
if (err === undefined) {
console.error('deleteBackward err: ' + JSON.stringify(err));
textInputClient.deleteBackward(length, (err, result) => {
if (err !== undefined) {
console.error('Failed to delete backward: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to deleteBackward. ');
console.info('Succeeded in deleting backward. ');
} else {
console.error('Failed to deleteBackward. ');
}
......@@ -1804,14 +1798,14 @@ Deletes the fixed-length text after the cursor. This API uses an asynchronous ca
```js
let length = 1;
TextInputClient.deleteBackward(length).then((result) => {
textInputClient.deleteBackward(length).then((result) => {
if (result) {
console.info('Success to deleteBackward. ');
console.info('Succeeded in deleting backward. ');
} else {
console.error('Failed to deleteBackward. ');
}
}).catch((err) => {
console.error('deleteBackward err: ' + JSON.stringify(err));
console.error('Failed to deleteBackward: ' + JSON.stringify(err));
});
```
### sendKeyFunction<sup>(deprecated)</sup>
......@@ -1837,13 +1831,13 @@ Sends the function key. This API uses an asynchronous callback to return the res
```js
let action = 1;
TextInputClient.sendKeyFunction(action, (err, result) => {
if (err === undefined) {
console.error('sendKeyFunction err: ' + JSON.stringify(err));
textInputClient.sendKeyFunction(action, (err, result) => {
if (err !== undefined) {
console.error('Failed to sendKeyFunction: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to sendKeyFunction. ');
console.info('Succeeded in sending key function. ');
} else {
console.error('Failed to sendKeyFunction. ');
}
......@@ -1878,14 +1872,14 @@ Sends the function key. This API uses a promise to return the result.
```js
let action = 1;
TextInputClient.sendKeyFunction(action).then((result) => {
textInputClient.sendKeyFunction(action).then((result) => {
if (result) {
console.info('Success to sendKeyFunction. ');
console.info('Succeeded in sending key function. ');
} else {
console.error('Failed to sendKeyFunction. ');
}
}).catch((err) => {
console.error('sendKeyFunction err:' + JSON.stringify(err));
console.error('Failed to sendKeyFunction:' + JSON.stringify(err));
});
```
......@@ -1911,13 +1905,13 @@ Inserts text. This API uses an asynchronous callback to return the result.
**Example**
```js
TextInputClient.insertText('test', (err, result) => {
if (err === undefined) {
console.error('insertText err: ' + JSON.stringify(err));
textInputClient.insertText('test', (err, result) => {
if (err !== undefined) {
console.error('Failed to insertText: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Success to insertText. ');
console.info('Succeeded in inserting text. ');
} else {
console.error('Failed to insertText. ');
}
......@@ -1951,14 +1945,14 @@ Inserts text. This API uses a promise to return the result.
**Example**
```js
TextInputClient.insertText('test').then((result) => {
textInputClient.insertText('test').then((result) => {
if (result) {
console.info('Success to insertText. ');
console.info('Succeeded in inserting text. ');
} else {
console.error('Failed to insertText. ');
}
}).catch((err) => {
console.error('insertText err: ' + JSON.stringify(err));
console.error('Failed to insertText: ' + JSON.stringify(err));
});
```
......@@ -1983,9 +1977,9 @@ Obtains the attribute of the edit box. This API uses an asynchronous callback to
**Example**
```js
TextInputClient.getEditorAttribute((err, editorAttribute) => {
if (err === undefined) {
console.error('getEditorAttribute err: ' + JSON.stringify(err));
textInputClient.getEditorAttribute((err, editorAttribute) => {
if (err !== undefined) {
console.error('Failed to getEditorAttribute: ' + JSON.stringify(err));
return;
}
console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
......@@ -2014,10 +2008,10 @@ Obtains the attribute of the edit box. This API uses a promise to return the res
**Example**
```js
TextInputClient.getEditorAttribute().then((editorAttribute) => {
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));
console.error('Failed to getEditorAttribute: ' + JSON.stringify(err));
});
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册