using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace Shared.Phone.UserCenter
|
{
|
/// <summary>
|
/// <para>做成一个上部有标题,中间是一遍白色区域,左下角是【取消按钮】,右下角是【确认按钮】的弹窗控件</para>
|
/// <para>子控件添加完成后,请调用【InitLastControl】函数完成最后的初始化(仅限None模式)</para>
|
/// <para>确认按钮的单击事件为:ComfirmClickEvent</para>
|
/// </summary>
|
public class DialogInputFrameControl : FrameLayout
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 上部菜单标题的高度
|
/// </summary>
|
public int topMenuHeight = 190;
|
/// <summary>
|
/// 按钮的高度
|
/// </summary>
|
public int buttonHeight = 150;
|
/// <summary>
|
/// 输入框的宽度
|
/// </summary>
|
public int InputControlWidth = 800;
|
/// <summary>
|
/// 确认按钮事件
|
/// </summary>
|
public delegate void _ComfirmClickEvent();
|
/// <summary>
|
/// 画面关闭事件(由InputText获取输入值,None模式除外)
|
/// </summary>
|
public _ComfirmClickEvent ComfirmClickEvent;
|
/// <summary>
|
/// 输入框的文本信息
|
/// </summary>
|
public string InputText
|
{
|
get
|
{
|
if (this.txtInput == null)
|
{
|
return string.Empty;
|
}
|
return txtInput.Text.Trim();
|
}
|
set
|
{
|
if (this.txtInput != null)
|
{
|
this.txtInput.Text = value;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 中部桌布控件
|
/// </summary>
|
public FrameLayout frameMiddle = null;
|
/// <summary>
|
/// 最外层边框
|
/// </summary>
|
private FrameLayout frameLayout = null;
|
/// <summary>
|
/// 输入框控件
|
/// </summary>
|
private TextInputControl txtInput = null;
|
/// <summary>
|
/// 弹窗模式
|
/// </summary>
|
private DialogFrameMode dialogFrameMode = DialogFrameMode.None;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// <para>做成一个上部有标题,中间是一遍白色区域,左下角是【取消按钮】,右下角是【确认按钮】的弹窗控件</para>
|
/// <para>子控件添加完成后,请调用【FinishInitControl】函数完成最后的初始化(仅限None模式)</para>
|
/// <para>确认按钮的单击事件为:ComfirmClickEvent</para>
|
/// </summary>
|
/// <param name="mainFrame">
|
/// <para>载体父控件(会自动将该控件加入此载体父控件)</para>
|
/// <para>可以为空,当为空时,请在添加入载体父控件后,调用InitframeControl函数进行初始化</para>
|
/// </param>
|
/// <param name="i_dialogFrameMode">弹窗模式</param>
|
public DialogInputFrameControl(FrameLayout mainFrame, DialogFrameMode i_dialogFrameMode = DialogFrameMode.None)
|
{
|
this.dialogFrameMode = i_dialogFrameMode;
|
|
if (mainFrame != null)
|
{
|
mainFrame.AddChidren(this);
|
//初始化桌布控件
|
this.InitframeControl(this.dialogFrameMode);
|
}
|
}
|
|
/// <summary>
|
/// 初始化桌布控件
|
/// </summary>
|
/// <param name="i_dialogFrameMode">窗体模式</param>
|
public void InitframeControl(DialogFrameMode i_dialogFrameMode)
|
{
|
if (this.frameLayout != null)
|
{
|
this.frameLayout.RemoveAll();
|
}
|
else
|
{
|
this.BackgroundColor = UserCenterColor.Current.DialogBackColor;
|
}
|
|
//这是一个框
|
//this.frameLayout = new SpecialFrameLayout(960, 620, buttonHeight);
|
this.frameLayout = new FrameLayout();
|
frameLayout.Height = Application.GetRealHeight(620);
|
frameLayout.Width = Application.GetRealWidth(960);
|
frameLayout.Gravity = Gravity.Center;
|
frameLayout.Radius = 5;
|
frameLayout.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
|
base.AddChidren(frameLayout);
|
|
//标题信息
|
var btnTitle = new NormalViewControl(frameLayout.Width, Application.GetRealHeight(topMenuHeight), false);
|
btnTitle.TextColor = UserCenterColor.Current.TextColor1;
|
btnTitle.TextSize = 22;
|
btnTitle.TextAlignment = TextAlignment.BottomCenter;
|
frameLayout.AddChidren(btnTitle);
|
frameLayout.AddTag("btnTitle", btnTitle);
|
|
//中间空白区域
|
int midHeight = frameLayout.Height - Application.GetRealHeight(topMenuHeight + buttonHeight);
|
//this.frameMiddle = new SpecialFrameLayout(frameLayout.Width, midHeight, buttonHeight, false);
|
this.frameMiddle = new FrameLayout();
|
frameMiddle.Height = midHeight;
|
frameMiddle.Width = frameLayout.Width;
|
frameMiddle.Y = btnTitle.Bottom;
|
//frameMiddle.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
|
frameLayout.AddChidren(frameMiddle);
|
|
//取消(因为有可能要扩大中部高度,所以先声明)
|
var btnCancel = new NormalClickButton(frameLayout.Width / 2 - 1, Application.GetRealHeight(buttonHeight));
|
btnCancel.BackgroundColor = 0;
|
btnCancel.TextID = R.MyInternationalizationString.uCancel;
|
btnCancel.TextSize = 18;
|
frameLayout.AddTag("btnCancel", btnCancel);
|
|
//确认(因为有可能要扩大中部高度,所以先声明)
|
var btnOk = new NormalClickButton(frameLayout.Width / 2 - 1, Application.GetRealHeight(buttonHeight));
|
btnOk.BackgroundColor = 0;
|
btnOk.TextID = R.MyInternationalizationString.OkMsg;
|
btnOk.TextSize = 18;
|
btnOk.TextColor = UserCenterColor.Current.TextBlueColor;
|
frameLayout.AddTag("btnOk", btnOk);
|
|
if (dialogFrameMode == DialogFrameMode.None)
|
{
|
return;
|
}
|
|
//根据模式添加控件
|
string methodName = "SetControlBy" + dialogFrameMode.ToString();
|
this.GetType().InvokeMember(methodName, System.Reflection.BindingFlags.InvokeMethod, null, this, null);
|
|
//完成初始化控件(因为有可能要扩大中部高度,所以在最后进行最后底部控件的添加)
|
this.FinishInitControl();
|
}
|
|
#endregion
|
|
#region ■ 弹窗模式___________________________
|
|
/// <summary>
|
/// 只有一个输入框
|
/// </summary>
|
public void SetControlByOnlyInput()
|
{
|
//初始化边框
|
var frameText = this.InitInputTextLine();
|
this.frameMiddle.AddChidren(frameText);
|
//输入框
|
this.txtInput = this.InitInputControl(frameText);
|
//frameText.AddChidren(txtInput, HeightAutoMode.IncreaseAll);
|
frameText.AddChidren(txtInput);
|
}
|
|
/// <summary>
|
/// 只有一个输入框(密码模式)
|
/// </summary>
|
public void SetControlByOnlyPassword()
|
{
|
//初始化边框
|
var frameText = this.InitInputTextLine();
|
this.frameMiddle.AddChidren(frameText);
|
frameText.Radius = 8;
|
|
//输入框
|
this.txtInput = this.InitInputControl(frameText);
|
this.txtInput.SecureTextEntry = true;
|
//frameText.AddChidren(txtInput, HeightAutoMode.IncreaseAll);
|
frameText.AddChidren(txtInput);
|
}
|
|
/// <summary>
|
/// 只有一个输入框(密码模式),右边有一个可以看见密码的图标
|
/// </summary>
|
public void SetControlByPasswordView()
|
{
|
//初始化边框
|
var frameText = this.InitInputTextLine();
|
this.frameMiddle.AddChidren(frameText);
|
frameText.Radius = 8;
|
|
//输入框
|
this.txtInput = this.InitInputControl(frameText);
|
this.txtInput.SecureTextEntry = true;
|
//frameText.AddChidren(txtInput, HeightAutoMode.IncreaseAll);
|
frameText.AddChidren(txtInput);
|
this.txtInput.Gravity = Gravity.Frame;
|
|
//密码可视图标
|
this.InitPswViewControl();
|
}
|
|
#endregion
|
|
#region ■ 控件原型___________________________
|
|
/// <summary>
|
/// 初始化输入框的边框线
|
/// </summary>
|
public FrameLayout InitInputTextLine()
|
{
|
//var frameText = new SpecialFrameLayout(this.InputControlWidth, 110, 20);
|
var frameText = new FrameLayout();
|
frameText.Width = Application.GetRealWidth(this.InputControlWidth);
|
frameText.Height = Application.GetRealHeight(110);
|
frameText.Gravity = Gravity.Center;
|
frameText.BorderColor = UserCenterColor.Current.TextFrameColor;
|
frameText.BorderWidth = 1;
|
frameText.Radius = 8;
|
|
return frameText;
|
}
|
|
/// <summary>
|
/// 初始化输入框控件
|
/// </summary>
|
/// <param name="frameLine"></param>
|
public TextInputControl InitInputControl(FrameLayout frameLine)
|
{
|
var txtText = new TextInputControl(Application.CurrentWidth);
|
txtText.InitSize(frameLine.Width - Application.GetRealHeight(10), ControlCommonResourse.NormalControlHeight, false);
|
txtText.TextAlignment = TextAlignment.Center;
|
txtText.Gravity = Gravity.Center;
|
|
return txtText;
|
}
|
|
/// <summary>
|
/// 初始化密码可视图标
|
/// </summary>
|
/// <returns></returns>
|
private IconViewControl InitPswViewControl()
|
{
|
//调整输入框位置和大小
|
int inputXX = Application.GetRealWidth(20);
|
this.txtInput.X = inputXX;
|
this.txtInput.Width = Application.GetRealWidth(this.InputControlWidth - 20 - 20 - 72);
|
|
var btnPswView = new IconViewControl(72);
|
btnPswView.X = this.txtInput.Right;
|
btnPswView.UnSelectedImagePath = "Account/HidenPWD.png";
|
btnPswView.SelectedImagePath = "Account/UnHidenPWD.png";
|
btnPswView.Gravity = Gravity.CenterVertical;
|
frameLayout.AddChidren(btnPswView);
|
btnPswView.MouseUpEventHandler += (sender, e) =>
|
{
|
btnPswView.IsSelected = !btnPswView.IsSelected;
|
this.txtInput.SecureTextEntry = !this.txtInput.SecureTextEntry;
|
};
|
return btnPswView;
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
/// <summary>
|
/// 完成初始化控件
|
/// </summary>
|
public void FinishInitControl()
|
{
|
//取消
|
var btnCancel = (NormalClickButton)frameLayout.GetTagByKey("btnCancel");
|
btnCancel.Gravity = Gravity.BottomLeft;
|
frameLayout.AddChidren(btnCancel);
|
btnCancel.MouseUpEventHandler += (sender, e) =>
|
{
|
this.RemoveFromParent();
|
};
|
|
//确认
|
var btnOk = (NormalClickButton)frameLayout.GetTagByKey("btnOk");
|
btnOk.Gravity = Gravity.BottomRight;
|
frameLayout.AddChidren(btnOk);
|
btnOk.MouseUpEventHandler += (sender, e) =>
|
{
|
if (this.ComfirmClickEvent == null)
|
{
|
this.RemoveFromParent();
|
return;
|
}
|
this.ComfirmClickEvent();
|
};
|
|
//灰线
|
var btnLine1 = new NormalViewControl(1, Application.GetRealHeight(buttonHeight), false);
|
btnLine1.X = btnCancel.Right;
|
btnLine1.Y = btnCancel.Y;
|
btnLine1.BackgroundColor = UserCenterColor.Current.Line;
|
frameLayout.AddChidren(btnLine1);
|
|
//灰线
|
var btnLine2 = new NormalViewControl(frameLayout.Width, 1, false);
|
btnLine2.Y = btnOk.Y - 1;
|
btnLine2.BackgroundColor = UserCenterColor.Current.Line;
|
frameLayout.AddChidren(btnLine2);
|
}
|
|
/// <summary>
|
/// 添加子控件
|
/// </summary>
|
/// <param name="view"></param>
|
/// <param name="heightAutoMode">高度变更模式</param>
|
public void AddChidren(View view, HeightAutoMode heightAutoMode = HeightAutoMode.None)
|
{
|
//this.frameMiddle.AddChidren(view, heightAutoMode);
|
this.frameMiddle.AddChidren(view);
|
}
|
|
/// <summary>
|
/// 画面关闭
|
/// </summary>
|
public void CloseDialog()
|
{
|
this.RemoveFromParent();
|
}
|
|
#endregion
|
|
#region ■ 设置信息___________________________
|
|
/// <summary>
|
/// 设置标题信息
|
/// </summary>
|
/// <param name="txtValue"></param>
|
public void SetTitleText(string txtValue)
|
{
|
var btnTitle = (NormalViewControl)frameLayout.GetTagByKey("btnTitle");
|
btnTitle.Text = txtValue;
|
}
|
/// <summary>
|
/// 设置取消按钮的文本信息
|
/// </summary>
|
/// <param name="txtValue"></param>
|
public void SetCancelButtonText(string txtValue)
|
{
|
var btnCancel = (NormalClickButton)frameLayout.GetTagByKey("btnCancel");
|
btnCancel.Text = txtValue;
|
}
|
|
/// <summary>
|
/// 设置确定按钮的文本信息
|
/// </summary>
|
/// <param name="txtValue"></param>
|
public void SetOkButtonText(string txtValue)
|
{
|
var btnOk = (NormalClickButton)frameLayout.GetTagByKey("btnOk");
|
btnOk.Text = txtValue;
|
}
|
|
/// <summary>
|
/// 设置输入框灰色字体说明
|
/// </summary>
|
/// <param name="txtValue"></param>
|
public void SetTipText(string txtValue)
|
{
|
if (this.txtInput != null)
|
{
|
this.txtInput.PlaceholderText = txtValue;
|
}
|
}
|
|
#endregion
|
}
|
}
|