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 Log from '../../../../../../../../common/src/main/ets/default/Log'
17import { TintContentInfo } from '../../../../../../../../common/src/main/ets/default/TintStateManager'
18import StyleConfigurationCommon, { CommonStyle
19} from '../../../../../../../../common/src/main/ets/default/StyleConfiguration'
20import StyleConfiguration, { StatusRingModeComponentStyle } from '../common/StyleConfiguration'
21import Constants, { AudioRingMode } from '../common/Constants'
22import ViewModel from '../viewmodel/RingModeVM'
23
24const TAG = 'ringmode-StatusBarIconItemRingModeComponent'
25
26@Component
27export default struct StatusBarIconItemRingModeComponent {
28  @StorageLink('RingModeComponentMode') RingModeComponentMode: AudioRingMode = AudioRingMode.RINGER_MODE_NORMAL
29  @State mTintContentInfo: TintContentInfo = ViewModel.getTintContentInfo()
30  @State styleCommon: CommonStyle = StyleConfigurationCommon.getCommonStyle()
31  @State style: StatusRingModeComponentStyle = StyleConfiguration.getStatusRingModeComponentStyle()
32  private ringModeIcons: any
33
34  aboutToAppear() {
35    Log.showInfo(TAG, 'aboutToAppear');
36    this.ringModeIcons = {};
37    this.ringModeIcons[AudioRingMode.RINGER_MODE_SILENT.toString()] = $r("app.media.ic_statusbar_ring_off_filled");
38    this.ringModeIcons[AudioRingMode.RINGER_MODE_VIBRATE.toString()] = $r("app.media.ic_statusbar_vibration_on");
39    ViewModel.initViewModel();
40  }
41
42  aboutToDisappear() {
43    Log.showInfo(TAG, 'aboutToDisappear');
44  }
45
46  build() {
47    Row() {
48      if (this.RingModeComponentMode != AudioRingMode.RINGER_MODE_NORMAL) {
49        Row().width(this.styleCommon.statusBarMarginLeftRight).height('100%')
50        Image(this.ringModeIcons[this.RingModeComponentMode.toString()])
51          .objectFit(ImageFit.Contain)
52          .width(this.style.statusBarRingModeWidth)
53          .height(this.style.statusBarRingModeHeight)
54          .fillColor(this.mTintContentInfo.contentColor)
55        Row().width(this.styleCommon.statusBarMarginLeftRight).height('100%')
56      }
57    }
58    .height('100%')
59    .opacity($r("app.float.icon_component_opacity"))
60  }
61}