• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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/constants'
17import mWifiModel from '../wifiModel'
18import {Log} from '@ohos/common'
19import {StatusBarGroupComponentData} from '../../../../../../screenlock/src/main/ets/com/ohos/common/constants'
20import StatusBarVM from '../../../../../../screenlock/src/main/ets/com/ohos/vm/StatusBarVM'
21
22const TAG = 'WifiComponent-WifiIcon'
23
24@Component
25export default struct WifiIcon {
26  @StorageLink('wifiInfo') wifiInfo: number = Constants.DEFAULT_WIFI_INFO
27  @StorageLink('wifiStatus') wifiStatus: boolean = Constants.DEFAULT_WIFI_STATUS
28  private mGroupId: string = ''
29  @State mStatusBarGroupComponentData: StatusBarGroupComponentData = new StatusBarGroupComponentData()
30  @State statusBarMarginLeftRight: Resource = $r("app.float.signal_status_margin_Left_right")
31  @State statusBarWifiWidth: Resource = $r('app.float.status_bar_wifi_width')
32  @State statusBarWifiHeight: Resource = $r('app.float.status_bar_wifi_height')
33
34  aboutToAppear() {
35    Log.showInfo(TAG, `aboutToAppear`)
36    this.mStatusBarGroupComponentData = StatusBarVM.getStatusBarGroupComponentData(this.mGroupId)
37    mWifiModel.initWifiModel()
38  }
39
40  aboutToDisappear() {
41    Log.showInfo(TAG, `aboutToDisappear`)
42  }
43
44  build() {
45    Row() {
46      if (this.wifiStatus) {
47        Row().width(this.statusBarMarginLeftRight).height('100%')
48        Image(this.getImage(this.wifiInfo))
49          .objectFit(ImageFit.Contain)
50          .width(this.statusBarWifiWidth)
51          .height(this.statusBarWifiHeight)
52          .fillColor(this.mStatusBarGroupComponentData.contentColor)
53        Row().width(this.statusBarMarginLeftRight).height('100%')
54      }
55    }
56    .height('100%')
57  }
58
59  private getImage(wifiInfo: number) {
60    Log.showInfo(TAG, `getImage, wifiInfo: ${JSON.stringify(wifiInfo)}`)
61    let wifiImage: Resource | undefined = undefined;
62    switch (wifiInfo) {
63      case Constants.WIFI_SIGNAL_NO:
64        wifiImage = $r('app.media.ic_statusbar_wifi_no');
65        break;
66      case Constants.WIFI_SIGNAL_LOW:
67        wifiImage = $r('app.media.ic_statusbar_wifi_1');
68        break;
69      case Constants.WIFI_SIGNAL_MID:
70        wifiImage = $r('app.media.ic_statusbar_wifi_2');
71        break;
72      case Constants.WIFI_SIGNAL_HIGH:
73        wifiImage = $r('app.media.ic_statusbar_wifi_3');
74        break;
75      case Constants.WIFI_SIGNAL_FULL:
76        wifiImage = $r('app.media.ic_statusbar_wifi_full');
77        break;
78      default:
79        wifiImage = $r('app.media.ic_statusbar_wifi_no');
80        break;
81    }
82    return wifiImage;
83  }
84}
85