• 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
35    constructor(context) {
36        this.mContext = context;
37    }
38
39    public onCreate(): void {
40        this.initWindow();
41        let that = this;
42        inputMethodAbility.on("inputStop", () => {
43            try{
44                that.mContext.destroy((err) => {
45                    console.info(TAG + '====>inputMethodEngine destroy err:' + JSON.stringify(err));
46                })
47            }catch(err){
48                console.info(TAG + '====>inputMethodEngine destroy catch err:' + JSON.stringify(err));
49            }
50        })
51
52        function subscriberCallback(err, data) {
53            console.debug(TAG + '====>receive event err: ' + JSON.stringify(err));
54            console.debug(TAG + '====>receive event data ' + JSON.stringify(data));
55            switch (data.code) {
56                case 1:
57                    console.debug(TAG + '====>inputMethodEngine_test_getInputMethodEngine_001 event:' + data.event);
58                    that.inputMethodEngine_test_getInputMethodEngine_001();
59                    break;
60                case 2:
61                    console.debug(TAG + '====>inputMethodEngine_test_getKeyboardDelegate_001 event:' + data.event);
62                    that.inputMethodEngine_test_getKeyboardDelegate_001();
63                    break;
64                case 28:
65                    console.debug(TAG + '====>inputMethodEngine_test_028 event:' + data.event);
66                    that.inputMethodEngine_test_028();
67                    break;
68                case 29:
69                    console.debug(TAG + '====>inputMethodEngine_test_029 event:' + data.event);
70                    that.inputMethodEngine_test_029();
71                    break;
72                case 30:
73                    console.debug(TAG + '====>inputMethodEngine_test_030 event:' + data.event);
74                    that.inputMethodEngine_test_030();
75                    break;
76                case 31:
77                    console.debug(TAG + '====>inputMethodEngine_test_031 event:' + data.event);
78                    that.inputMethodEngine_test_031();
79                    break;
80                case 32:
81                    console.debug(TAG + '====>inputMethodEngine_test_032 event:' + data.event);
82                    that.inputMethodEngine_test_032();
83                    break;
84                case 33:
85                    console.debug(TAG + '====>inputMethodEngine_test_033 event:' + data.event);
86                    that.inputMethodEngine_test_033();
87                    break;
88                case 34:
89                    console.debug(TAG + '====>inputMethodEngine_test_034 event:' + data.event);
90                    that.inputMethodEngine_test_034();
91                    break;
92                case 35:
93                    console.debug(TAG + '====>inputMethodEngine_test_035 event:' + data.event);
94                    that.inputMethodEngine_test_035();
95                    break;
96                case 36:
97                    console.debug(TAG + '====>inputMethodEngine_test_036 event:' + data.event);
98                    that.inputMethodEngine_test_036();
99                    break;
100                case 37:
101                    console.debug(TAG + '====>inputMethodEngine_test_037 event:' + data.event);
102                    that.inputMethodEngine_test_037();
103                    break;
104                case 38:
105                    console.debug(TAG + '====>inputMethodEngine_test_038 event:' + data.event);
106                    that.inputMethodEngine_test_038();
107                    break;
108                case 39:
109                    console.debug(TAG + '====>inputMethodEngine_test_039 event:' + data.event);
110                    that.inputMethodEngine_test_039();
111                    break;
112                case 40:
113                    console.debug(TAG + '====>inputMethodEngine_test_040 event:' + data.event);
114                    that.inputMethodEngine_test_040();
115                    break;
116                case 41:
117                    console.debug(TAG + '====>inputMethodEngine_test_041 event:' + data.event);
118                    that.inputMethodEngine_test_041();
119                    break;
120                case 42:
121                    console.debug(TAG + '====>inputMethodEngine_test_042 event:' + data.event);
122                    that.inputMethodEngine_test_042();
123                    break;
124                case 43:
125                    console.debug(TAG + '====>inputMethodEngine_test_043 event:' + data.event);
126                    that.inputMethodEngine_test_043();
127                    break;
128                case 49:
129                    console.debug(TAG + '====>inputMethodEngine_test_049 event:' + data.event);
130                    that.inputMethodEngine_test_049();
131                    break;
132                case 50:
133                    console.debug(TAG + '====>inputMethodEngine_test_050 event:' + data.event);
134                    that.inputMethodEngine_test_050();
135                    break;
136            }
137        }
138
139        var commonEventSubscribeInfo = {
140            events: ["test1"]
141        };
142
143        var subscriber;
144        commoneventmanager.createSubscriber(commonEventSubscribeInfo).then(function (data) {
145            subscriber = data;
146            commoneventmanager.subscribe(subscriber, subscriberCallback);
147            console.debug(TAG + '====>scene subscribe finish====');
148        });
149    }
150
151    public onDestroy(): void {
152        console.log('imsakitjsapp onDestroy');
153        globalThis.textInputClient.getTextIndexAtCursor().then((index) => {
154            console.log('imsakitjsapp getTextIndexAtCursor:  index = ' + index);
155            prompt.showToast({ message: 'getTextIndexAtCursor success' + index, duration: 200, bottom: 500 });
156            var win = windowManager.findWindow(this.windowName);
157            win.destroyWindow();
158            this.mContext.terminateSelf();
159            return true;
160        }).catch((err) => {
161            prompt.showToast({ message: 'getTextIndexAtCursor failed', duration: 200, bottom: 500 });
162        });
163    }
164
165    private initWindow(): void {
166        display.getDefaultDisplay().then(dis => {
167            var dWidth = dis.width;
168            var dHeight = dis.height;
169            var keyHeightRate = 0.47;
170            var keyHeight = dHeight * keyHeightRate;
171            this.windowWidth = dWidth;
172            this.windowHeight = keyHeight;
173            this.nonBarPosition = dHeight - keyHeight;
174
175            var config = {
176                name: this.windowName,
177                windowType: this.WINDOW_TYPE_INPUT_METHOD_FLOAT,
178                ctx: this.mContext
179            };
180            windowManager.createWindow(config).then((win) => {
181                win.resize(dWidth, keyHeight).then(() => {
182                    win.moveWindowTo(0, this.nonBarPosition).then(() => {
183                        win.setUIContent('pages/service/index').then(() => {
184                        });
185                    });
186                });
187            });
188        });
189    }
190
191    private publishCallback(err): void {
192        if (err) {
193            console.error(TAG + '====>publish failed: ' + JSON.stringify(err));
194        } else {
195            console.log(TAG + '====>publish');
196        }
197    }
198
199    private inputMethodEngine_test_getInputMethodEngine_001(): void {
200        console.debug(TAG + '====>receive inputMethodEngine_test_getInputMethodEngine_001 data');
201        if (typeof(inputMethodEngine) === "object") {
202            console.info(TAG + '====>receive inputMethodEngine_test_getInputMethodEngine_001 object');
203            var commonEventPublishData = {
204                data: "SUCCESS"
205            };
206        } else {
207            console.info(TAG + '====>receive inputMethodEngine_test_getInputMethodEngine_001 failed');
208            var commonEventPublishData = {
209                data: "FAILED"
210            };
211        }
212        commoneventmanager.publish("inputMethodEngine_test_getInputMethodEngine_001", commonEventPublishData, this.publishCallback);
213    }
214
215    private inputMethodEngine_test_getKeyboardDelegate_001(): void {
216        console.debug(TAG + '====>receive inputMethodEngine_test_getKeyboardDelegate_001 data');
217        if (typeof(inputKeyboardDelegate) === "object") {
218            console.info(TAG + '====>receive inputMethodEngine_test_getKeyboardDelegate_001 object');
219            var commonEventPublishData = {
220                data: "SUCCESS"
221            };
222        } else {
223            console.info(TAG + '====>receive inputMethodEngine_test_getKeyboardDelegate_001 failed');
224            var commonEventPublishData = {
225                data: "FAILED"
226            };
227        }
228        commoneventmanager.publish("inputMethodEngine_test_getKeyboardDelegate_001", commonEventPublishData, this.publishCallback);
229    }
230
231    private inputMethodEngine_test_028(): void {
232        console.debug(TAG + '====>receive inputMethodEngine_test_028 data');
233        inputMethodEngine.on('inputStart', async (keyboardController, TextInputClient) => {
234            inputMethodEngine.off('inputStart');
235            let commonEventPublishData;
236            if (TextInputClient == null) {
237                commonEventPublishData = {
238                    data: "FAILED"
239                };
240                commoneventmanager.publish("inputMethodEngine_test_028", commonEventPublishData, this.publishCallback);
241            } else {
242                let editorAttribyte = await TextInputClient.getEditorAttribute();
243                console.debug(TAG + '====>receive inputMethodEngine_test_028 editorAttribyte: ' + JSON.stringify(editorAttribyte));
244                TextInputClient.sendKeyFunction(editorAttribyte.enterKeyType, (err, value) => {
245                    if (err) {
246                        commonEventPublishData = {
247                            data: "FAILED"
248                        };
249                        console.debug(TAG + '====>inputMethodEngine_test_028 TextInputClient sendKeyFunction err: ' + JSON.stringify(err));
250                    } else {
251                        console.debug(TAG + '====>inputMethodEngine_test_028 TextInputClient sendKeyFunction value: ' + JSON.stringify(value));
252                        if (value) {
253                            commonEventPublishData = {
254                                data: "SUCCESS"
255                            };
256                        } else {
257                            commonEventPublishData = {
258                                data: "FAILED"
259                            };
260                        }
261
262                    }
263                    commoneventmanager.publish("inputMethodEngine_test_028", commonEventPublishData, this.publishCallback);
264                });
265            }
266        });
267    }
268    private inputMethodEngine_test_029(): void{
269        console.debug(TAG + '====>receive inputMethodEngine_test_029 data');
270        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
271            inputMethodEngine.off('inputStart');
272            let commonEventPublishData;
273            if (InputClient == null) {
274                commonEventPublishData = {
275                    data: "FAILED"
276                };
277                commoneventmanager.publish("inputMethodEngine_test_029", commonEventPublishData, this.publishCallback);
278            } else {
279                let editorAttribyte = await InputClient.getEditorAttribute();
280                console.debug(TAG + '====>inputMethodEngine_test_029 editorAttribyte:' + JSON.stringify(editorAttribyte));
281                let value = await InputClient.sendKeyFunction(editorAttribyte.enterKeyType);
282                console.debug(TAG + '====>inputMethodEngine_test_029 sendKeyFunction:' + JSON.stringify(value));
283                if (value){
284                    commonEventPublishData = {
285                        data: "SUCCESS"
286                    };
287                } else {
288                    commonEventPublishData = {
289                        data: "FAILED"
290                    };
291                }
292                commoneventmanager.publish("inputMethodEngine_test_029", commonEventPublishData, this.publishCallback);
293            }
294        });
295    }
296
297    private inputMethodEngine_test_030(): void{
298        console.debug(TAG + '====>receive inputMethodEngine_test_030 data');
299        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
300            inputMethodEngine.off('inputStart');
301            let commonEventPublishData;
302            if (InputClient == null) {
303                commonEventPublishData = {
304                    data: "FAILED"
305                };
306                commoneventmanager.publish("inputMethodEngine_test_030", commonEventPublishData, this.publishCallback);
307            } else {
308                InputClient.deleteForward(1, (err, value) => {
309                    if (err){
310                        console.debug(TAG + '====>inputMethodEngine_test_030 deleteForward err:' + JSON.stringify(err));
311                        commonEventPublishData = {
312                            data: "FAILED"
313                        };
314                    } else {
315                        console.debug(TAG + '====>inputMethodEngine_test_030 deleteForward value:' + JSON.stringify(value));
316                        if (typeof(value) === 'boolean'){
317                            commonEventPublishData = {
318                                data: "SUCCESS"
319                            };
320                        } else {
321                            commonEventPublishData = {
322                                data: "FAILED"
323                            };
324                        }
325                    }
326                    commoneventmanager.publish("inputMethodEngine_test_030", commonEventPublishData, this.publishCallback);
327                });
328            }
329        });
330    }
331    private inputMethodEngine_test_031(): void{
332        console.debug(TAG + '====>receive inputMethodEngine_test_031 data');
333        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
334            inputMethodEngine.off('inputStart');
335            let commonEventPublishData;
336            if (InputClient == null) {
337                commonEventPublishData = {
338                    data: "FAILED"
339                };
340                commoneventmanager.publish("inputMethodEngine_test_031", commonEventPublishData, this.publishCallback);
341            } else {
342                let value = await InputClient.deleteForward(1);
343                console.debug(TAG + '====>inputMethodEngine_test_031 deleteForward:' + JSON.stringify(value));
344                if (typeof(value) === 'boolean'){
345                    commonEventPublishData = {
346                        data: "SUCCESS"
347                    };
348                } else {
349                    commonEventPublishData = {
350                        data: "FAILED"
351                    };
352                }
353                commoneventmanager.publish("inputMethodEngine_test_031", commonEventPublishData, this.publishCallback);
354            }
355        });
356    }
357
358    private inputMethodEngine_test_032(): void{
359        console.debug(TAG + '====>receive inputMethodEngine_test_032 data');
360        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
361            inputMethodEngine.off('inputStart');
362            let commonEventPublishData;
363            if (InputClient == null) {
364                commonEventPublishData = {
365                    data: "FAILED"
366                };
367                commoneventmanager.publish("inputMethodEngine_test_032", commonEventPublishData, this.publishCallback);
368            } else {
369                InputClient.deleteBackward(1, (err, value) => {
370                    if (err){
371                        console.debug(TAG + '====>inputMethodEngine_test_032 deleteBackward err:' + JSON.stringify(err));
372                        commonEventPublishData = {
373                            data: "FAILED"
374                        };
375                    } else {
376                        console.debug(TAG + '====>inputMethodEngine_test_032 deleteBackward value:' + JSON.stringify(value));
377                        if (value){
378                            commonEventPublishData = {
379                                data: "SUCCESS"
380                            };
381                        } else {
382                            commonEventPublishData = {
383                                data: "FAILED"
384                            };
385                        }
386                    }
387                    commoneventmanager.publish("inputMethodEngine_test_032", commonEventPublishData, this.publishCallback);
388                });
389            }
390        });
391    }
392    private inputMethodEngine_test_033(): void{
393        console.debug(TAG + '====>receive inputMethodEngine_test_033 data');
394        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
395            inputMethodEngine.off('inputStart');
396            let commonEventPublishData;
397            if (InputClient == null) {
398                commonEventPublishData = {
399                    data: "FAILED"
400                };
401                commoneventmanager.publish("inputMethodEngine_test_033", commonEventPublishData, this.publishCallback);
402            } else {
403                let value = await InputClient.deleteBackward(1);
404                console.debug(TAG + '====>inputMethodEngine_test_033 deleteBackward:' + JSON.stringify(value));
405                if (value){
406                    commonEventPublishData = {
407                        data: "SUCCESS"
408                    };
409                } else {
410                    commonEventPublishData = {
411                        data: "FAILED"
412                    };
413                }
414                commoneventmanager.publish("inputMethodEngine_test_033", commonEventPublishData, this.publishCallback);
415            }
416        });
417    }
418
419    private inputMethodEngine_test_034(): void{
420        console.debug(TAG + '====>receive inputMethodEngine_test_034 data');
421        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
422            inputMethodEngine.off('inputStart');
423            let commonEventPublishData;
424            if (InputClient == null) {
425                commonEventPublishData = {
426                    data: "FAILED"
427                };
428                commoneventmanager.publish("inputMethodEngine_test_034", commonEventPublishData, this.publishCallback);
429            } else {
430                InputClient.insertText('test', (err, value) => {
431                    if (err){
432                        console.debug(TAG + '====>inputMethodEngine_test_034 insertText err:' + JSON.stringify(err));
433                        commonEventPublishData = {
434                            data: "FAILED"
435                        };
436                    } else {
437                        console.debug(TAG + '====>inputMethodEngine_test_034 insertText value:' + JSON.stringify(value));
438                        if (value){
439                            commonEventPublishData = {
440                                data: "SUCCESS"
441                            };
442                        } else {
443                            commonEventPublishData = {
444                                data: "FAILED"
445                            };
446                        }
447                    }
448                    commoneventmanager.publish("inputMethodEngine_test_034", commonEventPublishData, this.publishCallback);
449                });
450            }
451        });
452    }
453    private inputMethodEngine_test_035(): void{
454        console.debug(TAG + '====>receive inputMethodEngine_test_035 data');
455        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
456            inputMethodEngine.off('inputStart');
457            let commonEventPublishData;
458            if (InputClient == null) {
459                commonEventPublishData = {
460                    data: "FAILED"
461                };
462                commoneventmanager.publish("inputMethodEngine_test_035", commonEventPublishData, this.publishCallback);
463            } else {
464                let value = await InputClient.insertText('test');
465                console.debug(TAG + '====>inputMethodEngine_test_035 insertText:' + JSON.stringify(value));
466                if (value){
467                    commonEventPublishData = {
468                        data: "SUCCESS"
469                    };
470                } else {
471                    commonEventPublishData = {
472                        data: "FAILED"
473                    };
474                }
475                commoneventmanager.publish("inputMethodEngine_test_035", commonEventPublishData, this.publishCallback);
476            }
477        });
478    }
479
480    private inputMethodEngine_test_036(): void{
481        console.debug(TAG + '====>receive inputMethodEngine_test_036 data');
482        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
483            inputMethodEngine.off('inputStart');
484            let commonEventPublishData;
485            if (InputClient == null) {
486                commonEventPublishData = {
487                    data: "FAILED"
488                };
489                commoneventmanager.publish("inputMethodEngine_test_036", commonEventPublishData, this.publishCallback);
490            } else {
491                InputClient.getForward(1, (err, value) => {
492                    if (err){
493                        console.debug(TAG + '====>inputMethodEngine_test_036 getForward err:' + JSON.stringify(err));
494                        commonEventPublishData = {
495                            data: "FAILED"
496                        };
497                    } else {
498                        console.debug(TAG + '====>inputMethodEngine_test_036 getForward value:' + JSON.stringify(value));
499                        if (value){
500                            commonEventPublishData = {
501                                data: "SUCCESS"
502                            };
503                        } else {
504                            commonEventPublishData = {
505                                data: "FAILED"
506                            };
507                        }
508                    }
509                    commoneventmanager.publish("inputMethodEngine_test_036", commonEventPublishData, this.publishCallback);
510                });
511            }
512        });
513    }
514    private inputMethodEngine_test_037(): void{
515        console.debug(TAG + '====>receive inputMethodEngine_test_037 data');
516        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
517            inputMethodEngine.off('inputStart');
518            let commonEventPublishData;
519            if (InputClient == null) {
520                commonEventPublishData = {
521                    data: "FAILED"
522                };
523                commoneventmanager.publish("inputMethodEngine_test_037", commonEventPublishData, this.publishCallback);
524            } else {
525                let value = await InputClient.getForward(1);
526                console.debug(TAG + '====>inputMethodEngine_test_037 getForward:' + JSON.stringify(value));
527                if (value){
528                    commonEventPublishData = {
529                        data: "SUCCESS"
530                    };
531                } else {
532                    commonEventPublishData = {
533                        data: "FAILED"
534                    };
535                }
536                commoneventmanager.publish("inputMethodEngine_test_037", commonEventPublishData, this.publishCallback);
537            }
538        });
539    }
540
541    private inputMethodEngine_test_038(): void{
542        console.debug(TAG + '====>receive inputMethodEngine_test_038 data');
543        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
544            inputMethodEngine.off('inputStart');
545            let commonEventPublishData;
546            if (InputClient == null) {
547                commonEventPublishData = {
548                    data: "FAILED"
549                };
550                commoneventmanager.publish("inputMethodEngine_test_038", commonEventPublishData, this.publishCallback);
551            } else {
552                InputClient.getEditorAttribute((err, value) => {
553                    if (err){
554                        console.debug(TAG + '====>inputMethodEngine_test_038 getEditorAttribute err:' + JSON.stringify(err));
555                        commonEventPublishData = {
556                            data: "FAILED"
557                        };
558                    } else {
559                        console.debug(TAG + '====>inputMethodEngine_test_038 getEditorAttribute value:' + JSON.stringify(value));
560                        if (value){
561                            commonEventPublishData = {
562                                data: "SUCCESS"
563                            };
564                        } else {
565                            commonEventPublishData = {
566                                data: "FAILED"
567                            };
568                        }
569                    }
570                    commoneventmanager.publish("inputMethodEngine_test_038", commonEventPublishData, this.publishCallback);
571                });
572            }
573        });
574    }
575    private inputMethodEngine_test_039(): void{
576        console.debug(TAG + '====>receive inputMethodEngine_test_039 data');
577        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
578            inputMethodEngine.off('inputStart');
579            let commonEventPublishData;
580            if (InputClient == null) {
581                commonEventPublishData = {
582                    data: "FAILED"
583                };
584                commoneventmanager.publish("inputMethodEngine_test_039", commonEventPublishData, this.publishCallback);
585            } else {
586                let value = await InputClient.getEditorAttribute();
587                console.debug(TAG + '====>inputMethodEngine_test_039 getEditorAttribute:' + JSON.stringify(value));
588                if (value){
589                    commonEventPublishData = {
590                        data: "SUCCESS"
591                    };
592                } else {
593                    commonEventPublishData = {
594                        data: "FAILED"
595                    };
596                }
597                commoneventmanager.publish("inputMethodEngine_test_039", commonEventPublishData, this.publishCallback);
598            }
599        });
600    }
601
602    private inputMethodEngine_test_040(): void{
603        console.debug(TAG + '====>receive inputMethodEngine_test_040 data');
604        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
605            inputMethodEngine.off('inputStart');
606            let commonEventPublishData;
607            if (InputClient == null) {
608                commonEventPublishData = {
609                    data: "FAILED"
610                };
611                commoneventmanager.publish("inputMethodEngine_test_040", commonEventPublishData, this.publishCallback);
612            } else {
613                try{
614                    KeyboardDelegate.hideKeyboard((err, value) => {
615                        if (err){
616                            console.debug(TAG + '====>inputMethodEngine_test_040 hideKeyboard:' + JSON.stringify(err));
617                            commonEventPublishData = {
618                                data: "FAILED"
619                            };
620                        } else {
621                            commonEventPublishData = {
622                                data: "SUCCESS"
623                            };
624                        }
625                        commoneventmanager.publish("inputMethodEngine_test_040", commonEventPublishData, this.publishCallback);
626                    });
627                }catch(err){
628                    commonEventPublishData = {
629                        data: "FAILED"
630                    };
631                    console.debug(TAG + '====>inputMethodEngine_test_040 hideKeyboard throw_err:');
632                    commoneventmanager.publish("inputMethodEngine_test_040", commonEventPublishData, this.publishCallback);
633                }
634            }
635        });
636    }
637    private inputMethodEngine_test_041(): void{
638        console.debug(TAG + '====>receive inputMethodEngine_test_041 data');
639        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
640            inputMethodEngine.off('inputStart');
641            let commonEventPublishData;
642            if (InputClient == null) {
643                commonEventPublishData = {
644                    data: "FAILED"
645                };
646                commoneventmanager.publish("inputMethodEngine_test_041", commonEventPublishData, this.publishCallback);
647            } else {
648                try{
649                    await KeyboardDelegate.hideKeyboard();
650                    console.debug(TAG + '====>inputMethodEngine_test_041 hideKeyboard success');
651                    commonEventPublishData = {
652                        data: "SUCCESS"
653                    };
654                }catch(err){
655                    commonEventPublishData = {
656                        data: "FAILED"
657                    };
658                    console.debug(TAG + '====>inputMethodEngine_test_041 hideKeyboard catch err:');
659                }
660                commoneventmanager.publish("inputMethodEngine_test_041", commonEventPublishData, this.publishCallback);
661            }
662        });
663    }
664
665    private inputMethodEngine_test_042(): void{
666        console.debug(TAG + '====>receive inputMethodEngine_test_042 data');
667        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
668            inputMethodEngine.off('inputStart');
669            let commonEventPublishData;
670            if (InputClient == null) {
671                commonEventPublishData = {
672                    data: "FAILED"
673                };
674                commoneventmanager.publish("inputMethodEngine_test_042", commonEventPublishData, this.publishCallback);
675            } else {
676                InputClient.getBackward(1, (err, value) => {
677                    if (err){
678                        console.debug(TAG + '====>inputMethodEngine_test_042 getBackward err:' + JSON.stringify(err));
679                        commonEventPublishData = {
680                            data: "FAILED"
681                        };
682                    } else {
683                        console.debug(TAG + '====>inputMethodEngine_test_042 getBackward value:' + JSON.stringify(value));
684                        commonEventPublishData = {
685                            data: "SUCCESS"
686                        };
687                    }
688                    commoneventmanager.publish("inputMethodEngine_test_042", commonEventPublishData, this.publishCallback);
689                });
690            }
691        });
692    }
693    private inputMethodEngine_test_043(): void{
694        console.debug(TAG + '====>receive inputMethodEngine_test_043 data');
695        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
696            inputMethodEngine.off('inputStart');
697            let commonEventPublishData;
698            if (InputClient == null) {
699                commonEventPublishData = {
700                    data: "FAILED"
701                };
702                commoneventmanager.publish("inputMethodEngine_test_043", commonEventPublishData, this.publishCallback);
703            } else {
704                let value = await InputClient.getBackward(1);
705                console.debug(TAG + '====>inputMethodEngine_test_043 getBackward:' + JSON.stringify(value));
706                commonEventPublishData = {
707                    data: "SUCCESS"
708                };
709                commoneventmanager.publish("inputMethodEngine_test_043", commonEventPublishData, this.publishCallback);
710            }
711        });
712    }
713
714    private inputMethodEngine_test_049(): void{
715        console.debug(TAG + '====>receive inputMethodEngine_test_049 data');
716        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
717            inputMethodEngine.off('inputStart');
718            let commonEventPublishData;
719            if (InputClient == null) {
720                commonEventPublishData = {
721                    data: "FAILED"
722                };
723                commoneventmanager.publish("inputMethodEngine_test_049", commonEventPublishData, this.publishCallback);
724            } else {
725                try{
726                    KeyboardDelegate.hide((err, value) => {
727                        if (err){
728                            console.debug(TAG + '====>inputMethodEngine_test_049 hide:' + JSON.stringify(err));
729                            commonEventPublishData = {
730                                data: "FAILED"
731                            };
732                        } else {
733                            commonEventPublishData = {
734                                data: "SUCCESS"
735                            };
736                        }
737                        commoneventmanager.publish("inputMethodEngine_test_049", commonEventPublishData, this.publishCallback);
738                    });
739                }catch(err){
740                    commonEventPublishData = {
741                        data: "FAILED"
742                    };
743                    console.debug(TAG + '====>inputMethodEngine_test_049 hide throw_err:');
744                    commoneventmanager.publish("inputMethodEngine_test_040", commonEventPublishData, this.publishCallback);
745                }
746            }
747        });
748    }
749    private inputMethodEngine_test_050(): void{
750        console.debug(TAG + '====>receive inputMethodEngine_test_050 data');
751        inputMethodEngine.on('inputStart', async(KeyboardDelegate, InputClient) =>{
752            inputMethodEngine.off('inputStart');
753            let commonEventPublishData;
754            if (InputClient == null) {
755                commonEventPublishData = {
756                    data: "FAILED"
757                };
758                commoneventmanager.publish("inputMethodEngine_test_050", commonEventPublishData, this.publishCallback);
759            } else {
760                try{
761                    await KeyboardDelegate.hide();
762                    console.debug(TAG + '====>inputMethodEngine_test_050 hideKeyboard success');
763                    commonEventPublishData = {
764                        data: "SUCCESS"
765                    };
766                }catch(err){
767                    commonEventPublishData = {
768                        data: "FAILED"
769                    };
770                    console.debug(TAG + '====>inputMethodEngine_test_050 hideKeyboard catch err:');
771                }
772                commoneventmanager.publish("inputMethodEngine_test_050", commonEventPublishData, this.publishCallback);
773            }
774        });
775    }
776
777
778
779
780}