• 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 display from '@ohos.display'
17import Logger from '../model/Logger'
18
19const TAG: string = '[ShowInfo]'
20
21@CustomDialog
22export struct ShowInfo {
23  private defaultOrAllScreen?: boolean
24  private allScreens?: display.Display[]
25  private defaultScreens?: display.Display
26  private dialogController?: CustomDialogController
27
28  @Builder infoText(types: Resource, infos: string) {
29    Row() {
30      Text(types)
31        .margin({ right: 5 })
32        .fontSize(18)
33      Text(infos)
34        .margin({ left: 5 })
35        .fontSize(18)
36    }
37    .margin(5)
38  }
39
40  screenInfo(types: string) {
41    Logger.info(TAG, `defaultOrAllScreen = ${this.defaultOrAllScreen}`)
42    let info: string = ''
43    if (this.defaultOrAllScreen) {
44      const SCREEN_INFO = {
45        id: `${this.defaultScreens.id}`,
46        refreshRate: `${this.defaultScreens.refreshRate}`,
47        width: `${this.defaultScreens.width}`,
48        height: `${this.defaultScreens.height}`
49      }
50      info = SCREEN_INFO[types]
51    } else {
52      let ids: string = ''
53      let refreshRates: string = ''
54      let widths: string = ''
55      let heights: string = ''
56      for (let i = 0; i < this.allScreens.length; i++) {
57        ids = `${ids} ${this.allScreens[i].id}`
58        refreshRates = `${refreshRates} ${this.allScreens[i].refreshRate}`
59        widths = `${widths} ${this.allScreens[i].width}`
60        heights = `${heights} ${this.allScreens[i].height}`
61      }
62      const SCREENS_INFO = {
63        id: ids,
64        refreshRate: refreshRates,
65        width: widths,
66        height: heights
67      }
68      info = SCREENS_INFO[types]
69    }
70    Logger.info(TAG, `this info is ${info}`)
71    return info
72  }
73
74  build() {
75    Column() {
76      Text($r('app.string.info'))
77        .margin(10)
78        .fontSize(20)
79        .key('deviceInfo')
80
81      Column() {
82        this.infoText($r('app.string.id'), this.screenInfo('id'))
83        this.infoText($r('app.string.refreshRate'), this.screenInfo('refreshRate'))
84        this.infoText($r('app.string.width'), this.screenInfo('width'))
85        this.infoText($r('app.string.height'), this.screenInfo('height'))
86      }
87      .padding(5)
88      .width('100%')
89      .borderRadius(10)
90      .alignItems(HorizontalAlign.Start)
91    }
92    .padding(5)
93    .width('100%')
94    .borderRadius(10)
95    .alignItems(HorizontalAlign.Start)
96    .onClick(() => {
97      this.dialogController.close()
98    })
99  }
100}