From 6fa9d69da922c8049f5acfcbb9ce9fd26811024c Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期四, 16 四月 2020 17:10:57 +0800 Subject: [PATCH] 请合并代码 --- ZigbeeApp/Shared/Phone/Device/CommonForm/RoomView.cs | 266 +++++++++++++++++++++------------------------------- 1 files changed, 109 insertions(+), 157 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/Device/CommonForm/RoomView.cs b/ZigbeeApp/Shared/Phone/Device/CommonForm/RoomView.cs index dd89ea7..d9e47fd 100755 --- a/ZigbeeApp/Shared/Phone/Device/CommonForm/RoomView.cs +++ b/ZigbeeApp/Shared/Phone/Device/CommonForm/RoomView.cs @@ -2,21 +2,16 @@ using Shared.Common; using Shared.Phone.Device.DeviceLogic; using Shared.Phone.UserCenter; -using Shared.Phone.UserView; using ZigBee.Device; namespace Shared.Phone.Device.CommonForm { - public class RoomView:FrameLayout, ZigBee.Common.IStatus + public class RoomView : FrameLayout { /// <summary> /// Room /// </summary> private Common.Room room; - /// <summary> - /// action - /// </summary> - public Action action; FrameLayout roomNameBackground; @@ -24,132 +19,17 @@ Button roomListBtn; - Button temperatureText; + Button temperatureText; Button humidityText; - - CommonDevice temperDevice; - - CommonDevice humidDevice; - - #region 鈼� 鎺ュ彛__________________________ - /// <summary> - /// 澶勭悊鍙樺寲浜嬩欢 --灏嗗純鐢� 鏀圭敤DeviceInfoChange() + /// <summary> + /// 娓╁害璁惧 /// </summary> - /// <returns>The changed.</returns> - /// <param name="common">Common.</param> - public void Changed(CommonDevice common) - { - - } - /// <summary> - /// Changeds the IL ogic status. + private CommonDevice temperDevice = null; + /// <summary> + /// 婀垮害璁惧 /// </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> - /// <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 - { - if (common.DeviceStatusReport.AttriBute == null || common.DeviceStatusReport.AttriBute.Count == 0) - { - return; - } - //鏄惁涓哄綋鍓嶈澶� - if ((temperDevice?.DeviceEpoint != common.DeviceEpoint || temperDevice?.DeviceAddr != common.DeviceAddr) && (humidDevice?.DeviceEpoint != common.DeviceEpoint || humidDevice?.DeviceAddr != common.DeviceAddr) ) - { - //return; - } - - //if (common.Type == DeviceType.TemperatureSensor) - //{ - if (common.DeviceStatusReport.CluterID == 1026) - { - foreach (var data in common.DeviceStatusReport.AttriBute) - { - if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue) - { - if (data.AttriButeData == 0) - { - //0 - humidityText.Text = "--%"; - room.Humidity = 0; - } - else - { - //灏忔暟鐐归渶瑕佷竴浣�(婀垮害娌℃湁璐熸暟) - string strValue = data.AttriButeData.ToString(); - strValue = strValue.Substring(0, strValue.Length - 1); - humidityText.Text = strValue.Insert(strValue.Length - 1, ".") + "%"; - room.Humidity = int.Parse(strValue) * 0.1; - } - } - } - } - else if (common.DeviceStatusReport.CluterID == 1029) - { - foreach (var data in common.DeviceStatusReport.AttriBute) - { - if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue) - { - if (data.AttriButeData == 0) - { - //0 - humidityText.Text = "--%"; - room.Humidity = 0; - } - else - { - //灏忔暟鐐归渶瑕佷竴浣�(婀垮害娌℃湁璐熸暟) - string strValue = data.AttriButeData.ToString(); - strValue = strValue.Substring(0, strValue.Length - 1); - humidityText.Text = strValue.Insert(strValue.Length - 1, ".") + "%"; - room.Humidity = int.Parse(strValue) * 0.1; - } - } - } - } - //} - } - catch (Exception ex) - { - System.Console.WriteLine($"Error:{ex.Message}"); - } - }); - } - } - #endregion - - public override void RemoveFromParent() - { - ZbGateway.StatusList.Remove(this); - base.RemoveFromParent(); - } + private CommonDevice humidDevice = null; /// <summary> /// RoomView @@ -162,7 +42,6 @@ Y = Application.GetRealHeight(y); Width = Application.GetRealWidth(717); Height = Application.GetRealHeight(478); - ZbGateway.StatusList.Add(this); } /// <summary> @@ -171,25 +50,38 @@ /// <param name="r"></param> public void Init(Common.Room r) { + this.RemoveAll(); + this.room = r; - this.temperDevice= Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice); + this.temperDevice = Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice); - this.humidDevice= Common.LocalDevice.Current.GetDevice(room.HumidityDevice); + this.humidDevice = Common.LocalDevice.Current.GetDevice(room.HumidityDevice); var roomBackView = new FrameLayout() { Width = Application.GetRealWidth(717), - Height = Application.GetRealHeight(478) + Height = Application.GetRealHeight(478), + Radius = (uint)Application.GetRealHeight(17), + Tag = "R" }; AddChidren(roomBackView); var roomImg = new ImageView() { ImagePath = room.BackgroundImageType == 0 ? room.BackgroundImage : System.IO.Path.Combine(Config.Instance.FullPath, room.BackgroundImage), - Radius = (uint)Application.GetRealHeight(17) + Radius = (uint)Application.GetRealHeight(17), + Tag = "R" }; roomBackView.AddChidren(roomImg); + + //鍔犱釜鐗规畩鐨勯伄缃� + var frameBackGroudTemp = new FrameLayout(); + frameBackGroudTemp.Width = roomBackView.Width; + frameBackGroudTemp.Height = roomBackView.Height; + frameBackGroudTemp.Radius = (uint)Application.GetRealHeight(17); + frameBackGroudTemp.BackgroundColor = UserCenterColor.Current.PictrueZhezhaoColor; + roomBackView.AddChidren(frameBackGroudTemp); roomNameBackground = new FrameLayout { @@ -204,15 +96,17 @@ var roomName = new Button() { - X = Application.GetRealWidth(5), + X = Application.GetRealWidth(29), Width = Application.GetRealWidth(190), Text = room.Name, TextColor = ZigbeeColor.Current.GXCTextWhiteColor, - TextSize=10, - IsBold=true + TextSize = 10, + TextAlignment = TextAlignment.CenterLeft, + IsBold = true }; roomNameBackground.AddChidren(roomName); - + roomNameBackground.Width = (roomName.GetTextWidth() + Application.GetRealWidth(100)) > Application.GetRealWidth(600) ? Application.GetRealWidth(600) : roomName.GetTextWidth() + Application.GetRealWidth(100); + roomName.Width = roomNameBackground.Width - Application.GetRealWidth(40); roomTemperatureBackground = new FrameLayout { @@ -239,16 +133,21 @@ { X = Application.GetRealWidth(69), Width = Application.GetRealWidth(120), - Height = Application.GetRealHeight(58), - Gravity = Gravity.CenterVertical, - Text = Math.Abs(room.Temperatrue) <= 0 ? "--鈩�" : $"{room.Temperatrue}鈩�", - TextSize=14 + Text = "--鈩�", + TextSize = 14, + TextAlignment = TextAlignment.CenterLeft }; + if (LocalDevice.Current.GetDevice(room.TemperatrueDevice) != null) + { + //杩欎釜璁惧瑕佸瓨鍦ㄦ湰鍦版墠琛� + temperatureText.Text = room.Temperatrue == 0 ? "0.0鈩�" : room.Temperatrue.ToString() + "鈩�"; + } roomTemperatureBackground.AddChidren(temperatureText); + temperatureText.Width = temperatureText.GetTextWidth() + Application.GetRealWidth(60); var humidityIcon = new Button { - X = Application.GetRealWidth(200), + X = temperatureText.Right, Width = Application.GetMinRealAverage(58), Height = Application.GetMinRealAverage(58), Gravity = Gravity.CenterVertical, @@ -258,18 +157,23 @@ humidityText = new Button { - X = Application.GetRealWidth(260), + X = humidityIcon.Right, Width = Application.GetRealWidth(120), - Height = Application.GetRealHeight(58), - Gravity = Gravity.CenterVertical, - Text = Math.Abs(room.Temperatrue) <= 0 ? "--%" : $"{room.Humidity}%", - TextSize=14 + Text = "--%", + TextSize = 14, + TextAlignment = TextAlignment.CenterLeft }; + if (LocalDevice.Current.GetDevice(room.HumidityDevice) != null) + { + //杩欎釜璁惧瑕佸瓨鍦ㄦ湰鍦版墠琛� + humidityText.Text = room.Humidity == 0 ? "0.0%" : room.Humidity.ToString() + "%"; + } roomTemperatureBackground.AddChidren(humidityText); - + humidityText.Width = humidityText.GetTextWidth() + Application.GetRealWidth(60); + roomTemperatureBackground.Width = (humidityText.Width + temperatureText.Width + Application.GetRealWidth(150)) > Application.GetRealWidth(600) ? Application.GetRealWidth(600) : (humidityText.Width + temperatureText.Width + Application.GetRealWidth(150)); if (string.IsNullOrEmpty(room.TemperatrueDevice) == false) - { + { //鍙戦�佽幏鍙栨俯搴︾殑鍛戒护 var dev = Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice); ReadDeviceAttributeLogic.Instance.SendTemperatureStatuComand(dev); @@ -280,7 +184,6 @@ var dev = Common.LocalDevice.Current.GetDevice(room.HumidityDevice); ReadDeviceAttributeLogic.Instance.SendHumidityStatuComand(dev); } - roomListBtn = new Button() { @@ -295,15 +198,55 @@ roomListBtn.MouseUpEventHandler += (send, e) => { CommonPage.Instance.IsDrawerLockMode = true; - var editRoom = new Device.Room.EditRoom(); - HomePage.Instance.AddChidren(editRoom); - HomePage.Instance.PageIndex += 1; - editRoom.Show(room); - editRoom.action += () => - { - action?.Invoke(); + + var form = new UserCenter.Residence.EditorRoomInforForm(); + form.AddForm(room); + form.FinishEditorEvent += (roomName2) => + { + //閲嶆柊鍒锋柊鎺т欢 + this.Init(this.room); }; }; + //璁惧灞炴�т笂鎶� + HdlGatewayReceiveLogic.Current.AddAttributeEvent("RoomView" + this.room.Id, ReceiveComandDiv.A璁惧灞炴�т笂鎶�, (report) => + { + if (this.temperDevice != null) + { + //娓╁害璁惧 + if (report.DeviceAddr == temperDevice.DeviceAddr && report.DeviceEpoint == temperDevice.DeviceEpoint) + { + HdlThreadLogic.Current.RunMain(() => + { + if (((TemperatureSensor)temperDevice).Temperatrue == 0) + { + temperatureText.Text = "0.0鈩�"; + } + else + { + temperatureText.Text = ((TemperatureSensor)temperDevice).Temperatrue + "鈩�"; + } + }, ShowErrorMode.NO); + } + } + if (this.humidDevice != null) + { + //婀垮害璁惧 + if (report.DeviceAddr == humidDevice.DeviceAddr && report.DeviceEpoint == humidDevice.DeviceEpoint) + { + HdlThreadLogic.Current.RunMain(() => + { + if (((TemperatureSensor)temperDevice).Humidity == 0) + { + humidityText.Text = "--%"; + } + else + { + humidityText.Text = ((TemperatureSensor)temperDevice).Humidity + "%"; + } + }, ShowErrorMode.NO); + } + } + }); } /// <summary> @@ -312,6 +255,15 @@ public void HideName(bool statu) { roomNameBackground.Visible = roomTemperatureBackground.Visible = roomListBtn.Visible = !statu; + } + + /// <summary> + /// + /// </summary> + public override void RemoveFromParent() + { + HdlGatewayReceiveLogic.Current.RemoveEvent("RoomView" + this.room.Id); + base.RemoveFromParent(); } } } -- Gitblit v1.8.0