From 944b87b6bcccb095cd73f13f4410fb20faf48f74 Mon Sep 17 00:00:00 2001 From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local> Date: 星期三, 25 十二月 2019 11:21:06 +0800 Subject: [PATCH] 2019.12.25 --- ZigbeeApp/Shared/Phone/Device/Light/DimmableLightControl.cs | 397 ++++++++++++++++++++++++++++++++------------------------ 1 files changed, 224 insertions(+), 173 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/Device/Light/DimmableLightControl.cs b/ZigbeeApp/Shared/Phone/Device/Light/DimmableLightControl.cs index 8c802bc..c8c1092 100644 --- a/ZigbeeApp/Shared/Phone/Device/Light/DimmableLightControl.cs +++ b/ZigbeeApp/Shared/Phone/Device/Light/DimmableLightControl.cs @@ -1,5 +1,7 @@ 锘縰sing System; using Shared.Common; +using Shared.Phone.Device.CommonForm; +using Shared.Phone.Device.DeviceLogic; using ZigBee.Device; namespace Shared.Phone.Device.Light @@ -15,11 +17,7 @@ ///// <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,10 +135,10 @@ } 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) { @@ -135,13 +146,27 @@ } dimmableLight.OnOffStatus = dimmableLight.DeviceStatusReport.AttriBute[0].AttriButeData; switchBtn.IsSelected = dimmableLight.OnOffStatus == 1; + StatuBtn.Text = CommonFormResouce.GetSwitchStatu(switchBtn.IsSelected); + if (switchBtn.IsSelected == true) + { + levelSeekBar.IsClickable = true; + levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarColor; + //levelSeekBar.Progress = 100; + } + else + { + levelSeekBar.IsClickable = false; + levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor; + //levelSeekBar.Progress = 0; + } + //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) { @@ -153,18 +178,11 @@ //姝ゅ睘鎬ц〃鏄庡綋鍓嶄寒搴︾▼搴� dimmableLight.Level = attriButeList[0].AttriButeData; dimmableLight.LastDateTime = DateTime.Now; - levelSeekBar.Progress = dimmableLight.Level; + levelSeekBar.Progress = (int)(dimmableLight.Level*1.0/MaxLevel*100); 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 +193,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 +208,12 @@ { ZbGateway.StatusList.Remove(this); UserView.HomePage.Instance.ScrollEnabled = true; + //action(); + //action = null; + if (IsDrawerLockMode) + { + CommonPage.Instance.IsDrawerLockMode = false; + } base.RemoveFromParent(); } @@ -228,7 +225,9 @@ /// </summary> public DimmableLightControl() { + UserView.HomePage.Instance.ScrollEnabled = false; BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor; + ZbGateway.StatusList.Add(this); } #endregion @@ -241,7 +240,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 +247,7 @@ //娣诲姞topview AddTopView(); //娣诲姞midview - AddMidview(); + AddBodyView(this.device); //缁戝畾浜嬩欢 BindEvent(); //鏀惰棌 @@ -260,9 +258,7 @@ //鍙戦�佽鍙栫姸鎬佸懡浠� UserView.UserHomeView.ReadStatus(dimmableLight, () => { - dimmableLight.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch); - dimmableLight.ReadOnOffStatus(); - dimmableLight.ReadLevel(); + ReadDeviceAttributeLogic.Instance.SendDimmableLightStatuComand(device.CommonDevice); }); } else @@ -270,9 +266,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 +280,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> @@ -332,17 +322,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 +350,171 @@ 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), - Gravity = Gravity.CenterHorizontal, - UnSelectedImagePath = device.IconPath, - SelectedImagePath = device.OnlineIconPath, - IsSelected = dimmableLight.IsOnline == 1, - Tag = DeviceStatus_Online - }; - deviceView.AddChidren(deviceIMG); - - var lightName = new Button() - { - Y = deviceIMG.Bottom, - Height = Application.GetRealHeight(85), + Y = Application.GetRealHeight(46), + Width = Application.GetRealWidth(500), + Height = Application.GetRealHeight(60), Gravity = Gravity.CenterHorizontal, Text = device.CommonDevice.DeviceEpointName, - TextColor = ZigbeeColor.Current.GXCTextBlackColor + TextColor = ZigbeeColor.Current.GXCTextBlackColor, + TextSize = 15 }; - deviceView.AddChidren(lightName); + itemView.AddChidren(deviceNameBtn); - levelSeekBar = new HorizontalSeekBar() + StatuBtn = new Button { - Y = lightName.Bottom + Application.GetRealHeight(150), - Width = Application.GetRealWidth(800), - Height = Application.GetRealHeight(80), + Y = Application.GetRealHeight(118), + Width = Application.GetRealWidth(600), + Height = Application.GetRealHeight(60), 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, + TextColor = ZigbeeColor.Current.GXCTextGrayColor, + Text = CommonFormResouce.GetSwitchStatu((device.CommonDevice as DimmableLight).OnOffStatus == 1) }; - deviceView.AddChidren(levelSeekBar); - levelSeekBar.ProgressChanged += (send2, e2) => + itemView.AddChidren(StatuBtn); + + levelSeekBar = new WaveSeekBar() { - dimmableLight.SetLevel(levelSeekBar.Progress); + Y = Application.GetRealHeight(377), + Width = Application.GetRealWidth(271), + Height = Application.GetRealHeight(533), + Gravity = Gravity.CenterHorizontal, + WavePadding = Application.GetRealWidth(8), + MaxValue=100, + Progress = (int)(dimmableLight.Level*1.0/MaxLevel*100), + WaveColor = ZigbeeColor.Current.GXCWaveSeekBarColor }; + itemView.AddChidren(levelSeekBar); + + if (dimmableLight.OnOffStatus == 1) + { + levelSeekBar.IsClickable = true; + levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarColor; + } + else + { + levelSeekBar.IsClickable = false; + levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor; + } + + levelSeekBar.OnStartTrackingTouchEvent += (sender, e) => + { + OnProgressButtonMove(levelSeekBar.Progress); + ProgressBtn.Visible = true; + }; + + levelSeekBar.OnStopTrackingTouchEvent += (sender, e) => + { + ProgressBtn.Visible = false; + }; + + 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 }; 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 + }; + layout.AddChidren(ProgressBtn); } #endregion @@ -479,7 +527,6 @@ { switchBtn.MouseUpEventHandler += Switch_MouseUpEvent; collectionBtn.MouseUpEventHandler += Collection; - moreBtn.MouseUpEventHandler += MoreEvent; } #endregion @@ -494,13 +541,18 @@ private void Switch_MouseUpEvent(object sender, MouseEventArgs eventArgs) { switchBtn.IsSelected = !switchBtn.IsSelected; + StatuBtn.Text = CommonFormResouce.GetSwitchStatu(switchBtn.IsSelected); if (switchBtn.IsSelected == true) { dimmableLight.SwitchControl(1); + levelSeekBar.IsClickable = true; + levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarColor; } else { dimmableLight.SwitchControl(0); + levelSeekBar.IsClickable = false; + levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor; } } @@ -531,17 +583,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 -- Gitblit v1.8.0