HDL Home App 第二版本 旧平台金堂用 正在使用
hxb
2022-08-30 25429f085093d89d543a0b90e30d0d62d1b7dac9
ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceColorLightDetailCardForm.cs
@@ -19,10 +19,6 @@
        /// </summary>
        private List<ButtonBase> listControl = new List<ButtonBase>();
        /// <summary>
        /// MaxLevel
        /// </summary>
        private const int MaxLevel = 254;
        /// <summary>
        /// 彩灯控件
        /// </summary>
        private WaveSeekBar waveSeekBar = null;
@@ -30,10 +26,6 @@
        /// 进度值是否在改变中
        /// </summary>
        private bool isProgressing = false;
        /// <summary>
        /// 能否发送进度值
        /// </summary>
        private bool canSetProgressValue = true;
        /// <summary>
        /// 是否已经初始化了控件(因为底层有可能会刷新整个界面)
        /// </summary>
@@ -57,8 +49,10 @@
            this.ScrollEnabled = false;
            //先清空
            this.listControl = new List<ButtonBase>();
            //设置初始状态
            this.IsLightOpen = ((LightBase)this.device).OnOffStatus == 1;
            //设置状态文字
            if (((LightBase)this.device).OnOffStatus == 1)
            if (this.IsLightOpen == true)
            {
                //亮度 XX
                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + "  " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
@@ -72,13 +66,21 @@
            //彩灯控件
            this.waveSeekBar = new WaveSeekBar();
            waveSeekBar.Y = Application.GetRealHeight(377);
            waveSeekBar.Width = Application.GetMinRealAverage(271);
            waveSeekBar.Height = Application.GetMinRealAverage(533);
            waveSeekBar.Width = this.GetPictrueRealSize(271);
            waveSeekBar.Height = this.GetPictrueRealSize(533);
            waveSeekBar.Gravity = Gravity.CenterHorizontal;
            waveSeekBar.WavePadding = Application.GetRealWidth(8);
            waveSeekBar.MaxValue = 100;
            waveSeekBar.Progress = (int)(((DimmableLight)this.device).Level * 1.0 / MaxLevel * 100);
            waveSeekBar.Progress = HdlDeviceCommonLogic.Current.CalculateLightLevelPersent(((DimmableLight)this.device).Level);
            waveSeekBar.CornerRadius = Application.GetRealHeight(58);
            if (this.IsLightOpen == true)
            {
                waveSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarColor_Start, ZigbeeColor.Current.GXCWaveSeekBarColor_End);
            }
            else
            {
                waveSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor, ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor);
            }
            frameWhiteBack.AddChidren(waveSeekBar);
            //开关
@@ -87,6 +89,7 @@
            btnSwitch.SelectedImagePath = "Item/SwitchSelected.png";
            btnSwitch.Y = waveSeekBar.Bottom + Application.GetRealHeight(84);
            btnSwitch.Gravity = Gravity.CenterHorizontal;
            btnSwitch.IsSelected = this.IsLightOpen;
            frameWhiteBack.AddChidren(btnSwitch);
            listControl.Add(btnSwitch);
            btnSwitch.ButtonClickEvent += (sender, e) =>
@@ -94,21 +97,6 @@
                //发送开关命令
                this.SetSwitchCommand(!btnSwitch.IsSelected);
            };
            //设置初始状态
            this.IsLightOpen = ((LightBase)this.device).OnOffStatus == 1;
            this.canSetProgressValue = this.IsLightOpen;
            if (IsLightOpen == true)
            {
                btnSwitch.IsSelected = true;
                waveSeekBar.IsClickable = true;
                waveSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarColor_Start, ZigbeeColor.Current.GXCWaveSeekBarColor_End);
            }
            else
            {
                waveSeekBar.IsClickable = false;
                waveSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor, ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor);
            }
            //彩灯控件里面的那个显示百分比的控件
            int progressY = waveSeekBar.Y - Application.GetMinReal(154);
@@ -154,7 +142,17 @@
                //变更进度百分比的显示
                btnProgress.Y = progressY + waveSeekBar.NowProgressY;
                btnProgress.Text = value + "%";
                nowProgressValue = value;
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    nowProgressValue = value;
                }
                else
                {
                    //如果住宅为虚拟住宅,直接改缓存
                    ((DimmableLight)this.device).Level = HdlDeviceCommonLogic.Current.CalculateLightLevel(value);
                    //亮度 XX
                    this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + "  " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
                }
            };
            if (this.hadInitControl == true)
@@ -164,21 +162,26 @@
            }
            this.hadInitControl = true;
            if (Config.Instance.Home.IsVirtually == true)
            {
                //虚拟住宅
                return;
            }
            //开一个线程,监视是否滑动的滑动条,每秒检测一次
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (this.Parent != null)
                {
                    System.Threading.Thread.Sleep(1000);
                    if (nowProgressValue == oldProgressValue
                    || this.canSetProgressValue == false)
                    if (nowProgressValue == oldProgressValue)
                    {
                        //值一样
                        continue;
                    }
                    oldProgressValue = nowProgressValue;
                    //发送进度值
                    ((DimmableLight)this.device).SetLevel((int)(oldProgressValue * MaxLevel / 100.0));
                    ((DimmableLight)this.device).SetLevel(HdlDeviceCommonLogic.Current.CalculateLightLevel(oldProgressValue));
                }
            });
        }
