using HDL_ON.UI.CSS;
using Shared;
using System;
using System.Collections.Generic;
using System.Text;
namespace HDL_ON.Stan
{
///
/// App数字密码验证界面
///
public class AppNumPasswordSecurityForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// Action事件
/// 1:密码输入结束,这个时候,第二个参数为输入的密码
/// 2:点击了底部的消息
///
public Action ActionEvent = null;
///
/// 图标控件集合
///
private List listIconContr = new List();
///
/// 消息控件
///
private NormalViewControl btnErrorMsg = null;
///
/// 一个高度为0的输入框
///
private EditText txtPassword = null;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 是否添加头部Frame
/// 标题信息
/// 底部显示的信息行
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);
}
///
/// 初始化中部信息
///
/// 标题信息
/// 底部显示的信息行
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); };
}
///
/// 初始化图标控件
///
///
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 ■ 界面关闭___________________________
///
/// 界面关闭
///
public override void CloseFormBefore()
{
base.CloseFormBefore();
this.ActionEvent = null;
}
#endregion
#region ■ 一般方法___________________________
///
/// 显示错误消息
///
/// 需要显示的错误消息
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
}
}