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 hardware_deviceManager from '@ohos.distributedHardware.deviceManager' 16import Logger from '../model/Logger' 17 18const TAG: string = 'DeviceDialog' 19 20@CustomDialog 21export struct DeviceDialog { 22 controller: CustomDialogController 23 private deviceLists: Array<hardware_deviceManager.DeviceInfo> = [] 24 private selectedIndex: number 25 private selectedIndexChange: (selectedIndex: number) => void 26 27 build() { 28 Column() { 29 Text($r('app.string.choiceDevice')) 30 .fontSize(30) 31 .width('100%') 32 .fontColor(Color.Black) 33 .textAlign(TextAlign.Start) 34 .fontWeight(FontWeight.Bold) 35 List() { 36 ForEach(this.deviceLists, (item, index) => { 37 ListItem() { 38 Row() { 39 Text(item.deviceName) 40 .fontSize(21) 41 .width('90%') 42 .fontColor(Color.Black) 43 Image(index === this.selectedIndex ? $r('app.media.checked') : $r('app.media.uncheck')) 44 .width('8%') 45 .objectFit(ImageFit.Contain) 46 } 47 .height(55) 48 .onClick(() => { 49 Logger.info(TAG, `select device: ${item.deviceId}`) 50 if (index === this.selectedIndex) { 51 Logger.info(TAG, 'index === this.selectedIndex') 52 return 53 } 54 this.selectedIndex = index 55 this.controller.close() 56 this.selectedIndexChange(this.selectedIndex) 57 }) 58 } 59 }, item => item.deviceName) 60 }.width('100%').height("20%") 61 62 Button() { 63 Text($r('app.string.cancel')) 64 .width('90%') 65 .fontSize(21) 66 .fontColor('#0D9FFB') 67 .textAlign(TextAlign.Center) 68 } 69 .type(ButtonType.Capsule) 70 .backgroundColor(Color.White) 71 .onClick(() => { 72 this.controller.close() 73 }) 74 } 75 .padding(10) 76 .backgroundColor(Color.White) 77 .border({ color: Color.White, radius: 20 }) 78 } 79}