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
using Shared;
using HDL_ON.UI.CSS;
using System;
using System.Text;
 
namespace HDL_ON.Stan
{
    /// <summary>
    /// 文本输入的弹窗界面(不用加入父控件)
    /// </summary>
    public class TextInputDialog
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 标题文本
        /// </summary>
        private string titleText = string.Empty;
        /// <summary>
        /// 初始值
        /// </summary>
        private string textValue = string.Empty;
        /// <summary>
        /// 当输入框为空白时的提示文本
        /// </summary>
        private string emptyMsg = string.Empty;
        /// <summary>
        /// 确认按钮的文本
        /// </summary>
        private string buttonOkText = string.Empty;
        /// <summary>
        /// 取消按钮的文本
        /// </summary>
        private string buttonCancelText = string.Empty;
        /// <summary>
        /// 是否是密码输入
        /// </summary>
        private bool isPassword = false;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 文本输入的弹窗界面(不用加入父控件)
        /// </summary>
        /// <param name="i_title">标题文本</param>
        /// <param name="i_text">初始值</param>
        /// <param name="i_emptyMsg">当输入框为空白时的提示文本</param>
        /// <param name="i_buttonOkText">确认按钮的文本</param>
        /// <param name="i_buttonCancelText">取消按钮的文本</param>
        /// <param name="i_isPassword">是否是密码输入</param>
        public TextInputDialog(string i_title, string i_text, string i_emptyMsg, string i_buttonOkText = null, string i_buttonCancelText = null, bool i_isPassword = false)
        {
            this.titleText = i_title;
            this.textValue = i_text;
            this.emptyMsg = i_emptyMsg;
 
            //确认按钮文本
            this.buttonOkText = i_buttonOkText == null ? Language.StringByID(StringId.Confirm) : i_buttonOkText;
            this.buttonCancelText = i_buttonCancelText == null ? Language.StringByID(StringId.Cancel) : i_buttonCancelText;
 
            this.isPassword = i_isPassword;
        }
 
        #endregion
 
        #region ■ 弹窗显示___________________________
 
