HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-12-30 3dcbd186c42c598c0c08d1cd37034cf2baa09e54
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
using System;
using System.Collections.Generic;
using System.Globalization;
using Shared.Common;
using Shared.Phone.Device.CommonForm;
using Shared.Phone.Device.DeviceLogic;
using Shared.Phone.UserCenter;
using Shared.Phone.UserView;
using ZigBee.Device;
 
namespace Shared.Phone.Device.Room
{
    public class EditRoom : FrameLayout, ZigBee.Common.IStatus
    {
        #region ◆ 变量____________________________
        /// <summary>
        /// bodyFrameLayout
        /// </summary>
        private FrameLayout bodyFrameLayout;
 
        /// <summary>
        /// The room.
        /// </summary>
        public Shared.Common.Room room;
 
        /// <summary>
        /// The action.
        /// </summary>
        public Action action;
 
        /// <summary>
        /// backGround
        /// </summary>
        private ImageView backGround;
        /// <summary>
        /// IconPathType
        /// </summary>
        public int IconPathType;
        /// <summary>
        /// OldBackgroundImagePath
        /// </summary>
        private string OldBackgroundImagePath;
 
        /// <summary>
        /// OldIconPathType
        /// </summary>
        public int OldIconPathType;
 
        CommonDevice temperDevice;
 
        CommonDevice humidDevice;
 
        DeviceInfoRow temperatureRow;
 
        DeviceInfoRow humidityRow;
 
        #endregion
 
