From 66a9965c44ecc32a6696abca876ab9d1cd091584 Mon Sep 17 00:00:00 2001 From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local> Date: 星期五, 28 二月 2020 15:25:13 +0800 Subject: [PATCH] 2020.2.28 --- ZigbeeApp/Shared/Phone/Device/Room/EditRoom.cs | 377 +++++++++++++++++++++++++++-------------------------- 1 files changed, 192 insertions(+), 185 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/Device/Room/EditRoom.cs b/ZigbeeApp/Shared/Phone/Device/Room/EditRoom.cs index 94d2e87..a14d05a 100644 --- a/ZigbeeApp/Shared/Phone/Device/Room/EditRoom.cs +++ b/ZigbeeApp/Shared/Phone/Device/Room/EditRoom.cs @@ -3,12 +3,14 @@ using System.Globalization; using Shared.Common; using Shared.Phone.Device.CommonForm; +using Shared.Phone.Device.DeviceLogic; using Shared.Phone.UserCenter; using Shared.Phone.UserView; +using ZigBee.Device; namespace Shared.Phone.Device.Room { - public class EditRoom : FrameLayout + public class EditRoom : FrameLayout, ZigBee.Common.IStatus { #region 鈼� 鍙橀噺____________________________ /// <summary> @@ -44,11 +46,143 @@ /// </summary> public int OldIconPathType; - + public CommonDevice temperDevice; + + public CommonDevice humidDevice; + + DeviceInfoRow temperatureRow; + + DeviceInfoRow humidityRow; + #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> + /// <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鈩� + temperatureRow.NameText.Text = "--鈩�"; + room.Temperatrue = 0; + } + else if (data.AttriButeData > 32767) + { + //璐熸暟(鐗规畩澶勭悊) + string strValue = (data.AttriButeData - 65536).ToString(); + //灏忔暟鐐归渶瑕佷竴浣� + strValue = strValue.Substring(0, strValue.Length - 1); + temperatureRow.NameText.Text = strValue.Insert(strValue.Length - 1, ".") + "鈩�"; + room.Temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, ".")); + } + else + { + //灏忔暟鐐归渶瑕佷竴浣� + string strValue = data.AttriButeData.ToString(); + strValue = strValue.Substring(0, strValue.Length - 1); + temperatureRow.NameText.Text = strValue.Insert(strValue.Length - 1, ".") + "鈩�"; + room.Temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 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 + humidityRow.NameText.Text = "--%"; + room.Humidity = 0; + } + else + { + //灏忔暟鐐归渶瑕佷竴浣�(婀垮害娌℃湁璐熸暟) + string strValue = data.AttriButeData.ToString(); + strValue = strValue.Substring(0, strValue.Length - 1); + humidityRow.NameText.Text = strValue.Insert(strValue.Length - 1, ".") + "%"; + room.Humidity = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, ".")); + } + } + } + } + //} + } + catch (Exception ex) + { + System.Console.WriteLine($"Error:{ex.Message}"); + } + }); + } + } + #endregion + + public EditRoom() { + ZbGateway.StatusList.Add(this); BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor; } @@ -59,7 +193,7 @@ { room = r; IconPathType = r.BackgroundImageType; - OldIconPathType= r.BackgroundImageType; + OldIconPathType = r.BackgroundImageType; if (IconPathType != 0) { OldBackgroundImagePath = r.BackgroundImage; @@ -70,13 +204,11 @@ } - public override void RemoveFromParent() - { - HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice"); - HdlGatewayReceiveLogic.Current.RemoveEvent("HumidityDevice"); - - CommonPage.Instance.IsDrawerLockMode = false; - base.RemoveFromParent(); + public override void RemoveFromParent() + { + ZbGateway.StatusList.Remove(this); + CommonPage.Instance.IsDrawerLockMode = false; + base.RemoveFromParent(); } #region Add____________________________________ @@ -109,17 +241,27 @@ }; AddChidren(bodyFrameLayout); + var backGround1 = new ImageView() + { + Y = Application.GetRealHeight(60), + Width = Application.GetMinRealAverage(916), + Height = Application.GetMinRealAverage(487), + Gravity = Gravity.CenterHorizontal, + ImagePath = "Room/Room_Rectangle.png" + }; + bodyFrameLayout.AddChidren(backGround1); + backGround = new ImageView() { Y = Application.GetRealHeight(60), Width = Application.GetMinRealAverage(887), Height = Application.GetMinRealAverage(444), Gravity = Gravity.CenterHorizontal, - Radius = (uint)Application.GetRealHeight(CommonFormResouce.BigFormRadius), + Radius = (uint)Application.GetMinRealAverage(CommonFormResouce.BigFormRadius), ImagePath = room.BackgroundImageType == 0 ? room.BackgroundImage : System.IO.Path.Combine(Config.Instance.FullPath, room.BackgroundImage) }; bodyFrameLayout.AddChidren(backGround); - backGround.SetViewShadow(true); + if (room.BackgroundImageType != 0) { backGround.ImageBytes = Shared.IO.FileUtils.ReadFile(backGround.ImagePath); @@ -154,7 +296,7 @@ nameRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.RoomName)} :"); nameRow.SetTitle(room.Name); infoFL.AddChidren(nameRow); - if(room.IsLove) + if (room.IsLove) { nameRow.NameText.Enable = false; } @@ -188,7 +330,7 @@ }; - var temperatureRow = new DeviceInfoRow(446); + temperatureRow = new DeviceInfoRow(446); temperatureRow.Init(); temperatureRow.SetTipTitle(R.MyInternationalizationString.Temperature); temperatureRow.NameText.TextAlignment = TextAlignment.CenterRight; @@ -207,103 +349,18 @@ return; } room.TemperatrueDevice = $"{selectTemp.DeviceAddr}{selectTemp.DeviceEpoint}"; + temperDevice=Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice); temperatureRow.SetTitle(R.MyInternationalizationString.Getting); - - HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice"); - HdlGatewayReceiveLogic.Current.AddAttributeEvent("TemperatrueDevice", ReceiveComandDiv.A璁惧灞炴�т笂鎶�, (Action<ZigBee.Device.CommonDevice>)((report) => - { - string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report); - if (room.TemperatrueDevice != mainKeys) - { - return; - } - //绉婚櫎鎺変簨浠� - HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice"); - - foreach (var data in report.DeviceStatusReport.AttriBute) - { - if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue) - { - if (data.AttriButeData == 0) - { - //0鈩� - temperatureRow.NameText.Text = "0.0鈩�"; - room.Temperatrue = 0; - } - else if (data.AttriButeData > 32767) - { - //璐熸暟(鐗规畩澶勭悊) - string strValue = (data.AttriButeData - 65536).ToString(); - //灏忔暟鐐归渶瑕佷竴浣� - strValue = strValue.Substring(0, strValue.Length - 1); - temperatureRow.NameText.Text = strValue.Insert(strValue.Length - 1, ".") + "鈩�"; - room.Temperatrue = int.Parse(strValue) * 0.1; - } - else - { - //灏忔暟鐐归渶瑕佷竴浣� - string strValue = data.AttriButeData.ToString(); - strValue = strValue.Substring(0, strValue.Length - 1); - temperatureRow.NameText.Text = strValue.Insert(strValue.Length - 1, ".") + "鈩�"; - room.Temperatrue = int.Parse(strValue) *0.1; - } - } - } - })); //鍙戦�佽幏鍙栨俯搴︾殑鍛戒护 - (selectTemp as ZigBee.Device.TemperatureSensor).ReadTemperatureOrHumidity(); + ReadDeviceAttributeLogic.Instance.SendTemperatureStatuComand(selectTemp); }; }; if (string.IsNullOrEmpty(room.TemperatrueDevice) == false) { - temperatureRow.SetTitle(R.MyInternationalizationString.Getting); - HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice"); - HdlGatewayReceiveLogic.Current.AddAttributeEvent("TemperatrueDevice", ReceiveComandDiv.A璁惧灞炴�т笂鎶�, (Action<ZigBee.Device.CommonDevice>)((report) => - { - string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report); - if (room.TemperatrueDevice != mainKeys) - { - return; - } - //绉婚櫎鎺変簨浠� - HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice"); - - foreach (var data in report.DeviceStatusReport.AttriBute) - { - if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue) - { - if (data.AttriButeData == 0) - { - //0鈩� - temperatureRow.NameText.Text = "0.0鈩�"; - room.Temperatrue = 0; - } - else if (data.AttriButeData > 32767) - { - //璐熸暟(鐗规畩澶勭悊) - string strValue = (data.AttriButeData - 65536).ToString(); - //灏忔暟鐐归渶瑕佷竴浣� - strValue = strValue.Substring(0, strValue.Length - 1); - temperatureRow.NameText.Text = strValue.Insert(strValue.Length - 1, ".") + "鈩�"; - room.Temperatrue = int.Parse(strValue) * 0.1; - } - else - { - //灏忔暟鐐归渶瑕佷竴浣� - string strValue = data.AttriButeData.ToString(); - strValue = strValue.Substring(0, strValue.Length - 1); - temperatureRow.NameText.Text = strValue.Insert(strValue.Length - 1, ".") + "鈩�"; - room.Temperatrue = int.Parse(strValue) * 0.1; - } - } - } - })); + temperatureRow.SetTitle(room.Temperatrue == 0 ? "--鈩�" : $"{room.Temperatrue}鈩�"); //鍙戦�佽幏鍙栨俯搴︾殑鍛戒护 - var dev = Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice); - if (dev != null) - { - (dev as ZigBee.Device.TemperatureSensor).ReadTemperatureOrHumidity(); - } + temperDevice = Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice); + ReadDeviceAttributeLogic.Instance.SendTemperatureStatuComand(temperDevice); } else { @@ -311,7 +368,7 @@ } - var humidityRow = new DeviceInfoRow(585); + humidityRow = new DeviceInfoRow(585); humidityRow.Init(); humidityRow.SetTipTitle(R.MyInternationalizationString.Humidity); humidityRow.NameText.TextAlignment = TextAlignment.CenterRight; @@ -330,83 +387,19 @@ return; } room.HumidityDevice = $"{selectTemp.DeviceAddr}{selectTemp.DeviceEpoint}"; + humidDevice = Common.LocalDevice.Current.GetDevice(room.HumidityDevice); humidityRow.SetTitle(R.MyInternationalizationString.Getting); - HdlGatewayReceiveLogic.Current.RemoveEvent("HumidityDevice"); - HdlGatewayReceiveLogic.Current.AddAttributeEvent("HumidityDevice", ReceiveComandDiv.A璁惧灞炴�т笂鎶�, (report) => - { - string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report); - if (room.HumidityDevice != mainKeys) - { - return; - } - //绉婚櫎鎺変簨浠� - HdlGatewayReceiveLogic.Current.RemoveEvent("HumidityDevice"); - foreach (var data in report.DeviceStatusReport.AttriBute) - { - if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue) - { - if (data.AttriButeData == 0) - { - //0 - humidityRow.NameText.Text = "0.0%"; - room.Humidity = 0; - } - else - { - //灏忔暟鐐归渶瑕佷竴浣�(婀垮害娌℃湁璐熸暟) - string strValue = data.AttriButeData.ToString(); - strValue = strValue.Substring(0, strValue.Length - 1); - humidityRow.NameText.Text = strValue.Insert(strValue.Length - 1, ".") + "%"; - room.Humidity = int.Parse(strValue) * 0.1; - } - } - } - }); //鍙戦�佽幏鍙栨箍搴︾殑鍛戒护 - (selectTemp as ZigBee.Device.TemperatureSensor).ReadTemperatureOrHumidity(); + ReadDeviceAttributeLogic.Instance.SendHumidityStatuComand(selectTemp); }; }; if (string.IsNullOrEmpty(room.HumidityDevice) == false) { - humidityRow.SetTitle(R.MyInternationalizationString.Getting); - HdlGatewayReceiveLogic.Current.RemoveEvent("HumidityDevice"); - HdlGatewayReceiveLogic.Current.AddAttributeEvent("HumidityDevice", ReceiveComandDiv.A璁惧灞炴�т笂鎶�, (report) => - { - string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report); - if (room.HumidityDevice != mainKeys) - { - return; - } - //绉婚櫎鎺変簨浠� - HdlGatewayReceiveLogic.Current.RemoveEvent("HumidityDevice"); - foreach (var data in report.DeviceStatusReport.AttriBute) - { - if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue) - { - if (data.AttriButeData == 0) - { - //0 - humidityRow.NameText.Text = "0.0%"; - room.Humidity = 0; - } - else - { - //灏忔暟鐐归渶瑕佷竴浣�(婀垮害娌℃湁璐熸暟) - string strValue = data.AttriButeData.ToString(); - strValue = strValue.Substring(0, strValue.Length - 1); - humidityRow.NameText.Text = strValue.Insert(strValue.Length - 1, ".") + "%"; - room.Humidity = int.Parse(strValue) * 0.1; - } - } - } - }); + humidityRow.SetTitle(room.Humidity == 0 ? "--%" : $"{room.Humidity}%"); //鍙戦�佽幏鍙栨箍搴︾殑鍛戒护 - var dev = Common.LocalDevice.Current.GetDevice(room.HumidityDevice); - if (dev != null) - { - (dev as ZigBee.Device.TemperatureSensor).ReadTemperatureOrHumidity(); - } + humidDevice = Common.LocalDevice.Current.GetDevice(room.HumidityDevice); + ReadDeviceAttributeLogic.Instance.SendHumidityStatuComand(humidDevice); } else { @@ -416,11 +409,11 @@ if (Config.Instance.Home.FloorDics.Count == 0 || room.IsLove) { temperatureRow.Y = Application.GetRealHeight(308); - humidityRow.Y= Application.GetRealHeight(446); + humidityRow.Y = Application.GetRealHeight(446); } var confirm = new Device.CommonForm.CompleteButton(1700, 900, 127); - confirm.SetTitle(R.MyInternationalizationString.Confrim); + confirm.SetTitle(R.MyInternationalizationString.Save); AddChidren(confirm); confirm.MouseUpEventHandler += (sender, e) => { @@ -429,7 +422,8 @@ room.Name = nameRow.NameText.Text.Trim(); if (OldIconPathType != 0) { - Shared.IO.FileUtils.DeleteFile(System.IO.Path.Combine(Config.Instance.FullPath,OldBackgroundImagePath)); + Shared.IO.FileUtils.DeleteFile(System.IO.Path.Combine(Config.Instance.FullPath, OldBackgroundImagePath)); + HdlAutoBackupLogic.DeleteFile(OldBackgroundImagePath); } if (IconPathType == 0) { @@ -438,6 +432,7 @@ else { Shared.IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), backGround.ImageBytes); + HdlAutoBackupLogic.AddOrEditorFile(fileName); room.BackgroundImage = fileName; } room.BackgroundImageType = IconPathType; @@ -474,24 +469,25 @@ Height = Application.GetRealHeight(450), Width = Application.GetRealWidth(selectRow_Width), Gravity = Gravity.CenterHorizontal, - Radius = (uint)Application.GetRealHeight(17), + Radius = (uint)Application.GetRealHeight(35), BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor }; selectFL.AddChidren(itemFL); - itemFL.Animate = Animate.DownToUp; + //itemFL.Animate = Animate.DownToUp; var selectLocalPicture = new Button() { Height = Application.GetRealHeight(selectRow_Height) - 1, TextID = R.MyInternationalizationString.LocalPicture, - TextColor = ZigbeeColor.Current.GXCTextSelectedColor4 + TextColor = ZigbeeColor.Current.GXCTextSelectedColor4, + TextSize = 17 }; itemFL.AddChidren(selectLocalPicture); var selectLocalLine = new Button() { Y = selectLocalPicture.Bottom, Height = 1, - BackgroundColor = ZigbeeColor.Current.GXCLineColor + BackgroundColor = ZigbeeColor.Current.GXCGrayLineColor2 }; itemFL.AddChidren(selectLocalLine); @@ -500,14 +496,15 @@ Y = selectLocalLine.Bottom, Height = Application.GetRealHeight(selectRow_Height) - 1, TextID = R.MyInternationalizationString.Photograph, - TextColor = ZigbeeColor.Current.GXCTextSelectedColor4 + TextColor = ZigbeeColor.Current.GXCTextSelectedColor4, + TextSize = 17 }; itemFL.AddChidren(selectPhotographBtn); var selectPhotographLine = new Button() { Y = selectPhotographBtn.Bottom, Height = 1, - BackgroundColor = ZigbeeColor.Current.GXCLineColor, + BackgroundColor = ZigbeeColor.Current.GXCGrayLineColor2, }; itemFL.AddChidren(selectPhotographLine); @@ -516,7 +513,8 @@ Y = selectPhotographLine.Bottom, Height = Application.GetRealHeight(selectRow_Height) - 1, TextID = R.MyInternationalizationString.MyAblums, - TextColor = ZigbeeColor.Current.GXCTextSelectedColor4 + TextColor = ZigbeeColor.Current.GXCTextSelectedColor4, + TextSize = 17 }; itemFL.AddChidren(selectAblumsBtn); @@ -529,7 +527,8 @@ TextID = R.MyInternationalizationString.Cancel, TextColor = ZigbeeColor.Current.GXCTextSelectedColor4, BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor, - Radius = (uint)Application.GetRealHeight(17) + Radius = (uint)Application.GetRealHeight(35), + TextSize = 17 }; selectFL.AddChidren(cancelBtn); @@ -555,6 +554,10 @@ //閫氳繃鐩告満鎷嶇収瑁佸壀 CropImage.TakePicture((imagePath) => { + if (string.IsNullOrEmpty(imagePath)) + { + return; + } if (IconPathType != 0) { Global.DeleteFilebyHomeId(backGround.ImagePath); @@ -576,6 +579,10 @@ //浠庣浉鍐岄�夋嫨鍥剧墖瑁佸壀 CropImage.SelectPicture((imagePath) => { + if (string.IsNullOrEmpty(imagePath)) + { + return; + } if (IconPathType != 0) { Global.DeleteFilebyHomeId(backGround.ImagePath); -- Gitblit v1.8.0