using System; using System.Collections.Generic; using System.Text; namespace Shared.Phone.UserCenter { /// /// 做成一个上部有标题,中间是一遍白色区域,左下角是【取消按钮】,右下角是【确认按钮】的弹窗控件 /// 子控件添加完成后,请调用【InitLastControl】函数完成最后的初始化(仅限None模式) /// 确认按钮的单击事件为:ComfirmClickEvent /// public class DialogInputFrameControl : FrameLayout { #region ■ 变量声明___________________________ /// /// 菜单标题的高度 /// public int topTitleHeight = 63; /// /// 按钮的高度 /// public int buttonHeight = 150; /// /// 输入框的宽度 /// public int InputControlWidth = 677; /// /// 确认按钮事件(由Text获取输入值,None模式除外) /// public Action ComfirmClickEvent; /// /// 输入框的文本信息 /// public string Text { get { if (this.txtInput == null) { return string.Empty; } return txtInput.Text.Trim(); } set { if (this.txtInput != null) { this.txtInput.Text = value; } } } /// /// 中部桌布控件 /// public FrameLayout frameMiddle = null; /// /// 最外层边框 /// private FrameLayout frameLayout = null; /// /// 输入框控件 /// private TextInputControl txtInput = null; /// /// 弹窗模式 /// private DialogFrameMode dialogFrameMode = DialogFrameMode.None; #endregion #region ■ 初始化_____________________________ /// /// 做成一个上部有标题,中间是一遍白色区域,左下角是【取消按钮】,右下角是【确认按钮】的弹窗控件 /// 子控件添加完成后,请调用【FinishInitControl】函数完成最后的初始化(仅限None模式) /// 确认按钮的单击事件为:ComfirmClickEvent /// /// /// 载体父控件(会自动将该控件加入此载体父控件) /// 可以为空,当为空时,请在添加入载体父控件后,调用InitframeControl函数进行初始化 /// /// 弹窗模式 public DialogInputFrameControl(FrameLayout mainFrame, DialogFrameMode i_dialogFrameMode = DialogFrameMode.None) { this.dialogFrameMode = i_dialogFrameMode; if (mainFrame != null) { mainFrame.AddChidren(this); //初始化桌布控件 this.InitframeControl(); } } /// /// 初始化桌布控件 /// 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 ■ 弹窗模式___________________________ /// /// 只有一个输入框 /// public void SetControlByOnlyInput() { //初始化边框 var frameText = this.InitInputTextLine(); this.frameMiddle.AddChidren(frameText); //输入框 this.txtInput = this.InitInputControl(); frameText.AddChidren(txtInput); } /// /// 只有一个输入框(密码模式) /// public void SetControlByOnlyPassword() { //初始化边框 var frameText = this.InitInputTextLine(); this.frameMiddle.AddChidren(frameText); //输入框 this.txtInput = this.InitInputControl(); this.txtInput.SecureTextEntry = true; frameText.AddChidren(txtInput); } /// /// 只有一个输入框(密码模式),右边有一个可以看见密码的图标 /// 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 ■ 控件原型___________________________ /// /// 初始化输入框的边框线 /// 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; } /// /// 初始化输入框控件 /// public TextInputControl InitInputControl() { var txtText = new TextInputControl(this.InputControlWidth - 20, 69, true); txtText.TextAlignment = TextAlignment.Center; txtText.Gravity = Gravity.Center; return txtText; } /// /// 初始化密码可视图标 /// /// 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 ■ 一般方法___________________________ /// /// 完成初始化控件 /// 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); }; } /// /// 添加子控件 /// /// /// 高度变更模式(非None的时候都同一自动调整) /// 中间空白区域里面最底部的控件与底部按钮的间距(非真实值) 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; } } } /// /// 画面关闭 /// public void CloseDialog() { this.ComfirmClickEvent = null; this.RemoveFromParent(); } #endregion #region ■ 设置信息___________________________ /// /// 设置标题信息 /// /// public void SetTitleText(string txtValue) { var btnTitle = (NormalViewControl)frameLayout.GetTagByKey("btnTitle"); btnTitle.Text = txtValue; } /// /// 设置取消按钮的文本信息 /// /// public void SetCancelButtonText(string txtValue) { var btnCancel = (NormalClickButton)frameLayout.GetTagByKey("btnCancel"); btnCancel.Text = txtValue; } /// /// 设置确定按钮的文本信息 /// /// public void SetOkButtonText(string txtValue) { var btnOk = (NormalClickButton)frameLayout.GetTagByKey("btnOk"); btnOk.Text = txtValue; } /// /// 设置输入框灰色字体说明 /// /// public void SetTipText(string txtValue) { if (this.txtInput != null) { this.txtInput.PlaceholderText = txtValue; } } #endregion } }