From 94e4e5b9fd3da964c44b7b14227d6fe2bbb426d7 Mon Sep 17 00:00:00 2001 From: WJC <wjc@hdlchina.com.cn> Date: 星期四, 02 四月 2020 13:56:39 +0800 Subject: [PATCH] 2020-04-02-2 --- ZigbeeApp/Shared/Phone/Device/Light/LightControl.cs | 565 +++++++++++++++++++++++++++---------------------------- 1 files changed, 276 insertions(+), 289 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/Device/Light/LightControl.cs b/ZigbeeApp/Shared/Phone/Device/Light/LightControl.cs index d586038..504214d 100755 --- a/ZigbeeApp/Shared/Phone/Device/Light/LightControl.cs +++ b/ZigbeeApp/Shared/Phone/Device/Light/LightControl.cs @@ -1,6 +1,8 @@ 锘縰sing System; using System.Collections.Generic; using Shared.Common; +using Shared.Phone.Device.CommonForm; +using Shared.Phone.Device.DeviceLogic; using Shared.Phone.UserView; using ZigBee.Device; namespace Shared.Phone.Device.Light @@ -12,25 +14,14 @@ { #region 鈼� 鍙橀噺__________________________ /// <summary> - /// 璁惧鏄惁鍦ㄧ嚎鏍囪瘑--Online - /// </summary> - private readonly string DeviceStatus_Online = "Online"; - /// <summary> - /// 璁惧鐘舵�佸紑鍏虫爣璇�--Switch - /// </summary> - private readonly string DeviceStatus_OnOffStatus = "Switch"; - /// <summary> /// 寮�鍏� /// </summary> private Button switchBtn; /// <summary> /// The action. /// </summary> - public Action action; - /// <summary> - /// The light view. - /// </summary> - private FrameLayout deviceView; + public Action<CommonDevice, Common.Room> action; + /// <summary> /// The light image. /// </summary> @@ -42,15 +33,12 @@ /// <summary> /// 浼犺繃鏉ョ殑璁惧 /// </summary> - private DeviceUI device; + private CommonDevice device; /// <summary> /// 浼犺繃鏉ョ殑鎴块棿 /// </summary> private Shared.Common.Room room; - /// <summary> - /// 鏇村璁剧疆 - /// </summary> - private Button moreBtn; + /// <summary> /// 鎴块棿 /// </summary> @@ -68,34 +56,21 @@ /// </summary> private bool sendedControlCommand = false; + /// <summary> + /// bodyFrameLayout + /// </summary> + private FrameLayout bodyFrameLayout; + + private Button StatuBtn; + + /// <summary> + /// IsDrawerLockMode + /// </summary> + public bool IsDrawerLockMode; #endregion #region 鈼� 鎺ュ彛__________________________ - /// <summary> - /// 澶勭悊鍙樺寲浜嬩欢 --灏嗗純鐢� 鏀圭敤DeviceInfoChange() - /// </summary> - /// <returns>The changed.</returns> - /// <param name="common">Common.</param> - public void Changed(CommonDevice common) - { - - } - /// <summary> - /// Changeds the IL ogic status. - /// </summary> - /// <param name="logic">Logic.</param> - public void ChangedILogicStatus(ZigBee.Device.Logic logic) - { - //throw new NotImplementedException(); - } - /// <summary> - /// Changeds the IS cene status. - /// </summary> - /// <param name="scene">Scene.</param> - public void ChangedISceneStatus(Scene scene) - { - //throw new NotImplementedException(); - } + /// <summary> /// 璁惧鐘舵�佹洿鏂版帴鍙� /// <para>type锛氬鏋滀负 DeviceInComingRespon:璁惧鏂颁笂鎶�</para> @@ -114,38 +89,31 @@ { try { - var deviceUI = deviceView.Tag as DeviceUI; + var deviceUI = device; //璁惧涓虹┖ - if (deviceUI.CommonDevice == null) + if (deviceUI == null) { return; } //鏄惁涓哄綋鍓嶈澶� - if (deviceUI.CommonDevice.DeviceEpoint != common.DeviceEpoint || deviceUI.CommonDevice.DeviceAddr != common.DeviceAddr) + if (deviceUI.DeviceEpoint != common.DeviceEpoint || deviceUI.DeviceAddr != common.DeviceAddr) { return; } - if (deviceUI.CommonDevice.Type == DeviceType.OnOffOutput) + if (deviceUI.Type == DeviceType.OnOffOutput) { - if ((common as ToggleLight).DeviceStatusReport.CluterID == 6) + if (common.DeviceStatusReport.CluterID == 6) { - var light = deviceUI.CommonDevice as ToggleLight; - light.DeviceStatusReport = (common as ToggleLight).DeviceStatusReport; + var light = deviceUI as ToggleLight; + light.DeviceStatusReport = common.DeviceStatusReport; //璁板綍銆佹洿鏂扮姸鎬� - if(light.DeviceStatusReport.AttriBute==null || light.DeviceStatusReport.AttriBute.Count==0) + if (light.DeviceStatusReport.AttriBute == null || light.DeviceStatusReport.AttriBute.Count == 0) { return; } light.OnOffStatus = light.DeviceStatusReport.AttriBute[0].AttriButeData; - switchBtn.IsSelected = light.OnOffStatus == 1; - light.LastDateTime = DateTime.Now; - } - //***鏂版敼***璁惧鐘舵�佷笂鎶ヤ腑锛屽綋CluterID=3,璇佹槑璁惧鍦ㄧ嚎锛岀洿鎺ユ爣璁� - else if ((common as ToggleLight).DeviceStatusReport.CluterID == 3) - { - var light = deviceUI.CommonDevice as ToggleLight; - light.IsOnline = 1; - deviceIMG.IsSelected = light.IsOnline == 1; + deviceIMG.IsSelected = switchBtn.IsSelected = light.OnOffStatus == 1; + StatuBtn.Text = Language.StringByID(R.MyInternationalizationString.Current) + " " + UserCenter.HdlDeviceOtherLogic.Current.GetDeviceStatu(device); light.LastDateTime = DateTime.Now; } } @@ -162,27 +130,22 @@ { try { - var deviceUI = deviceView.Tag as DeviceUI; + var deviceUI = device; //璁惧涓虹┖ - if (deviceUI.CommonDevice == null) + if (deviceUI == null) { return; } //鏄惁涓哄綋鍓嶈澶� - if (deviceUI.CommonDevice.DeviceEpoint != common.DeviceEpoint || deviceUI.CommonDevice.DeviceAddr != common.DeviceAddr) + if (deviceUI.DeviceEpoint != common.DeviceEpoint || deviceUI.DeviceAddr != common.DeviceAddr) { return; } - if (deviceUI.CommonDevice.Type == DeviceType.OnOffOutput) - { - var light = deviceUI.CommonDevice as ToggleLight; - light.IsOnline = (common as ToggleLight).IsOnline; - deviceIMG.IsSelected = light.IsOnline == 1; - light.LastDateTime = DateTime.Now; - } + deviceUI.IsOnline = common.IsOnline; + deviceUI.LastDateTime = DateTime.Now; } catch (Exception ex) - { + { System.Console.WriteLine($"Error:{ex.Message}"); } }); @@ -190,199 +153,19 @@ } #endregion - #region 鈼� 鍒濆鍖朹_______________________ - /// <summary> - /// 鏄剧ず鐣岄潰 - /// </summary> - /// <param name="device">Device.</param> - /// <param name="room">Room.</param> - public void Show(DeviceUI device,Shared.Common.Room room) - { - #region topview - - var topBGView = new FrameLayout()鈥� {鈥� Height = Application.GetRealHeight(CommonPage.Navigation_Height),鈥� BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor鈥� };鈥� AddChidren(topBGView);鈥� var topView = new FrameLayout()鈥� {鈥� Y = Application.GetRealHeight(CommonPage.NavigationTitle_Y),鈥� Height = Application.GetRealHeight(CommonPage.Navigation_Height - CommonPage.NavigationTitle_Y),鈥� BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor,鈥� };鈥� AddChidren(topView); - - moreBtn = new Device.CommonForm.SelectedStatuButton() - { - 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", - }; - topView.AddChidren(moreBtn); - - var back = new Device.CommonForm.BackButton() { };鈥� topView.AddChidren(back); - back.MouseUpEventHandler += (sender, e) => - { - this.RemoveFromParent(); - }; - - if (device == null || device.CommonDevice == null || room == null) - { - return; - } - this.device = device; - this.zbGateway = this.device.CommonDevice.Gateway; - this.room = room; - var light = device.CommonDevice as ToggleLight; - //琛ヤ笂闈炶繙绋� - if (light.Gateway == null) - { - return; - } - if (light.Gateway.IsVirtual) - { - UserHomeView.ReadStatus(light, () => - { - light.ReadOnOffStatus(); - light.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch); - }); - } - else - { - //闃叉鐭椂闂村唴澶氭璇诲彇鐘舵�� - if (CommonPage.ReadDeviceStatuSpan < (DateTime.Now - light.LastDateTime).TotalSeconds) - { - light.ReadOnOffStatus(); - light.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch); - } - } - #endregion - - #region midFL - var midFL = new FrameLayout() - { - Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height), - Y = topView.Bottom, - BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, - }; - this.AddChidren(midFL); - - var itemView = new FrameLayout() - { - X = Application.GetRealWidth(50), - Y = Application.GetRealHeight(50), - Width = Application.GetRealWidth(CommonPage.AppRealWidth - 100), - Height = Application.GetRealHeight(850), - Radius = CommonPage.BigFormRadius, - Gravity = Gravity.CenterHorizontal, - BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor - }; - midFL.AddChidren(itemView); - deviceView = new FrameLayout() - { - X = 2, - Y = 2, - Width = itemView.Width - 4, - Height = itemView.Height - Application.GetRealHeight(130), - BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, - Tag = device - }; - itemView.AddChidren(deviceView); - - collectionBtn = new Button() - { - X = deviceView.Width - Application.GetRealWidth(130), - Y = Application.GetRealHeight(20), - Width = Application.GetMinReal(110), - Height = Application.GetMinReal(110), - UnSelectedImagePath = "Item/Collection.png", - SelectedImagePath = "Item/CollectionSelected.png" - }; - deviceView.AddChidren(collectionBtn); - - deviceIMG = new Button() - { - Y = Application.GetRealHeight(100), - Height = Application.GetMinRealAverage(240), - Width = Application.GetMinRealAverage(240), - Gravity = Gravity.CenterHorizontal, - UnSelectedImagePath = device.IconPath, - SelectedImagePath = device.OnlineIconPath, - IsSelected = light.IsOnline == 1, - Tag = DeviceStatus_Online - }; - deviceView.AddChidren(deviceIMG); - - var lightName = new Button() - { - Y = deviceIMG.Bottom, - Height = Application.GetRealHeight(85), - Gravity = Gravity.CenterHorizontal, - Text = device.CommonDevice.DeviceEpointName, - TextColor = ZigbeeColor.Current.GXCTextBlackColor - }; - deviceView.AddChidren(lightName); - - switchBtn = new Button() - { - Y = lightName.Bottom + Application.GetRealHeight(70), - Gravity = Gravity.CenterHorizontal, - Width = Application.GetMinRealAverage(180), - Height = Application.GetMinRealAverage(120), - UnSelectedImagePath = "Item/Switch.png", - SelectedImagePath = "Item/SwitchSelected.png", - Tag = DeviceStatus_OnOffStatus, - IsSelected = light.OnOffStatus == 1 - }; - deviceView.AddChidren(switchBtn); - - roomBtn = new Button() - { - X = Application.GetRealWidth(50), - Y = Application.GetRealHeight(25) + deviceView.Bottom, - Width = Application.GetMinReal(80), - Height = Application.GetMinReal(80), - UnSelectedImagePath = "Item/Room.png", - SelectedImagePath = "Item/RoomSelected.png" - }; - itemView.AddChidren(roomBtn); - - roomName = new Button() - { - X = roomBtn.Right + Application.GetRealWidth(20), - Y = roomBtn.Y, - Width = Application.GetRealWidth(400), - Height = Application.GetRealHeight(80), - Text = room.Name, - TextAlignment = TextAlignment.CenterLeft, - TextColor = ZigbeeColor.Current.GXCTextBlackColor, - SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor - }; - itemView.AddChidren(roomName); - - //var moreBtn = new Button() - //{ - // X = itemView.Width - Application.GetRealWidth(130), - // Y = roomBtn.Y, - // Width = Application.GetMinReal(80), - // Height = Application.GetMinReal(80), - // UnSelectedImagePath = "Item/More.png", - // SelectedImagePath = "Item/MoreSelected.png", - //}; - //itemView.AddChidren(moreBtn); - var dev = Shared.Common.Room.LoveRoomDeviceUIFilePathList.Find((obj) => obj == device.FileName); - if (dev == null) - { - collectionBtn.IsSelected = false; - } - else - { - collectionBtn.IsSelected = true; - } - this.BindEvent(); - #endregion - } - + #region 鈼� 鍒濆鍖朹____________________ /// <summary> /// 閲嶅啓绉婚櫎鏂规硶 /// </summary> public override void RemoveFromParent() { ZbGateway.StatusList.Remove(this); - action(); + action(device, room); + action = null; + if (IsDrawerLockMode) + { + CommonPage.Instance.IsDrawerLockMode = false; + } RemoveUpdateControlDeviceStatuAction(); base.RemoveFromParent(); } @@ -395,6 +178,214 @@ BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor; ZbGateway.StatusList.Add(this); } + /// <summary> + /// 鏄剧ず鐣岄潰 + /// </summary> + /// <param name="dev">Device.</param> + /// <param name="room">Room.</param> + public void Show(CommonDevice dev,Shared.Common.Room room) + { + device = dev; + zbGateway = this.device.Gateway; + this.room = room; + + AddTop(); + + AddBodyView(device); + + + var light = dev as ToggleLight; + //琛ヤ笂闈炶繙绋� + if (light.Gateway == null) + { + return; + } + if (light.Gateway.IsVirtual) + { + UserHomeView.ReadStatus(light, () => + { + ReadDeviceAttributeLogic.Instance.SendLightStatuComand(device); + }); + } + else + { + //闃叉鐭椂闂村唴澶氭璇诲彇鐘舵�� + if (CommonPage.ReadDeviceStatuSpan < (DateTime.Now - light.LastDateTime).TotalSeconds) + { + ReadDeviceAttributeLogic.Instance.SendLightStatuComand(device); + } + } + + if(UserCenter.HdlRoomLogic.Current.IsCollectInRoom(device) == false) + { + collectionBtn.IsSelected = false; + } + else + { + collectionBtn.IsSelected = true; + } + + + BindEvent(); + + } + + #endregion + + #region 鈼� Add______________________________ + + /// <summary> + /// AddTop + /// </summary> + public void AddTop() + { + var top = new TopFrameLayout(); + AddChidren(top); + top.InitTopview(); + top.backButton.MouseUpEventHandler += (sender, e) => + { + RemoveFromParent(); + }; + + + 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 += More; + + } + /// <summary> + /// AddBodyView + /// </summary> + public void AddBodyView(CommonDevice device) + { + bodyFrameLayout = new FrameLayout() + { + Y = Application.GetRealHeight(184), + Height = Application.GetRealHeight(1737), + BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor, + }; + AddChidren(bodyFrameLayout); + + var itemView = new FrameLayout() + { + Y = Application.GetRealHeight(115), + Width = Application.GetRealWidth(965), + Height = Application.GetRealHeight(1316), + Radius =(uint)Application.GetRealHeight(CommonFormResouce.BigFormRadius), + Gravity = Gravity.CenterHorizontal, + BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor + }; + bodyFrameLayout.AddChidren(itemView); + + collectionBtn = new Button() + { + X = Application.GetRealWidth(850), + Y = Application.GetRealHeight(46), + Width = Application.GetMinReal(69), + Height = Application.GetMinReal(69), + UnSelectedImagePath = "Item/Collection.png", + SelectedImagePath = "Item/CollectionSelected.png" + }; + itemView.AddChidren(collectionBtn); + + var deviceNameBtn = new Button() + { + Y = Application.GetRealHeight(46), + Width=Application.GetRealWidth(500), + Height = Application.GetRealHeight(60), + Gravity = Gravity.CenterHorizontal, + Text = Common.LocalDevice.Current.GetDeviceEpointName(device), + TextColor = ZigbeeColor.Current.GXCTextBlackColor, + TextSize=15, + IsBold=true + }; + itemView.AddChidren(deviceNameBtn); + + StatuBtn = new Button + { + Y = Application.GetRealHeight(118), + Width = Application.GetRealWidth(600), + Height = Application.GetRealHeight(60), + Gravity = Gravity.CenterHorizontal, + TextColor = ZigbeeColor.Current.GXCTextGrayColor, + Text = Language.StringByID(R.MyInternationalizationString.Current) + " " + UserCenter.HdlDeviceOtherLogic.Current.GetDeviceStatu(device), + TextSize = 10 + }; + itemView.AddChidren(StatuBtn); + + + deviceIMG = new Button() + { + Y = Application.GetRealHeight(389), + Width = Application.GetMinRealAverage(377), + Height = Application.GetMinRealAverage(435), + Gravity = Gravity.CenterHorizontal, + UnSelectedImagePath = "Light/DeskLamp.png", + SelectedImagePath = "Light/DeskLampSelected.png", + IsSelected = (device as ToggleLight).OnOffStatus == 1 + }; + itemView.AddChidren(deviceIMG); + + switchBtn = new Button() + { + Y = Application.GetRealHeight(996), + Width = Application.GetMinRealAverage(81), + Height = Application.GetMinRealAverage(81), + Gravity = Gravity.CenterHorizontal, + UnSelectedImagePath = "Item/Switch.png", + SelectedImagePath = "Item/SwitchSelected.png", + IsSelected = (device as ToggleLight).OnOffStatus == 1 + }; + itemView.AddChidren(switchBtn); + + var roomBG = new Button + { + 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" + }; + itemView.AddChidren(roomBtn); + + roomName = new Button() + { + X = Application.GetRealWidth(150), + Y = Application.GetRealHeight(1224), + Width = Application.GetRealWidth(400), + Height = Application.GetRealHeight(50), + Text = room.Name, + TextAlignment = TextAlignment.CenterLeft, + TextColor = ZigbeeColor.Current.GXCTextWhiteColor, + TextSize=12 + }; + itemView.AddChidren(roomName); + } #endregion @@ -405,10 +396,8 @@ private void BindEvent() { switchBtn.MouseUpEventHandler += Switch; + deviceIMG.MouseUpEventHandler += Switch; collectionBtn.MouseUpEventHandler += Collection; - moreBtn.MouseUpEventHandler += More; - roomBtn.MouseUpEventHandler += BackToRoomHandler; - roomName.MouseUpEventHandler += BackToRoomHandler; } #endregion @@ -425,16 +414,27 @@ sendedControlCommand = false; zbGateway.ReportAction += UpdateDeviceControllStatu; switchBtn.IsSelected = !switchBtn.IsSelected; + deviceIMG.IsSelected = !deviceIMG.IsSelected; + StatuBtn.Text = Language.StringByID(R.MyInternationalizationString.Current) + " "; + if (deviceIMG.IsSelected == true) + { + StatuBtn.Text += Language.StringByID(R.MyInternationalizationString.uOpen1); + } + else + { + StatuBtn.Text += Language.StringByID(R.MyInternationalizationString.Close); + } + if (switchBtn.IsSelected == true) { - (device.CommonDevice as ToggleLight).SwitchControl(1); + (device as ToggleLight).SwitchControl(1); } else { - (device.CommonDevice as ToggleLight).SwitchControl(0); + (device as ToggleLight).SwitchControl(0); } //鎺у埗寤舵椂鍥炶皟 - DeviceUI.SendCommandDelayAction(device.CommonDevice, () => + UserCenter.HdlDeviceOtherLogic.Current.SendCommandDelayAction(device, () => { if(Parent==null) { @@ -443,10 +443,12 @@ RemoveUpdateControlDeviceStatuAction(); if (sendedControlCommand==false) { - DeviceUI.ShowStatuTip(R.MyInternationalizationString.FAIL); + UserCenter.HdlDeviceOtherLogic.Current.ShowStatuTip(R.MyInternationalizationString.FAIL); } }); } + + #endregion @@ -462,9 +464,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); }; } @@ -479,31 +481,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; + UserCenter.HdlRoomLogic.Current.DeleteLoveDevice(device); + (sender as Button).IsSelected = false; } else - { - Shared.Common.Room.Lists[0].AddDevice(device.FileName); - collectionBtn.IsSelected = true; + { + UserCenter.HdlRoomLogic.Current.AddLoveDevice(device); + (sender as Button).IsSelected = true; } - action?.Invoke(); - } - - #endregion - - #region 鈼� 鍥炲埌涓婚〉________________________ - /// <summary> - /// 鍥炲埌涓婚〉 - /// </summary> - /// <param name="sender">Sender.</param> - /// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param> - private void BackToRoomHandler(object sender, MouseEventArgs mouseEventArgs ) - { - //backToRoom - } #endregion @@ -526,7 +513,7 @@ return; } var tempDevice = (CommonDevice)objValue; - if (tempDevice.DeviceEpoint != this.device.CommonDevice.DeviceEpoint || tempDevice.DeviceAddr != this.device.CommonDevice.DeviceAddr) + if (tempDevice.DeviceEpoint != this.device.DeviceEpoint || tempDevice.DeviceAddr != this.device.DeviceAddr) { //涓嶆槸褰撳墠璁惧鐨勬帹閫侊紝鍒欎笉澶勭悊 return; -- Gitblit v1.8.0