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
using System;
using System.Collections.Generic;
using System.Threading;
 
namespace Shared.SimpleControl.Phone
{
    public class UserDeviceToSecurity : FrameLayout
    {
        /// <summary>
        /// 当前设备界面
        /// </summary>
        static UserDeviceToSecurity curView;
        VerticalScrolViewLayout equipmentListScrolView;
        VerticalScrolViewLayout bodyScrolView;
 
        /// <summary>
        /// 构造函数
        /// </summary>
        public UserDeviceToSecurity ()
        {
            curView = this;
        }
 
        public void ShowSecurityView ()
        {
            #region 标题
            var topView = new FrameLayout () {
                Y = Application.GetRealHeight (36),
                Height = Application.GetRealHeight (90),
                BackgroundColor = SkinStyle.Current.MainColor,
            };
            AddChidren (topView);
 
            var title = new Button () {
                TextAlignment = TextAlignment.Center,
                Text = Language.StringByID (R.MyInternationalizationString.Security),
                TextColor = SkinStyle.Current.TextColor1,
                TextSize = 19,
            };
            topView.AddChidren (title);
 
            var logo = new Button () {
                Width = Application.GetRealWidth (154),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (486),
                UnSelectedImagePath = MainPage.LogoString,
            };
            topView.AddChidren (logo);
            var back = new Button () {
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (85),
                UnSelectedImagePath = "Item/Back.png",
                SelectedImagePath = "Item/BackSelected.png",
            };
            topView.AddChidren (back);
            back.MouseUpEventHandler += (sender, e) => {
                (Parent as PageLayout).PageIndex -= 1;
                curView = null;
            };
 
            #endregion
 
 
            bodyScrolView = new VerticalScrolViewLayout () {
                Height = Application.GetRealHeight (Application.DesignHeight - 126),
                Y = Application.GetRealHeight (126),
            };
            AddChidren (bodyScrolView);
 
            //显示有多少个
            var securityModulFiles = IO.FileUtils.ReadFiles ().FindAll ((obj) => obj.Split ('_').Length == 4 && obj.Split ('_') [0] == "Equipment" && obj.Split ('_') [1] == DeviceType.SecurityModule.ToString ());
            var securityFiles = IO.FileUtils.ReadFiles ().FindAll ((obj) => obj.Split ('_').Length == 5 && obj.Split ('_') [0] == "Equipment" && obj.Split ('_') [1] == DeviceType.SecurityModule.ToString ());
            foreach (var securityFile in securityModulFiles) {
                SecurityModul securityDevice = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityModul> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (securityFile)));
                if (securityDevice == null) {
                    continue;
                }
                FrameLayout roomView = new FrameLayout () {
                    Height = Application.GetRealHeight (110),
                    BackgroundColor = SkinStyle.Current.ViewColor,
                    Tag = securityDevice.Name
                };
                bodyScrolView.AddChidren (roomView);
                Button btnRoomNull = new Button () {
                    Height = 1,
                    SelectedBackgroundColor = SkinStyle.Current.MainColor,
                    BackgroundColor = SkinStyle.Current.MainColor,
                };
                bodyScrolView.AddChidren (btnRoomNull);
                Button btnPoint = new Button () {
                    Width = Application.GetRealWidth (10),
                    Height = Application.GetRealHeight (10),
                    X = Application.GetRealWidth (50),
                    Gravity = Gravity.CenterVertical,
                    UnSelectedImagePath = "Item/Point.png",
                    SelectedImagePath = "Item/Point.png",
                };
                roomView.AddChidren (btnPoint);
                Button btnRoomName = new Button () {
                    Text = securityDevice.Name,
                    X = btnPoint.Right + Application.GetRealWidth (20),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = SkinStyle.Current.TextColor1,
                    SelectedTextColor = SkinStyle.Current.TextColor1,
                };
                roomView.AddChidren (btnRoomName);
 
                btnRoomName.MouseUpEventHandler += (sender, e) => {
                    UserSecurityPage usp = new UserSecurityPage (securityDevice);
                    UserMiddle.DevicePageView.AddChidren (usp);
                    usp.ShowSecurityArea ();
                    UserMiddle.DevicePageView.PageIndex = 2;
                };
            }
 
            #region 
            FrameLayout ShowAllView = new FrameLayout () {
                Height = Application.GetRealHeight (85),
                BackgroundColor = SkinStyle.Current.MainColor,
            };
            bodyScrolView.AddChidren (ShowAllView);
 
