gxc
2019-12-25 944b87b6bcccb095cd73f13f4410fb20faf48f74
ZigbeeApp/Shared/Phone/Device/Curtain/RollerShadeControl.cs
@@ -1,6 +1,7 @@
using System;
using Shared.Common;
using Shared.Phone.Device.CommonForm;
using Shared.Phone.Device.DeviceLogic;
using Shared.Phone.UserView;
using ZigBee.Device;
@@ -65,6 +66,29 @@
        /// StopBtn
        /// </summary>
        public Button StopBtn;
        /// <summary>
        /// 开合帘
        /// </summary>
        private CurtainSeekBar curtainSeekBar = new CurtainSeekBar { };
        /// <summary>
        /// 卷帘
        /// </summary>
        private CurtainRollSeekBar curtainRollSeekBar = new CurtainRollSeekBar { };
        /// <summary>
        /// IsDrawerLockMode
        /// </summary>
        public bool IsDrawerLockMode;
        /// <summary>
        /// ProgressBtn
        /// </summary>
        Button ProgressBtn;
        /// <summary>
        /// ProgressBtnY
        /// </summary>
        int ProgressBtnY;
        #endregion
        #region ◆ 接口___________________________
@@ -115,8 +139,14 @@
                                rollerShade.DeviceStatusReport = common.DeviceStatusReport;
                                rollerShade.WcdCurrentPositionLiftPercentage = common.DeviceStatusReport.AttriBute[0].AttriButeData;
                                StatuBtn.Text = $"{Language.StringByID(R.MyInternationalizationString.Current)} { deviceUI.GetDeviceStatu()}";
                                //SeekBar.Progress = rollerShade.WcdCurrentPositionLiftPercentage;
                                //seekBarTitle.Text = $"{SeekBar.Progress} %";
                                if(rollerShade.WcdType==0)
                                {
                                    curtainRollSeekBar.Progress = rollerShade.WcdCurrentPositionLiftPercentage;
                                }
                                else if(rollerShade.WcdType==4)
                                {
                                    curtainSeekBar.Progress = rollerShade.WcdCurrentPositionLiftPercentage;
                                }
                                rollerShade.LastDateTime = DateTime.Now;
                            }
                            else if (common.DeviceStatusReport.AttriBute[0].AttributeId == 0)
@@ -215,6 +245,10 @@
            //action();
            //action = null;
            RemoveUpdateControlDeviceStatuAction();
            if (IsDrawerLockMode)
            {
                CommonPage.Instance.IsDrawerLockMode = false;
            }
            base.RemoveFromParent();
        }
@@ -248,8 +282,7 @@
            {
                UserHomeView.ReadStatus(rollerShade, () =>
                {
                    rollerShade.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                    rollerShade.ReadWcdCurrentPositionLiftPercentage();
                    ReadDeviceAttributeLogic.Instance.SendCurtainStatuComand(device.CommonDevice);
                });
            }
            else
@@ -257,8 +290,7 @@
                //防止短时间内多次读取
                if ((DateTime.Now - rollerShade.LastDateTime).TotalSeconds > CommonPage.ReadDeviceStatuSpan)
                {
                    rollerShade.ReadWcdCurrentPositionLiftPercentage();
                    rollerShade.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                    ReadDeviceAttributeLogic.Instance.SendCurtainStatuComand(device.CommonDevice);
                }
            }
@@ -294,15 +326,6 @@
                RemoveFromParent();
            };
            var sharedBtn = new Button
            {
                X = Application.GetRealWidth(850),
                Width = Application.GetMinReal(69),
                Height = Application.GetMinReal(69),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "Item/Shared.png"
            };
            top.topView.AddChidren(sharedBtn);
            var moreBtn = new Button
            {
@@ -417,7 +440,6 @@
                (device.CommonDevice as Rollershade).CurtainUpDownStopControl(1);
            };
            SetRollerShadeIcon((device.CommonDevice as Rollershade).WcdType);
            if ((device.CommonDevice as Rollershade).WcdType == -1)
            {
                CommonPage.Loading.Start();
@@ -434,6 +456,9 @@
                })
                { IsBackground = true }.Start();
            }
            SetCurtainType(itemView, (device.CommonDevice as Rollershade).WcdType);
            var roomBG = new Button
            {
                Y = Application.GetRealHeight(1178 - 50),
@@ -486,28 +511,12 @@
            //upBtn.MouseUpEventHandler += Up;
            //stopBtn.MouseUpEventHandler += Stop;
            //downBtn.MouseUpEventHandler += Down;
            //SeekBar.ProgressChanged += SeekBar_ProgressChange;
            //collectionBtn.MouseUpEventHandler += Collection;
            //moreBtn.MouseUpEventHandler += More;
            //roomBtn.MouseUpEventHandler += BackToRoomHandler;
            //roomName.MouseUpEventHandler += BackToRoomHandler;
            collectionBtn.MouseUpEventHandler += Collection;
        }
        #endregion
        #region ◆ 控制___________________________
        /// <summary>
        /// 滑条移动发送命令
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param>
        private void SeekBar_ProgressChange(object sender, int mouseEventArgs)
        {
            //seekBarTitle.Text = $"{SeekBar.Progress}%";
            //(device.CommonDevice as ZigBee.Device.Rollershade).WcdGoToTiltValue(SeekBar.Progress);
        }
        #region ◆ 控制__________________________
        /// <summary>
        /// 上、开
