JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
using Shared.SimpleControl.Phone;
using System;
using Shared;
using System.Collections.Generic;
/*
    2017-02-10 :去掉房间里面的新增修改场景,改为在用户节目新增修改
*/
namespace Shared.SimpleControl.Pad
{
    public class SystemRoom
    {
        /// <summary>
        /// 显示房间列表界面
        /// </summary>
        public void ShowRoomList ()
        {
            SystemMiddle.FristScrolView.RemoveAll ();
            SystemMiddle.SecondScrolView.RemoveAll ();
            SystemMiddle.ThirdScrolView.RemoveAll ();
 
            foreach (var roomFilePath in Room.FilePathList) {
                if(roomFilePath == Room.FavoriteRoom)
                {
                    continue;    
                }
                RowLayout frameLayout = new RowLayout () {
                    Height = Application.GetRealHeight (131),
                };
                EventHandler<MouseEventArgs> roomEvent = (sender, e) => {
                    SystemMiddle.FristScrolView.SelectedInVerticalScrolViewFrameLayoutButton (roomFilePath);
                    ShowRoom (roomFilePath);
                    ShowDevcieListView (roomFilePath);
                };
 
                frameLayout.MouseUpEventHandler += roomEvent;
                SystemMiddle.FristScrolView.AddChidren (frameLayout);
                var btnDelFile = new Button () {
                    TextID = R.MyInternationalizationString.Del,
                    BackgroundColor = SkinStyle.Current.DelColor
                };
                btnDelFile.MouseUpEventHandler += (sender, e) => {//删除房间确认
                    Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipDeleteRoomMessage), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
                    alert.ResultEventHandler += (object sender2, bool e2) => {
                        if (e2) {
                            Room.Remove (roomFilePath);
                            ShowRoomList ();
                        }
                    };
                    alert.Show ();
                };
                frameLayout.AddRightView (btnDelFile);
                Button btnIcon = new Button () {
                    Width = Application.GetRealHeight (13),
                    Height = Application.GetRealHeight (13),
                    X = Application.GetRealWidth (40),
                    UnSelectedImagePath = "Item/Point.png",
                    SelectedImagePath = "Item/PointSelected.png",
                    Gravity = Gravity.CenterVertical,
                    Tag = roomFilePath
                };
                frameLayout.AddChidren (btnIcon);
 
                Button btnName = new Button () {
                    Width = Application.GetRealWidth (342),
                    Height = LayoutParams.MatchParent,
                    Text = roomFilePath.Split ('_') [1],
                    TextAlignment = TextAlignment.CenterLeft,
                    X = btnIcon.X + btnIcon.Width + Application.GetRealWidth (20),
                    SelectedTextColor = SkinStyle.Current.SelectedColor,
                    TextColor = SkinStyle.Current.TextColor1,
                    Tag = roomFilePath
                };
                frameLayout.AddChidren (btnName);
 
                btnName.MouseUpEventHandler += roomEvent;
                frameLayout.MouseUpEventHandler += roomEvent;
 
                Button btnNul = new Button () {
                    Y = Application.GetRealHeight (131) - 2,
                    Height = 1,
                    BackgroundColor = SkinStyle.Current.MainColor,
                };
                frameLayout.AddChidren (btnNul);
                Button btnNull = new Button () {
                    Y = Application.GetRealHeight (131) - 1,
                    Height = 1,
                    BackgroundColor = 0xFF2f2f2f,
                };
                frameLayout.AddChidren (btnNull);
            }
 
            // top
            Button btnTopButton = new Button () {
                TextID = R.MyInternationalizationString.AddNewRoom,
                TextSize = 16
            };
            SystemMiddle.FristScrolView.TitleView.AddChidren (btnTopButton);
            btnTopButton.MouseUpEventHandler += (sender, e) => {
                SystemRoomScenesMethod.AddOrUpdateRoomForPad (ShowRoomList, null, "");
            };
        }
 
