using Shared; using System; using System.Collections.Generic; namespace HDL_ON.Stan { /// /// 个人中心的共通基层画面,继承于此共通的画面,请使用AddForm()函数实现添加画面 /// 然后在各自的画面中,实现一个ShowForm()的函数(参数由添加画面时,使用的函数的参数指定) /// public class EditorCommonForm : CommonFormBase { #region ■ 变量声明___________________________ /// /// 返回按键的点击事件(如果实现此事件,则底层的事件将不会再触发) /// public Action BackButtonClickEvent = null; /// /// TopMenuFrameLayout /// public NormalFrameLayout topMenuFrameLayout = null; /// /// TopFrameLayout /// public NormalFrameLayout topFrameLayout = null; /// /// bodyFrameLayout /// public NormalFrameLayout bodyFrameLayout = null; /// /// 缓存启动参数 /// private object[] m_parameter = null; #endregion #region ■ 初始化_____________________________ /// /// 初始化界面框架 /// public override void InitForm() { base.InitForm(); //初始化头部控件 this.InitTopFrameLayout(); //初始化中部控件 this.InitBodyFrameLayout(); } /// /// 执行ShowForm()方法 /// /// 启动参数 public override void LoadShowFormMethod(params object[] parameter) { this.m_parameter = parameter; base.LoadShowFormMethod(parameter); } #endregion #region ■ 初始化界面_________________________ #region ■ Top________________________________ /// /// 初始化头部控件 /// public void InitTopFrameLayout() { if (topFrameLayout != null) { return; } //TopMenuFrameLayout做成 topMenuFrameLayout = new NormalFrameLayout(); topMenuFrameLayout.Height = HdlControlResourse.TopMenuFrameHeight; topMenuFrameLayout.BackgroundColor = UI.CSS.CSS_Color.TopViewColor; topMenuFrameLayout.Name = "topMenuFrameLayout"; this.AddChidren(topMenuFrameLayout); //TopFrameLayout做成 topFrameLayout = new NormalFrameLayout(); topFrameLayout.Height = HdlControlResourse.TopFrameHeight; topFrameLayout.BackgroundColor = UI.CSS.CSS_Color.TopViewColor; topFrameLayout.Y = topMenuFrameLayout.Bottom; topFrameLayout.Name = "topFrameLayout"; this.AddChidren(topFrameLayout); //返回键 var btnBack = new PicViewControl(40, 28); btnBack.X = Application.GetRealWidth(10); btnBack.Y = Application.GetRealHeight(9); btnBack.UnSelectedImagePath = "Public/BackIcon.png"; topFrameLayout.AddChidren(btnBack); topFrameLayout.AddTag("btnBack", btnBack); //一个加大返回按键点击区域的东西 var frameBtnBack = new NormalFrameLayout(); frameBtnBack.Width = Application.GetRealWidth(100); topFrameLayout.AddChidren(frameBtnBack); topFrameLayout.AddTag("frameBtnBack", frameBtnBack); frameBtnBack.ButtonClickEvent += (sender, e) => { if (this.BackButtonClickEvent != null) { //如果实现此事件,则底层的事件将不会再触发 this.BackButtonClickEvent(); return; } //画面关闭 this.CloseForm(); }; //标题 var btnTilte = new NormalViewControl(270, 25, true); btnTilte.Gravity = Gravity.CenterHorizontal; btnTilte.Y = Application.GetRealHeight(10); btnTilte.TextAlignment = TextAlignment.Center; btnTilte.TextSize = UI.CSS.CSS_FontSize.HeadlineFontSize; btnTilte.TextColor = UI.CSS.CSS_Color.FirstLevelTitleColor; topFrameLayout.AddChidren(btnTilte); topFrameLayout.AddTag("txtTitle", btnTilte); #if DEBUG btnTilte.MouseLongEventHandler += (sender, e) => { var form = new BottomMenuSelectControl(3); form.AddMenu("切换为中文", () => { Language.CurrentLanguage = "Chinese"; //清除全部控件 this.ClearBodyFrame(); //执行ShowForm()方法实现重新加载 this.LoadShowFormMethod(this.m_parameter); }); form.AddMenu("切换为英文", () => { Language.CurrentLanguage = "English"; //清除全部控件 this.ClearBodyFrame(); //执行ShowForm()方法实现重新加载 this.LoadShowFormMethod(this.m_parameter); }); form.AddMenu("查看本地文件", () => { var form2 = new HideOptionDirectoryListForm(); form2.AddForm(); }); }; #endif } #endregion #region ■ Middle_____________________________ /// /// 初始化中部控件 /// public void InitBodyFrameLayout() { if (bodyFrameLayout != null) { return; } bodyFrameLayout = new NormalFrameLayout(); bodyFrameLayout.Height = HdlControlResourse.BodyFrameHeight; bodyFrameLayout.Y = topFrameLayout.Bottom; bodyFrameLayout.BackgroundColor = UI.CSS.CSS_Color.BackgroundColor; bodyFrameLayout.Name = "bodyFrameLayout"; this.AddChidren(bodyFrameLayout); } #endregion #endregion #region ■ 添加界面___________________________ /// /// 添加画面,启动参数由指定画面的ShowForm函数所指定 /// /// 启动参数:参数由指定画面的ShowForm函数所指定 public override void AddForm(params object[] parameter) { base.AddForm(parameter); MainPage.BasePageView.AddChidren(this); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; //初始化界面框架 this.InitForm(); //执行ShowForm()方法 this.LoadShowFormMethod(parameter); } #endregion #region ■ 关闭界面___________________________ /// /// 画面关闭 /// public override void CloseFormBefore() { base.CloseFormBefore(); this.BackButtonClickEvent = null; this.m_parameter = null; //清空bodyFrame this.ClearBodyFrame(); } #endregion #region ■ 显示重新加载_______________________ /// /// 显示重新加载的界面(主要是用在界面加载错误时,再次加载) /// public override void ShowReLoadView() { HdlThreadLogic.Current.RunMain(() => { if (bodyFrameLayout == null || bodyFrameLayout.Parent == null) { return; } bodyFrameLayout.RemoveAll(); //切换为重新加载模式时的事件 this.ReLoadModelEventMethod(); var frame = new NormalFrameLayout(); bodyFrameLayout.AddChidren(frame); //重新加载 var btnReLoad = new BottomClickButton(); btnReLoad.Gravity = Gravity.Center; btnReLoad.TextID = StringId.DoReloadAgain; frame.AddChidren(btnReLoad); btnReLoad.ButtonClickEvent += (sender, e) => { //清除全部控件 this.ClearBodyFrame(); //执行ShowForm()方法实现重新加载 this.LoadShowFormMethod(this.m_parameter); }; //清除topFrameLayout的非默认的控件 var list = new List(); for (int i = 0; i < topFrameLayout.ChildrenCount; i++) { var view = topFrameLayout.GetChildren(i); if (view.Name == "btnBack" || view.Name == "txtTitle") { //这里是默认的底层控件 continue; } list.Add(view); } foreach (var view in list) { view?.RemoveFromParent(); } }); } /// /// 切换为【重新加载模式】时的事件函数,旨在关闭所有线程信息 /// public virtual void ReLoadModelEventMethod() { } #endregion #region ■ 界面重新激活事件___________________ /// /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件 /// 重写的时候返回值请返回1(返回值是给底层使用的) /// public virtual int FormActionAgainEvent() { return -1; } #endregion #region ■ 清空BodyFrame______________________ /// /// 清空BodyFrame /// public void ClearBodyFrame() { if (this.Parent == null) { return; } if (bodyFrameLayout == null || bodyFrameLayout.Parent == null) { return; } bodyFrameLayout.RemoveAll(); } #endregion #region ■ 添加列表消息显示控件_______________ /// /// 添加列表消息显示控件,返回生成的控件(没看懂这个函数前,请勿使用,它不会帮计算换行) /// /// 桌布容器控件 /// 显示的消息(换行请使用【{0}】进行分割) /// 字体大小 /// 字体颜色 /// 控件高度(真实值) /// Y轴初始坐标(真实值) /// 文字对齐方式 /// /// 注:除了新建这个函数的开发者以外,都不建议把这个值不设置为true /// 说明:以最长的控件的X轴为基准,所有控件的X轴都变成一致 /// /// 文本宽度,真实值,当为-1时,内部自动计算 /// public List AddListMsgControls(FrameLayout frameTable, string i_msg, int i_fontSize, uint i_fontColor, int i_height, int i_yy, TextAlignment alignment = TextAlignment.Center, bool special = false, int i_width = -1) { var listMsg = i_msg.Split(new string[] { "{0}" }, StringSplitOptions.RemoveEmptyEntries); int defultWidth = 0; if (this.bodyFrameLayout != null) { defultWidth = i_width == -1 ? this.bodyFrameLayout.Width - HdlControlResourse.XXLeft * 2 : i_width; } else { defultWidth = i_width == -1 ? frameTable.Width - HdlControlResourse.XXLeft * 2 : i_width; } //如果只是一行的时候 bool isMoreLine = false; if (listMsg.Length == 1) { var btnTemp = new ButtonCtrBase(); btnTemp.TextSize = i_fontSize; btnTemp.Text = i_msg; int rowCount = btnTemp.GetRealRowCountByText(defultWidth); //它的高度由行数决定(理论上应该都是1行,这里做特殊处理而已) if (rowCount > 1) { i_height = i_height * rowCount; isMoreLine = true; } } var listContr = new List(); int minXX = 10086;//控件集合最小的X轴 foreach (var strMsg in listMsg) { //消息显示控件 var btnMsg = new NormalViewControl(defultWidth, i_height, false); btnMsg.Y = i_yy; btnMsg.Gravity = Gravity.CenterHorizontal; btnMsg.TextAlignment = alignment; btnMsg.TextColor = i_fontColor; btnMsg.TextSize = i_fontSize; btnMsg.Text = strMsg; if (isMoreLine == true) { //可以换行 btnMsg.IsMoreLines = isMoreLine; } //特殊处理 if (special == true) { //设置它的真实宽度(对special变量有用) int realWidth = btnMsg.GetRealWidthByText(); btnMsg.Width = realWidth > defultWidth ? defultWidth : realWidth; } frameTable.AddChidren(btnMsg); //收集控件 listContr.Add(btnMsg); //记录控件集合X轴最小的值 if (btnMsg.X < minXX) { minXX = btnMsg.X; } //两行之间的间距为4 i_yy = btnMsg.Bottom + Application.GetRealHeight(4); } //特殊处理 if (special == true) { foreach (var contr in listContr) { //以最长的控件的X轴为基准,所有控件的X轴都变成一致 contr.X = minXX; } } return listContr; } #endregion #region ■ 添加底部点击按钮控件_______________ /// /// 添加底部点击按钮控件 /// /// 显示的文本 /// public BottomClickButton AddBottomClickButton(string i_text) { //容器控件 var frameBack = new FrameLayout(); frameBack.Height = Application.GetRealHeight(76); frameBack.Gravity = Gravity.BottomCenter; bodyFrameLayout.AddChidren(frameBack); //然后在顶部添加一个有边框的东西 var frameLine = new FrameLayout(); frameLine.Height = Application.GetRealHeight(50); frameLine.BorderWidth = 1; frameLine.BackgroundColor = UI.CSS.CSS_Color.MainBackgroundColor; frameLine.BorderColor = UI.CSS.CSS_Color.DividingLineColor; frameLine.SetCornerWithSameRadius(Application.GetRealHeight(24), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight); frameBack.AddChidren(frameLine); //最后再整个白色的东西遮住它的下部 var frameWite = new FrameLayout(); frameWite.Height = frameBack.Height - Application.GetRealHeight(24 - 10);//需要超过它 frameWite.Width = frameBack.Width + Application.GetRealWidth(6); frameWite.X = -Application.GetRealWidth(3); frameWite.Y = Application.GetRealHeight(24); frameWite.BackgroundColor = UI.CSS.CSS_Color.MainBackgroundColor; frameBack.AddChidren(frameWite); //按钮 var btnOk = new BottomClickButton(220); btnOk.Gravity = Gravity.Center; btnOk.Text = i_text; frameBack.AddChidren(btnOk); return btnOk; } #endregion #region ■ 一般的方法_________________________ /// /// 设置标题信息 /// /// Title. public void SetTitleText(string title) { //设置头部信息 var btntitle = (Button)topFrameLayout.GetTagByKey("txtTitle"); btntitle.Text = title; } /// /// 移除返回键 /// public void RemoveBackButton() { //移除返回键 var back = (PicViewControl)topFrameLayout.GetTagByKey("btnBack"); topFrameLayout.RemoveTag("btnBack"); back?.RemoveFromParent(); var back2 = (NormalFrameLayout)topFrameLayout.GetTagByKey("frameBtnBack"); topFrameLayout.RemoveTag("frameBtnBack"); back2?.RemoveFromParent(); } #endregion } }