黄学彪
2020-03-23 21923381bdac04d1633b168c97accc81f0898d84
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
using System;
using System.Text;
using System.Text.RegularExpressions;
using Shared.Common;
 
namespace Shared.Phone.UserCenter.DoorLock
{
    /// <summary>
    /// 显示一个信息框
    /// </summary>
    public class ShowDoorLockMsgControl
    {
        #region ■ 变量声明___________________________
        public Action<string> InvalidTimeAction = null;
        /// <summary>
        /// 点击取消的事件
        /// </summary>
        public Action CancelClickEvent = null;
        /// <summary>
        /// 点击自动化的事件
        /// </summary>
        public Action LogicClickEvent = null;
        /// <summary>
        /// 点击确认的事件
        /// </summary>
        public Action InvalidClickEvent = null;
        /// <summary>
        /// 点击确认的事件
        /// </summary>
        public Action ConfirmClickEvent = null;
        /// <summary>
        /// 信息类型
        /// </summary>
        private DoorLockMsgType msgType = DoorLockMsgType.Confirm;
        /// <summary>
        /// 消息
        /// </summary>
        private string msgText = string.Empty;
        /// <summary>
        /// 确认按钮的文本
        /// </summary>
        private string buttonOkText = null;
        /// <summary>
        /// 失效时间编辑
        /// </summary>
        private EditText editInvalidTime = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 显示一个需要确认的信息框
        /// </summary>
        /// <param name="i_msgType">信息类型</param>
        /// <param name="i_msg">信息</param>
        /// <param name="buttonText">确认按钮的文本</param>
        public ShowDoorLockMsgControl(DoorLockMsgType i_msgType, string i_msg, string buttonText = null)
        {
            //确认按钮文本
            this.buttonOkText = buttonText == null ? Language.StringByID(R.MyInternationalizationString.OkMsg) : buttonText;
            this.msgType = i_msgType;
            this.msgText = i_msg;
        }
 
        #endregion
 
        #region ■ 显示消息___________________________
 
        /// <summary>
        /// 显示
        /// </summary>
        public void Show()
        {
            try
            {
                //初始化控件
                this.InitMsgControl();
            }
            catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
        }
 
        #endregion
 
        #region ■ 初始化控件_________________________
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        private void InitMsgControl()
        {
            //添加界面
            var nowForm = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
            if (nowForm == null || (nowForm is ViewGroup) == false)
            {
                return;
            }
            //主控件
            var frameMain = new FrameLayout();
            frameMain.BackgroundColor = UserCenterColor.Current.DialogBackColor;
            ((ViewGroup)nowForm).AddChidren(frameMain);
 
            //白色背景框
            var frameBack = new FrameLayout();
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            frameBack.Gravity = Gravity.CenterHorizontal;
            frameBack.Radius = (uint)Application.GetRealHeight(17);
            if (msgType == DoorLockMsgType.CancelNomallyOpenModeWithLogic)
            {
                frameBack.Height = Application.GetRealHeight(409 + 127);
                frameBack.Width = Application.GetRealWidth(850);
                frameBack.Y = Application.GetRealHeight(648);
            }
            else
            {
                frameBack.Height = Application.GetRealHeight(478);
                frameBack.Width = Application.GetRealWidth(792);
                frameBack.Y = Application.GetRealHeight(706);
            }
            frameMain.AddChidren(frameBack);
 
            //标题
            var btnTitle = new NormalViewControl(frameBack.Width, Application.GetRealHeight(65), false);
            btnTitle.Y = Application.GetRealHeight(68);
            btnTitle.TextColor = 0xff333443;
            btnTitle.TextAlignment = TextAlignment.Center;
            btnTitle.TextSize = 16;
            frameBack.AddChidren(btnTitle);
            if (msgType == DoorLockMsgType.Confirm || msgType == DoorLockMsgType.DoorLockLogic || msgType == DoorLockMsgType.NomallyOpenMode || msgType == DoorLockMsgType.CancelNomallyOpenModeWithLogic)
            {
                btnTitle.TextID = R.MyInternationalizationString.NormalTip;
            }
            else if (msgType == DoorLockMsgType.InValid)
            {
                btnTitle.TextID = R.MyInternationalizationString.DoorLockInValidSetting;
            }
            else if (msgType == DoorLockMsgType.NomallyOpenMode)
            {
                btnTitle.TextID = R.MyInternationalizationString.CancelNomallyMode;
            }
 
            if (msgType == DoorLockMsgType.InValid)
            {
                InitInValidTimeDialog(frameBack);
            }
            else if (msgType == DoorLockMsgType.CancelNomallyOpenModeWithLogic)
            {
                CancelNormallyOpenModeWithLogicDialog(frameBack);
            }
            else
            {
                //消息
                var btnMsg = new NormalViewControl(frameBack.Width - Application.GetRealWidth(55 * 2), Application.GetRealHeight(180), false);
                btnMsg.Y = Application.GetRealHeight(141);
                btnMsg.IsMoreLines = true;
                btnMsg.TextAlignment = TextAlignment.Center;
                btnMsg.TextColor = UserCenterColor.Current.TextGrayColor1;
                btnMsg.Gravity = Gravity.CenterHorizontal;
                frameBack.AddChidren(btnMsg);
                btnMsg.Text = msgText;
            }
 
            if (msgType == DoorLockMsgType.Confirm || msgType == DoorLockMsgType.InValid || msgType == DoorLockMsgType.NomallyOpenMode)
            {
                //初始化确认类型的底部按钮
                this.InitBottomConfirmButton(frameMain, frameBack);
            }
            else if (msgType == DoorLockMsgType.DoorLockLogic || msgType == DoorLockMsgType.CancelNomallyOpenModeWithLogic)
            {
                //失效设置的底部按钮
                this.InitBottomLogicButton(frameMain, frameBack);
            }
        }
 