        /// <summary>
        /// 显示指定房间界面
        /// </summary>
        public void ShowRoom (string roomFilePath)
        {
            MainPage.Loading.Start ("Loading...");
            System.Threading.Tasks.Task.Run (() => {
                Application.RunOnMainThread (() => {
                    Room.InitAllRoom ();
                    Room room = Room.GetRoomByFilePath (roomFilePath);
                    if (room == null)
                        return;
                    SystemMiddle.SecondScrolView.RemoveAll ();
                    #region  top
                    EditText textButton = new EditText () {
                        X = Application.GetRealWidth (40),
                        Height = Application.GetRealHeight (50),
                        Width = Application.GetRealWidth (400),
                        Text = roomFilePath.Split ('_') [1],
                        Gravity = Gravity.CenterVertical,
                        TextAlignment = TextAlignment.CenterLeft,
                        SelectedBackgroundColor = 0xFF000000,
                        Enable = false,
                        TextSize = 16,
                    };
                    SystemMiddle.SecondScrolView.TitleView.AddChidren (textButton);
 
                    Button editor = new Button () {
                        Height = Application.GetRealHeight (90),
                        Width = Application.GetRealWidth (70),
                        UnSelectedImagePath = "Item/Editor.png",
                        SelectedImagePath = "Item/EditorSelected.png",
                        Gravity = Gravity.CenterVertical,
                        X = Application.GetRealWidth (550),
                    };
                    SystemMiddle.SecondScrolView.TitleView.AddChidren (editor);
                    editor.MouseUpEventHandler += (sender, e) => {
                        if (editor.IsSelected) {
                        } else {
                            SystemRoomScenesMethod.AddOrUpdateRoomForPad (ShowRoomList, ShowRoom, roomFilePath, ShowDevcieListView);
                        }
                    };
                    #endregion
                    //显示已经添加进房间的设备
                    foreach (string deviceFilePath in room.DeviceFilePathList) {
                        initEquipmentsBase (deviceFilePath, roomFilePath);
                    }
 
                    MainPage.Loading.Hide ();
                });
            });
        }
 
