xm
2019-07-16 b910cb79c9b5bcc204022a3cf9e6950f0a64dfbd
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DevicePanel
{
    /// <summary>
    /// 控制面板的背光设置界面★
    /// </summary>
    public class PanelBackLightSettionForm : UserCenterCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 面板设备全部的回路
        /// </summary>
        private List<CommonDevice> listPenlDevice = null;
        /// <summary>
        /// 亮度调节的信息
        /// </summary>
        private Panel.PanelSwitchLevelInfo linghtLevelInfo = null;
        /// <summary>
        /// 节能模式
        /// </summary>
        private Panel.PanelSaveEnergyModeInfo energyModeInfo = null;
        /// <summary>
        /// 面板新属性
        /// </summary>
        private NewPanelInfo newPanelInfo = new NewPanelInfo();
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_listdevice">面板设备的全部回路</param>
        public void ShowForm(List<CommonDevice> i_listdevice)
        {
            UserView.HomePage.Instance.ScrollEnabled = false;
 
            this.listPenlDevice = i_listdevice;
 
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uBackLightSettion));
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            this.bodyFrameLayout.RemoveAll();
 
            //获取设备功能信息,然后添加行
            this.GetDeviceFunctionAndSetRow();
        }
 
        /// <summary>
        /// 获取设备功能信息,然后添加行
        /// </summary>
        private async void GetDeviceFunctionAndSetRow()
        {
            //开启进度条
            this.ShowProgressBar();
 
            Panel panel = null;
            //按键回路不可能为null,为null不会显示进入这个界面的菜单
            foreach (var device in listPenlDevice)
            {
                if (device.Type == DeviceType.OnOffSwitch)
                {
                    panel = (Panel)device;
                    break;
                }
            }
            //检测控制面板(灯类)所拥有的功能
            Dictionary<string, bool> dicCheck = await Common.LocalDevice.Current.CheckPanelLightFunctionLevel2(panel);
            if (dicCheck == null)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return;
            }
            if (dicCheck["亮度调节"] == true)
            {
                //获取亮度调节设置信息
                this.linghtLevelInfo = await Common.LocalDevice.Current.GetPanelSwitchLightSettion(panel);
                if (linghtLevelInfo == null)
                {
                    //关闭进度条
                    this.CloseProgressBar(ShowReLoadMode.YES);
                    return;
                }
                Application.RunOnMainThread(() =>
                {
                    newPanelInfo.BacklightLevel = linghtLevelInfo.panelBacklightLevel;
                    //添加【亮度调节】行
                    this.AddLightRegulationRow();
                });
            }
            if (dicCheck["节能模式"] == true)
            {
                //获取节能模式设置信息
                this.energyModeInfo = await Common.LocalDevice.Current.GetPanelEnergyConservationMode(panel);
                if (energyModeInfo == null)
                {
                    //关闭进度条
                    this.CloseProgressBar(ShowReLoadMode.YES);
                    return;
                }
                Application.RunOnMainThread(() =>
                {
                    newPanelInfo.EnergyLevel = energyModeInfo.level;
                    newPanelInfo.EnergyModeEnable = energyModeInfo.enable;
                    //添加【节能模式】行
                    this.AddEnergyConservationRow();
                });
            }
            //关闭进度条
            this.CloseProgressBar();
 
            new System.Threading.Thread(() =>
            {
                //保存设定值
                this.StartSavePanelDataThread(panel);
            })
            { IsBackground = true }.Start();
        }
 
        #endregion
 
        #region ■ 亮度调节行_________________________
 
        /// <summary>
        /// 添加【亮度调节】行
        /// </summary>
        private void AddLightRegulationRow()
        {
            int YY = 0;
            var view = bodyFrameLayout.GetChildren(bodyFrameLayout.ChildrenCount - 1);
            if (view != null)
            {
                YY = view.Bottom;
            }
 
            var row = new RowLayout();
            row.Y = YY;
            row.Height = ControlCommonResourse.ListViewRowHeight + ControlCommonResourse.NormalControlHeight;
            bodyFrameLayout.AddChidren(row);
 
            //亮度调节
            var btnText = new ViewNormalControl(600, true);
            btnText.X = ControlCommonResourse.XXLeft;
            btnText.Y = Application.GetRealHeight(20);
            btnText.TextID = R.MyInternationalizationString.uLightRegulation;
            row.AddChidren(btnText);
 
            //进度控件
            var btnProgress = new SeekBarFrameLayout(SeekBarTypeMode.OnlyPersent);
            btnProgress.Y = btnText.Bottom - Application.GetRealHeight(20);
            row.AddChidren(btnProgress);
            btnProgress.InitControl();
            btnProgress.SetProgressDefultValue(linghtLevelInfo.panelBacklightLevel);
 
            btnProgress.ProgressValueEvent += ((value) =>
            {
                //变更缓存
                newPanelInfo.BacklightLevel = value;
            });
        }
 
        #endregion
 
        #region ■ 色温调节行_________________________
 
        /// <summary>
        /// 添加【色温调节】行
        /// </summary>
        private void AddColorTemperatureRow()
        {
            int YY = 0;
            var view = bodyFrameLayout.GetChildren(bodyFrameLayout.ChildrenCount - 1);
            if (view != null)
            {
                YY = view.Bottom;
            }
 
            var row = new RowLayout();
            row.Y = YY;
            row.Height = ControlCommonResourse.ListViewRowHeight + ControlCommonResourse.NormalControlHeight;
            bodyFrameLayout.AddChidren(row);
 
            //色温调节
            var btnText = new ViewNormalControl(600, true);
            btnText.X = ControlCommonResourse.XXLeft;
            btnText.Y = Application.GetRealHeight(20);
            btnText.TextID = R.MyInternationalizationString.uColorTemperatureRegulation;
            row.AddChidren(btnText);
 
            //进度控件
            var btnProgress = new SeekBarFrameLayout(SeekBarTypeMode.LeftAndRight);
            //较冷
            btnProgress.SetLeftText(Language.StringByID(R.MyInternationalizationString.uMoreCold));
            //较暖
            btnProgress.SetRightText(Language.StringByID(R.MyInternationalizationString.uMoreWarm));
            btnProgress.Y = btnText.Bottom - Application.GetRealHeight(20);
            row.AddChidren(btnProgress);
            btnProgress.InitControl();
        }
 
        #endregion
 
        #region ■ 节能模式行_________________________
 
        /// <summary>
        /// 添加【节能模式】行
        /// </summary>
        private void AddEnergyConservationRow()
        {
            int YY = 0;
            var view = bodyFrameLayout.GetChildren(bodyFrameLayout.ChildrenCount - 1);
            if (view != null)
            {
                YY = view.Bottom;
            }
 
            var row = new RowLayout();
            row.Y = YY;
            row.Height = ControlCommonResourse.ListViewRowHeight;
            bodyFrameLayout.AddChidren(row);
 
            //节能模式
            var btnText = new RowCenterView(false);
            btnText.TextID = R.MyInternationalizationString.uEnergyConservationMode;
            row.AddChidren(btnText);
 
            //开关控件 
            var btnSwith = new SwichControl();
            btnSwith.IsSelected = energyModeInfo.enable;
            row.AddChidren(btnSwith);
            btnSwith.MouseUpEventHandler += ((sender, e) =>
            {
                //缓存值变更
                newPanelInfo.EnergyModeEnable = !newPanelInfo.EnergyModeEnable;
                //特效变更
                btnSwith.IsSelected = newPanelInfo.EnergyModeEnable;
 
                if (newPanelInfo.EnergyModeEnable == true)
                {
                    row.Height = ControlCommonResourse.ListViewRowHeight * 2;
                }
                else
                {
                    row.Height = ControlCommonResourse.ListViewRowHeight;
                }
            });
 
            //因为如果不在内部控件初始化完成后实行这个的话,自定义控件的位置会变化
            if (energyModeInfo.enable == true)
            {
                row.Height = ControlCommonResourse.ListViewRowHeight * 2;
            }
 
            //进度控件
            var btnProgress = new SeekBarFrameLayout(SeekBarTypeMode.LeftAndRight);
            //较暗
            btnProgress.SetLeftText(Language.StringByID(R.MyInternationalizationString.uMoreDark));
            //较亮
            btnProgress.SetRightText(Language.StringByID(R.MyInternationalizationString.uMoreLight));
            btnProgress.Y = btnText.Bottom;
            row.AddChidren(btnProgress);
            btnProgress.InitControl();
            btnProgress.SetProgressDefultValue(energyModeInfo.level);
 
            btnProgress.ProgressValueEvent += ((value) =>
            {
                //缓存值变更
                newPanelInfo.EnergyLevel = value;
            });
        }
 
        #endregion
 
        #region ■ 保存设定值_________________________
 
        /// <summary>
        /// 保存设定值
        /// </summary>
        /// <param name="panel">按键面板的某一个回路</param>
        private async void StartSavePanelDataThread(Panel panel)
        {
            while (this.Parent != null)
            {
                await System.Threading.Tasks.Task.Delay(1000);
                //【亮度调节】值改变
                if (linghtLevelInfo != null && linghtLevelInfo.panelBacklightLevel != newPanelInfo.BacklightLevel)
                {
                    //不管成不成功都变更缓存
                    linghtLevelInfo.panelBacklightLevel = newPanelInfo.BacklightLevel;
                    //执行保存
                    var result = await Common.LocalDevice.Current.SetPanelSwitchLightSettion(panel, linghtLevelInfo.panelDirectionsLevel, newPanelInfo.BacklightLevel);
                    if (result == false)
                    {
                        continue;
                    }
                }
                //【节能模式】值改变
                if (energyModeInfo != null && (energyModeInfo.enable != newPanelInfo.EnergyModeEnable || energyModeInfo.level != newPanelInfo.EnergyLevel))
                {
                    //不管成不成功都变更缓存
                    energyModeInfo.level = newPanelInfo.EnergyLevel;
                    energyModeInfo.enable = newPanelInfo.EnergyModeEnable;
                    //执行保存
                    var result = await Common.LocalDevice.Current.SetPanelEnergyConservationMode(panel, newPanelInfo.EnergyModeEnable, energyModeInfo.time, newPanelInfo.EnergyLevel);
                    if (result == false)
                    {
                        continue;
                    }
                }
            }
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        /// <param name="isCloseForm"></param>
        public override void CloseForm(bool isCloseForm = true)
        {
            UserView.HomePage.Instance.ScrollEnabled = true;
 
            base.CloseForm(isCloseForm);
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 面板新属性
        /// </summary>
        private class NewPanelInfo
        {
            /// <summary>
            /// 背光灯亮度 0-100(ui叫亮度调节)
            /// </summary>
            public int BacklightLevel = 0;
            /// <summary>
            /// 节能模式是否有效
            /// </summary>
            public bool EnergyModeEnable = false;
            /// <summary>
            /// 节能模式亮度:0-100
            /// </summary>
            public int EnergyLevel = 0;
        }
 
        #endregion
    }
}