黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone
{
    /// <summary>
    /// 安防管理主页的控件
    /// </summary>
    public class SafetyMasterControl : NormalFrameLayout
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 在家布防
        /// </summary>
        private GarrisonControl btnAthomeGarrison = null;
        /// <summary>
        /// 离家布防
        /// </summary>
        private GarrisonControl btnRemovehomeGarrison = null;
        /// <summary>
        /// 撤防
        /// </summary>
        private GarrisonControl btnReGarrisonGarrison = null;
        /// <summary>
        /// 桌布控件
        /// </summary>
        private FrameLayout frameTable = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 初始化
        /// </summary>
        public SafetyMasterControl()
        {
            this.Gravity = Gravity.CenterHorizontal;
            this.Width = Application.GetRealWidth(964);
            this.Height = Application.GetRealHeight(340);
        }
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        public void InitControl()
        {
            this.btnAthomeGarrison = null;
            this.btnReGarrisonGarrison = null;
            this.btnRemovehomeGarrison = null;
 
            this.frameTable = new FrameLayout();
            frameTable.Height = this.Height;
            frameTable.Width = this.Width;
            frameTable.Radius = (uint)Application.GetRealHeight(58);
            frameTable.BackgroundColor = UserCenterColor.Current.White;
            this.AddChidren(frameTable);
 
            //右上圆角背景
            var btnTopRight = new NormalViewControl(150, 60, true);
            btnTopRight.BackgroundColor = UserCenterColor.Current.White;
            btnTopRight.RadiusEx = 17;
            this.AddChidren(btnTopRight);
            btnTopRight.X = this.Width - btnTopRight.Width;
 
            //左下圆角背景
            var btnBottomRight = new NormalViewControl(150, 60, true);
            btnBottomRight.BackgroundColor = UserCenterColor.Current.White;
            btnBottomRight.RadiusEx = 17;
            this.AddChidren(btnBottomRight);
            btnBottomRight.Y = this.Height - btnBottomRight.Height;
 
            //设置有内部防区
            if (HdlSafeguardLogic.Current.IsHadInternalDefenseArea() == true)
            {
                //在家布防
                btnAthomeGarrison = new GarrisonControl();
                frameTable.AddChidren(btnAthomeGarrison);
                btnAthomeGarrison.InitControl(GarrisonMode.AtHome);
                btnAthomeGarrison.ButtonClickEvent += (sender, e) =>
                {
                    if (btnAthomeGarrison.btnIcon.IsSelected == false)
                    {
                        this.SetSafetyGarrisonModeInAtHome();
                    }
                };
                //离家布防
                btnRemovehomeGarrison = new GarrisonControl();
                btnRemovehomeGarrison.X = btnAthomeGarrison.Right + Application.GetRealWidth(32);
                frameTable.AddChidren(btnRemovehomeGarrison);
                btnRemovehomeGarrison.InitControl(GarrisonMode.RemoveHome);
                btnRemovehomeGarrison.ButtonClickEvent += (sender, e) =>
                {
                    if (btnRemovehomeGarrison.btnIcon.IsSelected == false)
                    {
                        this.SetSafetyGarrisonModeInRemoveHome();
                    }
                };
                //撤防
                btnReGarrisonGarrison = new GarrisonControl();
                btnReGarrisonGarrison.X = btnRemovehomeGarrison.Right + Application.GetRealWidth(32);
                frameTable.AddChidren(btnReGarrisonGarrison);
                btnReGarrisonGarrison.InitControl(GarrisonMode.RemoveGarrison);
                btnReGarrisonGarrison.ButtonClickEvent += (sender, e) =>
                {
                    this.RemoveSafetyGarrisonMode();
                };
            }
            else
            {
                //布防
                btnAthomeGarrison = new GarrisonControl();
                btnAthomeGarrison.X = Application.GetRealWidth(166);
                frameTable.AddChidren(btnAthomeGarrison);
                btnAthomeGarrison.InitControl(GarrisonMode.AtHome);
                btnAthomeGarrison.ButtonClickEvent += (sender, e) =>
                {
                    if (btnAthomeGarrison.btnIcon.IsSelected == false)
                    {
                        this.SetSafetyGarrisonModeInAtHome();
                    }
                };
                //撤防
                btnReGarrisonGarrison = new GarrisonControl();
                btnReGarrisonGarrison.X = btnAthomeGarrison.Right + Application.GetRealWidth(32);
                frameTable.AddChidren(btnReGarrisonGarrison);
                btnReGarrisonGarrison.InitControl(GarrisonMode.RemoveGarrison);
                btnReGarrisonGarrison.ButtonClickEvent += (sender, e) =>
                {
                    this.RemoveSafetyGarrisonMode();
                };
            }
            //根据布防模式,设置图标的选择状态
            this.SetIconStatuByGarrisonMode(HdlSafeguardLogic.Current.NowGarrisonMode);
        }
 
        #endregion
 
        #region ■ 布防撤防___________________________
 
        /// <summary>
        /// 在家布防
        /// </summary>
        private async void SetSafetyGarrisonModeInAtHome()
        {
            //打开进度条
            ProgressBar.Show(string.Empty);
            //在家布防
            GarrisonMode mode = await HdlSafeguardLogic.Current.SetSafetyGarrisonByModel(GarrisonMode.AtHome);
            //关闭进度条
            ProgressBar.Close();
            if (mode == GarrisonMode.None)
            {
                return;
            }
 
            HdlThreadLogic.Current.RunMain(() =>
            {
                //根据布防模式,设置图标的选择状态
                this.SetIconStatuByGarrisonMode(mode);
                if (mode == GarrisonMode.RemoveGarrison)
                {
                    return;
                }
 
                //如果设置有内部防区
                string msg = string.Empty;
                if (HdlSafeguardLogic.Current.IsHadInternalDefenseArea() == true)
                {
                    //在家布防设置成功
                    msg = Language.StringByID(R.MyInternationalizationString.uSetAtHomeGarrisonSuccess);
                }
                else
                {
                    //布防设置成功
                    msg = Language.StringByID(R.MyInternationalizationString.uSetGarrisonSuccess);
                }
                var control = new ShowMsgControl(ShowMsgType.Tip, msg);
                control.Show();
            });
        }
 
        /// <summary>
        /// 离家布防
        /// </summary>
        private async void SetSafetyGarrisonModeInRemoveHome()
        {
            //打开进度条
            ProgressBar.Show(string.Empty);
            //离家布防
            GarrisonMode mode = await HdlSafeguardLogic.Current.SetSafetyGarrisonByModel(GarrisonMode.RemoveHome);
            //关闭进度条
            ProgressBar.Close();
 
            if (mode == GarrisonMode.None)
            {
                return;
            }
 
            HdlThreadLogic.Current.RunMain(() =>
            {
                //根据布防模式,设置图标的选择状态
                this.SetIconStatuByGarrisonMode(mode);
                if (mode == GarrisonMode.RemoveGarrison)
                {
                    return;
                }
                //离家布防设置成功
                string msg = Language.StringByID(R.MyInternationalizationString.uSetRemoveHomeGarrisonSuccess);
                var control = new ShowMsgControl(ShowMsgType.Tip, msg);
                control.Show();
            });
        }
 
        /// <summary>
        /// 撤防
        /// </summary>
        private async void RemoveSafetyGarrisonMode()
        {
            //打开进度条
            ProgressBar.Show(string.Empty);
            //撤防
            var result = await HdlSafeguardLogic.Current.RemoveSafetyGarrison(GarrisonMode.RemoveGarrison, false);
            //关闭进度条
            ProgressBar.Close();
 
            if (result == -1)
            {
                return;
            }
            HdlThreadLogic.Current.RunMain(() =>
            {
                //根据布防模式,设置图标的选择状态
                this.SetIconStatuByGarrisonMode(GarrisonMode.RemoveGarrison);
 
                //离家布防设置成功
                string msg = Language.StringByID(R.MyInternationalizationString.uRemoveGarrisonSuccess);
                var control = new ShowMsgControl(ShowMsgType.Tip, msg);
                control.Show();
            });
        }
 
        /// <summary>
        /// 根据布防模式,设置图标的选择状态
        /// </summary>
        /// <param name="mode"></param>
        public void SetIconStatuByGarrisonMode(GarrisonMode mode)
        {
            //在家布防
            if (mode == GarrisonMode.AtHome)
            {
                this.btnAthomeGarrison?.SetActionStatu(true);
                this.btnRemovehomeGarrison?.SetActionStatu(false);
                this.btnReGarrisonGarrison?.SetActionStatu(false);
            }
            //离家布防
            else if (mode == GarrisonMode.RemoveHome)
            {
                this.btnAthomeGarrison?.SetActionStatu(false);
                this.btnRemovehomeGarrison?.SetActionStatu(true);
                this.btnReGarrisonGarrison?.SetActionStatu(false);
            }
            //撤防 
            else
            {
                this.btnAthomeGarrison?.SetActionStatu(false);
                this.btnRemovehomeGarrison?.SetActionStatu(false);
                this.btnReGarrisonGarrison?.SetActionStatu(true);
            }
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 设置布防按钮的可视状态
        /// </summary>
        public void SetButtonVisible()
        {
            //设置有内部防区
            if (HdlSafeguardLogic.Current.IsHadInternalDefenseArea() == true
                && btnRemovehomeGarrison != null)
            {
                //没必要再初始化界面
                return;
            }
            HdlThreadLogic.Current.RunMain(() =>
            {
                //清空全部控件
                this.RemoveAll();
                //重新初始化控件
                this.InitControl();
            });
        }
 
        #endregion
 
        #region ■ 封装控件___________________________
 
        /// <summary>
        /// 封装的布防控件
        /// </summary>
        private class GarrisonControl : FrameLayoutStatuControl
        {
            #region ■ 变量声明___________________________
 
            /// <summary>
            /// 背景控件
            /// </summary>
            private NormalViewControl btnBack = null;
            /// <summary>
            /// 图标控件
            /// </summary>
            public IconViewControl btnIcon = null;
            /// <summary>
            /// 文本控件
            /// </summary>
            private NormalViewControl btnText = null;
            /// <summary>
            /// 选择状态的背景色
            /// </summary>
            private uint selectBackColor = 0;
 
            #endregion
 
            #region ■ 初始化_____________________________
 
            /// <summary>
            /// 封装的布防控件
            /// </summary>
            public GarrisonControl()
            {
                //关闭状态显示
                this.UseClickStatu = false;
                this.Gravity = Gravity.CenterVertical;
                this.Width = Application.GetRealWidth(300);
                this.Height = Application.GetRealHeight(216);
            }
 
            /// <summary>
            /// 初始化控件
            /// </summary>
            /// <param name="garrison">防区模式</param>
            public void InitControl(GarrisonMode garrison)
            {
                //移除底层事件
                this.RemoveBaseClickEvent();
 
                //背景
                int backHeight = this.GetPictrueRealSize(132);
                btnBack = new NormalViewControl(backHeight, backHeight, false);
                btnBack.Gravity = Gravity.CenterHorizontal;
                btnBack.Radius = (uint)backHeight / 2;
                btnBack.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
                this.AddChidren(btnBack, ChidrenBindMode.BindEvent);
 
                //图标
                btnIcon = new IconViewControl(81);
                btnIcon.Y = Application.GetRealHeight(26);
                btnIcon.Gravity = Gravity.CenterHorizontal;
                this.AddChidren(btnIcon, ChidrenBindMode.BindEvent);
 
                //文本
                btnText = new NormalViewControl(this.Width, Application.GetRealHeight(58), false);
                btnText.TextColor = UserCenterColor.Current.TextGrayColor3;
                btnText.Y = Application.GetRealHeight(158);
                btnText.TextAlignment = TextAlignment.Center;
                this.AddChidren(btnText, ChidrenBindMode.NotBind);
 
                if (garrison == GarrisonMode.AtHome)
                {
                    this.selectBackColor = 0xffffa200;
                    btnIcon.UnSelectedImagePath = "Safeguard/ProtectionAtHome.png";
                    btnIcon.SelectedImagePath = "Safeguard/ProtectionAtHomeSelected.png";
 
                    //设置有内部防区
                    if (HdlSafeguardLogic.Current.IsHadInternalDefenseArea() == true)
                    {
                        btnText.TextID = R.MyInternationalizationString.uAtHomeGarrison;
                    }
                    else
                    {
                        btnText.TextID = R.MyInternationalizationString.uGarrison;
                    }
                }
                else if (garrison == GarrisonMode.RemoveHome)
                {
                    this.selectBackColor = 0xff35b87f;
                    btnIcon.UnSelectedImagePath = "Safeguard/ProtectionRemoveHome.png";
                    btnIcon.SelectedImagePath = "Safeguard/ProtectionRemoveHomeSelected.png";
                    btnText.TextID = R.MyInternationalizationString.uRemoveHomeGarrison;
                }
                else if (garrison == GarrisonMode.RemoveGarrison)
                {
                    this.selectBackColor = 0xff4a90e2;
                    btnIcon.UnSelectedImagePath = "Safeguard/WithdrawGarrison.png";
                    btnIcon.SelectedImagePath = "Safeguard/WithdrawGarrisonSelected.png";
                    btnText.TextID = R.MyInternationalizationString.uWithdrawGarrison;
                }
            }
            #endregion
 
            #region ■ 一般方法___________________________
 
            /// <summary>
            /// 设置控件的激活状态
            /// </summary>
            /// <param name="actionStatu">设置控件的激活状态 true:激活状态(选中) false:非激活状态</param>
            public void SetActionStatu(bool actionStatu)
            {
                if (actionStatu == true)
                {
                    btnIcon.IsSelected = true;
                    btnBack.BackgroundColor = selectBackColor;
                    btnText.TextColor = selectBackColor;
                }
                else
                {
                    btnIcon.IsSelected = false;
                    btnBack.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
                    btnText.TextColor = UserCenterColor.Current.TextGrayColor3;
                }
            }
 
            #endregion
        }
 
        #endregion
    }
}