@@ -193,52 +196,54 @@
        /// <param name="isOpen"></param>
        private void SetSwitchCommand(bool isOpen)
        {
            //当按下开关按钮时,不能再发送进度值
            this.canSetProgressValue = false;
            //获取当前亮度
            int level = Convert.ToInt32(this.device.GetType().InvokeMember("Level", System.Reflection.BindingFlags.GetField, null, this.device, null));
            //如果住宅是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                ((LightBase)this.device).OnOffStatus = isOpen == true ? 1 : 0;
                if (((LightBase)this.device).OnOffStatus == 1 && level == 0)
                {
                    //如果当前是打开状态,并且亮度为0的话,则需要变成100%亮度
                    this.device.GetType().InvokeMember("Level", System.Reflection.BindingFlags.SetField, null, this.device, new object[] { 100 });
                }
                //刷新开关状态
                this.RefreshSwitchStatu(isOpen);
                return;
            }
            //检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息
            this.StartCheckResponeResult(this.listControl, (result) =>
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //没有接收到网关回复
                    if (result == false)
                    bool statu = ((LightBase)this.device).OnOffStatus == 1;
                    //接收到网关回复
                    if (result == true)
                    {
                        bool statu = ((LightBase)this.device).OnOffStatus == 1;
                        //刷新开关状态
                        this.RefreshSwitchStatu(statu);
                        if (statu == true)
                        {
                            //等待结果结束后,彩灯控件可以滑动
                            waveSeekBar.IsClickable = true;
                        }
                        //状态取反
                        listControl[0].IsSelected = statu;
                    }
                });
            });
            //状态取反
            listControl[0].IsSelected = !listControl[0].IsSelected;
            //发送等待的时间内,不能滑动彩灯控件
            waveSeekBar.IsClickable = false;
            if (isOpen == true)
            {
                waveSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarColor_Start, ZigbeeColor.Current.GXCWaveSeekBarColor_End);
            }
            else
            {
                waveSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor, ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor);
            }
            if (isOpen == true)
            {
                //打开
                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uOpen1));
                this.device.SwitchControl(1);
                if (level == 0)
                {
                    //如果当前是打开状态,并且亮度为0的话,则需要变成100%亮度
                    this.device.GetType().InvokeMember("SetLevel", System.Reflection.BindingFlags.InvokeMethod, null, this.device, new object[] { 255 });
                }
                else
                {
                    this.device.SwitchControl(1);
                }
            }
            else
            {
                //关闭
                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close));
                this.device.SwitchControl(0);
            }
        }
@@ -255,17 +260,14 @@
        /// <returns></returns>
        public override bool CheckResponeResultStatu(ReceiveComandDiv comandDiv, CommonDevice report)
        {
            if (comandDiv == ReceiveComandDiv.A节点控制反馈)
            {
                return true;
            }
            else if (comandDiv == ReceiveComandDiv.A设备属性上报)
            if (comandDiv == ReceiveComandDiv.A设备属性上报)
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //刷新开关状态
                    this.RefreshSwitchStatu(((LightBase)this.device).OnOffStatus == 1);
                });
                return true;
            }
            return false;
        }
@@ -284,11 +286,6 @@
            {
                //亮度是必须要刷新的  亮度 XX
                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + "  " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
                if (this.isProgressing == false)
                {
                    //当进度值在手动变更中时,不接收推送
                    waveSeekBar.Progress = (int)(((DimmableLight)this.device).Level * 1.0 / MaxLevel * 100);
                }
            }
            if (isOpen == false && this.IsLightOpen == true)
            {
@@ -296,29 +293,31 @@
                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close));
            }
            if (this.isProgressing == false)
            {
                //当进度值在手动变更中时,不接收推送
                int progress = HdlDeviceCommonLogic.Current.CalculateLightLevelPersent(((DimmableLight)this.device).Level);
                if (waveSeekBar.Progress != progress)
                {
                    waveSeekBar.Progress = progress;
                }
            }
            if (listControl[0].IsSelected != isOpen)
            {
                //开关状态变更
                listControl[0].IsSelected = isOpen;
            }
            //状态不一样才变更
            if (this.IsLightOpen != isOpen)
            {
                if (isOpen == true)
                {
                    waveSeekBar.IsClickable = true;
                    waveSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarColor_Start, ZigbeeColor.Current.GXCWaveSeekBarColor_End);
                }
                else
                {
                    waveSeekBar.IsClickable = false;
                    waveSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor, ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor);
                }
            }
            this.IsLightOpen = isOpen;
            //回复的结果说,处于打开状态才能发送
            this.canSetProgressValue = this.IsLightOpen;
        }
        #endregion