using Shared.Common; using Shared.Phone.UserCenter; using System; using System.Collections.Generic; using System.Text; using ZigBee.Device; namespace Shared.Phone.MainPage.ControlForm { /// /// 窗帘类型的深度卡片界面 /// public class DeviceCurtainDetailCardForm : DeviceDetailCardCommonForm { #region ■ 变量声明___________________________ /// /// 打开控件 /// private IconBigViewControl btnOpen = null; /// /// 停止控件 /// private IconBigViewControl btnStop = null; /// /// 关闭控件 /// private IconBigViewControl btnClose = null; /// /// 窗帘类型 4:开合帘 0:卷帘 /// private int WcdType = -2; /// /// 开合帘控件 /// private CurtainSeekBar SeekBarOpenCurtain = null; /// /// 卷帘控件 /// private CurtainRollSeekBar SeekBarSiphonateCurtain = null; /// /// 进度值是否在改变中 /// private bool isProgressing = false; /// /// 是否已经初始化了控件(因为底层有可能会刷新整个界面) /// private bool hadInitControl = false; #endregion #region ■ 初始化_____________________________ /// /// 底层初始化中部控件完成之后 /// /// 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 ■ 初始化卷帘控件_____________________ /// /// 初始化卷帘控件 /// 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 ■ 初始化开合帘控件___________________ /// /// 初始化开合帘控件 /// 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 ■ 发送窗帘命令_______________________ /// /// 发送窗帘命令 /// /// private void SetCurtainCommand(int comand) { //在没有接收到反馈之前,不能再点击 this.btnClose.CanClick = false; this.btnOpen.CanClick = false; this.btnStop.CanClick = false; //检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息 this.StartCheckResponeResult(new List(), (result) => { //时间结束,可以再次点击 this.btnClose.CanClick = true; this.btnOpen.CanClick = true; this.btnStop.CanClick = true; }); //发送命令 ((Rollershade)device).CurtainUpDownStopControl(comand); } #endregion #region ■ 是否获取网关反馈的结果_____________ /// /// 检测网关的反馈结果(属性上报的对象:device.DeviceStatusReport) /// /// 命令区分 /// 上报数据 /// 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 } }