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