wxr
2021-07-01 43b0d5870d528f23ecd6aeceb6cfd4325188b46f
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
using Shared;
using HDL_ON.UI.CSS;
using System;
using System.Text;
 
namespace HDL_ON.Stan
{
    /// <summary>
    /// 显示一个信息框(请使用HdlMessageLogic调用)
    /// </summary>
    public class ShowMsgControl
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 点击确认的事件
        /// </summary>
        public Action ConfirmClickEvent = null;
        /// <summary>
        /// 点击取消的事件
        /// </summary>
        public Action CancelClickEvent = null;
        /// <summary>
        /// 信息类型
        /// </summary>
        private ShowMsgType msgType = ShowMsgType.Confirm;
        /// <summary>
        /// 消息
        /// </summary>
        private string msgText = string.Empty;
        /// <summary>
        /// 确认按钮的文本
        /// </summary>
        private string buttonOkText = null;
        /// <summary>
        /// 取消按钮的文本
        /// </summary>
        private string buttonCancelText = null;
        /// <summary>
        /// 提示控件
        /// </summary>
        private Tip myTip = null;
        /// <summary>
        /// 等待时间
        /// </summary>
        private int WaitTime = -1;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 显示一个需要确认的信息框
        /// </summary>
        /// <param name="i_msgType">信息类型</param>
        /// <param name="i_msg">信息</param>
        /// <param name="i_buttonOkText">确认按钮的文本</param>
        /// <param name="i_buttonCancelText">取消按钮的文本</param>
        /// <param name="i_waitTime">等待时间,单位为秒,设置确认按钮在多长时间后才能够点击</param>
        public ShowMsgControl(ShowMsgType i_msgType, string i_msg, string i_buttonOkText = null, string i_buttonCancelText = null, int i_waitTime = -1)
        {
            //确认按钮文本
            this.buttonOkText = i_buttonOkText == null ? Language.StringByID(StringId.Confirm) : i_buttonOkText;
            this.buttonCancelText = i_buttonCancelText == null ? Language.StringByID(StringId.Cancel) : i_buttonCancelText;
            this.msgType = i_msgType;
            this.msgText = i_msg.Replace("{0}", "\r\n");
            this.WaitTime = i_waitTime;
 
            if (i_msgType == ShowMsgType.Tip)
            {
                myTip = new Tip();
                myTip.Direction = AMPopTipDirection.None;
                myTip.CloseTime = 2;
                myTip.Text = i_msg;
            }
        }
 
        #endregion
 
        #region ■ 显示消息___________________________
 
        /// <summary>
        /// 显示
        /// </summary>
        public void Show()
        {
            try
            {
                if (myTip != null)
                {
                    myTip.Show(MainPage.BasePageView);
                    myTip = null;
                    return;
                }
                if (this.msgType == ShowMsgType.TipRemind || this.msgType == ShowMsgType.TipSuccess)
                {
                    //初始化控件
                    this.InitExTipControl();
                }
                else if (this.msgType == ShowMsgType.ConfirmSuccess || this.msgType == ShowMsgType.ConfirmFail)
                {
                    //初始化控件
                    this.InitConfirmSuccessTypeContorl();
                }
                else
                {
                    //初始化控件
                    this.InitMsgControl();
                }
            }
            catch { }
        }
 
        #endregion
 
