黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
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
using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.UserCenter;
using ZigBee.Device;
 
namespace Shared.Phone.MainPage.ControlForm
{
    /// <summary>
    /// 新风类型的深度卡片界面
    /// </summary>
    public class DeviceFreshAirDetailCardForm : DeviceDetailCardCommonForm
    {
        #region ■ 变量声明___________________________ 
        /// <summary>
        /// 界面上可以操作的控件
        /// </summary>
        private List<ButtonBase> listControl = new List<ButtonBase>();
        /// <summary>
        /// 控件
        /// </summary>
        private FreshAir freshAirDev = null;
        /// <summary>
        /// 状态控件
        /// </summary>
        private NormalViewControl btnStatu = null;
        /// <summary>
        /// 当前的文本
        /// </summary>
        private string CurrentText = string.Empty;
 
        /// <summary>
        /// 设备名称控件
        /// </summary>
        private NormalViewControl btnDeviceName = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
        public override void InitMiddleFrameAfter(FrameLayout frameWhiteBack)
        {
            //左滑不能
            this.ScrollEnabled = true;
            this.freshAirDev = (FreshAir)this.device;
            //先清空
            this.listControl = new List<ButtonBase>();
            InitFreshAirControl(frameWhiteBack);
            UpdateStatus();
        }
 
        /// <summary>
        /// 初始化新风控件
        /// </summary>
        /// <param name="frameWhiteBack"></param>
        private void InitFreshAirControl(FrameLayout frameWhiteBack)
        {
            //新风控件的容器
            var frameAcBack = new FrameLayout();
            frameAcBack.Y = Application.GetRealHeight(262);
            frameAcBack.Width = Application.GetMinRealAverage(444);
            frameAcBack.Height = Application.GetMinRealAverage(444);
            frameAcBack.Gravity = Gravity.CenterHorizontal;
            frameAcBack.BackgroundImagePath = "FreshAir/FreshAirPic.png";
            frameWhiteBack.AddChidren(frameAcBack);
 
            //新风自动Layout【为了扩大点击范围】
            var autoFrameLayout = new NormalViewControl(213 + 40, 63 + 80, true);
            autoFrameLayout.X = Application.GetRealWidth(275 - 20);
            autoFrameLayout.Y = Application.GetRealHeight(821 - 20);
            frameWhiteBack.AddChidren(autoFrameLayout);
            autoFrameLayout.ButtonClickEvent += HandlerAuto;
 
            // 自动(第1个,listControl【0】)
            var btnAuto = new NormalViewControl(213, 63, true);
            btnAuto.X = Application.GetRealWidth(275);
            btnAuto.Y = Application.GetRealHeight(821);
            btnAuto.TextID = R.MyInternationalizationString.Mode_Auto;
            btnAuto.TextColor = ZigbeeColor.Current.XMGray3;
            btnAuto.IsBold = false;
            btnAuto.TextAlignment = TextAlignment.Center;
            frameWhiteBack.AddChidren(btnAuto);
 
            this.listControl.Add(btnAuto);
            btnAuto.ButtonClickEvent += HandlerAuto;
 
            //自动下划线(第2个,listControl【1】)
            var btnAutoLine = new NormalViewControl(72, 12, true);
            btnAutoLine.X = Application.GetRealWidth(346);
            btnAutoLine.Y = Application.GetRealHeight(896);
            btnAutoLine.BackgroundColor = ZigbeeColor.Current.XMOrange;
            btnAutoLine.Visible = false;
            frameWhiteBack.AddChidren(btnAutoLine);
            this.listControl.Add(btnAutoLine);
            btnAutoLine.ButtonClickEvent += HandlerAuto;
 
            //新风手动Layout【为了扩大点击范围】
            var manualFrameLayout = new NormalViewControl(213 + 40, 63 + 80, true);
            manualFrameLayout.X = Application.GetRealWidth(488 - 20);
            manualFrameLayout.Y = Application.GetRealHeight(821 - 20);
            frameWhiteBack.AddChidren(manualFrameLayout);
            manualFrameLayout.ButtonClickEvent += HandlerManual;
 
            //手动(第3个,listControl【2】)
            var btnManual = new NormalViewControl(213, 63, true);
            btnManual.X = Application.GetRealWidth(488);
            btnManual.Y = btnAuto.Y;
            btnManual.TextID = R.MyInternationalizationString.Manual;
            btnManual.TextColor = ZigbeeColor.Current.XMGray3;
            btnManual.IsBold = false;
            btnManual.TextAlignment = TextAlignment.Center;
            frameWhiteBack.AddChidren(btnManual);
            this.listControl.Add(btnManual);
            btnManual.ButtonClickEvent += HandlerManual;
 
            //手动下划线(第4个,listControl【3】)
            var btnManualLine = new NormalViewControl(72, 12, true);
            btnManualLine.X = Application.GetRealWidth(560);
            btnManualLine.BackgroundColor = ZigbeeColor.Current.XMOrange;
            btnManualLine.Y = btnAutoLine.Y;
            btnManualLine.Visible = false;
            frameWhiteBack.AddChidren(btnManualLine);
            this.listControl.Add(btnManualLine);
            btnManualLine.ButtonClickEvent += HandlerManual;
 
            //高风(第5个,listControl【4】)
            var btnHighSpeed = new IconViewControl(81);
            btnHighSpeed.X = Application.GetRealWidth(207);
            btnHighSpeed.Y = Application.GetRealHeight(999);
            btnHighSpeed.UnSelectedImagePath = "AC/Fan_Height.png";
            btnHighSpeed.SelectedImagePath = "AC/Fan_HeightSelected.png";
            frameWhiteBack.AddChidren(btnHighSpeed);
            this.listControl.Add(btnHighSpeed);
            btnHighSpeed.ButtonClickEvent += (sender, e) =>
            {
                if (freshAirDev.currentFanStatus == 0)
                {
                    return;
                }
                if (freshAirDev.currentFanMode == 5)
                {
                    var msgContr = new ShowMsgControl(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.AutoModeForbiddenOperate));
                    msgContr.Show();
                    return;
                }
 
                if (!btnHighSpeed.IsSelected)
                {
                    this.listControl[4].Enable = false;
                    this.SetFanComand(3);
                }
            };
 
