wxr
2024-06-06 f54a487bb42ac49bf81bd7b5eea311fc79231bc6
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
using Shared;
using System;
using System.Collections.Generic;
using System.Text;
using HDL_ON.UI.CSS;
using HDL_ON.Entity;
using HDL_ON.DriverLayer;
using HDL_ON.UI.Music;
using HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock;
 
namespace HDL_ON.UI
{
    /// <summary>
    /// 视频门锁的控制界面
    /// </summary>
    public class VideoDoorLockPage : FrameLayout
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 设备
        /// </summary>
        private Function device;
        /// <summary>
        /// 上一级界面的设备名字控件
        /// </summary>
        private Button btnDeviceName;
        /// <summary>
        /// 上一级界面的房间名字控件
        /// </summary>
        private Button btnRoomName;
        /// <summary>
        /// 头部布局
        /// </summary>
        private TopView topView;
        /// <summary>
        /// 当前设备名称
        /// </summary>
        private Button btnCurrDeviceName;
        /// <summary>
        /// 区域
        /// </summary>
        private Button btnCurrDeviceRoom;
        /// <summary>
        /// 电量父控件
        /// </summary>
        private FrameLayout cellFrame;
        /// <summary>
        /// 电量
        /// </summary>
        private Button btnCell;
        /// <summary>
        /// 电量进度条
        /// </summary>
        private DiyArcSeekBar cellDiyArcSeekBar;
        /// <summary>
        ///收藏图标
        /// </summary>
        private Button btnCollectIcon;
        /// <summary>
        /// 门锁状态
        /// </summary>
        private Button btnDoorLockIcon;
            Button btnDoorlockStatus;
        /// <summary>
        /// 实时视频
        /// </summary>
        private CustomFrameLayout rtvFL;
        /// <summary>
        /// 临时密码
        /// </summary>
        private CustomFrameLayout pswFL;
        /// <summary>
        /// 历史记录
        /// </summary>
        private CustomFrameLayout recordFL;
 
        /// <summary>
        /// 表示来自那个界面
        /// </summary>
        private Comerom comerom;
        /// <summary>
        /// 删除设备后需要更新界面的回调
        /// </summary>
        public Action action;
        #endregion
 
 
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="function">设备</param>
        /// <param name="btnDeviceName">上一级界面的设备名字控件(注:不能传null,没有可以传new Button())</param>
        /// <param name="btnRoomName">上一级界面的房间名字控件(注:不能传null,没有可以传new Button())</param> 
        public VideoDoorLockPage(Function function, Button btnDeviceName, Button btnRoomName, Comerom comerom, Action action)
        {
            this.device = function;
            this.btnDeviceName = btnDeviceName;
            this.btnRoomName = btnRoomName;
            this.comerom = comerom;
            this.action = action;
 
        }
 