        #region ■ 初始化控件_________________________
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        private void InitMsgControl()
        {
            var dialogForm = new Dialog();
            dialogForm.BackgroundColor = CSS_Color.DialogTransparentColor1;
            //主控件
            var frameMain = new NormalFrameLayout();
            dialogForm.AddChidren(frameMain);
            dialogForm.Show();
 
            //计算用
            var btnTemp = new ButtonCtrBase();
            btnTemp.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnTemp.Text = msgText.Replace("\r\n", string.Empty);
            //获取这个显示的内容的高度
            int rowCount = btnTemp.GetRealRowCountByText();
            //再看看它原来按换行符分割为几行
            var myArry = msgText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            //看看谁的行数多,就用谁的
            if (myArry.Length > rowCount)
            {
                rowCount = myArry.Length;
            }
            int contentHeight = rowCount * Application.GetRealHeight(18);
            if (rowCount <= 2)
            {
                //它有一个最小高度
                contentHeight = Application.GetRealHeight(51);
            }
 
            //这个区域的高度比例为:显示内容到上部的距离(50)+显示内容的高度+显示内容到底部的距离(70)
 
            //中间区域
            var frameCenter = new NormalFrameLayout();
            frameCenter.Gravity = Gravity.Center;
            frameCenter.Width = Application.GetRealWidth(270);
            frameCenter.Height = Application.GetRealHeight(50) + contentHeight + Application.GetRealHeight(70);
            frameCenter.BackgroundColor = CSS_Color.MainBackgroundColor;
            frameCenter.BorderColor = 0x00000000;
            frameCenter.BorderWidth = 0;
            frameCenter.Radius = (uint)Application.GetMinRealAverage(10);
            frameMain.AddChidren(frameCenter);
 
            //标题
            var btnTitle = new NormalViewControl(frameCenter.Width - HdlControlResourse.XXLeft * 2, Application.GetRealHeight(22), false);
            btnTitle.Y = Application.GetRealHeight(20);
            btnTitle.Gravity = Gravity.CenterHorizontal;
            btnTitle.TextColor = CSS_Color.MainColor;
            btnTitle.TextSize = CSS_FontSize.SubheadingFontSize;
            btnTitle.TextAlignment = TextAlignment.Center;
            btnTitle.IsBold = true;
            btnTitle.Text = Language.StringByID(StringId.Tip);
            frameCenter.AddChidren(btnTitle);
            //提示内容按钮
            var btnMsg = new NormalViewControl(Application.GetRealWidth(258), contentHeight, false);
            btnMsg.Y = btnTitle.Bottom + Application.GetRealHeight(8);
            btnMsg.Gravity = Gravity.CenterHorizontal;
            btnMsg.TextAlignment = TextAlignment.Center;
            btnMsg.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnMsg.Text = msgText;
            btnMsg.IsMoreLines = true;
            frameCenter.AddChidren(btnMsg);
 
            if (msgType == ShowMsgType.Confirm)
            {
                //初始化确认类型的底部按钮
                this.InitBottomConfirmButton(dialogForm, frameCenter);
            }
            else
            {
                //初始化普通类型的底部按钮
                this.InitBottomNormalButton(dialogForm, frameCenter);
            }
        }
 
        /// <summary>
        /// 初始化确认类型的底部按钮
        /// </summary>
        /// <param name="frameCenter"></param>
        private void InitBottomConfirmButton(Dialog dialogForm, NormalFrameLayout frameCenter)
        {
            //取消
            var btnCancel = new NormalViewControl(frameCenter.Width / 2, Application.GetRealHeight(43), false);
            btnCancel.Gravity = Gravity.BottomLeft;
            btnCancel.TextAlignment = TextAlignment.Center;
            btnCancel.TextSize = CSS_FontSize.SubheadingFontSize;
            btnCancel.Text = this.buttonCancelText;
            //btnCancel.SetCornerWithSameRadius((uint)Application.GetMinRealAverage(10), HDLUtils.RectCornerBottomLeft);
            frameCenter.AddChidren(btnCancel);
            btnCancel.ButtonClickEvent += (sender, e) =>
            {
                //关闭界面
                dialogForm.Close();
                //回调函数
                this.CancelClickEvent?.Invoke();
                this.ConfirmClickEvent = null;
                this.CancelClickEvent = null;
            };
            //线
            var btnLine = new NormalViewControl(frameCenter.Width / 2, HdlControlResourse.BottomLineHeight, false);
            btnLine.Y = btnCancel.Y - HdlControlResourse.BottomLineHeight;
            btnLine.BackgroundColor = CSS_Color.DividingLineColor;
            frameCenter.AddChidren(btnLine);
 
            //确认
            var btnConfirm = new NormalViewControl(frameCenter.Width - btnCancel.Width, Application.GetRealHeight(45), false);
            btnConfirm.X = btnCancel.Right;
            btnConfirm.Y = btnLine.Y;
            btnConfirm.TextAlignment = TextAlignment.Center;
            btnConfirm.TextSize = CSS_FontSize.SubheadingFontSize;
            btnConfirm.TextColor = CSS_Color.MainBackgroundColor;
            btnConfirm.BackgroundColor = CSS_Color.MainColor;
            btnConfirm.Text = this.buttonOkText;
            frameCenter.AddChidren(btnConfirm);
            btnConfirm.SetCornerWithSameRadius((uint)Application.GetMinRealAverage(10), HDLUtils.RectCornerBottomRight);
            btnConfirm.ButtonClickEvent += (sender, e) =>
            {
                //关闭界面
                dialogForm.Close();
                //回调函数
                this.ConfirmClickEvent?.Invoke();
                this.ConfirmClickEvent = null;
                this.CancelClickEvent = null;
            };
 
            //开启等待时间
            this.StartWaitTime(btnConfirm);
        }
 
