黄学彪
2020-12-16 28d269d8aa90eca5470fff825a9b9545135a3ec0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
using System;
using Shared;
 
namespace HDL_ON.UI
{
    public partial class AppUnlockSettingsPage
    {
        Action refreshAction;
        void LoadEventList()
        {
            LoadEvent_OptionChange();
            LoadEvent_InitOptionState();
 
            refreshAction = () =>
            {
                LoadView_UnlockView();
                //fingerprintUnlockDiv.Visible = sTouchID && (UserInfo.Current.appUnlockType.Contains("1") || UserInfo.Current.appUnlockType.Contains("2"));
                //faceIdUnlockDiv.Visible = sFaceID && (UserInfo.Current.appUnlockType.Contains("1") || UserInfo.Current.appUnlockType.Contains("2"));
                //btnFingerprintUnlockSwtichIcon.IsSelected = UserInfo.Current.appUnlockType.Contains("3");
                //btnFaceIdUnlockSwtichIcon.IsSelected = UserInfo.Current.appUnlockType.Contains("4");
            };
        }
 
        /// <summary>
        /// 加载密码选项事件
        /// </summary>
        void LoadEvent_OptionChange()
        {
            EventHandler<MouseEventArgs> eventHandler1 = (sender, e1) =>
            {
                Action action = () =>
                {
                    btnUnprotectedBg.IsSelected = btnUnprotectedSelectionIcon.IsSelected = btnUnprotectedSelectionTip.IsSelected = true;
                    btnStartupBg.IsSelected = btnStartupSelectionIcon.IsSelected = btnStartupSelectionTip.IsSelected = false;
                    btnSecurityBg.IsSelected = btnSecuritySelectionIcon.IsSelected = btnSecuritySelectionTip.IsSelected = false;
                    btnDoorlockBg.IsSelected = btnDoorlockSelectionIcon.IsSelected = btnDoorlockSelectionTip.IsSelected = false;
 
                    btnTipMsg.TextID = StringId.UnprotectedTipMsg;
 
                    UserInfo.Current.appUnlockPage = new System.Collections.Generic.List<string>();
                    UserInfo.Current.appUnlockType = new System.Collections.Generic.List<string>();
                    UserInfo.Current.appUnlockPasswrod = "";
                    UserInfo.Current.SaveUserInfo();
                    unlockOptionView.Visible = false;
                    refreshAction();
                };
                Action action1 = () =>
                {
                    if (!btnUnprotectedBg.IsSelected)
                    {
                        //1:验证指纹
                        if (UserInfo.Current.appUnlockType.Contains("3"))
                        {
                            TouchIDVerification_TurnOffUnlock(action);
                        }
                        else if (UserInfo.Current.appUnlockType.Contains("4"))
                        {
                            //Face ID验证
                            FaceIDVerification_TurnOffUnlock(action);
                        }
                        else if (UserInfo.Current.appUnlockType.Contains("1"))
                        {
                            var page = new AppUnlockPasswordPage(UserInfo.Current.appUnlockPasswrod, action);
                            MainPage.BasePageView.AddChidren(page);
                            page.LoadPage("4");
                            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                        }
                        else if (UserInfo.Current.appUnlockType.Contains("2"))
                        {
                            var page = new AppUnlockGesturePage(UserInfo.Current.appUnlockPasswrod, action);
                            MainPage.BasePageView.AddChidren(page);
                            page.LoadPage("4");
                            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                        }
                    }
                };
 
                if (UserInfo.Current.appUnlockPasswrod != "")
                {
                    new PublicAssmebly().TipOptionMsg(StringId.Tip, StringId.TipTurnOffUnlockingSetting, action1);
                }
                else
                {
                    action();
                }
            };
            btnUnprotectedBg.MouseUpEventHandler = eventHandler1;
            btnUnprotectedSelectionIcon.MouseUpEventHandler = eventHandler1;
            btnUnprotectedSelectionTip.MouseUpEventHandler = eventHandler1;
 
            EventHandler<MouseEventArgs> eventHandler2 = (sender, e) =>
            {
                bool result = !btnStartupBg.IsSelected;
                if (!result)
                {
                    //如果启动解锁 不能取消启动解锁
                    if (!CheckIfCanDeselect("1")) return;
                }
                btnStartupBg.IsSelected = btnStartupSelectionIcon.IsSelected = btnStartupSelectionTip.IsSelected = result;
 
                btnTipMsg.Text = Language.StringByID(StringId.AtStartupTipMsg);
                if (result)
                {
                    btnUnprotectedBg.IsSelected = btnUnprotectedSelectionIcon.IsSelected = btnUnprotectedSelectionTip.IsSelected = false;
                    if (!UserInfo.Current.appUnlockPage.Contains("1"))
                    {
                        UserInfo.Current.appUnlockPage.Add("1");
                        if (UserInfo.Current.appUnlockPasswrod != "")
                            UserInfo.Current.SaveUserInfo();
                    }
                    unlockOptionView.Visible = true;
                }
                else
                {
                    if (UserInfo.Current.appUnlockPage.Contains("1"))
                    {
                        UserInfo.Current.appUnlockPage.Remove("1");
                    }
                    if (UserInfo.Current.appUnlockPage.Count == 0)
                    {
                        btnUnprotectedBg.IsSelected = btnUnprotectedSelectionIcon.IsSelected = btnUnprotectedSelectionTip.IsSelected = true;
                        btnTipMsg.TextID = StringId.UnprotectedTipMsg;
                        UserInfo.Current.appUnlockPasswrod = "";
                        unlockOptionView.Visible = false;
                        refreshAction();
                    }
                    UserInfo.Current.SaveUserInfo();
                }
            };
            btnStartupBg.MouseUpEventHandler = eventHandler2;
            btnStartupSelectionIcon.MouseUpEventHandler = eventHandler2;
            btnStartupSelectionTip.MouseUpEventHandler = eventHandler2;
 
            EventHandler<MouseEventArgs> eventHandler3 = (sender, e) =>
            {
                bool result = !btnSecurityBg.IsSelected;
                if (!result)
                {
                    //如果只剩布防/撤防一种 不能取消布防/撤防
                    if (!CheckIfCanDeselect("2")) return;
                }
 
                btnSecurityBg.IsSelected = btnSecuritySelectionIcon.IsSelected = btnSecuritySelectionTip.IsSelected = result;
 
                btnTipMsg.Text = Language.StringByID(StringId.DefenseAndUndefenseTipMsg);
 
                if (result)
                {
                    btnUnprotectedBg.IsSelected = btnUnprotectedSelectionIcon.IsSelected = btnUnprotectedSelectionTip.IsSelected = false;
                    if (!UserInfo.Current.appUnlockPage.Contains("2"))
                    {
                        UserInfo.Current.appUnlockPage.Add("2");
                        if (UserInfo.Current.appUnlockPasswrod != "")
                            UserInfo.Current.SaveUserInfo();
                    }
                    unlockOptionView.Visible = true;
                }
                else
                {
                    if (UserInfo.Current.appUnlockPage.Contains("2"))
                    {
                        UserInfo.Current.appUnlockPage.Remove("2");
                    }
                    if (UserInfo.Current.appUnlockPage.Count == 0)
                    {
                        btnUnprotectedBg.IsSelected = btnUnprotectedSelectionIcon.IsSelected = btnUnprotectedSelectionTip.IsSelected = result;
                        btnTipMsg.TextID = StringId.UnprotectedTipMsg;
                        UserInfo.Current.appUnlockPasswrod = "";
                        unlockOptionView.Visible = false;
                        refreshAction();
                    }
                    UserInfo.Current.SaveUserInfo();
                }
            };
            btnSecurityBg.MouseUpEventHandler = eventHandler3;
            btnSecuritySelectionIcon.MouseUpEventHandler = eventHandler3;
            btnSecuritySelectionTip.MouseUpEventHandler = eventHandler3;
 
            EventHandler<MouseEventArgs> eventHandler4 = (sender, e) =>
            {
                bool result = !btnDoorlockBg.IsSelected;
                if (!result)
                {
                    //如果只剩远程开锁不能取消远程开锁
                    if (!CheckIfCanDeselect("3")) return;
                }
 
                btnDoorlockBg.IsSelected = btnDoorlockSelectionIcon.IsSelected = btnDoorlockSelectionTip.IsSelected = result;
 
                btnTipMsg.Text = Language.StringByID(StringId.RemoteUnlockingTipMsg);
                if (result)
                {
                    btnUnprotectedBg.IsSelected = btnUnprotectedSelectionIcon.IsSelected = btnUnprotectedSelectionTip.IsSelected = false;
                    if (!UserInfo.Current.appUnlockPage.Contains("3"))
                    {
                        UserInfo.Current.appUnlockPage.Add("3");
                        if (UserInfo.Current.appUnlockPasswrod != "")
                            UserInfo.Current.SaveUserInfo();
                    }
                    unlockOptionView.Visible = true;
                }
                else
                {
                    if (UserInfo.Current.appUnlockPage.Contains("3"))
                    {
                        UserInfo.Current.appUnlockPage.Remove("3");
                    }
                    if (UserInfo.Current.appUnlockPage.Count == 0)
                    {
                        btnUnprotectedBg.IsSelected = btnUnprotectedSelectionIcon.IsSelected = btnUnprotectedSelectionTip.IsSelected = true;
                        btnTipMsg.TextID = StringId.UnprotectedTipMsg;
                        UserInfo.Current.appUnlockPasswrod = "";
                        unlockOptionView.Visible = false;
                        refreshAction();
                    }
                    UserInfo.Current.SaveUserInfo();
                }
            };
            btnDoorlockBg.MouseUpEventHandler = eventHandler4;
            btnDoorlockSelectionIcon.MouseUpEventHandler = eventHandler4;
            btnDoorlockSelectionTip.MouseUpEventHandler = eventHandler4;
        }
 
