• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import prompt from '@ohos.prompt';
2/*
3 * Copyright (c) 2022 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import inputmethodengine from '@ohos.inputMethodEngine';
17import display from '@ohos.display';
18import windowManager from '@ohos.window';
19import commoneventmanager from '@ohos.commonEventManager';
20
21
22let inputMethodEngine = inputmethodengine.getInputMethodEngine();
23let inputKeyboardDelegate = inputmethodengine.createKeyboardDelegate();
24let inputMethodAbility = inputmethodengine.getInputMethodAbility();
25const TAG = "keyboardController";
26
27export class KeyboardController {
28  mContext;
29  WINDOW_TYPE_INPUT_METHOD_FLOAT = 2105;
30  windowName = 'inputApp';
31  private windowHeight: number = 0;
32  private windowWidth: number = 0;
33  private nonBarPosition: number = 0;
34  private keyboardController: inputmethodengine.KeyboardController;
35  private TextInputClient: inputmethodengine.TextInputClient;
36
37  constructor(context) {
38    this.mContext = context;
39  }
40
41  public onCreate(): void {
42    this.initWindow();
43    let that = this;
44    inputMethodAbility.on("inputStop", () => {
45      inputMethodAbility.off("inputStop", () => {
46        console.log('====>inputMethodEngine delete inputStop notification.');
47      });
48      try {
49        that.mContext.destroy((err) => {
50          console.info(TAG + '====>inputMethodEngine destroy err:' + JSON.stringify(err));
51        })
52      } catch (err) {
53        console.info(TAG + '====>inputMethodEngine destroy catch err:' + JSON.stringify(err));
54      }
55    })
56
57    inputMethodEngine.on('inputStart', async (keyboardController, TextInputClient) => {
58      this.keyboardController = keyboardController;
59      this.TextInputClient = TextInputClient
60      console.info(TAG + '====>inputMethodEngine inputStart into');
61    })
62
63    function subscriberCallback(err, data) {
64      console.info(TAG + '====>receive event err: ' + JSON.stringify(err));
65      console.info(TAG + '====>receive event data ' + JSON.stringify(data));
66      switch (data.code) {
67        case 1:
68          console.info(TAG + '====>inputMethodEngine_test_getInputMethodEngine_001 event:' + data.event);
69          that.inputMethodEngine_test_getInputMethodEngine_001();
70          break;
71        case 2:
72          console.info(TAG + '====>inputMethodEngine_test_getKeyboardDelegate_001 event:' + data.event);
73          that.inputMethodEngine_test_getKeyboardDelegate_001();
74          break;
75        case 28:
76          console.info(TAG + '====>inputMethodEngine_test_028 event:' + data.event);
77          that.inputMethodEngine_test_028();
78          break;
79        case 29:
80          console.info(TAG + '====>inputMethodEngine_test_029 event:' + data.event);
81          that.inputMethodEngine_test_029();
82          break;
83        case 30:
84          console.info(TAG + '====>inputMethodEngine_test_030 event:' + data.event);
85          that.inputMethodEngine_test_030();
86          break;
87        case 31:
88          console.info(TAG + '====>inputMethodEngine_test_031 event:' + data.event);
89          that.inputMethodEngine_test_031();
90          break;
91        case 32:
92          console.info(TAG + '====>inputMethodEngine_test_032 event:' + data.event);
93          that.inputMethodEngine_test_032();
94          break;
95        case 33:
96          console.info(TAG + '====>inputMethodEngine_test_033 event:' + data.event);
97          that.inputMethodEngine_test_033();
98          break;
99        case 34:
100          console.info(TAG + '====>inputMethodEngine_test_034 event:' + data.event);
101          that.inputMethodEngine_test_034();
102          break;
103        case 35:
104          console.info(TAG + '====>inputMethodEngine_test_035 event:' + data.event);
105          that.inputMethodEngine_test_035();
106          break;
107        case 36:
108          console.info(TAG + '====>inputMethodEngine_test_036 event:' + data.event);
109          that.inputMethodEngine_test_036();
110          break;
111        case 37:
112          console.info(TAG + '====>inputMethodEngine_test_037 event:' + data.event);
113          that.inputMethodEngine_test_037();
114          break;
115        case 38:
116          console.info(TAG + '====>inputMethodEngine_test_038 event:' + data.event);
117          that.inputMethodEngine_test_038();
118          break;
119        case 39:
120          console.info(TAG + '====>inputMethodEngine_test_039 event:' + data.event);
121          that.inputMethodEngine_test_039();
122          break;
123        case 40:
124          console.info(TAG + '====>inputMethodEngine_test_040 event:' + data.event);
125          that.inputMethodEngine_test_040();
126          break;
127        case 41:
128          console.info(TAG + '====>inputMethodEngine_test_041 event:' + data.event);
129          that.inputMethodEngine_test_041();
130          break;
131        case 42:
132          console.info(TAG + '====>inputMethodEngine_test_042 event:' + data.event);
133          that.inputMethodEngine_test_042();
134          break;
135        case 43:
136          console.info(TAG + '====>inputMethodEngine_test_043 event:' + data.event);
137          that.inputMethodEngine_test_043();
138          break;
139        case 49:
140          console.info(TAG + '====>inputMethodEngine_test_049 event:' + data.event);
141          that.inputMethodEngine_test_049();
142          break;
143        case 50:
144          console.info(TAG + '====>inputMethodEngine_test_050 event:' + data.event);
145          that.inputMethodEngine_test_050();
146          break;
147        case 71:
148          console.info(TAG + '====>inputMethodEngine_test_071 event:' + data.event);
149          that.inputMethodEngine_test_071();
150          break;
151        case 72:
152          console.info(TAG + '====>inputMethodEngine_test_072 event:' + data.event);
153          that.inputMethodEngine_test_072();
154          break;
155        case 73:
156          console.info(TAG + '====>inputMethodEngine_test_073 event:' + data.event);
157          that.inputMethodEngine_test_073();
158          break;
159        case 74:
160          console.info(TAG + '====>inputMethodEngine_test_074 event:' + data.event);
161          that.inputMethodEngine_test_074();
162          break;
163        case 76:
164          console.info(TAG + '====>inputMethodEngine_test_076 event:' + data.event);
165          that.inputMethodEngine_test_076();
166          break;
167        case 77:
168          console.info(TAG + '====>inputMethodEngine_test_077 event:' + data.event);
169          that.inputMethodEngine_test_077();
170          break;
171        case 78:
172          console.debug(TAG + '====>Sub_InputMethod_IME_VisualInput_0500 event:' + data.event);
173          that.Sub_InputMethod_IME_VisualInput_0500();
174          break;
175        case 79:
176          console.debug(TAG + '====>Sub_InputMethod_IME_VisualInput_0600 event:' + data.event);
177          that.Sub_InputMethod_IME_VisualInput_0600();
178          break;
179      }
180    }
181
182    var commonEventSubscribeInfo = {
183      events: ["inputMethodEngineTest"]
184    };
185
186    var subscriber;
187    commoneventmanager.createSubscriber(commonEventSubscribeInfo).then(function (data) {
188      subscriber = data;
189      commoneventmanager.subscribe(subscriber, subscriberCallback);
190      console.info(TAG + '====>scene subscribe finish====');
191    });
192  }
193
194  public onDestroy(): void {
195    console.log('imsakitjsapp onDestroy');
196    globalThis.textInputClient.getTextIndexAtCursor().then((index) => {
197      console.log('imsakitjsapp getTextIndexAtCursor:  index = ' + index);
198      prompt.showToast({ message: 'getTextIndexAtCursor success' + index, duration: 200, bottom: 500 });
199      var win = windowManager.findWindow(this.windowName);
200      win.destroyWindow();
201      this.mContext.terminateSelf();
202      return true;
203    }).catch((err) => {
204      prompt.showToast({ message: 'getTextIndexAtCursor failed', duration: 200, bottom: 500 });
205    });
206  }
207
208  private initWindow(): void {
209    display.getDefaultDisplay().then(dis => {
210      var dWidth = dis.width;
211      var dHeight = dis.height;
212      var keyHeightRate = 0.47;
213      var keyHeight = dHeight * keyHeightRate;
214      this.windowWidth = dWidth;
215      this.windowHeight = keyHeight;
216      this.nonBarPosition = dHeight - keyHeight;
217
218      var config = {
219        name: this.windowName,
220        windowType: windowManager.WindowType.TYPE_INPUT_METHOD,
221        ctx: this.mContext
222      };
223      windowManager.createWindow(config).then((win) => {
224        win.resize(dWidth, keyHeight).then(() => {
225          win.moveWindowTo(0, this.nonBarPosition).then(() => {
226            win.setUIContent('pages/service/index').then(() => {
227            });
228          });
229        });
230      });
231    });
232  }
233
234  private publishCallback(err): void {
235    if (err) {
236      console.error(TAG + '====>publish failed: ' + JSON.stringify(err));
237    } else {
238      console.log(TAG + '====>publish');
239    }
240  }
241
242  private inputMethodEngine_test_getInputMethodEngine_001(): void {
243    console.info(TAG + '====>receive inputMethodEngine_test_getInputMethodEngine_001 data');
244    if (typeof (inputMethodEngine) === "object") {
245      console.info(TAG + '====>receive inputMethodEngine_test_getInputMethodEngine_001 object');
246      var commonEventPublishData = {
247        data: "SUCCESS"
248      };
249    } else {
250      console.info(TAG + '====>receive inputMethodEngine_test_getInputMethodEngine_001 failed');
251      var commonEventPublishData = {
252        data: "FAILED"
253      };
254    }
255    commoneventmanager.publish("inputMethodEngine_test_getInputMethodEngine_001", commonEventPublishData,
256      this.publishCallback);
257  }
258
259  private inputMethodEngine_test_getKeyboardDelegate_001(): void {
260    console.info(TAG + '====>receive inputMethodEngine_test_getKeyboardDelegate_001 data');
261    if (typeof (inputKeyboardDelegate) === "object") {
262      console.info(TAG + '====>receive inputMethodEngine_test_getKeyboardDelegate_001 object');
263      var commonEventPublishData = {
264        data: "SUCCESS"
265      };
266    } else {
267      console.info(TAG + '====>receive inputMethodEngine_test_getKeyboardDelegate_001 failed');
268      var commonEventPublishData = {
269        data: "FAILED"
270      };
271    }
272    commoneventmanager.publish("inputMethodEngine_test_getKeyboardDelegate_001", commonEventPublishData,
273      this.publishCallback);
274  }
275
276  async inputMethodEngine_test_028() {
277    console.info(TAG + '====>receive inputMethodEngine_test_028 data');
278    let commonEventPublishData;
279    let editorAttribyte = await this.TextInputClient.getEditorAttribute();
280    console.info(TAG + '====>receive inputMethodEngine_test_028 editorAttribyte: ' + JSON.stringify(editorAttribyte));
281    this.TextInputClient.sendKeyFunction(editorAttribyte.enterKeyType, (err, value) => {
282      if (err) {
283        commonEventPublishData = {
284          data: "FAILED"
285        };
286        console.info(TAG + '====>inputMethodEngine_test_028 TextInputClient sendKeyFunction err: ' +
287        JSON.stringify(err));
288      } else {
289        console.info(TAG + '====>inputMethodEngine_test_028 TextInputClient sendKeyFunction value: ' +
290        JSON.stringify(value));
291        if (value) {
292          commonEventPublishData = {
293            data: "SUCCESS"
294          };
295        } else {
296          commonEventPublishData = {
297            data: "FAILED"
298          };
299        }
300
301      }
302      commoneventmanager.publish("inputMethodEngine_test_028", commonEventPublishData, this.publishCallback);
303    })
304  }
305
306  async inputMethodEngine_test_029() {
307    console.info(TAG + '====>receive inputMethodEngine_test_029 data');
308    let commonEventPublishData;
309    let editorAttribyte = await this.TextInputClient.getEditorAttribute();
310    console.info(TAG + '====>inputMethodEngine_test_029 editorAttribyte:' + JSON.stringify(editorAttribyte));
311    let value = await this.TextInputClient.sendKeyFunction(editorAttribyte.inputPattern);
312    console.info(TAG + '====>inputMethodEngine_test_029 sendKeyFunction:' + JSON.stringify(value));
313    if (value) {
314      commonEventPublishData = {
315        data: "SUCCESS"
316      };
317    } else {
318      commonEventPublishData = {
319        data: "FAILED"
320      };
321    }
322    commoneventmanager.publish("inputMethodEngine_test_029", commonEventPublishData, this.publishCallback);
323  }
324
325  async inputMethodEngine_test_030() {
326    console.info(TAG + '====>receive inputMethodEngine_test_030 data');
327    let commonEventPublishData;
328    this.TextInputClient.deleteForward(1, (err, value) => {
329      if (err) {
330        console.info(TAG + '====>inputMethodEngine_test_030 deleteForward err:' + JSON.stringify(err));
331        commonEventPublishData = {
332          data: "FAILED"
333        };
334      } else {
335        console.info(TAG + '====>inputMethodEngine_test_030 deleteForward value:' + JSON.stringify(value));
336        if (typeof (value) === 'boolean') {
337          commonEventPublishData = {
338            data: "SUCCESS"
339          };
340        } else {
341          commonEventPublishData = {
342            data: "FAILED"
343          };
344        }
345      }
346      commoneventmanager.publish("inputMethodEngine_test_030", commonEventPublishData, this.publishCallback);
347    });
348  }
349
350  async inputMethodEngine_test_031() {
351    console.info(TAG + '====>receive inputMethodEngine_test_031 data');
352    let commonEventPublishData;
353    let value = await this.TextInputClient.deleteForward(1);
354    console.info(TAG + '====>inputMethodEngine_test_031 deleteForward:' + JSON.stringify(value));
355    if (typeof (value) === 'boolean') {
356      commonEventPublishData = {
357        data: "SUCCESS"
358      };
359    } else {
360      commonEventPublishData = {
361        data: "FAILED"
362      };
363    }
364    commoneventmanager.publish("inputMethodEngine_test_031", commonEventPublishData, this.publishCallback);
365  }
366
367  async inputMethodEngine_test_032() {
368    console.info(TAG + '====>receive inputMethodEngine_test_032 data');
369    let commonEventPublishData;
370    this.TextInputClient.deleteBackward(1, (err, value) => {
371      if (err) {
372        console.info(TAG + '====>inputMethodEngine_test_032 deleteBackward err:' + JSON.stringify(err));
373        commonEventPublishData = {
374          data: "FAILED"
375        };
376      } else {
377        console.info(TAG + '====>inputMethodEngine_test_032 deleteBackward value:' + JSON.stringify(value));
378        if (value) {
379          commonEventPublishData = {
380            data: "SUCCESS"
381          };
382        } else {
383          commonEventPublishData = {
384            data: "FAILED"
385          };
386        }
387      }
388      commoneventmanager.publish("inputMethodEngine_test_032", commonEventPublishData, this.publishCallback);
389    });
390  }
391
392  async inputMethodEngine_test_033() {
393    console.info(TAG + '====>receive inputMethodEngine_test_033 data');
394    let commonEventPublishData;
395    let value = await this.TextInputClient.deleteBackward(1);
396    console.info(TAG + '====>inputMethodEngine_test_033 deleteBackward:' + JSON.stringify(value));
397    if (value) {
398      commonEventPublishData = {
399        data: "SUCCESS"
400      };
401    } else {
402      commonEventPublishData = {
403        data: "FAILED"
404      };
405    }
406    commoneventmanager.publish("inputMethodEngine_test_033", commonEventPublishData, this.publishCallback);
407  }
408
409  async inputMethodEngine_test_034() {
410    console.info(TAG + '====>receive inputMethodEngine_test_034 data');
411    let commonEventPublishData;
412    this.TextInputClient.insertText('test', (err, value) => {
413      if (err) {
414        console.info(TAG + '====>inputMethodEngine_test_034 insertText err:' + JSON.stringify(err));
415        commonEventPublishData = {
416          data: "FAILED"
417        };
418      } else {
419        console.info(TAG + '====>inputMethodEngine_test_034 insertText value:' + JSON.stringify(value));
420        if (value) {
421          commonEventPublishData = {
422            data: "SUCCESS"
423          };
424        } else {
425          commonEventPublishData = {
426            data: "FAILED"
427          };
428        }
429      }
430      commoneventmanager.publish("inputMethodEngine_test_034", commonEventPublishData, this.publishCallback);
431    });
432  }
433
434  async inputMethodEngine_test_035() {
435    console.info(TAG + '====>receive inputMethodEngine_test_035 data');
436    let commonEventPublishData;
437    let value = await this.TextInputClient.insertText('test');
438    console.info(TAG + '====>inputMethodEngine_test_035 insertText:' + JSON.stringify(value));
439    if (value) {
440      commonEventPublishData = {
441        data: "SUCCESS"
442      };
443    } else {
444      commonEventPublishData = {
445        data: "FAILED"
446      };
447    }
448    commoneventmanager.publish("inputMethodEngine_test_035", commonEventPublishData, this.publishCallback);
449  }
450
451  async inputMethodEngine_test_036() {
452    console.info(TAG + '====>receive inputMethodEngine_test_036 data');
453    let commonEventPublishData;
454    this.TextInputClient.getForward(1, (err, value) => {
455      if (err) {
456        console.info(TAG + '====>inputMethodEngine_test_036 getForward err:' + JSON.stringify(err));
457        commonEventPublishData = {
458          data: "FAILED"
459        };
460      } else {
461        console.info(TAG + '====>inputMethodEngine_test_036 getForward value:' + JSON.stringify(value));
462        if (typeof (value) !== null) {
463          commonEventPublishData = {
464            data: "SUCCESS"
465          };
466        } else {
467          commonEventPublishData = {
468            data: "FAILED"
469          };
470        }
471      }
472      commoneventmanager.publish("inputMethodEngine_test_036", commonEventPublishData, this.publishCallback);
473    });
474  }
475
476  async inputMethodEngine_test_037() {
477    console.info(TAG + '====>receive inputMethodEngine_test_037 data');
478    let commonEventPublishData;
479    let value = await this.TextInputClient.getForward(1);
480    console.info(TAG + '====>inputMethodEngine_test_037 getForward:' + JSON.stringify(value));
481    if (typeof (value) !== null) {
482      commonEventPublishData = {
483        data: "SUCCESS"
484      };
485    } else {
486      commonEventPublishData = {
487        data: "FAILED"
488      };
489    }
490    commoneventmanager.publish("inputMethodEngine_test_037", commonEventPublishData, this.publishCallback);
491  }
492
493  async inputMethodEngine_test_038() {
494    console.info(TAG + '====>receive inputMethodEngine_test_038 data');
495    let commonEventPublishData;
496    this.TextInputClient.getEditorAttribute((err, value) => {
497      if (err) {
498        console.info(TAG + '====>inputMethodEngine_test_038 getEditorAttribute err:' + JSON.stringify(err));
499        commonEventPublishData = {
500          data: "FAILED"
501        };
502      } else {
503        console.info(TAG + '====>inputMethodEngine_test_038 getEditorAttribute value:' + JSON.stringify(value));
504        if (value) {
505          commonEventPublishData = {
506            data: "SUCCESS"
507          };
508        } else {
509          commonEventPublishData = {
510            data: "FAILED"
511          };
512        }
513      }
514      commoneventmanager.publish("inputMethodEngine_test_038", commonEventPublishData, this.publishCallback);
515    });
516  }
517
518  async inputMethodEngine_test_039() {
519    console.info(TAG + '====>receive inputMethodEngine_test_039 data');
520    let commonEventPublishData;
521    let value = await this.TextInputClient.getEditorAttribute();
522    console.info(TAG + '====>inputMethodEngine_test_039 getEditorAttribute:' + JSON.stringify(value));
523    if (value) {
524      commonEventPublishData = {
525        data: "SUCCESS"
526      };
527    } else {
528      commonEventPublishData = {
529        data: "FAILED"
530      };
531    }
532    commoneventmanager.publish("inputMethodEngine_test_039", commonEventPublishData, this.publishCallback);
533  }
534
535  async inputMethodEngine_test_040() {
536    console.info(TAG + '====>receive inputMethodEngine_test_040 data');
537    let commonEventPublishData;
538    try {
539      this.keyboardController.hideKeyboard((err, value) => {
540        if (err) {
541          console.info(TAG + '====>inputMethodEngine_test_040 hideKeyboard:' + JSON.stringify(err));
542          commonEventPublishData = {
543            data: "FAILED"
544          };
545        } else {
546          commonEventPublishData = {
547            data: "SUCCESS"
548          };
549        }
550        commoneventmanager.publish("inputMethodEngine_test_040", commonEventPublishData, this.publishCallback);
551      });
552    } catch (err) {
553      commonEventPublishData = {
554        data: "FAILED"
555      };
556      console.info(TAG + '====>inputMethodEngine_test_040 hideKeyboard throw_err:');
557      commoneventmanager.publish("inputMethodEngine_test_040", commonEventPublishData, this.publishCallback);
558    }
559  }
560
561  async inputMethodEngine_test_041() {
562    console.info(TAG + '====>receive inputMethodEngine_test_041 data');
563    let commonEventPublishData;
564    try {
565      await this.keyboardController.hideKeyboard();
566      console.info(TAG + '====>inputMethodEngine_test_041 hideKeyboard success');
567      commonEventPublishData = {
568        data: "SUCCESS"
569      };
570    } catch (err) {
571      commonEventPublishData = {
572        data: "FAILED"
573      };
574      console.info(TAG + '====>inputMethodEngine_test_041 hideKeyboard catch err:');
575    }
576    commoneventmanager.publish("inputMethodEngine_test_041", commonEventPublishData, this.publishCallback);
577  }
578
579  async inputMethodEngine_test_042() {
580    console.info(TAG + '====>receive inputMethodEngine_test_042 data');
581    let commonEventPublishData;
582    this.TextInputClient.getBackward(1, (err, value) => {
583      if (err) {
584        console.info(TAG + '====>inputMethodEngine_test_042 getBackward err:' + JSON.stringify(err));
585        commonEventPublishData = {
586          data: "FAILED"
587        };
588      } else {
589        console.info(TAG + '====>inputMethodEngine_test_042 getBackward value:' + JSON.stringify(value));
590        commonEventPublishData = {
591          data: "SUCCESS"
592        };
593      }
594      commoneventmanager.publish("inputMethodEngine_test_042", commonEventPublishData, this.publishCallback);
595    });
596  }
597
598  async inputMethodEngine_test_043() {
599    console.info(TAG + '====>receive inputMethodEngine_test_043 data');
600    let commonEventPublishData;
601    let value = await this.TextInputClient.getBackward(1);
602    console.info(TAG + '====>inputMethodEngine_test_043 getBackward:' + JSON.stringify(value));
603    commonEventPublishData = {
604      data: "SUCCESS"
605    };
606    commoneventmanager.publish("inputMethodEngine_test_043", commonEventPublishData, this.publishCallback);
607  }
608
609  async inputMethodEngine_test_049() {
610    console.info(TAG + '====>receive inputMethodEngine_test_049 data');
611    let commonEventPublishData;
612    try {
613      this.keyboardController.hide((err, value) => {
614        if (err) {
615          console.info(TAG + '====>inputMethodEngine_test_049 hide:' + JSON.stringify(err));
616          commonEventPublishData = {
617            data: "FAILED"
618          };
619        } else {
620          commonEventPublishData = {
621            data: "SUCCESS"
622          };
623        }
624        commoneventmanager.publish("inputMethodEngine_test_049", commonEventPublishData, this.publishCallback);
625      });
626    } catch (err) {
627      commonEventPublishData = {
628        data: "FAILED"
629      };
630      console.info(TAG + '====>inputMethodEngine_test_049 hide throw_err:');
631      commoneventmanager.publish("inputMethodEngine_test_040", commonEventPublishData, this.publishCallback);
632    }
633  }
634
635  async inputMethodEngine_test_050() {
636    console.info(TAG + '====>receive inputMethodEngine_test_050 data');
637    let commonEventPublishData;
638    try {
639      await this.keyboardController.hide();
640      console.info(TAG + '====>inputMethodEngine_test_050 hideKeyboard success');
641      commonEventPublishData = {
642        data: "SUCCESS"
643      };
644    } catch (err) {
645      commonEventPublishData = {
646        data: "FAILED"
647      };
648      console.info(TAG + '====>inputMethodEngine_test_050 hideKeyboard catch err:');
649    }
650    commoneventmanager.publish("inputMethodEngine_test_050", commonEventPublishData, this.publishCallback);
651  }
652
653  async inputMethodEngine_test_071() {
654    let commonEventPublishData = {
655      data: "FAILED"
656    };
657    console.info(TAG + '====>receive inputMethodEngine_test_071 success');
658    let count = 0;
659    inputMethodEngine.on('keyboardHide', () => {
660      count += 1;
661      inputMethodEngine.off("keyboardHide");
662      console.info(TAG + '====>inputMethodEngine.off("keyboardHide") count: ' + count);
663    });
664
665    let t = setTimeout(async () => {
666      clearTimeout(t);
667      await this.keyboardController.hideKeyboard();
668      console.info(TAG + '====>inputMethodEngine_test_071 hideKeyboard success');
669    }, 100);
670
671    let t1 = setTimeout(() => {
672      if (count === 1) {
673        commonEventPublishData = {
674          data: "SUCCESS"
675        };
676      }
677      commoneventmanager.publish("inputMethodEngine_test_071", commonEventPublishData, this.publishCallback);
678      clearTimeout(t1);
679    }, 1000);
680  }
681
682  async inputMethodEngine_test_072() {
683    let commonEventPublishData = {
684      data: "FAILED"
685    };
686    console.info(TAG + '====>receive inputMethodEngine_test_072 success');
687    let count = 0;
688    inputMethodEngine.on('keyboardShow', () => {
689      count += 1;
690      inputMethodEngine.off("keyboardShow");
691      console.info(TAG + '====>inputMethodEngine.off("keyboardShow") count: ' + count);
692    });
693
694    let t1 = setTimeout(() => {
695      if (count === 1) {
696        commonEventPublishData = {
697          data: "SUCCESS"
698        };
699      }
700      commoneventmanager.publish("inputMethodEngine_test_072", commonEventPublishData, this.publishCallback);
701      clearTimeout(t1);
702    }, 1500);
703  }
704
705  async inputMethodEngine_test_073() {
706    let commonEventPublishData = {
707      data: "FAILED"
708    };
709    console.info(TAG + '====>receive inputMethodEngine_test_073 success');
710    let count = 0;
711    inputKeyboardDelegate.on('keyDown', (keyEvent) => {
712      inputKeyboardDelegate.off('keyDown');
713      console.info(TAG + "====>inputKeyboardDelegate.on('keyDown') count: " + count);
714      console.info(TAG + "====>inputKeyboardDelegate.keyEvent.keyAction " + keyEvent.keyAction);
715      if (keyEvent.keyCode === 2000 && keyEvent.keyAction === 2) {
716        count += 1;
717      }
718      return true;
719    });
720    inputKeyboardDelegate.on('keyUp', (keyEvent) => {
721      inputKeyboardDelegate.off('keyUp');
722      console.info(TAG + "====>inputKeyboardDelegate.on('keyUp') count: " + count);
723      console.info(TAG + "====>inputKeyboardDelegate.keyEvent.keyAction " + keyEvent.keyAction);
724      if (keyEvent.keyCode === 2000 && keyEvent.keyAction === 3) {
725        count += 1;
726      }
727      return true;
728    });
729    let t = setTimeout(() => {
730      commonEventPublishData = {
731        data: "SUCCESS"
732      };
733      commoneventmanager.publish("inputMethodEngine_test_073", commonEventPublishData, this.publishCallback);
734      clearTimeout(t);
735    }, 1000);
736  }
737
738  async inputMethodEngine_test_074() {
739    let commonEventPublishData = {
740      data: "FAILED"
741    };
742    console.info(TAG + '====>receive inputMethodEngine_test_074 success');
743    let count = 0;
744
745    let t = setTimeout(async () => {
746      clearTimeout(t);
747      inputKeyboardDelegate.on('cursorContextChange', (x, y, h) => {
748        console.info(TAG + "====>inputKeyboardDelegate.on('cursorContextChange') count: " + count);
749        if (count === 1) {
750          inputKeyboardDelegate.off('cursorContextChange');
751          console.info(TAG + '====>inputMethodEngine_test_074 inputKeyboardDelegate.off');
752        }
753        count += 1;
754        console.info(TAG + '====>inputMethodEngine_test_074 x,y,z: ' + x + "---" + y + "---" + h);
755      });
756
757      let loop = 0;
758      let t1 = setInterval(async () => {
759        await this.TextInputClient.insertText("ttt");
760        console.info(TAG + '====>keyboardController.insertText count: ' + count);
761        console.info(TAG + '====>keyboardController.insertText loop: ' + loop);
762        loop += 1;
763        if (loop === 3) {
764          clearInterval(t1);
765        }
766      }, 500);
767    }, 1000);
768
769    let t1 = setTimeout(() => {
770      if (count === 2) {
771        commonEventPublishData = {
772          data: "SUCCESS"
773        };
774      }
775      commoneventmanager.publish("inputMethodEngine_test_074", commonEventPublishData, this.publishCallback);
776      clearTimeout(t1);
777    }, 4000);
778  }
779
780  async inputMethodEngine_test_076() {
781    let commonEventPublishData = {
782      data: "FAILED"
783    };
784    console.info(TAG + '====>receive inputMethodEngine_test_076 success');
785    inputKeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
786      console.info(TAG + "====>inputKeyboardDelegate.on('selectionChange')");
787      inputKeyboardDelegate.off('selectionChange');
788      commonEventPublishData = {
789        data: "SUCCESS"
790      };
791      console.info(TAG + '====>inputMethodEngine_test_076 oldBegin,oldEnd,newBegin,newEnd: ' + oldBegin + "---" +
792        oldEnd + "---" + newBegin + "---" + newEnd);
793    });
794
795    let t = setTimeout(() => {
796      commoneventmanager.publish("inputMethodEngine_test_076", commonEventPublishData, this.publishCallback);
797      clearTimeout(t);
798    }, 2000);
799  }
800
801  async inputMethodEngine_test_077() {
802    let commonEventPublishData = {
803      data: "FAILED"
804    };
805    console.info(TAG + '====>receive inputMethodEngine_test_077 success');
806    let count = 0;
807    inputKeyboardDelegate.on('textChange', (text) => {
808      console.info(TAG + "====>inputKeyboardDelegate.on('textChange') count:" + count);
809      if (count === 1) {
810        inputKeyboardDelegate.off('textChange');
811      }
812      count += 1;
813      console.info(TAG + '====>inputMethodEngine_test_077 text: ' + text);
814    });
815
816    let loopCount = 0;
817    let t = setInterval(async () => {
818      await this.TextInputClient.insertText("tttt");
819      console.info(TAG + '====>keyboardController.insertText count: ' + count);
820      if (loopCount === 2) {
821        clearInterval(t);
822      }
823      loopCount += 1;
824    }, 300);
825
826    let t1 = setTimeout(() => {
827      if (count === 2) {
828        commonEventPublishData = {
829          data: "SUCCESS"
830        };
831      }
832      commoneventmanager.publish("inputMethodEngine_test_077", commonEventPublishData, this.publishCallback);
833      clearTimeout(t1);
834    }, 2000);
835  }
836
837  async Sub_InputMethod_IME_VisualInput_0500() {
838    console.info(TAG + '====>receive Sub_InputMethod_IME_VisualInput_0500 data');
839    let commonEventPublishData = {
840      data: "FAILED"
841    };
842    try {
843      console.info(TAG + '====>Sub_InputMethod_IME_VisualInput_0500 exitCurrentInputType start');
844      await this.keyboardController.exitCurrentInputType();
845      console.info(TAG + '====>Sub_InputMethod_IME_VisualInput_0500 exitCurrentInputType success');
846      commonEventPublishData = {
847        data: "FAILED"
848      };
849    } catch (err) {
850      console.info(TAG + '====>Sub_InputMethod_IME_VisualInput_0500 exitCurrentInputType catch err:' +
851      JSON.stringify(err));
852      if (err.code === 12800010) {
853        commonEventPublishData = {
854          data: "SUCCESS"
855        };
856      }
857    }
858    commoneventmanager.publish('Sub_InputMethod_IME_VisualInput_0500', commonEventPublishData, this.publishCallback);
859  }
860
861  async Sub_InputMethod_IME_VisualInput_0600() {
862    console.info(TAG + '====>receive Sub_InputMethod_IME_VisualInput_0600 data');
863    let commonEventPublishData = {
864      data: "FAILED"
865    };
866    this.keyboardController.exitCurrentInputType((err) => {
867      console.info(TAG + '====>Sub_InputMethod_IME_VisualInput_0600 exitCurrentInputType failed: ' +
868      JSON.stringify(err));
869      if (err.code === 12800010) {
870        commonEventPublishData = {
871          data: "SUCCESS"
872        };
873      } else {
874        console.info(TAG + '====>Sub_InputMethod_IME_VisualInput_0600 exitCurrentInputType not throw 12800010');
875      }
876      commoneventmanager.publish('Sub_InputMethod_IME_VisualInput_0600', commonEventPublishData, this.publishCallback);
877    });
878  }
879}