        void initEquipmentsBase (string deviceFilePath,string roomFilePath)
        {
            if (!deviceFilePath.StartsWith ("Equipment_")) {
                return;
            }
            if (deviceFilePath.Split ('_') [1] == DeviceType.FanModule.ToString ()) {
                #region 风扇
                FanModule fanModule = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (CommonPage.MyEncodingUTF8.GetString (
                IO.FileUtils.ReadFile (deviceFilePath)));
                if (fanModule == null)
                    return;
 
                initEquipments (fanModule.Name, roomFilePath, "Fan/Fan.png", deviceFilePath);
                #endregion
            } else if (deviceFilePath.Split ('_') [1] == DeviceType.LightDimming.ToString () || deviceFilePath.Split ('_') [1] == DeviceType.LightMixDimming.ToString ()) {
                #region 调光器
                LightDimming dimming = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDimming> (CommonPage.MyEncodingUTF8.GetString (
                    IO.FileUtils.ReadFile (deviceFilePath)));
                if (dimming == null)
                    return;
 
                initEquipments (dimming.Name, roomFilePath, "Item/Light.png", deviceFilePath);
                #endregion
            } else if (deviceFilePath.Split ('_') [1] == DeviceType.LightRGB.ToString ()) {
                #region RGB
                LightLogic rgbLight = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (CommonPage.MyEncodingUTF8.GetString (
                    IO.FileUtils.ReadFile (deviceFilePath)));
                if (rgbLight == null)
                    return;
 
                initEquipments (rgbLight.Name, roomFilePath, "Item/Light.png", deviceFilePath);
                #endregion
            } else if (deviceFilePath.Split ('_') [1] == DeviceType.LightSwitch.ToString () || deviceFilePath.Split ('_') [1] == DeviceType.LightMixSwitch.ToString ()
                      || deviceFilePath.Split ('_') [1] == DeviceType.LightEnergySwitch.ToString ()) {
                #region 继电器
                LightSwitch switchLight = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (CommonPage.MyEncodingUTF8.GetString (
                IO.FileUtils.ReadFile (deviceFilePath)));
                if (switchLight == null)
                    return;
 
                initEquipments (switchLight.Name, roomFilePath, "Item/Light.png", deviceFilePath);
                #endregion
            } else if (deviceFilePath.Split ('_') [1] == DeviceType.CurtainModel.ToString ()) {
                #region 窗帘
                CurtainModel curtain = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainModel> (CommonPage.MyEncodingUTF8.GetString (
                IO.FileUtils.ReadFile (deviceFilePath)));
                if (curtain == null)
                    return;
 
                initEquipments (curtain.Name, roomFilePath, "Curtain/Curtain.png", deviceFilePath);
                #endregion
            } else if (deviceFilePath.Split ('_') [1] == DeviceType.CurtainTrietex.ToString ()) {
                #region 开合帘窗帘
                CurtainTrietex curtain = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainTrietex> (CommonPage.MyEncodingUTF8.GetString (
                IO.FileUtils.ReadFile (deviceFilePath)));
                if (curtain == null)
                    return;
 
                initEquipments (curtain.Name, roomFilePath, "Curtain/Curtain.png", deviceFilePath);
                #endregion
            } else if (deviceFilePath.Split ('_') [1] == DeviceType.CurtainRoller.ToString ()) {
                #region 卷帘
                CurtainRoller curtain = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainRoller> (CommonPage.MyEncodingUTF8.GetString (
                IO.FileUtils.ReadFile (deviceFilePath)));
                if (curtain == null)
                    return;
 
                initEquipments (curtain.Name, roomFilePath, "Curtain/Curtain.png", deviceFilePath);
                #endregion
            } else if (deviceFilePath.Split ('_') [1] == DeviceType.MusicModel.ToString ()) {
                #region 音乐模块
                MusicModel musicMode = Newtonsoft.Json.JsonConvert.DeserializeObject<MusicModel> (CommonPage.MyEncodingUTF8.GetString (
                    IO.FileUtils.ReadFile (deviceFilePath)));
                if (musicMode == null)
                    return;
                string loopID = (Convert.ToInt32 (musicMode.LoopID) < 10 ? "0" + musicMode.LoopID.ToString () : musicMode.LoopID.ToString ());
 
                initEquipments (musicMode.Name, roomFilePath, "Item/Music.png", deviceFilePath);
                #endregion
            } else if (deviceFilePath.Split ('_') [1] == DeviceType.HVAC.ToString ()) {
                #region AC
                HVAC acHost = Newtonsoft.Json.JsonConvert.DeserializeObject<HVAC> (CommonPage.MyEncodingUTF8.GetString (
                    IO.FileUtils.ReadFile (deviceFilePath)));
                if (acHost == null)
                    return;
 
                initEquipments (acHost.Name, roomFilePath, @"AC/AC.png", deviceFilePath);
            } else if (deviceFilePath.Split ('_') [1] == typeof (ACInfrared).Name) {
                ACInfrared acHost = Newtonsoft.Json.JsonConvert.DeserializeObject<ACInfrared> (CommonPage.MyEncodingUTF8.GetString (
                    IO.FileUtils.ReadFile (deviceFilePath)));
                if (acHost == null)
                    return;
 
                initEquipments (acHost.Name, roomFilePath, @"AC/AC.png", deviceFilePath);
                #endregion
            } else if (deviceFilePath.Split ('_') [1] == DeviceType.FoolHeat.ToString ()) {
                #region 地热模块
                FoolHeat th = Newtonsoft.Json.JsonConvert.DeserializeObject<FoolHeat> (CommonPage.MyEncodingUTF8.GetString (
                    IO.FileUtils.ReadFile (deviceFilePath)));
                if (th == null)
                    return;
 
                initEquipments (th.Name, roomFilePath, @"Item/FloorHeating.png", deviceFilePath);
                #endregion
            } else if (deviceFilePath.Split ('_') [1] == DeviceType.DryContact.ToString ()) {
                #region 干接点
                DryContact dc = Newtonsoft.Json.JsonConvert.DeserializeObject<DryContact> (CommonPage.MyEncodingUTF8.GetString (
                    IO.FileUtils.ReadFile (deviceFilePath)));
                if (dc == null)
                    return;
 
                initEquipments (dc.Name, roomFilePath, "Item/DryContact.png", deviceFilePath);
                #endregion
            } else if (deviceFilePath.Split ('_') [1] == DeviceType.InfraredMode.ToString ()) {
                #region 红外电视
                try {
                    InfraredMode infraredTV = Newtonsoft.Json.JsonConvert.DeserializeObject<InfraredMode> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                    if (infraredTV != null)
                        Console.WriteLine (infraredTV.InfraredType);
                    if (infraredTV.InfraredType == InfraredType.TV) {
 
                        initEquipments (infraredTV.Name, roomFilePath, "Item/InfraredTV.png", deviceFilePath);
                    }
                } catch (Exception ex) {
                    Console.WriteLine (ex.ToString ());
                    return;
                }
                #endregion
            }
        }
 
