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 Accounts from '../../../../../../features/screenlock/src/main/ets/com/ohos/view/component/accounts' 18import {UserData} from '../../../../../../features/screenlock/src/main/ets/com/ohos/data/userData' 19import DateTime from '../../../../../../features/datetimecomponent/src/main/ets/com/ohos/view/component/dateTime' 20import LockIcon from '../../../../../../features/screenlock/src/main/ets/com/ohos/view/component/lockIcon' 21import Wallpaper from '../../../../../../features/wallpapercomponent/src/main/ets/com/ohos/view/component/wallpaper' 22import NotificationListComponent from '../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/view/NotificationListComponent' 23import StatusBar from '../../../../../../features/screenlock/src/main/ets/com/ohos/view/component/statusBar' 24import Constants from '../common/constants' 25import ViewModel from '../vm/slideScreenLockViewModel' 26 27const TAG = 'ScreenLock-SlideScreenlock' 28 29@Component 30export default struct SlideScreenlock { 31 @State mViewModel: ViewModel = new ViewModel() 32 @StorageLink('batteryCharging') @Watch('onCharging') batteryCharging: boolean = false 33 @Prop @Watch("onStatusChange") pageStatus: number 34 @StorageLink('deviceStatus') @Watch('onDeviceStatusChange') deviceStatus: string = "" 35 @StorageLink('isWallpaperShow') isWallpaperShow: boolean = true 36 private mHeightPx : number = 48 37 aboutToAppear() { 38 Log.showInfo(TAG, `aboutToAppear`) 39 this.mViewModel.ViewModelInit() 40 } 41 42 aboutToDisappear() { 43 Log.showInfo(TAG, `aboutToDisAppear`) 44 } 45 46 onPageShow() { 47 Log.showInfo(TAG, `onPageShow`) 48 } 49 50 onPageHide() { 51 Log.showInfo(TAG, `onPageHide`) 52 } 53 54 build() { 55 Stack({ alignContent: Alignment.Bottom }) { 56 Column() { 57 Wallpaper() 58 } 59 .backgroundColor($r('app.color.screenlock_backgroundcolor')) 60 .width(Constants.FULL_CONTAINER_WIDTH) 61 .height(Constants.FULL_CONTAINER_HEIGHT) 62 .scale({ 63 x: this.mViewModel.backgroundScale, 64 y: this.mViewModel.backgroundScale 65 }) 66 .animation({ 67 duration: this.mViewModel.duration, // animation duration 68 curve: Curve.Linear, // animation curve 69 delay: 0, // animation delay 70 iterations: 1, // times of play 71 playMode: PlayMode.Normal // animation mode 72 }) 73 74 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { 75 Column() { 76 StatusBar() 77 } 78 .height(this.mHeightPx + 'px' ) 79 .onAreaChange((e, e2) => { 80 Log.showDebug(TAG, `onAreaChange, e: ${JSON.stringify(e)} e2: ${JSON.stringify(e2)}`); 81 }) 82 } 83 84 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { 85 Column() { 86 } 87 .height(0) 88 89 Column() { 90 Row() { 91 Blank() 92 Accounts() 93 } 94 .width(Constants.NOTIFICATION_AREA_WIDTH) 95 .height($r("app.float.accounts_area_height")) 96 } 97 .margin({ top: $r("app.float.accounts_area_margin_top") }) 98 99 Column() { 100 LockIcon() 101 }.height(Constants.P_LOCKICON_AREA_WIDTH) 102 103 Column() { 104 DateTime({ isShowDate: true }) 105 }.height(Constants.P_DATETIME_AREA_WIDTH) 106 .margin({ top: $r("app.float.DateTime_margin_top"), bottom: $r("app.float.DateTime_margin_bottom") }) 107 108 Column() { 109 NotificationListComponent() 110 } 111 .alignItems(HorizontalAlign.Center) 112 .width(Constants.NOTIFICATION_AREA_WIDTH) 113 } 114 .width(Constants.FULL_CONTAINER_WIDTH) 115 .height(Constants.FULL_CONTAINER_HEIGHT) 116 .opacity(this.mViewModel.elementAlpha) 117 .scale({ 118 x: this.mViewModel.elementScale, 119 y: this.mViewModel.elementScale 120 }) 121 .animation({ 122 duration: this.mViewModel.duration, // animation duration 123 curve: Curve.Linear, // animation curve 124 delay: 0, // animation delay 125 iterations: 1, // times of play 126 playMode: PlayMode.Normal // animation mode 127 }) 128 .onTouch((event) => { 129 this.mViewModel.touchEvent(event) 130 }) 131 } 132 } 133 134 onCharging(propName: string): void { 135 Log.showInfo(TAG, `onCharging ${this.batteryCharging}`) 136 this.mViewModel.toggleDisplay(this.batteryCharging); 137 } 138 139 onStatusChange(propName: string): void { 140 Log.showInfo(TAG, `onStatusChange ${this.pageStatus}`) 141 switch (this.pageStatus) { 142 case Constants.STATUS_ON_PAGE_SHOW: 143 this.mViewModel.onPageShow(); 144 break; 145 default: 146 } 147 } 148 149 onDeviceStatusChange(propName: string): void{ 150 Log.showInfo(TAG, `onDeviceStatusChange ${this.deviceStatus}`) 151 if (this.deviceStatus == "endScreenOn") { 152 if (this.batteryCharging) { 153 this.mViewModel.toggleDisplay(); 154 } 155 } 156 } 157}