xm
2021-12-01 6d73bf6e816570291865674bef8bce8972e4de3f
HDL_ON/UI/UI2/FuntionControlView/ArmCenter/ArmCenterPage.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
@@ -10,12 +11,48 @@
        /// <summary>
        /// 主窗体
        /// </summary>
        FrameLayout bodyView;
        public static ArmCenterPage bodyView;
        /// <summary>
        /// 自定义布防区域
        /// </summary>
        HorizontalScrolViewLayout customDeploymentView;
        /// <summary>
        ///
        /// </summary>
        FrameLayout alarmIconBgView;
        //安防状态背景图
        Button btnArmTipIcon;
        /// <summary>
        /// 安防警报图标
        /// </summary>
        Button btnInalarmIcon;
        /// <summary>
        /// 当前布防名称
        /// </summary>
        Button btnDefenseName;
        /// <summary>
        /// 撤防区域
        /// </summary>
        FrameLayout disarmView;
        /// <summary>
        /// 布防接口
        /// </summary>
        SecurityAlarm InDefenseMode = null;
        /// <summary>
        /// 自定义布防控件列表
        /// </summary>
        List<ArmDiyView> armDiyViewList = new List<ArmDiyView>();
        Action refreshAction = null;
        public ArmCenterPage(Action action)
        {
            refreshAction = action;
            bodyView = this;
        }
        public ArmCenterPage()
        {
            bodyView = this;
@@ -43,16 +80,52 @@
                Height =Application.GetRealWidth(32),
            });
            //安防状态背景图
            Button btnArmTipIcon = new Button()
            alarmIconBgView = new FrameLayout()
            {
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(198),
                Height = Application.GetRealWidth(198),
            };
            contentView.AddChidren(alarmIconBgView);
            btnArmTipIcon = new Button()
            {
                //Gravity = Gravity.CenterHorizontal,
                //Width = Application.GetRealWidth(198),
                //Height = Application.GetRealWidth(198),
                UnSelectedImagePath = "FunctionIcon/ArmCenter/NoDefenseBigIcon.png",
                SelectedImagePath = "FunctionIcon/ArmCenter/InDefenseBigIcon.png",
            };
            contentView.AddChidren(btnArmTipIcon);
            alarmIconBgView.AddChidren(btnArmTipIcon);
            btnInalarmIcon = new Button()
            {
                Width = Application.GetRealWidth(198),
                Height = Application.GetRealWidth(198),
                UnSelectedImagePath = "FunctionIcon/ArmCenter/InAlarmBigIcon.png",
            };
            btnInalarmIcon.MouseUpEventHandler = (sender, e) => {
                if(InDefenseMode!= null)
                {
                    Action action = () =>
                    {
                        InDefenseMode.alarm = false;
                        Control.Ins.ControlSecurity(InDefenseMode, "enable");
                    };
                    new PublicAssmebly().TipOptionMsg(StringId.Tip, StringId.ClearTheSecurityAlarmTip, action);
                }
            };
            btnDefenseName = new Button()
            {
                Y = Application.GetRealWidth(117),
                Height = Application.GetRealHeight(81),
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextColor =  CSS_Color.MainBackgroundColor,
            };
            alarmIconBgView.AddChidren(btnDefenseName);
            contentView.AddChidren(new Button()
            {
@@ -61,26 +134,31 @@
            #region 撤防区域
            var disarmView = new FrameLayout()
            Button btnDisarm;
            disarmView = new FrameLayout()
            {
                Height = 0,
            };
            contentView.AddChidren(disarmView);
            var btnDisarm = new Button()
            btnDisarm = new Button()
            {
                Width = Application.GetRealWidth(120),
                Height = Application.GetRealHeight(44),
                BackgroundColor = CSS_Color.WarningColor,
                Y = Application.GetRealHeight(10),
                Width = Application.GetRealWidth(148),
                Height = Application.GetRealHeight(40),
                BackgroundColor = CSS_Color.MainColor,
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.MainBackgroundColor,
                Text = "撤防"
                TextID = StringId.chefang,// = "撤防",
                Radius = (uint)Application.GetRealWidth(20),
                Gravity = Gravity.CenterHorizontal,
            };
            disarmView.AddChidren(btnDisarm);
            btnDisarm.MouseUpEventHandler = (sender, e) => {
                if (SecurityCenter.Security.CurrentDefenseMode != null)
                if(InDefenseMode!= null)
                {
                    Control.Ins.ControlSecurity(SecurityCenter.Security.CurrentDefenseMode, "disable");
                    Control.Ins.ControlSecurity(InDefenseMode, "disable");
                }
            };
@@ -107,8 +185,6 @@
                ScrollEnabled = false,
            };
            contentView.AddChidren(customDeploymentView);
            iniCustomDeploymentView();
            #endregion
@@ -182,11 +258,34 @@
            #endregion
            iniCustomDeploymentView();
        }
        /// <summary>
        /// 初始化报警状态
        /// </summary>
        /// <param name="inAlarm"></param>
        public void InitAlarmStatus(bool inAlarm)
        {
            try
            {
                if (inAlarm)
                {
                    if (btnInalarmIcon.Parent == null)
                    {
                        alarmIconBgView.AddChidren(btnInalarmIcon);
                    }
                }
                else
                {
                    if (btnInalarmIcon.Parent != null)
                    {
                        btnInalarmIcon.RemoveFromParent();
                    }
                }
            }
            catch { }
        }
        /// <summary>
