xm
2020-07-20 b02e8275a21dc06bf54b66273485d44e007a2616
ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceCurtainDetailCardForm.cs
New file
@@ -0,0 +1,424 @@
using Shared.Common;
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.MainPage.ControlForm
{
    /// <summary>
    /// 窗帘类型的深度卡片界面
    /// </summary>
    public class DeviceCurtainDetailCardForm : DeviceDetailCardCommonForm
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 打开控件
        /// </summary>
        private IconBigViewControl btnOpen = null;
        /// <summary>
        /// 停止控件
        /// </summary>
        private IconBigViewControl btnStop = null;
        /// <summary>
        /// 关闭控件
        /// </summary>
        private IconBigViewControl btnClose = null;
        /// <summary>
        /// 窗帘类型 4:开合帘 0:卷帘
        /// </summary>
        private int WcdType = -2;
        /// <summary>
        /// 开合帘控件
        /// </summary>
        private CurtainSeekBar SeekBarOpenCurtain = null;
        /// <summary>
        /// 卷帘控件
        /// </summary>
        private CurtainRollSeekBar SeekBarSiphonateCurtain = null;
        /// <summary>
        /// 进度值是否在改变中
        /// </summary>
        private bool isProgressing = false;
        /// <summary>
        /// 是否已经初始化了控件(因为底层有可能会刷新整个界面)
        /// </summary>
        private bool hadInitControl = false;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 底层初始化中部控件完成之后
        /// </summary>
        /// <param name="frameWhiteBack"></param>
        public override void InitMiddleFrameAfter(FrameLayout frameWhiteBack)
        {
            //左滑不能
            this.ScrollEnabled = false;
            this.WcdType = ((Rollershade)this.device).WcdType;
            //设置状态文字
            this.SetStatuText(HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
            if (WcdType == 0)
            {
                //初始化卷帘控件
                this.InitSiphonateCurtainControl(frameWhiteBack);
            }
            else
            {
                //初始化开合帘控件
                this.InitOpenCurtainControl(frameWhiteBack);
            }
            //打开控件
            this.btnOpen = new IconBigViewControl(81, 81);
            btnOpen.btnIcon.UseClickStatu = true;
            frameWhiteBack.AddChidren(btnOpen);
            btnOpen.InitControl();
            btnOpen.X = Application.GetRealWidth(253) - btnOpen.XOffset;
            btnOpen.Y = Application.GetRealHeight(994) - btnOpen.YOffset;
            btnOpen.ButtonClickEvent += (sender, e) =>
            {
                //如果住宅为虚拟住宅,则此功能无效
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    ((Rollershade)device).WcdCurrentPositionLiftPercentage = 100;
                    if (this.WcdType == 0)
                    {
                        SeekBarSiphonateCurtain.Progress = 100;
                    }
                    else
                    {
                        SeekBarOpenCurtain.Progress = 100;
                    }
                    //设置状态文字
                    this.SetStatuText(HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
                    return;
                }
                //发送窗帘命令
                this.SetCurtainCommand(0);
            };
            //停止控件
            this.btnStop = new IconBigViewControl(81, 81);
            btnStop.btnIcon.UseClickStatu = true;
            btnStop.UnSelectedImagePath = "RollerShade/Stop.png";
            btnStop.SelectedImagePath = "RollerShade/StopSelected.png";
            frameWhiteBack.AddChidren(btnStop);
            btnStop.InitControl();
            btnStop.X = btnOpen.Right + Application.GetRealWidth(109) - btnOpen.XOffset;
            btnStop.Y = btnOpen.Y;
            btnStop.ButtonClickEvent += (sender, e) =>
            {
                //如果住宅为虚拟住宅,则此功能无效
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    return;
                }
                //发送窗帘命令
                this.SetCurtainCommand(2);
            };
            //关闭
            this.btnClose = new IconBigViewControl(81, 81);
            btnClose.btnIcon.UseClickStatu = true;
            frameWhiteBack.AddChidren(btnClose);
            btnClose.InitControl();
            btnClose.X = btnStop.Right + Application.GetRealWidth(109) - btnOpen.XOffset;
            btnClose.Y = btnOpen.Y;
            btnClose.ButtonClickEvent += (sender, e) =>
            {
                //如果住宅为虚拟住宅,则此功能无效
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    ((Rollershade)device).WcdCurrentPositionLiftPercentage = 0;
                    if (this.WcdType == 0)
                    {
                        SeekBarSiphonateCurtain.Progress = 0;
                    }
                    else
                    {
                        SeekBarOpenCurtain.Progress = 0;
                    }
                    //设置状态文字
                    this.SetStatuText(HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
                    return;
                }
                //发送窗帘命令
                this.SetCurtainCommand(1);
            };
            if (this.WcdType == 0)
            {
                btnOpen.UnSelectedImagePath = "RollerShade/Up.png";
                btnOpen.SelectedImagePath = "RollerShade/UpSelected.png";
                btnClose.UnSelectedImagePath = "RollerShade/Down.png";
                btnClose.SelectedImagePath = "RollerShade/DownSelected.png";
            }
            else
            {
                btnOpen.UnSelectedImagePath = "RollerShade/Open.png";
                btnOpen.SelectedImagePath = "RollerShade/OpenSelected.png";
                btnClose.UnSelectedImagePath = "RollerShade/Close.png";
                btnClose.SelectedImagePath = "RollerShade/CloseSelected.png";
            }
        }
        #endregion
        #region ■ 初始化卷帘控件_____________________
        /// <summary>
        /// 初始化卷帘控件
        /// </summary>
        private void InitSiphonateCurtainControl(FrameLayout frameWhiteBack)
        {
            //卷帘控件
            this.SeekBarSiphonateCurtain = new CurtainRollSeekBar();
            SeekBarSiphonateCurtain.Y = Application.GetRealHeight(300);
            SeekBarSiphonateCurtain.Width = this.GetPictrueRealSize(438);
            SeekBarSiphonateCurtain.Height = this.GetPictrueRealSize(576);
            SeekBarSiphonateCurtain.Gravity = Gravity.CenterHorizontal;
            SeekBarSiphonateCurtain.Progress = (device as Rollershade).WcdCurrentPositionLiftPercentage;
            frameWhiteBack.AddChidren(SeekBarSiphonateCurtain);
            SeekBarSiphonateCurtain.IsProgressTextShow = false;
            SeekBarSiphonateCurtain.CurtainPaddingTop = Application.GetRealHeight(110);
            //卷帘控件里面的那个显示百分比的控件
            int progressY = SeekBarSiphonateCurtain.Y - Application.GetMinReal(204);
            var btnProgress = new NormalViewControl(Application.GetMinReal(135), Application.GetMinReal(104), false);
            btnProgress.Y = progressY;
            btnProgress.UnSelectedImagePath = "Item/ProgressBubbles.png";
            btnProgress.IsBold = true;
            btnProgress.TextColor = UserCenterColor.Current.White;
            btnProgress.Gravity = Gravity.CenterHorizontal;
            btnProgress.TextAlignment = TextAlignment.Center;
            frameWhiteBack.AddChidren(btnProgress);
            btnProgress.Visible = false;
            //开始滑动事件
            SeekBarSiphonateCurtain.OnStartTrackingTouchEvent += (sender, e) =>
            {
                //进度值开始变更
                this.isProgressing = true;
                //变更进度百分比的显示
                btnProgress.Y = progressY + SeekBarSiphonateCurtain.NowProgressY;
                btnProgress.Text = SeekBarSiphonateCurtain.Progress + "%";
                if (btnProgress.Visible == false)
                {
                    btnProgress.Visible = true;
                }
            };
            //结束滑动事件
            SeekBarSiphonateCurtain.OnStopTrackingTouchEvent += (sender, e) =>
            {
                //进度值开始结束
                this.isProgressing = false;
                btnProgress.Visible = false;
            };
            //滑动过程中
            int oldProgressValue = SeekBarSiphonateCurtain.Progress;//之前的值
            int nowProgressValue = oldProgressValue;//变更的值
            SeekBarSiphonateCurtain.OnProgressChangedEvent += (send2, value) =>
            {
                //变更进度百分比的显示
                btnProgress.Y = progressY + SeekBarSiphonateCurtain.NowProgressY;
                btnProgress.Text = value + "%";
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    nowProgressValue = value;
                }
                else
                {
                    //如果住宅为虚拟住宅,直接改缓存
                    (device as Rollershade).WcdCurrentPositionLiftPercentage = value;
                }
            };
            if (this.hadInitControl == true)
            {
                //已经完成初始化
                return;
            }
            this.hadInitControl = true;
            //开一个线程,监视是否滑动的滑动条,每秒检测一次
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (this.Parent != null)
                {
                    System.Threading.Thread.Sleep(1000);
                    if (nowProgressValue == oldProgressValue)
                    {
                        //值一样
                        continue;
                    }
                    oldProgressValue = nowProgressValue;
                    //发送进度值
                    (device as Rollershade).WcdGoToTiltValue(oldProgressValue);
                }
            });
        }
        #endregion
        #region ■ 初始化开合帘控件___________________
        /// <summary>
        /// 初始化开合帘控件
        /// </summary>
        private void InitOpenCurtainControl(FrameLayout frameWhiteBack)
        {
            //开合帘控件
            this.SeekBarOpenCurtain = new CurtainSeekBar();
            SeekBarOpenCurtain.Y = Application.GetRealHeight(334);
            SeekBarOpenCurtain.Width = this.GetPictrueRealSize(570);
            SeekBarOpenCurtain.Height = this.GetPictrueRealSize(513);
            SeekBarOpenCurtain.Gravity = Gravity.CenterHorizontal;
            SeekBarOpenCurtain.IsProgressTextShow = false;
            SeekBarOpenCurtain.Progress = (device as Rollershade).WcdCurrentPositionLiftPercentage;
            frameWhiteBack.AddChidren(SeekBarOpenCurtain);
            //开合帘控件里面的那个显示百分比的控件
            int progressX = SeekBarOpenCurtain.X - Application.GetMinReal(20);
            var btnProgress = new NormalViewControl(Application.GetMinReal(135), Application.GetMinReal(104), false);
            btnProgress.X = progressX;
            btnProgress.Y = SeekBarOpenCurtain.Y + SeekBarOpenCurtain.Height / 2 - Application.GetMinReal(180);
            btnProgress.UnSelectedImagePath = "Item/ProgressBubbles.png";
            btnProgress.IsBold = true;
            btnProgress.TextColor = UserCenterColor.Current.White;
            btnProgress.TextAlignment = TextAlignment.Center;
            frameWhiteBack.AddChidren(btnProgress);
            btnProgress.Visible = false;
            //开始滑动的事件
            SeekBarOpenCurtain.OnStartTrackingTouchEvent += (sender, e) =>
            {
                //进度值开始变更
                this.isProgressing = true;
                btnProgress.X = progressX + SeekBarOpenCurtain.NowProgressX - Application.GetMinReal(5);
                btnProgress.Text = SeekBarOpenCurtain.Progress + "%";
                if (btnProgress.Visible == false)
                {
                    btnProgress.Visible = true;
                }
            };
            //结束滑动的事件
            SeekBarOpenCurtain.OnStopTrackingTouchEvent += (sender, e) =>
            {
                //进度值开始结束
                this.isProgressing = false;
                btnProgress.Visible = false;
            };
            //滑动过程中
            int oldProgressValue = SeekBarOpenCurtain.Progress;//之前的值
            int nowProgressValue = oldProgressValue;//变更的值
            SeekBarOpenCurtain.OnProgressChangedEvent += (sender, value) =>
            {
                btnProgress.X = progressX + SeekBarOpenCurtain.NowProgressX - Application.GetMinReal(5);
                btnProgress.Text = value + "%";
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    nowProgressValue = value;
                }
                else
                {
                    //如果住宅为虚拟住宅,直接修改缓存
                    (device as Rollershade).WcdCurrentPositionLiftPercentage = value;
                }
            };
            //开一个线程,监视是否滑动的滑动条,每秒检测一次
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (this.Parent != null)
                {
                    System.Threading.Thread.Sleep(1000);
                    if (nowProgressValue == oldProgressValue)
                    {
                        //值一样
                        continue;
                    }
                    oldProgressValue = nowProgressValue;
                    //发送进度值
                    (device as Rollershade).WcdGoToTiltValue(oldProgressValue);
                }
            });
        }
        #endregion
        #region ■ 发送窗帘命令_______________________
        /// <summary>
        /// 发送窗帘命令
        /// </summary>
        /// <param name="comand"></param>
        private void SetCurtainCommand(int comand)
        {
            //在没有接收到反馈之前,不能再点击
            this.btnClose.CanClick = false;
            this.btnOpen.CanClick = false;
            this.btnStop.CanClick = false;
            //检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息
            this.StartCheckResponeResult(new List<ButtonBase>(), (result) =>
            {
                //时间结束,可以再次点击
                this.btnClose.CanClick = true;
                this.btnOpen.CanClick = true;
                this.btnStop.CanClick = true;
            });
            //发送命令
            ((Rollershade)device).CurtainUpDownStopControl(comand);
        }
        #endregion
        #region ■ 是否获取网关反馈的结果_____________
        /// <summary>
        /// 检测网关的反馈结果(属性上报的对象:device.DeviceStatusReport)
        /// </summary>
        /// <param name="comandDiv">命令区分</param>
        /// <param name="report">上报数据</param>
        /// <returns></returns>
        public override bool CheckResponeResultStatu(ReceiveComandDiv comandDiv, CommonDevice report)
        {
            if (comandDiv == ReceiveComandDiv.A设备属性上报)
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //设置状态文字
                    this.SetStatuText(HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
                    if (this.isProgressing == false)
                    {
                        //当进度值在手动变更中时,不接收推送
                        if (this.WcdType == 0)
                        {
                            SeekBarSiphonateCurtain.Progress = (device as Rollershade).WcdCurrentPositionLiftPercentage;
                        }
                        else
                        {
                            SeekBarOpenCurtain.Progress = (device as Rollershade).WcdCurrentPositionLiftPercentage;
                        }
                    }
                });
                return true;
            }
            return false;
        }
        #endregion
    }
}