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 topTitleHeight = 63;
|
/// <summary>
|
/// 按钮的高度
|
/// </summary>
|
public int buttonHeight = 150;
|
/// <summary>
|
/// 输入框的宽度
|
/// </summary>
|
public int InputControlWidth = 677;
|
/// <summary>
|
/// 确认按钮事件(由Text获取输入值,None模式除外)
|
/// </summary>
|
public Action<string> ComfirmClickEvent;
|
/// <summary>
|
/// 输入框的文本信息
|
/// </summary>
|
public string Text
|
{
|
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();
|
}
|
}
|
|
/// <summary>
|
/// 初始化桌布控件
|
/// </summary>
|
public void InitframeControl()
|
{
|
if (this.frameLayout != null)
|
{
|
this.frameLayout.RemoveAll();
|
}
|
else
|
{
|
this.BackgroundColor = UserCenterColor.Current.DialogBackColor;
|
}
|
|
//这是一个框
|
this.frameLayout = new FrameLayout();
|
frameLayout.Height = Application.GetRealHeight(538);
|
frameLayout.Width = Application.GetRealWidth(792);
|
frameLayout.Gravity = Gravity.Center;
|
frameLayout.Radius = 6;
|
frameLayout.BackgroundColor = UserCenterColor.Current.White;
|
base.AddChidren(frameLayout);
|
|
//标题信息
|
var btnTitle = new NormalViewControl(frameLayout.Width, Application.GetRealHeight(topTitleHeight), false);
|
btnTitle.Y = Application.GetRealHeight(69);
|
btnTitle.TextColor = UserCenterColor.Current.TextColor1;
|
btnTitle.TextSize = 16;
|
btnTitle.TextAlignment = TextAlignment.Center;
|
frameLayout.AddChidren(btnTitle);
|
frameLayout.AddTag("btnTitle", btnTitle);
|
|
//中间空白区域
|
int midHeight = frameLayout.Height - Application.GetRealHeight(btnTitle.Bottom + buttonHeight);
|
this.frameMiddle = new FrameLayout();
|
frameMiddle.Height = midHeight;
|
frameMiddle.Width = frameLayout.Width;
|
frameMiddle.Y = btnTitle.Bottom;
|
frameLayout.AddChidren(frameMiddle);
|
|
//取消(因为有可能要扩大中部高度,所以先声明)
|
var btnCancel = new NormalClickButton(frameLayout.Width / 2, Application.GetRealHeight(buttonHeight));
|
btnCancel.BackgroundColor = 0x66cccccc;
|
btnCancel.TextColor = UserCenterColor.Current.TextGrayColor1;
|
btnCancel.TextID = R.MyInternationalizationString.uCancel;
|
frameLayout.AddTag("btnCancel", btnCancel);
|
|
//确认(因为有可能要扩大中部高度,所以先声明)
|
var btnOk = new NormalClickButton(frameLayout.Width / 2, Application.GetRealHeight(buttonHeight));
|
btnOk.TextID = R.MyInternationalizationString.OkMsg;
|
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.AddChidren(txtInput);
|
}
|
|
/// <summary>
|
/// 只有一个输入框(密码模式)
|
/// </summary>
|
public void SetControlByOnlyPassword()
|
{
|
//初始化边框
|
var frameText = this.InitInputTextLine();
|
this.frameMiddle.AddChidren(frameText);
|
|
//输入框
|
this.txtInput = this.InitInputControl();
|
this.txtInput.SecureTextEntry = true;
|
frameText.AddChidren(txtInput);
|
}
|
|
/// <summary>
|
/// 只有一个输入框(密码模式),右边有一个可以看见密码的图标
|
/// </summary>
|
public void SetControlByPasswordView()
|
{
|
//初始化边框
|
var frameText = this.InitInputTextLine();
|
this.frameMiddle.AddChidren(frameText);
|
|
//输入框
|
this.txtInput = this.InitInputControl();
|
this.txtInput.SecureTextEntry = true;
|
frameText.AddChidren(txtInput);
|
this.txtInput.Gravity = Gravity.Frame;
|
|
//密码可视图标
|
this.InitPswViewControl();
|
}
|
|
#endregion
|
|
#region ■ 控件原型___________________________
|
|
/// <summary>
|
/// 初始化输入框的边框线
|
/// </summary>
|
public FrameLayout InitInputTextLine()
|
{
|
var frameText = new FrameLayout();
|
frameText.Width = Application.GetRealWidth(this.InputControlWidth);
|
frameText.Height = Application.GetRealHeight(100);
|
frameText.Y = Application.GetRealHeight(81);
|
frameText.Gravity = Gravity.CenterHorizontal;
|
frameText.BorderColor = 0xff676767;
|
frameText.BorderWidth = 1;
|
frameText.Radius = 8;
|
|
return frameText;
|
}
|
|
/// <summary>
|
/// 初始化输入框控件
|
/// </summary>
|
public TextInputControl InitInputControl()
|
{
|
var txtText = new TextInputControl(this.InputControlWidth - 20, 69, true);
|
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(this.Text);
|
};
|
}
|
|
/// <summary>
|
/// 添加子控件
|
/// </summary>
|
/// <param name="view"></param>
|
/// <param name="heightAutoMode">高度变更模式(非None的时候都同一自动调整)</param>
|
/// <param name="bottomSpace">中间空白区域里面最底部的控件与底部按钮的间距(非真实值)</param>
|
public void AddChidren(View view, HeightAutoMode heightAutoMode = HeightAutoMode.None, int bottomSpace = 0)
|
{
|
this.frameMiddle.AddChidren(view);
|
if (heightAutoMode != HeightAutoMode.None)
|
{
|
//获取最底部控件的坐标
|
int realHeight = 0;
|
for (int i = 0; i < this.frameMiddle.ChildrenCount; i++)
|
{
|
var myView = this.frameMiddle.GetChildren(i);
|
if (myView.Bottom > realHeight)
|
{
|
realHeight = myView.Bottom;
|
}
|
}
|
int value = realHeight + Application.GetRealHeight(bottomSpace) - this.frameMiddle.Height;
|
if (value > 0)
|
{
|
//底部控件已经超出了目前的高度,则扩大控件
|
this.frameMiddle.Height += value;
|
this.frameLayout.Height += value;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 画面关闭
|
/// </summary>
|
public void CloseDialog()
|
{
|
this.ComfirmClickEvent = null;
|
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
|
}
|
}
|