• 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 deviceManager from '@ohos.distributedHardware.deviceManager'
16
17@CustomDialog
18export default struct DeviceDialog {
19  private controller?: CustomDialogController
20  private onSelectedIndexChange?: (selectedIndex: number) => void
21  private devices: Array<deviceManager.DeviceInfo> = []
22
23  build() {
24    Column() {
25      Text($r('app.string.check_device'))
26        .fontSize(20)
27        .width('100%')
28        .textAlign(TextAlign.Center)
29        .fontColor(Color.Black)
30        .fontWeight(FontWeight.Bold)
31      List() {
32        ForEach(this.devices, (item, index) => {
33          ListItem() {
34            Row() {
35              Text(item.deviceName)
36                .fontSize(20)
37                .width('90%')
38                .fontColor(Color.Black)
39
40              Image($r('app.media.connect'))
41                .width('8%')
42                .objectFit(ImageFit.Contain)
43            }
44            .height(80)
45            .onClick(() => {
46              this.onSelectedIndexChange(index)
47            })
48          }
49        }, item => item.deviceName)
50      }
51      .width('80%')
52      .height(150)
53
54      Button() {
55        Text($r('app.string.cancel'))
56          .fontColor('#0D9FFB')
57          .width('90%')
58          .textAlign(TextAlign.Center)
59          .fontSize(20)
60      }
61      .type(ButtonType.Capsule)
62      .backgroundColor(Color.White)
63      .margin({ top: 20 })
64      .onClick(() => {
65        this.controller.close()
66      })
67    }
68    .backgroundColor(Color.White)
69    .border({ color: Color.White, radius: 20 })
70    .padding(10)
71  }
72}