        /// <summary>
        /// 显示设备的方法
        /// </summary>
        void initEquipments (string remark, string roomFilePath, string iconPath, string deviceFilePath)
        {
            RowLayout frameLayout2 = new RowLayout () {
                Width = LayoutParams.MatchParent,
                Height = Application.GetRealHeight (131),
                Tag = deviceFilePath
            };
            SystemMiddle.SecondScrolView.AddChidren (frameLayout2);
 
            Button btnIcon = new Button () {
                Width = Application.GetRealHeight (60),
                Height = Application.GetRealHeight (60),
                X = Application.GetRealWidth (30),
                UnSelectedImagePath = iconPath,
                Gravity = Gravity.CenterVertical
            };
            frameLayout2.AddChidren (btnIcon);
            Button btnName = new Button () {
                Width = Application.GetRealWidth (342),
                Height = LayoutParams.MatchParent,
                Text = remark,
                TextAlignment = TextAlignment.CenterLeft,
                X = btnIcon.X + btnIcon.Width + Application.GetRealWidth (10),
            };
            frameLayout2.AddChidren (btnName);
 
            Button btnRight = new Button () {
                Width = Application.GetRealWidth (28),
                Height = Application.GetRealHeight (40),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "Item/Right.png",
                SelectedImagePath = "Item/RightSelected.png",
            };
            btnRight.X = frameLayout2.Width - btnRight.Width - Application.GetRealWidth (20);
 
            Button btnDelFile = new Button () {
                TextID = R.MyInternationalizationString.Del,
                BackgroundColor = SkinStyle.Current.DelColor,
            };
            frameLayout2.AddRightView (btnDelFile);
            btnDelFile.MouseUpEventHandler += (sender, e) => {
                Room room = Room.GetRoomByFilePath (roomFilePath);
                if (room == null)
                    return;
                room.DeviceFilePathList.Remove (deviceFilePath);
                room.Save (roomFilePath);
                ShowRoomList ();
            };
 
            Button btnNul = new Button () {
                Y = Application.GetRealHeight (131) - 2,
                Height = 1,
                BackgroundColor = SkinStyle.Current.MainColor,
            };
            frameLayout2.AddChidren (btnNul);
            Button btnNull = new Button () {
                Y = Application.GetRealHeight (131) - 1,
                Height = 1,
                BackgroundColor = 0xFF2f2f2f,
            };
            frameLayout2.AddChidren (btnNull);
        }
 
