• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import inputMethod from '@ohos.inputMethod';
16
17@Entry
18@Component
19struct Dialog {
20  private arr: string[] = []
21  private properityMap: Map<string, inputMethod.InputMethodProperty> = new Map();
22  @State private win: any = undefined
23  @State private context: any = undefined
24  private inputMethods: Array<inputMethod.InputMethodProperty> = null
25  private TAG = "[InputMethodChooseDialog]"
26
27  aboutToAppear() {
28    console.log(this.TAG, "dialog page appears")
29    this.context = globalThis.context
30    this.win = globalThis.extensionWin
31    this.inputMethods = globalThis.inputMethodList
32
33    for (let inputmethod of this.inputMethods) {
34      let name = inputmethod.packageName
35      this.arr.push(name)
36      this.properityMap.set(name, inputmethod)
37    }
38  }
39
40  onPrint() {
41    console.log(this.TAG + "print file or text")
42  }
43
44  onCopy() {
45    console.log(this.TAG + "copy file and html")
46  }
47
48  build() {
49    Column() {
50      List({ space: 1, initialIndex: 0 }) {
51        ListItem() {
52          Text($r("app.string.dialogTitle"))
53            .width('100%')
54            .height(40)
55            .fontSize(14)
56            .textAlign(TextAlign.Center)
57            .backgroundColor(Color.Pink)
58        }.sticky(Sticky.Normal)
59
60        ForEach(this.arr, (item, index) => {
61          ListItem() {
62            Text(item.split('.').length > 2 ? item.split('.')[2] : item.split('.')[-1])
63              .width('100%')
64              .height(60)
65              .fontSize(16)
66              .textAlign(TextAlign.Center)
67              .borderRadius(10)
68              .backgroundColor($r("app.color.btn_default"))
69              .onClick(async () => {
70                if (this.properityMap.has(item)) {
71                  let prop = this.properityMap.get(item)
72                  globalThis.chooseInputMethods(prop)
73                }
74                setTimeout(() => {
75                  this.win.destroy()
76                  this.context.terminateSelf()
77                }, 1000)
78              })
79          }
80          .sticky(0 == index ? Sticky.Opacity : Sticky.None)
81        }, item => item)
82      }
83    }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 })
84  }
85}