• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15import vibrator from '@ohos.vibrator'
16import Logger from '../mode/Logger'
17
18let TAG = '[TextDialog]'
19
20@CustomDialog
21export struct TextDialog {
22  private controller: CustomDialogController
23
24  build() {
25    Column() {
26      Text($r('app.string.prompt'))
27        .fontSize(25)
28        .fontWeight(20)
29        .margin(10)
30        .fontColor('#1a1919')
31        .textAlign(TextAlign.Center)
32      Text($r('app.string.dialogText'))
33        .fontSize(20)
34      Row() {
35        Button() {
36          Text($r('app.string.yes'))
37            .fontSize(30)
38        }
39        .key('confirmDialog')
40        .backgroundColor(Color.White)
41        .margin({ top: 20, right: 40, bottom: 20 })
42        .onClick(() => {
43          try {
44            // 按照VIBRATOR_STOP_MODE_TIME模式停止振动
45            vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_TIME, (error) => {
46              if (error) {
47                Logger.error(TAG, `error.code: ${error.code} , error.message: ${error.message}`)
48                return;
49              }
50              Logger.info(TAG, `Callback returned to indicate successful.`)
51            })
52          } catch (err) {
53            Logger.error(TAG, `catch error.code: ${err.code} , error.message: ${err.message}`)
54          } finally {
55            this.controller.close()
56          }
57        })
58
59        Divider()
60          .height(30)
61          .vertical(true)
62          .strokeWidth(2)
63          .color('#999999')
64        Button() {
65          Text($r('app.string.no'))
66            .fontSize(30)
67        }
68        .backgroundColor(Color.White)
69        .margin({ top: 20, left: 40, bottom: 20 })
70        .onClick(() => {
71          this.controller.close()
72        })
73      }
74    }.id('textDialog')
75
76  }
77}