        /// <summary>
        /// 弹窗显示
        /// </summary>
        /// <param name="finishEvent">回调函数,参数为输入框的值</param>
        public void Show(Action<string> finishEvent)
        {
            var dialogForm = new Dialog();
            dialogForm.BackgroundColor = CSS_Color.DialogTransparentColor1;
            //主控件
            var frameMain = new NormalFrameLayout();
            dialogForm.AddChidren(frameMain);
            dialogForm.Show();
 
            //中间区域
            var frameCenter = new NormalFrameLayout();
            frameCenter.Gravity = Gravity.Center;
            frameCenter.Width = Application.GetRealWidth(270);
            frameCenter.Height = Application.GetRealHeight(50);
            frameCenter.BackgroundColor = CSS_Color.MainBackgroundColor;
            frameCenter.Radius = (uint)Application.GetMinRealAverage(10);
            frameMain.AddChidren(frameCenter);
 
            //标题
            var btnTitle = new NormalViewControl(frameCenter.Width - HdlControlResourse.XXLeft * 2, Application.GetRealHeight(24), false);
            btnTitle.Y = Application.GetRealHeight(19);
            btnTitle.Gravity = Gravity.CenterHorizontal;
            btnTitle.TextColor = CSS_Color.MainColor;
            btnTitle.TextSize = CSS_FontSize.SubheadingFontSize;
            btnTitle.TextAlignment = TextAlignment.Center;
            btnTitle.IsBold = true;
            btnTitle.Text = this.titleText.Replace("{0}", "\r\n");
            btnTitle.Height = Application.GetRealHeight(24) * btnTitle.GetRealRowCountByText();
            btnTitle.IsMoreLines = true;
            frameCenter.AddChidren(btnTitle);
 
            //输入框的背景
            var frameInput = new FrameLayout();
            frameInput.Y = btnTitle.Bottom + Application.GetRealHeight(16);
            frameInput.Width = Application.GetRealWidth(222);
            frameInput.Height = Application.GetRealHeight(40);
            frameInput.Gravity = Gravity.CenterHorizontal;
            frameInput.Radius = (uint)Application.GetRealWidth(4);
            frameInput.BackgroundColor = CSS_Color.BackgroundColor;
            frameCenter.AddChidren(frameInput);
            //输入框
            var txtInput = new TextInputControl(174, 24, true);
            txtInput.X = Application.GetRealWidth(12);
            txtInput.Gravity = Gravity.CenterVertical;
            txtInput.TextColor = CSS_Color.FirstLevelTitleColor;
            txtInput.Text = this.textValue;
            frameInput.AddChidren(txtInput);
 
            //密码型
            if (this.isPassword == true)
            {
                txtInput.IsNumberKeyboardType = true;
                txtInput.SecureTextEntry = true;
                //密码可视图标
                var btnIcon = new IconViewControl(24);
                btnIcon.X = txtInput.Right + Application.GetRealWidth(8);
                btnIcon.Gravity = Gravity.CenterVertical;
                btnIcon.UnSelectedImagePath = "LoginIcon/HidePasswordIcon.png";
                btnIcon.SelectedImagePath = "LoginIcon/ShowPasswordIcon.png";
                frameInput.AddChidren(btnIcon);
                btnIcon.ButtonClickEvent += (sender, e) =>
                {
                    btnIcon.IsSelected = !btnIcon.IsSelected;
                    txtInput.SecureTextEntry = !txtInput.SecureTextEntry;
                };
            }
            else
            {
                //取消图标
                var btnIcon = new IconViewControl(24);
                btnIcon.X = txtInput.Right + Application.GetRealWidth(8);
                btnIcon.Gravity = Gravity.CenterVertical;
                btnIcon.UnSelectedImagePath = "LoginIcon/1.png";
                frameInput.AddChidren(btnIcon);
                btnIcon.ButtonClickEvent += (sender, e) =>
                {
                    txtInput.Text = string.Empty;
                };
            }
 
            //错误显示消息
            var btnErrorMsg = new NormalViewControl(frameInput.Width, Application.GetRealHeight(21), false);
            btnErrorMsg.Y = frameInput.Bottom;
            btnErrorMsg.Gravity = Gravity.CenterHorizontal;
            btnErrorMsg.TextColor = CSS_Color.WarningColor;
            btnErrorMsg.Text = this.emptyMsg.Replace("{0}", "\r\n");
            btnErrorMsg.IsMoreLines = true;
            btnErrorMsg.TextAlignment = TextAlignment.TopLeft;
            btnErrorMsg.Height = Application.GetRealHeight(21) * btnErrorMsg.GetRealRowCountByText();
            btnErrorMsg.Visible = false;
            frameCenter.AddChidren(btnErrorMsg);
 
            //底部按钮的高度
            int buttomButtonHeigth = Application.GetRealHeight(43);
            //调整白色桌布的高度和坐标
            frameCenter.Height = frameInput.Bottom + Application.GetRealHeight(31) + buttomButtonHeigth;
            //白色背景在蓝湖上的坐标为264,高度为172  然后让它按这个比例置于桌布
            frameCenter.Y = Application.GetRealHeight(264) - (frameCenter.Height - Application.GetRealHeight(172)) / 2;
 
            //取消
            var btnCancel = new NormalViewControl(frameCenter.Width / 2, buttomButtonHeigth, false);
            btnCancel.Gravity = Gravity.BottomLeft;
            btnCancel.TextAlignment = TextAlignment.Center;
            btnCancel.TextSize = CSS_FontSize.SubheadingFontSize;
            btnCancel.Text = this.buttonCancelText;
            frameCenter.AddChidren(btnCancel);
            btnCancel.ButtonClickEvent += (sender, e) =>
            {
                //关闭界面
                dialogForm.Close();
                finishEvent = 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, buttomButtonHeigth + HdlControlResourse.BottomLineHeight, 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) =>
            {
                string inputValue = txtInput.Text.Trim();
                if (inputValue == string.Empty && string.IsNullOrEmpty(this.emptyMsg) != true)
                {
                    //空白的时候,提示消息
                    btnErrorMsg.Visible = true;
 
                    //看看消息显示的控件有没有大于31,大于的话,则算出它增加的宽度(31是输入框到底部按钮Y轴的空白区域)
                    int value = 0;
                    if (btnErrorMsg.Height > Application.GetRealHeight(31))
                    {
                        //5是与底部按钮Y轴的间距
                        value = btnErrorMsg.Height - Application.GetRealHeight(31) + Application.GetRealHeight(5);
                    }
                    //调整白色桌布的高度和坐标
                    frameCenter.Height = frameInput.Bottom + Application.GetRealHeight(31) + buttomButtonHeigth + value;
                    //白色背景在蓝湖上的坐标为264,高度为172  然后让它按这个比例置于桌布
                    frameCenter.Y = Application.GetRealHeight(264) - (frameCenter.Height - Application.GetRealHeight(172)) / 2;
                    //两个按钮置底
                    btnCancel.Gravity = Gravity.BottomLeft;
                    btnLine.Y = btnCancel.Y - HdlControlResourse.BottomLineHeight;
                    btnConfirm.Y = btnLine.Y;
 
                    return;
                }
                //关闭界面
                dialogForm.Close();
                //回调函数
                finishEvent?.Invoke(txtInput.Text.Trim());
            };
        }
 
        #endregion
    }
}