        void ShowDevcieListView (string roomFilePath)
        {
            SystemMiddle.ThirdScrolView.RemoveAll ();
            FrameLayout dropDownLayout = new FrameLayout ();
            SystemMiddle.ThirdScrolView.TitleView.AddChidren (dropDownLayout);
            Button btnEquipmentIcon = new Button () {
                Width = Application.GetRealHeight (65),
                Height = Application.GetRealHeight (65),
                UnSelectedImagePath = "Item/PointBig.png",
                X = Application.GetRealWidth (10),
                Gravity = Gravity.CenterVertical,
            };
            dropDownLayout.AddChidren (btnEquipmentIcon);
 
            FrameLayout DeviceListView = new FrameLayout ();
            SystemMiddle.ThirdScrolView.AddChidren (DeviceListView);
 
            Button btnEquipmentType = new Button () {
                Height = Application.GetRealHeight (70),
                X = btnEquipmentIcon.Right + Application.GetRealWidth (20),
                Gravity = Gravity.CenterVertical,
                TextAlignment = TextAlignment.CenterLeft,
                Text = Language.StringByID (R.MyInternationalizationString.All),
                TextSize = 16
            };
            dropDownLayout.AddChidren (btnEquipmentType);
 
            //存放设备的view
            VerticalScrolViewLayout DeviceListScrolView = new VerticalScrolViewLayout ();
            DeviceListView.AddChidren (DeviceListScrolView);
            FrameLayout inScrolView_DeviceListView = new FrameLayout ();
            DeviceListScrolView.AddChidren (inScrolView_DeviceListView);
 
            // ---显示在本地找到的所有设备---
            initAllLocalEquipment (roomFilePath,inScrolView_DeviceListView);
            VerticalScrolViewLayout typeLayout = new VerticalScrolViewLayout () {
                Height = 0,
            };
            DeviceListView.AddChidren (typeLayout);
 
            #region ---Add Device Dialog---
            btnEquipmentType.MouseUpEventHandler += (sender33, e55) => {
                //下拉列表的数据源(选项为设备类型有关)
                List<string> typeTemp = new List<string>{
                        Language.StringByID(R.MyInternationalizationString.All),
                        Language.StringByID(R.MyInternationalizationString.Lights),
                        Language.StringByID(R.MyInternationalizationString.Curtains),
                        Language.StringByID(R.MyInternationalizationString.AC),
                        Language.StringByID(R.MyInternationalizationString.FoolHeat),
                        Language.StringByID(R.MyInternationalizationString.TV),
                        Language.StringByID(R.MyInternationalizationString.ElectricalControl),
                        Language.StringByID(R.MyInternationalizationString.Fan),
                        Language.StringByID (R.MyInternationalizationString.MusicModel)
                };
 
                //如果当前显示的是所有的设备,就隐藏
                if (DeviceListScrolView.Height != 0) {
                    DeviceListScrolView.Height = 0;
                    typeLayout.Height = Application.GetRealHeight (1080);
                    if (typeLayout.ChildrenCount != 0) {
                        return;
                    }
                    foreach (string typeName in typeTemp) {
                        FrameLayout typeDropDownLayout1 = new FrameLayout () {
                            Height = Application.GetRealHeight (131),
                        };
                        typeLayout.AddChidren (typeDropDownLayout1);
                        Button btnEquipmentIcon2 = new Button () {
                            Width = Application.GetRealHeight (65),
                            Height = Application.GetRealHeight (65),
                            X = Application.GetRealWidth (40),
                            UnSelectedImagePath = "Item/PointBig.png",
                            Gravity = Gravity.CenterVertical,
                        };
                        typeDropDownLayout1.AddChidren (btnEquipmentIcon2);
                        Button btnTypeName = new Button () {
                            Width = Application.GetRealHeight (500),
                            X = btnEquipmentIcon.Right + Application.GetRealWidth (10),
                            Text = typeName,
                            TextAlignment = TextAlignment.CenterLeft,
                            Gravity = Gravity.CenterVertical,
                        };
                        typeDropDownLayout1.AddChidren (btnTypeName);
                        EventHandler<MouseEventArgs> typeEvent = (sender1, e1) => {
                            typeLayout.Height = 0;
                            DeviceListScrolView.Height = Application.GetRealHeight (1080);
                            btnEquipmentType.Text = typeName;
                            string deviceType = typeName;
                            if (typeName == Language.StringByID (R.MyInternationalizationString.Lights)) {
                                btnEquipmentIcon.UnSelectedImagePath = "Item/Light.png";
                                deviceType = "Light";
                            } else if (typeName == Language.StringByID (R.MyInternationalizationString.Curtains)) {
                                btnEquipmentIcon.UnSelectedImagePath = "Curtain/Curtain.png";
                                deviceType = "Curtain";
                            } else if (typeName == Language.StringByID (R.MyInternationalizationString.AC)) {
                                btnEquipmentIcon.UnSelectedImagePath = "AC/AC.png";
                                deviceType = "AC";
                            } else if (typeName == Language.StringByID (R.MyInternationalizationString.FoolHeat)) {
                                btnEquipmentIcon.UnSelectedImagePath = "Item/FloorHeating.png";
                                deviceType = "FoolHeat";
                            } else if (typeName == Language.StringByID (R.MyInternationalizationString.DryContactPanel)) {
                                btnEquipmentIcon.UnSelectedImagePath = "Item/DryContact.png";
                                deviceType = "DryContact";
                            } else if (typeName == Language.StringByID (R.MyInternationalizationString.MusicModel)) {
                                btnEquipmentIcon.UnSelectedImagePath = "Item/Music.png";
                                deviceType = "Music";
                            } else if (typeName == Language.StringByID (R.MyInternationalizationString.InfraredMode)) {
                                btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredTV.png";
                                deviceType = "InfraredMode";
                            } else if (typeName == Language.StringByID (R.MyInternationalizationString.TV)) {
                                btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredTV.png";
                                deviceType = "InfraredMode";
                            } else if (typeName == Language.StringByID (R.MyInternationalizationString.ElectricalControl)) {
                                btnEquipmentIcon.UnSelectedImagePath = "Light/Socket.png";
                                deviceType = "EC";//电器控制
                            } else if (typeName == Language.StringByID (R.MyInternationalizationString.Fan)) {
                                btnEquipmentIcon.UnSelectedImagePath = "Fan/Fan.png";
                                deviceType = "Fan";
                            } else if (typeName == Language.StringByID (R.MyInternationalizationString.LogicModule)) {
                                btnEquipmentIcon.UnSelectedImagePath = "Item/PointBig.png";
                                deviceType = "LogicModule";
                            } else {
                                btnEquipmentIcon.UnSelectedImagePath = "Item/LogicModule.png";
                                deviceType = "All";
                            }
                            initAllLocalEquipment (roomFilePath, inScrolView_DeviceListView, deviceType);
                        };
                        typeDropDownLayout1.MouseUpEventHandler += typeEvent;
                        btnTypeName.MouseUpEventHandler += typeEvent;
                        btnEquipmentIcon2.MouseUpEventHandler += typeEvent;
 
                        Button btnNul = new Button () {
                            Y = Application.GetRealHeight (131) - 2,
                            Height = 1,
                            BackgroundColor = SkinStyle.Current.MainColor,
                        };
                        typeDropDownLayout1.AddChidren (btnNul);
                        Button btnNull = new Button () {
                            Y = Application.GetRealHeight (131) - 1,
                            Height = 1,
                            BackgroundColor = 0xFF2f2f2f,
                        };
                        typeDropDownLayout1.AddChidren (btnNull);
                    }
 
                } else {
                    typeLayout.Height = Application.GetRealHeight (0);
                    DeviceListScrolView.Height = Application.GetRealHeight (1080);
                }
            };
            #endregion
        }
 
 
        /// <summary>
        /// 显示在本地找到的所有设备
        /// </summary>
        void initAllLocalEquipment (string roomFilePath,FrameLayout inScrolView_DeviceListView, string selectedDeviceType = null)
        {
            var filesList = IO.FileUtils.ReadFiles ();
            inScrolView_DeviceListView.RemoveAll ();
            var room = Room.GetRoomByFilePath (roomFilePath);
            
            int btnEquipmentIndex = 0;
            //找出需要显示的设备
            var localEquipments = filesList.FindAll ((obj) => {
                string [] str = obj.Split ('_');
                return obj.StartsWith ("Equipment_") && str.Length == 5
                          && (str [1] == DeviceType.LightSwitch.ToString () || str [1] == DeviceType.LightDimming.ToString () || str [1] == DeviceType.LightRGB.ToString ()
                              || str [1] == DeviceType.LightMixSwitch.ToString () || str [1] == DeviceType.LightMixDimming.ToString () || str [1] == DeviceType.LightEnergySwitch.ToString () 
                            || str [1] == DeviceType.CurtainModel.ToString () || str [1] == DeviceType.CurtainRoller.ToString ()
                            || str [1] == DeviceType.CurtainTrietex.ToString ()
                            || str [1] == DeviceType.ACInfrared.ToString ()
                            || str [1] == DeviceType.HVAC.ToString ()
                            || str [1] == DeviceType.FoolHeat.ToString ()
                              || str [1] == DeviceType.InfraredMode.ToString () 
                              || str [1] == DeviceType.MusicModel.ToString () 
                              || str [1] == DeviceType.FanModule.ToString ()
                              //|| str [1] == DeviceType.LogicModule.ToString () 
                          );
            });
            int i = 0;
            foreach (string deviceFilePath in localEquipments) {
                i++;
                string [] str = deviceFilePath.Split ('_');
                if (str [4].Length == 2 && str [4] [0] == '0') {
                    str [4] = str [4] [1].ToString ();
                }
                if (selectedDeviceType != null && selectedDeviceType != "All") {
                    //只显示当前选择的设备类型的设备
                    if (selectedDeviceType == "EC") {
                        if (str [1].Contains (DeviceType.LightSwitch.ToString ())) {
                            var b = IO.FileUtils.ReadFile (deviceFilePath);
                            LightSwitch c = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (b));
                            if (!c.IsSocket) {
                                continue;
                            }
                        } else
                            continue;
                    } else if (selectedDeviceType == "Light") {
                        if (str [1].Contains (DeviceType.LightSwitch.ToString ())) {
                            var b = IO.FileUtils.ReadFile (deviceFilePath);
                            LightSwitch c = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (b));
                            if (c.IsSocket) {
                                continue;
                            }
                        } else if (!str [1].Contains (selectedDeviceType))
                            continue;
                    } else {
                        if (!str [1].Contains (selectedDeviceType)) {
                            continue;
                        }
                    }
                }
                var deviceType = str [1];
                Button btnEquipment = new Button () {
                    Width = (inScrolView_DeviceListView.Width - Application.GetRealWidth (70)) / 2,
                    Height = Application.GetRealHeight (110),
                    X = Application.GetRealHeight (30),
                    Y = Application.GetRealHeight (20),
                    TextAlignment = TextAlignment.Center,
                    BackgroundColor = 0xFFDBDDDF,
                    SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
                    TextColor = 0xFF000000,
                    Text = i.ToString ()
                };
                var commonBytes = IO.FileUtils.ReadFile (deviceFilePath);
                if (commonBytes.Length == 0) {
                    Console.WriteLine ("length loss");
                    continue;
                }
                if (commonBytes.Length == 1) {
                    Console.WriteLine ("length loss 1");
                    continue;
                }
                Common commonDevice = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (System.Text.Encoding.UTF8.GetString (commonBytes));
 
