黄学彪
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
using System;
using System.Collections.Generic;
using Shared;
using Shared.Common;
using Shared.R;
using ZigBee.Device;
 
namespace Shared.Phone.Device.Logic
{
    public class Nightlight : FrameLayout
    {
        public Nightlight()
        {
            Tag = "Logic";
        }
        string selectedDeviceStatus = "";
        Dictionary<string, object> actionsInfo = null;
        List<Dictionary<string, string>> TaskList = null;
        public void Show(CommonDevice common, bool edit,string str_if,Dictionary<string, object> editdeviceActionInfo = null)
        {
            actionsInfo = editdeviceActionInfo;
            this.BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor;
            TopView view = new TopView();
            this.AddChidren(view.TopRowView());
            view.toptitleNameBtn.Text = LocalDevice.Current.GetDeviceEpointName(common);
            view.clickBtn.MouseDownEventHandler += (sender, e) =>
            {
                RemoveFromParent();
            };
            var middle = new FrameLayout
            {
                Y = view.topRowLayout.Bottom,
                Height = Application.GetRealHeight(Method.H - 184),
                BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
            };
            this.AddChidren(middle);
 
            LogicView.LightView openView = new LogicView.LightView();
            openView.titleBtn.Text = Language.StringByID(MyInternationalizationString.nightLightSwitch);
            middle.AddChidren(openView.Show());
            openView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
            {
                CurrentDeviceView("夜灯开关", common, edit, openView.seletecdTextBtn);
            };
 
            LogicView.LightView brightnessView = new LogicView.LightView();
            brightnessView.frameLayout.Y = openView.frameLayout.Bottom;
            brightnessView.titleBtn.Text = Language.StringByID(MyInternationalizationString.brightness);
            middle.AddChidren(brightnessView.Show());
            brightnessView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
            {
                CurrentDeviceView("亮度", common, edit, brightnessView.seletecdTextBtn);
            };
 
            LogicView.LightView colorTemperatureView = new LogicView.LightView();
            colorTemperatureView.frameLayout.Y = brightnessView.frameLayout.Bottom;
            colorTemperatureView.titleBtn.Text = Language.StringByID(MyInternationalizationString.colorTemperature);
            middle.AddChidren(colorTemperatureView.Show());
            colorTemperatureView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
            {
                CurrentDeviceView("色温", common, edit, colorTemperatureView.seletecdTextBtn);
            };
 
            LogicView.LightView buzzView = new LogicView.LightView();
            buzzView.frameLayout.Y = colorTemperatureView.frameLayout.Bottom;
            buzzView.titleBtn.Text = Language.StringByID(MyInternationalizationString.buzzer);
            middle.AddChidren(buzzView.Show());
            buzzView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
            {
                CurrentDeviceView("蜂鸣器", common, edit, buzzView.seletecdTextBtn);
            };
 
            LogicView.SaveView saveView = new LogicView.SaveView();
            saveView.frameLayout.Y = middle.Height - Application.GetRealHeight(260);
            middle.AddChidren(saveView.Show());
            saveView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (selectedDeviceStatus != "" && actionsInfo != null)
                {
                    LogicIfon.AddDeviceActions(common, actionsInfo);
                }
                else
                {
                    if (!edit)
                    {
                        var alert = new UserCenter.ShowMsgControl(UserCenter.ShowMsgType.Normal,
                                    Language.StringByID(MyInternationalizationString.selectdevicestatuscondition),
                                   Language.StringByID(MyInternationalizationString.confrim));
                        alert.Show();
                        return;
                    }
 
                }
 
                if (str_if == "logic")
                {
                    var logicCommunalPage = new LogicCommunalPage();
                    UserView.HomePage.Instance.AddChidren(logicCommunalPage);
                    UserView.HomePage.Instance.PageIndex += 1;
                    logicCommunalPage.Show(() => { });
                }
                else if (str_if == "lockaction")
                {
                    //门锁联动事件
                    var lockLogicCommunalPage = new DoorLockLogic.LockLogicCommunalPage();
                    UserView.HomePage.Instance.AddChidren(lockLogicCommunalPage);
                    UserView.HomePage.Instance.PageIndex += 1;
                    lockLogicCommunalPage.Show(() => { });
                }
 
            };
 
