tzy
2021-05-25 65bcedda4d8e3ff6500dbf59a4e607d96e469375
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
using HDL_ON.UI.CSS;
using Shared;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON.Stan
{
    /// <summary>
    /// App数字密码验证界面
    /// </summary>
    public class AppNumPasswordSecurityForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// <para>Action事件</para>   
        /// <para>1:密码输入结束,这个时候,第二个参数为输入的密码</para>
        /// <para>2:点击了底部的消息</para>
        /// </summary>
        public Action<int, string> ActionEvent = null;
        /// <summary>
        /// 图标控件集合
        /// </summary>
        private List<IconViewControl> listIconContr = new List<IconViewControl>();
        /// <summary>
        /// 消息控件
        /// </summary>
        private NormalViewControl btnErrorMsg = null;
        /// <summary>
        /// 一个高度为0的输入框
        /// </summary>
        private EditText txtPassword = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="addTopFrame">是否添加头部Frame</param>
        /// <param name="i_title">标题信息</param>
        /// <param name="i_bottomMsg">底部显示的信息行</param>
        public void ShowForm(bool addTopFrame, string i_title, string i_bottomMsg)
        {
            //不允许左滑
            this.ScrollLeftEnabled = false;
 
            if (addTopFrame == false)
            {
                //清空头部全部控件
                topFrameLayout.RemoveAll();
                //然后让背景色一体化
                topFrameLayout.BackgroundColor = bodyFrameLayout.BackgroundColor;
                topMenuFrameLayout.BackgroundColor = bodyFrameLayout.BackgroundColor;
            }
            else
            {
                //验证数字密码
                base.SetTitleText(Language.StringByID(StringId.VerifyDigitalPassword));
            }
 
            //初始化中部信息
            this.InitMiddleFrame(i_title, i_bottomMsg);
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        /// <param name="i_title">标题信息</param>
        /// <param name="i_bottomMsg">底部显示的信息行</param>
        private void InitMiddleFrame(string i_title, string i_bottomMsg)
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //标题
            var btnTitle = new NormalViewControl(bodyFrameLayout.Width - HdlControlResourse.XXLeft * 2, Application.GetRealHeight(42), false);
            btnTitle.Y = Application.GetRealHeight(228) - topFrameLayout.Bottom;
            btnTitle.Gravity = Gravity.CenterHorizontal;
            btnTitle.TextAlignment = TextAlignment.Center;
            btnTitle.TextColor = CSS_Color.FirstLevelTitleColor;
            btnTitle.TextSize = CSS_FontSize.SubheadingFontSize;
            btnTitle.Text = i_title;
            bodyFrameLayout.AddChidren(btnTitle);
 
            //第一个圆圈
            var btnIcon1 = this.InitIconControl();
            btnIcon1.X = Application.GetRealWidth(132);
            btnIcon1.Y = btnTitle.Bottom + Application.GetRealWidth(10);
 
            //第二个圆圈
            var btnIcon2 = this.InitIconControl();
            btnIcon2.X = btnIcon1.Right + Application.GetRealWidth(16);
            btnIcon2.Y = btnIcon1.Y;
 
            //第三个圆圈
            var btnIcon3 = this.InitIconControl();
            btnIcon3.X = btnIcon2.Right + Application.GetRealWidth(16);
            btnIcon3.Y = btnIcon1.Y;
 
            //第四个圆圈
            var btnIcon4 = this.InitIconControl();
            btnIcon4.X = btnIcon3.Right + Application.GetRealWidth(16);
            btnIcon4.Y = btnIcon1.Y;
 
            //错误消息
            this.btnErrorMsg = new NormalViewControl(bodyFrameLayout.Width - HdlControlResourse.XXLeft * 2, Application.GetRealHeight(24), false);
            btnErrorMsg.Y = btnIcon1.Bottom + Application.GetRealHeight(4);
            btnErrorMsg.Gravity = Gravity.CenterHorizontal;
            btnErrorMsg.TextColor = CSS_Color.WarningColor;
            btnErrorMsg.TextAlignment = TextAlignment.Center;
            btnErrorMsg.IsMoreLines = true;
            bodyFrameLayout.AddChidren(btnErrorMsg);
 
            //底部消息
            if (string.IsNullOrEmpty(i_bottomMsg) == false)
            {
                var btnBottomTip = new NormalViewControl(bodyFrameLayout.Width - HdlControlResourse.XXLeft * 2, 20, false);
                btnBottomTip.Y = Application.GetRealHeight(517) - topFrameLayout.Bottom;
                btnBottomTip.Gravity = Gravity.CenterHorizontal;
                btnBottomTip.TextAlignment = TextAlignment.TopCenter;
                btnBottomTip.TextColor = CSS_Color.MainColor;
                btnBottomTip.Text = i_bottomMsg;
                btnBottomTip.Height = btnBottomTip.GetRealRowCountByText() * Application.GetRealHeight(24);
                btnBottomTip.IsMoreLines = true;
                bodyFrameLayout.AddChidren(btnBottomTip);
                btnBottomTip.ButtonClickEvent += (sender, e) =>
                {
                    this.ActionEvent?.Invoke(2, null);
                };
            }
 
            //密码输入框
            this.txtPassword = new EditText();
            txtPassword.IsNumberKeyboardType = true;
            txtPassword.Height = 1;
            bodyFrameLayout.AddChidren(txtPassword);
            txtPassword.Foucs = true;
            txtPassword.TextChangeEventHandler = (sender, e) =>
            {
                string passwrod = txtPassword.Text.Trim();
                btnErrorMsg.Text = string.Empty;
                for (int i = 0; i < 4; i++)
                {
                    if (i < passwrod.Length)
                    { 
                        //实心图标
                        this.listIconContr[i].IsSelected = true;
                    }
                    else 
                    { 
                        //空心图标
                        this.listIconContr[i].IsSelected = false; 
                    }
                }
                if (passwrod.Length == 4)
                {
                    //关闭输入法
                    Application.HideSoftInput();
 
                    this.ActionEvent?.Invoke(1, passwrod);
                }
            };
 
            bodyFrameLayout.ButtonClickEvent += (sedner, e) =>
            {
                txtPassword.Foucs = true;
            };
            btnIcon1.ButtonClickEvent += (sender, e) => { bodyFrameLayout.ButtonClickEvent(null, null); };
            btnIcon2.ButtonClickEvent += (sender, e) => { bodyFrameLayout.ButtonClickEvent(null, null); };
            btnIcon3.ButtonClickEvent += (sender, e) => { bodyFrameLayout.ButtonClickEvent(null, null); };
            btnIcon4.ButtonClickEvent += (sender, e) => { bodyFrameLayout.ButtonClickEvent(null, null); };
        }
 
        /// <summary>
        /// 初始化图标控件
        /// </summary>
        /// <returns></returns>
        private IconViewControl InitIconControl()
        {
            var btnIcon1 = new IconViewControl(16);
            btnIcon1.BorderColor = CSS_Color.FirstLevelTitleColor;
            btnIcon1.BorderWidth = (uint)Application.GetRealWidth(1);
            btnIcon1.Radius = (uint)Application.GetRealWidth(8);
            btnIcon1.BackgroundColor = CSS_Color.MainBackgroundColor;
            btnIcon1.SelectedBackgroundColor = CSS_Color.FirstLevelTitleColor;
            bodyFrameLayout.AddChidren(btnIcon1);
 
            //加入缓存
            this.listIconContr.Add(btnIcon1);
 
            return btnIcon1;
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            base.CloseFormBefore();
 
            this.ActionEvent = null;
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 显示错误消息
        /// </summary>
        /// <param name="i_errorMsg">需要显示的错误消息</param>
        public void ShowErrorMsg(string i_errorMsg)
        {
            this.txtPassword.Text = string.Empty;
            btnErrorMsg.Text = i_errorMsg;
            btnErrorMsg.Height = btnErrorMsg.GetRealRowCountByText() * Application.GetRealHeight(24);
            //全部弄成空心图标
            for (int i = 0; i < this.listIconContr.Count; i++)
            {
                this.listIconContr[i].IsSelected = false;
            }
        }
 
        #endregion
    }
}