                if (btnEquipmentIndex < 2) {
                    btnEquipment.X = btnEquipmentIndex * (btnEquipment.Width + Application.GetRealWidth (25)) + Application.GetRealWidth (20);
                    btnEquipment.Y = Application.GetRealHeight (30);
                    btnEquipmentIndex++;
                } else {
                    btnEquipment.X = btnEquipmentIndex % 2 * (btnEquipment.Width + Application.GetRealWidth (25)) + Application.GetRealWidth (20);
                    btnEquipment.Y = (int)btnEquipmentIndex / 2 * (btnEquipment.Height + Application.GetRealHeight (30)) + Application.GetRealHeight (30);
                    btnEquipmentIndex++;
                }
                btnEquipment.Text = commonDevice.Name;
                btnEquipment.Tag = deviceFilePath;
                inScrolView_DeviceListView.AddChidren (btnEquipment);
 
                if (room.DeviceFilePathList.Contains (btnEquipment.Tag.ToString ())) {
                    btnEquipment.IsSelected = true;
                } else {
                    foreach (var roomF in Room.Lists) {
                        if (roomF.DeviceFilePathList.Contains (btnEquipment.Tag.ToString ())) {
                            btnEquipment.BackgroundColor = 0xFB757575;
                        }
                    }
                }
 
                btnEquipment.MouseUpEventHandler += (sendere, ee) => {
                    btnEquipment.IsSelected = !btnEquipment.IsSelected;
                    if (btnEquipment.IsSelected) {
                        if (!room.DeviceFilePathList.Contains (btnEquipment.Tag.ToString ())) {
                            room.DeviceFilePathList.Add (btnEquipment.Tag.ToString ());
                        }
                        room.Save (roomFilePath);
                        initEquipmentsBase (deviceFilePath, roomFilePath);
                    } else {
                        room.DeviceFilePathList.Remove (btnEquipment.Tag.ToString ());
                        this.ShowRoom (roomFilePath);
                        room.Save (roomFilePath);
                    }
                };
 
                if (btnEquipmentIndex > 14) {
                    inScrolView_DeviceListView.Height = (btnEquipmentIndex / 2 + 1) * Application.GetRealHeight (150);
                } else {
                    inScrolView_DeviceListView.Height = Application.GetRealHeight (1080);
                }
            }
        }
    }
}