HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
using Shared.Common;
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.MainPage.ControlForm
{
    /// <summary>
    /// mini夜灯的深度卡片界面
    /// </summary>
    public class DeviceMiniLightDetailCardForm : DeviceDetailCardCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 蜂鸣器的开关控件
        /// </summary>
        private IconBigViewControl btnBuzzerSwitch = null;
        /// <summary>
        /// mini夜灯的开关控件
        /// </summary>
        private IconBigViewControl btnMiniSwitch = null;
        /// <summary>
        /// 亮度的进度条控件
        /// </summary>
        private SeekBarControl seekBarLight = null;
        /// <summary>
        /// 色温的进度条控件
        /// </summary>
        private SeekBarControl seekBarColor = null;
        /// <summary>
        /// MaxLevel
        /// </summary>
        private const int MaxLevel = 254;
        /// <summary>
        /// 亮度进度值是否在改变中
        /// </summary>
        private bool isLightProgressing = false;
        /// <summary>
        /// 色温进度值是否在改变中
        /// </summary>
        private bool isColorProgressing = false;
        /// <summary>
        /// 能否发送进度值
        /// </summary>
        private bool canSetProgressValue = true;
        /// <summary>
        /// 1:发送的是小夜灯  2:发送的是蜂鸣器
        /// </summary>
        private int sendDiv = 0;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 底层初始化中部控件完成之后
        /// </summary>
        /// <param name="frameWhiteBack"></param>
        public override void InitMiddleFrameAfter(FrameLayout frameWhiteBack)
        {
            //添加接收蜂鸣器Ack主题
            this.AddReceiveBuzzerAckEvent();
 
            //左滑不能
            this.ScrollEnabled = false;
            //设置状态文字
            if (((LightBase)this.device).OnOffStatus == 1)
            {
                //亮度 XX
                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + "  " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
            }
            else
            {
                //关闭
                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close));
            }
 
            //亮度
            var btnLightView = new NormalViewControl(300, 60, true);
            btnLightView.Text = Language.StringByID(R.MyInternationalizationString.uBrightness) + ":";
            btnLightView.X = Application.GetRealWidth(43);
            btnLightView.Y = Application.GetRealHeight(320);
            frameWhiteBack.AddChidren(btnLightView);
            //底线
            var btnLightLine = new NormalViewControl(Application.GetRealWidth(841), ControlCommonResourse.BottomLineHeight, false);
            btnLightLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
            btnLightLine.X = btnLightView.X;
            btnLightLine.Y = btnLightView.Bottom + Application.GetRealHeight(37);
            frameWhiteBack.AddChidren(btnLightLine);
            //进度条(+60的偏移量)
            this.seekBarLight = new SeekBarControl(611 + 120);
            seekBarLight.Y = Application.GetRealHeight(280);
            seekBarLight.X = Application.GetRealWidth(266 - 60);
            seekBarLight.Height = Application.GetRealHeight(144);
            seekBarLight.SeekBarViewHeight = Application.GetRealHeight(20);
            seekBarLight.SeekBarPadding = Application.GetRealWidth(60);
            seekBarLight.IsProgressTextShow = true;
            seekBarLight.ProgressBarColor = 0xffff6c2c;
            seekBarLight.ProgressTextSize = 14;
            seekBarLight.ProgressTextColor = UserCenterColor.Current.TextGrayColor2;
            seekBarLight.Gravity = Gravity.Frame;
            seekBarLight.Progress = (int)(((ColorTemperatureLight)this.device).Level * 1.0 / MaxLevel * 100);
            frameWhiteBack.AddChidren(seekBarLight);
 
            //色温
            var btnColorView = new NormalViewControl(300, 60, true);
            btnColorView.Text = Language.StringByID(R.MyInternationalizationString.uColorTemperature) + ":";
            btnColorView.X = Application.GetRealWidth(43);
            btnColorView.Y = btnLightLine.Y + Application.GetRealHeight(107);
            frameWhiteBack.AddChidren(btnColorView);
            //底线
            var btnColorLine = new NormalViewControl(Application.GetRealWidth(841), ControlCommonResourse.BottomLineHeight, false);
            btnColorLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
            btnColorLine.X = btnColorView.X;
            btnColorLine.Y = btnColorView.Bottom + Application.GetRealHeight(37);
            frameWhiteBack.AddChidren(btnColorLine);
            //色温的渐变色背景
            var btnColorBack = new PicViewControl(611, 20);
            btnColorBack.UnSelectedImagePath = "Item/ColorTemperatureBar.png";
            btnColorBack.X = Application.GetRealWidth(266);
            btnColorBack.Y = btnColorView.Y + btnColorView.Height / 2 - HdlControlLogic.Current.GetPictrueRealSize(20) / 2;
            frameWhiteBack.AddChidren(btnColorBack);
            //进度条(+60的偏移量,色温的范围是 3000~6000)
            this.seekBarColor = new SeekBarControl(611 + 120);
            seekBarColor.Y = btnLightLine.Bottom + Application.GetRealHeight(58);
            seekBarColor.X = Application.GetRealWidth(266 - 60);
            seekBarColor.Height = Application.GetRealHeight(144);
            seekBarColor.SeekBarViewHeight = Application.GetRealHeight(20);
            seekBarColor.SeekBarPadding = Application.GetRealWidth(60);
            seekBarColor.IsProgressTextShow = true;
            seekBarColor.ProgressBarColor = UserCenterColor.Current.Transparent;
            seekBarColor.SeekBarBackgroundColor = UserCenterColor.Current.Transparent;
            seekBarColor.ProgressTextSize = 14;
            seekBarColor.ProgressTextColor = UserCenterColor.Current.TextGrayColor2;
            seekBarColor.Gravity = Gravity.Frame;
            seekBarColor.ProgressBarUnitSring = "K";
            seekBarColor.MinValue = 30;
            seekBarColor.MaxValue = 60;
            frameWhiteBack.AddChidren(seekBarColor);
            //设置初始值
            int colorValue = ((ColorTemperatureLight)this.device).ColorTemperature;
            if (colorValue == 0) { colorValue = 3000; }
            seekBarColor.Progress = colorValue / 100;
 
            //蜂鸣器开关:
            var btnBuzzerView = new NormalViewControl(300, 60, true);
            btnBuzzerView.Text = Language.StringByID(R.MyInternationalizationString.uBuzzerSwitch) + ":";
            btnBuzzerView.X = Application.GetRealWidth(43);
            btnBuzzerView.Y = btnColorLine.Y + Application.GetRealHeight(107);
            frameWhiteBack.AddChidren(btnBuzzerView);
            //底线
            var btnBuzzerLine = new NormalViewControl(Application.GetRealWidth(841), ControlCommonResourse.BottomLineHeight, false);
            btnBuzzerLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
            btnBuzzerLine.X = btnBuzzerView.X;
            btnBuzzerLine.Y = btnBuzzerView.Bottom + Application.GetRealHeight(37);
            frameWhiteBack.AddChidren(btnBuzzerLine);
            //开关
            this.btnBuzzerSwitch = new IconBigViewControl(81, 81);
            btnBuzzerSwitch.UnSelectedImagePath = "Item/Switch.png";
            btnBuzzerSwitch.SelectedImagePath = "Item/SwitchSelected.png";
            frameWhiteBack.AddChidren(btnBuzzerSwitch);
            btnBuzzerSwitch.InitControl();
            btnBuzzerSwitch.UseClickStatu = false;
            btnBuzzerSwitch.X = Application.GetRealWidth(795) - btnBuzzerSwitch.XOffset;
            btnBuzzerSwitch.Y = btnColorLine.Y + Application.GetRealHeight(98) - btnBuzzerSwitch.YOffset;
            btnBuzzerSwitch.ButtonClickEvent += (sender, e) =>
            {
                //发送开关命令
                this.SetBuzzerSwitchCommand(!btnBuzzerSwitch.IsSelected);
            };
 
            //小夜灯开关:
            var btnMiniView = new NormalViewControl(300, 60, true);
            btnMiniView.Text = Language.StringByID(R.MyInternationalizationString.uMiniLightSwitch) + ":";
            btnMiniView.X = Application.GetRealWidth(43);
            btnMiniView.Y = btnBuzzerLine.Y + Application.GetRealHeight(107);
            frameWhiteBack.AddChidren(btnMiniView);
            //底线
            var btnMiniLine = new NormalViewControl(Application.GetRealWidth(841), ControlCommonResourse.BottomLineHeight, false);
            btnMiniLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
            btnMiniLine.X = btnMiniView.X;
            btnMiniLine.Y = btnMiniView.Bottom + Application.GetRealHeight(37);
            frameWhiteBack.AddChidren(btnMiniLine);
            //开关
            this.btnMiniSwitch = new IconBigViewControl(81, 81);
            btnMiniSwitch.UnSelectedImagePath = "Item/Switch.png";
            btnMiniSwitch.SelectedImagePath = "Item/SwitchSelected.png";
            frameWhiteBack.AddChidren(btnMiniSwitch);
            btnMiniSwitch.InitControl();
            btnMiniSwitch.UseClickStatu = false;
            btnMiniSwitch.X = Application.GetRealWidth(795) - btnMiniSwitch.XOffset;
            btnMiniSwitch.Y = btnBuzzerLine.Y + Application.GetRealHeight(98) - btnMiniSwitch.YOffset;
            btnMiniSwitch.ButtonClickEvent += (sender, e) =>
            {
                //发送开关命令
                this.SetLightSwitchCommand(!btnMiniSwitch.IsSelected);
            };
            btnMiniSwitch.IsSelected = ((LightBase)this.device).OnOffStatus == 1;
            this.canSetProgressValue = btnMiniSwitch.IsSelected;
 
            //亮度开始滑动的事件
            seekBarLight.OnStartTrackingTouchEvent += (sender, e) =>
            {
                //进度值开始变更
                this.isLightProgressing = true;
            };
 
            //亮度结束滑动的事件
            seekBarLight.OnStopTrackingTouchEvent += (sender, e) =>
            {
                //进度值开始结束
                this.isLightProgressing = false;
            };
 
            //亮度滑动过程中
            int oldLightValue = seekBarLight.Progress;//之前的值
            int nowLightValue = oldLightValue;//变更的值
            seekBarLight.OnProgressChangedEvent += (sender, value) =>
            {
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    if (this.canSetProgressValue == true)
                    {
                        //能够发送进度值的时候,才记录
                        nowLightValue = value;
                    }
                }
                else
                {
                    //如果住宅为虚拟住宅,直接改缓存
                    ((ColorTemperatureLight)this.device).Level = value * MaxLevel / 100;
                    //亮度 XX
                    this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + "  " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
                }
            };
 
 
            //色温开始滑动的事件
            seekBarColor.OnStartTrackingTouchEvent += (sender, e) =>
            {
                //进度值开始变更
                this.isColorProgressing = true;
            };
 
            //色温结束滑动的事件
            seekBarColor.OnStopTrackingTouchEvent += (sender, e) =>
            {
                //进度值开始结束
                this.isColorProgressing = false;
            };
 
            //色温滑动过程中
            int oldColorValue = seekBarColor.Progress;//之前的值
            int nowColorValue = oldColorValue;//变更的值
            seekBarColor.OnProgressChangedEvent += (sender, value) =>
            {
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    if (this.canSetProgressValue == true)
                    {
                        //能够发送进度值的时候,才记录
                        nowColorValue = value;
                    }
                }
                else
                {
                    //如果住宅为虚拟住宅,直接改缓存
                    ((ColorTemperatureLight)this.device).ColorTemperature = value * 100;
                }
            };
 
            //开一个线程,监视是否滑动的滑动条,每秒检测一次
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (this.Parent != null)
                {
                    System.Threading.Thread.Sleep(1000);
                    //发送亮度值
                    if (nowLightValue != oldLightValue)
                    {
                        oldLightValue = nowLightValue;
                        ((ColorTemperatureLight)this.device).SetLevel((int)(oldLightValue * MaxLevel / 100.0));
                    }
                    //发送色温值
                    if (nowColorValue != oldColorValue)
                    {
                        oldColorValue = nowColorValue;
                        int value = 1000000 / (oldColorValue * 100);
                        ((ColorTemperatureLight)this.device).SetColorTemperature(value);
                    }
                }
                if (this.canSetProgressValue == true)
                {
                    //界面关闭时
                    if (nowLightValue != oldLightValue)
                    {
                        //发送亮度值
                        ((ColorTemperatureLight)this.device).SetLevel((int)(nowLightValue * MaxLevel / 100.0));
                    }
                    if (nowColorValue != oldColorValue)
                    {
                        //发送色温值
                        int value = 1000000 / (nowColorValue * 100);
                        ((ColorTemperatureLight)this.device).SetColorTemperature(value);
                    }
                }
            });
        }
 
        #endregion
 
        #region ■ 发送夜灯开关命令___________________
 
        /// <summary>
        /// 发送夜灯开关命令
        /// </summary>
        /// <param name="isOpen"></param>
        private void SetLightSwitchCommand(bool isOpen)
        {
            //如果住宅是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                ((LightBase)this.device).OnOffStatus = isOpen == true ? 1 : 0;
                //刷新开关状态
                this.RefreshSwitchStatu(isOpen);
                return;
            }
 
            //当按下开关按钮时,不能再发送进度值
            this.canSetProgressValue = false;
 
            //检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息
            this.StartCheckResponeResult(new List<ButtonBase> { this.btnMiniSwitch.btnIcon }, (result) =>
             {
                 HdlThreadLogic.Current.RunMain(() =>
                 {
                     //接收到网关回复
                     if (result == true)
                     {
                         bool statu = ((LightBase)this.device).OnOffStatus == 1;
                         //刷新开关状态
                         this.RefreshSwitchStatu(statu);
                         if (statu == true)
                         {
                             //当是打开状态时,网关说它会默认把亮度变成100%
                             //以防万一,这里再次读取一下
                             ((ColorTemperatureLight)device).ReadLevel();
                         }
                     }
                 });
             });
 
            this.sendDiv = 1;
            if (isOpen == true)
            {
                //打开
                this.device.SwitchControl(1);
            }
            else
            {
                //关闭
                this.device.SwitchControl(0);
            }
        }
 
        #endregion
 
        #region ■ 发送蜂鸣器开关命令_________________
 
        /// <summary>
        /// 发送蜂鸣器开关命令
        /// </summary>
        /// <param name="isOpen"></param>
        private void SetBuzzerSwitchCommand(bool isOpen)
        {
            //如果住宅是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                //((LightBase)this.device).OnOffStatus = isOpen == true ? 1 : 0;
                ////刷新开关状态
                //this.RefreshSwitchStatu(isOpen);
                return;
            }
 
            //检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息
            this.StartCheckResponeResult(new List<ButtonBase> { this.btnBuzzerSwitch.btnIcon }, (result) =>
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //接收到网关回复
                    if (result == true)
                    {
                        this.btnBuzzerSwitch.IsSelected = isOpen;
                        //bool statu = ((LightBase)this.device).OnOffStatus == 1;
                        ////刷新开关状态
                        //this.RefreshSwitchStatu(statu);
                    }
                });
            });
            //发送命令
            this.sendDiv = 2;
            ((ColorTemperatureLight)this.device).SendBuzzerSwitchControl(isOpen);
        }
 
        /// <summary>
        /// 添加接收蜂鸣器Ack主题
        /// </summary>
        private void AddReceiveBuzzerAckEvent()
        {
            //Ack主题上报
            string mainKeys = LocalDevice.Current.GetDeviceMainKeys(this.device);
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceBuzzerDetailCardACK", ReceiveComandDiv.A节点控制反馈, (report) =>
            {
                string mainKey2 = LocalDevice.Current.GetDeviceMainKeys(report);
                if (mainKeys != mainKey2)
                {
                    //不是同一个东西
                    return;
                }
                //这里只处理蜂鸣器的
                if (this.sendDiv == 2)
                {
                    //结果已经接收到
                    this.ResponeResult = 1;
                }
            });
        }
 
        #endregion
 
        #region ■ 是否获取网关反馈的结果_____________
 
        /// <summary>
        /// 检测网关的反馈结果(属性上报的对象:device.DeviceStatusReport)
        /// </summary>
        /// <param name="comandDiv">命令区分</param>
        /// <param name="report">上报数据</param>
        /// <returns></returns>
        public override bool CheckResponeResultStatu(ReceiveComandDiv comandDiv, CommonDevice report)
        {
            if (comandDiv == ReceiveComandDiv.A设备属性上报)
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //刷新开关状态
                    this.RefreshSwitchStatu(((LightBase)this.device).OnOffStatus == 1);
                });
                return true;
            }
            return false;
        }
 
        #endregion
 
        #region ■ 刷新开关状态_______________________
 
        /// <summary>
        /// 刷新开关状态
        /// </summary>
        /// <param name="isOpen">打开状态</param>
        private void RefreshSwitchStatu(bool isOpen)
        {
            if (this.isColorProgressing == true)
            {
                //如果是色温滑动的话,不需要刷新界面
                return;
            }
            if (isOpen == true)
            {
                //亮度是必须要刷新的  亮度 XX
                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + "  " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
                if (this.isLightProgressing == false)
                {
                    //当进度值在手动变更中时,不接收推送
                    seekBarLight.Progress = (int)(((ColorTemperatureLight)this.device).Level * 1.0 / MaxLevel * 100);
                }
                if (this.isColorProgressing == false)
                {
                    //当进度值在手动变更中时,不接收推送
                    seekBarColor.Progress = (int)(((ColorTemperatureLight)this.device).ColorTemperature / 100);
                }
                this.btnMiniSwitch.IsSelected = true;
            }
            else
            {
                //变更字样:关闭
                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close));
                this.btnMiniSwitch.IsSelected = false;
            }
 
            //回复的结果说,处于打开状态才能发送
            this.canSetProgressValue = isOpen;
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            base.CloseFormBefore();
            HdlGatewayReceiveLogic.Current.RemoveEvent("DeviceBuzzerDetailCardACK");
        }
 
        #endregion
    }
}