• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ViewModel from '../../vm/lockIconViewModel'
18import Constants from '../../common/constants'
19
20const TAG = 'ScreenLock-LockIcon'
21
22@Component
23export default struct LockIcon {
24  @StorageLink('lockStatus') @Watch("onStatusChange") lockStatus: ScreenLockStatus = ScreenLockStatus.Locking
25  @State mViewModel: ViewModel = new ViewModel()
26
27  aboutToAppear() {
28    Log.showInfo(TAG, `aboutToAppear`)
29    this.mViewModel.ViewModelInit()
30  }
31
32  build() {
33    Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
34      Image(this.mViewModel.iconPath)
35        .margin({ top: $r('app.float.lockicon_top_margin'), bottom: $r('app.float.lockicon_bottom_margin') })
36        .objectFit(ImageFit.Contain)
37        .width($r('app.float.lockicon_width'))
38        .height($r('app.float.lockicon_height'))
39        .fillColor($r('app.color.lock_ic_color'))
40      Text(this.mViewModel.cutMessage).fontSize($r('app.float.lock_prompt_fontsize'))
41        .fontColor($r('app.color.lock_prompt_color'))
42        .margin({ top: $r("app.float.lock_Text_top_margin") })
43    }
44    .width(Constants.FULL_CONTAINER_WIDTH)
45    .gesture(GestureGroup(GestureMode.Exclusive, TapGesture({ count: 2 })
46      .onAction((event: GestureEvent) => {
47        Log.showInfo(TAG, 'double click');
48        this.mViewModel.onRecognizeFace(this.lockStatus);
49      })
50    ))
51  }
52
53  onStatusChange(propName: string): void {
54    Log.showInfo(TAG, `lockStatus:${this.lockStatus}`);
55    this.mViewModel.onStatusChange(this.lockStatus)
56  }
57}