黄学彪
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone
{
    /// <summary>
    /// <para>手势密码输入控件(自制的手势输入类型,请实现【FinishInputEvent】事件)</para>
    /// <para>标题控件的Y轴为0,也就是这个控件的上部没有空白区域</para>
    /// </summary>
    public class PswGestureInputControl : FrameLayout
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 密码输入完成的事件 value1:密码 value2:密码长度
        /// </summary>
        public Action<string, int> FinishInputEvent = null;
        /// <summary>
        /// 标题控件
        /// </summary>
        public NormalViewControl btnTitle = null;
        /// <summary>
        /// 错误信息提示控件
        /// </summary>
        public NormalViewControl btnError = null;
        /// <summary>
        /// 手势控件(有可能需要调整它的未知)
        /// </summary>
        public GestureLockView gestureControl = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// <para>手势密码输入控件(自制的手势输入类型,请实现【FinishInputEvent】事件)</para>
        /// <para>标题控件的Y轴为0,也就是这个控件的上部没有空白区域</para>
        /// </summary>
        /// <param name="i_title">初始标题文本信息</param>
        public PswGestureInputControl(string i_title)
        {
            //加间距
            this.Width = Application.GetRealWidth(965);
            this.Height = Application.GetRealHeight(1290);
 
            this.btnTitle = new NormalViewControl(Application.CurrentWidth, Application.GetRealWidth(75), false);
            btnTitle.Width = this.Width;
            btnTitle.TextAlignment = TextAlignment.Center;
            btnTitle.TextSize = 18;
            btnTitle.Text = i_title;
            btnTitle.IsBold = true;
        }
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        public void InitControl()
        {
            //标题
            this.AddChidren(btnTitle);
 
            //错误信息提示
            this.btnError = new NormalViewControl(this.Width, Application.GetRealHeight(60), false);
            btnError.Y = btnTitle.Bottom + Application.GetRealHeight(98);
            btnError.TextAlignment = TextAlignment.Center;
            btnError.TextColor = 0xfff75858;
            this.AddChidren(btnError);
 
            this.gestureControl = new GestureLockView();
            gestureControl.Gravity = Gravity.CenterHorizontal;
            gestureControl.Y = btnError.Bottom + Application.GetRealHeight(104);
            gestureControl.Width = Application.GetRealWidth(786);
            gestureControl.Height = Application.GetRealWidth(786);
            //默认和正确 时显示的颜色
            //gestureControl.LockViewCorrectColor = 0xfffc744b;
            //错误时 显示的颜色
            //gestureControl.LockViewErrorColor = 0xfffc744b;
            this.AddChidren(gestureControl);
 
            //滑动结束 回调密码结果和密码长度
            gestureControl.OnLockVerifyEvent += (selectNumStr, selectCount) =>
            {
                btnError.Text = string.Empty;
                HdlThreadLogic.Current.RunThread(() =>
                {
                    System.Threading.Thread.Sleep(1000);
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        this.FinishInputEvent?.Invoke(selectNumStr, selectCount);
                    });
                });
            };
        }
 
        #endregion
 
        #region ■ 重置控件___________________________
 
        /// <summary>
        /// 重置控件
        /// </summary>
        /// <param name="i_title">标题信息</param>
        /// <param name="clearError">是否清除错误信息</param>
        public void ResetControlInfo(string i_title, bool clearError = true)
        {
            //标题
            btnTitle.Text = i_title;
            if (clearError == true)
            {
                //错误信息
                btnError.Text = string.Empty;
            }
        }
 
        #endregion
 
        #region ■ 错误信息设置_______________________
 
        /// <summary>
        /// 显示错误的信息
        /// </summary>
        /// <param name="i_msg"></param>
        public void SetErrorMsg(string i_msg)
        {
            //自行验证密码,提示正确或者错误 false为显示红色错误, 自行选择调用时机
            gestureControl.showCorrectStatus(false);
            btnError.Text = i_msg;
        }
 
        #endregion
 
        #region ■ 添加关闭按钮_______________________
 
        /// <summary>
        /// 添加关闭按钮
        /// </summary>
        /// <returns></returns>
        public IconViewControl AddCloseButton()
        {
            //关闭按钮
            var btnClose = new IconViewControl(86);
            btnClose.X = this.Width - btnClose.IconSize - Application.GetRealHeight(46);
            btnClose.UnSelectedImagePath = "Item/CancelIcon.png";
            this.AddChidren(btnClose);
 
            return btnClose;
        }
 
        #endregion
 
        #region ■ 控件摧毁___________________________
 
        /// <summary>
        /// 控件摧毁
        /// </summary>
        public override void RemoveFromParent()
        {
            FinishInputEvent = null;
            base.RemoveFromParent();
        }
 
        #endregion
    }
}