xm
2020-07-20 b02e8275a21dc06bf54b66273485d44e007a2616
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
using System;
using Shared.Common;
using Shared.R;
using Shared;
using ZigBee.Device;
using System.Collections.Generic;
namespace Shared.Phone.Device.Logic
{
    public class RoomAndDeviceView : FrameLayout
    {
        public RoomAndDeviceView()
        {
            Tag = "Logic";
        }
        Button roombjButton = new Button();
        Button roomTextButton = new Button();
        Button devicetypeButton = new Button();
        FrameLayout clickframeLayout = new FrameLayout();
        Button clickbutton = new Button();
        Button clicktextcolcrbutton = new Button();
        /// <summary>
        /// 判断字符
        /// </summary>
        public string IfType;
        /// <summary>
        /// 房间滑动的控件
        /// </summary>
        public HorizontalScrolViewLayout roomhorizontalScrol = new HorizontalScrolViewLayout
        {
            Width = Application.GetRealWidth(1080 - 58),
            Height = Application.GetRealHeight(200),
            X = Application.GetRealWidth(58),
            Y = Application.GetRealHeight(184),
        };
        /// <summary>
        /// 设备类型滑动的控件
        /// </summary>
        public HorizontalScrolViewLayout devicetypehorizontalScrol = new HorizontalScrolViewLayout
        {
            Width = Application.GetRealWidth(1080 - 58),
            Height = Application.GetRealHeight(280),
            Y = Application.GetRealHeight(184 + 200),
            BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor,
            X = Application.GetRealWidth(58),
            // Radius = (uint)Application.GetRealHeight(50),
 
        };
        /// <summary>
        /// 显示设备列表的控件
        /// </summary>
        public VerticalScrolViewLayout middle = new VerticalScrolViewLayout
        {
            X = Application.GetRealWidth(58),
            Y = Application.GetRealHeight(184 + 200 + 280 + 40),
            Height = Application.GetRealHeight(Method.H - 40 - 184 - 280 - 200),
            BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor,
        };
 
