1/* 2 * Copyright (c) 2022-2023 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 '../common/constant'; 17import GlobalContext from '../common/GlobalContext'; 18 19@Extend(Button) 20function customizeButton() { 21 .backgroundColor(Color.Transparent) 22 .fontColor($r('app.color.button_text_color')) 23 .fontSize(Constants.BUTTON_TEXT_FONT_SIZE) 24 .fontWeight(Constants.BUTTON_TEXT_FONT_WEIGHT) 25 .height(Constants.BUTTON_HEIGHT) 26 .width(Constants.BUTTON_WIDTH) 27} 28 29@CustomDialog 30struct HighCustomDialog { 31 controller?: CustomDialogController 32 cancel: () => void = () => { 33 } 34 35 build() { 36 Column() { 37 Column(){ 38 Row(){ 39 Text($r('app.string.TEXT_HIGH_TEMPERATURE_THERMALDIALOG_HIGH')) 40 .fontSize(Constants.DIALOG_TITLE_FONT_SIZE) 41 .fontColor($r('app.color.title_color')) 42 .fontWeight(Constants.DIALOG_TITLE_FONT_WEIGHT) 43 .lineHeight(Constants.DIALOG_TITLE_LINE_HEIGHT) 44 .opacity(Constants.DIALOG_TITLE_OPACITY) 45 } 46 }.margin({ 47 top: Constants.DIALOG_TITLE_MARGIN_TOP, 48 bottom: Constants.DIALOG_TITLE_MARGIN_BOTTOM 49 }) 50 Row() { 51 Button($r('app.string.BUTTON_KNOW')) 52 .onClick(() => { 53 if (this.controller) { 54 this.controller.close() 55 } 56 this.cancel(); 57 }).customizeButton() 58 } 59 } 60 .backgroundColor($r('app.color.default_background_color')) 61 .borderRadius(Constants.DIALOG_BORDER_RADIUS) 62 .width(Constants.DIALOG_WIDTH) 63 .height(Constants.DIALOG_HEIGHT) 64 } 65} 66 67@Entry 68@Component 69struct HighDialog { 70 dialogController: CustomDialogController = new CustomDialogController({ 71 builder: HighCustomDialog({ 72 cancel: this.onCancel, 73 }), 74 cancel: this.existApp, 75 autoCancel: false, 76 alignment: DialogAlignment.Center, 77 offset: { dx: 0, dy: -20 }, 78 gridCount: 4, 79 customStyle: false 80 }) 81 82 onCancel() { 83 (GlobalContext.getContext().getObject('thermalHighWindow') as Record<string, Function>).destroy(); 84 GlobalContext.getContext().setObject('g_thermalHighWindowFirst', undefined); 85 (GlobalContext.getContext().getObject('extensionContext') as Record<string, Function>).terminateSelf(); 86 } 87 88 existApp() { 89 this.onCancel(); 90 } 91 92 build() { 93 Column(this.dialogController.open()) {} 94 } 95} 96