gxc
2020-02-28 66a9965c44ecc32a6696abca876ab9d1cd091584
ZigbeeApp/Shared/Phone/Device/Light/DimmableLightControl.cs
old mode 100755 new mode 100644
@@ -1,5 +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
@@ -11,15 +13,11 @@
        /// <summary>
        /// The action.
        /// </summary>
        public Action action;
        public Action<DeviceUI, Common.Room> action;
        ///// <summary>
        ///// The top view.
        ///// </summary>
        private CommonForm.TopFrameLayout topFL;
        /// <summary>
        /// 更多设置
        /// </summary>
        private Button moreBtn;
        private CommonForm.TopFrameLayout top;
        /// <summary>
        /// 传过来的设备
        /// </summary>
@@ -33,25 +31,14 @@
        /// </summary>
        private Shared.Common.Room room;
        /// <summary>
        /// The middle fl.
        /// bodyFrameLayout
        /// </summary>
        private FrameLayout midFL;
        private FrameLayout bodyFrameLayout;
        /// <summary>
        /// 收藏按钮
        /// </summary>
        private Button collectionBtn;
        /// <summary>
        /// 设备是否在线标识--Online
        /// </summary>
        private readonly string DeviceStatus_Online = "Online";
        /// <summary>
        /// 设备状态开关标识--Switch
        /// </summary>
        private readonly string DeviceStatus_OnOffStatus = "Switch";
        /// <summary>
        /// The light image.
        /// </summary>
        private Button deviceIMG;
        /// <summary>
        /// 开关
        /// </summary>
@@ -59,11 +46,35 @@
        /// <summary>
        /// 滑条
        /// </summary>
        private HorizontalSeekBar levelSeekBar;
        private WaveSeekBar levelSeekBar;
        private Button StatuBtn;
        /// <summary>
        /// 延时 300毫秒
        /// 房间
        /// </summary>
        private int sleepSpan = 300;
        private Button roomBtn;
        /// <summary>
        /// 房间名
        /// </summary>
        private Button roomName;
        /// <summary>
        /// MaxLevel
        /// </summary>
        private const int MaxLevel = 254;
        /// <summary>
        /// IsDrawerLockMode
        /// </summary>
        public bool IsDrawerLockMode;
        /// <summary>
        /// ProgressBtn
        /// </summary>
        Button ProgressBtn;
        /// <summary>
        /// ProgressBtnY
        /// </summary>
        int ProgressBtnY;
        #endregion
@@ -124,24 +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 = 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.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarColor_Start, ZigbeeColor.Current.GXCWaveSeekBarColor_End);
                                }
                                else
                                {
                                    levelSeekBar.IsClickable = false;
                                    levelSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor, ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor);
                                }
                                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)
                                {
@@ -153,18 +175,12 @@
                                        //此属性表明当前亮度程度
                                        dimmableLight.Level = attriButeList[0].AttriButeData;
                                        dimmableLight.LastDateTime = DateTime.Now;
                                        levelSeekBar.Progress = dimmableLight.Level;
                                        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;
                                }
                            }
                            //***新改***设备状态上报中,当CluterID=3,证明设备在线,直接标记
                            else if ((common as DimmableLight).DeviceStatusReport.CluterID == 3)
                            {
                                dimmableLight = deviceUI.CommonDevice as DimmableLight;
                                dimmableLight.IsOnline = 1;
                                deviceIMG.IsSelected = dimmableLight.IsOnline == 1;
                                dimmableLight.LastDateTime = DateTime.Now;
                            }
                        }
                    }
                    catch (Exception ex)
@@ -175,34 +191,7 @@
            }
            else if (typeTag == "OnlineStatusChange")
            {
                Application.RunOnMainThread(() =>
                {
                    try
                    {
                        var deviceUI = device;
                        //设备为空
                        if (deviceUI.CommonDevice == null)
                        {
                            return;
                        }
                        //是否为当前设备
                        if (deviceUI.CommonDevice.DeviceEpoint != common.DeviceEpoint || deviceUI.CommonDevice.DeviceAddr != common.DeviceAddr)
                        {
                            return;
                        }
                        if (deviceUI.CommonDevice.Type == DeviceType.DimmableLight)
                        {
                            dimmableLight = deviceUI.CommonDevice as DimmableLight;
                            dimmableLight.IsOnline = (common as DimmableLight).IsOnline;
                            deviceIMG.IsSelected = dimmableLight.IsOnline == 1;
                            dimmableLight.LastDateTime = DateTime.Now;
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine($"Error:{ex.Message}");
                    }
                });
            }
        }
