| | |
| | | using System; |
| | | using Shared.Common; |
| | | using Shared.Phone.UserCenter; |
| | | using Shared.Phone.UserView; |
| | | using ZigBee.Device; |
| | | |
| | | namespace Shared.Phone.Device.CommonForm |
| | | { |
| | | public class RoomView:FrameLayout |
| | | public class RoomView : FrameLayoutBase |
| | | { |
| | | /// <summary> |
| | | /// Room |
| | | /// </summary> |
| | | private Common.Room room; |
| | | /// <summary> |
| | | /// action |
| | | /// </summary> |
| | | public Action action; |
| | | |
| | | public override void RemoveFromParent()
|
| | | {
|
| | | HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice");
|
| | | HdlGatewayReceiveLogic.Current.RemoveEvent("HumidityDevice");
|
| | | base.RemoveFromParent();
|
| | | } |
| | | FrameLayout roomNameBackground; |
| | | |
| | | FrameLayout roomTemperatureBackground; |
| | | |
| | | Button roomListBtn; |
| | | |
| | | Button temperatureText; |
| | | |
| | | Button humidityText; |
| | | /// <summary> |
| | | /// 温度设备 |
| | | /// </summary> |
| | | private CommonDevice temperDevice = null; |
| | | /// <summary> |
| | | /// 湿度设备 |
| | | /// </summary> |
| | | private CommonDevice humidDevice = null; |
| | | |
| | | /// <summary> |
| | | /// RoomView |
| | |
| | | /// <param name="r"></param> |
| | | public void Init(Common.Room r) |
| | | { |
| | | this.RemoveAll(); |
| | | |
| | | this.room = r; |
| | | |
| | | this.temperDevice = HdlDeviceCommonLogic.Current.GetDevice(room.TemperatrueDevice); |
| | | |
| | | this.humidDevice = HdlDeviceCommonLogic.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 roomNameBackground = new FrameLayout |
| | | //加个特殊的遮罩 |
| | | 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 |
| | | { |
| | | X = Application.GetRealWidth(29), |
| | | Y = Application.GetRealHeight(282), |
| | |
| | | |
| | | 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, |
| | | 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); |
| | | |
| | | |
| | | var roomTemperatureBackground = new FrameLayout |
| | | roomTemperatureBackground = new FrameLayout |
| | | { |
| | | X = Application.GetRealWidth(29), |
| | | Y = Application.GetRealHeight(374), |
| | | Width = Application.GetRealWidth(340), |
| | | Width = Application.GetRealWidth(400), |
| | | Height = Application.GetRealHeight(80), |
| | | BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor2 |
| | | }; |
| | |
| | | var temperatureIcon = new Button |
| | | { |
| | | X = Application.GetRealWidth(12), |
| | | Width = Application.GetMinRealAverage(58), |
| | | Height = Application.GetMinRealAverage(58), |
| | | Width = this.GetPictrueRealSize(58), |
| | | Height = this.GetPictrueRealSize(58), |
| | | Gravity = Gravity.CenterVertical, |
| | | UnSelectedImagePath = "Room/Temperature.png" |
| | | }; |
| | | roomTemperatureBackground.AddChidren(temperatureIcon); |
| | | |
| | | var temperatureText = new Button |
| | | temperatureText = new Button |
| | | { |
| | | X = Application.GetRealWidth(69), |
| | | Width = Application.GetRealWidth(86), |
| | | Height = Application.GetRealHeight(58), |
| | | Gravity = Gravity.CenterVertical, |
| | | Text = "26℃" |
| | | Width = Application.GetRealWidth(120), |
| | | Text = "--℃", |
| | | TextSize = 14, |
| | | TextAlignment = TextAlignment.CenterLeft |
| | | }; |
| | | if (this.temperDevice != null) |
| | | { |
| | | //这个设备要存在本地才行 |
| | | decimal temperatrue = (decimal)temperDevice.GetType().InvokeMember("currentTemperature", System.Reflection.BindingFlags.GetField, null, temperDevice, null); |
| | | temperatureText.Text = temperatrue == 0 ? "0.0℃" : temperatrue.ToString() + "℃"; |
| | | } |
| | | roomTemperatureBackground.AddChidren(temperatureText); |
| | | temperatureText.Width = temperatureText.GetTextWidth() + Application.GetRealWidth(60); |
| | | |
| | | var humidityIcon = new Button |
| | | { |
| | | X = Application.GetRealWidth(179), |
| | | Width = Application.GetMinRealAverage(58), |
| | | Height = Application.GetMinRealAverage(58), |
| | | X = temperatureText.Right, |
| | | Width = this.GetPictrueRealSize(58), |
| | | Height = this.GetPictrueRealSize(58), |
| | | Gravity = Gravity.CenterVertical, |
| | | UnSelectedImagePath = "Room/Humidity.png" |
| | | }; |
| | | roomTemperatureBackground.AddChidren(humidityIcon); |
| | | |
| | | var humidityText = new Button |
| | | humidityText = new Button |
| | | { |
| | | X = Application.GetRealWidth(236), |
| | | Width = Application.GetRealWidth(86), |
| | | Height = Application.GetRealHeight(58), |
| | | Gravity = Gravity.CenterVertical, |
| | | Text = "13%" |
| | | X = humidityIcon.Right, |
| | | Width = Application.GetRealWidth(120), |
| | | Text = "--%", |
| | | TextSize = 14, |
| | | TextAlignment = TextAlignment.CenterLeft |
| | | }; |
| | | roomTemperatureBackground.AddChidren(humidityText); |
| | | |
| | | if (this.humidDevice != null) |
| | | { |
| | | //这个设备要存在本地才行 |
| | | decimal humidity = (decimal)humidDevice.GetType().InvokeMember("currentHumidity", System.Reflection.BindingFlags.GetField, null, humidDevice, null); |
| | | humidityText.Text = humidity == 0 ? "0.0%" : 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) |
| | | { |
| | | 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℃ |
| | | temperatureText.Text = "0.0℃"; |
| | | } |
| | | else if (data.AttriButeData > 32767) |
| | | { |
| | | //负数(特殊处理) |
| | | string strValue = (data.AttriButeData - 65536).ToString(); |
| | | //小数点需要一位 |
| | | strValue = strValue.Substring(0, strValue.Length - 1); |
| | | temperatureText.Text = strValue.Insert(strValue.Length - 1, ".") + "℃"; |
| | | } |
| | | else |
| | | { |
| | | //小数点需要一位 |
| | | string strValue = data.AttriButeData.ToString(); |
| | | strValue = strValue.Substring(0, strValue.Length - 1); |
| | | temperatureText.Text = strValue.Insert(strValue.Length - 1, ".") + "℃"; |
| | | } |
| | | } |
| | | } |
| | | })); |
| | | //发送获取温度的命令 |
| | | var dev = Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice); |
| | | if (dev != null) |
| | | { |
| | | (dev as ZigBee.Device.TemperatureSensor).ReadTemperatureOrHumidity(); |
| | | } |
| | | var dev = HdlDeviceCommonLogic.Current.GetDevice(room.TemperatrueDevice); |
| | | HdlDeviceAttributeLogic.Current.SendTemperatureStatuComand(dev); |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(room.HumidityDevice) == false) |
| | | { |
| | | 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 |
| | | humidityText.Text = "0.0%"; |
| | | } |
| | | else |
| | | { |
| | | //小数点需要一位(湿度没有负数) |
| | | string strValue = data.AttriButeData.ToString(); |
| | | strValue = strValue.Substring(0, strValue.Length - 1); |
| | | humidityText.Text = strValue.Insert(strValue.Length - 1, ".") + "%"; |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | //发送获取湿度的命令 |
| | | var dev = Common.LocalDevice.Current.GetDevice(room.HumidityDevice); |
| | | if (dev != null) |
| | | { |
| | | (dev as ZigBee.Device.TemperatureSensor).ReadTemperatureOrHumidity(); |
| | | } |
| | | var dev = HdlDeviceCommonLogic.Current.GetDevice(room.HumidityDevice); |
| | | HdlDeviceAttributeLogic.Current.SendHumidityStatuComand(dev); |
| | | } |
| | | |
| | | var roomListBtn = new Button() |
| | | roomListBtn = new Button() |
| | | { |
| | | X = roomBackView.Width - Application.GetRealWidth(100 + 20), |
| | | Y = Application.GetRealHeight(20), |
| | | Width = Application.GetMinRealAverage(100), |
| | | Height = Application.GetMinRealAverage(100), |
| | | Width = this.GetPictrueRealSize(100), |
| | | Height = this.GetPictrueRealSize(100), |
| | | UnSelectedImagePath = "Room/List.png", |
| | | }; |
| | | roomBackView.AddChidren(roomListBtn); |
| | |
| | | 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 += () => |
| | | |
| | | var form = new UserCenter.Residence.EditorRoomInforForm(); |
| | | form.AddForm(room); |
| | | form.FinishEditorEvent += (roomName2) => |
| | | { |
| | | action?.Invoke(); |
| | | //重新刷新控件 |
| | | 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(() => |
| | | { |
| | | decimal temperatrue = (decimal)temperDevice.GetType().InvokeMember("currentTemperature", System.Reflection.BindingFlags.GetField, null, temperDevice, null); |
| | | if (temperatrue == 0) |
| | | { |
| | | temperatureText.Text = "0.0℃"; |
| | | } |
| | | else |
| | | { |
| | | temperatureText.Text = temperatrue + "℃"; |
| | | } |
| | | }, ShowErrorMode.NO); |
| | | } |
| | | } |
| | | if (this.humidDevice != null) |
| | | { |
| | | //湿度设备 |
| | | if (report.DeviceAddr == humidDevice.DeviceAddr && report.DeviceEpoint == humidDevice.DeviceEpoint) |
| | | { |
| | | HdlThreadLogic.Current.RunMain(() => |
| | | { |
| | | decimal humidity = (decimal)humidDevice.GetType().InvokeMember("currentHumidity", System.Reflection.BindingFlags.GetField, null, humidDevice, null); |
| | | if (humidity == 0) |
| | | { |
| | | humidityText.Text = "--%"; |
| | | } |
| | | else |
| | | { |
| | | humidityText.Text = humidity + "%"; |
| | | } |
| | | }, ShowErrorMode.NO); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// HideName |
| | | /// </summary> |
| | | 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(); |
| | | } |
| | | } |
| | | } |