        /// <summary>
        /// 加载用户密码选项状态
        /// </summary>
        void LoadEvent_InitOptionState()
        {
            if (UserInfo.Current.appUnlockPage.Count == 0)
            {
                btnUnprotectedBg.IsSelected = btnUnprotectedSelectionIcon.IsSelected = btnUnprotectedSelectionTip.IsSelected = true;
            }
            else
            {
                if (UserInfo.Current.appUnlockPage.Contains("1"))
                {
                    btnStartupBg.IsSelected = btnStartupSelectionIcon.IsSelected = btnStartupSelectionTip.IsSelected = true;
                    btnTipMsg.Text = Language.StringByID(StringId.AtStartupTipMsg);
                }
                if (UserInfo.Current.appUnlockPage.Contains("2"))
                {
                    btnSecurityBg.IsSelected = btnSecuritySelectionIcon.IsSelected = btnSecuritySelectionTip.IsSelected = true;
                    btnTipMsg.Text = Language.StringByID(StringId.DefenseAndUndefenseTipMsg);
                }
                if (UserInfo.Current.appUnlockPage.Contains("3"))
                {
                    btnDoorlockBg.IsSelected = btnDoorlockSelectionIcon.IsSelected = btnDoorlockSelectionTip.IsSelected = true;
                    btnTipMsg.Text = Language.StringByID(StringId.RemoteUnlockingTipMsg);
                }
            }
        }
 
