using System; using System.Collections.Generic; using System.Text; namespace Shared.Phone.UserCenter { /// /// 做成一个上部有标题,中间是一遍白色区域,左下角是【取消按钮】,右下角是【确认按钮】的弹窗控件 /// 子控件添加完成后,请调用【InitLastControl】函数完成最后的初始化(仅限None模式) /// 确认按钮的单击事件为:ComfirmClickEvent /// public class DialogInputFrameControl : FrameLayout { #region ■ 变量声明___________________________ /// /// 上部菜单标题的高度 /// public int topMenuHeight = 190; /// /// 按钮的高度 /// public int buttonHeight = 150; /// /// 输入框的宽度 /// public int InputControlWidth = 800; /// /// 确认按钮事件 /// public delegate void _ComfirmClickEvent(); /// /// 画面关闭事件(由InputText获取输入值,None模式除外) /// public _ComfirmClickEvent ComfirmClickEvent; /// /// 输入框的文本信息 /// public string InputText { get { if (this.txtInput == null) { return string.Empty; } return txtInput.Text.Trim(); } set { if (this.txtInput != null) { this.txtInput.Text = value; } } } /// /// 中部桌布控件 /// public SpecialFrameLayout frameMiddle = null; /// /// 最外层边框 /// private SpecialFrameLayout frameLayout = null; /// /// 输入框控件 /// private EditInputText 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(this.dialogFrameMode); } } /// /// 初始化桌布控件 /// /// 窗体模式 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); frameLayout.Gravity = Gravity.Center; frameLayout.Radius = 5; frameLayout.BackgroundColor = UserCenterColor.Current.BodyFrameLayout; base.AddChidren(frameLayout); //标题信息 var btnTitle = new ViewNormalControl(frameLayout.Width, Application.GetRealHeight(topMenuHeight)); btnTitle.TextColor = UserCenterColor.Current.TextColor; 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); frameMiddle.Y = btnTitle.Bottom; //frameMiddle.BackgroundColor = UserCenterColor.Current.BodyFrameLayout; frameLayout.AddChidren(frameMiddle); //取消(因为有可能要扩大中部高度,所以先声明) var btnCancel = new DialogClickButton(frameLayout.Width / 2 - 1, Application.GetRealHeight(buttonHeight)); btnCancel.TextID = R.MyInternationalizationString.uCancel; btnCancel.TextSize = 18; frameLayout.AddTag("btnCancel", btnCancel); //确认(因为有可能要扩大中部高度,所以先声明) var btnOk = new DialogClickButton(frameLayout.Width / 2 - 1, Application.GetRealHeight(buttonHeight)); 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 ■ 弹窗模式___________________________ /// /// 只有一个输入框 /// public void SetControlByOnlyInput() { //初始化边框 var frameText = this.InitInputTextLine(); this.frameMiddle.AddChidren(frameText); //输入框 this.txtInput = this.InitInputControl(frameText); frameText.AddChidren(txtInput, HeightAutoMode.IncreaseAll); } /// /// 只有一个输入框(密码模式) /// 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); } /// /// 只有一个输入框(密码模式),右边有一个可以看见密码的图标 /// 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); this.txtInput.Gravity = Gravity.Frame; //密码可视图标 this.InitPswViewControl(); } #endregion #region ■ 控件原型___________________________ /// /// 初始化输入框的边框线 /// public SpecialFrameLayout InitInputTextLine() { var frameText = new SpecialFrameLayout(this.InputControlWidth, 110, 20); frameText.Gravity = Gravity.Center; frameText.BorderColor = UserCenterColor.Current.TextFrameColor; frameText.BorderWidth = 1; frameText.Radius = 8; return frameText; } /// /// 初始化输入框控件 /// /// public EditInputText InitInputControl(SpecialFrameLayout frameLine) { var txtText = new EditInputText(); txtText.InitSize(frameLine.Width - Application.GetRealHeight(10), ControlCommonResourse.NormalControlHeight, false); 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 = (DialogClickButton)frameLayout.GetTagByKey("btnCancel"); btnCancel.Gravity = Gravity.BottomLeft; frameLayout.AddChidren(btnCancel); btnCancel.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); }; //确认 var btnOk = (DialogClickButton)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 ViewNormalControl(1, Application.GetRealHeight(buttonHeight)); btnLine1.X = btnCancel.Right; btnLine1.Y = btnCancel.Y; btnLine1.BackgroundColor = UserCenterColor.Current.Line; frameLayout.AddChidren(btnLine1); //灰线 var btnLine2 = new ViewNormalControl(frameLayout.Width, 1); btnLine2.Y = btnOk.Y - 1; btnLine2.BackgroundColor = UserCenterColor.Current.Line; frameLayout.AddChidren(btnLine2); } /// /// 添加子控件 /// /// /// 高度变更模式 public void AddChidren(View view, HeightAutoMode heightAutoMode = HeightAutoMode.None) { this.frameMiddle.AddChidren(view, heightAutoMode); } /// /// 画面关闭 /// public void CloseDialog() { this.RemoveFromParent(); } #endregion #region ■ 设置信息___________________________ /// /// 设置标题信息 /// /// public void SetTitleText(string txtValue) { var btnTitle = (ViewNormalControl)frameLayout.GetTagByKey("btnTitle"); btnTitle.Text = txtValue; } /// /// 设置取消按钮的文本信息 /// /// public void SetCancelButtonText(string txtValue) { var btnCancel = (DialogClickButton)frameLayout.GetTagByKey("btnCancel"); btnCancel.Text = txtValue; } /// /// 设置确定按钮的文本信息 /// /// public void SetOkButtonText(string txtValue) { var btnOk = (DialogClickButton)frameLayout.GetTagByKey("btnOk"); btnOk.Text = txtValue; } /// /// 设置输入框灰色字体说明 /// /// public void SetTipText(string txtValue) { if (this.txtInput != null) { this.txtInput.PlaceholderText = txtValue; this.txtInput.PlaceholderTextColor = UserCenterColor.Current.TextTipColor; } } #endregion } }