            if (edit)
            {
                foreach (var deviceinfo in Common.Logic.CurrentLogic.Actions)
                {
                    if (deviceinfo["LinkType"].ToString() == "0")
                    {
 
                        if (deviceinfo["DeviceAddr"].ToString() == common.DeviceAddr && deviceinfo["Epoint"].ToString() == common.DeviceEpoint.ToString())
                        {
                            TaskList = deviceinfo["TaskList"] as List<Dictionary<string, string>>;
                            foreach (var tasks in TaskList)
                            {
                                switch (tasks["TaskType"])
                                {
                                    case "1":
                                        {
                                            if (tasks["Data1"] == "0")
                                            {
                                                openView.seletecdTextBtn.TextID = MyInternationalizationString.close;
                                            }
                                            else
                                            {
                                                openView.seletecdTextBtn.TextID = MyInternationalizationString.open;
                                            }
                                        }
                                        break;
                                    case "3":
                                        {
                                            var intvalue = int.Parse(tasks["Data1"]);
                                            var lightbrightnessvalue = (intvalue * 100) / 254;
                                            brightnessView.seletecdTextBtn.Text = lightbrightnessvalue.ToString() + "%";
                                        }
                                        break;
                                    case "7":
                                        {
                                            if (tasks["Data1"] == "0")
                                            {
                                                buzzView.seletecdTextBtn.TextID = MyInternationalizationString.close;
                                            }
                                            else
                                            {
                                                buzzView.seletecdTextBtn.TextID = MyInternationalizationString.open;
                                            }
                                        }
                                        break;
                                    case "8":
                                        {
                                            var intvalue = int.Parse(tasks["Data1"]);
                                            var lightbrightnessvalue = 1000000 / (intvalue * 100);
                                            colorTemperatureView.seletecdTextBtn.Text = lightbrightnessvalue.ToString() + "K";
                                        }
                                        break;
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }
        public void CurrentDeviceView(string if_str, CommonDevice common, bool edit, Button button)
        {
            var flMain = new FrameLayout { BackgroundColor = ZigbeeColor.Current.LogicViewBackgroundColor };
            this.AddChidren(flMain);
            UserView.HomePage.Instance.ScrollEnabled = false;//不让当前界面滑动
            CompleteView completeView = new CompleteView();
            flMain.AddChidren(completeView.Show(2));
            completeView.Btntitle.Text = LocalDevice.Current.GetDeviceEpointName(common);
            EventHandler<MouseEventArgs> clickcancel = (sender, e) =>
            {
                UserView.HomePage.Instance.ScrollEnabled = true;
                flMain.RemoveFromParent();
            };
            flMain.MouseUpEventHandler += clickcancel;
            completeView.Btncancel.MouseUpEventHandler += clickcancel;
            if (actionsInfo == null)
            {
                actionsInfo = new Dictionary<string, object>();
                TaskList = new List<Dictionary<string, string>>();
                actionsInfo.Add("LinkType", 0);
                actionsInfo.Add("DeviceAddr", common.DeviceAddr);
                actionsInfo.Add("Epoint", common.DeviceEpoint);
                actionsInfo.Add("Time", 0);
                actionsInfo.Add("TaskList", TaskList);
            }
            string status = "";
 
            switch (if_str)
            {
                case "夜灯开关":
                    {
 
                        Dictionary<string, string> switchDictionary = new Dictionary<string, string>();
                        Send.dictionary(switchDictionary, "TaskType", "1");
                        Send.dictionary(switchDictionary, "Data2", "0");
                        mFunView openView = new mFunView();
                        openView.frameLayout.Y = Application.GetRealHeight(140 + 20);
                        openView.titleBtn.TextID = MyInternationalizationString.open;
                        completeView.Show(2).AddChidren(openView.Show());
                        mFunView closeView = new mFunView();
                        closeView.frameLayout.Y = Application.GetRealHeight(140 + 20 + 160);
                        closeView.titleBtn.TextID = MyInternationalizationString.close;
                        completeView.Show(2).AddChidren(closeView.Show());
                        closeView.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor;
                        ///点击确认事件
                        openView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
                        {
                            selectedDeviceStatus = "1";
                            openView.selectedIconBtn.Visible = true;
                            closeView.selectedIconBtn.Visible = false;
                            openView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor;
                            closeView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor;
                            Send.dictionary(switchDictionary, "Data1", "1");//默认值
                            DicValue("1", switchDictionary);
                            status = Language.StringByID(MyInternationalizationString.open);
                        };
 
                        ///点击取消事件
                        closeView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
                        {
                            selectedDeviceStatus = "1";
                            openView.selectedIconBtn.Visible = false;
                            closeView.selectedIconBtn.Visible = true;
                            openView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor;
                            closeView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor;
                            Send.dictionary(switchDictionary, "Data1", "0");//默认值
                            DicValue("1", switchDictionary);
                            status = Language.StringByID(MyInternationalizationString.close);
 
                        };
                        if (TaskList != null && TaskList.Count != 0)
                        {
                            foreach (var value in TaskList)
                            {
                                if (value["TaskType"] == "1")
                                {
                                    if (value["Data1"] == "1")
                                    {
                                        openView.selectedIconBtn.Visible = true;
                                        closeView.selectedIconBtn.Visible = false;
                                    }
                                    else
                                    {
                                        openView.selectedIconBtn.Visible = false;
                                        closeView.selectedIconBtn.Visible = true;
                                    }
                                    break;
                                }
 
                            }
                        }
                    }
                    break;
                case "亮度":
                    {
                        Dictionary<string, string> brightnessDictionary = new Dictionary<string, string>();
                        Send.dictionary(brightnessDictionary, "TaskType", "3");
                        Send.dictionary(brightnessDictionary, "Data2", "0");
                        var horizontalSeekBarVol = new DiyImageSeekBar
                        {
                            Y = Application.GetRealHeight(140),//进度条父控件Y坐标
                            X = Application.GetRealWidth(78),//进度条X坐标
                            Width = Application.GetRealWidth(918),//进度条的长度
                            Height = Application.GetRealHeight(320),//进度条父控控件高度
                            IsProgressTextShow = true,//显示百分比
                            IsClickable = true,//进度条是否滑动
                            ProgressBarColor = ZigbeeColor.Current.LogicProgressColorSelected,//选中进度条颜色
                            ThumbImagePath = "ZigeeLogic/progressbtn2.png",//进度条按钮图标
                            ThumbImageHeight = Application.GetRealHeight(89),//进度条按钮图标的高度(默认正方形:宽和高一样)
                            ProgressTextColor = ZigbeeColor.Current.LogicBtnCancelColor,
                            ProgressTextSize = 9,//显示百分比字体大小12
                            SeekBarViewHeight = Application.GetRealHeight(6),//进度条的高度10
                        };
                        completeView.Show(2).AddChidren(horizontalSeekBarVol);
                        EventHandler<int> progressclick = (sender, e) =>
                        {
                            selectedDeviceStatus = "3";
                            int lightbrightnessvalue = (254 * horizontalSeekBarVol.Progress) / 100;
                            Send.dictionary(brightnessDictionary, "Data1", lightbrightnessvalue.ToString());
                            DicValue("3", brightnessDictionary);
                            status = horizontalSeekBarVol.Progress.ToString() + "%";
                        };
                        horizontalSeekBarVol.OnProgressChangedEvent += progressclick;
                        horizontalSeekBarVol.OnStopTrackingTouchEvent += progressclick;
 
                        if (TaskList != null && TaskList.Count != 0)
                        {
                            foreach (var value in TaskList)
                            {
                                if (value["TaskType"] == "3")
                                {
                                    var intvalue = int.Parse(value["Data1"]);
                                    var lightbrightnessvalue = (intvalue * 100) / 254;
                                    horizontalSeekBarVol.Progress = lightbrightnessvalue;
                                    break;
                                }
 
                            }
                        }
                    }
                    break;
                case "色温":
                    {
                        Dictionary<string, string> brightnessDictionary = new Dictionary<string, string>();
                        Send.dictionary(brightnessDictionary, "TaskType", "8");
                        Send.dictionary(brightnessDictionary, "Data2", "0");
                        Button seekIconBtn = new Button
                        {
                            Y = Application.GetRealHeight(140 + 154),
                            X = Application.GetRealWidth(78),
                            Height = Application.GetRealHeight(12),
                            Width = Application.GetRealWidth(918),
                            UnSelectedImagePath = "ZigeeLogic/seek.png",
                        };
                        completeView.Show(2).AddChidren(seekIconBtn);
                        var horizontalSeekBarVol = new DiyImageSeekBar
                        {
                            Y = Application.GetRealHeight(140),
                            X = Application.GetRealWidth(78),
                            Width = Application.GetRealWidth(918),
                            Height = Application.GetRealHeight(320),//滑动条父控件高度
                            IsProgressTextShow = true,//显示百分比
                            IsClickable = true,//进度条是否滑动
                            ProgressBarColor = 0x00000000,// ZigbeeColor.Current.LogicProgressColorSelected,//选中进度条颜色
                            SeekBarBackgroundColor = 0x00000000,
                            ThumbImagePath = "ZigeeLogic/progressbtn2.png",//进度条按钮图标
                            ThumbImageHeight = Application.GetRealHeight(89),//进度条按钮图标的高度(默认正方形:宽和高一样)
                            ProgressTextColor = ZigbeeColor.Current.LogicBtnCancelColor,
                            ProgressTextSize = 9,//显示百分比字体大小12
                            SeekBarViewHeight = Application.GetRealHeight(12),//进度条的高度10
                            MinValue = 30,
                            MaxValue = 60,
                            ProgressBarUnitSring = "K",//切换单位
                        };
                        completeView.Show(2).AddChidren(horizontalSeekBarVol);
                        EventHandler<int> progressclick = (sender, e) =>
                        {
                            selectedDeviceStatus = "8";
                            var lightbrightnessvalue = 1000000 / (100 * horizontalSeekBarVol.Progress);
                            Send.dictionary(brightnessDictionary, "Data1", lightbrightnessvalue.ToString());
                            DicValue("8", brightnessDictionary);
                            status = horizontalSeekBarVol.Progress.ToString() + "K";
                        };
                        horizontalSeekBarVol.OnProgressChangedEvent += progressclick;
                        horizontalSeekBarVol.OnStopTrackingTouchEvent += progressclick;
 
 
                        if (TaskList != null && TaskList.Count != 0)
                        {
                            foreach (var value in TaskList)
                            {
                                if (value["TaskType"] == "8")
                                {
                                    var intvalue = int.Parse(value["Data1"]);
                                    var lightbrightnessvalue = 1000000 / (intvalue * 100);
                                    horizontalSeekBarVol.Progress = lightbrightnessvalue;
                                    break;
                                }
 
                            }
                        }
                    }
                    break;
                case "蜂鸣器":
                    {
                        Dictionary<string, string> switchDictionary = new Dictionary<string, string>();
                        Send.dictionary(switchDictionary, "TaskType", "7");
                        Send.dictionary(switchDictionary, "Data2", "0");
 
 
                        mFunView openView = new mFunView();
                        openView.frameLayout.Y = Application.GetRealHeight(140 + 20);
                        openView.titleBtn.TextID = MyInternationalizationString.open;
                        completeView.Show(2).AddChidren(openView.Show());
                        mFunView closeView = new mFunView();
                        closeView.frameLayout.Y = Application.GetRealHeight(140 + 20 + 160);
                        closeView.titleBtn.TextID = MyInternationalizationString.close;
                        completeView.Show(2).AddChidren(closeView.Show());
                        closeView.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor;
 
                        ///点击确认事件
                        openView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
                        {
                            selectedDeviceStatus = "7";
                            openView.selectedIconBtn.Visible = true;
                            closeView.selectedIconBtn.Visible = false;
                            openView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor;
                            closeView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor;
                            Send.dictionary(switchDictionary, "Data1", "1");//默认值
                            DicValue("7", switchDictionary);
                            status = Language.StringByID(MyInternationalizationString.open);
                        };
 
                        ///点击取消事件
                        closeView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
                        {
                            selectedDeviceStatus = "7";
                            openView.selectedIconBtn.Visible = false;
                            closeView.selectedIconBtn.Visible = true;
                            openView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor;
                            closeView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor;
                            Send.dictionary(switchDictionary, "Data1", "0");//默认值
                            DicValue("7", switchDictionary);
                            status = Language.StringByID(MyInternationalizationString.close);
 
                        };
 
                        if (TaskList != null && TaskList.Count != 0)
                        {
                            foreach (var value in TaskList)
                            {
                                if (value["TaskType"] == "7")
                                {
                                    if (value["Data1"] == "1")
                                    {
                                        openView.selectedIconBtn.Visible = true;
                                        closeView.selectedIconBtn.Visible = false;
                                    }
                                    else
                                    {
                                        openView.selectedIconBtn.Visible = false;
                                        closeView.selectedIconBtn.Visible = true;
                                    }
                                    break;
                                }
 
                            }
                        }
                    }
                    break;
            }
            completeView.Btncomplete.MouseUpEventHandler += (sender, e) =>
            {
                if (selectedDeviceStatus != "")
                {
 
                    flMain.RemoveFromParent();
                    button.Text = status;
 
                }
                else
                {
                    if (!edit)
                    {
                        var alert = new UserCenter.ShowMsgControl(UserCenter.ShowMsgType.Normal,
                                    Language.StringByID(MyInternationalizationString.selectdevicestatuscondition),
                                   Language.StringByID(MyInternationalizationString.confrim));
                        alert.Show();
                        return;
                    }
                    else
                    {
                        flMain.RemoveFromParent();
                    }
 
                }
 
            };
        }
        public void DicValue(string str, Dictionary<string, string> dictionay)
        {
            bool d = false;
            foreach (var tasks in TaskList)
            {
                if (tasks["TaskType"] == str)
                {
 
                    TaskList.Remove(tasks);
                    TaskList.Add(dictionay);
                    d = true;
                    break;
                }
            }
            if (!d)
            {
                if (TaskList != null)
                {
                    TaskList.Add(dictionay);
                }
            }
        }
    }
 
}