        /// <summary>
        /// 取消常开模式带有自动化的弹窗显示
        /// </summary>
        /// <param name="frameMain"></param>
        /// <param name="frameBack"></param>
        private void CancelNormallyOpenModeWithLogicDialog(FrameLayout frameBack)
        {
            //消息
            var btnMsg = new NormalViewControl(frameBack.Width - Application.GetRealWidth(55 * 2), Application.GetRealHeight(63), false);
            btnMsg.Y = Application.GetRealHeight(173);
            btnMsg.IsMoreLines = true;
            btnMsg.TextAlignment = TextAlignment.Center;
            btnMsg.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnMsg.Gravity = Gravity.CenterHorizontal;
            frameBack.AddChidren(btnMsg);
            btnMsg.Text = msgText;
 
            var alarmMsg = Language.StringByID(R.MyInternationalizationString.XingTip);//.Replace("{0}", "\r\n");
            var btnAlarmMsg = new NormalViewControl(frameBack.Width - Application.GetRealWidth(55 * 2), Application.GetRealHeight(104), false);
            btnAlarmMsg.Y = Application.GetRealHeight(259);
            btnAlarmMsg.IsMoreLines = true;
            btnAlarmMsg.TextAlignment = TextAlignment.Center;
            btnAlarmMsg.TextColor = ZigbeeColor.Current.XMAlarmText;
            btnAlarmMsg.Gravity = Gravity.CenterHorizontal;
            frameBack.AddChidren(btnAlarmMsg);
            btnAlarmMsg.Text = alarmMsg;
        }
 
        /// <summary>
        /// 失效时间设置的弹窗显示
        /// </summary>
        /// <param name="frameMain"></param>
        /// <param name="frameBack"></param>
        private void InitInValidTimeDialog(FrameLayout frameBack)
        {
            //消息 
            string[] msgArray = msgText.Split(new string[] { "{0}" }, StringSplitOptions.RemoveEmptyEntries);
            var btnMsg1 = new Button()
            {
                Width = Application.GetRealWidth(389),
                Height = Application.GetRealHeight(180),
                Y = Application.GetRealHeight(141),
                IsMoreLines = false,
                TextColor = UserCenterColor.Current.TextGrayColor1,
                TextAlignment = TextAlignment.CenterRight,
                Text = msgArray[0],
            };
            frameBack.AddChidren(btnMsg1);
 
            //失效时间设置
            var editTextFrameLayout = new FrameLayout()
            {
                Width = Application.GetRealWidth(132),
                Height = Application.GetRealHeight(81 + 40 * 2),
                Y = Application.GetRealHeight(184 - 40),
                X = btnMsg1.Right,
            };
            frameBack.AddChidren(editTextFrameLayout);
            editInvalidTime = new EditText()
            {
                Height = Application.GetRealHeight(81),
                X = Application.GetRealWidth(132),
                Y = Application.GetRealHeight(40),
                Gravity = Gravity.Center,
                Radius = (uint)Application.GetMinRealAverage(17),
                BackgroundColor = ZigbeeColor.Current.XMPEditTextBackground,
                TextColor = ZigbeeColor.Current.XMBlack,
                TextAlignment = TextAlignment.Center,
                TextSize = 14,
                Text = DoorLockCommonInfo.NormallyOpenModeInvalidTime.ToString(),
                PlaceholderTextColor = ZigbeeColor.Current.XMGray3,
            };
            editTextFrameLayout.AddChidren(editInvalidTime);
 
            var btnMsg2 = new Button()
            {
                Width = Application.GetRealWidth(271),
                Height = Application.GetRealHeight(180),
                Y = Application.GetRealHeight(141),
                X = editTextFrameLayout.Right,
                IsMoreLines = false,
                TextColor = UserCenterColor.Current.TextGrayColor1,
                TextAlignment = TextAlignment.CenterLeft,
                Text = msgArray[1]
            };
            frameBack.AddChidren(btnMsg2);
        }
 
