• 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 statusBarClockMaxWidth: Resource = $r('app.float.status_bar_clock_width')
35  @State statusBarMarginLeftRight: Resource = $r("app.float.signal_status_margin_Left_right")
36  @State statusBarFontSize: Resource = $r("app.float.signal_fontSize")
37  unSubscriber?: unsubscribe;
38
39  aboutToAppear() {
40    Log.showInfo(TAG, 'aboutToAppear');
41    this.mStatusBarGroupComponentData = StatusBarVM.getStatusBarGroupComponentData(this.mGroupId)
42    this.unSubscriber = EventManager.subscribe(TIME_CHANGE_EVENT, (args: TimeEventArgs) => {
43      this.mTime = TimeManager.formatTime(args.date);
44    });
45    this.mTime = TimeManager.formatTime(new Date());
46  }
47
48  aboutToDisappear() {
49    Log.showInfo(TAG, 'aboutToDisappear');
50    this.unSubscriber && this.unSubscriber();
51    this.unSubscriber = undefined;
52  }
53
54  build() {
55    Row() {
56      Row().width(this.statusBarMarginLeftRight).height('100%')
57      Text(this.mTime)
58        .fontColor(this.mStatusBarGroupComponentData.contentColor)
59        .fontSize(this.statusBarFontSize)
60        .width(this.statusBarClockMaxWidth)
61        .fontWeight(FontWeight.Medium)
62        .margin({ left: $r("app.float.status_bar_clock_margin") })
63      Row().width(this.statusBarMarginLeftRight).height('100%')
64    }
65  }
66}