@@ -217,6 +206,12 @@
        {
            ZbGateway.StatusList.Remove(this);
            UserView.HomePage.Instance.ScrollEnabled = true;
            action(device, room);
            action = null;
            if (IsDrawerLockMode)
            {
                CommonPage.Instance.IsDrawerLockMode = false;
            }
            base.RemoveFromParent();
        }
@@ -228,7 +223,9 @@
        /// </summary>
        public DimmableLightControl()
        {
            UserView.HomePage.Instance.ScrollEnabled = false;
            BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
            ZbGateway.StatusList.Add(this);
        }
        #endregion
@@ -241,7 +238,6 @@
        /// <param name="room">Room.</param>
        public void Show(DeviceUI device, Shared.Common.Room room)
        {
            ZbGateway.StatusList.Add(this);
            this.device = device;
            this.room = room;
            this.dimmableLight = device.CommonDevice as ZigBee.Device.DimmableLight;
@@ -249,7 +245,7 @@
            //添加topview
            AddTopView();
            //添加midview
            AddMidview();
            AddBodyView(this.device);
            //绑定事件
            BindEvent();
            //收藏
@@ -260,9 +256,7 @@
                //发送读取状态命令
                UserView.UserHomeView.ReadStatus(dimmableLight, () =>
                {
                    dimmableLight.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                    dimmableLight.ReadOnOffStatus();
                    dimmableLight.ReadLevel();
                    ReadDeviceAttributeLogic.Instance.SendDimmableLightStatuComand(device.CommonDevice);
                });
            }
            else
@@ -270,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);
                }
            }
        }
@@ -286,30 +278,26 @@
        /// </summary>
        private void AddTopView()
        {
            topFL = new CommonForm.TopFrameLayout(this) { };
            AddChidren(topFL);
            AddMoreview();
        }
        /// <summary>
        /// Adds the moreview.
        /// </summary>
        private void AddMoreview()
        {
            moreBtn = new CommonForm.SelectedStatuButton()
            top = new CommonForm.TopFrameLayout();
            AddChidren(top);
            top.InitTopview();
            top.backButton.MouseUpEventHandler += (sender, e) =>
            {
                X = Application.GetRealWidth(CommonPage.AppRealWidth - 150),
                Width = Application.GetMinReal(110),
                Height = Application.GetMinReal(110),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "Item/More.png",
                SelectedImagePath = "Item/MoreSelected.png",
                RemoveFromParent();
            };
            topFL.topView.AddChidren(moreBtn);
            var moreBtn = new Button
            {
                X = Application.GetRealWidth(953),
                Width = Application.GetMinReal(69),
                Height = Application.GetMinReal(69),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "Item/More.png"
            };
            top.topView.AddChidren(moreBtn);
            moreBtn.MouseUpEventHandler += MoreEvent;
        }
        /// <summary>
        /// 更多设置
        /// </summary>
@@ -321,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);
            };
        }
@@ -332,17 +320,17 @@
        #region ◆ midview_______________________
        /// <summary>
        /// Adds the midview.
        /// AddBodyView
        /// </summary>
        private void AddMidview()
        public void AddBodyView(DeviceUI device)
        {
            midFL = new FrameLayout()
            bodyFrameLayout = new FrameLayout()
            {
                Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
                Y = topFL.Bottom,
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
                Y = Application.GetRealHeight(184),
                Height = Application.GetRealHeight(1737),
                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
            };
            AddChidren(midFL);
            AddChidren(bodyFrameLayout);
            AddItemview();
        }
