using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace Shared.Phone
|
{
|
/// <summary>
|
/// 数字按键密码输入控件(自制的手动按键输入类型,请实现【ActionPswFinish】事件)
|
/// </summary>
|
public class PswNumberInputControl : FrameLayoutBase
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 密码输入完成的事件
|
/// </summary>
|
public Action<string> FinishInputEvent = null;
|
/// <summary>
|
/// 密码长度
|
/// </summary>
|
private int passwordLength = 0;
|
/// <summary>
|
/// 数字按键的大小
|
/// </summary>
|
private int NumberSize = 196;
|
/// <summary>
|
/// 数字按键左右的间距
|
/// </summary>
|
private int NumberLeftRightSpace = 101;
|
/// <summary>
|
/// 数字按键上下的间距
|
/// </summary>
|
private int NumberTopButtomSpace = 63;
|
/// <summary>
|
/// 输入的密码
|
/// </summary>
|
private string inputPassword = string.Empty;
|
/// <summary>
|
/// 标题控件
|
/// </summary>
|
public NormalViewControl btnTitle = null;
|
/// <summary>
|
/// 错误信息提示控件
|
/// </summary>
|
public NormalViewControl btnError = null;
|
/// <summary>
|
/// 显示密码黑点的Frame(有可能需要调整它的位置)
|
/// </summary>
|
public FrameLayout framePswIcon = null;
|
/// <summary>
|
/// 数字表盘的Frame(有可能需要调整它的位置)
|
/// </summary>
|
public FrameLayout frameNumberIcon = null;
|
/// <summary>
|
/// 数字表盘按键的背景色
|
/// </summary>
|
public uint NumberIconBackColor = 0xfff5f6fa;
|
/// <summary>
|
/// 删除控件
|
/// </summary>
|
private NormalViewControl btnDelete = null;
|
/// <summary>
|
/// 密码图标控件集合
|
/// </summary>
|
private List<NormalViewControl> listPswIcon = new List<NormalViewControl>();
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// <para>密码输入控件(自制的手动按键输入类型,请实现【FinishInputEvent】事件)</para>
|
/// <para>宽度为:数字键盘的宽度+左右各40间距</para>
|
/// <para>宽度为:【标题的顶部】到【按键0】底部的高度</para>
|
/// </summary>
|
/// <param name="i_title">初始标题文本信息</param>
|
/// <param name="i_passwordLength">密码长度,默认4位</param>
|
public PswNumberInputControl(string i_title, int i_passwordLength = 4)
|
{
|
this.passwordLength = i_passwordLength;
|
//加间距
|
this.Width = this.GetPictrueRealSize(NumberSize * 3 + NumberLeftRightSpace * 2 + 80);
|
this.Height = this.GetPictrueRealSize(NumberSize * 4 + NumberTopButtomSpace * 3) + Application.GetRealHeight(368);
|
this.btnTitle = new NormalViewControl(Application.CurrentWidth, Application.GetRealWidth(75), false);
|
btnTitle.Text = i_title;
|
btnTitle.IsBold = true;
|
}
|
|
/// <summary>
|
/// 初始化控件
|
/// </summary>
|
public void InitControl()
|
{
|
//标题
|
btnTitle.Width = this.Width;
|
btnTitle.TextAlignment = TextAlignment.Center;
|
btnTitle.TextSize = 18;
|
this.AddChidren(btnTitle);
|
|
//初始化密码图标
|
this.InitPswIconControl();
|
|
//初始化数字表盘
|
this.InitNumberTableControl();
|
|
//错误信息提示
|
this.btnError = new NormalViewControl(this.Width, Application.GetRealHeight(60), false);
|
btnError.Y = Application.GetRealHeight(222);
|
btnError.TextAlignment = TextAlignment.Center;
|
btnError.TextColor = 0xfff75858;
|
this.AddChidren(btnError);
|
|
//删除控件
|
this.btnDelete = new NormalViewControl(200, 60, true);
|
btnDelete.X = this.Width - Application.GetRealWidth(200) - this.GetPictrueRealSize(40);
|
btnDelete.Y = this.Height - Application.GetRealHeight(60);
|
btnDelete.TextColor = UserCenterColor.Current.TextGrayColor3;
|
btnDelete.TextAlignment = TextAlignment.Center;
|
btnDelete.TextID = R.MyInternationalizationString.uDelete;
|
this.AddChidren(btnDelete);
|
btnDelete.ButtonClickEvent += (sender, e) =>
|
{
|
if (inputPassword == string.Empty)
|
{
|
return;
|
}
|
//取消一位密码
|
inputPassword = inputPassword.Substring(0, inputPassword.Length - 1);
|
listPswIcon[inputPassword.Length].BackgroundColor = UserCenterColor.Current.Transparent;
|
if (btnError.Visible == true)
|
{
|
btnError.Visible = false;
|
}
|
};
|
}
|
|
#endregion
|
|
#region ■ 初始化密码图标_____________________
|
|
/// <summary>
|
/// 初始化密码图标
|
/// </summary>
|
private void InitPswIconControl()
|
{
|
//图标大小
|
int iconSize = this.GetPictrueRealSize(36);
|
//图标间的间隔
|
int space = this.GetPictrueRealSize(100);
|
//计算密码个数是否越界
|
int value = Application.CurrentWidth - iconSize * passwordLength;
|
if (passwordLength > 1)
|
{
|
value = value / (passwordLength - 1);
|
}
|
if (value < space)
|
{
|
//越界时,调整间距
|
space = value;
|
}
|
|
this.framePswIcon = new FrameLayout();
|
framePswIcon.Height = iconSize;
|
framePswIcon.Width = iconSize * passwordLength + space * (passwordLength - 1);
|
framePswIcon.Y = Application.GetRealHeight(149);
|
framePswIcon.Gravity = Gravity.CenterHorizontal;
|
this.AddChidren(framePswIcon);
|
|
for (int i = 0; i < passwordLength; i++)
|
{
|
var btnIcon = new NormalViewControl(iconSize, iconSize, false);
|
btnIcon.BorderWidth = 1;
|
btnIcon.BorderColor = 0xff999999;
|
btnIcon.Radius = (uint)iconSize / 2;
|
if (listPswIcon.Count > 0)
|
{
|
btnIcon.X = listPswIcon[listPswIcon.Count - 1].Right + space;
|
}
|
framePswIcon.AddChidren(btnIcon);
|
listPswIcon.Add(btnIcon);
|
}
|
}
|
|
#endregion
|
|
#region ■ 初始化数字表盘_____________________
|
|
/// <summary>
|
/// 初始化数字表盘
|
/// </summary>
|
private void InitNumberTableControl()
|
{
|
this.frameNumberIcon = new FrameLayout();
|
frameNumberIcon.Y = Application.GetRealHeight(368);
|
frameNumberIcon.Width = this.Width;
|
frameNumberIcon.Gravity = Gravity.CenterHorizontal;
|
frameNumberIcon.Height = this.GetPictrueRealSize(NumberSize * 4 + NumberTopButtomSpace * 3);
|
this.AddChidren(frameNumberIcon);
|
|
//前一个控件的右坐标
|
int btnTempRight = 0;
|
//间距
|
int space = this.GetPictrueRealSize(NumberLeftRightSpace);
|
//1到9的数字盘
|
for (int i = 1; i <= 9; i++)
|
{
|
var btnNum = this.InitNumberControl();
|
btnNum.Text = i.ToString();
|
if (btnTempRight != 0)
|
{
|
btnNum.X = btnTempRight + space;
|
}
|
|
frameNumberIcon.AddChidren(btnNum);
|
btnNum.Y = (i - 1) / 3 * (btnNum.Height + this.GetPictrueRealSize(NumberTopButtomSpace));
|
btnNum.ButtonClickEvent += (sender, e) =>
|
{
|
//点击数字按键
|
this.btnNumClickEvent(sender.Text);
|
};
|
btnTempRight = btnNum.Right;
|
if (i % 3 == 0)
|
{
|
//清空
|
btnTempRight = 0;
|
}
|
}
|
|
//0的数字盘
|
var btnNum0 = this.InitNumberControl();
|
btnNum0.X = this.GetPictrueRealSize(40) + frameNumberIcon.GetChildren(0).Height + space;
|
btnNum0.Text = "0";
|
|
frameNumberIcon.AddChidren(btnNum0);
|
btnNum0.Y = 3 * (frameNumberIcon.GetChildren(0).Height + this.GetPictrueRealSize(NumberTopButtomSpace));
|
btnNum0.ButtonClickEvent += (sender, e) =>
|
{
|
//点击数字按键
|
this.btnNumClickEvent("0");
|
};
|
}
|
|
/// <summary>
|
/// 初始化数字控件
|
/// </summary>
|
/// <returns></returns>
|
private NormalClickButton InitNumberControl()
|
{
|
int iconSize = this.GetPictrueRealSize(NumberSize);
|
var btnNum = new NormalClickButton(iconSize, iconSize, false);
|
btnNum.X = this.GetPictrueRealSize(40);
|
btnNum.BackgroundColor = this.NumberIconBackColor;
|
btnNum.clickStatuColor = 0x7e656565;
|
btnNum.Radius = (uint)iconSize / 2;
|
btnNum.TextColor = UserCenterColor.Current.TextGrayColor3;
|
btnNum.TextSize = 32;
|
|
return btnNum;
|
}
|
|
/// <summary>
|
/// 点击数字按键
|
/// </summary>
|
/// <param name="strNum">数字值</param>
|
private void btnNumClickEvent(string strNum)
|
{
|
if (inputPassword.Length >= listPswIcon.Count)
|
{
|
return;
|
}
|
if (btnError.Visible == true)
|
{
|
btnError.Visible = false;
|
}
|
//特效改变
|
listPswIcon[inputPassword.Length].BackgroundColor = 0xff333333;
|
inputPassword += strNum;
|
//输入结束
|
if (FinishInputEvent != null && inputPassword.Length == passwordLength)
|
{
|
//调用回调函数
|
FinishInputEvent(inputPassword);
|
}
|
}
|
|
#endregion
|
|
#region ■ 重置控件___________________________
|
|
/// <summary>
|
/// 重置控件
|
/// </summary>
|
/// <param name="i_title">标题信息</param>
|
public void ResetControlInfo(string i_title)
|
{
|
//标题
|
btnTitle.Text = i_title;
|
//记录的密码
|
inputPassword = string.Empty;
|
//密码图标
|
for (int i = 0; i < listPswIcon.Count; i++)
|
{
|
listPswIcon[i].BackgroundColor = UserCenterColor.Current.Transparent;
|
}
|
//错误信息
|
btnError.Text = string.Empty;
|
}
|
|
#endregion
|
|
#region ■ 错误信息设置_______________________
|
|
/// <summary>
|
/// 显示错误的信息
|
/// </summary>
|
/// <param name="i_msg"></param>
|
public void SetErrorMsg(string i_msg)
|
{
|
if (btnError.Visible == false)
|
{
|
btnError.Visible = true;
|
}
|
btnError.Text = i_msg;
|
|
//记录的密码
|
inputPassword = string.Empty;
|
//密码图标
|
for (int i = 0; i < listPswIcon.Count; i++)
|
{
|
listPswIcon[i].BackgroundColor = UserCenterColor.Current.Transparent;
|
}
|
}
|
|
#endregion
|
|
#region ■ 变更删除按钮位置___________________
|
|
/// <summary>
|
/// 变更删除按钮位置,它最初的默认位置是在最底部(父控件的高度会自动调整)
|
/// </summary>
|
/// <param name="XX">X轴(不变更请设置为-1)</param>
|
/// <param name="YY">Y轴(不变更请设置为-1)</param>
|
/// <param name="real">是否计算真实值</param>
|
public void ChangedDeleteButtonPoint(int XX, int YY, bool real = true)
|
{
|
if (real == true)
|
{
|
if (XX != -1)
|
{
|
XX = Application.GetRealWidth(XX);
|
}
|
if (YY != -1)
|
{
|
YY = Application.GetRealHeight(YY);
|
}
|
}
|
if (XX != -1)
|
{
|
this.btnDelete.X = XX;
|
}
|
if (YY != -1)
|
{
|
this.btnDelete.Y = YY;
|
}
|
|
//自动调整高度
|
int minHeight = this.GetPictrueRealSize(NumberSize * 4 + NumberTopButtomSpace * 3) + Application.GetRealHeight(368);
|
int realHeight = this.btnDelete.Bottom;
|
if (realHeight < minHeight)
|
{
|
realHeight = minHeight;
|
}
|
this.Height = realHeight;
|
}
|
|
#endregion
|
|
#region ■ 添加关闭按钮_______________________
|
|
/// <summary>
|
/// 添加关闭按钮
|
/// </summary>
|
/// <returns></returns>
|
public IconViewControl AddCloseButton()
|
{
|
//关闭按钮
|
var btnClose = new IconViewControl(86);
|
btnClose.Y = Application.GetRealHeight(-12);
|
btnClose.X = this.Width - btnClose.IconSize;
|
btnClose.UnSelectedImagePath = "Item/CancelIcon.png";
|
this.AddChidren(btnClose);
|
|
return btnClose;
|
}
|
|
#endregion
|
|
#region ■ 控件摧毁___________________________
|
|
/// <summary>
|
/// 控件摧毁
|
/// </summary>
|
public override void RemoveFromParent()
|
{
|
FinishInputEvent = null;
|
base.RemoveFromParent();
|
}
|
|
#endregion
|
}
|
}
|