提交 aa93b19c 编写于 作者: G guojin31

输入法示例代码ArkTs规范整改

Signed-off-by: Nguojin31 <guojin31@huawei.com>
上级 aa86c2ec
...@@ -61,13 +61,13 @@ ...@@ -61,13 +61,13 @@
export default class InputDemoService extends InputMethodExtensionAbility { export default class InputDemoService extends InputMethodExtensionAbility {
onCreate(want: Want) { onCreate(want: Want): void {
keyboardController.onCreate(this.context); // 初始化窗口并注册对输入法框架的事件监听 keyboardController.onCreate(this.context); // 初始化窗口并注册对输入法框架的事件监听
} }
onDestroy() { onDestroy(): void {
console.log("onDestroy."); console.log("onDestroy.");
this.keyboardController.onDestroy(); // 销毁窗口并去注册事件监听 keyboardController.onDestroy(); // 销毁窗口并去注册事件监听
} }
} }
``` ```
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
import display from '@ohos.display'; import display from '@ohos.display';
import inputMethodEngine from '@ohos.inputMethodEngine'; import inputMethodEngine from '@ohos.inputMethodEngine';
import InputMethodExtensionContext from '@ohos.inputMethodExtensionContext'; import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext';
// 调用输入法框架的getInputMethodAbility方法获取实例,并由此实例调用输入法框架功能接口 // 调用输入法框架的getInputMethodAbility方法获取实例,并由此实例调用输入法框架功能接口
const inputMethodAbility: inputMethodEngine.InputMethodAbility = inputMethodEngine.getInputMethodAbility(); const inputMethodAbility: inputMethodEngine.InputMethodAbility = inputMethodEngine.getInputMethodAbility();
...@@ -95,13 +95,13 @@ ...@@ -95,13 +95,13 @@
public onCreate(context: InputMethodExtensionContext): void public onCreate(context: InputMethodExtensionContext): void
{ {
this.mContext = context; this.mContext = context;
this.initWindow(); // 初始化窗口 this.initWindow(); // 初始化窗口
this.registerListener(); // 注册对输入法框架的事件监听 this.registerListener(); // 注册对输入法框架的事件监听
} }
public onDestroy(): void // 应用生命周期销毁 public onDestroy(): void // 应用生命周期销毁
{ {
this.unRegisterListener(); // 去注册事件监听 this.unRegisterListener(); // 去注册事件监听
if(this.panel) { // 销毁窗口 if(this.panel) { // 销毁窗口
this.panel.hide(); this.panel.hide();
inputMethodAbility.destroyPanel(this.panel); inputMethodAbility.destroyPanel(this.panel);
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
} }
} }
private initWindow(): void // 初始化窗口 private initWindow(): void // 初始化窗口
{ {
if(this.mContext === undefined) { if(this.mContext === undefined) {
return; return;
...@@ -150,18 +150,18 @@ ...@@ -150,18 +150,18 @@
private registerListener(): void private registerListener(): void
{ {
this.registerInputListener(); // 注册对输入法框架服务的监听 this.registerInputListener(); // 注册对输入法框架服务的监听
... ...
// 注册隐藏键盘事件监听等 // 注册隐藏键盘事件监听等
} }
private registerInputListener(): void { // 注册对输入法框架服务的开启及停止事件监听 private registerInputListener(): void { // 注册对输入法框架服务的开启及停止事件监听
inputMethodAbility.on('inputStart', (kbController, textInputClient) => { inputMethodAbility.on('inputStart', (kbController, textInputClient) => {
this.textInputClient = textInputClient; // 此为输入法客户端实例,由此调用输入法框架提供给输入法应用的功能接口 this.textInputClient = textInputClient; // 此为输入法客户端实例,由此调用输入法框架提供给输入法应用的功能接口
this.boardController = kbController; this.keyboardController = kbController;
}) })
inputMethodAbility.on('inputStop', () => { inputMethodAbility.on('inputStop', () => {
this.onDestroy(); // 销毁KeyboardController this.onDestroy(); // 销毁KeyboardController
}); });
} }
...@@ -232,7 +232,7 @@ ...@@ -232,7 +232,7 @@
@Component @Component
struct keyItem { struct keyItem {
private keyValue: sourceListType private keyValue: sourceListType = numberSourceListData[0];
@State keyBgc: string = "#fff" @State keyBgc: string = "#fff"
@State keyFontColor: string = "#000" @State keyFontColor: string = "#000"
...@@ -283,9 +283,9 @@ ...@@ -283,9 +283,9 @@
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceEvenly }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceEvenly }) {
Flex({ justifyContent: FlexAlign.SpaceBetween }) { Flex({ justifyContent: FlexAlign.SpaceBetween }) {
ForEach(this.numberList, (item: sourceListType) => { // 数字键盘第一行 ForEach(this.numberList, (item: sourceListType) => { // 数字键盘第一行
keyItem({ keyValue: item }) keyItem({ keyValue: item })
}, (item: sourceListType): sourceListType => item.content); }, (item: sourceListType) => item.content);
} }
.padding({ top: "2%" }) .padding({ top: "2%" })
.width("96%") .width("96%")
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
## 导入模块 ## 导入模块
```js ```ts
import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility'; import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility';
``` ```
...@@ -36,9 +36,11 @@ Extension生命周期回调,在拉起Extension输入法应用时调用,执 ...@@ -36,9 +36,11 @@ Extension生命周期回调,在拉起Extension输入法应用时调用,执
**示例:** **示例:**
```js ```ts
import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility';
import Want from '@ohos.app.ability.Want';
class InputMethodExt extends InputMethodExtensionAbility { class InputMethodExt extends InputMethodExtensionAbility {
onCreate(want) { onCreate(want: Want): void {
console.log('onCreate, want:' + want.abilityName); console.log('onCreate, want:' + want.abilityName);
} }
} }
...@@ -54,9 +56,10 @@ Extension生命周期回调,在销毁输入法应用时回调,执行资源 ...@@ -54,9 +56,10 @@ Extension生命周期回调,在销毁输入法应用时回调,执行资源
**示例:** **示例:**
```js ```ts
import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility';
class InputMethodExt extends InputMethodExtensionAbility { class InputMethodExt extends InputMethodExtensionAbility {
onDestroy() { onDestroy(): void {
console.log('onDestroy'); console.log('onDestroy');
} }
} }
......
...@@ -8,7 +8,7 @@ InputMethodExtensionContext模块是InputMethodExtensionAbility的上下文环 ...@@ -8,7 +8,7 @@ InputMethodExtensionContext模块是InputMethodExtensionAbility的上下文环
## 导入模块 ## 导入模块
``` ```ts
import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext'; import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext';
``` ```
...@@ -16,10 +16,11 @@ import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext'; ...@@ -16,10 +16,11 @@ import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext';
在使用InputMethodExtensionContext的功能前,需要通过InputMethodExtensionAbility子类实例获取。 在使用InputMethodExtensionContext的功能前,需要通过InputMethodExtensionAbility子类实例获取。
```js ```ts
import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility'; import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility';
class EntryAbility extends InputMethodExtensionAbility { import Want from '@ohos.app.ability.Want';
onCreate() { class InputMethodExtnAbility extends InputMethodExtensionAbility {
onCreate(want: Want): void {
let context = this.context; let context = this.context;
} }
} }
...@@ -41,8 +42,12 @@ destroy(callback: AsyncCallback\<void>): void ...@@ -41,8 +42,12 @@ destroy(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
this.context.destroy(() => { this.context.destroy((err: Error) => {
if(err) {
console.log('Failed to destroy context.');
return;
}
console.log('Succeeded in destroying context.'); console.log('Succeeded in destroying context.');
}); });
``` ```
...@@ -63,8 +68,10 @@ destroy(): Promise\<void>; ...@@ -63,8 +68,10 @@ destroy(): Promise\<void>;
**示例:** **示例:**
```js ```ts
this.context.destroy().then(() => { this.context.destroy().then(() => {
console.log('Succeed in destroying context.'); console.log('Succeed in destroying context.');
}).catch((err: Error)=>{
console.log('Failed to destroy context.');
}); });
``` ```
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
## 导入模块 ## 导入模块
``` ```ts
import InputMethodSubtype from '@ohos.InputMethodSubtype'; import InputMethodSubtype from '@ohos.InputMethodSubtype';
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册