gxc
2020-02-28 66a9965c44ecc32a6696abca876ab9d1cd091584
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
using System;
using System.Collections.Generic;
using Shared.Common;
using ZigBee.Device;
using Shared.Phone.Device.AC;
using System.Text;
using Shared.Phone.Device.Account;
 
namespace Shared.Phone.UserView
{
    /// <summary>
    /// User page.
    /// </summary>
    public class UserPage : FrameLayout,ZigBee.Common.IStatus
    {
        #region ◆ 变量_______________________
        /// <summary>
        /// The user menu page.
        /// </summary>
        static UserPage userMenuPage;
        /// <summary>
        /// 底部单独菜单的宽度-360
        /// </summary>
        private static readonly int tabBarEnum_Width = CommonPage.AppRealWidth / 3;
        /// <summary>
        /// 底部按钮图片的高度
        /// </summary>
        private static readonly int tabBarEnumIMG_Height = 98;
        /// <summary>
        /// 底部按钮图片的宽度
        /// </summary>
        private static readonly int tabBarEnumIMG_Width = 138;
        /// <summary>
        /// 底部按钮图片的Y值
        /// </summary>
        private static readonly int tabBarEnumIMG_Y = 3;
        /// <summary>
        /// 底部按钮文字的高度
        /// </summary>
        private static readonly int tabBarEnumName_Height = 40;
        /// <summary>
        /// 底部按钮文字的Y值
        /// </summary>
        private static readonly int tabBarEnumName_Y = 98;
        #endregion
 
        #region ◆ 接口____________________________
 
        /// <summary>
        /// 该接口将弃用 !!!!!!
        /// 改用DeviceInfoChange()
        /// </summary>
        /// <returns>The changed.</returns>
        /// <param name="common">Common.</param>
        public void Changed(CommonDevice common)
        {
 
        }
 