@@ -195,23 +294,32 @@
        private void iniCustomDeploymentView()
        {
            customDeploymentView.RemoveAll();
            armDiyViewList.Clear();
            foreach (var mode in FunctionList.List.securities)
            {
                var armDiyView = new ArmDiyView("FunctionIcon/ArmCenter/AddDefenseIcon.png", "FunctionIcon/ArmCenter/AddDefenseIcon.png",
                mode.name);
                var armDiyView = new ArmDiyView("FunctionIcon/ArmCenter/AtHomeDefenseIcon.png", "FunctionIcon/ArmCenter/AtHomeDefenseIconOn.png",
                mode.name,mode.sid);
                customDeploymentView.AddChidren(armDiyView);
                EventHandler<MouseEventArgs> event2 = (sender, e) =>
                        {
                            ShowArmDialog(mode);
                        };
                {
                    ShowArmDialog(mode);
                };
                armDiyView.SetClickEvent(event2);
                if (mode.status == "enable")
                {
                    armDiyView.LightingView(true);
                    InDefenseMode = mode;
                    ///刷新界面
                    LoadEvent_RefreshSecurityStatus(InDefenseMode);
                }
                armDiyViewList.Add(armDiyView);
            }
            if (FunctionList.List.securities.Count < 4)
            {
                var view = new ArmDiyView("FunctionIcon/ArmCenter/AddDefenseIcon.png", "FunctionIcon/ArmCenter/AddDefenseIcon.png",
                  Language.StringByID(StringId.Custom));
                  Language.StringByID(StringId.Custom),"customSid");
                customDeploymentView.AddChidren(view);
                EventHandler<MouseEventArgs> event1 = (sender, e) =>
                {
@@ -293,8 +401,19 @@
            dialog.Show();
            if(alarm.status == "enable")
            {
                btnOpen.TextColor = CSS_Color.PromptingColor1;
                btnOpen.Text = Language.StringByID(StringId.AlreadyOpened).Trim() ;
            }
            btnOpen.MouseUpEventHandler = (sender, e) => {
                Control.Ins.ControlSecurity(alarm,  "enable");
                string controlStatus = alarm.status == "disable" ? "enable" : "disable";
                new System.Threading.Thread(() =>
                {
                    Control.Ins.ControlSecurity(alarm, controlStatus);
                })
                { IsBackground = true }.Start();
                dialog.Close();  
            };
@@ -305,7 +424,7 @@
                {
                    iniCustomDeploymentView();
                };
                var armSetPage = new ArmDeploymentSettingPage(alarm,refreshAction);
                var armSetPage = new AddAlarmDeploymentPage(alarm,refreshAction);
                MainPage.BasePageView.AddChidren(armSetPage);
                armSetPage.LoadPage();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
@@ -318,7 +437,73 @@
        }
        public static void LoadEvent_RefreshSecurityStatus(SecurityAlarm updataTemp)
        {
            Application.RunOnMainThread(() =>
            {
                try
                {
                    if (bodyView != null)
                    {
                        bodyView.refreshAction?.Invoke();
                        //布防
                        if (updataTemp.status == "enable")
                        {
                            bodyView.InDefenseMode = updataTemp;
                            foreach (var tempView in bodyView.armDiyViewList)
                            {
                                tempView.LightingView(false);
                                if (tempView.sid == updataTemp.sid)
                                {
                                    tempView.LightingView(updataTemp.status == "enable");
                                }
                            }
                        }
                        else
                        {
                            //撤防
                            if(bodyView.InDefenseMode.sid == updataTemp.sid)
                            {
                                foreach (var tempView in bodyView.armDiyViewList)
                                {
                                    tempView.LightingView(false);
                                }
                            }
                        }
                        //foreach(var tempView in bodyView.armDiyViewList)
                        //{
                        //    tempView.LightingView(false);
                        //    if(tempView.sid == updataTemp.sid)
                        //    {
                        //        tempView.LightingView(updataTemp.status == "enable");
                        //    }
                        //}
                        //没有布防的情况
                        if (bodyView.InDefenseMode ==null|| bodyView.InDefenseMode.status == "disable")
                        {
                            bodyView.disarmView.Height = 0;
                            bodyView.btnArmTipIcon.IsSelected = false;
                            bodyView.btnDefenseName.Text = "";
                        }
                        else
                        {
                            bodyView.disarmView.Height = Application.GetRealHeight(68);
                            bodyView.btnArmTipIcon.IsSelected = true;
                            bodyView.btnDefenseName.Text = bodyView.InDefenseMode.name;
                        }
                        bodyView.InitAlarmStatus(bodyView.InDefenseMode.alarm);
                    }
                }
                catch (Exception ex)
                {
                    MainPage.Log($"安防界面更新异常:{ex.Message}");
                }
            });
        }
    }
@@ -329,14 +514,16 @@
    {
        Button btnIcon;
        Button btnText;
        public string sid;
        /// <summary>
        /// 自定义布防界面
        /// </summary>
        /// <param name="UnSelectedIconPath">图片路径</param>
        /// <param name="SelectedIconPath">图片路径</param>
        /// <param name="Text">显示文本</param>
        public ArmDiyView(string UnSelectedIconPath, string SelectedIconPath, string Text)
        public ArmDiyView(string UnSelectedIconPath, string SelectedIconPath, string Text,string inSid)
        {
            sid = inSid;
            this.Width = Application.GetRealWidth(82);
            this.Height = Application.GetRealWidth(80);
@@ -369,9 +556,20 @@
            btnText.MouseUpEventHandler = eventHandler;
        }
        /// <summary>
        /// 点亮区域
        /// </summary>
        public void LightingView(bool seleted)
        {
            btnIcon.IsSelected = seleted;
        }
    }
    /// <summary>
    /// 固定布防控件
    /// </summary>
    public class FixedArmView : FrameLayout
    {
        /// <summary>