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@CustomDialog
29struct LowCustomDialog {
30  controller?: CustomDialogController
31  cancel: () => void = () => {
32  }
33
34  build() {
35    Column() {
36      Column(){
37        Row(){
38          Text($r('app.string.TEXT_LOW_TEMPERATURE_THERMALDIALOG_LOW'))
39            .fontSize(Constants.DIALOG_TITLE_FONT_SIZE)
40            .fontColor($r('app.color.title_color'))
41            .fontWeight(Constants.DIALOG_TITLE_FONT_WEIGHT)
42            .lineHeight(Constants.DIALOG_TITLE_LINE_HEIGHT)
43            .opacity(Constants.DIALOG_TITLE_OPACITY)
44        }
45      }.margin({
46        top: Constants.DIALOG_TITLE_MARGIN_TOP,
47        bottom: Constants.DIALOG_TITLE_MARGIN_BOTTOM
48      })
49      Row() {
50        Button($r('app.string.BUTTON_KNOW'))
51          .onClick(() => {
52            if (this.controller) {
53            this.controller.close()
54            }
55            this.cancel();
56          }).customizeButton()
57      }
58    }
59    .backgroundColor($r('app.color.default_background_color'))
60    .borderRadius(Constants.DIALOG_BORDER_RADIUS)
61    .width(Constants.DIALOG_WIDTH)
62    .height(Constants.DIALOG_HEIGHT)
63  }
64}
65
66@Entry
67@Component
68struct LowDialog {
69  dialogController: CustomDialogController = new CustomDialogController({
70    builder: LowCustomDialog({
71      cancel: this.onCancel,
72    }),
73    cancel: this.existApp,
74    autoCancel: false,
75    alignment: DialogAlignment.Center,
76    offset: { dx: 0, dy: -20 },
77    gridCount: 4,
78    customStyle: false
79  })
80
81  onCancel() {
82    (GlobalContext.getContext().getObject('thermalLowWindow') as Record<string, Function>).destroy();
83    GlobalContext.getContext().setObject('g_thermalLowWindowFirst', undefined);
84    (GlobalContext.getContext().getObject('extensionContext') as Record<string, Function>).terminateSelf();
85  }
86
87  existApp() {
88    this.onCancel();
89  }
90
91  build() {
92    Column(this.dialogController.open()) {}
93  }
94}
95