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