        /// <summary>
        /// 初始化普通类型的底部按钮
        /// </summary>
        /// <param name="dialogForm"></param>
        /// <param name="frameCenter"></param>
        private void InitBottomNormalButton(Dialog dialogForm, NormalFrameLayout frameCenter)
        {
            //确认
            var btnConfirm = new NormalViewControl(frameCenter.Width, Application.GetRealHeight(45), false);
            btnConfirm.Gravity = Gravity.BottomCenter;
            btnConfirm.TextAlignment = TextAlignment.Center;
            btnConfirm.TextSize = CSS_FontSize.SubheadingFontSize;
            btnConfirm.TextColor = CSS_Color.MainBackgroundColor;
            btnConfirm.BackgroundColor = CSS_Color.MainColor;
            btnConfirm.Text = this.buttonOkText;
            frameCenter.AddChidren(btnConfirm);
            btnConfirm.SetCornerWithSameRadius((uint)Application.GetMinRealAverage(10), HDLUtils.RectCornerBottomLeft | HDLUtils.RectCornerBottomRight);
            btnConfirm.ButtonClickEvent += (sender, e) =>
            {
                //关闭界面
                dialogForm.Close();
                //回调函数
                this.ConfirmClickEvent?.Invoke();
                this.ConfirmClickEvent = null;
                this.CancelClickEvent = null;
            };
 
            //开启等待时间
            this.StartWaitTime(btnConfirm);
        }
 
        /// <summary>
        /// 初始化特殊的tip控件,仅支持 TipRemind 和 TipSuccess
        /// </summary>
        private void InitExTipControl()
        {
            //获取当前的界面
            var nowActionForm = MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1) as ViewGroup;
            if (nowActionForm == null)
            {
                return;
            }
            //主控件
            var frameMain = new NormalFrameLayout();
            frameMain.Height = nowActionForm.Height;
            frameMain.Width = nowActionForm.Width;
            nowActionForm.AddChidren(frameMain);
            frameMain.ButtonClickEvent += (sender, e) =>
            {
                frameMain.RemoveFromParent();
            };
 
            //计算用
            var btnTemp = new ButtonCtrBase();
            btnTemp.Text = msgText.Replace("\r\n", string.Empty);
            //获取这个显示的内容的高度(蓝湖的黑色背景的宽度为198,然后再减去余白)
            int rowCount = btnTemp.GetRealRowCountByText(Application.GetRealWidth(198) - HdlControlResourse.XXLeft * 2);
            //再看看它原来按换行符分割为几行
            var myArry = msgText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            //看看谁的行数多,就用谁的
            if (myArry.Length > rowCount)
            {
                rowCount = myArry.Length;
            }
            int contentHeight = rowCount * Application.GetRealHeight(20);
            //蓝湖黑色背景的Y轴为302
            var frameBlack = new FrameLayout();
            //如果是多行时,减掉一行的高度,则得出新增加的高度,然后再除以2,则为Y轴原始占比
            frameBlack.Y = Application.GetRealHeight(302) - (contentHeight - Application.GetRealHeight(20)) / 2;
            frameBlack.Width = Application.GetRealWidth(198);
            //实际计算出来的高度为 62+文本高度+16
            frameBlack.Height = Application.GetRealHeight(62) + contentHeight + Application.GetRealHeight(16);
            frameBlack.Radius = (uint)Application.GetRealWidth(12);
            frameBlack.Gravity = Gravity.CenterHorizontal;
            frameBlack.BackgroundColor = CSS_Color.DialogTransparentColor1;
            frameMain.AddChidren(frameBlack);
 
            //图标
            var btnIcon = new IconViewControl(42);
            btnIcon.Y = Application.GetRealHeight(10);
            btnIcon.Gravity = Gravity.CenterHorizontal;
            btnIcon.UnSelectedImagePath = this.msgType == ShowMsgType.TipSuccess ? "Public/MsgIcon/TipSuccessIcon.png" : "Public/MsgIcon/TipIconWhite.png";
            frameBlack.AddChidren(btnIcon);
 
            //显示文本
            var btnText = new NormalViewControl(frameBlack.Width - HdlControlResourse.XXLeft * 2, contentHeight, false);
            btnText.Y = btnIcon.Bottom + Application.GetRealHeight(10);
            btnText.TextAlignment = TextAlignment.Center;
            btnText.TextColor = CSS_Color.MainBackgroundColor;
            btnText.Gravity = Gravity.CenterHorizontal;
            btnText.IsMoreLines = true;
            btnText.Text = this.msgText;
            frameBlack.AddChidren(btnText);
 
