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/OnOffControl.cs | 724 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 723 insertions(+), 1 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/Device/Light/OnOffControl.cs b/ZigbeeApp/Shared/Phone/Device/Light/OnOffControl.cs index 2c82b6e..bb3e05b 100755 --- a/ZigbeeApp/Shared/Phone/Device/Light/OnOffControl.cs +++ b/ZigbeeApp/Shared/Phone/Device/Light/OnOffControl.cs @@ -1,13 +1,735 @@ 锘縰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 { /// <summary> /// 寮�鍏� /// </summary> - public class OnOffControl + public class OnOffControl:FrameLayout, ZigBee.Common.IStatus { + #region 鈼� 鍙橀噺__________________________ + /// <summary> + /// 寮�鍏� + /// </summary> + private Button switchBtn; + /// <summary> + /// The action. + /// </summary> + public Action<CommonDevice, Common.Room> action; + + /// <summary> + /// The light image. + /// </summary> + private Button deviceIMG; + /// <summary> + /// 鏀惰棌鎸夐挳 + /// </summary> + private Button collectionBtn; + /// <summary> + /// 浼犺繃鏉ョ殑璁惧 + /// </summary> + private CommonDevice device; + /// <summary> + /// 浼犺繃鏉ョ殑鎴块棿 + /// </summary> + private Shared.Common.Room room; + + /// <summary> + /// 鎴块棿 + /// </summary> + private Button roomBtn; + /// <summary> + /// 鎴块棿鍚� + /// </summary> + private Button roomName; + /// <summary> + /// 缃戝叧 + /// </summary> + private ZbGateway zbGateway = null; + /// <summary> + /// 鏄惁鍙戦�佹帶鍒跺懡浠ゆ垚鍔熶簡 + /// </summary> + private bool sendedControlCommand = false; + + /// <summary> + /// bodyFrameLayout + /// </summary> + private FrameLayout bodyFrameLayout; + + private Button StatuBtn; + /// <summary> + /// OnBtn + /// </summary> + private Button OnBtn; + /// <summary> + /// OffBtn + /// </summary> + private Button OffBtn; + + /// <summary> + /// IsDrawerLockMode + /// </summary> + public bool IsDrawerLockMode; + #endregion + + #region 鈼� 鎺ュ彛__________________________ + + /// <summary> + /// 璁惧鐘舵�佹洿鏂版帴鍙� + /// <para>type锛氬鏋滀负 DeviceInComingRespon:璁惧鏂颁笂鎶�</para> + /// <para>type锛氬鏋滀负 IASInfoReport:RemoveDeviceRespon</para> + /// <para>type锛氬鏋滀负 DeviceStatusReport:璁惧涓婃姤</para> + /// <para>type锛氬鏋滀负 IASInfoReport:IAS瀹夐槻淇℃伅涓婃姤</para> + /// <para>type锛氬鏋滀负 OnlineStatusChange: 璁惧鍦ㄧ嚎鐘舵�佹洿鏂�</para> + /// </summary> + /// <param name="common">Common.</param> + /// <param name="typeTag">Type tag.</param> + public void DeviceInfoChange(CommonDevice common, string typeTag) + { + if (typeTag == "DeviceStatusReport") + { + Application.RunOnMainThread(() => + { + try + { + var deviceUI = device; + //璁惧涓虹┖ + if (deviceUI == null) + { + return; + } + //鏄惁涓哄綋鍓嶈澶� + if (deviceUI.DeviceEpoint != common.DeviceEpoint || deviceUI.DeviceAddr != common.DeviceAddr) + { + return; + } + if (deviceUI.Type == DeviceType.OnOffOutput) + { + if (common.DeviceStatusReport.CluterID == 6) + { + var light = deviceUI as ToggleLight; + light.DeviceStatusReport = common.DeviceStatusReport; + //璁板綍銆佹洿鏂扮姸鎬� + if (light.DeviceStatusReport.AttriBute == null || light.DeviceStatusReport.AttriBute.Count == 0) + { + return; + } + light.OnOffStatus = light.DeviceStatusReport.AttriBute[0].AttriButeData; + StatuBtn.Text = Language.StringByID(R.MyInternationalizationString.Current) + " " + UserCenter.HdlDeviceOtherLogic.Current.GetDeviceStatu(device); + + if (device.DfunctionType == DeviceFunctionType.A寮�鍏�) + { + SetONOFFStatu(light.OnOffStatus == 1); + } + else if (device.DfunctionType == DeviceFunctionType.A鎻掑骇) + { + deviceIMG.IsSelected = switchBtn.IsSelected = light.OnOffStatus == 1; + } + else + { + deviceIMG.IsSelected = switchBtn.IsSelected = light.OnOffStatus == 1; + } + + + light.LastDateTime = DateTime.Now; + } + } + } + catch (Exception ex) + { + System.Console.WriteLine($"Error:{ex.Message}"); + } + }); + } + else if (typeTag == "OnlineStatusChange") + { + Application.RunOnMainThread(() => + { + try + { + var deviceUI = device; + //璁惧涓虹┖ + if (deviceUI == null) + { + return; + } + //鏄惁涓哄綋鍓嶈澶� + if (deviceUI.DeviceEpoint != common.DeviceEpoint || deviceUI.DeviceAddr != common.DeviceAddr) + { + return; + } + deviceUI.IsOnline = common.IsOnline; + //OnBtn.IsSelected = OffBtn.IsSelected= deviceUI.CommonDevice.IsOnline == 1; + deviceUI.LastDateTime = DateTime.Now; + } + catch (Exception ex) + { + System.Console.WriteLine($"Error:{ex.Message}"); + } + }); + } + } + #endregion + + #region 鈼� 鍒濆鍖朹____________________ + /// <summary> + /// 閲嶅啓绉婚櫎鏂规硶 + /// </summary> + public override void RemoveFromParent() + { + ZbGateway.StatusList.Remove(this); + action(device, room); + action = null; + RemoveUpdateControlDeviceStatuAction(); + if (IsDrawerLockMode) + { + CommonPage.Instance.IsDrawerLockMode = false; + } + base.RemoveFromParent(); + } + + /// <summary> + /// 鏋勯�犳柟娉� + /// </summary> public OnOffControl() { + 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); + + 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); + + AddByFunctionType(itemView); + } + + /// <summary> + /// AddByFunctionType + /// </summary> + private void AddByFunctionType(FrameLayout itemView) + { + if(device.DfunctionType == DeviceFunctionType.A寮�鍏�) + { + AddOnOff(itemView); + } + else if(device.DfunctionType == DeviceFunctionType.A鎻掑骇) + { + AddPlug(itemView); + } + else + { + AddLight(itemView); + } + } + + /// <summary> + /// AddOnOff + /// </summary> + private void AddOnOff(FrameLayout itemView) + { + deviceIMG = new Button() + { + Y = Application.GetRealHeight(340), + Width = Application.GetMinRealAverage(579), + Height = Application.GetMinRealAverage(579), + Gravity = Gravity.CenterHorizontal, + UnSelectedImagePath = "Light/OnOff.png", + }; + itemView.AddChidren(deviceIMG); + + OffBtn = new Button + { + X = Application.GetRealWidth(294), + Y = Application.GetRealHeight(588), + Width = Application.GetMinRealAverage(81), + Height = Application.GetMinRealAverage(81), + UnSelectedImagePath = "Light/OFF.png", + SelectedImagePath = "Light/OFFSelected.png", + IsSelected = (device as ToggleLight).OnOffStatus == 0 + }; + itemView.AddChidren(OffBtn); + + OnBtn = new Button + { + X = Application.GetRealWidth(590), + Y = Application.GetRealHeight(588), + Width = Application.GetMinRealAverage(81), + Height = Application.GetMinRealAverage(81), + UnSelectedImagePath = "Light/ON.png", + SelectedImagePath = "Light/ONSelected.png", + IsSelected = (device as ToggleLight).OnOffStatus == 1 + }; + itemView.AddChidren(OnBtn); + + OnBtn.MouseUpEventHandler += ON; + OffBtn.MouseUpEventHandler += OFF; + } + + /// <summary> + /// light + /// </summary> + /// <param name="itemView"></param> + private void AddLight(FrameLayout itemView) + { + 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); + + switchBtn.MouseUpEventHandler += Switch; + deviceIMG.MouseUpEventHandler += Switch; + } + + /// <summary> + /// plug + /// </summary> + /// <param name="itemView"></param> + private void AddPlug(FrameLayout itemView) + { + deviceIMG = new Button() + { + Y = Application.GetRealHeight(344), + Width = Application.GetMinRealAverage(567), + Height = Application.GetMinRealAverage(567), + Gravity = Gravity.CenterHorizontal, + UnSelectedImagePath = "Light/Plug.png", + SelectedImagePath = "Light/PlugSelected.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); + + switchBtn.MouseUpEventHandler += Switch; + deviceIMG.MouseUpEventHandler += Switch; + } + + #endregion + + #region 鈼� 缁戝畾鎸夐挳_______________________ + /// <summary> + /// 缁戝畾鎸夐挳鐨勪簨浠� + /// </summary> + private void BindEvent() + { + collectionBtn.MouseUpEventHandler += Collection; + } + + #endregion + + #region 鈼� 寮�鍏砡_________________________ + + /// <summary> + /// 寮�鍏宠缃� + /// </summary> + /// <param name="sender">Sender.</param> + /// <param name="eventArgs">Event arguments.</param> + private void Switch(object sender, MouseEventArgs eventArgs) + { + 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 as ToggleLight).SwitchControl(1); + } + else + { + (device as ToggleLight).SwitchControl(0); + } + //鎺у埗寤舵椂鍥炶皟 + UserCenter.HdlDeviceOtherLogic.Current.SendCommandDelayAction(device, () => + { + if (Parent == null) + { + return; + } + RemoveUpdateControlDeviceStatuAction(); + if (sendedControlCommand == false) + { + UserCenter.HdlDeviceOtherLogic.Current.ShowStatuTip(R.MyInternationalizationString.FAIL); + } + }); + } + + /// <summary> + /// ON + /// </summary> + /// <param name="sender"></param> + /// <param name="eventArgs"></param> + private void ON(object sender, MouseEventArgs eventArgs) + { + SetONOFFStatu(true); + (device as ToggleLight).SwitchControl(1); + //鎺у埗寤舵椂鍥炶皟 + zbGateway.ReportAction += UpdateDeviceControllStatu; + UserCenter.HdlDeviceOtherLogic.Current.SendCommandDelayAction(device, () => + { + if (Parent == null) + { + return; + } + RemoveUpdateControlDeviceStatuAction(); + if (sendedControlCommand == false) + { + UserCenter.HdlDeviceOtherLogic.Current.ShowStatuTip(R.MyInternationalizationString.FAIL); + } + }); + } + /// <summary> + /// OFF + /// </summary> + /// <param name="sender"></param> + /// <param name="eventArgs"></param> + private void OFF(object sender, MouseEventArgs eventArgs) + { + SetONOFFStatu(false); + (device as ToggleLight).SwitchControl(0); + //鎺у埗寤舵椂鍥炶皟 + zbGateway.ReportAction += UpdateDeviceControllStatu; + UserCenter.HdlDeviceOtherLogic.Current.SendCommandDelayAction(device, () => + { + if (Parent == null) + { + return; + } + RemoveUpdateControlDeviceStatuAction(); + if (sendedControlCommand == false) + { + UserCenter.HdlDeviceOtherLogic.Current.ShowStatuTip(R.MyInternationalizationString.FAIL); + } + }); + } + + /// <summary> + /// SetONOFFStatu + /// </summary> + /// <param name="statu"></param> + private void SetONOFFStatu(bool statu) + { + StatuBtn.Text = Language.StringByID(R.MyInternationalizationString.Current) + " "; + if (statu) + { + OnBtn.IsSelected = true; + OffBtn.IsSelected = false; + StatuBtn.Text += Language.StringByID(R.MyInternationalizationString.uOpen1); + } + else + { + OnBtn.IsSelected = false; + OffBtn.IsSelected = true; + StatuBtn.Text += Language.StringByID(R.MyInternationalizationString.Close); + } + } + + + #endregion + + #region 鈼� 璁剧疆__________________________ + /// <summary> + /// 鏇村璁剧疆 + /// </summary> + /// <param name="sender">Sender.</param> + /// <param name="e">E.</param> + private void More(object sender, MouseEventArgs e) + { + var detailInfo = new Device.CommonForm.DeviceDetailInfo { }; + UserView.HomePage.Instance.AddChidren(detailInfo); + UserView.HomePage.Instance.PageIndex += 1; + detailInfo.Show(device, room); + detailInfo.EditAction += (curDev, curRoom) => + { + Show(curDev, curRoom); + }; + } + + #endregion + + #region 鈼� 鏀惰棌__________________________ + /// <summary> + /// 鏀惰棌鍒颁富椤� + /// </summary> + /// <param name="sender">Sender.</param> + /// <param name="e">E.</param> + private void Collection(object sender, MouseEventArgs e) + { + //collection + if ((sender as Button).IsSelected) + { + UserCenter.HdlRoomLogic.Current.DeleteLoveDevice(device); + (sender as Button).IsSelected = false; + } + else + { + UserCenter.HdlRoomLogic.Current.AddLoveDevice(device); + (sender as Button).IsSelected = true; + } + } + + #endregion + + #region 鈼� 璁惧鎺у埗鐘舵�乢____________________ + + /// <summary> + /// 鏄剧ず璁惧鎺у埗鐘舵�� + /// </summary> + /// <param name="command">Command.</param> + /// <param name="objValue">Object value.</param> + private void UpdateDeviceControllStatu(string command, object objValue) + { + if (Parent == null) + { + return; + } + if (command != "DeviceDefaultAck" || objValue == null) + { + return; + } + var tempDevice = (CommonDevice)objValue; + if (tempDevice.DeviceEpoint != this.device.DeviceEpoint || tempDevice.DeviceAddr != this.device.DeviceAddr) + { + //涓嶆槸褰撳墠璁惧鐨勬帹閫侊紝鍒欎笉澶勭悊 + return; + } + //鏍囪宸茬粡鍙戦�佹帶鍒跺懡浠ゅ埌缃戝叧 + sendedControlCommand = true; + //DeviceUI.ShowStatuTip(R.MyInternationalizationString.Success); + } + + /// <summary> + /// 绉婚櫎鏇存柊鎺у埗璁惧鐨刟ction + /// </summary> + private void RemoveUpdateControlDeviceStatuAction() + { + //绉婚櫎action + if (zbGateway != null) + { + zbGateway.ReportAction -= UpdateDeviceControllStatu; + } + } + + #endregion } } -- Gitblit v1.8.0