@@ -645,11 +654,22 @@
        }
        /// <summary>
        /// SetCurtainType
        /// </summary>
        /// <param name="layout"></param>
        /// <param name="type"></param>
        private void SetCurtainType(FrameLayout layout, int type)
        {
            SetRollerShadeIcon(type);
            SetRollerSeekBar(layout, type);
        }
        /// <summary>
        /// WcdType=4:开合帘
        /// WcdType=0:卷帘
        /// </summary>
        /// <param name="type"></param>
        public void SetRollerShadeIcon(int type)
        private void SetRollerShadeIcon(int type)
        {
            if (type == 0)
            {
@@ -669,6 +689,94 @@
            }
        }
        /// <summary>
        /// SetRollerSeekBar
        /// </summary>
        /// <param name="layout"></param>
        /// <param name="type"></param>
        private void SetRollerSeekBar(FrameLayout layout,int type)
        {
            if(type == 0)
            {
                curtainRollSeekBar.Y = Application.GetRealHeight(300);
                curtainRollSeekBar.Width = Application.GetRealWidth(438);
                curtainRollSeekBar.Height = Application.GetRealHeight(576);
                curtainRollSeekBar.Gravity = Gravity.CenterHorizontal;
                curtainRollSeekBar.Progress = (device.CommonDevice as Rollershade).WcdCurrentPositionLiftPercentage;
                layout.AddChidren(curtainRollSeekBar);
                curtainRollSeekBar.IsProgressTextShow = false;
                //curtainRollSeekBar.OnStopTrackingTouchEvent += (sender, e) =>
                //{
                //    (device.CommonDevice as Rollershade).WcdGoToTiltValue(curtainRollSeekBar.Progress);
                //};
                curtainRollSeekBar.OnStartTrackingTouchEvent += (sender, e) =>
                {
                    OnProgressButtonMove(curtainRollSeekBar.Progress);
                    ProgressBtn.Visible = true;
                };
                curtainRollSeekBar.OnStopTrackingTouchEvent += (sender, e) =>
                {
                    ProgressBtn.Visible = false;
                };
                curtainRollSeekBar.OnProgressChangedEvent += (send2, e2) =>
                {
                    OnProgressButtonMove(e2);
                    //判断是否300ms屏蔽
                    if (curtainRollSeekBar.IsProgressChangeDelay()) return;
                    (device.CommonDevice as Rollershade).WcdGoToTiltValue(curtainRollSeekBar.Progress);
                };
                InitProgressBtn(layout);
            }
            else
            {
                curtainSeekBar.Y = Application.GetRealHeight(334);
                curtainSeekBar.Width = Application.GetRealWidth(570);
                curtainSeekBar.Height = Application.GetRealHeight(513);
                curtainSeekBar.Gravity = Gravity.CenterHorizontal;
                curtainSeekBar.Progress = (device.CommonDevice as Rollershade).WcdCurrentPositionLiftPercentage;
                layout.AddChidren(curtainSeekBar);
                curtainSeekBar.OnStopTrackingTouchEvent += (sender, e) =>
                {
                    (device.CommonDevice as Rollershade).WcdGoToTiltValue(curtainSeekBar.Progress);
                };
            }
        }
        /// <summary>
        /// 添加进度按钮
        /// </summary>
        private void InitProgressBtn(FrameLayout layout)
        {
            ProgressBtnY = curtainRollSeekBar.Y - Application.GetMinReal(204);
            ProgressBtn = new Button()
            {
                Y = ProgressBtnY,
                Width = Application.GetMinReal(135),
                Height = Application.GetMinReal(104),
                UnSelectedImagePath = "Item/ProgressBubbles.png",
                Visible = false,
                Gravity = Gravity.CenterHorizontal
            };
            layout.AddChidren(ProgressBtn);
        }
        /// <summary>
        /// OnProgressButtonMove
        /// </summary>
        private void OnProgressButtonMove(int mProgress)
        {
            ProgressBtn.Y = ProgressBtnY + curtainRollSeekBar.NowProgressY;
            ProgressBtn.Text = mProgress + "%";
        }
        #endregion
        #region ◆ 收藏到主页_______________________
@@ -680,15 +788,14 @@
        /// <param name="e">E.</param>
        private void Collection(object sender, MouseEventArgs e)
        {
            //collection
            if (collectionBtn.IsSelected)
            {
                Shared.Common.Room.Lists[0].DeleteDevice(device.FileName);
                Common.Room.CurrentRoom.GetLoveRoom().DeleteDevice(device.FileName);
                collectionBtn.IsSelected = false;
            }
            else
            {
                Shared.Common.Room.Lists[0].AddDevice(device.FileName);
                Common.Room.CurrentRoom.GetLoveRoom().AddDevice(device.FileName);
                collectionBtn.IsSelected = true;
            }
        }