提交 cd748d72 编写于 作者: Z zhaolinglan

modify example code

Signed-off-by: Nzhaolinglan <zhaolinglan@huawei.com>
上级 2a9be9dd
...@@ -94,12 +94,16 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolea ...@@ -94,12 +94,16 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolea
**示例:** **示例:**
```js ```js
inputMethod.switchInputMethod({packageName:"com.example.kikakeyboard", methodId:"com.example.kikakeyboard"} ,(err,data) => { inputMethod.switchInputMethod({packageName:"com.example.kikakeyboard", methodId:"com.example.kikakeyboard"} ,(err,result) => {
if (err) { if (err) {
console.log("switchInputMethod err: " + JSON.stringify(err)); console.error("switchInputMethod err: " + JSON.stringify(err));
return; return;
} }
console.log("switchInputMethod success result: " + data); if (result) {
console.info("Success to switchInputMethod.(callback)");
} else {
console.error("Failed to switchInputMethod.(callback)");
}
}); });
``` ```
## inputMethod.switchInputMethod<sup>9+</sup> ## inputMethod.switchInputMethod<sup>9+</sup>
...@@ -124,18 +128,15 @@ switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt; ...@@ -124,18 +128,15 @@ switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt;
```js ```js
async function InputMethod() { inputMethod.switchInputMethod({packageName:"com.example.kikakeyboard", methodId:"com.example.kikakeyboard"}).then((result) => {
await inputMethod.switchInputMethod({packageName:"com.example.kikakeyboard", if (result) {
methodId:"com.example.kikakeyboard"}).then((result) => { console.info("Success to switchInputMethod.(promise)");
if (result) { } else {
console.info("Success to switchInputMethod.(promise)"); console.error("Failed to switchInputMethod.(promise)");
} else { }
console.info("Failed to switchInputMethod.(promise)"); }).catch((err) => {
} console.error("switchInputMethod promise err: " + err);
}).catch((err) => { })
console.info("switchInputMethod promise err: " + err);
});
}
``` ```
## InputMethodController ## InputMethodController
...@@ -158,12 +159,16 @@ stopInput(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -158,12 +159,16 @@ stopInput(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```js
InputMethodController.stopInput((error, data) => { InputMethodController.stopInput((error, result) => {
if (error) { if (error) {
console.error("failed to stopInput because: " + JSON.stringify(error)); console.error("failed to stopInput because: " + JSON.stringify(error));
return; return;
} }
console.info("success stopInput: " + JSON.stringify(data)); if (result) {
console.info("Success to stopInput.(callback)");
} else {
console.error("Failed to stopInput.(callback)");
}
}); });
``` ```
...@@ -185,17 +190,15 @@ stopInput(): Promise&lt;boolean&gt; ...@@ -185,17 +190,15 @@ stopInput(): Promise&lt;boolean&gt;
```js ```js
async function InputMethod() { InputMethodController.stopInput().then((result) => {
await InputMethodController.stopInput().then((result)=>{ if (result) {
if (result) { console.info("Success to stopInput.(promise)");
console.info("Success to stopInput.(promise)"); } else {
} else { console.error("Failed to stopInput.(promise)");
console.info("Failed to stopInput.(promise)"); }
} }).catch((err) => {
}).catch((err) => { console.error("stopInput promise err: " + err);
console.error("stopInput promise err: " + err); })
});
}
``` ```
### showSoftKeyboard<sup>9+</sup> ### ### showSoftKeyboard<sup>9+</sup> ###
...@@ -217,9 +220,9 @@ showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void ...@@ -217,9 +220,9 @@ showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
```js ```js
InputMethodController.showSoftKeyboard((err) => { InputMethodController.showSoftKeyboard((err) => {
if (err == undefined) { if (err == undefined) {
console.error('showSoftKeyboard success'); console.info('showSoftKeyboard success');
} else { } else {
console.info('showSoftKeyboard failed : ' + JSON.stringify(err)); console.error('showSoftKeyboard failed because : ' + JSON.stringify(err));
} }
}) })
``` ```
...@@ -245,7 +248,7 @@ showSoftKeyboard(): Promise&lt;void&gt; ...@@ -245,7 +248,7 @@ showSoftKeyboard(): Promise&lt;void&gt;
InputMethodController.showSoftKeyboard().then(async (err) => { InputMethodController.showSoftKeyboard().then(async (err) => {
console.log('showSoftKeyboard success'); console.log('showSoftKeyboard success');
}).catch((err) => { }).catch((err) => {
console.log('showSoftKeyboard fail ' + JSON.stringify(err)); console.error('showSoftKeyboard promise err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -268,9 +271,9 @@ hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void ...@@ -268,9 +271,9 @@ hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
```js ```js
InputMethodController.hideSoftKeyboard((err) => { InputMethodController.hideSoftKeyboard((err) => {
if (err == undefined) { if (err == undefined) {
console.error('hideSoftKeyboard success'); console.info('hideSoftKeyboard success');
} else { } else {
console.info('hideSoftKeyboard failed : ' + JSON.stringify(err)); console.error('hideSoftKeyboard failed because : ' + JSON.stringify(err));
} }
}) })
``` ```
...@@ -296,7 +299,7 @@ hideSoftKeyboard(): Promise&lt;void&gt; ...@@ -296,7 +299,7 @@ hideSoftKeyboard(): Promise&lt;void&gt;
InputMethodController.hideSoftKeyboard().then(async (err) => { InputMethodController.hideSoftKeyboard().then(async (err) => {
console.log('hideSoftKeyboard success'); console.log('hideSoftKeyboard success');
}).catch((err) => { }).catch((err) => {
console.log('hideSoftKeyboard fail ' + JSON.stringify(err)); console.error('hideSoftKeyboard promise err: ' + JSON.stringify(err));
}); });
``` ```
...@@ -322,11 +325,11 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;) ...@@ -322,11 +325,11 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;)
```js ```js
imeList: Array<inputMethod.InputMethodProperty> = null imeList: Array<inputMethod.InputMethodProperty> = null
InputMethodSetting.listInputMethod((err,data) => { InputMethodSetting.listInputMethod((err,data) => {
if (err == undefined) { if (err) {
console.error("fail to listInputMethod because: " + JSON.stringify(err)); console.error("listInputMethod failed because: " + JSON.stringify(err));
return; return;
} }
console.log("success listInputMethod"); console.log("listInputMethod success");
this.imeList = data; this.imeList = data;
}); });
``` ```
...@@ -348,14 +351,12 @@ listInputMethod(): Promise&lt;Array<InputMethodProperty>&gt; ...@@ -348,14 +351,12 @@ listInputMethod(): Promise&lt;Array<InputMethodProperty>&gt;
```js ```js
imeList: Array<inputMethod.InputMethodProperty> = null imeList: Array<inputMethod.InputMethodProperty> = null
async function InputMethod() { InputMethodSetting.listInputMethod().then((data) => {
await InputMethodSetting.listInputMethod().then((data)=>{ console.info("listInputMethod success");
console.info("listInputMethod success"); this.imeList = data;
this.imeList = data; }).catch((err) => {
}).catch((err) => { console.error("listInputMethod promise err: " + err);
console.info("listInputMethod promise err:" + err); })
});
}
``` ```
### displayOptionalInputMethod ### displayOptionalInputMethod
...@@ -376,11 +377,11 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void ...@@ -376,11 +377,11 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
```js ```js
InputMethodSetting.displayOptionalInputMethod((err) => { InputMethodSetting.displayOptionalInputMethod((err) => {
if (err == undefined) { if (err) {
console.error("failed to displayOptionalInputMethod because: " + JSON.stringify(err)); console.error("displayOptionalInputMethod failed because: " + JSON.stringify(err));
return; return;
} }
console.info("success displayOptionalInputMethod"); console.info("displayOptionalInputMethod success");
}); });
``` ```
...@@ -401,11 +402,9 @@ InputMethodSetting.displayOptionalInputMethod((err) => { ...@@ -401,11 +402,9 @@ InputMethodSetting.displayOptionalInputMethod((err) => {
**示例:** **示例:**
```js ```js
async function InputMethod() { InputMethodSetting.displayOptionalInputMethod().then(() => {
await InputMethodSetting.displayOptionalInputMethod().then(()=>{ console.info("displayOptionalInputMethod success.(promise)");
console.info("displayOptionalInputMethod promise"); }).catch((err) => {
}).catch((err) => { console.error("displayOptionalInputMethod promise err: " + err);
console.info("displayOptionalInputMethod promise err: " + err); })
});
}
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册