BruceLee
2019-09-24 a9f88790c31c8b61d9b90241c4df258a980f1c00
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 安防记录控件
    /// </summary>
    public class SafeguardLogControl : FrameLayout
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 今日无任何报警记录 的控件
        /// </summary>
        private NormalViewControl btnMsg = null;
        /// <summary>
        /// 各防区的桌布控件
        /// </summary>
        private Dictionary<int, FrameLayout> dicFrame = new Dictionary<int, FrameLayout>();
        /// <summary>
        /// 各防区的行控件
        /// </summary>
        private Dictionary<int, List<FrameLayout>> dicRowFrame = new Dictionary<int, List<FrameLayout>>();
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 初始化
        /// </summary>
        public SafeguardLogControl()
        {
            this.BackgroundColor = UserCenterColor.Current.White;
            this.Radius = (uint)Application.GetMinRealAverage(17);
            this.Height = Application.GetRealHeight(260);
        }
 
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="dayText">日期</param>
        /// <param name="dicInfo">防区报警信息</param>
        public void InitControl(string dayText, Dictionary<int, List<SafeguardAlarmInfo>> dicInfo)
        {
            //记录时间
            var btnTime = new NormalViewControl(300, 58, true);
            btnTime.X = Application.GetRealWidth(92);
            btnTime.Y = Application.GetRealHeight(29);
            btnTime.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnTime.TextID = R.MyInternationalizationString.uRecordTime;
            this.AddChidren(btnTime);
 
            //日期
            string month = dayText.Substring(4, 2);
            string day = dayText.Substring(6, 2);
            var btnDay = new NormalViewControl(300, 58, true);
            btnDay.X = this.Width - Application.GetRealWidth(300 + 89);
            btnDay.Y = btnTime.Y;
            btnDay.TextColor = UserCenterColor.Current.TextColor2;
            btnDay.TextAlignment = TextAlignment.CenterRight;
            btnDay.Text = month + Language.StringByID(R.MyInternationalizationString.Month) + day + Language.StringByID(R.MyInternationalizationString.Day);
            this.AddChidren(btnDay);
 
            //线
            var btnLine = new NormalViewControl(Application.GetRealWidth(904), ControlCommonResourse.BottomLineHeight, false);
            btnLine.X = Application.GetRealWidth(86);
            btnLine.Y = Application.GetRealHeight(98);
            btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
            this.AddChidren(btnLine);
 
            //预创建五大防区的桌布
            var listId = new List<int>() { 1, 2, 4, 5, 3 };
            int tempY = 0;
            for (int i = 0; i < listId.Count; i++)
            {
                var frame1 = new FrameLayout();
                frame1.Height = Application.GetRealHeight(10);
                frame1.Y = tempY == 0 ? Application.GetRealHeight(98) : tempY;
                this.AddChidren(frame1);
                dicFrame[listId[i]] = frame1;
                dicRowFrame[listId[i]] = new List<FrameLayout>();
 
                //初始化防区标题控件
                this.InitGarrisonTitleControl(listId[i]);
 
                if (dicInfo != null && dicInfo.ContainsKey(listId[i]) == true && dicInfo[listId[i]].Count > 0)
                {
                    var listRow = dicRowFrame[listId[i]];
                    foreach (var alarmInfo in dicInfo[listId[i]])
                    {
                        //添加报警信息
                        var contr = this.AddAlarmInfoControl(alarmInfo);
                        if (listRow.Count != 0)
                        {
                            contr.Y = listRow[listRow.Count - 1].Bottom + Application.GetRealHeight(23);
                        }
                        listRow.Add(contr);
                    }
                    //变更高度
                    frame1.Height = listRow[listRow.Count - 1].Bottom + Application.GetRealHeight(55);
                    this.Height = frame1.Bottom;
                    tempY = frame1.Bottom;
                }
                else
                {
                    frame1.Visible = false;
                }
            }
 
            if (dicInfo == null || dicInfo.Count == 0)
            {
                //今日无任何报警记录
                btnMsg = new NormalViewControl(this.Width, Application.GetRealHeight(58), false);
                btnMsg.Y = btnLine.Bottom + Application.GetRealHeight(29);
                btnMsg.TextColor = UserCenterColor.Current.TextGrayColor3;
                btnMsg.TextID = R.MyInternationalizationString.uNowDayNotHadAlarmLog;
                btnMsg.TextAlignment = TextAlignment.Center;
                this.AddChidren(btnMsg);
            }
        }
 
        #endregion
 
        #region ■ 初始化防区标题控件_________________
 
        /// <summary>
        /// 初始化防区标题控件
        /// </summary>
        /// <param name="zoneId"></param>
        private void InitGarrisonTitleControl(int zoneId)
        {
            FrameLayout frame = dicFrame[zoneId];
            //图标
            var btnIcon = new IconViewControl(69);
            btnIcon.X = Application.GetRealWidth(86);
            btnIcon.Y = Application.GetRealHeight(23);
            //只会是1~5
            if (zoneId == 1 || zoneId == 2)
            {
                btnIcon.UnSelectedImagePath = "Safeguard/ProtectionAtHome.png";
            }
            else
            {
                btnIcon.UnSelectedImagePath = "Safeguard/ProtectionRemoveHome.png";
            }
            frame.AddChidren(btnIcon);
            //防区名
            var btnName = new NormalViewControl(400, 58, true);
            btnName.X = Application.GetRealWidth(167);
            btnName.Y = Application.GetRealHeight(35);
            btnName.Text = HdlSafeguardLogic.Current.GetGarrisonText(zoneId);
            frame.AddChidren(btnName);
            //已启动
            var btnStatu = new NormalViewControl(300, 46, true);
            btnStatu.X = frame.Width - Application.GetRealWidth(300 + 89);
            btnStatu.Y = Application.GetRealHeight(35);
            btnStatu.TextSize = 12;
            btnStatu.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnStatu.TextAlignment = TextAlignment.CenterRight;
            btnStatu.TextID = R.MyInternationalizationString.uHadStarted;
            frame.AddChidren(btnStatu);
            //空白行
            var btnSpace = new FrameLayout();
            btnSpace.Height = Application.GetRealHeight(46);
            btnSpace.Y = btnIcon.Bottom;
            frame.AddChidren(btnSpace);
        }
 
        #endregion
 
        #region ■ 添加报警信息_______________________
 
        /// <summary>
        /// 添加报警信息
        /// </summary>
        /// <returns></returns>
        public int AddSafeguardAlarmInfo(SafeguardAlarmInfo alarmInfo)
        {
            if (dicFrame.ContainsKey(alarmInfo.ZoneId) == false)
            {
                return -1;
            }
            if (btnMsg != null)
            {
                //移除信息提示控件
                btnMsg.RemoveFromParent();
                btnMsg = null;
            }
            var listRow = dicRowFrame[alarmInfo.ZoneId];
            if (listRow.Count == 0)
            {
                dicFrame[alarmInfo.ZoneId].Visible = true;
                //重置桌布间的间距
                int tempY = 0;
                foreach (var frame in dicFrame.Values)
                {
                    if (frame.Visible == true)
                    {
                        frame.Y = tempY == 0 ? Application.GetRealHeight(98) : tempY;
                        tempY = frame.Bottom;
                    }
                }
            }
 
            //添加报警信息控件
            var frameRow = this.AddAlarmInfoControl(alarmInfo);
            if (listRow.Count >= 100)
            {
                //移除最后一个
                listRow[listRow.Count - 1].RemoveFromParent();
                listRow.RemoveAt(listRow.Count - 1);
            }
            //当前这个防区的全部行控件往下移动
            foreach (var row in listRow)
            {
                row.Y += frameRow.Height + Application.GetRealHeight(23);
            }
            listRow.Insert(0, frameRow);
 
            var value = listRow[listRow.Count - 1].Bottom + Application.GetRealHeight(55) - dicFrame[alarmInfo.ZoneId].Height;
            if (value <= 0)
            {
                return 0;
            }
 
            //变更高度
            dicFrame[alarmInfo.ZoneId].Height += value;
            //它之下的全部桌布全部往下移动
            bool canMove = false;
            int realHeight = 0;
            foreach (var id in dicFrame.Keys)
            {
                if (id == alarmInfo.ZoneId)
                {
                    //当前的桌布
                    canMove = true;
                }
                else if (canMove == true)
                {
                    dicFrame[id].Y += value;
                }
                if (canMove == true && dicFrame[id].Visible == true)
                {
                    //记录起最后一个FrameLayout的底部
                    realHeight = dicFrame[id].Bottom;
                }
            }
            if (realHeight > 0)
            {
                //变更整个控件的真实高度 
                this.Height = realHeight;
            }
            return value;
        }
 
        /// <summary>
        /// 添加报警信息控件
        /// </summary>
        /// <param name="alarmInfo"></param>
        /// <returns></returns>
        private FrameLayout AddAlarmInfoControl(SafeguardAlarmInfo alarmInfo)
        {
            var frame = dicFrame[alarmInfo.ZoneId];
 
            var rowFrame = new FrameLayout();
            rowFrame.Y = Application.GetRealHeight(130);
            rowFrame.Height = Application.GetRealHeight(58);
            frame.AddChidren(rowFrame);
 
            //房间
            var btnRoom = new NormalViewControl(165, 58, true);
            btnRoom.X = Application.GetRealWidth(92);
            btnRoom.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnRoom.Text = alarmInfo.RoomName;
            rowFrame.AddChidren(btnRoom);
            //设备
            string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(alarmInfo.DeviceAddr, alarmInfo.DeviceEpoint);
            var device = Common.LocalDevice.Current.GetDevice(mainkeys);
            var btnDevice = new NormalViewControl(271, 58, true);
            btnDevice.X = Application.GetRealWidth(256);
            btnDevice.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnDevice.Text = device == null ? alarmInfo.DeviceName : Common.LocalDevice.Current.GetDeviceEpointName(device);
            rowFrame.AddChidren(btnDevice);
            //报警信息
            var btnMsg = new NormalViewControl(303, 58, true);
            btnMsg.X = Application.GetRealWidth(527);
            btnMsg.TextColor = UserCenterColor.Current.TextGrayColor3;
            //电池电量
            if (alarmInfo.BatteryMsg != null)
            {
                btnMsg.Text = alarmInfo.BatteryMsg;
            }
            //被拆报警
            else if (alarmInfo.DemolishmentMsg != null)
            {
                btnMsg.Text = alarmInfo.DemolishmentMsg;
            }
            else
            {
                btnMsg.Text = alarmInfo.AlarmMsg;
            }
            rowFrame.AddChidren(btnMsg);
            //时间:时分秒
            var btnTime = new NormalViewControl(176, 58, true);
            btnTime.X = Application.GetRealWidth(829);
            btnTime.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnTime.TextAlignment = TextAlignment.CenterRight;
            btnTime.Text = alarmInfo.Time;
            rowFrame.AddChidren(btnTime);
 
            return rowFrame;
        }
 
        #endregion
 
        #region ■ 控件销毁___________________________
 
        /// <summary>
        /// 控件销毁
        /// </summary>
        public override void RemoveFromParent()
        {
            dicRowFrame.Clear();
            dicFrame.Clear();
 
            base.RemoveFromParent();
        }
 
        #endregion
    }
}