        #region ◆ 接口__________________________
        /// <summary>
        /// 处理变化事件 --将弃用 改用DeviceInfoChange()
        /// </summary>
        /// <returns>The changed.</returns>
        /// <param name="common">Common.</param>
        public void Changed(CommonDevice common)
        {
 
        }
        /// <summary>
        /// Changeds the IL ogic status.
        /// </summary>
        /// <param name="logic">Logic.</param>
        public void ChangedILogicStatus(ZigBee.Device.Logic logic)
        {
            //throw new NotImplementedException();
        }
        /// <summary>
        /// Changeds the IS cene status.
        /// </summary>
        /// <param name="scene">Scene.</param>
        public void ChangedISceneStatus(Scene scene)
        {
            //throw new NotImplementedException();
        }
        /// <summary>
        /// 设备状态更新接口
        /// <para>type:如果为 DeviceInComingRespon:设备新上报</para>
        /// <para>type:如果为 IASInfoReport:RemoveDeviceRespon</para>
        /// <para>type:如果为 DeviceStatusReport:设备上报</para>
        /// <para>type:如果为 IASInfoReport:IAS安防信息上报</para>
        /// <para>type:如果为 OnlineStatusChange: 设备在线状态更新</para>
        /// </summary>
        /// <param name="common">Common.</param>
        /// <param name="typeTag">Type tag.</param>
        public void DeviceInfoChange(CommonDevice common, string typeTag)
        {
            if (typeTag == "DeviceStatusReport")
            {
                Application.RunOnMainThread(() =>
                {
                    try
                    {
                        if (common.DeviceStatusReport.AttriBute == null || common.DeviceStatusReport.AttriBute.Count == 0)
                        {
                            return;
                        }
                        //是否为当前设备
                        if ((temperDevice?.DeviceEpoint != common.DeviceEpoint || temperDevice?.DeviceAddr != common.DeviceAddr) && (humidDevice?.DeviceEpoint != common.DeviceEpoint || humidDevice?.DeviceAddr != common.DeviceAddr))
                        {
                            //return;
                        }
 
                        //if (common.Type == DeviceType.TemperatureSensor)
                        //{
                        if (common.DeviceStatusReport.CluterID == 1026)
                        {
                            foreach (var data in common.DeviceStatusReport.AttriBute)
                            {
                                if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue)
                                {
                                    if (data.AttriButeData == 0)
                                    {
                                        //0℃
                                        temperatureRow.NameText.Text = "--℃";
                                        room.Temperatrue = 0;
                                    }
                                    else if (data.AttriButeData > 32767)
                                    {
                                        //负数(特殊处理)
                                        string strValue = (data.AttriButeData - 65536).ToString();
                                        //小数点需要一位
                                        strValue = strValue.Substring(0, strValue.Length - 1);
                                        temperatureRow.NameText.Text = strValue.Insert(strValue.Length - 1, ".") + "℃";
                                        room.Temperatrue = int.Parse(strValue) * 0.1;
                                    }
                                    else
                                    {
                                        //小数点需要一位
                                        string strValue = data.AttriButeData.ToString();
                                        strValue = strValue.Substring(0, strValue.Length - 1);
                                        temperatureRow.NameText.Text = strValue.Insert(strValue.Length - 1, ".") + "℃";
                                        room.Temperatrue = int.Parse(strValue) * 0.1;
                                    }
                                }
                            }
                        }
                        else if (common.DeviceStatusReport.CluterID == 1029)
                        {
                            foreach (var data in common.DeviceStatusReport.AttriBute)
                            {
                                if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue)
                                {
                                    if (data.AttriButeData == 0)
                                    {
                                        //0
                                        humidityRow.NameText.Text = "--%";
                                        room.Humidity = 0;
                                    }
                                    else
                                    {
                                        //小数点需要一位(湿度没有负数)
                                        string strValue = data.AttriButeData.ToString();
                                        strValue = strValue.Substring(0, strValue.Length - 1);
                                        humidityRow.NameText.Text = strValue.Insert(strValue.Length - 1, ".") + "%";
                                        room.Humidity = int.Parse(strValue) * 0.1;
                                    }
                                }
                            }
                        }
                        //}
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine($"Error:{ex.Message}");
                    }
                });
            }
        }
        #endregion
 
 
 
        public EditRoom()
        {
            ZbGateway.StatusList.Add(this);
            BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
        }
 
        /// <summary>
        /// Show this instance.
        /// </summary>
        public void Show(Shared.Common.Room r)
        {
            room = r;
            IconPathType = r.BackgroundImageType;
            OldIconPathType= r.BackgroundImageType;
            if (IconPathType != 0)
            {
                OldBackgroundImagePath = r.BackgroundImage;
            }
            AddTop();
 
            AddBodyView();
 
        }
 
        public override void RemoveFromParent()
        {
            ZbGateway.StatusList.Remove(this);
            CommonPage.Instance.IsDrawerLockMode = false;
            base.RemoveFromParent();
        }
 
        #region Add____________________________________
 
        /// <summary>
        /// AddTop
        /// </summary>
        public void AddTop()
        {
            var top = new TopFrameLayout();
            AddChidren(top);
            top.InitTopview();
            top.SetTopTitle(R.MyInternationalizationString.EditRoom);
            top.backButton.MouseUpEventHandler += (sender, e) =>
            {
                RemoveFromParent();
            };
        }
 
        /// <summary>
        /// AddBodyView
        /// </summary>
        public void AddBodyView()
        {
            bodyFrameLayout = new FrameLayout()
            {
                Y = Application.GetRealHeight(184),
                Height = Application.GetRealHeight(1737),
                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
            };
            AddChidren(bodyFrameLayout);
 
            backGround = new ImageView()
            {
                Y = Application.GetRealHeight(60),
                Width = Application.GetMinRealAverage(887),
                Height = Application.GetMinRealAverage(444),
                Gravity = Gravity.CenterHorizontal,
                Radius = (uint)Application.GetRealHeight(CommonFormResouce.BigFormRadius),
                ImagePath = room.BackgroundImageType == 0 ? room.BackgroundImage : System.IO.Path.Combine(Config.Instance.FullPath, room.BackgroundImage)
            };
            bodyFrameLayout.AddChidren(backGround);
            backGround.SetViewShadow(true);
            if (room.BackgroundImageType != 0)
            {
                backGround.ImageBytes = Shared.IO.FileUtils.ReadFile(backGround.ImagePath);
            }
            backGround.MouseUpEventHandler += backGroundIMGHander;
 
            var infoFL = new FrameLayout
            {
                Y = Application.GetRealHeight(562),
                Height = Application.GetRealHeight(1175),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
            };
            bodyFrameLayout.AddChidren(infoFL);
            var rectCornerID = HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight;
            infoFL.SetCornerWithSameRadius(Application.GetRealHeight(50), rectCornerID);
 
            var infoEdit = new Button
            {
                X = Application.GetRealWidth(CommonFormResouce.X_Left),
                Y = Application.GetRealHeight(80),
                Height = Application.GetRealHeight(60),
                Width = Application.GetRealWidth(700),
                TextID = R.MyInternationalizationString.EditInfo,
                TextColor = ZigbeeColor.Current.GXCTextDeepBlackColor,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 15
            };
            infoFL.AddChidren(infoEdit);
 
            var nameRow = new DeviceInfoEditRow(170);
            nameRow.Init();
            nameRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.RoomName)} :");
            nameRow.SetTitle(room.Name);
            infoFL.AddChidren(nameRow);
            if(room.IsLove)
            {
                nameRow.NameText.Enable = false;
            }
 
            var floorRow = new DeviceInfoRow(308);
            floorRow.Init();
            floorRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.BelongFloor)} :");
            if (Config.Instance.Home.FloorDics.Count > 0 && room.IsLove == false)
            {
                infoFL.AddChidren(floorRow);
            }
            floorRow.SetTitle(room.FloorName);
            floorRow.ClickBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (Config.Instance.Home.FloorDics != null)
                {
                    List<string> floorIds = new List<string> { };
                    List<string> floorNames = new List<string> { };
                    foreach (var floor in Config.Instance.Home.FloorDics)
                    {
                        floorIds.Add(floor.Key);
                        floorNames.Add(floor.Value);
                    }
 
                    PickerView.Show(floorNames, (index) =>
                    {
                        room.FloorId = floorIds[index];
                        floorRow.SetTitle(room.FloorName);
                    }, floorIds.IndexOf(room.FloorId), Language.StringByID(R.MyInternationalizationString.BelongFloor), Language.StringByID(R.MyInternationalizationString.Confrim), Language.StringByID(R.MyInternationalizationString.Cancel));
                }
            };
 
 
            temperatureRow = new DeviceInfoRow(446);
            temperatureRow.Init();
            temperatureRow.SetTipTitle(R.MyInternationalizationString.Temperature);
            temperatureRow.NameText.TextAlignment = TextAlignment.CenterRight;
            infoFL.AddChidren(temperatureRow);
            temperatureRow.ClickBtn.MouseUpEventHandler += (sender, e) =>
            {
                var tem = new RoomTemperatureSetting { };
                HomePage.Instance.AddChidren(tem);
                HomePage.Instance.PageIndex += 1;
                tem.tempDevice = Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice);
                tem.Show(room);
                tem.selectDeviceAction = (selectTemp) =>
                {
                    if (selectTemp == null)
                    {
                        return;
                    }
                    room.TemperatrueDevice = $"{selectTemp.DeviceAddr}{selectTemp.DeviceEpoint}";
                    temperatureRow.SetTitle(R.MyInternationalizationString.Getting);
                    //发送获取温度的命令
                    ReadDeviceAttributeLogic.Instance.SendTemperatureStatuComand(selectTemp);
                };
            };
            if (string.IsNullOrEmpty(room.TemperatrueDevice) == false)
            {
                temperatureRow.SetTitle(R.MyInternationalizationString.Getting);
                //发送获取温度的命令
                var dev = Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice);
                ReadDeviceAttributeLogic.Instance.SendTemperatureStatuComand(dev);
            }
            else
            {
                temperatureRow.SetTitle(R.MyInternationalizationString.No);
            }
 
 
            humidityRow = new DeviceInfoRow(585);
            humidityRow.Init();
            humidityRow.SetTipTitle(R.MyInternationalizationString.Humidity);
            humidityRow.NameText.TextAlignment = TextAlignment.CenterRight;
            infoFL.AddChidren(humidityRow);
            humidityRow.ClickBtn.MouseUpEventHandler += (sender, e) =>
            {
                var tem = new RoomHumiditySetting { };
                HomePage.Instance.AddChidren(tem);
                HomePage.Instance.PageIndex += 1;
                tem.tempDevice = Common.LocalDevice.Current.GetDevice(room.HumidityDevice);
                tem.Show(room);
                tem.selectDeviceAction = (selectTemp) =>
                {
                    if (selectTemp == null)
                    {
                        return;
                    }
                    room.HumidityDevice = $"{selectTemp.DeviceAddr}{selectTemp.DeviceEpoint}";
                    humidityRow.SetTitle(R.MyInternationalizationString.Getting);
 
                    //发送获取湿度的命令
                    ReadDeviceAttributeLogic.Instance.SendHumidityStatuComand(selectTemp);
                };
            };
            if (string.IsNullOrEmpty(room.HumidityDevice) == false)
            {
                humidityRow.SetTitle(R.MyInternationalizationString.Getting);
                //发送获取湿度的命令
                var dev = Common.LocalDevice.Current.GetDevice(room.HumidityDevice);
                ReadDeviceAttributeLogic.Instance.SendHumidityStatuComand(dev);
            }
            else
            {
                humidityRow.SetTitle(R.MyInternationalizationString.No);
            }
 
            if (Config.Instance.Home.FloorDics.Count == 0 || room.IsLove)
            {
                temperatureRow.Y = Application.GetRealHeight(308);
                humidityRow.Y= Application.GetRealHeight(446);
            }
 
            var confirm = new Device.CommonForm.CompleteButton(1700, 900, 127);
            confirm.SetTitle(R.MyInternationalizationString.Confrim);
            AddChidren(confirm);
            confirm.MouseUpEventHandler += (sender, e) =>
            {
                var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
                var fileName = $"RoomIcon_{tradeTime}.png";
                room.Name = nameRow.NameText.Text.Trim();
                if (OldIconPathType != 0)
                {
                    Shared.IO.FileUtils.DeleteFile(System.IO.Path.Combine(Config.Instance.FullPath,OldBackgroundImagePath));
                }
                if (IconPathType == 0)
                {
                    room.BackgroundImage = backGround.ImagePath;
                }
                else
                {
                    Shared.IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), backGround.ImageBytes);
                    room.BackgroundImage = fileName;
                }
                room.BackgroundImageType = IconPathType;
                room.Save();
                action?.Invoke();
                RemoveFromParent();
            };
        }
 
        /// <summary>
        /// 选择背景图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backGroundIMGHander(object sender, MouseEventArgs e)
        {
            if (room != null && room.IsSharedRoom)
            {
                RoomCommon.ShowTipRoomIsShared();
                return;
            }
 
            int selectRow_Height = 150;
            int selectRow_Width = 1034;
            var selectFL = new FrameLayout()
            {
                BackgroundColor = ZigbeeColor.Current.GXCDailogBackGroundColor
            };
            AddChidren(selectFL);
 
            var itemFL = new FrameLayout()
            {
                Y = Application.GetRealHeight(1276),
                Height = Application.GetRealHeight(450),
                Width = Application.GetRealWidth(selectRow_Width),
                Gravity = Gravity.CenterHorizontal,
                Radius = (uint)Application.GetRealHeight(35),
                BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
            };
            selectFL.AddChidren(itemFL);
            //itemFL.Animate = Animate.DownToUp;
 
            var selectLocalPicture = new Button()
            {
                Height = Application.GetRealHeight(selectRow_Height) - 1,
                TextID = R.MyInternationalizationString.LocalPicture,
                TextColor = ZigbeeColor.Current.GXCTextSelectedColor4,
                TextSize = 17
            };
            itemFL.AddChidren(selectLocalPicture);
            var selectLocalLine = new Button()
            {
                Y = selectLocalPicture.Bottom,
                Height = 1,
                BackgroundColor = ZigbeeColor.Current.GXCGrayLineColor2
            };
            itemFL.AddChidren(selectLocalLine);
 
            var selectPhotographBtn = new Button()
            {
                Y = selectLocalLine.Bottom,
                Height = Application.GetRealHeight(selectRow_Height) - 1,
                TextID = R.MyInternationalizationString.Photograph,
                TextColor = ZigbeeColor.Current.GXCTextSelectedColor4,
                TextSize = 17
            };
            itemFL.AddChidren(selectPhotographBtn);
            var selectPhotographLine = new Button()
            {
                Y = selectPhotographBtn.Bottom,
                Height = 1,
                BackgroundColor = ZigbeeColor.Current.GXCGrayLineColor2,
            };
            itemFL.AddChidren(selectPhotographLine);
 
            var selectAblumsBtn = new Button()
            {
                Y = selectPhotographLine.Bottom,
                Height = Application.GetRealHeight(selectRow_Height) - 1,
                TextID = R.MyInternationalizationString.MyAblums,
                TextColor = ZigbeeColor.Current.GXCTextSelectedColor4,
                TextSize = 17
            };
            itemFL.AddChidren(selectAblumsBtn);
 
            var cancelBtn = new Button()
            {
                Y = Application.GetRealHeight(1742),
                Height = Application.GetRealHeight(selectRow_Height),
                Width = Application.GetRealWidth(selectRow_Width),
                Gravity = Gravity.CenterHorizontal,
                TextID = R.MyInternationalizationString.Cancel,
                TextColor = ZigbeeColor.Current.GXCTextSelectedColor4,
                BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor,
                Radius = (uint)Application.GetRealHeight(35),
                TextSize = 17
            };
            selectFL.AddChidren(cancelBtn);
 
            selectLocalPicture.MouseUpEventHandler += (send, ee) =>
            {
                selectFL.RemoveFromParent();
                var localPic = new AddRoomSelectPicByLocal();
                Shared.Phone.UserView.HomePage.Instance.AddChidren(localPic);
                Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                localPic.Show();
                localPic.action = (imgPath) =>
                {
                    IconPathType = 0;
                    backGround.ImageBytes = null;
                    backGround.ImagePath = imgPath;
                };
            };
            selectPhotographBtn.MouseUpEventHandler += (send, ee) =>
            {
                selectFL.RemoveFromParent();
                var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
                var fileName = $"RoomIcon_{tradeTime}.png";
                //通过相机拍照裁剪
                CropImage.TakePicture((imagePath) =>
                {
                    if (string.IsNullOrEmpty(imagePath) == true)
                    {
                        return;
                    }
                    if (IconPathType != 0)
                    {
                        Global.DeleteFilebyHomeId(backGround.ImagePath);
                    }
 
                    IconPathType = 1;
                    backGround.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
                    backGround.ImagePath = imagePath;
                    System.IO.File.Delete(imagePath);
 
                }, fileName, 2, 1);
            };
 
            selectAblumsBtn.MouseUpEventHandler += (send, ee) =>
            {
                selectFL.RemoveFromParent();
                var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
                var fileName = $"RoomIcon_{tradeTime}.png";
                //从相册选择图片裁剪
                CropImage.SelectPicture((imagePath) =>
                {
                    if (string.IsNullOrEmpty(imagePath) == true)
                    {
                        return;
                    }
                    if (IconPathType != 0)
                    {
                        Global.DeleteFilebyHomeId(backGround.ImagePath);
                    }
 
                    IconPathType = 2;
                    backGround.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
                    backGround.ImagePath = imagePath;
                    System.IO.File.Delete(imagePath);
 
                }, fileName, 2, 1);
            };
 
            cancelBtn.MouseUpEventHandler += (send, ee) =>
            {
                selectFL.RemoveFromParent();
            };
            selectFL.MouseUpEventHandler += (send, ee) =>
            {
                selectFL.RemoveFromParent();
            };
        }
 
        #endregion
 
    }
}