        /// <summary>
        /// 失效设置的底部按钮
        /// </summary>
        /// <param name="frameMain"></param>
        /// <param name="frameBack"></param>
        private void InitBottomLogicButton(FrameLayout frameMain, FrameLayout frameBack)
        {
            //自动化按钮
            var btnDoorLockLogic = new BottomLeftClickButton(Application.GetRealWidth(396), Application.GetRealHeight(127));
            frameBack.AddChidren(btnDoorLockLogic);
            btnDoorLockLogic.InitControl(Language.StringByID(R.MyInternationalizationString.DoorLockLogic));
            btnDoorLockLogic.ButtonClickEvent += (sender, e) =>
            {
                //移除界面
                frameMain.RemoveFromParent();
                //回调函数
                this.LogicClickEvent?.Invoke();
                this.LogicClickEvent = null;
            };
 
            //失效设置按钮
            var btnInvalid = new BottomRightClickButton(frameBack.Width - btnDoorLockLogic.Width, btnDoorLockLogic.Height);
            frameBack.AddChidren(btnInvalid);
            btnInvalid.InitControl(buttonOkText);
            btnInvalid.ButtonClickEvent += (sender, e) =>
            {
                //移除界面
                frameMain.RemoveFromParent();
                //回调函数
                this.InvalidClickEvent?.Invoke();
                this.InvalidClickEvent = null;
            };
        }
 
        /// <summary>
        /// 初始化确认类型的底部按钮
        /// </summary>
        /// <param name="frameMain"></param>
        /// <param name="frameBack"></param>
        private void InitBottomConfirmButton(FrameLayout frameMain, FrameLayout frameBack)
        {
            //取消按钮
            var btnCancel = new BottomLeftClickButton(Application.GetRealWidth(396), Application.GetRealHeight(127));
            frameBack.AddChidren(btnCancel);
            var bottomLeftText = Language.StringByID(R.MyInternationalizationString.uCancel);
            if (msgType == DoorLockMsgType.NomallyOpenMode)
            {
                bottomLeftText = Language.StringByID(R.MyInternationalizationString.KeepNomallyMode);
            }
            btnCancel.InitControl(bottomLeftText);
            btnCancel.ButtonClickEvent += (sender, e) =>
            {
                //移除界面
                frameMain.RemoveFromParent();
                //回调函数
                this.CancelClickEvent?.Invoke();
                this.CancelClickEvent = null;
            };
 
            //确定按钮
            var btnConfirm = new BottomRightClickButton(frameBack.Width - btnCancel.Width, btnCancel.Height);
            frameBack.AddChidren(btnConfirm);
            btnConfirm.InitControl(buttonOkText);
            btnConfirm.ButtonClickEvent += (sender, e) =>
            {
                //移除界面
                frameMain.RemoveFromParent();
                if (msgType == DoorLockMsgType.InValid)
                {
                    if (InvalidTimeAction != null)
                    {
                        InvalidTimeAction(editInvalidTime.Text);
                    }
                }
                else
                {
                    //回调函数
                    this.ConfirmClickEvent?.Invoke();
                    this.ConfirmClickEvent = null;
                }
            };
        }
 
        #endregion
 
        /// <summary>
        /// 信息显示的类型
        /// </summary>
        public enum DoorLockMsgType
        {
            /// <summary>
            /// 确认类型
            /// </summary>
            Confirm = 1,
            /// <summary>
            /// 失效设置
            /// </summary>
            InValid = 2,
            /// <summary>
            /// 逻辑类型
            /// </summary>
            DoorLockLogic = 3,
            /// <summary>
            /// 常开模式
            /// </summary>
            NomallyOpenMode = 4,
            /// <summary>
            /// 取消带有逻辑的常开模式
            /// </summary>
            CancelNomallyOpenModeWithLogic = 5,
        }
    }
}