黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DeviceRelay
{
    /// <summary>
    /// 国标3路10A继电器小模块,欧标2路5A继电器小模块 的背光灯设置
    /// </summary>
    public class RelayNationalBackLightSettionForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 亮度调节的信息
        /// </summary>
        private Panel.PanelSwitchLevelInfo linghtLevelInfo = null;
        /// <summary>
        /// 节能模式
        /// </summary>
        private Panel.PanelSaveEnergyModeInfo energyModeInfo = null;
        /// <summary>
        /// 设备列表
        /// </summary>
        private List<CommonDevice> listDevice = null;
        /// <summary>
        /// 数据是否变更
        /// </summary>
        private bool valueChanged = false;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm(string i_deviceMac)
        {
            this.ScrollEnabled = false;
 
            this.listDevice = HdlDeviceCommonLogic.Current.GetDevicesByMac(i_deviceMac);
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uBackLight));
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //获取设备初始数据
            var result = this.GetDeviceDefultData();
            if (result == false)
            {
                return;
            }
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //点击状态
            var btnClickStatu = new NormalViewControl(600, 49, true);
            btnClickStatu.X = HdlControlResourse.XXLeft;
            btnClickStatu.Y = Application.GetRealHeight(207);
            btnClickStatu.TextSize = 12;
            btnClickStatu.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnClickStatu.TextID = R.MyInternationalizationString.uClickStatu;
            bodyFrameLayout.AddChidren(btnClickStatu);
 
            //各种背光灯的容器
            var frameLinght = new FrameLayout();
            frameLinght.Height = Application.GetRealHeight(748);
            frameLinght.Y = Application.GetRealHeight(279);
            frameLinght.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameLinght);
 
            //添加1-6干接点的背光灯进度条
            this.AddSixDryContactProgress(frameLinght);
            //第七干接点的背光灯进度条
            this.AddSevenDryContactProgress(frameLinght);
            //添加节能模式
            this.AddEnergyConservationRow(btnClickStatu, frameLinght);
 
            //保存
            var btnSave = new BottomClickButton();
            btnSave.TextID = R.MyInternationalizationString.uSave;
            bodyFrameLayout.AddChidren(btnSave);
            btnSave.ButtonClickEvent += (sender, e) =>
            {
                if (valueChanged == true)
                {
                    this.ShowProgressBar();
                    //亮度调节更改(他们说随便一个回路就行)
                    result = HdlDevicePanelLogic.Current.SetDeviceLightSettion(listDevice[0], linghtLevelInfo.panelDirectionsLevel, linghtLevelInfo.panelBacklightLevel);
                    if (result == false)
                    {
                        this.CloseProgressBar();
                        return;
                    }
                    //节能模式修改(他们说随便一个回路就行)
                    result = HdlDevicePanelLogic.Current.SetDeviceEnergyConservationMode(listDevice[0], energyModeInfo.enable, energyModeInfo.time, energyModeInfo.level);
                    this.CloseProgressBar();
                    if (result == false)
                    {
                        return;
                    }
                }
                //关闭自身
                this.CloseForm();
            };
        }
 
        #endregion
 
        #region ■ 节能模式行_________________________
 
        /// <summary>
        ///  添加节能模式行
        /// </summary>
        /// <param name="btnClickStatu">点击状态控件(控件伸缩使用)</param>
        /// <param name="frameLinght">各种背光灯的容器(控件伸缩使用)</param>
        private void AddEnergyConservationRow(NormalViewControl btnClickStatu, FrameLayout frameLinght)
        {
            //缩小:170  扩大:429+RowHeight+23
            var frameBack = new FrameRowControl();
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            frameBack.UseClickStatu = false;
            frameBack.Height = Application.GetRealHeight(170);
            bodyFrameLayout.AddChidren(frameBack);
 
            //当前亮度(先声明,为了对应IOS的折叠后,没有完全遮挡的问题)
            var btnProgressView1 = new NormalViewControl(200, 49, true);
            var btnProgress1 = new NormalViewControl(200, 49, true);
 
            //节能模式
            frameBack.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uEnergyConservationMode), 400);
            //开关控件
            var btnSwitch = frameBack.AddMostRightSwitchIcon();
            btnSwitch.ButtonClickEvent += (sender, e) =>
            {
                btnSwitch.IsSelected = !btnSwitch.IsSelected;
                energyModeInfo.enable = btnSwitch.IsSelected;
                //展开或者缩小的高度
                var value = Application.GetRealHeight(259 + 23) + HdlControlResourse.ListViewRowHeight;
                if (btnSwitch.IsSelected == true)
                {
                    frameBack.Height += value;
                    btnClickStatu.Y += value;
                    frameLinght.Y += value;
                    btnProgressView1.Visible = true;
                    btnProgress1.Visible = true;
                }
                else
                {
                    frameBack.Height -= value;
                    btnClickStatu.Y -= value;
                    frameLinght.Y -= value;
                    btnProgressView1.Visible = false;
                    btnProgress1.Visible = false;
                }
                //数据变更
                valueChanged = true;
            };
            if (energyModeInfo.enable == true)
            {
                btnSwitch.IsSelected = true;
            }
 
            //当前亮度
            btnProgressView1.X = HdlControlResourse.XXLeft;
            btnProgressView1.Y = Application.GetRealHeight(161);
            btnProgressView1.TextSize = 12;
            btnProgressView1.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnProgressView1.TextID = R.MyInternationalizationString.uNowLuminance;
            frameBack.AddChidren(btnProgressView1);
            btnProgressView1.Visible = false;
            btnProgress1.X = Application.GetRealWidth(222);
            btnProgress1.Y = Application.GetRealHeight(158);
            btnProgress1.TextSize = 12;
            btnProgress1.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnProgress1.Text = energyModeInfo.level + "%";
            frameBack.AddChidren(btnProgress1);
            btnProgress1.Visible = false;
 
            //进度条
            var seekBar1 = new SeekBarControl();
            seekBar1.Y = Application.GetRealHeight(253);
            seekBar1.ProgressBarColor = 0xff3e99f4;
            frameBack.AddChidren(seekBar1);
            seekBar1.ProgressChangedEvent += (div, value) =>
            {
                btnProgress1.Text = value + "%";
                //数据变更
                energyModeInfo.level = value;
                valueChanged = true;
            };
            seekBar1.Progress = energyModeInfo.level;
 
            var btnTemp1 = new NormalViewControl(200, 49, true);
            btnTemp1.X = HdlControlResourse.XXLeft;
            btnTemp1.Y = Application.GetRealHeight(325);
            btnTemp1.TextSize = 12;
            btnTemp1.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnTemp1.Text = "0%";
            frameBack.AddChidren(btnTemp1);
 
            var btnTemp2 = new NormalViewControl(200, 49, true);
            btnTemp2.X = frameLinght.Width - Application.GetRealWidth(200 + 49);
            btnTemp2.Y = Application.GetRealHeight(325);
            btnTemp2.TextAlignment = TextAlignment.CenterRight;
            btnTemp2.TextSize = 12;
            btnTemp2.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnTemp2.Text = "100%";
            frameBack.AddChidren(btnTemp2);
 
            if (energyModeInfo.enable == true)
            {
                //展开或者缩小的高度
                var value = Application.GetRealHeight(259 + 23) + HdlControlResourse.ListViewRowHeight;
                frameBack.Height += value;
                btnClickStatu.Y += value;
                frameLinght.Y += value;
 
                btnProgressView1.Visible = true;
                btnProgress1.Visible = true;
            }
            //如果当前是展示模板
            if (Common.Config.Instance.Home.IsShowTemplate == true)
            {
                seekBar1.Enable = false;
                btnSwitch.CanClick = false;
            }
 
            //添加睡眠时间行
            this.AddSleepTimeRow(frameBack, btnTemp1.Bottom);
        }
 
        #endregion
 
        #region ■ 睡眠时间___________________________
 
        /// <summary>
        /// 添加睡眠时间行
        /// </summary>
        /// <param name="frameBack">白色区域容器控件</param>
        /// <param name="i_bottom">参照物控件的底部坐标</param>
        private void AddSleepTimeRow(FrameRowControl frameBack, int i_bottom)
        {
            var row = new FrameRowControl();
            row.Y = i_bottom + Application.GetRealHeight(23);
            frameBack.AddChidren(row, ChidrenBindMode.NotBind);
            //睡眠时间
            row.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.SleepTime), 500);
            //右箭头
            row.AddRightArrow();
            //状态
            var btnStatu = row.AddMostRightView(string.Empty, 400);
            //底线
            row.AddBottomLine();
 
            int selectIndex = -1;
            if (this.energyModeInfo.time == 15)
            {
                selectIndex = 0;
                btnStatu.Text = "15" + Language.StringByID(R.MyInternationalizationString.uSecond) + Language.StringByID(R.MyInternationalizationString.Later);
            }
            else if (this.energyModeInfo.time == 60)
            {
                selectIndex = 1;
                btnStatu.Text = "1min" + Language.StringByID(R.MyInternationalizationString.Later);
            }
            else if (this.energyModeInfo.time == 300)
            {
                selectIndex = 2;
                btnStatu.Text = "5min" + Language.StringByID(R.MyInternationalizationString.Later);
            }
 
            //如果当前不是展示模板
            if (Common.Config.Instance.Home.IsShowTemplate == false)
            {
                row.ButtonClickEvent += (sender, e) =>
                {
                    //显示睡眠时间列表
                    var listText = new List<string>();
                    //15秒后
                    listText.Add("15s" + Language.StringByID(R.MyInternationalizationString.Later));
                    //1min后
                    listText.Add("1min" + Language.StringByID(R.MyInternationalizationString.Later));
                    //5min后
                    listText.Add("5min" + Language.StringByID(R.MyInternationalizationString.Later));
 
                    var form = new BottomItemSelectForm();
                    form.AddForm(Language.StringByID(R.MyInternationalizationString.uAutomaticTimingOff), listText, null, selectIndex);
                    form.FinishSelectEvent += (index) =>
                    {
                        selectIndex = index;
                        btnStatu.Text = listText[index];
 
                        if (selectIndex == 0)
                        {
                            //修改缓存
                            energyModeInfo.time = 15;
                        }
                        else
                        {
                            //修改缓存
                            energyModeInfo.time = selectIndex == 1 ? 60 : 300;
                        }
                    };
                };
            }
        }
 
        #endregion
 
        #region ■ 1-6干接点的背光灯__________________
 
        /// <summary>
        ///  添加1-6干接点的背光灯进度条(这个对应的是【指示灯亮度】)
        /// </summary>
        /// <param name="frameLinght">各种背光灯的容器</param>
        private void AddSixDryContactProgress(FrameLayout frameLinght)
        {
            var btnProgressView1 = new NormalViewControl(200, 49, true);
            btnProgressView1.X = HdlControlResourse.XXLeft;
            btnProgressView1.Y = Application.GetRealHeight(29);
            btnProgressView1.TextSize = 12;
            btnProgressView1.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnProgressView1.Text = "Dry1-6";
            frameLinght.AddChidren(btnProgressView1);
            var btnProgress1 = new NormalViewControl(200, 49, true);
            btnProgress1.X = Application.GetRealWidth(204);
            btnProgress1.Y = Application.GetRealHeight(29);
            btnProgress1.TextSize = 12;
            btnProgress1.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnProgress1.Text = linghtLevelInfo.panelDirectionsLevel + "%";
            frameLinght.AddChidren(btnProgress1);
 
            //进度条
            var seekBar1 = new SeekBarControl();
            seekBar1.Y = Application.GetRealHeight(124);
            seekBar1.ProgressBarColor = 0xfffdb500;
            frameLinght.AddChidren(seekBar1);
            seekBar1.ProgressChangedEvent += (div, value) =>
            {
                btnProgress1.Text = value + "%";
                //数据变更
                linghtLevelInfo.panelDirectionsLevel = value;
                valueChanged = true;
            };
            seekBar1.Progress = linghtLevelInfo.panelDirectionsLevel;
 
            var btnTemp1 = new NormalViewControl(200, 49, true);
            btnTemp1.X = HdlControlResourse.XXLeft;
            btnTemp1.Y = Application.GetRealHeight(193);
            btnTemp1.TextSize = 12;
            btnTemp1.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnTemp1.Text = "0%";
            frameLinght.AddChidren(btnTemp1);
 
            var btnTemp2 = new NormalViewControl(200, 49, true);
            btnTemp2.X = frameLinght.Width - Application.GetRealWidth(200 + 49);
            btnTemp2.Y = Application.GetRealHeight(193);
            btnTemp2.TextAlignment = TextAlignment.CenterRight;
            btnTemp2.TextSize = 12;
            btnTemp2.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnTemp2.Text = "100%";
            frameLinght.AddChidren(btnTemp2);
 
            //线
            var btnLine = new NormalViewControl(Application.GetRealWidth(965), HdlControlResourse.BottomLineHeight, false);
            btnLine.Y = Application.GetRealHeight(311);
            btnLine.Gravity = Gravity.CenterHorizontal;
            btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
            frameLinght.AddChidren(btnLine);
 
            //如果当前是展示模板
            if (Common.Config.Instance.Home.IsShowTemplate == true)
            {
                seekBar1.Enable = false;
            }
        }
 
        #endregion
 
        #region ■ 第七干接点的背光灯_________________
 
        /// <summary>
        ///  添加第七干接点的背光灯进度条(这个对应的是【背光灯亮度】)
        /// </summary>
        /// <param name="frameLinght">各种背光灯的容器</param>
        private void AddSevenDryContactProgress(FrameLayout frameLinght)
        {
            var btnProgressView1 = new NormalViewControl(200, 49, true);
            btnProgressView1.X = HdlControlResourse.XXLeft;
            btnProgressView1.Y = Application.GetRealHeight(369);
            btnProgressView1.TextSize = 12;
            btnProgressView1.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnProgressView1.Text = "Dry7";
            frameLinght.AddChidren(btnProgressView1);
            var btnProgress1 = new NormalViewControl(200, 49, true);
            btnProgress1.X = Application.GetRealWidth(161);
            btnProgress1.Y = Application.GetRealHeight(369);
            btnProgress1.TextSize = 12;
            btnProgress1.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnProgress1.Text = linghtLevelInfo.panelBacklightLevel + "%";
            frameLinght.AddChidren(btnProgress1);
 
            //进度条
            var seekBar1 = new SeekBarControl();
            seekBar1.Y = Application.GetRealHeight(464);
            seekBar1.ProgressBarColor = 0xfffdb500;
            frameLinght.AddChidren(seekBar1);
            seekBar1.ProgressChangedEvent += (div, value) =>
            {
                btnProgress1.Text = value + "%";
                //数据变更
                linghtLevelInfo.panelBacklightLevel = value;
                valueChanged = true;
            };
            seekBar1.Progress = linghtLevelInfo.panelBacklightLevel;
 
            var btnTemp1 = new NormalViewControl(200, 49, true);
            btnTemp1.X = HdlControlResourse.XXLeft;
            btnTemp1.Y = Application.GetRealHeight(533);
            btnTemp1.TextSize = 12;
            btnTemp1.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnTemp1.Text = "0%";
            frameLinght.AddChidren(btnTemp1);
 
            var btnTemp2 = new NormalViewControl(200, 49, true);
            btnTemp2.X = frameLinght.Width - Application.GetRealWidth(200 + 49);
            btnTemp2.Y = Application.GetRealHeight(533);
            btnTemp2.TextAlignment = TextAlignment.CenterRight;
            btnTemp2.TextSize = 12;
            btnTemp2.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnTemp2.Text = "100%";
            frameLinght.AddChidren(btnTemp2);
 
            //线
            var btnLine = new NormalViewControl(Application.GetRealWidth(965), HdlControlResourse.BottomLineHeight, false);
            btnLine.Gravity = Gravity.CenterHorizontal;
            btnLine.Y = Application.GetRealHeight(651);
            btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
            frameLinght.AddChidren(btnLine);
 
            //如果当前是展示模板
            if (Common.Config.Instance.Home.IsShowTemplate == true)
            {
                seekBar1.Enable = false;
            }
        }
 
        #endregion
 
        #region ■ 获取初始数据_______________________
 
        /// <summary>
        /// 获取设备初始数据
        /// </summary>
        /// <returns></returns>
        private bool GetDeviceDefultData()
        {
            //开启进度条
            this.ShowProgressBar();
            //亮度调节(他们说随便拿一路回路就行了)
            linghtLevelInfo = HdlDevicePanelLogic.Current.GetDeviceLightSettion(listDevice[0]);
            if (linghtLevelInfo == null)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return false;
            }
            //节能模式(他们说随便拿一路回路就行了)
            energyModeInfo = HdlDevicePanelLogic.Current.GetDeviceEnergyConservationMode(listDevice[0]);
            if (energyModeInfo == null)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return false;
            }
            //关闭进度条
            this.CloseProgressBar();
 
            return true;
        }
 
        #endregion
    }
}