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