黄学彪
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
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>
    /// 窗帘类型的深度卡片界面
    /// </summary>
    public class DeviceCurtainDetailCardForm : DeviceDetailCardCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 打开控件
        /// </summary>
        private IconBigViewControl btnOpen = null;
        /// <summary>
        /// 停止控件
        /// </summary>
        private IconBigViewControl btnStop = null;
        /// <summary>
        /// 关闭控件
        /// </summary>
        private IconBigViewControl btnClose = null;
        /// <summary>
        /// 窗帘类型 4:开合帘 0:卷帘
        /// </summary>
        private int WcdType = -2;
        /// <summary>
        /// 开合帘控件
        /// </summary>
        private CurtainSeekBar SeekBarOpenCurtain = null;
        /// <summary>
        /// 卷帘控件
        /// </summary>
        private CurtainRollSeekBar SeekBarSiphonateCurtain = null;
        /// <summary>
        /// 进度值是否在改变中
        /// </summary>
        private bool isProgressing = false;
        /// <summary>
        /// 是否已经初始化了控件(因为底层有可能会刷新整个界面)
        /// </summary>
        private bool hadInitControl = false;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 底层初始化中部控件完成之后
        /// </summary>
        /// <param name="frameWhiteBack"></param>
        public override void InitMiddleFrameAfter(FrameLayout frameWhiteBack)
        {
            //左滑不能
            this.ScrollEnabled = false;
            this.WcdType = ((Rollershade)this.device).WcdType;
            //设置状态文字
            this.SetStatuText(HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
 
            if (WcdType == 0)
            {
                //初始化卷帘控件
                this.InitSiphonateCurtainControl(frameWhiteBack);
            }
            else
            {
                //初始化开合帘控件
                this.InitOpenCurtainControl(frameWhiteBack);
            }
 
            //打开控件
            this.btnOpen = new IconBigViewControl(81, 81);
            btnOpen.btnIcon.UseClickStatu = true;
            frameWhiteBack.AddChidren(btnOpen);
            btnOpen.InitControl();
            btnOpen.X = Application.GetRealWidth(253) - btnOpen.XOffset;
            btnOpen.Y = Application.GetRealHeight(994) - btnOpen.YOffset;
            btnOpen.ButtonClickEvent += (sender, e) =>
            {
                //如果住宅为虚拟住宅,则此功能无效
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    ((Rollershade)device).WcdCurrentPositionLiftPercentage = 100;
                    if (this.WcdType == 0)
                    {
                        SeekBarSiphonateCurtain.Progress = 100;
                    }
                    else
                    {
                        SeekBarOpenCurtain.Progress = 100;
                    }
                    //设置状态文字
                    this.SetStatuText(HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
                    return;
                }
                //发送窗帘命令
                this.SetCurtainCommand(0);
            };
 
            //停止控件
            this.btnStop = new IconBigViewControl(81, 81);
            btnStop.btnIcon.UseClickStatu = true;
            btnStop.UnSelectedImagePath = "RollerShade/Stop.png";
            btnStop.SelectedImagePath = "RollerShade/StopSelected.png";
            frameWhiteBack.AddChidren(btnStop);
            btnStop.InitControl();
            btnStop.X = btnOpen.Right + Application.GetRealWidth(109) - btnOpen.XOffset;
            btnStop.Y = btnOpen.Y;
            btnStop.ButtonClickEvent += (sender, e) =>
            {
                //如果住宅为虚拟住宅,则此功能无效
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    return;
                }
                //发送窗帘命令
                this.SetCurtainCommand(2);
            };
 
            //关闭
            this.btnClose = new IconBigViewControl(81, 81);
            btnClose.btnIcon.UseClickStatu = true;
            frameWhiteBack.AddChidren(btnClose);
            btnClose.InitControl();
            btnClose.X = btnStop.Right + Application.GetRealWidth(109) - btnOpen.XOffset;
            btnClose.Y = btnOpen.Y;
            btnClose.ButtonClickEvent += (sender, e) =>
            {
                //如果住宅为虚拟住宅,则此功能无效
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    ((Rollershade)device).WcdCurrentPositionLiftPercentage = 0;
                    if (this.WcdType == 0)
                    {
                        SeekBarSiphonateCurtain.Progress = 0;
                    }
                    else
                    {
                        SeekBarOpenCurtain.Progress = 0;
                    }
                    //设置状态文字
                    this.SetStatuText(HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
                    return;
                }
                //发送窗帘命令
                this.SetCurtainCommand(1);
            };
 
            if (this.WcdType == 0)
            {
                btnOpen.UnSelectedImagePath = "RollerShade/Up.png";
                btnOpen.SelectedImagePath = "RollerShade/UpSelected.png";
                btnClose.UnSelectedImagePath = "RollerShade/Down.png";
                btnClose.SelectedImagePath = "RollerShade/DownSelected.png";
            }
            else
            {
                btnOpen.UnSelectedImagePath = "RollerShade/Open.png";
                btnOpen.SelectedImagePath = "RollerShade/OpenSelected.png";
                btnClose.UnSelectedImagePath = "RollerShade/Close.png";
                btnClose.SelectedImagePath = "RollerShade/CloseSelected.png";
            }
        }
 
        #endregion
 
        #region ■ 初始化卷帘控件_____________________
 
        /// <summary>
        /// 初始化卷帘控件
        /// </summary>
        private void InitSiphonateCurtainControl(FrameLayout frameWhiteBack)
        {
            //卷帘控件
            this.SeekBarSiphonateCurtain = new CurtainRollSeekBar();
            SeekBarSiphonateCurtain.Y = Application.GetRealHeight(300);
            SeekBarSiphonateCurtain.Width = this.GetPictrueRealSize(438);
            SeekBarSiphonateCurtain.Height = this.GetPictrueRealSize(576);
            SeekBarSiphonateCurtain.Gravity = Gravity.CenterHorizontal;
            SeekBarSiphonateCurtain.Progress = (device as Rollershade).WcdCurrentPositionLiftPercentage;
            frameWhiteBack.AddChidren(SeekBarSiphonateCurtain);
            SeekBarSiphonateCurtain.IsProgressTextShow = false;
            SeekBarSiphonateCurtain.CurtainPaddingTop = Application.GetRealHeight(110);
 
            //卷帘控件里面的那个显示百分比的控件
            int progressY = SeekBarSiphonateCurtain.Y - Application.GetMinReal(204);
            var btnProgress = new NormalViewControl(Application.GetMinReal(135), Application.GetMinReal(104), false);
            btnProgress.Y = progressY;
            btnProgress.UnSelectedImagePath = "Item/ProgressBubbles.png";
            btnProgress.IsBold = true;
            btnProgress.TextColor = UserCenterColor.Current.White;
            btnProgress.Gravity = Gravity.CenterHorizontal;
            btnProgress.TextAlignment = TextAlignment.Center;
            frameWhiteBack.AddChidren(btnProgress);
            btnProgress.Visible = false;
 
            //开始滑动事件
            SeekBarSiphonateCurtain.OnStartTrackingTouchEvent += (sender, e) =>
            {
                //进度值开始变更
                this.isProgressing = true;
                //变更进度百分比的显示
                btnProgress.Y = progressY + SeekBarSiphonateCurtain.NowProgressY;
                btnProgress.Text = SeekBarSiphonateCurtain.Progress + "%";
                if (btnProgress.Visible == false)
                {
                    btnProgress.Visible = true;
                }
            };
 
            //结束滑动事件
            SeekBarSiphonateCurtain.OnStopTrackingTouchEvent += (sender, e) =>
            {
                //进度值开始结束
                this.isProgressing = false;
                btnProgress.Visible = false;
            };
 
            //滑动过程中
            int oldProgressValue = SeekBarSiphonateCurtain.Progress;//之前的值
            int nowProgressValue = oldProgressValue;//变更的值
            SeekBarSiphonateCurtain.OnProgressChangedEvent += (send2, value) =>
            {
                //变更进度百分比的显示
                btnProgress.Y = progressY + SeekBarSiphonateCurtain.NowProgressY;
                btnProgress.Text = value + "%";
 
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    nowProgressValue = value;
                }
                else
                {
                    //如果住宅为虚拟住宅,直接改缓存
                    (device as Rollershade).WcdCurrentPositionLiftPercentage = value;
                }
            };
 
            if (this.hadInitControl == true)
            {
                //已经完成初始化
                return;
            }
            this.hadInitControl = true;
 
            //开一个线程,监视是否滑动的滑动条,每秒检测一次
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (this.Parent != null)
                {
                    System.Threading.Thread.Sleep(1000);
                    if (nowProgressValue == oldProgressValue)
                    {
                        //值一样
                        continue;
                    }
                    oldProgressValue = nowProgressValue;
                    //发送进度值
                    (device as Rollershade).WcdGoToTiltValue(oldProgressValue);
                }
            });
        }
 
        #endregion
 
        #region ■ 初始化开合帘控件___________________
 
        /// <summary>
        /// 初始化开合帘控件
        /// </summary>
        private void InitOpenCurtainControl(FrameLayout frameWhiteBack)
        {
            //开合帘控件
            this.SeekBarOpenCurtain = new CurtainSeekBar();
            SeekBarOpenCurtain.Y = Application.GetRealHeight(334);
            SeekBarOpenCurtain.Width = this.GetPictrueRealSize(570);
            SeekBarOpenCurtain.Height = this.GetPictrueRealSize(513);
            SeekBarOpenCurtain.Gravity = Gravity.CenterHorizontal;
            SeekBarOpenCurtain.IsProgressTextShow = false;
            SeekBarOpenCurtain.Progress = (device as Rollershade).WcdCurrentPositionLiftPercentage;
            frameWhiteBack.AddChidren(SeekBarOpenCurtain);
 
            //开合帘控件里面的那个显示百分比的控件
            int progressX = SeekBarOpenCurtain.X - Application.GetMinReal(20);
            var btnProgress = new NormalViewControl(Application.GetMinReal(135), Application.GetMinReal(104), false);
            btnProgress.X = progressX;
            btnProgress.Y = SeekBarOpenCurtain.Y + SeekBarOpenCurtain.Height / 2 - Application.GetMinReal(180);
            btnProgress.UnSelectedImagePath = "Item/ProgressBubbles.png";
            btnProgress.IsBold = true;
            btnProgress.TextColor = UserCenterColor.Current.White;
            btnProgress.TextAlignment = TextAlignment.Center;
            frameWhiteBack.AddChidren(btnProgress);
            btnProgress.Visible = false;
 
            //开始滑动的事件
            SeekBarOpenCurtain.OnStartTrackingTouchEvent += (sender, e) =>
            {
                //进度值开始变更
                this.isProgressing = true;
                btnProgress.X = progressX + SeekBarOpenCurtain.NowProgressX - Application.GetMinReal(5);
                btnProgress.Text = SeekBarOpenCurtain.Progress + "%";
                if (btnProgress.Visible == false)
                {
                    btnProgress.Visible = true;
                }
            };
 
            //结束滑动的事件
            SeekBarOpenCurtain.OnStopTrackingTouchEvent += (sender, e) =>
            {
                //进度值开始结束
                this.isProgressing = false;
                btnProgress.Visible = false;
            };
 
            //滑动过程中
            int oldProgressValue = SeekBarOpenCurtain.Progress;//之前的值
            int nowProgressValue = oldProgressValue;//变更的值
            SeekBarOpenCurtain.OnProgressChangedEvent += (sender, value) =>
            {
                btnProgress.X = progressX + SeekBarOpenCurtain.NowProgressX - Application.GetMinReal(5);
                btnProgress.Text = value + "%";
 
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    nowProgressValue = value;
                }
                else
                {
                    //如果住宅为虚拟住宅,直接修改缓存
                    (device as Rollershade).WcdCurrentPositionLiftPercentage = value;
                }
            };
 
            //开一个线程,监视是否滑动的滑动条,每秒检测一次
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (this.Parent != null)
                {
                    System.Threading.Thread.Sleep(1000);
                    if (nowProgressValue == oldProgressValue)
                    {
                        //值一样
                        continue;
                    }
                    oldProgressValue = nowProgressValue;
                    //发送进度值
                    (device as Rollershade).WcdGoToTiltValue(oldProgressValue);
                }
            });
        }
 
        #endregion
 
        #region ■ 发送窗帘命令_______________________
 
        /// <summary>
        /// 发送窗帘命令
        /// </summary>
        /// <param name="comand"></param>
        private void SetCurtainCommand(int comand)
        {
            //在没有接收到反馈之前,不能再点击
            this.btnClose.CanClick = false;
            this.btnOpen.CanClick = false;
            this.btnStop.CanClick = false;
 
            //检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息
            this.StartCheckResponeResult(new List<ButtonBase>(), (result) =>
            {
                //时间结束,可以再次点击
                this.btnClose.CanClick = true;
                this.btnOpen.CanClick = true;
                this.btnStop.CanClick = true;
            });
            //发送命令
            ((Rollershade)device).CurtainUpDownStopControl(comand);
        }
 
        #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.SetStatuText(HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
                    if (this.isProgressing == false)
                    {
                        //当进度值在手动变更中时,不接收推送
                        if (this.WcdType == 0)
                        {
                            SeekBarSiphonateCurtain.Progress = (device as Rollershade).WcdCurrentPositionLiftPercentage;
                        }
                        else
                        {
                            SeekBarOpenCurtain.Progress = (device as Rollershade).WcdCurrentPositionLiftPercentage;
                        }
                    }
                });
                return true;
            }
            return false;
        }
 
        #endregion
    }
}