        public void Show()
        {
            //初始化UI
            this.InitUI();
            //初始化事件
            this.EventListener();
            //读取数据
            this.ReadData();
 
        }
 
 
        /// <summary>
        /// 初始化界面
        /// </summary>
        private void InitUI()
        {
            #region   ---界面布局---
            this.BackgroundColor = MusicColor.ViewColor;
            this.topView = new TopView();
            this.topView.setBtn.Visible = true;
            this.topView.topNameBtn.TextID = StringId.shipinmensuo;
            this.AddChidren(topView.TopFLayoutView());
            var middleFl = new FrameLayout
            {
                Y = topView.fLayout.Bottom,
                Height = Application.GetRealHeight(H_W.H - H_W.T_Height),
            };
            this.AddChidren(middleFl);
 
            var whiteFl = new FrameLayout
            {
                Y = Application.GetRealHeight(24),
                X = Application.GetRealWidth(24),
                Height = Application.GetRealHeight(526),
                Width = Application.GetRealWidth(327),
                BackgroundImagePath = "MusicIcon/playBj.png",
                Name = "fl",
            };
            middleFl.AddChidren(whiteFl);
 
            btnCollectIcon = new Button
            {
                X = Application.GetRealWidth(264),
                Y = Application.GetRealHeight(14),
                Width = Application.GetRealWidth(40),
                Height = Application.GetRealWidth(40),
                UnSelectedImagePath = "MusicIcon/collect.png",
                SelectedImagePath = "MusicIcon/collectSelected.png",
                IsSelected = this.device.collect,
                Name = "collect"
            };
            whiteFl.AddChidren(btnCollectIcon);
 
            btnCurrDeviceName = new Button
            {
                TextSize = TextSize.Text24,
                TextColor = MusicColor.Text18Color,
                Width = Application.GetRealWidth(160),
                Height = Application.GetRealHeight(33),
                Y = Application.GetRealHeight(16),
                X = Application.GetRealWidth(16),
                Text = this.device.name,
                TextAlignment = TextAlignment.CenterLeft,
            };
            whiteFl.AddChidren(btnCurrDeviceName);
 
 
            btnCurrDeviceRoom = new Button
            {
                TextSize = TextSize.Text12,
                TextColor = MusicColor.MusicNoTxetColor,
                Width = Application.GetRealWidth(160),
                Height = Application.GetRealHeight(17),
                Y = btnCurrDeviceName.Bottom + Application.GetRealHeight(4),
                X = Application.GetRealWidth(16),
                Text = this.device.GetRoomListName(),
                TextAlignment = TextAlignment.CenterLeft,
            };
            whiteFl.AddChidren(btnCurrDeviceRoom);
 
            cellFrame = new FrameLayout
            {
                X = btnCurrDeviceRoom.Right + Application.GetRealWidth(20),
                Y = btnCurrDeviceName.Bottom + Application.GetRealHeight(5),
                Width = Application.GetRealWidth(30),
                Height = Application.GetRealHeight(16),
            };
            whiteFl.AddChidren(cellFrame);
 
            cellDiyArcSeekBar = new DiyArcSeekBar
            {
                X = Application.GetRealWidth(3),
                Y = Application.GetRealHeight(3),
                Width = cellFrame.Width + Application.GetRealWidth(-6),
                Height = cellFrame.Height + Application.GetRealHeight(-6),
                Progress = 60,
                ProgressBarColor = MusicColor.MusicNoTxetColor,
                MaxValue = 100,
                MinValue = 0,
 
                //IsCanMove = false,
                //IsCanScrolled=false,
            };
            //cellFrame.AddChidren(cellDiyArcSeekBar);
 
            btnCell = new Button
            {
                TextSize = TextSize.Text10,
                TextColor = MusicColor.TextColor,
                Text = "60" + "%",
                TextAlignment = TextAlignment.Center,
                UnSelectedImagePath = "FunctionIcon/DoorLock/Cell.png",
            };
            cellFrame.AddChidren(btnCell);
 
 
#if __IOS__
//btnCell.Padding = new Padding(0,0,0,0);
            btnCell.Width += 5;
            cellFrame.Width += 5;
#else
#endif
 
 
            //门锁状态
            btnDoorLockIcon = new Button
            {
                X = Application.GetRealWidth(65),
                Y = Application.GetRealHeight(108),
                Width = Application.GetRealWidth(198),
                Height = Application.GetRealWidth(200),
                UnSelectedImagePath = "FunctionIcon/DoorLock/UnLocked.png",
                SelectedImagePath = "FunctionIcon/DoorLock/UnLocking.png",
            };
            whiteFl.AddChidren(btnDoorLockIcon);
 
            this.CalculatedPosition();//重新计算宽度
 
            btnDoorlockStatus = new Button()
            {
                Width = Application.GetRealWidth(200),
                Height = Application.GetRealHeight(62),
                Y = btnDoorLockIcon.Bottom,
                TextAlignment = TextAlignment.Center,
                Gravity = Gravity.CenterHorizontal,
                TextID = StringId.DoorlockOpen,
                TextColor = CSS_Color.WarningColor,
                TextSize = 16,
            };
            whiteFl.AddChidren(btnDoorlockStatus);
            
            int heightY = btnDoorLockIcon.Bottom + Application.GetRealHeight(133);
            //实时视频
            rtvFL = new CustomFrameLayout(CustomFrameLayout.widthFrameLayout, CustomFrameLayout.heightFrameLayout);
            whiteFl.AddChidren(rtvFL);
            rtvFL.Y = heightY;
            rtvFL.X = Application.GetRealWidth(26);
            rtvFL.AddImageView();
            rtvFL.AddTextButtonView();
            rtvFL.GetImageButton().UnSelectedImagePath = "FunctionIcon/DoorLock/RTV.png";
            rtvFL.GetTextButton().TextID = StringId.shishishipin;
            
            
            //临时密码
            pswFL = new CustomFrameLayout(CustomFrameLayout.widthFrameLayout, CustomFrameLayout.heightFrameLayout);
            whiteFl.AddChidren(pswFL);
            pswFL.Y = heightY;
            pswFL.X = rtvFL.Right + Application.GetRealWidth(CustomFrameLayout.interval);
            pswFL.AddImageView();
            pswFL.AddTextButtonView();
            pswFL.GetImageButton().UnSelectedImagePath = "FunctionIcon/DoorLock/OneOpenLock.png";
            pswFL.GetTextButton().TextID = StringId.linshimima1;
            if (device.omodel.Contains("CS-DL30F-V100"))
            {
                rtvFL.Visible = rtvFL.Enable = false;
                pswFL.X = Application.GetRealWidth(26);
            }
 
            //历史记录
            recordFL = new CustomFrameLayout(CustomFrameLayout.widthFrameLayout, CustomFrameLayout.heightFrameLayout);
            whiteFl.AddChidren(recordFL);
            recordFL.Y = heightY;
            recordFL.X = pswFL.Right + Application.GetRealWidth(CustomFrameLayout.interval);
            recordFL.AddImageView();
            recordFL.AddTextButtonView();
            recordFL.GetImageButton().UnSelectedImagePath = "FunctionIcon/DoorLock/HistoryList.png";
            recordFL.GetTextButton().TextID = StringId.lishijilu;
 
            if (!DB_ResidenceData.Instance.CurrentRegion.isOtherShare)
            {
                //用户管理
                CustomFrameLayout userManagerView = new CustomFrameLayout(CustomFrameLayout.widthFrameLayout, CustomFrameLayout.heightFrameLayout);
                whiteFl.AddChidren(userManagerView);
                userManagerView.Y = heightY;
                userManagerView.X = recordFL.Right + Application.GetRealWidth(CustomFrameLayout.interval);
                userManagerView.AddImageView();
                userManagerView.AddTextButtonView();
                userManagerView.GetImageButton().UnSelectedImagePath = "FunctionIcon/DoorLock/DoorlockUserManager.png";
                userManagerView.GetTextButton().TextID = StringId.UserManagement;
 
                userManagerView.SetClickListener((fl, btnImage, btnText) =>
                {
                    var page = new VideoDoorlockUserListPage(device);
                    MainPage.BasePageView.AddChidren(page);
                    page.LoadPage();
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
 
                });
            }
            #endregion
 
 
        }
        /// <summary>
        /// 注册事件
        /// </summary>
        private void EventListener()
        {
            //返回
            this.topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
            {
                this.RemoveFromParent();
            };
            //设置
            this.topView.clickSetBtn.MouseUpEventHandler += (sender, e) =>
            {
                CommonMethod.Current.MainThread(() =>
                {
                    //调用秀绕的界面
                    var infoView = new UI.FunctionBaseInfoSetPage(this.device, () =>
                     {
                         if (this.btnDeviceName == null || this.btnRoomName == null || this.device == null)
                         {
                             return;
                         }
                         ////刷新显示
                         this.btnDeviceName.Text = this.device.name;
                         this.btnRoomName.Text = this.device.GetRoomListName();
                         this.btnCurrDeviceName.Text = this.device.name;
                         this.btnCurrDeviceRoom.Text = this.device.GetRoomListName();
                         this.CalculatedPosition();//重新计算宽度
 
                     });
                    infoView.actionDel += () =>
                      {
                          //解绑设备后
                          this.RemoveFromParent();
                          this.action?.Invoke();
 
                      };
                    MainPage.BasePageView.AddChidren(infoView);
                    infoView.LoadPage();
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                });
            };
            //收藏
            this.btnCollectIcon.MouseUpEventHandler += (sender, e) =>
            {
                btnCollectIcon.IsSelected = this.device.collect = !btnCollectIcon.IsSelected;
                this.device.CollectFunction();
            };
 
            int delayTimeMaxValue = 0;//
            var startTime = DateTime.Now;
            //实时视频
            this.rtvFL.SetClickListener((fl, btnStateImage, btnStateText) =>
            {
                bool isDeyayClick = false;
                var clickTime = DateTime.Now;
                if ((clickTime - startTime).TotalMilliseconds > delayTimeMaxValue)
                {
                    delayTimeMaxValue = 2*1000;
                    startTime = clickTime;
                    isDeyayClick = true;
                }
                if (!isDeyayClick)
                {
                    return;
                }
                CommonMethod.Current.SkipRTVActivity(this.device.sid, this.device.deviceId, this.device.spk, false);
 
            });
            var lastClickTime = DateTime.MinValue;
            //临时密码
            this.pswFL.SetClickListener((fl, btnStateImage, btnStateText) =>
            {
                if (lastClickTime.AddSeconds(3) > DateTime.Now)
                {
                    return;
                }
                lastClickTime = DateTime.Now;
                CommonMethod.Current.SkipPSWActivity(this.device.deviceId);
            });
 
            //历史记录
            this.recordFL.SetClickListener((fl, btnStateImage, btnStateText) =>
            {
                if (lastClickTime.AddSeconds(3) > DateTime.Now)
                {
                    return;
                }
                lastClickTime = DateTime.Now;
 
                //VideoDoorlockHistoryPage historyPage = new VideoDoorlockHistoryPage(device);
                //MainPage.BasePageView.AddChidren(historyPage);
                //historyPage.LoadPage();
                //MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                var waitPage = new Loading();
                this.AddChidren(waitPage);
                waitPage.Start("");
                new System.Threading.Thread(() =>
                {
                    try
                    {
                        Application.RunOnMainThread(() =>
                        {
                            CommonMethod.Current.SkipRecordActivity(this.device.deviceId);
                        });
                    }catch(Exception ex)
                    {
 
                    }
                    finally
                    {
                        Application.RunOnMainThread(() => {
                            waitPage.Hide();
                        });
                    }
                })
                { IsBackground = true }.Start();
            });
 
 
        }
        /// <summary>
        /// 初始数据
        /// </summary>
        private void ReadData()
        {
            CommonMethod.Current.Loading.Start();
            CommonMethod.Current.SunThread(() =>
            {
                try
                {
                    var videoDoorLockInfo = VideDoorLockSend.Current.GetVideoDoorLockState(this.device);
                    var cellInfo = VideDoorLockSend.Current.GetCellValue(this.device);
                    CommonMethod.Current.MainThread(() =>
                    {
                        //this.cellDiyArcSeekBar.Progress = i;
                        //更新电量值
                        this.btnCell.Text = cellInfo.remain + "%";
                        if(videoDoorLockInfo.doorStatus == "open")
                        {
                            this.btnDoorLockIcon.IsSelected = true;
                            this.btnDoorlockStatus.TextID = StringId.DoorlockOpen;
                            this.btnDoorlockStatus.TextColor = CSS_Color.WarningColor;
                        }
                        else
                        {
                            this.btnDoorLockIcon.IsSelected = false;
                            this.btnDoorlockStatus.TextID = StringId.DoorlockClose;
                            this.btnDoorlockStatus.TextColor = 0xFF000000;
                        }
                    });
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        CommonMethod.Current.Loading.Hide();
                    });
                }
            });
        }
 
 
 
        /// <summary>
        /// 重新计算宽度(设备名称,房间控件)
        /// </summary>
        private void CalculatedPosition()
        {
            this.btnCurrDeviceName.Width = this.btnCurrDeviceName.GetTextWidth();
            this.btnCurrDeviceName.Width += 10; 
            if (this.btnCurrDeviceName.GetTextWidth() > this.btnCollectIcon.X)
            {
                //重新计算宽度
                this.btnCurrDeviceName.Width = this.btnCollectIcon.X + Application.GetRealWidth(-10);
            }
            this.btnCurrDeviceRoom.Width = this.btnCurrDeviceRoom.GetTextWidth();
            this.btnCurrDeviceRoom.Width += 10;
            if (this.btnCurrDeviceRoom.GetTextWidth() > this.btnCollectIcon.X)
            {
                //重新计算宽度
                this.btnCurrDeviceRoom.Width = this.btnCollectIcon.X + Application.GetRealWidth(-20 - 10);
            }
            this.cellFrame.X = this.btnCurrDeviceRoom.Right + Application.GetRealWidth(20);
        }
 
        /// <summary>
        /// 更新状态
        /// </summary>
        public void UpdateState(PushMessageType pushMessageType)
        {
            CommonMethod.Current.MainThread(() =>
            {
                if (pushMessageType == PushMessageType.Alarm)
                {
                    //门锁电池值
                    if (this.btnCell != null)
                    {
                        //videoDoorLockPage.btnCell.Text = "";
                    }
                }
                else
                {
                    if (this.btnDoorLockIcon != null && !this.btnDoorLockIcon.IsSelected)
                    {
                        this.btnDoorLockIcon.IsSelected = false;
                    }
                }
 
            });
 
        }
 
    }
    /// <summary>
    /// 自己弄一个FrameLayout
    /// </summary>
    class CustomFrameLayout : FrameLayout
    {
        public const int widthFrameLayout = 48;
        public const int heightFrameLayout = 53;
        public const int yFrameLayout = 442;
        public const int xFrameLayout = 41;
        public const int interval = 30;//行中的列间隔值
 
        public CustomFrameLayout(int width, int height, int x = 0, int y = 0)
        {
            this.Width = Application.GetRealWidth(width);
            this.Height = Application.GetRealHeight(height);
            this.X = Application.GetRealWidth(x);
            this.Y = Application.GetRealHeight(y);
 
        }
        Button btnStateImage = new Button
        {
            Width = Application.GetRealWidth(32),
            Height = Application.GetRealWidth(32),
            Gravity = Gravity.TopCenter,
            Name = "btnStateImage",
 
        };
        Button btnStateText = new Button
        {
            Y = Application.GetRealHeight(4),
            Width = Application.GetRealWidth(100),
            Height = Application.GetRealWidth(20),
            TextID = StringId.dangqianmenweiguan,
            TextSize = TextSize.Text12,
            TextColor = MusicColor.TextCancelColor,
            TextAlignment = TextAlignment.Center,
            Gravity = Gravity.CenterHorizontal,
            Name = "btnStateText",
            IsMoreLines = true,
        };
        public void AddImageView()
        {
            this.AddChidren(btnStateImage);
 
        }
        public void AddTextButtonView()
        {
            btnStateText.Y += btnStateImage.Bottom;
            this.AddChidren(btnStateText);
        }
        public Button GetImageButton()
        {
            //if (!this.AddWithout(this.btnStateImage))
            //{
            //    this.AddImageView();
            //}
            return this.btnStateImage;
        }
        public Button GetTextButton()
        {
            //if (!this.AddWithout(this.btnStateText))
            //{
            //    this.AddTextButtonView();
            //}
            return this.btnStateText;
        }
 
        /// <summary>
        /// 事件监听方法
        /// </summary>
        /// <param name="action">回调(第一个是父类对象;第二个是图标对象;第三个是状态对象</param>
        /// <param name="button1">注意:在SetClickListener()前面调用AddImageView()才有效</param>
        /// <param name="button2">注意:在SetClickListener()前面调用AddImageView()才有效</param>
        public void SetClickListener(Action<FrameLayout, Button, Button> action)
        {
            EventHandler<MouseEventArgs> click = (sender, e) =>
                    {
                        action?.Invoke(this, btnStateImage, btnStateText);
                    };
            this.MouseUpEventHandler += click;
            btnStateImage.MouseUpEventHandler += click;
            btnStateText.MouseUpEventHandler += click;
 
        }
 
 
 
        /// <summary>
        /// 在父布局查找子控件是否存在
        /// </summary>
        /// <param name="btn">查找对象</param>
        /// <returns>存在为true,否则为false</returns>
        private bool AddWithout(View btn)
        {
 
            if (this.ChildrenCount <= 0 || btn == null)
            {
                return false;
            }
            for (int i = 0; i < this.ChildrenCount; i++)
            {
                View view = this.GetChildren(i);
                if (view == null)
                {
                    continue;
                }
                if (view is Button)
                {
                    if (view.Name == btn.Name)
                    {
                        return true;
                    }
                }
 
            }
            return false;
 
        }
 
 
 
 
    }
 
 
}