        public void Show(string Name)
        {
            #region  上面的布局代码
            UserView.HomePage.Instance.ScrollEnabled = false;//锁住左滑
            this.BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor;
            TopView view = new TopView();
            this.AddChidren(view.TopRowView(true));
            view.toptitleNameBtn.Text = Name;
            view.clickBtn.MouseDownEventHandler += (sender, e) =>
            {
                UserView.HomePage.Instance.ScrollEnabled = true;//恢复左滑
                RemoveFromParent();
            };
            view.foolrnameBtn.Text = Config.Instance.Home.GetCurrentFloorName;
            if (Config.Instance.Home.FloorDics.Count < 2)
            {
                ///没有楼层或者只有一个楼层,默认不显示图标和文本;
                view.foolrnameBtn.Visible = false;
                view.dropdownBtn.Visible = false;
                view.foolrclickBtn.Visible = false;
            }
            if (Config.Instance.Home.FloorDics.Count == 0)
            {
                Config.Instance.Home.CurrentFloorId = "";
            }
            #endregion
 
            ///房间列表
            var roomlists = Method.GetRoomList(IfType, Config.Instance.Home.CurrentFloorId);
            if (roomlists.Count == 0)
            {
                //返回没有房间隐藏下面整块;
                devicetypehorizontalScrol.Height = 0;
                middle.Height = 0;
            }
            /// 设备类型列表
            var deviceTypeList = Method.GetDevice(IfType);
            this.AddChidren(roomhorizontalScrol);
            this.AddChidren(devicetypehorizontalScrol);
            this.AddChidren(middle);
            devicetypehorizontalScrol.SetCornerWithSameRadius(Application.GetRealHeight(50), HDLUtils.RectCornerBottomLeft);
            middle.SetCornerWithSameRadius(Application.GetRealHeight(50), HDLUtils.RectCornerTopLeft);
            ///楼层点击事件
            view.foolrclickBtn.MouseUpEventHandler += (sender, e) =>
                {
                    var flMain = new FrameLayout { BackgroundColor = ZigbeeColor.Current.LogicViewBackgroundColor };
                    this.AddChidren(flMain);
                    flMain.MouseUpEventHandler += (sender2, e2) =>
                  {
                      flMain.RemoveFromParent();
                  };
                    var foolrbjicon = new FrameLayout
                    {
 
                        Width = Application.GetRealWidth(450),
                        Height = Application.GetRealHeight(780),
                        X = Application.GetRealWidth(1080 - 468 - 35),
                        Y = Application.GetRealHeight(184),
                        BackgroundImagePath = "Item/SelectFloor_Right.png",
                    };
                    flMain.AddChidren(foolrbjicon);
 
                    var btnfoolrtext = new Button
                    {
                        Width = Application.GetRealWidth(450),
                        Height = Application.GetRealHeight(150),
                        TextAlignment = TextAlignment.CenterLeft,
                        TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                        X = Application.GetRealWidth(80),
                        TextID = MyInternationalizationString.selecfoolr,
                        TextSize = 14,
                    };
                    foolrbjicon.AddChidren(btnfoolrtext);
 
                    var foolrbj = new VerticalScrolViewLayout
                    {
 
                        Width = Application.GetRealWidth(450),
                        Height = foolrbjicon.Height - btnfoolrtext.Height,
                        X = Application.GetRealWidth(80),
                        Y = btnfoolrtext.Bottom,
                    };
                    foolrbjicon.AddChidren(foolrbj);
 
                    foreach (var foolr in Config.Instance.Home.FloorDics)
                    {
                        var foolrRowLayout = new RowLayout
                        {
                            Height = Application.GetRealHeight(150),
                            LineColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
                        };
                        foolrbj.AddChidren(foolrRowLayout);
 
                        var btnfoolricon = new Button
                        {
                            Width = Application.GetMinRealAverage(81),
                            Height = Application.GetMinRealAverage(81),
                            UnSelectedImagePath = "Floor/Floor.png",
                            Gravity = Gravity.CenterVertical,
                        };
                        foolrRowLayout.AddChidren(btnfoolricon);
 
                        var btnfoolrname = new Button
                        {
                            Width = Application.GetRealWidth(250),
                            Height = Application.GetRealHeight(150),
                            Text = foolr.Value,
                            TextAlignment = TextAlignment.CenterLeft,
                            TextColor = ZigbeeColor.Current.LogicBtnCancelColor,
                            Tag = foolr.Key,
                            X = btnfoolricon.Right + Application.GetRealWidth(12),
                            TextSize = 14,
                        };
                        foolrRowLayout.AddChidren(btnfoolrname);
                        if (view.foolrnameBtn.Text == foolr.Value)
                        {
                            btnfoolricon.UnSelectedImagePath = "Floor/FloorSelected.png";
                            btnfoolrname.TextColor = ZigbeeColor.Current.LogicTextBlackColor;
                        }
 
                        EventHandler<MouseEventArgs> foolrnameclick = (sender13, e13) =>
                      {
 
                          roomhorizontalScrol.RemoveAll();
                          devicetypehorizontalScrol.RemoveAll();
                          middle.RemoveAll();
                          view.foolrnameBtn.Text = btnfoolrname.Text;
                          flMain.RemoveFromParent();
                          var list = Method.GetRoomList(IfType, btnfoolrname.Tag.ToString());
                          if (list.Count == 0)
                          {
                              devicetypehorizontalScrol.Height = 0;
                              middle.Height = 0;
                          }
                          else
                          {
                              devicetypehorizontalScrol.Height = Application.GetRealHeight(280);
                              middle.Height = Application.GetRealHeight(1920 - 40 - 184 - 280 - 200);
                          }
                          AllRoomView(list, deviceTypeList);
                      };
                        foolrRowLayout.MouseUpEventHandler += foolrnameclick;
                        btnfoolrname.MouseUpEventHandler += foolrnameclick;
 
                    }
 
                };
            AllRoomView(roomlists, deviceTypeList);
        }
        /// <summary>
        /// 加载所有房间的视图方法
        /// </summary>
        void AllRoomView(List<Common.Room> roomlist, List<DeviceType> deviceTypeList)
        {
            for (int i = 0; i < roomlist.Count; i++)
            {
                var room = roomlist[i];
 
                var fra = new FrameLayout
                {
                    Height = Application.GetRealHeight(200),
                    Width = Application.GetRealWidth(255),
                };
                roomhorizontalScrol.AddChidren(fra);
 
                var roombjBtn = new Button
                {
                    Height = Application.GetRealHeight(158),
                    Width = Application.GetRealWidth(255),
                    UnSelectedImagePath = "ZigeeLogic/iconBackgroundColor.png",
                    SelectedImagePath = "ZigeeLogic/iconSelectedBackgroundColor.png",
                    Y = Application.GetRealHeight(21),
                };
                fra.AddChidren(roombjBtn);
 
                var roomnameBtn = new Button
                {
 
                    Height = Application.GetRealHeight(152 - 26 - 20),
                    Width = Application.GetRealWidth(255 - 20 - 50),
                    Text = room.Name,
                    TextColor = ZigbeeColor.Current.LogicBtnCancelColor,
                    SelectedTextColor = ZigbeeColor.Current.LogicBlankBackgroundColor,
                    Y = Application.GetRealHeight(21 + 13 + 10),
                    X = Application.GetRealWidth(10 + 25),
 
                };
                fra.AddChidren(roomnameBtn);
 
                if (i == 0)//默认选中第一个房间
                {
                    roombjButton.IsSelected = false;
                    roombjButton = roombjBtn;
                    roombjBtn.IsSelected = true;
 
                    roomTextButton.IsSelected = false;
                    roomTextButton = roomnameBtn;
                    roomnameBtn.IsSelected = true;
 
                    roombjBtn.IsSelected = true;
                    roomnameBtn.IsSelected = true;
 
                    var list = Method.GetDeviceUIList(room, deviceTypeList);
                    AllDeviceTypeView(list);
                }
 
                EventHandler<MouseEventArgs> roomclick = (sender, e) =>
                {
                    roombjButton.IsSelected = false;
                    roombjButton = roombjBtn;
                    roombjBtn.IsSelected = true;
 
                    roomTextButton.IsSelected = false;
                    roomTextButton = roomnameBtn;
                    roomnameBtn.IsSelected = true;
 
 
                    var list = Method.GetDeviceUIList(room, deviceTypeList);
                    AllDeviceTypeView(list);
                };
                roomnameBtn.MouseUpEventHandler += roomclick;
                roombjBtn.MouseUpEventHandler += roomclick;
 
            }
        }
        /// <summary>
        /// 加载该区域所有设备视图方法
        /// </summary>0
        /// <param name="devicelist">Devicelist.</param>
        void AllDeviceTypeView(List<CommonDevice> devicelist)
        {
            var devicetypelist = Method.GetDeviceTypeList(devicelist);
            devicetypehorizontalScrol.RemoveAll();
            for (int i = 0; i < devicetypelist.Count; i++)
            {
                var devicetype = devicetypelist[i];
                var spaceRowLayout = new FrameLayout();
                devicetypehorizontalScrol.AddChidren(spaceRowLayout);
                if (i == 0)
                {
                    spaceRowLayout.Width = Application.GetRealWidth(37);
                }
                else
                {
                    spaceRowLayout.Width = Application.GetRealWidth(80);
                }
 
                var deviceRowLayout = new FrameLayout
                {
                    Width = Application.GetRealWidth(156 + 20),
                    Height = Application.GetRealHeight(280 - 30),
                    Y = Application.GetRealHeight(30),
                };
                devicetypehorizontalScrol.AddChidren(deviceRowLayout);
 
                var backgroundColor = new Button
                {
                    Width = Application.GetMinRealAverage(156),
                    Height = Application.GetMinRealAverage(180),
                    X = Application.GetRealWidth(10),
                    UnSelectedImagePath = "ZigeeLogic/deviceunselectedbackgroundcolor.png",
                    SelectedImagePath = "ZigeeLogic/deviceselectedbackgroundcolor.png",
                };
                deviceRowLayout.AddChidren(backgroundColor);
 
 
                var devicetypeicon = new Button
                {
                    Width = Application.GetMinRealAverage(84),
                    Height = Application.GetMinRealAverage(84),
                    X = Application.GetRealWidth(46),
                    Y = Application.GetRealHeight(30),
                    UnSelectedImagePath =Method.GetDeviceTypeIcon(devicetype),
                };
                deviceRowLayout.AddChidren(devicetypeicon);
 
                var devicetypename = new Button
                {
                    Width = Application.GetRealWidth(176),
                    Height = Application.GetRealHeight(40),
                    Text = devicetype,
                    TextAlignment = TextAlignment.Center,
                    Y = backgroundColor.Bottom,
                    TextColor = ZigbeeColor.Current.LogicAddColor,
                    TextSize = 10,
                };
                deviceRowLayout.AddChidren(devicetypename);
 
 
                //if (i == 0)//默认选中第一个设备类型
                //{
                //    devicetypeButton.IsSelected = false;
                //    devicetypeButton = backgroundColor;
                //    backgroundColor.IsSelected = true;
                //    var list = Method.GetDeviceType(devicetypename.Text);
                //    ConditionDeviceView(list, devicelist);
                //}
 
                EventHandler<MouseEventArgs> devicetypeclick = (sender13, e13) =>
                {
                    devicetypeButton.IsSelected = false;
                    devicetypeButton = backgroundColor;
                    backgroundColor.IsSelected = true;
                    var list = Method.GetDeviceType(devicetypename.Text);
                    ConditionDeviceView(list, devicelist);
                };
                deviceRowLayout.MouseUpEventHandler += devicetypeclick;
                devicetypename.MouseUpEventHandler += devicetypeclick;
                devicetypeicon.MouseUpEventHandler += devicetypeclick;
                backgroundColor.MouseUpEventHandler += devicetypeclick;
 
            }
            ///显示房间所有设备
            ConditionDeviceView(new List<DeviceType>(), devicelist);
 
 
        }
        /// <summary>
        /// 加载该类型设备视图方法
        /// </summary>
        /// <param name="deviceTypelist">Device typelist.</param>
        /// <param name="devicelist">设备列表</param>
        void ConditionDeviceView(List<DeviceType> deviceTypelist, List<CommonDevice> devicelist)
        {
 
            middle.RemoveAll();
            foreach (var common in devicelist)
            {
                if (deviceTypelist.Count != 0 && !deviceTypelist.Contains(common.Type))
                {
                    continue;
                }
                if (IfType == "condition_mould")
                {
                    if (common.IasDeviceType != 13)
                    {//自动化模板只支持红外传感器
                        continue;
                    }
                }
                var deviceFramelayout = new FrameLayout
                {
                    Height = Application.GetRealHeight(160),
                };
                middle.AddChidren(deviceFramelayout);
                var bjFramelayout = new FrameLayout
                {
                    Width = Application.GetMinRealAverage(112),
                    Height = Application.GetMinRealAverage(112),
                    X = Application.GetRealWidth(58),
                    Y = Application.GetRealHeight(30 + 9),
                     Radius = (uint)Application.GetMinRealAverage(56),
                    BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
                };
                deviceFramelayout.AddChidren(bjFramelayout);
                var deviceIconBtn = new Button
                {
                    Width = Application.GetMinRealAverage(82),
                    Height = Application.GetMinRealAverage(82),
                    Gravity = Gravity.Center,
                };
                bjFramelayout.AddChidren(deviceIconBtn);
                Method.GetDeviceIcon(common, deviceIconBtn);
                var deviceRow = new RowLayout
                {
                    Y = Application.GetRealHeight(30),
                    Width = Application.GetRealWidth(850),
                    Height = Application.GetRealHeight(130),
                    X = Application.GetRealWidth(176 + 25),
                    //LineColor = ZigbeeColor.Current.LogicRowLayoutLineColor,
                    LineColor = ZigbeeColor.Current.LogicBlankBackgroundColor,
                };
                deviceFramelayout.AddChidren(deviceRow);
                var devicename = new Button
                {
                    Text = LocalDevice.Current.GetDeviceEpointName(common),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                    SelectedTextColor = ZigbeeColor.Current.LogicAddColor,
                    TextSize = 14,
                };
                deviceRow.AddChidren(devicename);
 
                var lineBtn = new Button
                {
                    Y = deviceFramelayout.Height-1,
                    Height = 1,
                    Width = Application.GetRealWidth(850),
                    X = Application.GetRealWidth(176 + 25),
                    BackgroundColor = ZigbeeColor.Current.LogicRowLayoutLineColor,
                };
                deviceFramelayout.AddChidren(lineBtn);
                EventHandler<MouseEventArgs> devicclick = (sen, e) =>
                {
                    clickbutton.IsSelected = false;
                    clickbutton = deviceIconBtn;
                    deviceIconBtn.IsSelected = true;
                    clickframeLayout.BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor;
                    clickframeLayout = bjFramelayout;
                    bjFramelayout.BackgroundColor = ZigbeeColor.Current.LogicIconBackgroundColor;
                    clicktextcolcrbutton.IsSelected = false;
                    clicktextcolcrbutton = devicename;
                    devicename.IsSelected = true;
                    var flMain = new FrameLayout { BackgroundColor = ZigbeeColor.Current.LogicViewBackgroundColor };
                    this.AddChidren(flMain);
                    CurrentDeviceState.CurrentDeviceView(flMain, common, false, IfType,0);
                };
                deviceFramelayout.MouseUpEventHandler += devicclick;
                bjFramelayout.MouseUpEventHandler += devicclick;
                deviceIconBtn.MouseUpEventHandler += devicclick;
                deviceRow.MouseUpEventHandler += devicclick;
                devicename.MouseUpEventHandler += devicclick;
            }
        }
        
    }
}