1/* 2 * Copyright (c) 2024 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'; 16import { BusinessError } from '@ohos.base'; 17import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 18import deviceInfo from '@ohos.deviceInfo'; 19import Constant from '../common/constant'; 20 21let TAG = '[DeviceManagerUI:BluetoothDialog]==>'; 22 23@CustomDialog 24struct BluetoothCustomDialog { 25 @State btnColor: ResourceColor = Color.Transparent; 26 @State isPC: boolean = false; 27 controller?: CustomDialogController 28 29 aboutToAppear() { 30 console.log(TAG + 'aboutToAppear execute BluetoothCustomDialog'); 31 this.isPC = Constant.isPC(); 32 } 33 34 build() { 35 GridRow({ 36 columns: { xs: 4, sm: 8, md: this.isPC ? 24 : 12 }, 37 gutter: { x: 4 }, 38 breakpoints: { value: ['600vp', '840vp'] } 39 }) { 40 GridCol({ span: { xs: 4, sm: 4, md: this.isPC ? 6 : 4 }, offset: { sm: 2, md: this.isPC ? 9 : 4 } }) { 41 Column() { 42 Flex({ justifyContent: FlexAlign.Center }) { 43 Text($r('app.string.dm_bluetooth_dialog_content')) 44 .fontSize($r('sys.float.ohos_id_text_size_body1')) 45 .fontColor($r('sys.color.ohos_id_color_text_primary')) 46 .fontWeight(FontWeight.Regular) 47 .margin({ 48 left: 24, 49 right: 24 50 }) 51 .flexBasis('auto') 52 .width('auto') 53 } 54 .margin({ 55 bottom: this.isPC ? 16 : 8, 56 top: this.isPC ? 32 : 24 57 }) 58 59 Flex({ justifyContent: FlexAlign.Center }) { 60 Button($r('app.string.dm_bluetooth_dialog_close')) 61 .fontSize($r('sys.float.ohos_id_text_size_button1')) 62 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 63 .height(40) 64 .width('100%') 65 .backgroundColor(this.btnColor) 66 .onClick(() => { 67 if (this.controller) { 68 this.controller.close(); 69 } 70 let session = AppStorage.get<UIExtensionContentSession>('bluetoothSession'); 71 if (session) { 72 session.terminateSelf(); 73 } 74 }) 75 .onHover((isHover?: boolean, event?: HoverEvent): void => { 76 if (isHover) { 77 this.btnColor = $r('sys.color.ohos_id_color_hover'); 78 } else { 79 this.btnColor = this.isPC ? $r('sys.color.ohos_id_color_button_normal') : Color.Transparent; 80 } 81 }) 82 .stateStyles({ 83 pressed: { 84 .backgroundColor($r('sys.color.ohos_id_color_click_effect')) 85 }, 86 normal: { 87 .backgroundColor(this.isPC ? $r('sys.color.ohos_id_color_button_normal') : Color.Transparent) 88 } 89 }) 90 }.margin({ 91 left: this.isPC ? 72 : 16, 92 right: this.isPC ? 72 : 16, 93 bottom: this.isPC ? 24 : 16 }) 94 } 95 .constraintSize({ maxHeight: `${300}` }) 96 .borderRadius($r('sys.float.ohos_id_corner_radius_dialog')) 97 .backgroundBlurStyle(BlurStyle.COMPONENT_ULTRA_THICK) 98 .margin({ left: $r('sys.float.ohos_id_dialog_margin_start'), right: $r('sys.float.ohos_id_dialog_margin_end') }) 99 } 100 } 101 } 102} 103 104@Entry 105@Component 106struct dialogPlusPage { 107 dialogController: CustomDialogController = new CustomDialogController({ 108 builder: BluetoothCustomDialog(), 109 autoCancel: false, 110 alignment: DialogAlignment.Center, 111 offset: { dx: 0, dy: -20 }, 112 customStyle: true, 113 maskColor: $r('sys.color.ohos_id_color_mask_thin') 114 }); 115 116 aboutToAppear() { 117 console.log(TAG + 'aboutToAppear execute') 118 } 119 120 aboutToDisappear() { 121 console.log(TAG + 'aboutToDisappear executed') 122 } 123 124 build() { 125 Column(this.dialogController.open()) 126 } 127}