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