提交 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
**示例:**
```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) {
console.log("switchInputMethod err: " + JSON.stringify(err));
console.error("switchInputMethod err: " + JSON.stringify(err));
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>
......@@ -124,18 +128,15 @@ switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt;
```js
async function InputMethod() {
await inputMethod.switchInputMethod({packageName:"com.example.kikakeyboard",
methodId:"com.example.kikakeyboard"}).then((result) => {
if (result) {
console.info("Success to switchInputMethod.(promise)");
} else {
console.info("Failed to switchInputMethod.(promise)");
}
}).catch((err) => {
console.info("switchInputMethod promise err: " + err);
});
}
inputMethod.switchInputMethod({packageName:"com.example.kikakeyboard", methodId:"com.example.kikakeyboard"}).then((result) => {
if (result) {
console.info("Success to switchInputMethod.(promise)");
} else {
console.error("Failed to switchInputMethod.(promise)");
}
}).catch((err) => {
console.error("switchInputMethod promise err: " + err);
})
```
## InputMethodController
......@@ -158,12 +159,16 @@ stopInput(callback: AsyncCallback&lt;boolean&gt;): void
**示例:**
```js
InputMethodController.stopInput((error, data) => {
InputMethodController.stopInput((error, result) => {
if (error) {
console.error("failed to stopInput because: " + JSON.stringify(error));
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;
```js
async function InputMethod() {
await InputMethodController.stopInput().then((result)=>{
if (result) {
console.info("Success to stopInput.(promise)");
} else {
console.info("Failed to stopInput.(promise)");
}
}).catch((err) => {
console.error("stopInput promise err: " + err);
});
}
InputMethodController.stopInput().then((result) => {
if (result) {
console.info("Success to stopInput.(promise)");
} else {
console.error("Failed to stopInput.(promise)");
}
}).catch((err) => {
console.error("stopInput promise err: " + err);
})
```
### showSoftKeyboard<sup>9+</sup> ###
......@@ -217,9 +220,9 @@ showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
```js
InputMethodController.showSoftKeyboard((err) => {
if (err == undefined) {
console.error('showSoftKeyboard success');
console.info('showSoftKeyboard success');
} 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;
InputMethodController.showSoftKeyboard().then(async (err) => {
console.log('showSoftKeyboard success');
}).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
```js
InputMethodController.hideSoftKeyboard((err) => {
if (err == undefined) {
console.error('hideSoftKeyboard success');
console.info('hideSoftKeyboard success');
} 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;
InputMethodController.hideSoftKeyboard().then(async (err) => {
console.log('hideSoftKeyboard success');
}).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;)
```js
imeList: Array<inputMethod.InputMethodProperty> = null
InputMethodSetting.listInputMethod((err,data) => {
if (err == undefined) {
console.error("fail to listInputMethod because: " + JSON.stringify(err));
if (err) {
console.error("listInputMethod failed because: " + JSON.stringify(err));
return;
}
console.log("success listInputMethod");
console.log("listInputMethod success");
this.imeList = data;
});
```
......@@ -348,14 +351,12 @@ listInputMethod(): Promise&lt;Array<InputMethodProperty>&gt;
```js
imeList: Array<inputMethod.InputMethodProperty> = null
async function InputMethod() {
await InputMethodSetting.listInputMethod().then((data)=>{
console.info("listInputMethod success");
this.imeList = data;
}).catch((err) => {
console.info("listInputMethod promise err:" + err);
});
}
InputMethodSetting.listInputMethod().then((data) => {
console.info("listInputMethod success");
this.imeList = data;
}).catch((err) => {
console.error("listInputMethod promise err: " + err);
})
```
### displayOptionalInputMethod
......@@ -376,11 +377,11 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
```js
InputMethodSetting.displayOptionalInputMethod((err) => {
if (err == undefined) {
console.error("failed to displayOptionalInputMethod because: " + JSON.stringify(err));
if (err) {
console.error("displayOptionalInputMethod failed because: " + JSON.stringify(err));
return;
}
console.info("success displayOptionalInputMethod");
console.info("displayOptionalInputMethod success");
});
```
......@@ -401,11 +402,9 @@ InputMethodSetting.displayOptionalInputMethod((err) => {
**示例:**
```js
async function InputMethod() {
await InputMethodSetting.displayOptionalInputMethod().then(()=>{
console.info("displayOptionalInputMethod promise");
}).catch((err) => {
console.info("displayOptionalInputMethod promise err: " + err);
});
}
InputMethodSetting.displayOptionalInputMethod().then(() => {
console.info("displayOptionalInputMethod success.(promise)");
}).catch((err) => {
console.error("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.
先完成此消息的编辑!
想要评论请 注册