gxc
2020-02-28 66a9965c44ecc32a6696abca876ab9d1cd091584
ZigbeeApp/Shared/Phone/Device/Light/DimmableLightControl.cs
@@ -1,6 +1,7 @@
using System;
using Shared.Common;
using Shared.Phone.Device.CommonForm;
using Shared.Phone.Device.DeviceLogic;
using ZigBee.Device;
namespace Shared.Phone.Device.Light
@@ -12,7 +13,7 @@
        /// <summary>
        /// The action.
        /// </summary>
        public Action action;
        public Action<DeviceUI, Common.Room> action;
        ///// <summary>
        ///// The top view.
        ///// </summary>
@@ -37,7 +38,7 @@
        /// 收藏按钮
        /// </summary>
        private Button collectionBtn;
        /// <summary>
        /// 开关
        /// </summary>
@@ -46,7 +47,7 @@
        /// 滑条
        /// </summary>
        private WaveSeekBar levelSeekBar;
        private Button StatuBtn;
        /// <summary>
@@ -61,6 +62,20 @@
        /// MaxLevel
        /// </summary>
        private const int MaxLevel = 254;
        /// <summary>
        /// IsDrawerLockMode
        /// </summary>
        public bool IsDrawerLockMode;
        /// <summary>
        /// ProgressBtn
        /// </summary>
        Button ProgressBtn;
        /// <summary>
        /// ProgressBtnY
        /// </summary>
        int ProgressBtnY;
        #endregion
        #region ◆ 接口__________________________
@@ -120,36 +135,35 @@
                        }
                        if (deviceUI.CommonDevice.Type == DeviceType.DimmableLight)
                        {
                            if ((common as DimmableLight).DeviceStatusReport.CluterID == 6)
                            if (common.DeviceStatusReport.CluterID == 6)
                            {
                                dimmableLight = deviceUI.CommonDevice as DimmableLight;
                                dimmableLight.DeviceStatusReport = (common as DimmableLight).DeviceStatusReport;
                                //记录、更新状态
                                dimmableLight.DeviceStatusReport = common.DeviceStatusReport;
                                if (dimmableLight.DeviceStatusReport.AttriBute == null || dimmableLight.DeviceStatusReport.AttriBute.Count == 0)
                                {
                                    return;
                                }
                                dimmableLight.OnOffStatus = dimmableLight.DeviceStatusReport.AttriBute[0].AttriButeData;
                                switchBtn.IsSelected = dimmableLight.OnOffStatus == 1;
                                StatuBtn.Text = CommonFormResouce.GetSwitchStatu(switchBtn.IsSelected);
                                StatuBtn.Text = switchBtn.IsSelected ? $"{Language.StringByID(R.MyInternationalizationString.CurrentLightLevel)} { device.GetDeviceStatu()}" : $"{Language.StringByID(R.MyInternationalizationString.Current)} {Language.StringByID(R.MyInternationalizationString.Shut)}";
                                if (switchBtn.IsSelected == true)
                                {
                                    levelSeekBar.IsClickable = true;
                                    levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarColor;
                                    levelSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarColor_Start, ZigbeeColor.Current.GXCWaveSeekBarColor_End);
                                }
                                else
                                {
                                    levelSeekBar.IsClickable = false;
                                    levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor;
                                    levelSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor, ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor);
                                }
                                //change color
                                dimmableLight.LastDateTime = DateTime.Now;
                            }
                            //亮度
                            if ((common as ZigBee.Device.DimmableLight).DeviceStatusReport.CluterID == 8)
                            if (common.DeviceStatusReport.CluterID == 8)
                            {
                                dimmableLight = deviceUI.CommonDevice as ZigBee.Device.DimmableLight;
                                dimmableLight.DeviceStatusReport = (common as ZigBee.Device.DimmableLight).DeviceStatusReport;
                                dimmableLight.DeviceStatusReport = common.DeviceStatusReport;
                                var attriButeList = dimmableLight.DeviceStatusReport.AttriBute;
                                if (attriButeList == null || attriButeList.Count == 0)
                                {
@@ -162,10 +176,11 @@
                                        dimmableLight.Level = attriButeList[0].AttriButeData;
                                        dimmableLight.LastDateTime = DateTime.Now;
                                        levelSeekBar.Progress = (int)(dimmableLight.Level*1.0/MaxLevel*100);
                                        StatuBtn.Text = switchBtn.IsSelected ? $"{Language.StringByID(R.MyInternationalizationString.CurrentLightLevel)} { device.GetDeviceStatu()}" : $"{Language.StringByID(R.MyInternationalizationString.Current)} {Language.StringByID(R.MyInternationalizationString.Shut)}";
                                        break;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
@@ -176,7 +191,7 @@
            }
            else if (typeTag == "OnlineStatusChange")
            {
            }
        }