            //开启关闭时间
            this.StartCloseTime(frameMain);
        }
 
        /// <summary>
        /// 初始化确认成功型控件,仅支持 ConfirmSuccess 和 ConfirmFail
        /// </summary>
        private void InitConfirmSuccessTypeContorl()
        {
            var dialogForm = new Dialog();
            dialogForm.BackgroundColor = CSS_Color.DialogTransparentColor1;
            //主控件
            var frameMain = new NormalFrameLayout();
            dialogForm.AddChidren(frameMain);
            dialogForm.Show();
 
            //白色背景
            var frameBack = new FrameLayout();
            frameBack.Y = Application.GetRealHeight(223);
            frameBack.Gravity = Gravity.CenterHorizontal;
            frameBack.Width = Application.GetRealWidth(288);
            frameBack.Height = Application.GetRealHeight(245);
            frameBack.BackgroundColor = CSS_Color.MainBackgroundColor;
            frameBack.Radius = (uint)Application.GetRealWidth(12);
            frameMain.AddChidren(frameBack);
 
            //大图标(蓝湖上,它高出白色区域70像素,因为高宽的比率是不一样的,所以需要计算一下比率)
            decimal decProportion = 70m / 160;
            var btnIcon = new IconViewControl(160);
            btnIcon.Y = frameBack.Y - (int)(decProportion * btnIcon.IconSize);
            btnIcon.Gravity = Gravity.CenterHorizontal;
            btnIcon.UnSelectedImagePath = this.msgType == ShowMsgType.ConfirmSuccess ? "Public/Dialog/DialogTipTitleIcon_1.png" : "Public/Dialog/DialogTipTitleIcon_2.png";
            frameMain.AddChidren(btnIcon);
 
            //消息
            var btnMsg = new NormalViewControl(frameMain.Width - HdlControlResourse.XXLeft * 2, Application.GetRealHeight(50), false);
            //取大图标的下部高度,然后再加间距10
            btnMsg.Y = btnIcon.Height - (frameBack.Y - btnIcon.Y) + Application.GetRealHeight(10);
            btnMsg.Gravity = Gravity.CenterHorizontal;
            btnMsg.TextAlignment = TextAlignment.TopCenter;
            btnMsg.IsMoreLines = true;
            btnMsg.TextSize = CSS_FontSize.SubheadingFontSize;
            btnMsg.TextColor = CSS_Color.MainColor;
            btnMsg.Text = this.msgText;
            frameBack.AddChidren(btnMsg);
 
            //确认按钮
            var btnConfirm = new BottomClickButton(220);
            btnConfirm.Text = this.buttonOkText;
            btnConfirm.Y = Application.GetRealHeight(169);
            frameBack.AddChidren(btnConfirm);
            btnConfirm.ButtonClickEvent += (sender, e) =>
            {
                //关闭界面
                dialogForm.Close();
                //回调函数
                this.ConfirmClickEvent?.Invoke();
                this.ConfirmClickEvent = null;
                this.CancelClickEvent = null;
            };
 
            //开启等待时间
            this.StartWaitTime(btnConfirm);
        }
 
        #endregion
 
        #region ■ 开启等待时间_______________________
 
        /// <summary>
        /// 开启等待时间
        /// </summary>
        /// <param name="btnConfirm">确认按钮</param>
        private void StartWaitTime(ButtonCtrBase btnConfirm)
        {
            if (this.WaitTime <= 0)
            {
                return;
            }
 
            btnConfirm.CanClick = false;
            HdlThreadLogic.Current.RunThread(() =>
            {
                //显示剩余等待时间
                while (btnConfirm.Parent != null && this.WaitTime >= 0)
                {
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        btnConfirm.Text = this.buttonOkText + "(" + this.WaitTime + ")";
 
                    }, ShowErrorMode.NO);
                    System.Threading.Thread.Sleep(1000);
                    this.WaitTime--;
                }
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //可以点击
                    btnConfirm.Text = this.buttonOkText;
                    btnConfirm.CanClick = true;
 
                }, ShowErrorMode.NO);
            });
        }
 
        /// <summary>
        /// 开启关闭时间
        /// </summary>
        /// <param name="frameMain">主界面</param>
        private void StartCloseTime(FrameLayout frameMain)
        {
            if (this.WaitTime <= 0)
            {
                return;
            }
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (frameMain.Parent != null && this.WaitTime >= 0)
                {
                    System.Threading.Thread.Sleep(1000);
                    this.WaitTime--;
                }
                HdlThreadLogic.Current.RunMain(() =>
                {
                    frameMain?.RemoveFromParent();
 
                }, ShowErrorMode.NO);
            });
        }
 
        #endregion
    }
}