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 statusBarMarginLeftRight: Resource = $r("app.float.signal_status_margin_Left_right") 34 @State statusBarWifiWidth: Resource = $r('app.float.status_bar_wifi_width') 35 @State statusBarWifiHeight: Resource = $r('app.float.status_bar_wifi_height') 36 37 aboutToAppear() { 38 Log.showInfo(TAG, `aboutToAppear`) 39 this.mStatusBarGroupComponentData = StatusBarVM.getStatusBarGroupComponentData(this.mGroupId) 40 mWifiModel.initWifiModel() 41 } 42 43 aboutToDisappear() { 44 Log.showInfo(TAG, `aboutToDisappear`) 45 } 46 47 build() { 48 Row() { 49 if (this.wifiStatus) { 50 Row().width(this.statusBarMarginLeftRight).height('100%') 51 Image(this.getImage(this.wifiInfo)) 52 .objectFit(ImageFit.Contain) 53 .width(this.statusBarWifiWidth) 54 .height(this.statusBarWifiHeight) 55 .fillColor(this.mStatusBarGroupComponentData.contentColor) 56 Row().width(this.statusBarMarginLeftRight).height('100%') 57 } 58 } 59 .height('100%') 60 } 61 62 private getImage(wifiInfo: number) { 63 Log.showInfo(TAG, `getImage, wifiInfo: ${JSON.stringify(wifiInfo)}`) 64 let wifiImage; 65 switch (wifiInfo) { 66 case Constants.WIFI_SIGNAL_NO: 67 wifiImage = $r('app.media.ic_statusbar_wifi_no'); 68 break; 69 case Constants.WIFI_SIGNAL_LOW: 70 wifiImage = $r('app.media.ic_statusbar_wifi_1'); 71 break; 72 case Constants.WIFI_SIGNAL_MID: 73 wifiImage = $r('app.media.ic_statusbar_wifi_2'); 74 break; 75 case Constants.WIFI_SIGNAL_HIGH: 76 wifiImage = $r('app.media.ic_statusbar_wifi_3'); 77 break; 78 case Constants.WIFI_SIGNAL_FULL: 79 wifiImage = $r('app.media.ic_statusbar_wifi_full'); 80 break; 81 default: 82 wifiImage = $r('app.media.ic_statusbar_wifi_no'); 83 break; 84 } 85 return wifiImage; 86 } 87} 88