            Button btnShowAll = new Button () {
                X = Application.GetRealWidth (20),
                TextAlignment = TextAlignment.CenterLeft,
                Text = Language.StringByID (R.MyInternationalizationString.AreaList),
                TextColor = SkinStyle.Current.TextColor1,
                SelectedTextColor = SkinStyle.Current.TextColor1
            };
            ShowAllView.AddChidren (btnShowAll);
 
            Button downSelectedButton = new Button () {
                X = Application.GetRealWidth (550),
                Height = Application.GetRealHeight (50),
                Width = Application.GetRealWidth (55),
                UnSelectedImagePath = "Item/Down.png",
                SelectedImagePath = "Item/DownSelected.png",
                Gravity = Gravity.CenterVertical,
                IsSelected = true,
            };
            ShowAllView.AddChidren (downSelectedButton);
 
            //显示出所有的灯
            equipmentListScrolView = new VerticalScrolViewLayout () {
                Height = bodyScrolView.Height - ShowAllView.Height,
            };
            bodyScrolView.AddChidren (equipmentListScrolView);
            int LightCount = 0;
 
            EventHandler<MouseEventArgs> eHandler = (sender, e) => {
                btnShowAll.IsSelected = !btnShowAll.IsSelected;
                downSelectedButton.IsSelected = btnShowAll.IsSelected;
                UserConfig.Instance.SaveUserConfig ();
                if (btnShowAll.IsSelected) {
                    equipmentListScrolView.RemoveAll ();
                    foreach (var securityModulFile in securityFiles) {
                        SecurityModul securityDevice = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityModul> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (securityModulFile)));
                        if (securityDevice == null) {
                            continue;
                        }
                        LightCount++;
 
                        FrameLayout lightView = new FrameLayout () {
                            Width = Application.GetRealWidth(640),
                            Height = Application.GetRealHeight (110),
                        };
                        lightView.AddTag ("UpdataKey", securityDevice.CommonLoopID);
                        equipmentListScrolView.AddChidren (lightView);
                        Button btnLightViewBottomNull = new Button () {
                            Y = Application.GetRealHeight (107),
                            Height = Application.GetRealHeight (3),
                            BackgroundColor = SkinStyle.Current.MainColor,
                            SelectedBackgroundColor = SkinStyle.Current.MainColor,
                        };
                        lightView.AddChidren (btnLightViewBottomNull);
                        Button btnPoint2 = new Button () {
                            Width = Application.GetRealWidth (10),
                            Height = Application.GetRealHeight (10),
                            X = Application.GetRealWidth (50),
                            Gravity = Gravity.CenterVertical,
                            UnSelectedImagePath = "Item/Point.png",
                            SelectedImagePath = "Item/Point.png",
                        };
                        lightView.AddChidren (btnPoint2);
                        
                        var tempDeviceName = new Button () {
                            X = btnPoint2.Right + Application.GetRealWidth (20),
                            TextAlignment = TextAlignment.CenterLeft,
                            Width = Application.GetRealWidth (640),
                            Text = securityDevice.Name,
                            TextColor = SkinStyle.Current.TextColor1,
                            SelectedTextColor = SkinStyle.Current.TextColor1,
                        };
                        lightView.AddChidren (tempDeviceName);
 
                        EventHandler<MouseEventArgs> eHandler2 = (sender2, e2) => {
                            UserSecurityAreaPage usap = new UserSecurityAreaPage (securityDevice);
                            UserMiddle.DevicePageView.AddChidren (usap);
                            usap.ShowSecurityArea ();
                            UserMiddle.DevicePageView.PageIndex = 2;
                        };
                        tempDeviceName.MouseUpEventHandler += eHandler2;
                        lightView.MouseUpEventHandler += eHandler2;
                        btnLightViewBottomNull.MouseUpEventHandler += eHandler2;
                    }
                    equipmentListScrolView.Height = LightCount * Application.GetRealHeight (130);
                } else {
                    equipmentListScrolView.Height = 0;
                    LightCount = 0;
                }
            };
            btnShowAll.MouseUpEventHandler += eHandler;
            downSelectedButton.MouseUpEventHandler += eHandler;
            //默认是选中状态
            eHandler (btnShowAll, new MouseEventArgs ());
            #endregion
        }
    }
}