        /// <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)
        {
            var myDevice = LocalDevice.Current.GetDevice(common.DeviceAddr, common.DeviceEpoint);
            if (myDevice == null)
            {
                return;
            }
            //设备上报状态中 当CluterID=3,就证明该设备在线,直接标记
            if (typeTag == "DeviceStatusReport")
            {
                try
                {
                    if (common.DeviceStatusReport.AttriBute == null || common.DeviceStatusReport.AttriBute.Count == 0)
                    {
                        return;
                    }
                    switch (myDevice.Type)
                    {
                        case DeviceType.OnOffOutput:
                            //开关功能
                            if (common.DeviceStatusReport.CluterID == 6)
                            {
                                var onOffOutputLight = (ToggleLight)myDevice;
                                onOffOutputLight.DeviceStatusReport = common.DeviceStatusReport;
                                onOffOutputLight.OnOffStatus = onOffOutputLight.DeviceStatusReport.AttriBute[0].AttriButeData;
                                onOffOutputLight.LastDateTime = DateTime.Now;
                            }
                            //当CluterID=3,就证明该设备在线,直接标记
                            if (common.DeviceStatusReport.CluterID == 3)
                            {
                                myDevice.IsOnline = 1;
                                myDevice.LastDateTime = DateTime.Now;
                            }
                            break;
 
                        case DeviceType.AirSwitch:
                            //开关功能
                            if (common.DeviceStatusReport.CluterID == 6)
                            {
                                var airSwitch = (AirSwitch)myDevice;
                                airSwitch.DeviceStatusReport = common.DeviceStatusReport;
                                airSwitch.OnOffStatus = airSwitch.DeviceStatusReport.AttriBute[0].AttriButeData;
                                airSwitch.LastDateTime = DateTime.Now;
                            }
                            //当CluterID=3,就证明该设备在线,直接标记
                            if (common.DeviceStatusReport.CluterID == 3)
                            {
                                myDevice.IsOnline = 1;
                                myDevice.LastDateTime = DateTime.Now;
                            }
                            break;
 
                        case DeviceType.WindowCoveringDevice:
                            if (common.DeviceStatusReport.CluterID == 258)
                            {
                                var rollershade = (Rollershade)myDevice;
                                rollershade.DeviceStatusReport = common.DeviceStatusReport;
                                var attriButeList = rollershade.DeviceStatusReport.AttriBute;
                                switch (attriButeList[0].AttributeId)
                                {
                                    case 0:
                                        rollershade.WcdType = attriButeList[0].AttriButeData;
                                        rollershade.LastDateTime = DateTime.Now;
                                        break;
                                }
                            }
                            if (common.DeviceStatusReport.CluterID == 3)
                            {
                                myDevice.IsOnline = 1;
                                myDevice.LastDateTime = DateTime.Now;
                            }
                            break;
 
                        case DeviceType.Thermostat:
                            //AC功能
                            if (common.DeviceStatusReport.CluterID == 513)
                            {
                                var ac = (AC)myDevice;
                                ac.DeviceStatusReport = common.DeviceStatusReport;
                                var attriButeList = ac.DeviceStatusReport.AttriBute;
                                foreach (var attList in attriButeList)
                                {
                                    //此属性表明室内当前的温度 * 100,实际温度为“LocalTemperature / 100”,单位:℃
                                    var curTemp = (attList.AttriButeData / 100 < ACControlBase.Temperature_High && attList.AttriButeData / 100 > ACControlBase.Temperature_Low) ? attList.AttriButeData / 100 : ACControlBase.Temperature_Default;
                                    switch (attList.AttributeId)
                                    {
                                        case 0:
                                            ac.currentLocalTemperature = curTemp;
                                            ac.LastDateTime = DateTime.Now;
                                            break;
                                        case 17:
                                            ac.currentCoolingSetpoint = curTemp;
                                            ac.LastDateTime = DateTime.Now;
                                            break;
                                        case 18:
                                            ac.currentHeatingSetpoint = curTemp;
                                            ac.LastDateTime = DateTime.Now;
                                            break;
                                        case 4096:
                                            ac.currentAutoSetpoint = curTemp;
                                            ac.LastDateTime = DateTime.Now;
                                            break;
                                        case 28:
                                            ac.currentSystemMode = attList.AttriButeData;
                                            ac.LastDateTime = DateTime.Now;
                                            break;
                                        case 4097:
                                            ac.CleanStatu = attList.AttriButeData == 42;
                                            break;
                                    }
                                }
                            }
 
                            if (common.DeviceStatusReport.CluterID == 514)
                            {
                                var ac = (AC)myDevice;
                                var attriButeList = common.DeviceStatusReport.AttriBute;
                                ac.DeviceStatusReport = common.DeviceStatusReport;
                                foreach (var attList in attriButeList)
                                {
                                    switch (attList.AttributeId)
                                    {
                                        case 0:
                                            ac.currentFanMode = attList.AttriButeData;
                                            ac.LastDateTime = DateTime.Now;
                                            break;
                                        case 4096:
                                            ac.currentFanSwingMode = attList.AttriButeData;
                                            ac.LastDateTime = DateTime.Now;
                                            break;
                                    }
                                }
                            }
 
                            //当CluterID=3,就证明该设备在线,直接标记
                            if (common.DeviceStatusReport.CluterID == 3)
                            {
                                myDevice.IsOnline = 1;
                                myDevice.LastDateTime = DateTime.Now;
                            }
                            break;
 
                        case DeviceType.DimmableLight:
                            //调光灯功能
                            //开关功能
                            if (common.DeviceStatusReport.CluterID == 6)
                            {
                                var dimmableLight = (DimmableLight)myDevice;
                                dimmableLight.DeviceStatusReport = common.DeviceStatusReport;
                                dimmableLight.OnOffStatus = dimmableLight.DeviceStatusReport.AttriBute[0].AttriButeData;
                                dimmableLight.LastDateTime = DateTime.Now;
                            }
                            //亮度
                            if (common.DeviceStatusReport.CluterID == 8)
                            {
                                var dimmableLight = (DimmableLight)myDevice;
                                dimmableLight.DeviceStatusReport = common.DeviceStatusReport;
                                var attriButeList = dimmableLight.DeviceStatusReport.AttriBute;
                                switch (attriButeList[0].AttributeId)
                                {
                                    case 0:
                                        dimmableLight.Level = attriButeList[0].AttriButeData;
                                        dimmableLight.LastDateTime = DateTime.Now;
                                        break;
                                }
                            }
                            //当CluterID=3,就证明该设备在线,直接标记
                            if (common.DeviceStatusReport.CluterID == 3)
                            {
                                myDevice.IsOnline = 1;
                                myDevice.LastDateTime = DateTime.Now;
                            }
                            break;
 
                        case DeviceType.TemperatureSensor:
                            //温度
                            if (common.DeviceStatusReport.CluterID == 1026)
                            {
                                var tempera = (TemperatureSensor)myDevice;
                                foreach (var data in common.DeviceStatusReport.AttriBute)
                                {
                                    if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue)
                                    {
                                        if (data.AttriButeData == 0)
                                        {
                                            tempera.Temperatrue = 0;
                                        }
                                        else if (data.AttriButeData > 32767)
                                        {
                                            //负数(特殊处理)
                                            string strValue = (data.AttriButeData - 65536).ToString();
                                            //小数点需要一位
                                            strValue = strValue.Substring(0, strValue.Length - 1);
                                            tempera.Temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
                                        }
                                        else
                                        {
                                            //小数点需要一位
                                            string strValue = data.AttriButeData.ToString();
                                            strValue = strValue.Substring(0, strValue.Length - 1);
                                            tempera.Temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
                                        }
                                    }
                                }
                            }
                            //湿度
                            if (common.DeviceStatusReport.CluterID == 1029)
                            {
                                var tempera = (TemperatureSensor)myDevice;
                                foreach (var data in common.DeviceStatusReport.AttriBute)
                                {
                                    if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue)
                                    {
                                        if (data.AttriButeData == 0)
                                        {
                                            tempera.Humidity = 0;
                                        }
                                        else
                                        {
                                            //小数点需要一位(湿度没有负数)
                                            string strValue = data.AttriButeData.ToString();
                                            strValue = strValue.Substring(0, strValue.Length - 1);
                                            tempera.Humidity = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
                                            tempera.LastDateTime = DateTime.Now;
                                        }
                                    }
                                }
                            }
                            break;
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine($"Error:{ex.Message}");
                }
            }
            //设备在线状态上报
            else if (typeTag == "OnlineStatusChange")
            {
                myDevice.IsOnline = common.IsOnline;
                //记录回复时间
                myDevice.LastDateTime = DateTime.Now;
            }
            else if (typeTag == "IASInfoReport")
            {
                try
                {
                    switch (myDevice.Type)
                    {
                        case DeviceType.IASZone:
                            var iAS = (IASZone)myDevice;
                            iAS.iASInfo = (common as IASZone).iASInfo;
                            iAS.LastDateTime = DateTime.Now;
                            break;
                    }
                }
                catch { }
            }
        }
        /// <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();
        }
        #endregion
 
        /// <summary>
        /// 用户界面
        /// </summary>
        /// <value>The instance.</value>
        public static UserPage Instance
        {
            get
            {
                if (userMenuPage == null)
                {
                    userMenuPage = new UserPage { };
                }
                return userMenuPage;
            }
        }
 
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Shared.Phone.UserView.UserPage"/> class.
        /// </summary>
        public UserPage()
        {
            BackgroundColor = Shared.Common.ZigbeeColor.Current.MainColor;
            ZbGateway.StatusList.Add(this);
            Shared.Application.LocationAction += (lon, lat) =>
            {
                AccountLogic.Instance.ReceiveAppLatAndLon(lon.ToString(), lat.ToString());
            };
        }
 
        /// <summary>
        /// 用户主体界面(中间部分)
        /// </summary>
        public FrameLayout BodyView = new FrameLayout
        {
            Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.TabbarHeight),
            BackgroundColor = Shared.Common.ZigbeeColor.Current.MainColor,
        };
        /// <summary>
        /// 用户菜单界面(底部部分)
        /// </summary>
        public FrameLayout BottomMenuView = new FrameLayout
        {
            Y = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.TabbarHeight),
            Height = Application.GetRealHeight(CommonPage.TabbarHeight),
            BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCBottomColor,
        };
 
        #region 分割线
 
        private Button bottomLine = new Button
        {
            Height = 1,
            BackgroundColor = ZigbeeColor.Current.GXCBottomLineColor
        };
 
        #endregion
 
        #region 底部-主页按钮
        /// <summary>
        /// 底部-主页按钮
        /// </summary>
        public FrameLayout homePageFL = new FrameLayout
        {
            Width = Application.GetRealWidth(tabBarEnum_Width),
            Height = Application.GetRealHeight(CommonPage.TabbarHeight),
 
        };
        /// <summary>
        /// The home page image.
        /// </summary>
        public Button homePageIMG = new Button
        {
            Y = Application.GetRealHeight(tabBarEnumIMG_Y),
            Height = Application.GetMinRealAverage(tabBarEnumIMG_Height),
            Width = Application.GetMinRealAverage(tabBarEnumIMG_Width),
            UnSelectedImagePath = "Navigation/Home.png",
            SelectedImagePath = "Navigation/HomeSelected.png",
            IsSelected = true,
            Gravity = Gravity.CenterHorizontal
        };
        /// <summary>
        /// The name of the home page.
        /// </summary>
        public Button homePageName = new Button
        {
            Y = Application.GetRealHeight(tabBarEnumName_Y),
            Height = Application.GetRealHeight(tabBarEnumName_Height),
            TextID = R.MyInternationalizationString.HomePage,
            TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBottomUnSelectedColor,
            SelectedTextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor2,
            IsSelected = true,
            Gravity = Gravity.CenterHorizontal,
            TextSize = 10
        };
        #endregion
 
        #region 分类-底部按钮
        /// <summary>
        /// 分类-底部按钮
        /// </summary>
        public FrameLayout categoryFL = new FrameLayout
        {
            X=Application.GetRealWidth(tabBarEnum_Width),
            Width = Application.GetRealWidth(tabBarEnum_Width),
            Height = Application.GetRealHeight(CommonPage.TabbarHeight)
        };
        /// <summary>
        /// The category image.
        /// </summary>
        public Button categoryIMG = new Button
        {
            Y = Application.GetRealHeight(tabBarEnumIMG_Y),
            Height = Application.GetMinRealAverage(tabBarEnumIMG_Height),
            Width = Application.GetMinRealAverage(tabBarEnumIMG_Width),
            UnSelectedImagePath = "Navigation/Category.png",
            SelectedImagePath = "Navigation/CategorySelected.png",
            Gravity = Gravity.CenterHorizontal
        };
        /// <summary>
        /// The name of the category.
        /// </summary>
        public Button categoryName = new Button
        {
            Y = Application.GetRealHeight(tabBarEnumName_Y),
            Height = Application.GetRealHeight(tabBarEnumName_Height),
            TextID = R.MyInternationalizationString.Category,
            TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBottomUnSelectedColor,
            SelectedTextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor2,
            IsSelected = false,
            Gravity = Gravity.CenterHorizontal,
            TextSize=10
        };
        #endregion
 
        #region 个人中心-底部按钮
        /// <summary>
        /// 个人中心-底部按钮
        /// </summary>
        public FrameLayout settingFL = new FrameLayout
        {
            X = Application.GetRealWidth(tabBarEnum_Width*2),
            Width = Application.GetRealWidth(tabBarEnum_Width),
            Height = Application.GetRealHeight(CommonPage.TabbarHeight)
        };
        /// <summary>
        /// The setting image.
        /// </summary>
        public Button settingIMG = new Button
        {
            Y = Application.GetRealHeight(tabBarEnumIMG_Y),
            Height = Application.GetMinRealAverage(tabBarEnumIMG_Height),
            Width = Application.GetMinRealAverage(tabBarEnumIMG_Width),
            UnSelectedImagePath = "Navigation/Setting.png",
            SelectedImagePath = "Navigation/SettingSelected.png",
            Gravity = Gravity.CenterHorizontal
        };
        /// <summary>
        /// 个人中心
        /// </summary>
        public Button settingName = new Button
        {
            Y = Application.GetRealHeight(tabBarEnumName_Y),
            Height = Application.GetRealHeight(tabBarEnumName_Height),
            TextID = R.MyInternationalizationString.Me,
            TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBottomUnSelectedColor,
            SelectedTextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor2,
            IsSelected = false,
            Gravity = Gravity.CenterHorizontal,
            TextSize = 10
        };
        #endregion
 
 
        EventHandler<MouseEventArgs> BottomEventHandler = (sender, e) =>
        {
            Instance.homePageName.IsSelected = false;
            Instance.homePageIMG.IsSelected = false;
 
            Instance.categoryName.IsSelected = false;
            Instance.categoryIMG.IsSelected = false;
 
            Instance.settingName.IsSelected = false;
            Instance.settingIMG.IsSelected = false;
 
            Instance.BodyView.RemoveAll();
            if (sender == Instance.homePageIMG || sender == Instance.homePageName)
            {
                //主页
                CommonPage.Instance.IsDrawerLockMode = false;
                Instance.homePageName.IsSelected = true;
                Instance.homePageIMG.IsSelected = true;
                var home = new UserHomeView { };
                Instance.BodyView.AddChidren(home);
                home.Show();
 
            }
            else if (sender == Instance.categoryIMG || sender==Instance.categoryName)
            {
                //分类
                CommonPage.Instance.IsDrawerLockMode = true;
                Instance.categoryName.IsSelected = true;
                Instance.categoryIMG.IsSelected = true;
                var category = new Phone.Device.Category.Category { };
                Instance.BodyView.AddChidren(category);
                category.Show();
            }
            else if (sender == Instance.settingIMG || sender==Instance.settingName)
            {
                //个人中心
                CommonPage.Instance.IsDrawerLockMode = true;
                Instance.settingName.IsSelected = true;
                Instance.settingIMG.IsSelected = true;
                var form = new UserCenter.UserMain.UserMainForm();
                Instance.BodyView.AddChidren(form);
                form.ShowForm();
            }
        };
 
        /// <summary>
        /// Fresh this instance.
        /// </summary>
        public void Fresh()
        {
            BottomEventHandler(Instance.homePageIMG, null);
        }
 
        /// <summary>
        /// Inits the page.
        /// </summary>
        public void InitPage()
        {
            if (0 < ChildrenCount)
            {
                return;
            }
 
            AddChidren(BodyView);
            AddChidren(BottomMenuView);
 
            BottomMenuView.AddChidren(Instance.bottomLine);
 
            Instance.homePageFL.AddChidren(Instance.homePageIMG);
            Instance.homePageFL.AddChidren(Instance.homePageName);
            BottomMenuView.AddChidren(Instance.homePageFL);
 
            Instance.categoryFL.AddChidren(Instance.categoryIMG);
            Instance.categoryFL.AddChidren(Instance.categoryName);
            BottomMenuView.AddChidren(Instance.categoryFL);
 
            Instance.settingFL.AddChidren(Instance.settingIMG);
            Instance.settingFL.AddChidren(Instance.settingName);
            BottomMenuView.AddChidren(Instance.settingFL);
 
            homePageIMG.MouseUpEventHandler += BottomEventHandler;
            homePageName.MouseUpEventHandler += BottomEventHandler;
 
            categoryIMG.MouseUpEventHandler += BottomEventHandler;
            categoryName.MouseUpEventHandler += BottomEventHandler;
 
            settingIMG.MouseUpEventHandler += BottomEventHandler;
            settingName.MouseUpEventHandler += BottomEventHandler;
        }
    }
}