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