        /// <summary>
        /// 密码设置跳转事件列表
        /// </summary>
        void LoadEvet_SkipEventList()
        {
            btnPasswordUnlockTitle.MouseUpEventHandler = (sender, e) =>
            {
                var page = new AppUnlockPasswordPage(UserInfo.Current.appUnlockPasswrod, refreshAction);
                MainPage.BasePageView.AddChidren(page);
                page.LoadPage(UserInfo.Current.appUnlockType.Contains("1") ? "3" : "1");
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
 
            btnResetPasswordTitle.MouseUpEventHandler = (sender, e) =>
            {
                var page = new AppUnlockPasswordPage(UserInfo.Current.appUnlockPasswrod, refreshAction);
                MainPage.BasePageView.AddChidren(page);
                page.LoadPage("2");
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
 
            btnGestureUnlockTitle.MouseUpEventHandler = (sender, e) =>
            {
                var page = new AppUnlockGesturePage(UserInfo.Current.appUnlockPasswrod, refreshAction);
                MainPage.BasePageView.AddChidren(page);
                page.LoadPage(UserInfo.Current.appUnlockType.Contains("2") ? "3" : "1");
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            btnResetGestureTitle.MouseUpEventHandler = (sender, e) =>
            {
                var page = new AppUnlockGesturePage(UserInfo.Current.appUnlockPasswrod, refreshAction);
                MainPage.BasePageView.AddChidren(page);
                page.LoadPage("2");//2020-12-11
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
 
            if (sTouchID)
            {
                btnFingerprintUnlockSwtichIcon.MouseUpEventHandler = (sender, e1) =>
                {
                    TouchIDVerification_SwtichOnOff();
                };
            }
            if (sFaceID)
            {
                btnFaceIdUnlockSwtichIcon.MouseUpEventHandler = (sender, e1) =>
                {
                    FaceIDVerification_SwtichOnOff();
                };
            }
        }
 
        /// <summary>
        /// 判断是否能够取消,如果只剩最后一种解锁方案禁止取消
        /// </summary>
        /// <param name="appUnlockPageType">1:启动时 2:布防撤防时 3:远程开锁时</param>
        /// <returns></returns>
        bool CheckIfCanDeselect(string appUnlockPageType)
        {
            if (UserInfo.Current.appUnlockPage.Count == 1 && UserInfo.Current.appUnlockPage.Contains(appUnlockPageType))
            {
                return false;
            }
 
            return true;
        }
 
        /// <summary>
        /// 面容ID开启和关闭
        /// </summary>
        void FaceIDVerification_SwtichOnOff()
        {
            //6:面容ID开关
            string optionType = "6";
            //4:面容ID
            string faceIDUnlockType = "4";
 
            Action fingerAction = () =>
            {
                TouchIDUtils.Instance.showTouchIDWithDescribe(null, Language.StringByID(StringId.VerifyFaceID));
            };
            new AppUnlockPage().LoadFaceIDGesturePage(optionType, fingerAction);
 
            TouchIDUtils.Instance.showTouchIDWithDescribe(null, Language.StringByID(StringId.VerifyFaceID));
 
            TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = (sender1, e) =>
            {
                if (e == TouchIDUtils.TouchIDState.Success)
                {
                    var result = btnFaceIdUnlockSwtichIcon.IsSelected = !btnFaceIdUnlockSwtichIcon.IsSelected;
                    if (result)
                    {
                        if (!UserInfo.Current.appUnlockType.Contains(faceIDUnlockType))
                        {
                            UserInfo.Current.appUnlockType.Add(faceIDUnlockType);
                            UserInfo.Current.SaveUserInfo();
                        }
                    }
                    else
                    {
                        if (UserInfo.Current.appUnlockType.Contains(faceIDUnlockType))
                        {
                            UserInfo.Current.appUnlockType.Remove(faceIDUnlockType);
                            UserInfo.Current.SaveUserInfo();
                        }
                    }
                    //MainPage.BasePageView.RemoveAt(MainPage.BasePageView.ChildrenCount - 1);
                    MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1).RemoveFromParent();
                }
                else// if (e == TouchIDUtils.TouchIDState.InputPassword || e == TouchIDUtils.TouchIDState.TouchIDLockout)
                {
                    ///将验证面容ID的页面移除
                    MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1).RemoveFromParent();
 
                    GotogoToVerifyPasswordPage(optionType, refreshAction);
                }
            };
        }
 
        /// <summary>
        /// FaceID验证 关闭解锁设置
        /// </summary>
        /// <param name="action">验证成功事件</param>
        void FaceIDVerification_TurnOffUnlock(Action successAction)
        {
            //使用密码验证
            Action goToVerifyPasswordAction = () =>
            {
                //关闭解锁验证
                GotogoToVerifyPasswordPage("4", successAction);
            };
 
            TouchIDUtils.Instance.showTouchIDWithDescribe(null, Language.StringByID(StringId.VerifyFaceID));
            TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = (sender1, e) =>
            {
                if (e == TouchIDUtils.TouchIDState.Success)
                {
                    MainPage.Log("KK:FaceID验证成功");
                    successAction?.Invoke();
                }
                else if (e == TouchIDUtils.TouchIDState.NotSupport)
                {
                    MainPage.Log("KK:当前设备不支持FaceID验证,请输入密码来验证");
                    goToVerifyPasswordAction();
                }
                else if (e == TouchIDUtils.TouchIDState.InputPassword || e == TouchIDUtils.TouchIDState.TouchIDLockout)
                {
                    MainPage.Log("KK:用户选择手动输入密码");
                    goToVerifyPasswordAction();
                }
            };
        }
 
        /// <summary>
        /// 指纹ID开启和关闭
        /// </summary>
        void TouchIDVerification_SwtichOnOff()
        {
            //5:指纹ID开关
            string optionType = "5";
 
            Action fingerAction = () =>
            {
                TouchIDUtils.Instance.showTouchIDWithDescribe(null, Language.StringByID(StringId.PleaseVerifyTheFingerprint));
            };
            new AppUnlockPage().LoadGesturePage(optionType, fingerAction);
 
            TouchIDUtils.Instance.showTouchIDWithDescribe(null, Language.StringByID(StringId.PleaseVerifyTheFingerprint));
 
            TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = (sender1, e) =>
            {
                if (e == TouchIDUtils.TouchIDState.Success)
                {
                    var result = btnFingerprintUnlockSwtichIcon.IsSelected = !btnFingerprintUnlockSwtichIcon.IsSelected;
                    if (result)
                    {
                        if (!UserInfo.Current.appUnlockType.Contains("3"))
                        {
                            UserInfo.Current.appUnlockType.Add("3");
                            UserInfo.Current.SaveUserInfo();
                        }
                    }
                    else
                    {
                        if (UserInfo.Current.appUnlockType.Contains("3"))
                        {
                            UserInfo.Current.appUnlockType.Remove("3");
                            UserInfo.Current.SaveUserInfo();
                        }
                    }
                    MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1).RemoveFromParent();
                }
                else// if (e == TouchIDUtils.TouchIDState.InputPassword || e == TouchIDUtils.TouchIDState.TouchIDLockout)
                {
                    ///将验证指纹ID的页面移除
                    MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1).RemoveFromParent();
                    
                    GotogoToVerifyPasswordPage(optionType, refreshAction);
                }
            };
        }
 
