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