            //开关(第6个,listControl【5】)
            var btnSwitch = new IconViewControl(81);
            btnSwitch.X = Application.GetRealWidth(444);
            btnSwitch.Y = btnHighSpeed.Y;
            btnSwitch.UnSelectedImagePath = "AC/OpenOrClose.png";
            btnSwitch.SelectedImagePath = "AC/OpenOrCloseSelected.png";
            frameWhiteBack.AddChidren(btnSwitch);
            this.listControl.Add(btnSwitch);
            btnSwitch.ButtonClickEvent += (sender, e) =>
            {
                btnSwitch.IsSelected = !btnSwitch.IsSelected;
                if (btnSwitch.IsSelected)
                {
                    this.listControl[5].Enable = false;
                    this.SetFanComand(4);
                }
                else
                {
                    this.listControl[5].Enable = false;
                    this.SetFanComand(0);
                }
            };
 
            //低风(第7个,listControl【6】)
            var btnLowSpeed = new IconViewControl(81);
            btnLowSpeed.X = Application.GetRealWidth(677);
            btnLowSpeed.Y = btnHighSpeed.Y;
            btnLowSpeed.UnSelectedImagePath = "AC/Fan_Low.png";
            btnLowSpeed.SelectedImagePath = "AC/Fan_LowSelected.png";
            frameWhiteBack.AddChidren(btnLowSpeed);
            this.listControl.Add(btnLowSpeed);
            btnLowSpeed.ButtonClickEvent += (sender, e) =>
            {
                if (freshAirDev.currentFanStatus == 0)
                {
                    return;
                }
                if (freshAirDev.currentFanMode == 5)
                {
                    var msgContr = new ShowMsgControl(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.AutoModeForbiddenOperate));
                    msgContr.Show();
                    return;
                }
                if (!btnLowSpeed.IsSelected)
                {
                    this.listControl[6].Enable = false;
                    this.SetFanComand(1);
                }
            };
        }
 
        /// <summary>
        /// 自动事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HandlerAuto(object sender, MouseEventArgs e)
        {
            if (freshAirDev.currentFanStatus == 0)
            {
                return;
            }
            if (freshAirDev.currentFanMode == 5)
            {
                return;
            }
            if (!listControl[0].IsSelected)
            {
                this.listControl[0].Enable = false;
                this.SetFanComand(5);
            }
        }
 
        /// <summary>
        /// 手动事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HandlerManual(object sender, MouseEventArgs e)
        {
            if (freshAirDev.currentFanStatus == 0)
            {
                return;
            }
            if (freshAirDev.currentFanMode == 15)
            {
                return;
            }
            if (!this.listControl[2].IsSelected)
            {
                this.listControl[2].Enable = false;
                this.SetFanComand(15);
            }
        }
        #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设备属性上报)
            {
                if (report.DeviceStatusReport.CluterID == 514)
                {
                    var attriButeList = report.DeviceStatusReport.AttriBute;
                    foreach (var attList in attriButeList)
                    {
                        if (attList.AttributeId == 0)
                        {
                            //风速
                            HdlThreadLogic.Current.RunMain(() =>
                            {
                                UpdateStatus();
                            });
 
                            //已经接收到网关的反馈
                            return true;
                        }
                    }
                }
            }
            this.listControl[0].Enable = true;
            this.listControl[2].Enable = true;
            this.listControl[4].Enable = true;
            this.listControl[5].Enable = true;
            this.listControl[6].Enable = true;
            return false;
        }
        #endregion
 
        #region ■ 设置方法 
        /// <summary>
        ///命令
        ///0:Off
        ///1:Low
        ///3:High
        ///4:On
        ///5:Auto
        /// 15:Manual
        /// </summary> 
        private void SetFanComand(int command)
        {
            //检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息
            this.StartCheckResponeResult(this.listControl, (result) =>
            {
                //接收到网关回复
                if (result == true)
                {
                }
            });
 
            switch (command)
            {
                case 0:
                    freshAirDev.Close();
                    break;
                case 1:
                    freshAirDev.SetLowSpeed();
                    break;
                case 3:
                    freshAirDev.SetHighSpeed();
                    break;
                case 4:
                    freshAirDev.Open();
                    break;
                case 5:
                    freshAirDev.SetAuto();
                    break;
                case 15:
                    freshAirDev.SetManual();
                    break;
            }
        }
        #endregion
 
        #region ■ 刷新状态_____________
        /// <summary>
        /// 刷新状态
        /// </summary>
        private void UpdateStatus()
        {
            //设置状态文字
            if (freshAirDev.currentFanStatus == 4)
            {
                this.listControl[5].Enable = true;
                //打开
                this.listControl[5].IsSelected = true;
                //设置状态文字 
                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uOpen1));
            }
            if (freshAirDev.currentFanStatus == 0)
            {
                //关闭
                this.listControl[0].TextColor = ZigbeeColor.Current.XMGray3;
                this.listControl[0].IsBold = false;
                this.listControl[1].Visible = false;
                this.listControl[2].TextColor = ZigbeeColor.Current.XMGray3;
                this.listControl[2].IsBold = false;
                this.listControl[3].Visible = false;
                this.listControl[4].IsSelected = false;
                this.listControl[5].IsSelected = false;
                this.listControl[6].IsSelected = false;
                this.listControl[5].Enable = true;
                //设置状态文字 
                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close));
                return;
            }
 
            //设置模式
            if (freshAirDev.currentFanMode == 5)
            {
                this.listControl[0].TextColor = ZigbeeColor.Current.XMGray1;
                this.listControl[0].IsBold = true;
                this.listControl[1].Visible = true;
                this.listControl[2].TextColor = ZigbeeColor.Current.XMGray3;
                this.listControl[2].IsBold = false;
                this.listControl[3].Visible = false;
                this.listControl[0].Enable = true;
            }
            else if (freshAirDev.currentFanMode == 15)
            {
                this.listControl[0].TextColor = ZigbeeColor.Current.XMGray3;
                this.listControl[0].IsBold = false;
                this.listControl[1].Visible = false;
                this.listControl[2].TextColor = ZigbeeColor.Current.XMGray1;
                this.listControl[2].IsBold = true;
                this.listControl[3].Visible = true;
                this.listControl[2].Enable = true;
            }
 
            //设置风速
            if (freshAirDev.currentFanSpeed == 1)
            {
                this.listControl[4].IsSelected = false;
                this.listControl[6].IsSelected = true;
                this.listControl[6].Enable = true;
            }
            else if (freshAirDev.currentFanSpeed == 3)
            {
                this.listControl[4].IsSelected = true;
                this.listControl[6].IsSelected = false;
                this.listControl[4].Enable = true;
            }
        }
        #endregion
    }
}