HDL Home App 第二版本 旧平台金堂用 正在使用
温居城
2021-11-23 8b0c761887fc1bc3ec777e4aec87133233550836
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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
using System;
using Newtonsoft.Json.Linq;
using Shared.Common;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DoorLock
{
    public class DoorLockCommonLayout : EditorCommonForm
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public DoorLockCommonLayout()
        {
        }
        #region 变量申明
        public new FrameLayout topFrameLayout = new FrameLayout { Height = Application.GetRealHeight(184), BackgroundColor = ZigbeeColor.Current.XMTopFrameLayout };
        public FrameLayout midFrameLayout = new FrameLayout { Height = Application.GetRealHeight(1925 - 184), BackgroundColor = ZigbeeColor.Current.XMMidFrameLayout };
        /// <summary>
        /// 选中的开锁方式回调
        /// </summary>
        public Action<string> ChooseUnlockMethodAction = null;
        /// <summary>
        /// 选中的开锁方式回调
        /// </summary>
        public Action<int> UndateUnlockMethodAction = null;
        #region 底部有圆角布局
        /// 背景阴影界面
        /// </summary>
        public FrameLayout shadowRadiusFrameLayout = new FrameLayout { BackgroundColor = 0x0f000000 };
        /// <summary>
        /// 设置圆角的界面
        /// </summary>
        public FrameLayout bottomRadiusFrameLayout = new FrameLayout()
        {
            Height = Application.GetRealHeight(806),
            Y = Application.GetRealHeight(930),
            BackgroundColor = ZigbeeColor.Current.XMWhite,
        };
        /// <summary>
        /// 底部圆角中的取消按钮
        /// </summary>
        public Button btnCancel = new Button
        {
            X = Application.GetRealWidth(81),
            Y = Application.GetRealHeight(40),
            Height = Application.GetRealHeight(58),
            Width = Application.GetRealWidth(101),
            Text = Language.StringByID(R.MyInternationalizationString.Cancel),
            TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
            TextSize = 14,
        };
        /// <summary>
        /// 底部圆角中的标题栏
        /// </summary>
        public Button btnBottomTitle = new Button
        {
            X = Application.GetRealWidth(446 - 50),
            Y = Application.GetRealHeight(35),
            Height = Application.GetRealHeight(63),
            Width = Application.GetRealWidth(284),
            Text = Language.StringByID(R.MyInternationalizationString.MatchPerson),
            TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
            TextSize = 16,
        };
        /// <summary>
        /// 底部圆角中的确认按钮
        /// </summary>
        public Button btnFinish = new Button
        {
            X = Application.GetRealWidth(919),
            Y = Application.GetRealHeight(40),
            Height = Application.GetRealHeight(58),
            Width = Application.GetRealWidth(101),
            Text = Language.StringByID(R.MyInternationalizationString.Complete),
            TextColor = Shared.Common.ZigbeeColor.Current.XMOrange,
            TextSize = 14,
        };
        /// <summary>
        /// 底部圆角中的标题栏下的线条
        /// </summary>
        public Button line = new Button()
        {
            Y = Application.GetRealHeight(138),
            Height = 1,
            BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
        };
 
        #endregion
 
        /// <summary>
        /// 标题栏布局
        /// </summary>
        public FrameLayout titleFrameLayout = new FrameLayout
        {
            Y = Application.GetRealHeight(92),
            X = Application.GetRealWidth(58 * 2),
            Width = Application.GetRealWidth(1080 - 116),
            Height = Application.GetRealHeight(69),
        };
 
        /// <summary>
        /// 标题返回布局
        /// </summary>
        public FrameLayout btnBackFrameLayout = new FrameLayout
        {
            Width = Application.GetRealWidth(58 * 2),
        };
 
        /// <summary>
        /// 标题返回按键
        /// </summary>
        public Button btnBack = new Button
        {
            Height = Application.GetRealHeight(51),
            Width = Application.GetRealWidth(30),
            X = Application.GetRealWidth(58),
            Y = Application.GetRealHeight(98),
            UnSelectedImagePath = "DoorLock/Left.png",
        };
 
        /// <summary>
        /// 标题下线
        /// </summary>
        public Button btnTitleLine = new Button
        {
            Y = Application.GetRealHeight(181),
            Height = 1,
            BackgroundColor = Shared.Common.ZigbeeColor.Current.XMTitleLine,
        };
 
        /// <summary>
        /// 弹窗取消按键
        /// </summary>
        public Button dialogBtnCancel = new Button
        {
            Width = Application.GetRealWidth(397),
            Height = Application.GetRealHeight(127),
            Y = Application.GetRealHeight(380),
            TextID = R.MyInternationalizationString.Cancel,
            TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
            BackgroundColor = Shared.Common.ZigbeeColor.Current.XMMidFrameLayout,
        };
        #endregion
 
        /// <summary>
        /// 门锁顶部布局
        /// </summary>
        /// <param name="frameLayout"></param>
        public void TopFrameLayout(FrameLayout frameLayout, string titleText)
        {
            this.AddChidren(topFrameLayout);
            topFrameLayout.AddChidren(btnBackFrameLayout);
            topFrameLayout.AddChidren(titleFrameLayout);
            topFrameLayout.AddChidren(btnTitleLine);
 
            var title = new Button()
            {
                TextAlignment = TextAlignment.CenterLeft,
                Text = titleText,
                TextColor = Shared.Common.ZigbeeColor.Current.XMTopTitleText,
                Width = Application.GetRealWidth(1080 - 161),
                Height = Application.GetRealWidth(69),
                TextSize = 17,
                IsBold = true,
                X = Application.GetRealWidth(161 - 116),
            };
            titleFrameLayout.AddChidren(title);
            btnBackFrameLayout.AddChidren(btnBack);
        }
        /// <summary>
        /// 门锁中部布局
        /// </summary>
        /// <param name="frameLayout"></param>
        public void MidFrameLayout(FrameLayout frameLayout)
        {
            midFrameLayout.Y = topFrameLayout.Bottom;
            this.AddChidren(midFrameLayout);
        }
 
        /// <summary>
        /// 门锁底部布局
        /// </summary>
        /// <param name="frameLayout"></param>
        public void BottomFrameLayout(FrameLayout frameLayout)
        {
            var bottomFrameLayout1 = new FrameLayout()
            {
                Height = Application.GetRealHeight(806 - 50),
                Y = Application.GetRealHeight(930 + 48),
                BackgroundColor = ZigbeeColor.Current.XMWhite,
            };
            this.midFrameLayout.AddChidren(bottomFrameLayout1);
        }
 
        /// <summary>
        /// 门锁底部带圆角布局
        /// </summary>
        /// <param name="frameLayout"></param>
        public void BottomRadiusFrameLayout(FrameLayout frameLayout)
        {
            this.shadowRadiusFrameLayout.AddChidren(this.bottomRadiusFrameLayout);
            this.bottomRadiusFrameLayout.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
            this.bottomRadiusFrameLayout.AddChidren(btnCancel);
            this.bottomRadiusFrameLayout.AddChidren(btnBottomTitle);
            this.bottomRadiusFrameLayout.AddChidren(btnFinish);
            this.bottomRadiusFrameLayout.AddChidren(line);
        }
 
        /// <summary>
        /// 远程控制权限处理
        /// </summary>
        /// <param name="btnNext"></param>
        public void RemotePasswordDialog(ZigBee.Device.DoorLock doorLock, Button btnNext = null)
        {
            var dialog = new Dialog { };
            var doorDialog = new Shared.Phone.UserCenter.DoorLock.DoorlockDialog(dialog, Language.StringByID(R.MyInternationalizationString.BindDoorLock));
            doorDialog.Show();
            doorDialog.dialogMidFraFrameLayout.Width = Application.GetRealWidth(677);
            doorDialog.dialogMidFraFrameLayout.Height = Application.GetRealHeight(69);
            doorDialog.dialogMidFraFrameLayout.X = Application.GetRealWidth(58);
            doorDialog.dialogMidFraFrameLayout.Y = Application.GetRealHeight(213);
            doorDialog.dialogMidFraFrameLayout.BackgroundColor = BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBorder;
 
            var editInputPasswordFrameLayout = new FrameLayout()
            {
                Width = Application.GetRealWidth(677) - 2,
                Height = Application.GetRealHeight(69) - 2,
                X = 1,
                Y = 1,
                BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
            };
            doorDialog.dialogMidFraFrameLayout.AddChidren(editInputPasswordFrameLayout);
 
            var editInputPassword = new EditText()
            {
                X = Application.GetRealHeight(15),
                TextSize = 13,
                PlaceholderTextColor = Shared.Common.ZigbeeColor.Current.XMGray4,
                PlaceholderText = Language.StringByID(R.MyInternationalizationString.InputUnlockPasswrd),
                TextColor = Shared.Common.ZigbeeColor.Current.XMGray2,
                TextAlignment = TextAlignment.CenterLeft,
                IsNumberKeyboardType = true,
            };
            editInputPasswordFrameLayout.AddChidren(editInputPassword);
 
            doorDialog.dialogBtnCancel.MouseUpEventHandler += (sender1, e1) =>
            {
                if (btnNext != null)
                {
                    btnNext.IsSelected = false;
                }
                dialog.Close();
            };
            DateTime oldTime = DateTime.MaxValue;
            doorDialog.dialogBtnConfirm.MouseUpEventHandler += async (sender1, e1) =>
            {
                Application.RunOnMainThread(() => { CommonPage.Loading.Start(""); });
                if (DateTime.Now < ZigBee.Device.DoorLock.minValue)
                {
                    CommonPage.Loading.Hide();
                    this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.NoFiftySeconds));
                    return;
                }
 
                if (DateTime.Now >= oldTime && ZigBee.Device.DoorLock.RemoteUnlockCount == 0)
                {
                    ZigBee.Device.DoorLock.RemoteUnlockCount = 5;
                    oldTime = DateTime.MaxValue;
                }
 
                if (ZigBee.Device.DoorLock.RemoteUnlockCount <= 0)
                {
                    ZigBee.Device.DoorLock.minValue = DateTime.Now.AddSeconds(+15);
                    oldTime = ZigBee.Device.DoorLock.minValue;
                    CommonPage.Loading.Hide();
                    this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.AfterFiftySeconds));
                    return;
                }
 
                if (editInputPassword.Text.Length != 6)
                {
                    ZigBee.Device.DoorLock.RemoteUnlockCount--;
                    string tipText = Language.StringByID(R.MyInternationalizationString.PasswordError) + "," + Language.StringByID(R.MyInternationalizationString.Surplus) + ZigBee.Device.DoorLock.RemoteUnlockCount.ToString() + Language.StringByID(R.MyInternationalizationString.Opportunity);
                    CommonPage.Loading.Hide();
                    this.ShowMassage(ShowMsgType.Tip, tipText);
                    return;
                }
 
                var verifyResult = await doorLock.VerifyPasswordAsync(editInputPassword.Text);
                if (verifyResult != null)
                {
                    if (verifyResult.result == 0)
                    {
                        ///保存远程门锁密码
                        new Device.DeviceMacInfoEditorForm { }.SaveLocalPassword(editInputPassword.Text);
                        System.Threading.Thread.Sleep(500);
                        doorLock.RemoteUnlockPassword = editInputPassword.Text;
                        ZigBee.Device.DoorLock.minValue = DateTime.MinValue;
                        ZigBee.Device.DoorLock.failedCount = 3;
                        ZigBee.Device.DoorLock.RemoteUnlockCount = 5;
                        oldTime = DateTime.MaxValue;
                        CommonPage.Loading.Hide();
                        dialog.Close();
                        if (btnNext != null)
                        {
                            btnNext.IsSelected = true;
                        }
                        if (!UserCenterResourse.AccountOption.DoorUnLockByRemote)
                        {
                            string msg = Language.StringByID(R.MyInternationalizationString.RemoteUnlockBindSucessTip).Replace("{0}", "\r\n");
                            var alert = new ShowDoorLockMsgControl(ShowDoorLockMsgControl.DoorLockMsgType.Confirm, msg, Language.StringByID(R.MyInternationalizationString.GoSetting));
                            alert.Show();
                            //使用确认型弹框时,的回调函数
                            alert.ConfirmClickEvent += () =>
                            {
                                var form = new UserCenter.UserMain.SecondAuthenticationForm();
                                form.AddForm();
                            };
                        }
                        doorLock.ReSave();
                    }
                    else
                    {
                        ZigBee.Device.DoorLock.RemoteUnlockCount--;
                        string tipText = Language.StringByID(R.MyInternationalizationString.OperrateFailed) + "," + Language.StringByID(R.MyInternationalizationString.Surplus) + ZigBee.Device.DoorLock.RemoteUnlockCount.ToString() + Language.StringByID(R.MyInternationalizationString.Opportunity);
                        CommonPage.Loading.Hide();
                        this.ShowMassage(ShowMsgType.Tip, tipText);
                        return;
                    }
                }
                else
                {
                    CommonPage.Loading.Hide();
                    this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.GwResponseOvertime));
                    return;
                }
            };
            doorDialog.flMain.MouseUpEventHandler += (sender11, e11) =>
            {
                if (btnNext != null)
                {
                    btnNext.IsSelected = false;
                }
                dialog.Close();
            };
        }
 
        /// <summary>
        /// 安全验证
        /// </summary>
        /// <param name="doorLock">门锁设备</param>
        /// <param name="action">二次验证的结果成功后的通知</param> 
        public static void SecurityRequest(ZigBee.Device.DoorLock doorLock)
        {
            string msg = Language.StringByID(R.MyInternationalizationString.SetSecondarySecurityVerificationMode).Replace("{0}", "\r\n");
            var alert = new ShowDoorLockMsgControl(ShowDoorLockMsgControl.DoorLockMsgType.Confirm, msg, Language.StringByID(R.MyInternationalizationString.GoSetting));
            alert.Show();
            //使用确认型弹框时,的回调函数
            alert.ConfirmClickEvent += () =>
            {
                var form = new UserCenter.UserMain.SecondAuthenticationForm();
                form.AddForm();
            };
        }
 
        /// <summary>
        /// 绑定远程开锁权限窗口
        /// </summary>
        /// <param name="doorLock"></param>
        /// <param name="btnDoorLockTitle"></param>
        public void BindRemoteUnlockDoorlock(Room room, CommonDevice devDoorLock, Button btnDoorLockTitle = null)
        {
            ZigBee.Device.DoorLock doorLock = devDoorLock as ZigBee.Device.DoorLock;
            string msgRemoteUnlockRequest = Language.StringByID(R.MyInternationalizationString.BindRemoteUnlockDoorlock);
            var alertRemoteUnlockRequest = new ShowDoorLockMsgControl(ShowDoorLockMsgControl.DoorLockMsgType.Confirm, msgRemoteUnlockRequest, Language.StringByID(R.MyInternationalizationString.GoSetting));
            alertRemoteUnlockRequest.Show();
            //使用确认型弹框时,的回调函数
            alertRemoteUnlockRequest.ConfirmClickEvent += () =>
            {
                var functionSetting = new Shared.Phone.UserCenter.DoorLock.FunctionSetting(room, devDoorLock);
                Shared.Phone.UserView.HomePage.Instance.AddChidren(functionSetting);
                Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                functionSetting.Show();
                functionSetting.devicNameAction += (deviceRename) =>
                {
                    if (!string.IsNullOrEmpty(deviceRename))
                    {
                        if (btnDoorLockTitle != null)
                        {
                            btnDoorLockTitle.Text = deviceRename;
                        }
                    }
                };
            };
        }
 
        /// <summary>
        /// 去个人中心,开启系统密码支持开锁权限
        /// </summary>
        public void SystemSecondAuthentication()
        {
            string msgDoorUnLockByRemote = Language.StringByID(R.MyInternationalizationString.GoPersonalCenter).Replace("{0}", "\r\n");
            var alertDoorUnLockByRemote = new ShowDoorLockMsgControl(ShowDoorLockMsgControl.DoorLockMsgType.Confirm, msgDoorUnLockByRemote, Language.StringByID(R.MyInternationalizationString.GoSetting));
            alertDoorUnLockByRemote.Show();
            //使用确认型弹框时,的回调函数
            alertDoorUnLockByRemote.ConfirmClickEvent += () =>
            {
                var form = new UserCenter.UserMain.SecondAuthenticationForm();
                form.AddForm();
            };
        }
 
        /// <summary>
        /// 远程开锁请求
        /// </summary>
        /// <param name="doorLock">门锁设备</param>
        /// <param name="action">二次验证的结果成功后的通知</param>
        /// <param name="progressButton">门锁开或关时进度显示</param>
        /// <param name="btnDoorLockPic">门锁图片开/关显示</param>
        public void RemoteUnlockRequest(Room room, CommonDevice devDoorLock, Action action, Button progressButton = null, Button btnDoorLockPic = null, Button btnStatus = null, Button btnDoorLockTitle = null)
        {
            ZigBee.Device.DoorLock doorLock = devDoorLock as ZigBee.Device.DoorLock;
            if (string.IsNullOrEmpty(doorLock.RemoteUnlockPassword))
            {
                BindRemoteUnlockDoorlock(room, devDoorLock, btnDoorLockTitle);
                return;
            }
 
            if (!UserCenterResourse.AccountOption.DoorUnLockByRemote)
            {
                SystemSecondAuthentication();
                return;
            }
 
            string msg = Language.StringByID(R.MyInternationalizationString.SureToOpenDoorLock);
            var alert = new ShowDoorLockMsgControl(ShowDoorLockMsgControl.DoorLockMsgType.Confirm, msg, Language.StringByID(R.MyInternationalizationString.DoorlockConfirm));
            alert.Show();
            //使用确认型弹框时,的回调函数
            alert.ConfirmClickEvent += () =>
            {
                action = () =>
                {
                    System.Threading.Tasks.Task.Run(async () =>
                    {
                        Application.RunOnMainThread(() => { CommonPage.Loading.Start(""); });
                        try
                        {
                            Application.RunOnMainThread(() =>
                            {
                                if (progressButton != null)
                                {
                                    progressButton.Y = Application.GetRealHeight(10);
                                }
                                if (btnDoorLockPic != null)
                                {
                                    btnDoorLockPic.IsSelected = true;
                                }
                                if (btnStatus != null)
                                {
                                    btnStatus.Text = Language.StringByID(R.MyInternationalizationString.Opening);
 
                                }
                            });
                            //远程开锁 
                            var remoteControlResult = await doorLock.RemoteControlAsync(doorLock.RemoteUnlockPassword);
 
                            //远程开锁成功,返回默认响应
                            if (remoteControlResult != null && remoteControlResult.responseData != null)
                            {
                                if (remoteControlResult.responseData.status == 0)
                                {
                                    ZigBee.Device.DoorLock.failedCount = 3;
                                    Application.RunOnMainThread(() =>
                                    {
                                        if (progressButton != null)
                                        {
                                            progressButton.Y = Application.GetRealHeight(10);
                                        }
                                        if (btnDoorLockPic != null)
                                        {
                                            btnDoorLockPic.IsSelected = true;
                                        }
                                        if (btnStatus != null)
                                        {
                                            btnStatus.Text = Language.StringByID(R.MyInternationalizationString.Current) + Language.StringByID(R.MyInternationalizationString.DoorLockOpen);
                                            this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.UnlockSuccess));
                                        }
                                    });
                                    //开锁成功,默认5秒后门锁自动关锁,根据不同的门锁可能时间不同,这里以“H06C”门锁给的时间
                                    System.Threading.Thread.Sleep(5000);
                                }
                                else
                                {
                                    this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.UnlockFailed));
                                }
                            }
                            //用于远程开锁的门锁中的密码被删除情况
                            else if (remoteControlResult != null && remoteControlResult.IsPawDispear == true)
                            {
                                //远程开锁有3次连续操作失败的机会
                                ZigBee.Device.DoorLock.failedCount--;
                                if (ZigBee.Device.DoorLock.failedCount != 0)
                                {
                                    this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.UnlockFailed));
                                }
                                else
                                {
                                    //3次操作失败远程开锁失败后,重写设置远程开锁密码
                                    Application.RunOnMainThread(() =>
                                    {
                                        this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.DoorlockPasswordDispear));
                                        doorLock.RemoteUnlockPassword = "";
                                        var functionSetting = new Shared.Phone.UserCenter.DoorLock.FunctionSetting(room, devDoorLock);
                                        Shared.Phone.UserView.HomePage.Instance.AddChidren(functionSetting);
                                        Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                                        functionSetting.Show();
                                        functionSetting.devicNameAction += (deviceRename) =>
                                        {
                                            if (!string.IsNullOrEmpty(deviceRename))
                                            {
                                                if (btnDoorLockTitle != null)
                                                {
                                                    btnDoorLockTitle.Text = deviceRename;
                                                }
                                            }
                                        };
                                    });
                                }
                            }
                            //远程开锁失败的情况
                            else
                            {
                                this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.GwResponseOvertime));
                            }
                        }
                        catch { }
                        finally
                        {
                            Application.RunOnMainThread(() =>
                            {
                                if (progressButton != null)
                                {
                                    progressButton.Y = Application.GetRealHeight(347);
                                }
                                if (btnDoorLockPic != null)
                                {
                                    btnDoorLockPic.IsSelected = false;
                                }
                                if (btnStatus != null)
                                {
                                    btnStatus.Text = Language.StringByID(R.MyInternationalizationString.Current) + Language.StringByID(R.MyInternationalizationString.CLose);
                                }
                                CommonPage.Loading.Hide();
                            });
                        }
                    });
                };
 
                HdlCheckLogic.Current.CheckSecondarySecurity(action);
            };
        }
        // 获取到到名称更改回调通知
        public Action<string> devicNameSecAction;
 
 
        /// <summary>
        /// 当前选中的开锁方式
        /// </summary>
        /// <param name="btnAllMethod"></param>
        /// <param name="btnMethodText"></param>
        /// <param name="oldbutton"></param>
        /// <param name="oldbuttonText"></param>
        public void CurrentSelectUnlockMethod(Button btnAllMethod, Button btnMethodText, Button oldbutton, Button oldbuttonText)
        {
            btnAllMethod.IsSelected = true;
            btnMethodText.TextColor = Shared.Common.ZigbeeColor.Current.XMBlack;
            btnMethodText.IsBold = true;
            oldbutton = btnAllMethod;
            oldbuttonText = btnMethodText;
        }
 
        /// <summary>
        /// 显示所有开锁方式的数据
        /// </summary>
        /// <param name="curIndex"></param>
        /// <param name="btnAllMethod"></param>
        /// <param name="btnMethodText"></param>
        public void DisplayAllUnlockMethod(ZigBee.Device.DoorLock doorLock, int curIndex, Button btnAllMethod, Button btnMethodText)
        {
            var listDevice = Common.LocalDevice.Current.GetDevicesByMac(doorLock.DeviceAddr);
            var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(listDevice);
            if (curIndex == 0)
            {
                btnAllMethod.UnSelectedImagePath = "DoorLock/AllMethod.png";
                btnAllMethod.SelectedImagePath = "DoorLock/AllMethodOn.png";
                btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.AllMethod);
            }
            else if (curIndex == 1)
            {
                btnAllMethod.UnSelectedImagePath = "DoorLock/Password.png";
                btnAllMethod.SelectedImagePath = "DoorLock/PasswordOn.png";
                btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.PasswordUnlock);
            }
            else if (curIndex == 2)
            {
                if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.IntelligentLocks_AT1F)
                {
                    btnAllMethod.UnSelectedImagePath = "DoorLock/Fingerprint.png";
                    btnAllMethod.SelectedImagePath = "DoorLock/FingerprintOn.png";
                    btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.CalmFingerprintUnlock);
                }
                else if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.IntelligentLocks_HAT1B)
                {
                    btnAllMethod.UnSelectedImagePath = "DoorLock/Fingerprint.png";
                    btnAllMethod.SelectedImagePath = "DoorLock/FingerprintOn.png";
                    btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.CalmFingerprintUnlock);
                }
                else
                {
                    btnAllMethod.UnSelectedImagePath = "DoorLock/Fingerprint.png";
                    btnAllMethod.SelectedImagePath = "DoorLock/FingerprintOn.png";
                    btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.FingerprintUnlock);
                }
            }
            else if (curIndex == 3)
            {
                if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.IntelligentLocks_AT1F)
                {
                    btnAllMethod.UnSelectedImagePath = "DoorLock/faceId.png";
                    btnAllMethod.SelectedImagePath = "DoorLock/faceIdOn.png";
                    btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.FaceIDUnlock);
                }
                else if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.IntelligentLocks_AT1TF)
                {
                    btnAllMethod.UnSelectedImagePath = "DoorLock/proximityCard.png";
                    btnAllMethod.SelectedImagePath = "DoorLock/proximityCardOn.png";
                    btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.ProximithCardUnlock);
                }
                else
                {
                    btnAllMethod.UnSelectedImagePath = "DoorLock/proximityCard.png";
                    btnAllMethod.SelectedImagePath = "DoorLock/proximityCardOn.png";
                    btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.ProximithCardUnlock);
                }
            }
            if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.IntelligentLocks_AT1TF)
            {
                if (curIndex == 4)
                {
                    btnAllMethod.UnSelectedImagePath = "DoorLock/faceId.png";
                    btnAllMethod.SelectedImagePath = "DoorLock/faceIdOn.png";
                    btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.FaceIDUnlock);
                }
            }
 
 
 
            //switch (curIndex)
            //{
            //    case 0:
            //        btnAllMethod.UnSelectedImagePath = "DoorLock/AllMethod.png";
            //        btnAllMethod.SelectedImagePath = "DoorLock/AllMethodOn.png";
            //        btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.AllMethod);
            //        break;
            //    case 1:
            //        btnAllMethod.UnSelectedImagePath = "DoorLock/Password.png";
            //        btnAllMethod.SelectedImagePath = "DoorLock/PasswordOn.png";
            //        btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.PasswordUnlock);
            //        break;
            //    case 2:
            //        btnAllMethod.UnSelectedImagePath = "DoorLock/Fingerprint.png";
            //        btnAllMethod.SelectedImagePath = "DoorLock/FingerprintOn.png";
            //        btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.FingerprintUnlock);
            //        break;
            //    case 3:
            //        btnAllMethod.UnSelectedImagePath = "DoorLock/proximityCard.png";
            //        btnAllMethod.SelectedImagePath = "DoorLock/proximityCardOn.png";
            //        btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.ProximithCardUnlock);
            //        break;
            //    case 4:
            //        btnAllMethod.UnSelectedImagePath = "DoorLock/faceId.png";
            //        btnAllMethod.SelectedImagePath = "DoorLock/faceIdOn.png";
            //        btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.FaceIDUnlock);
            //        break;
            //    case 5:
            //        btnAllMethod.UnSelectedImagePath = "DoorLock/Fingerprint.png";
            //        btnAllMethod.SelectedImagePath = "DoorLock/FingerprintOn.png";
            //        btnMethodText.Text = Language.StringByID(R.MyInternationalizationString.CalmFingerprintUnlock);
            //        break;
            //}
        }
 
        /// <summary>
        /// 侧边导航栏
        /// </summary>
        public void SideslipFramelayout(ZigBee.Device.DoorLock doorLock)
        {
            #region sidelipFrameLayout UI
            var dialog = new Dialog
            {
            };
            dialog.Show();
 
            var flMain = new FrameLayout { BackgroundColor = 0x00000000 };
            dialog.AddChidren(flMain);
            flMain.MouseUpEventHandler += (sender11, e11) =>
            {
                dialog.Close();
            };
 
            var sidelipFrameLayout = new FrameLayout()
            {
                Width = Application.GetRealWidth(449),
                Y = Application.GetRealHeight(115 + 160),
                X = Application.GetRealWidth(596),
                BackgroundImagePath = "DoorLock/SideslipPic.png",
            };
            flMain.AddChidren(sidelipFrameLayout);
 
            var sidelipVerticalScrolViewLayout = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(28),
            };
            sidelipFrameLayout.AddChidren(sidelipVerticalScrolViewLayout);
            #endregion
 
            Button oldbutton = null;
            Button oldbuttonText = null;
            int count = 1 + GetSupportType(doorLock);
            sidelipFrameLayout.Height = Application.GetRealHeight(150) * count + Application.GetRealHeight(6);
            sidelipVerticalScrolViewLayout.Height = Application.GetRealHeight(150) * count + Application.GetRealHeight(6);
            for (var i = 0; i < count; i++)
            {
                #region rowFrameLayout UI
                var rowFrameLayout = new FrameLayout()
                {
                    Height = Application.GetRealHeight(150),
                    X = Application.GetRealWidth(81),
                };
                sidelipVerticalScrolViewLayout.AddChidren(rowFrameLayout);
 
                var btnAllMethod = new Button()
                {
                    Width = Application.GetRealWidth(81),
                    Height = Application.GetRealHeight(81),
                    Y = Application.GetRealHeight(35),
                };
                rowFrameLayout.AddChidren(btnAllMethod);
 
                var btnMethodText = new Button()
                {
                    Width = Application.GetRealWidth(311),
                    Height = Application.GetRealHeight(58),
                    X = Application.GetRealWidth(92),
                    Y = Application.GetRealHeight(49),
                    TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                    TextSize = 14,
                    TextAlignment = TextAlignment.CenterLeft,
                };
                rowFrameLayout.AddChidren(btnMethodText);
 
                var line2 = new Button()
                {
                    Y = rowFrameLayout.Height - 1,
                    X = Application.GetRealWidth(81),
                    Width = Application.GetRealWidth(965),
                    Height = 1,
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
                };
                rowFrameLayout.AddChidren(line2);
                if (i == count)
                {
                    line2.Visible = false;
                }
                #endregion
 
                #region 数据处理
                EventHandler<MouseEventArgs> hander = (sender, e) =>
                {
                    if (!btnAllMethod.IsSelected)
                    {
                        if (oldbutton != null)
                        {
                            oldbutton.IsSelected = false;
                        }
                        if (oldbuttonText != null)
                        {
                            oldbuttonText.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
                        }
                        oldbutton = btnAllMethod;
                        oldbuttonText = btnMethodText;
 
                        doorLock.ReSave();
                        btnAllMethod.IsSelected = true;
                        oldbuttonText.TextColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                        oldbuttonText.IsBold = true;
                        doorLock.currentUserDisplayMethod = btnMethodText.Text;
                        TypeRefresh(doorLock);
                    }
                    dialog.Close();
                };
                rowFrameLayout.MouseUpEventHandler += hander;
                btnAllMethod.MouseUpEventHandler += hander;
                btnMethodText.MouseUpEventHandler += hander;
 
                DisplayAllUnlockMethod(doorLock, i, btnAllMethod, btnMethodText);
 
                if (string.IsNullOrEmpty(doorLock.currentUserDisplayMethod) && i == 0)
                {
                    CurrentSelectUnlockMethod(btnAllMethod, btnMethodText, oldbutton, oldbuttonText);
                }
                if (doorLock.currentUserDisplayMethod == Language.StringByID(R.MyInternationalizationString.AllMethod) && i == 0)
                {
                    CurrentSelectUnlockMethod(btnAllMethod, btnMethodText, oldbutton, oldbuttonText);
                }
                if (doorLock.currentUserDisplayMethod == Language.StringByID(R.MyInternationalizationString.PasswordUnlock) && i == 1)
                {
                    CurrentSelectUnlockMethod(btnAllMethod, btnMethodText, oldbutton, oldbuttonText);
                }
                if (doorLock.currentUserDisplayMethod == Language.StringByID(R.MyInternationalizationString.FingerprintUnlock) && i == 2)
                {
                    CurrentSelectUnlockMethod(btnAllMethod, btnMethodText, oldbutton, oldbuttonText);
                }
                if (doorLock.currentUserDisplayMethod == Language.StringByID(R.MyInternationalizationString.ProximithCardUnlock) && i == 3)
                {
                    CurrentSelectUnlockMethod(btnAllMethod, btnMethodText, oldbutton, oldbuttonText);
                }
                if (doorLock.currentUserDisplayMethod == Language.StringByID(R.MyInternationalizationString.FaceIDUnlock) && i == 4)
                {
                    CurrentSelectUnlockMethod(btnAllMethod, btnMethodText, oldbutton, oldbuttonText);
                }
                if (doorLock.currentUserDisplayMethod == Language.StringByID(R.MyInternationalizationString.CalmFingerprintUnlock) && i == 5)
                {
                    CurrentSelectUnlockMethod(btnAllMethod, btnMethodText, oldbutton, oldbuttonText);
                }
                #endregion
            }
        }
 
        /// <summary>
        /// 当前门锁支持的开锁类型个数
        /// </summary>
        /// <param name="doorLock"></param>
        /// <returns></returns>
        public int GetSupportType(ZigBee.Device.DoorLock doorLock)
        {
            int count = 0;
            var listDevice = Common.LocalDevice.Current.GetDevicesByMac(doorLock.DeviceAddr);
            var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(listDevice);
            if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.IntelligentLocks_AT1F)
            {
                //AT1F有密码,感应卡,faceID
                count = 3;
            }
            else if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.IntelligentLocks_AT1T)
            {
                //AT1T有密码,指纹,感应卡 
                count = 3;
            }
            else if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.IntelligentLocks_AT1TF)
            {
                //AT1TF有密码,指纹,感应卡,faceID
                count = 4;
            }
            else if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.IntelligentLocks_HAT1B)
            {
                //HAT1B密码、静脉纹、刷卡
                count = 3;
            }
            else if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.IntelligentLocks_HAT1T)
            {
                //HAT1T密码、指纹、刷卡
                count = 3;
            }
            else
            {
                //只有密码,指纹,感应卡
                count = 3;
            }
            return count;
        }
 
        /// <summary>
        /// 类型区分 
        /// </summary>
        public void TypeRefresh(ZigBee.Device.DoorLock doorLock)
        {
            if (doorLock.currentUserDisplayMethod == Language.StringByID(R.MyInternationalizationString.PasswordUnlock))
            {
                UndateUnlockMethodAction?.Invoke(0);
            }
            else if (doorLock.currentUserDisplayMethod == Language.StringByID(R.MyInternationalizationString.ProximithCardUnlock))
            {
                UndateUnlockMethodAction?.Invoke(3);
            }
            else if (doorLock.currentUserDisplayMethod == Language.StringByID(R.MyInternationalizationString.CalmFingerprintUnlock))
            {
                UndateUnlockMethodAction?.Invoke(13);
            }
            else if (doorLock.currentUserDisplayMethod == Language.StringByID(R.MyInternationalizationString.FaceIDUnlock))
            {
                UndateUnlockMethodAction?.Invoke(14);
            }
            else if (doorLock.currentUserDisplayMethod == Language.StringByID(R.MyInternationalizationString.FingerprintUnlock))
            {
                UndateUnlockMethodAction?.Invoke(15);
            }
            else
            {
                UndateUnlockMethodAction?.Invoke(-1);
            }
            //每次调完清空
            UndateUnlockMethodAction = null;
        }
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 显示错误信息窗口
        /// </summary>
        /// <param name="msg"></param>
        public void ShowErrorMsg(string msg)
        {
            Application.RunOnMainThread(() =>
            {
                var contr = new ShowMsgControl(ShowMsgType.Error, msg);
                contr.Show();
            });
        }
 
        /// <summary>
        /// 显示Tip信息窗口
        /// </summary>
        /// <param name="msg"></param>
        public void ShowTipMsg(string msg)
        {
            Application.RunOnMainThread(() =>
            {
                var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
                contr.Show();
                CommonPage.Loading.Hide();
            });
        }
 
        #endregion
    }
}