        /// <summary>
        /// TouchID验证 关闭解锁设置
        /// </summary>
        /// <param name="action">验证成功事件</param>
        void TouchIDVerification_TurnOffUnlock(Action successAction)
        {
            //使用密码验证
            Action goToVerifyPasswordAction = () =>
            {
                //关闭解锁验证
                GotogoToVerifyPasswordPage("4", successAction);
            };
 
            TouchIDUtils.Instance.showTouchIDWithDescribe(null, Language.StringByID(StringId.PleaseVerifyTheFingerprint));
            TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = (sender1, e) =>
            {
                if (e == TouchIDUtils.TouchIDState.NotSupport)
                {
                    MainPage.Log("KK:当前设备不支持TouchID验证,请输入密码来验证");
                    goToVerifyPasswordAction?.Invoke();
                }
                else if (e == TouchIDUtils.TouchIDState.Success)
                {
                    MainPage.Log("KK:TouchID验证成功");
                    successAction?.Invoke();
                }
                else if (e == TouchIDUtils.TouchIDState.InputPassword || e == TouchIDUtils.TouchIDState.TouchIDLockout)
                {
                    MainPage.Log("KK:用户选择手动输入密码");
                    goToVerifyPasswordAction?.Invoke();
                }
 
            };
        }
 
        /// <summary>
        /// 跳转手势或者密码验证界面
        /// </summary>
        /// <param name="optionType">1:设置密码;2:验证密码;3:关闭密码;4:关闭解锁设置;5:指纹ID开关;6:面容ID开关;7:解锁验证</param>
        /// <param name="successAction"></param>
        void GotogoToVerifyPasswordPage(string optionType, Action successAction)
        {
            if (UserInfo.Current.appUnlockType.Contains("1"))
            {
                var page = new AppUnlockPasswordPage(UserInfo.Current.appUnlockPasswrod, successAction);
                MainPage.BasePageView.AddChidren(page);
                page.LoadPage(optionType);
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            }
            else if (UserInfo.Current.appUnlockType.Contains("2"))
            {
                var page = new AppUnlockGesturePage(UserInfo.Current.appUnlockPasswrod, successAction);
                MainPage.BasePageView.AddChidren(page);
                page.LoadPage(optionType);
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            }
        }
    }
}