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, ScreenLockStatus} from '@ohos/common' 17import screenLockService from '../model/screenLockService' 18 19const TAG = 'ScreenLock-LockIconViewModel' 20 21export default class LockIconViewModel { 22 cutMessage: any= {} 23 iconPath: any= {} 24 25 ViewModelInit(): void{ 26 Log.showDebug(TAG, `ViewModelInit`); 27 this.iconPath = $r('app.media.ic_public_lock_filled'); 28 this.cutMessage = $r('app.string.lock_prompt') 29 } 30 31 onStatusChange(lockStatus: ScreenLockStatus): void { 32 Log.showInfo(TAG, `onStatusChange lockStatus:${lockStatus}`); 33 switch (lockStatus) { 34 case ScreenLockStatus.Locking: 35 this.iconPath = $r('app.media.ic_public_lock_filled'); 36 this.cutMessage = $r('app.string.lock_prompt') 37 break; 38 case ScreenLockStatus.Unlock: 39 this.iconPath = $r('app.media.ic_public_unlock_filled'); 40 this.cutMessage = $r('app.string.unlock_prompt') 41 break; 42 case ScreenLockStatus.RecognizingFace: 43 this.iconPath = $r('app.media.ic_public_unlock_filled'); 44 this.cutMessage = $r('app.string.recognizing_face') 45 break; 46 case ScreenLockStatus.FaceNotRecognized: 47 this.iconPath = $r('app.media.ic_public_unlock_filled'); 48 this.cutMessage = $r('app.string.face_not_recognized') 49 break; 50 default: 51 this.iconPath = $r('app.media.ic_public_lock_filled'); 52 this.cutMessage = $r('app.string.lock_prompt') 53 break; 54 } 55 } 56 57 onRecognizeFace(lockStatus: ScreenLockStatus) { 58 Log.showInfo(TAG, `onRecognizeFace lockStatus: ${lockStatus}`); 59 if (lockStatus == ScreenLockStatus.FaceNotRecognized) { 60 screenLockService.authUserByFace() 61 } 62 } 63}