WJC
2020-03-23 bba578c2f0acf2eca747edcb69426771e0cadd32
ZigbeeApp/Shared/Phone/MainPage/Controls/DeviceCard/Base/DeviceCardCommon.cs
@@ -14,6 +14,10 @@
        #region ■ 变量声明___________________________
        /// <summary>
        /// 设备对象
        /// </summary>
        public CommonDevice device = null;
        /// <summary>
        /// 卡片需要被移除的事件
        /// </summary>
        public Action CardNeedRemoveEvent = null;
@@ -28,7 +32,7 @@
        /// <summary>
        /// 设备的背景圆圈图控件
        /// </summary>
        private NormalViewControl btnDeviceRound = null;
        private FrameLayout fraDeviceRound = null;
        /// <summary>
        /// 设备图标控件
        /// </summary>
@@ -42,9 +46,17 @@
        /// </summary>
        private PicViewControl btnSwitch = null;
        /// <summary>
        /// 收集控件
        /// </summary>
        private IconViewControl btnCollect = null;
        /// <summary>
        /// 是否获取网关反馈的结果  0:没有获取得到  1:已经获取得到
        /// </summary>
        private int ResponeResult = 0;
        /// <summary>
        /// 判断是否有开关功能
        /// </summary>
        private bool isHadOpenSwitch = true;
        #endregion
@@ -69,6 +81,7 @@
        /// <param name="i_device">指定设备</param>
        public virtual void InitControl(CommonDevice i_device)
        {
            this.device = i_device;
            //背景图片
            this.btnBackGroud = new PicViewControl(this.Width, this.Height, false);
            btnBackGroud.UnSelectedImagePath = "Item/FunctionCardView.png";
@@ -87,7 +100,7 @@
            this.AddChidren(btnDeviceName, ChidrenBindMode.BindEventOnly);
            //收集控件
            var btnCollect = new IconViewControl(107);
            this.btnCollect = new IconViewControl(107);
            btnCollect.X = Application.GetMinRealAverage(350);
            btnCollect.Y = Application.GetMinRealAverage(12);
            btnCollect.UnSelectedImagePath = "Item/Collection1.png";
@@ -116,19 +129,20 @@
            };
            //设备的背景圆圈图
            this.btnDeviceRound = new NormalViewControl(Application.GetMinRealAverage(124), Application.GetMinRealAverage(124), false);
            btnDeviceRound.Radius = (uint)Application.GetMinRealAverage(124) / 2;
            btnDeviceRound.X = Application.GetMinRealAverage(44);
            btnDeviceRound.Y = Application.GetMinRealAverage(101);
            btnDeviceRound.BackgroundColor = Common.ZigbeeColor.Current.GXCForFunctionUnSelectedBackgroundColor;
            btnDeviceRound.SelectedBackgroundColor = Common.ZigbeeColor.Current.GXCForFunctionBackgroundColor;
            this.AddChidren(btnDeviceRound, ChidrenBindMode.BindEventOnly);
            this.fraDeviceRound = new FrameLayout();
            fraDeviceRound.Width = Application.GetMinRealAverage(124);
            fraDeviceRound.Height = Application.GetMinRealAverage(124);
            fraDeviceRound.Radius = (uint)Application.GetMinRealAverage(124) / 2;
            fraDeviceRound.X = Application.GetMinRealAverage(44);
            fraDeviceRound.Y = Application.GetMinRealAverage(101);
            fraDeviceRound.BackgroundColor = Common.ZigbeeColor.Current.GXCForFunctionUnSelectedBackgroundColor;
            this.AddChidren(fraDeviceRound, ChidrenBindMode.BindEventOnly);
            //设备图标控件
            this.btnDeviceIcon = new IconViewControl(86);
            btnDeviceIcon.X = Application.GetMinRealAverage(63);
            btnDeviceIcon.Y = Application.GetMinRealAverage(121);
            this.AddChidren(btnDeviceIcon, ChidrenBindMode.BindEventOnly);
            btnDeviceIcon.Gravity = Gravity.Center;
            fraDeviceRound.AddChidren(btnDeviceIcon);
            this.ChangedChidrenBindMode(fraDeviceRound, ChidrenBindMode.BindEventOnly);
            //状态文本控件
            this.btnStatu = new NormalViewControl(Application.GetMinRealAverage(280), Application.GetMinRealAverage(63), false);
@@ -145,8 +159,6 @@
            btnSwitch.Y = Application.GetMinRealAverage(202);
            btnSwitch.UnSelectedImagePath = "Item/Switch1.png";
            btnSwitch.SelectedImagePath = "Item/SwitchSelected1.png";
            this.AddChidren(this.btnSwitch, ChidrenBindMode.NotBind);
            btnSwitch.Visible = false;
            //刷新信息
            this.RefreshControlInfo(i_device);
@@ -162,7 +174,7 @@
        /// <returns></returns>
        public PicViewControl AddSwitchControl()
        {
            btnSwitch.Visible = true;
            this.AddChidren(this.btnSwitch, ChidrenBindMode.NotBind);
            return btnSwitch;
        }