@@ -191,8 +206,12 @@
        {
            ZbGateway.StatusList.Remove(this);
            UserView.HomePage.Instance.ScrollEnabled = true;
            //action();
            //action = null;
            action(device, room);
            action = null;
            if (IsDrawerLockMode)
            {
                CommonPage.Instance.IsDrawerLockMode = false;
            }
            base.RemoveFromParent();
        }
@@ -204,6 +223,7 @@
        /// </summary>
        public DimmableLightControl()
        {
            UserView.HomePage.Instance.ScrollEnabled = false;
            BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
            ZbGateway.StatusList.Add(this);
        }
@@ -236,9 +256,7 @@
                //发送读取状态命令
                UserView.UserHomeView.ReadStatus(dimmableLight, () =>
                {
                    dimmableLight.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                    dimmableLight.ReadOnOffStatus();
                    dimmableLight.ReadLevel();
                    ReadDeviceAttributeLogic.Instance.SendDimmableLightStatuComand(device.CommonDevice);
                });
            }
            else
@@ -246,9 +264,7 @@
                //防止短时间内多次读取设备状态
                if ((DateTime.Now - dimmableLight.LastDateTime).TotalSeconds > CommonPage.ReadDeviceStatuSpan)
                {
                    dimmableLight.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                    dimmableLight.ReadOnOffStatus();
                    dimmableLight.ReadLevel();
                    ReadDeviceAttributeLogic.Instance.SendDimmableLightStatuComand(device.CommonDevice);
                }
            }
        }
@@ -293,9 +309,9 @@
            UserView.HomePage.Instance.AddChidren(detailInfo);
            UserView.HomePage.Instance.PageIndex += 1;
            detailInfo.Show(device, room);
            detailInfo.action = () =>
            detailInfo.EditAction += (curDev, curRoom) =>
            {
                Show(device, room);
                Show(curDev, curRoom);
            };
        }
@@ -355,9 +371,10 @@
                Width = Application.GetRealWidth(500),
                Height = Application.GetRealHeight(60),
                Gravity = Gravity.CenterHorizontal,
                Text = device.CommonDevice.DeviceEpointName,
                Text = Common.LocalDevice.Current.GetDeviceEpointName(device.CommonDevice),
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 15
                TextSize = 15,
                IsBold=true
            };
            itemView.AddChidren(deviceNameBtn);
@@ -368,8 +385,10 @@
                Height = Application.GetRealHeight(60),
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                Text = CommonFormResouce.GetSwitchStatu(device.CommonDevice.IsOnline == 1)
                Text = dimmableLight.Level>0?$"{Language.StringByID(R.MyInternationalizationString.CurrentLightLevel)} { device.GetDeviceStatu()}" :$"{Language.StringByID(R.MyInternationalizationString.Current)} {Language.StringByID(R.MyInternationalizationString.Shut)}",
                TextSize=10
            };
            itemView.AddChidren(StatuBtn);
            levelSeekBar = new WaveSeekBar()