@@ -360,113 +348,182 @@
                Y = Application.GetRealHeight(115),
                Width = Application.GetRealWidth(965),
                Height = Application.GetRealHeight(1316),
                Radius = CommonPage.BigFormRadius,
                Radius = (uint)Application.GetRealHeight(CommonFormResouce.BigFormRadius),
                Gravity = Gravity.CenterHorizontal,
                BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
            };
            midFL.AddChidren(itemView);
            var deviceView = new FrameLayout()
            {
                X = 2,
                Y = 2,
                Width = itemView.Width - 4,
                Height = itemView.Height - Application.GetRealHeight(138),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
                Tag = device
            };
            itemView.AddChidren(deviceView);
            bodyFrameLayout.AddChidren(itemView);
            collectionBtn = new Button()
            {
                X = deviceView.Width - Application.GetRealWidth(130),
                Y = Application.GetRealHeight(20),
                Width = Application.GetMinReal(110),
                Height = Application.GetMinReal(110),
                X = Application.GetRealWidth(850),
                Y = Application.GetRealHeight(46),
                Width = Application.GetMinReal(69),
                Height = Application.GetMinReal(69),
                UnSelectedImagePath = "Item/Collection.png",
                SelectedImagePath = "Item/CollectionSelected.png"
            };
            deviceView.AddChidren(collectionBtn);
            itemView.AddChidren(collectionBtn);
            deviceIMG = new Button()
            var deviceNameBtn = new Button()
            {
                Y = Application.GetRealHeight(100),
                Height = Application.GetMinRealAverage(240),
                Width = Application.GetMinRealAverage(240),
                Y = Application.GetRealHeight(46),
                Width = Application.GetRealWidth(500),
                Height = Application.GetRealHeight(60),
                Gravity = Gravity.CenterHorizontal,
                UnSelectedImagePath = device.IconPath,
                SelectedImagePath = device.OnlineIconPath,
                IsSelected = dimmableLight.IsOnline == 1,
                Tag = DeviceStatus_Online
                Text = Common.LocalDevice.Current.GetDeviceEpointName(device.CommonDevice),
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 15,
                IsBold=true
            };
            deviceView.AddChidren(deviceIMG);
            itemView.AddChidren(deviceNameBtn);
            var lightName = new Button()
            StatuBtn = new Button
            {
                Y = deviceIMG.Bottom,
                Height = Application.GetRealHeight(85),
                Y = Application.GetRealHeight(118),
                Width = Application.GetRealWidth(600),
                Height = Application.GetRealHeight(60),
                Gravity = Gravity.CenterHorizontal,
                Text = device.CommonDevice.DeviceEpointName,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                Text = dimmableLight.Level>0?$"{Language.StringByID(R.MyInternationalizationString.CurrentLightLevel)} { device.GetDeviceStatu()}" :$"{Language.StringByID(R.MyInternationalizationString.Current)} {Language.StringByID(R.MyInternationalizationString.Shut)}",
                TextSize=10
            };
            deviceView.AddChidren(lightName);
            levelSeekBar = new HorizontalSeekBar()
            itemView.AddChidren(StatuBtn);
            levelSeekBar = new WaveSeekBar()
            {
                Y = lightName.Bottom + Application.GetRealHeight(150),
                Width = Application.GetRealWidth(800),
                Height = Application.GetRealHeight(80),
                Y = Application.GetRealHeight(377),
                Width = Application.GetRealWidth(271),
                Height = Application.GetRealHeight(533),
                Gravity = Gravity.CenterHorizontal,
                BackgroundColor = ZigbeeColor.Current.GXCSliderUnSelectedColor,
                ThumbColor = ZigbeeColor.Current.GXCButtonBlueColor,
                BorderColor = ZigbeeColor.Current.GXCButtonBlueColor,
                ProgressColor = ZigbeeColor.Current.GXCButtonBlueColor,
                Max = 254,
                Tag = "LevelSeekBar",
                Progress = dimmableLight.Level,
                SleepTime=sleepSpan,
                WavePadding = Application.GetRealWidth(8),
                MaxValue=100,
                Progress = (int)(dimmableLight.Level*1.0/MaxLevel*100),
                CornerRadius= Application.GetRealHeight(58)
            };
            deviceView.AddChidren(levelSeekBar);
            levelSeekBar.ProgressChanged += (send2, e2) =>
            itemView.AddChidren(levelSeekBar);
            if (dimmableLight.OnOffStatus == 1)
            {
                dimmableLight.SetLevel(levelSeekBar.Progress);
            };
                levelSeekBar.IsClickable = true;
                levelSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarColor_Start, ZigbeeColor.Current.GXCWaveSeekBarColor_End);
            }
            else
            {
                levelSeekBar.IsClickable = false;
                levelSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor, ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor);
            }
            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) =>
            {
                OnProgressButtonMove(e2);
                //判断是否300ms屏蔽
                //if (levelSeekBar.IsProgressChangeDelay()) return;
                //dimmableLight.SetLevel((int)(levelSeekBar.Progress * MaxLevel / 100.0));
            };
            InitProgressBtn(itemView);
            switchBtn = new Button()
            {
                Y = levelSeekBar.Bottom + Application.GetRealHeight(150),
                Y = Application.GetRealHeight(1005),
                Width = Application.GetMinRealAverage(81),
                Height = Application.GetMinRealAverage(81),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetMinRealAverage(180),
                Height = Application.GetMinRealAverage(120),
                UnSelectedImagePath = "Item/Switch.png",
                SelectedImagePath = "Item/SwitchSelected.png",
                Tag = DeviceStatus_OnOffStatus,
                IsSelected = dimmableLight.OnOffStatus == 1
                IsSelected = (device.CommonDevice as DimmableLight).OnOffStatus == 1
            };
            deviceView.AddChidren(switchBtn);
            itemView.AddChidren(switchBtn);
            var roomBtn = new Button()
            var roomBG = new Button
            {
                X = Application.GetRealWidth(50),
                Y = Application.GetRealHeight(25) + deviceView.Bottom,
                Y = Application.GetRealHeight(1178 - 50),
                Height = Application.GetRealHeight(138 + 50),
                BackgroundColor = ZigbeeColor.Current.GXCBlackBackgroundColor,
                Radius = (uint)Application.GetRealHeight(CommonFormResouce.BigFormRadius)
            };
            itemView.AddChidren(roomBG);
            var roomBG2 = new Button
            {
                Y = Application.GetRealHeight(1178 - 50),
                Height = Application.GetRealHeight(50),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
            };
            itemView.AddChidren(roomBG2);
            roomBtn = new Button()
            {
                X = Application.GetRealWidth(CommonFormResouce.X_Left),
                Y = Application.GetRealHeight(1207),
                Width = Application.GetMinReal(80),
                Height = Application.GetMinReal(80),
                UnSelectedImagePath = "Item/Room.png",
                SelectedImagePath = "Item/RoomSelected.png"
                UnSelectedImagePath = "Item/Room.png"
            };
            itemView.AddChidren(roomBtn);
            var roomName = new Button()
            roomName = new Button()
            {
                X = roomBtn.Right + Application.GetRealWidth(20),
                Y = roomBtn.Y,
                X = Application.GetRealWidth(150),
                Y = Application.GetRealHeight(1224),
                Width = Application.GetRealWidth(400),
                Height = Application.GetRealHeight(80),
                Height = Application.GetRealHeight(50),
                Text = room.Name,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor
                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
@@ -479,7 +536,6 @@
        {
            switchBtn.MouseUpEventHandler += Switch_MouseUpEvent;
            collectionBtn.MouseUpEventHandler += Collection;
            moreBtn.MouseUpEventHandler += MoreEvent;
        }
        #endregion
@@ -494,13 +550,18 @@
        private void Switch_MouseUpEvent(object sender, MouseEventArgs eventArgs)
        {
            switchBtn.IsSelected = !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.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarColor_Start, ZigbeeColor.Current.GXCWaveSeekBarColor_End);
            }
            else
            {
                dimmableLight.SwitchControl(0);
                levelSeekBar.IsClickable = false;
                levelSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor, ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor);
            }
        }
@@ -513,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;
            }
@@ -531,17 +591,16 @@
        private void Collection(object sender, MouseEventArgs e)
        {
            //collection
            if (collectionBtn.IsSelected)
            if ((sender as Button).IsSelected)
            {
                Shared.Common.Room.Lists[0].DeleteDevice(device.FileName);
                collectionBtn.IsSelected = false;
                Shared.Common.Room.CurrentRoom.GetLoveRoom().DeleteDevice(device.FileName);
                (sender as Button).IsSelected = false;
            }
            else
            {
                Shared.Common.Room.Lists[0].AddDevice(device.FileName);
                collectionBtn.IsSelected = true;
                Shared.Common.Room.CurrentRoom.GetLoveRoom().AddDevice(device.FileName);
                (sender as Button).IsSelected = true;
            }
            action?.Invoke();
        }
        #endregion