@@ -176,21 +188,27 @@
        /// <param name="i_device">设备对象,不是推送的那个</param>
        public void RefreshControlInfo(CommonDevice i_device)
        {
            //设备状态必须刷新
            this.btnStatu.Text = HdlDeviceOtherLogic.Current.GetDeviceStatu(i_device);
            bool collect = HdlRoomLogic.Current.IsCollectInRoom(i_device);
            if (btnCollect.IsSelected != collect)
            {
                btnCollect.IsSelected = collect;
            }
            //设备图标也刷新
            Common.LocalDevice.Current.SetDeviceIconToControl(btnDeviceIcon, i_device);
            Common.LocalDevice.Current.SetDeviceIconToControl2(btnDeviceIcon, i_device);
            //检测设备是否是打开状态
            bool isOpen = this.CheckIsOpenStatu(i_device);
            this.SetCardStatu(isOpen);
            this.SetCardOpenStatu(isOpen);
        }
        /// <summary>
        /// 设置卡片状态
        /// </summary>
        /// <param name="isOpen"></param>
        public void SetCardStatu(bool isOpen)
        public void SetCardOpenStatu(bool isOpen)
        {
            //设备状态必须刷新
            this.btnStatu.Text = HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device);
            if (this.btnBackGroud.IsSelected == isOpen)
            {
                //状态一样,则不需要处理
@@ -202,13 +220,37 @@
            this.btnDeviceName.IsSelected = isOpen;
            this.btnDeviceName.IsBold = isOpen;
            //设备的背景圆圈图
            this.btnDeviceRound.IsSelected = isOpen;
            if (isOpen == true)
            {
                fraDeviceRound.BackgroundColor = Common.ZigbeeColor.Current.GXCForFunctionBackgroundColor;
            }
            else
            {
                fraDeviceRound.BackgroundColor = Common.ZigbeeColor.Current.GXCForFunctionUnSelectedBackgroundColor;
            }
            //设备图标控件
            this.btnDeviceIcon.IsSelected = isOpen;
            //状态文本控件
            this.btnStatu.IsSelected = isOpen;
            //开关控件
            if (btnSwitch != null)
            {
            this.btnSwitch.IsSelected = isOpen;
            }
        }
        /// <summary>
        /// 设置卡片的在线状态
        /// </summary>
        /// <param name="isOnline">在线</param>
        public void SetCardOnlineStatu(bool isOnline)
        {
            if (this.isHadOpenSwitch == true)
            {
                //如果这个设备有开关功能,则在线状态不会改变状态
                return;
            }
            this.SetCardOpenStatu(isOnline);
        }
        /// <summary>
@@ -227,8 +269,7 @@
        /// <summary>
        /// 发送获取状态命令
        /// </summary>
        /// <param name="i_device"></param>
        public virtual void SendStatuComand(CommonDevice i_device)
        public virtual void SendStatuComand()
        {
            return;
        }
@@ -244,6 +285,8 @@
        /// <returns></returns>
        public virtual bool CheckIsOpenStatu(CommonDevice i_device)
        {
            //如果这个函数被重写的话,则代表这个设备有开关功能
            this.isHadOpenSwitch = false;
            //默认用在线状态来判断
            return i_device.IsOnline == 1;
        }
@@ -290,9 +333,12 @@
        public void StartCheckResponeResult(bool oldOpenStatu)
        {
            this.ResponeResult = 0;
            //开关按钮不能再点击
            if (btnSwitch != null) { this.btnSwitch.CanClick = false; }
            HdlThreadLogic.Current.RunThread(() =>
            {
                int waitime = 30 * 100;
                int waitime = 30;
                while (waitime > 0)
                {
                    System.Threading.Thread.Sleep(100);
@@ -301,6 +347,7 @@
                        //已经获取得到数据
                        break;
                    }
                    waitime--;
                }
                if (waitime <= 0)
                {
@@ -310,9 +357,11 @@
                        var msgContr = new ShowMsgControl(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.FAIL));
                        msgContr.Show();
                        //变更回原来的状态
                        this.SetCardStatu(oldOpenStatu);
                        this.SetCardOpenStatu(oldOpenStatu);
                    });
                }
                //开关按钮不能再点击
                if (btnSwitch != null) { this.btnSwitch.CanClick = true; }
            });
        }
@@ -326,6 +375,29 @@
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 检测能否发送获取状态命令
        /// </summary>
        /// <returns></returns>
        public bool CheckCanSendStatuComand()
        {
            if (this.device.HadReadDeviceStatu == false)
            {
                //还没有读取过数据
                return true;
            }
            if ((DateTime.Now - this.device.LastDateTime).TotalMinutes >= 10)
            {
                //10分钟后可以再次获取
                return true;
            }
            return false;
        }
        #endregion
        #region ■ 控件摧毁___________________________
        /// <summary>