@@ -378,28 +397,51 @@
                Width = Application.GetRealWidth(271),
                Height = Application.GetRealHeight(533),
                Gravity = Gravity.CenterHorizontal,
                WavePadding = 2,
                WavePadding = Application.GetRealWidth(8),
                MaxValue=100,
                Progress = (int)(dimmableLight.Level*1.0/MaxLevel*100),
                WaveColor = ZigbeeColor.Current.GXCWaveSeekBarColor
                CornerRadius= Application.GetRealHeight(58)
            };
            itemView.AddChidren(levelSeekBar);
            if (dimmableLight.OnOffStatus==1)
            if (dimmableLight.OnOffStatus == 1)
            {
                levelSeekBar.IsClickable = true;
                levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarColor;
                levelSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarColor_Start, ZigbeeColor.Current.GXCWaveSeekBarColor_End);
            }
            else
            {
                levelSeekBar.IsClickable = false;
                levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor;
                levelSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor, ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor);
            }
            levelSeekBar.OnProgressChangedEvent += (send2, e2) =>
            levelSeekBar.OnStartTrackingTouchEvent += (sender, e) =>
            {
                OnProgressButtonMove(levelSeekBar.Progress);
                levelSeekBar.IsProgressTextShow = false;
                ProgressBtn.Visible = true;
            };
            levelSeekBar.OnStopTrackingTouchEvent += (sender, e) =>
            {
                ProgressBtn.Visible = false;
                levelSeekBar.IsProgressTextShow = true;
                dimmableLight.SetLevel((int)(levelSeekBar.Progress * MaxLevel / 100.0));
            };
            levelSeekBar.OnProgressChangedEvent += (send2, e2) =>
            {
                dimmableLight.SetLevel((int)(levelSeekBar.Progress*MaxLevel/100.0));
            };
                OnProgressButtonMove(e2);
                //判断是否300ms屏蔽
                //if (levelSeekBar.IsProgressChangeDelay()) return;
                //dimmableLight.SetLevel((int)(levelSeekBar.Progress * MaxLevel / 100.0));
            };
            InitProgressBtn(itemView);
            switchBtn = new Button()
            {
@@ -448,9 +490,40 @@
                Height = Application.GetRealHeight(50),
                Text = room.Name,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = ZigbeeColor.Current.GXCTextWhiteColor
                TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
                TextSize = 12
            };
            itemView.AddChidren(roomName);
        }
        /// <summary>
        /// OnProgressButtonMove
        /// </summary>
        private void OnProgressButtonMove(int mProgress)
        {
            ProgressBtn.Y = ProgressBtnY + levelSeekBar.NowProgressY;
            ProgressBtn.Text = mProgress + "%";
        }
        /// <summary>
        /// 添加进度按钮
        /// </summary>
        private void InitProgressBtn(FrameLayout layout)
        {
            ProgressBtnY = levelSeekBar.Y - Application.GetMinReal(154);
            ProgressBtn = new Button()
            {
                Y = ProgressBtnY,
                Width = Application.GetMinReal(135),
                Height = Application.GetMinReal(104),
                UnSelectedImagePath = "Item/ProgressBubbles.png",
                Visible = false,
                Gravity = Gravity.CenterHorizontal,
                TextSize = 14,
                IsBold = true,
                TextColor = ZigbeeColor.Current.GXCTextWhiteColor
            };
            layout.AddChidren(ProgressBtn);
        }
        #endregion
@@ -477,18 +550,18 @@
        private void Switch_MouseUpEvent(object sender, MouseEventArgs eventArgs)
        {
            switchBtn.IsSelected = !switchBtn.IsSelected;
            StatuBtn.Text = CommonFormResouce.GetSwitchStatu(switchBtn.IsSelected);
            StatuBtn.Text = switchBtn.IsSelected ? $"{Language.StringByID(R.MyInternationalizationString.CurrentLightLevel)} { device.GetDeviceStatu()}" : $"{Language.StringByID(R.MyInternationalizationString.Current)} {Language.StringByID(R.MyInternationalizationString.Shut)}";
            if (switchBtn.IsSelected == true)
            {
                dimmableLight.SwitchControl(1);
                levelSeekBar.IsClickable = true;
                levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarColor;
                levelSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarColor_Start, ZigbeeColor.Current.GXCWaveSeekBarColor_End);
            }
            else
            {
                dimmableLight.SwitchControl(0);
                levelSeekBar.IsClickable = false;
                levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor;
                levelSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor, ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor);
            }
        }
@@ -501,8 +574,7 @@
        /// </summary>
        private void InitCollection()
        {
            var dev = Shared.Common.Room.LoveRoomDeviceUIFilePathList.Find((obj) => obj == device.FileName);
            if (dev == null)
            if (Common.Room.CurrentRoom.IsCollectInRoom(device.FileName) == false)
            {
                collectionBtn.IsSelected = false;
            }