1/*
2 * Copyright (c) 2022-2023 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 BackComponent from '../component/backComponent';
17import Log from '../utils/log';
18import CommonController from '../controller/commonController';
19import FaceConfigController from '../controller/faceConfigController';
20import ConfirmDialog from '../component/confirmDialog';
21import router from '@system.router';
22
23@Extend(Span) function configSetSpanFormat() {
24  .fontColor($r('sys.color.ohos_id_color_text_secondary'))
25  .fontSize($r('sys.float.ohos_id_text_size_caption1'))
26  .fontWeight(FontWeight.Regular)
27}
28
29@Extend(Span) function configSetLinkFormat() {
30  .fontColor($r('sys.color.ohos_id_color_text_hyperlink'))
31  .fontSize($r('sys.float.ohos_id_text_size_caption1'))
32  .fontWeight(FontWeight.Medium)
33}
34
35@Extend(Text) function configDeleteData() {
36  .fontColor($r('sys.color.ohos_id_color_warning'))
37  .fontSize($r('sys.float.ohos_id_text_size_body1'))
38  .fontWeight(FontWeight.Medium)
39}
40
41@Entry
42@Component
43struct FaceConfig {
44  @State readonly TAG: string = 'FaceConfig';
45  @State touched: boolean = false;
46  @StorageLink('CONTENT_TYPE_WIDTH') CONTENT_TYPE_WIDTH: number = 0;
47  @StorageLink('CARD_TYPE_WIDTH') CARD_TYPE_WIDTH: number = 0;
48
49  private deleteFaceDialogController: CustomDialogController = new CustomDialogController({
50    builder: ConfirmDialog({
51      title: $r('app.string.delete_record_title'),
52      content: $r('app.string.wether_delete_face_data'),
53      confirmText: $r('app.string.face_record_delete'),
54      cancelText: $r('app.string.face_record_cancel'),
55      confirmOperation: FaceConfigController.deleteFace
56    }),
57    alignment: CommonController.getDialogAlignment(),
58    offset: {
59      dx : '0vp',
60      dy : CommonController.getDialogYOffset()
61    }
62  });
63
64  build() {
65    Column() {
66      Column() {
67        BackComponent({ prevTag: this.TAG, title: $r('app.string.face_checker') })
68        Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
69          Row() {
70            Text($r('app.string.delete_record_title'))
71              .configDeleteData()
72              .margin({ left: '24vp', right: '24vp', top: '12vp', bottom: '12vp' })
73              .textAlign(TextAlign.Start);
74          }
75        }
76        .backgroundColor(this.touched ? '#D8D8D8' : '#FFFFFF')
77        .height('56vp')
78        .margin({
79          top: '8vp',
80          bottom: '8vp'
81        })
82        .borderRadius('24vp')
83        .onClick(() => {
84          this.deleteFaceDialogController.open()
85        })
86        .onTouch((event?: TouchEvent) => {
87          if (event !== undefined) {
88            if (event.type === TouchType.Down) {
89              this.touched = true;
90            }
91            if (event.type === TouchType.Up) {
92              this.touched = false;
93            }
94          }
95        });
96        Column() {
97          Text() {
98            Span($r('app.string.face_3dguide_info_2'))
99            .configSetSpanFormat()
100            Span($r('app.string.face_guide_2d_announce_link'))
101            .configSetLinkFormat()
102            .onClick(() => {
103              router.push({ uri: 'pages/enrollDeclare' })
104            })
105            Span($r('app.string.period'))
106            .configSetSpanFormat()
107          }
108          .textAlign(TextAlign.Start)
109        }
110        .margin({
111          left: '24vp',
112          right: '24vp'
113        })
114      }
115      .alignItems(HorizontalAlign.Start)
116      .width(this.CONTENT_TYPE_WIDTH)
117    }
118    .width('100%')
119    .height('100%')
120    .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
121    .onAreaChange((_, newArea) => {
122      Log.info(this.TAG, 'new display area :' + JSON.stringify(newArea))
123      CommonController.setDisplaySize(Number(newArea.width), Number(newArea.height))
124      Log.info(this.TAG, 'total area w: ' + newArea.width + ' h: ' + newArea.height)
125    })
126  }
127
128  onBackPress(): boolean {
129    Log.info(this.TAG, 'onBackPress+');
130    CommonController.routeBack();
131    Log.info(this.TAG, 'onBackPress-');
132    return true;
133  }
134}