• 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 Log from '../../../../../../../common/src/main/ets/default/Log'
17import StyleConfiguration from '../common/StyleConfiguration'
18import StyleConfigurationCommon from '../../../../../../../common/src/main/ets/default/StyleConfiguration'
19import { StatusBarGroupComponentData } from '../../../../../../screenlock/src/main/ets/com/ohos/common/constants'
20import StatusBarVM from '../../../../../../screenlock/src/main/ets/com/ohos/vm/StatusBarVM'
21import TimeManager, {
22  TimeEventArgs,
23  TIME_CHANGE_EVENT,
24} from '../../../../../../../common/src/main/ets/default/TimeManager'
25import EventManager, { unsubscribe } from '../../../../../../../common/src/main/ets/default/event/EventManager'
26
27const TAG = 'ClockComponent-clockIcon';
28
29@Component
30export default struct ClockIcon {
31  @State mTime: string = '16:01'
32  private mGroupId: string = ''
33  @State mStatusBarGroupComponentData: StatusBarGroupComponentData = new StatusBarGroupComponentData()
34  @State style: any = StyleConfiguration.getClockComponentStyle()
35  @State styleCommon: any = StyleConfigurationCommon.getCommonStyle()
36  unSubscriber?: unsubscribe;
37
38  aboutToAppear() {
39    Log.showInfo(TAG, 'aboutToAppear');
40    this.mStatusBarGroupComponentData = StatusBarVM.getStatusBarGroupComponentData(this.mGroupId)
41    this.unSubscriber = EventManager.subscribe(TIME_CHANGE_EVENT, (args: TimeEventArgs) => {
42      this.mTime = TimeManager.formatTime(args.date);
43    });
44    this.mTime = TimeManager.formatTime(new Date());
45  }
46
47  aboutToDisappear() {
48    Log.showInfo(TAG, 'aboutToDisappear');
49    this.unSubscriber && this.unSubscriber();
50    this.unSubscriber = undefined;
51  }
52
53  build() {
54    Row() {
55      Row().width(this.styleCommon.statusBarMarginLeftRight).height('100%')
56      Text(this.mTime)
57        .fontColor(this.mStatusBarGroupComponentData.contentColor)
58        .fontSize(this.styleCommon.statusBarFontSize)
59        .width(this.style.statusBarClockMaxWidth)
60        .fontWeight(FontWeight.Medium)
61        .margin({ left: $r("app.float.status_bar_clock_margin") })
62      Row().width(this.styleCommon.statusBarMarginLeftRight).height('100%')
63    }
64  }
65}