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, Trace, styleManager as CommonStyleManager, AbilityManager} from '@ohos/common' 17import {LockStyleMode} from '../../../../../../features/screenlock/src/main/ets/com/ohos/model/screenlockStyle' 18import ViewModel from '../vm/indexViewModel' 19import SlideScreenLock from './slidescreenlock' 20import CustomScreenLock from './customscreenlock' 21import JournalScreenLock from './journalscreenlock' 22import Constants from '../common/constants' 23import StyleManager from '../common/StyleManager' 24import Router from '@system.router'; 25import { ScreenRect } from '../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/common/constants' 26 27const TAG = 'ScreenLock-Entry'; 28 29@Entry 30@Component 31struct Index { 32 @State mViewModel: ViewModel = new ViewModel() 33 @State pageStatus: number = Constants.STATUS_ABOUT_TO_APPEAR 34 @State mHeightPx: number = 0 35 36 aboutToAppear() { 37 Log.showInfo(TAG, `aboutToAppear`) 38 try { 39 CommonStyleManager.setAbilityPageName(TAG) 40 let configInfo: ScreenRect = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_STATUS_BAR, 'rect') 41 Log.showDebug(TAG, `configMaxWidth${JSON.stringify(configInfo.height)}`) 42 this.mHeightPx = configInfo.height 43 StyleManager.setStyle() 44 this.pageStatus = Constants.STATUS_ABOUT_TO_APPEAR 45 } catch (error) { 46 Log.showDebug(TAG, `set status error:` + JSON.stringify(error)); 47 } 48 this.mViewModel.ViewModelInit() 49 } 50 51 aboutToDisappear() { 52 Log.showInfo(TAG, `aboutToDisAppear`) 53 this.pageStatus = Constants.STATUS_ABOUT_TO_DISAPPEAR 54 this.mViewModel.ViewModelDestroy() 55 } 56 57 onPageShow() { 58 Trace.end(Trace.CORE_METHOD_SLEEP_TO_LOCK_SCREEN); 59 Trace.end(Trace.CORE_METHOD_SHOW_LOCK_SCREEN); 60 Log.showInfo(TAG, `onPageShow`) 61 this.pageStatus = Constants.STATUS_ON_PAGE_SHOW 62 this.mViewModel.onPageShow(); 63 } 64 65 onPageHide() { 66 Log.showInfo(TAG, `onPageHide`) 67 this.pageStatus = Constants.STATUS_ON_PAGE_HIDE 68 } 69 70 onBackPress(): boolean { 71 let length = parseInt(Router.getLength()) 72 Log.showInfo(TAG, `onBackPress length: ${length}`) 73 if (length > 1) { 74 Router.back() 75 return false 76 } 77 return true 78 } 79 80 build() { 81 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 82 if (this.mViewModel.mode == LockStyleMode.SlideScreenLock) { 83 // Slide of lock screen 84 SlideScreenLock({ pageStatus: this.pageStatus, mHeightPx: this.mHeightPx }) 85 } else if (this.mViewModel.mode == LockStyleMode.JournalScreenLock) { 86 JournalScreenLock() 87 } else if (this.mViewModel.mode == LockStyleMode.CustomScreenLock) { 88 CustomScreenLock() 89 } 90 } 91 } 92} 93 94