1/* 2 * Copyright (c) 2021-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 Constants from '../utils/constant'; 17import audio from '@ohos.multimedia.audio' 18import camera from '@ohos.multimedia.camera' 19import deviceInfo from '@ohos.deviceInfo' 20import display from '@ohos.display'; 21 22let bottomPopoverTypes = ['default', 'phone'] 23 24@Extend(Button) function customizeButton() { 25 .backgroundColor($r('app.color.default_background_color')) 26 .fontColor($r('app.color.button_color')) 27 .fontWeight(FontWeight.Medium) 28 .height(Constants.BUTTON_HEIGHT) 29 .width(Constants.BUTTON_WIDTH) 30} 31 32@CustomDialog 33export struct authorizeDialog { 34 controller: CustomDialogController; 35 cancel: () => void; 36 confirm: () => void; 37 38 build() { 39 Column() { 40 Row() { 41 Flex({ justifyContent: FlexAlign.Center }) { 42 Text($r("app.string.Authorization_failed")).fontSize(Constants.DIALOG_TEXT_FONT_SIZE) 43 .margin({ 44 top: Constants.DIALOG_TEXT_MARGIN_TOP 45 }) 46 } 47 } 48 } 49 .backgroundColor($r('app.color.default_background_color')) 50 .borderRadius(Constants.DIALOG_BORDER_RADIUS) 51 .height(Constants.DIALOG_HEIGHT) 52 .width(Constants.DIALOG_WIDTH) 53 } 54} 55 56@CustomDialog 57export struct globalDialog { 58 @Link globalIsOn: boolean 59 @State isBottomPopover: boolean = true 60 controller: CustomDialogController; 61 62 build() { 63 GridRow({ columns: { xs: Constants.XS_COLUMNS, sm: Constants.SM_COLUMNS, md: Constants.MD_COLUMNS, lg: Constants.LG_COLUMNS }, gutter: Constants.DIALOG_GUTTER }) { 64 GridCol({ span: { xs: Constants.XS_SPAN, sm: Constants.SM_SPAN, md: Constants.DIALOG_MD_SPAN, lg: Constants.DIALOG_LG_SPAN }, 65 offset: {xs: Constants.XS_OFFSET, sm: Constants.SM_OFFSET, md: Constants.DIALOG_MD_OFFSET, lg: Constants.DIALOG_LG_OFFSET} }) { 66 Flex({ justifyContent: FlexAlign.Center, alignItems: this.isBottomPopover ? ItemAlign.End : ItemAlign.Center }) { 67 Column() { 68 Text(globalThis.currentPermissionGroup == 'CAMERA' ? $r('app.string.close_camera') : $r('app.string.close_microphone')) 69 .fontSize(Constants.TEXT_BIG_FONT_SIZE) 70 .fontColor($r('app.color.label_color')) 71 .fontWeight(FontWeight.Medium) 72 .lineHeight(Constants.TEXT_BIG_LINE_HEIGHT) 73 .height(Constants.ROW_HEIGHT) 74 .width(Constants.FULL_WIDTH) 75 .padding({ left: Constants.DIALOG_DESP_MARGIN_LEFT, right: Constants.DIALOG_DESP_MARGIN_RIGHT }) 76 Text(globalThis.currentPermissionGroup == 'CAMERA' ? $r('app.string.close_camera_desc') : $r('app.string.close_microphone_desc')) 77 .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) 78 .fontColor($r('app.color.label_color')) 79 .lineHeight(Constants.TEXT_LINE_HEIGHT) 80 .width(Constants.FULL_WIDTH) 81 .padding({ left: Constants.DIALOG_DESP_MARGIN_LEFT, right: Constants.DIALOG_DESP_MARGIN_RIGHT }) 82 .margin({ bottom: Constants.DIALOG_DESP_MARGIN_BOTTOM }) 83 Row() { 84 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Start }) { 85 Button($r('app.string.cancel')) 86 .fontSize(Constants.BUTTON_FONT_SIZE) 87 .onClick(() => { 88 this.cancel() 89 }).customizeButton().margin({ left: Constants.BUTTON_MARGIN_LEFT }) 90 Text('|').fontSize(Constants.BUTTON_DIVIDER_FONT_SIZE).fontColor($r('app.color.divider_color')) 91 .margin({ top: Constants.BUTTON_MARGIN_TOP }) 92 Button($r('app.string.close')) 93 .fontSize(Constants.BUTTON_FONT_SIZE) 94 .onClick(() => { 95 this.confirm() 96 }).customizeButton().margin({ right: Constants.BUTTON_MARGIN_RIGHT }) 97 }.height(Constants.ROW_HEIGHT) 98 } 99 } 100 .backgroundColor($r('app.color.default_background_color')) 101 .borderRadius(Constants.DIALOG_PRIVACY_BORDER_RADIUS) 102 .width(Constants.FULL_WIDTH) 103 .margin({ bottom: Constants.DIALOG_MARGIN_BOTTOM }) 104 }.width(Constants.FULL_WIDTH) 105 .height(Constants.FULL_HEIGHT) 106 } 107 }.margin({ left: this.isBottomPopover ? Constants.DIALOG_MARGIN_VERTICAL : Constants.DIALOG_MARGIN, 108 right: this.isBottomPopover ? Constants.DIALOG_MARGIN_VERTICAL : Constants.DIALOG_MARGIN }) 109 } 110 111 confirm() { 112 if(globalThis.currentPermissionGroup == 'CAMERA') { 113 let cameraManager = camera.getCameraManager(globalThis.context); 114 cameraManager.muteCamera(true); 115 this.globalIsOn = false; 116 this.controller.close(); 117 }else { 118 var audioManager = audio.getAudioManager(); 119 audioManager.setMicrophoneMute(true).then(() => { 120 this.globalIsOn = false 121 this.controller.close() 122 }) 123 } 124 } 125 126 cancel() { 127 this.controller.close() 128 } 129 130 aboutToAppear() { 131 try { 132 let dis = display.getDefaultDisplaySync(); 133 let isVertical = dis.width > dis.height ? false : true 134 this.isBottomPopover = bottomPopoverTypes.includes(deviceInfo.deviceType) && isVertical 135 } catch (exception) { 136 console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); 137 }; 138 } 139}