HDL Home App 第二版本 旧平台金堂用 正在使用
hxb
2022-08-30 25429f085093d89d543a0b90e30d0d62d1b7dac9
ZigbeeApp/Shared/Phone/CommonForm/EditorCommonForm.cs
old mode 100755 new mode 100644
@@ -1,8 +1,8 @@
using Shared.Phone.UserCenter;
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Shared.Phone
{
    /// <summary>
@@ -15,10 +15,10 @@
        #region ■ 变量声明___________________________
        /// <summary>
        /// 返回按键的点击事件(如果实现此事件,则底层的事件将不会再触发)
        /// </summary>
        public Action<BackViewControl> BackButtonClickEvent = null;
        /// <summary>
        /// 返回按键的点击事件(如果实现此事件,则底层的事件将不会再触发)
        /// </summary>
        public Action<BackViewControl> BackButtonClickEvent = null;
        /// <summary>
        /// TopMenuFrameLayout
        /// </summary>
        public NormalFrameLayout topMenuFrameLayout = null;
@@ -30,34 +30,34 @@
        /// bodyFrameLayout
        /// </summary>
        public NormalFrameLayout bodyFrameLayout = null;
        /// <summary>
        /// 左滑使能
        /// <summary>
        /// 左滑使能
        /// </summary>
        private bool m_ScrollEnabled = true;
        /// <summary>
        /// 左滑使能(界面关闭时,底层会还原,无需再处理)
        /// <summary>
        /// 左滑使能(界面关闭时,底层会还原,无需再处理)
        /// </summary>
        public bool ScrollEnabled
        {
            get { return m_ScrollEnabled; }
            set
            {
                if (UserView.HomePage.Instance.ScrollEnabled != value)
                {
                    UserView.HomePage.Instance.ScrollEnabled = value;
                    this.m_ScrollEnabled = value;
                }
            }
        public bool ScrollEnabled
        {
            get { return m_ScrollEnabled; }
            set
            {
                if (UserView.HomePage.Instance.ScrollEnabled != value)
                {
                    UserView.HomePage.Instance.ScrollEnabled = value;
                    this.m_ScrollEnabled = value;
                }
            }
        }
        /// <summary>
        /// 缓存启动参数
        /// <summary>
        /// 缓存启动参数
        /// </summary>
        private object[] m_parameter = null;
        private object[] m_parameter = null;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 初始化界面框架
        /// </summary>
@@ -80,17 +80,17 @@
        /// </summary>
        /// <param name="parameter">启动参数</param>
        public override void LoadShowFormMethod(params object[] parameter)
        {
            this.m_parameter = parameter;
        {
            this.m_parameter = parameter;
            base.LoadShowFormMethod(parameter);
        }
        #endregion
        #endregion
        #region ■ 初始化界面_________________________
        #region ■ Top________________________________
        /// <summary>
        /// 初始化头部控件
        /// </summary>
@@ -106,7 +106,7 @@
            topMenuFrameLayout.Height = ControlCommonResourse.TopMenuFrameHeight;
            topMenuFrameLayout.BackgroundColor = UserCenterColor.Current.TopFrameLayout;
            topMenuFrameLayout.Name = "topMenuFrameLayout";
            this.AddChidren(topMenuFrameLayout);
            this.AddChidren(topMenuFrameLayout);
            //TopFrameLayout做成
            topFrameLayout = new NormalFrameLayout();
@@ -121,316 +121,316 @@
            btnLine.BackgroundColor = 0x40000000;
            btnLine.Y = topFrameLayout.Height - 1;
            topFrameLayout.AddChidren(btnLine);
            topFrameLayout.AddTag("btnLine", btnLine);
            topFrameLayout.AddTag("btnLine", btnLine);
            //返回键
            var btnBack = new BackViewControl();
            topFrameLayout.AddChidren(btnBack);
            btnBack.InitControl();
            btnBack.ButtonClickEvent += (sender, e) =>
            {
                if (this.BackButtonClickEvent != null)
                {
                    //如果实现此事件,则底层的事件将不会再触发
                    BackButtonClickEvent(btnBack);
                    return;
                }
                //画面关闭
                this.CloseForm();
            };
            btnBack.ButtonClickEvent += (sender, e) =>
            {
                if (this.BackButtonClickEvent != null)
                {
                    //如果实现此事件,则底层的事件将不会再触发
                    BackButtonClickEvent(btnBack);
                    return;
                }
                //画面关闭
                this.CloseForm();
            };
            topFrameLayout.AddTag("btnBack", btnBack);
            //标题
            var txttitle = new Button();
            var txttitle = new Button();
            txttitle.Name = "txtTitle";
            txttitle.TextSize = 17;
            txttitle.X = Application.GetRealWidth(161);
            txttitle.Height = Application.GetRealHeight(75);
            txttitle.Width = Application.GetRealWidth(850);
            txttitle.Gravity = Gravity.CenterVertical;
            txttitle.TextColor = UserCenterColor.Current.TopLayoutTitleText;
            txttitle.TextAlignment = TextAlignment.CenterLeft;
            txttitle.TextColor = UserCenterColor.Current.TopLayoutTitleText;
            txttitle.TextAlignment = TextAlignment.CenterLeft;
            txttitle.IsBold = true;
            topFrameLayout.AddChidren(txttitle);
            topFrameLayout.AddTag("txtTitle", txttitle);
        }
        #endregion
        #region ■ Middle_____________________________
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        public void InitBodyFrameLayout()
        {
        {
            if (bodyFrameLayout != null)
            {
                bodyFrameLayout.RemoveAll();
            }
            }
            bodyFrameLayout = new NormalFrameLayout();
            bodyFrameLayout.Height = ControlCommonResourse.BodyFrameHeight;
            bodyFrameLayout.Y = topFrameLayout.Bottom;
            bodyFrameLayout.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
            bodyFrameLayout.Name = "bodyFrameLayout";
            this.AddChidren(bodyFrameLayout);
        }
        }
        #endregion
        #endregion
        #region ■ 添加界面___________________________
        /// <summary>
        /// 添加画面,启动参数由指定画面的ShowForm函数所指定
        /// </summary>
        /// <param name="parameter">启动参数:参数由指定画面的ShowForm函数所指定</param>
        public override void AddForm(params object[] parameter)
        {
            //界面加载中
            ControlCommonResourse.IsFormAdding = true;
            base.AddForm(parameter);
        #region ■ 添加界面___________________________
        /// <summary>
        /// 添加画面,启动参数由指定画面的ShowForm函数所指定
        /// </summary>
        /// <param name="parameter">启动参数:参数由指定画面的ShowForm函数所指定</param>
        public override void AddForm(params object[] parameter)
        {
            //界面加载中
            ControlCommonResourse.IsFormAdding = true;
            base.AddForm(parameter);
            //检测能否追加画面 2020.05.14舍弃
            //if (UserCenterLogic.CheckCanAddForm(this) == false)
            //{
            //    return;
            //}
            UserView.HomePage.Instance.AddChidren(this);
            UserView.HomePage.Instance.PageIndex += 1;
            //初始化界面框架
            this.InitForm();
            //执行ShowForm()方法
            this.LoadShowFormMethod(parameter);
            //界面加载结束
            ControlCommonResourse.IsFormAdding = false;
        }
        #endregion
        #region ■ 关闭界面___________________________
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            base.CloseFormBefore();
            //左滑使能
            this.ScrollEnabled = true;
            this.BackButtonClickEvent = null;
            this.m_parameter = null;
            //清空bodyFrame
            this.ClearBodyFrame();
        }
        #endregion
        #region ■ 添加帮助控件_______________________
        /// <summary>
        /// 添加查看帮助控件
        /// </summary>
        /// <returns></returns>
        public NormalViewControl AddHelpControl()
        {
            //查看帮助
            var btnHelp = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(50), false);
            btnHelp.Y = Application.GetRealHeight(1388);
            btnHelp.TextSize = 12;
            btnHelp.TextAlignment = TextAlignment.Center;
            btnHelp.TextColor = UserCenterColor.Current.TextOrangeColor;
            btnHelp.Text = Language.StringByID(R.MyInternationalizationString.uSearchHelp);
            bodyFrameLayout.AddChidren(btnHelp);
            //底线
            int lineWidth = btnHelp.GetRealWidthByText();
            var btnLine = new NormalViewControl(lineWidth, ControlCommonResourse.BottomLineHeight, false);
            btnLine.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
            btnLine.Gravity = Gravity.CenterHorizontal;
            btnLine.Y = btnHelp.Bottom - Application.GetRealHeight(8);
            bodyFrameLayout.AddChidren(btnLine);
            return btnHelp;
        }
        #endregion
        #region ■ 显示重新加载_______________________
            UserView.HomePage.Instance.AddChidren(this);
            UserView.HomePage.Instance.PageIndex += 1;
        /// <summary>
        /// 显示重新加载的界面(主要是用在界面加载错误时,再次加载)
        /// </summary>
        public override void ShowReLoadView()
        {
            HdlThreadLogic.Current.RunMain(() =>
            {
                if (bodyFrameLayout == null || bodyFrameLayout.Parent == null)
                {
                    return;
                }
                //切换为重新加载模式时的事件
                this.ReLoadModelEventMethod();
                var frame = new FrameLayout();
                frame.BackgroundColor = UserCenterColor.Current.White;
                bodyFrameLayout.AddChidren(frame);
                //重新加载
                var btnReLoad = new BottomClickButton();
                btnReLoad.Gravity = Gravity.Center;
                btnReLoad.TextID = R.MyInternationalizationString.uDoReload;
                frame.AddChidren(btnReLoad);
                btnReLoad.ButtonClickEvent += (sender, e) =>
                {
                    //点击重新加载时,允许再次联网
                    HdlWifiLogic.Current.CanAccessHttp = true;
                    //清除全部控件
                    this.ClearBodyFrame();
                    //执行ShowForm()方法实现重新加载
                    this.LoadShowFormMethod(this.m_parameter);
                };
                //清除topFrameLayout的非默认的控件
                var list = new List<View>();
                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();
                }
            });
        }
        /// <summary>
        /// 切换为【重新加载模式】时的事件函数,旨在关闭所有线程信息
        /// </summary>
        public virtual void ReLoadModelEventMethod()
        {
        }
        #endregion
        #region ■ 显示弹窗输入界面___________________
        /// <summary>
        /// <para>显示一个Dialog的弹窗输入界面,它不会自动关闭,需要手动关闭</para>
        /// <para>.CloseDialog()为关闭弹窗</para>
        /// <para>如果输入框的内容为空,并且设置有【i_TipText】,则不会调用回调函数,并且提示【i_TipText】的内容</para>
        /// </summary>
        /// <param name="i_TitleText">弹窗的标题信息</param>
        /// <param name="i_InputText">输入框初始化值(忽略请设置为null)</param>
        /// <param name="i_TipText">输入框灰色字体说明(忽略请设置为null)</param>
        /// <param name="i_ComfirmClickEvent">确认按钮事件</param>
        /// <returns></returns>
        public void ShowDialogInputForm(string i_TitleText, string i_InputText, string i_TipText, Action<DialogInputControl, string> i_ComfirmClickEvent)
        {
            //生成一个弹窗画面
            var dialogForm = new DialogInputControl();
            //标题
            dialogForm.SetTitleText(i_TitleText);
            //输入框灰色字体说明
            if (i_TipText != null)
            {
                dialogForm.SetTipText(i_TipText);
            }
            //输入框初始值
            if (i_InputText != null)
            {
                dialogForm.Text = i_InputText;
            }
            //按下确认按钮
            dialogForm.ComfirmClickEvent += ((textValue) =>
            {
                i_ComfirmClickEvent?.Invoke(dialogForm, textValue);
            });
        }
        #endregion
        #region ■ 显示没有数据的图像显示特效_________
        /// <summary>
        /// 显示没有数据的图像显示特效
        /// </summary>
        /// <param name="frameTable">容器</param>
        /// <param name="i_Text">显示文字</param>
        /// <param name="Imagepath">图像地址</param>
        /// <param name="imageWith">图像宽度(非真实值)</param>
        /// <param name="imageHeight">图像高度(非真实值)</param>
        public void ShowNotDataImage(FrameLayout frameTable, string i_Text, string Imagepath = "Item/NoFunction.png", int imageWith = 683, int imageHeight = 392)
        {
            this.ShowNotDataImage(frameTable, new string[] { i_Text }, Imagepath, imageWith, imageHeight);
        }
        /// <summary>
        /// 显示没有数据的图像显示特效
        /// </summary>
        /// <param name="frameTable">容器</param>
        /// <param name="listText">显示文字</param>
        /// <param name="Imagepath">图像地址</param>
        /// <param name="imageWith">图像宽度(非真实值)</param>
        /// <param name="imageHeight">图像高度(非真实值)</param>
        public void ShowNotDataImage(FrameLayout frameTable, string[] listText, string Imagepath = "Item/NoFunction.png", int imageWith = 683, int imageHeight = 392)
        {
            var btnPic = new PicViewControl(imageWith, imageHeight);
            btnPic.UnSelectedImagePath = Imagepath;
            btnPic.Y = (int)(frameTable.Height * 0.382) - Application.GetRealHeight(imageHeight / 2);
            btnPic.Gravity = Gravity.CenterHorizontal;
            frameTable.AddChidren(btnPic);
            int yy = btnPic.Bottom + Application.GetRealHeight(32);
            for (int i = 0; i < listText.Length; i++)
            {
                var btnView = new NormalViewControl(frameTable.Width, Application.GetRealHeight(50), false);
                btnView.Y = yy;
                btnView.Text = listText[i];
                btnView.TextAlignment = TextAlignment.Center;
                btnView.TextSize = 12;
                btnView.TextColor = UserCenterColor.Current.TextGrayColor1;
                frameTable.AddChidren(btnView);
                yy = btnView.Bottom;
            }
        }
        #endregion
        #region ■ 界面重新激活事件___________________
        /// <summary>
        /// <para>自身的上层界面关闭后,它自身处于最上层时,触发的事件</para>
        /// <para>重写的时候返回值请返回1(返回值是给底层使用的)</para>
        /// </summary>
        public virtual int FormActionAgainEvent()
        {
            return -1;
            //初始化界面框架
            this.InitForm();
            //执行ShowForm()方法
            this.LoadShowFormMethod(parameter);
            //界面加载结束
            ControlCommonResourse.IsFormAdding = false;
        }
        #endregion
        #endregion
        #region ■ 关闭界面___________________________
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            base.CloseFormBefore();
            //左滑使能
            this.ScrollEnabled = true;
            this.BackButtonClickEvent = null;
            this.m_parameter = null;
            //清空bodyFrame
            this.ClearBodyFrame();
        }
        #endregion
        #region ■ 添加帮助控件_______________________
        /// <summary>
        /// 添加查看帮助控件
        /// </summary>
        /// <returns></returns>
        public NormalViewControl AddHelpControl()
        {
            //查看帮助
            var btnHelp = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(50), false);
            btnHelp.Y = Application.GetRealHeight(1388);
            btnHelp.TextSize = 12;
            btnHelp.TextAlignment = TextAlignment.Center;
            btnHelp.TextColor = UserCenterColor.Current.TextOrangeColor;
            btnHelp.Text = Language.StringByID(R.MyInternationalizationString.uSearchHelp);
            bodyFrameLayout.AddChidren(btnHelp);
            //底线
            int lineWidth = btnHelp.GetRealWidthByText();
            var btnLine = new NormalViewControl(lineWidth, ControlCommonResourse.BottomLineHeight, false);
            btnLine.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
            btnLine.Gravity = Gravity.CenterHorizontal;
            btnLine.Y = btnHelp.Bottom - Application.GetRealHeight(8);
            bodyFrameLayout.AddChidren(btnLine);
            return btnHelp;
        }
        #endregion
        #region ■ 显示重新加载_______________________
        /// <summary>
        /// 显示重新加载的界面(主要是用在界面加载错误时,再次加载)
        /// </summary>
        public override void ShowReLoadView()
        {
            HdlThreadLogic.Current.RunMain(() =>
            {
                if (bodyFrameLayout == null || bodyFrameLayout.Parent == null)
                {
                    return;
                }
                //切换为重新加载模式时的事件
                this.ReLoadModelEventMethod();
                var frame = new FrameLayout();
                frame.BackgroundColor = UserCenterColor.Current.White;
                bodyFrameLayout.AddChidren(frame);
                //重新加载
                var btnReLoad = new BottomClickButton();
                btnReLoad.Gravity = Gravity.Center;
                btnReLoad.TextID = R.MyInternationalizationString.uDoReload;
                frame.AddChidren(btnReLoad);
                btnReLoad.ButtonClickEvent += (sender, e) =>
                {
                    //点击重新加载时,允许再次联网
                    HdlWifiLogic.Current.CanAccessHttp = true;
                    //清除全部控件
                    this.ClearBodyFrame();
                    //执行ShowForm()方法实现重新加载
                    this.LoadShowFormMethod(this.m_parameter);
                };
                //清除topFrameLayout的非默认的控件
                var list = new List<View>();
                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();
                }
            });
        }
        /// <summary>
        /// 切换为【重新加载模式】时的事件函数,旨在关闭所有线程信息
        /// </summary>
        public virtual void ReLoadModelEventMethod()
        {
        }
        #endregion
        #region ■ 显示弹窗输入界面___________________
        /// <summary>
        /// <para>显示一个Dialog的弹窗输入界面,它不会自动关闭,需要手动关闭</para>
        /// <para>.CloseDialog()为关闭弹窗</para>
        /// <para>如果输入框的内容为空,并且设置有【i_TipText】,则不会调用回调函数,并且提示【i_TipText】的内容</para>
        /// </summary>
        /// <param name="i_TitleText">弹窗的标题信息</param>
        /// <param name="i_InputText">输入框初始化值(忽略请设置为null)</param>
        /// <param name="i_TipText">输入框灰色字体说明(忽略请设置为null)</param>
        /// <param name="i_ComfirmClickEvent">确认按钮事件</param>
        /// <returns></returns>
        public void ShowDialogInputForm(string i_TitleText, string i_InputText, string i_TipText, Action<DialogInputControl, string> i_ComfirmClickEvent)
        {
            //生成一个弹窗画面
            var dialogForm = new DialogInputControl();
            //标题
            dialogForm.SetTitleText(i_TitleText);
            //输入框灰色字体说明
            if (i_TipText != null)
            {
                dialogForm.SetTipText(i_TipText);
            }
            //输入框初始值
            if (i_InputText != null)
            {
                dialogForm.Text = i_InputText;
            }
            //按下确认按钮
            dialogForm.ComfirmClickEvent += ((textValue) =>
            {
                i_ComfirmClickEvent?.Invoke(dialogForm, textValue);
            });
        }
        #endregion
        #region ■ 显示没有数据的图像显示特效_________
        /// <summary>
        /// 显示没有数据的图像显示特效
        /// </summary>
        /// <param name="frameTable">容器</param>
        /// <param name="i_Text">显示文字</param>
        /// <param name="Imagepath">图像地址</param>
        /// <param name="imageWith">图像宽度(非真实值)</param>
        /// <param name="imageHeight">图像高度(非真实值)</param>
        public void ShowNotDataImage(FrameLayout frameTable, string i_Text, string Imagepath = "Item/NoFunction.png", int imageWith = 683, int imageHeight = 392)
        {
            this.ShowNotDataImage(frameTable, new string[] { i_Text }, Imagepath, imageWith, imageHeight);
        }
        /// <summary>
        /// 显示没有数据的图像显示特效
        /// </summary>
        /// <param name="frameTable">容器</param>
        /// <param name="listText">显示文字</param>
        /// <param name="Imagepath">图像地址</param>
        /// <param name="imageWith">图像宽度(非真实值)</param>
        /// <param name="imageHeight">图像高度(非真实值)</param>
        public void ShowNotDataImage(FrameLayout frameTable, string[] listText, string Imagepath = "Item/NoFunction.png", int imageWith = 683, int imageHeight = 392)
        {
            var btnPic = new PicViewControl(imageWith, imageHeight);
            btnPic.UnSelectedImagePath = Imagepath;
            btnPic.Y = (int)(frameTable.Height * 0.382) - Application.GetRealHeight(imageHeight / 2);
            btnPic.Gravity = Gravity.CenterHorizontal;
            frameTable.AddChidren(btnPic);
            int yy = btnPic.Bottom + Application.GetRealHeight(32);
            for (int i = 0; i < listText.Length; i++)
            {
                var btnView = new NormalViewControl(frameTable.Width, Application.GetRealHeight(50), false);
                btnView.Y = yy;
                btnView.Text = listText[i];
                btnView.TextAlignment = TextAlignment.Center;
                btnView.TextSize = 12;
                btnView.TextColor = UserCenterColor.Current.TextGrayColor1;
                frameTable.AddChidren(btnView);
                yy = btnView.Bottom;
            }
        }
        #endregion
        #region ■ 界面重新激活事件___________________
        /// <summary>
        /// <para>自身的上层界面关闭后,它自身处于最上层时,触发的事件</para>
        /// <para>重写的时候返回值请返回1(返回值是给底层使用的)</para>
        /// </summary>
        public virtual int FormActionAgainEvent()
        {
            return -1;
        }
        #endregion
        #region ■ 清空BodyFrame______________________
        /// <summary>
        /// 清空BodyFrame
        /// </summary>
@@ -440,17 +440,17 @@
            {
                return;
            }
            if (bodyFrameLayout == null || bodyFrameLayout.Parent == null)
            {
                return;
            if (bodyFrameLayout == null || bodyFrameLayout.Parent == null)
            {
                return;
            }
            bodyFrameLayout.RemoveAll();
        }
        }
        #endregion
        #region ■ 一般的方法_________________________
        /// <summary>
        /// 设置标题信息
        /// </summary>
@@ -470,8 +470,8 @@
            //移除返回键
            var back = (BackViewControl)topFrameLayout.GetTagByKey("btnBack");
            back?.RemoveFromParent();
        }
        }
        /// <summary>
        /// 获取返回键
        /// </summary>
@@ -480,8 +480,8 @@
            //移除返回键
            var back = (BackViewControl)topFrameLayout.GetTagByKey("btnBack");
            return back;
        }
        }
        #endregion
    }
}