using System;
|
using Shared.Common;
|
using Shared.Phone.UserCenter;
|
using Shared.Phone.UserView;
|
|
namespace Shared.Phone.Device.CommonForm
|
{
|
public class RoomView:FrameLayout
|
{
|
/// <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();
|
}
|
|
/// <summary>
|
/// RoomView
|
/// </summary>
|
/// <param name="x"></param>
|
/// <param name="y"></param>
|
public RoomView(int x, int y)
|
{
|
X = Application.GetRealWidth(x);
|
Y = Application.GetRealHeight(y);
|
Width = Application.GetRealWidth(717);
|
Height = Application.GetRealHeight(478);
|
}
|
|
/// <summary>
|
/// Init
|
/// </summary>
|
/// <param name="r"></param>
|
public void Init(Common.Room r)
|
{
|
this.room = r;
|
|
var roomBackView = new FrameLayout()
|
{
|
Width = Application.GetRealWidth(717),
|
Height = Application.GetRealHeight(478)
|
};
|
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)
|
};
|
roomBackView.AddChidren(roomImg);
|
|
var roomNameBackground = new FrameLayout
|
{
|
X = Application.GetRealWidth(29),
|
Y = Application.GetRealHeight(282),
|
Width = Application.GetRealWidth(200),
|
Height = Application.GetRealHeight(80),
|
BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor2
|
};
|
roomBackView.AddChidren(roomNameBackground);
|
roomNameBackground.SetCornerWithSameRadius(Application.GetRealHeight(40), HDLUtils.RectCornerTopRight | HDLUtils.RectCornerBottomRight);
|
|
var roomName = new Button()
|
{
|
X = Application.GetRealWidth(5),
|
Width = Application.GetRealWidth(190),
|
Text = room.Name,
|
TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
};
|
roomNameBackground.AddChidren(roomName);
|
|
|
var roomTemperatureBackground = new FrameLayout
|
{
|
X = Application.GetRealWidth(29),
|
Y = Application.GetRealHeight(374),
|
Width = Application.GetRealWidth(400),
|
Height = Application.GetRealHeight(80),
|
BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor2
|
};
|
roomBackView.AddChidren(roomTemperatureBackground);
|
roomTemperatureBackground.SetCornerWithSameRadius(Application.GetRealHeight(40), HDLUtils.RectCornerTopRight | HDLUtils.RectCornerBottomRight);
|
|
var temperatureIcon = new Button
|
{
|
X = Application.GetRealWidth(12),
|
Width = Application.GetMinRealAverage(58),
|
Height = Application.GetMinRealAverage(58),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Room/Temperature.png"
|
};
|
roomTemperatureBackground.AddChidren(temperatureIcon);
|
|
var temperatureText = new Button
|
{
|
X = Application.GetRealWidth(69),
|
Width = Application.GetRealWidth(120),
|
Height = Application.GetRealHeight(58),
|
Gravity = Gravity.CenterVertical,
|
Text = $"{room.Temperatrue}℃"
|
};
|
roomTemperatureBackground.AddChidren(temperatureText);
|
|
var humidityIcon = new Button
|
{
|
X = Application.GetRealWidth(200),
|
Width = Application.GetMinRealAverage(58),
|
Height = Application.GetMinRealAverage(58),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Room/Humidity.png"
|
};
|
roomTemperatureBackground.AddChidren(humidityIcon);
|
|
var humidityText = new Button
|
{
|
X = Application.GetRealWidth(260),
|
Width = Application.GetRealWidth(120),
|
Height = Application.GetRealHeight(58),
|
Gravity = Gravity.CenterVertical,
|
Text = $"{room.Humidity}%"
|
};
|
roomTemperatureBackground.AddChidren(humidityText);
|
|
|
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℃";
|
room.Temperatrue = 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, ".") + "℃";
|
room.Temperatrue = int.Parse(strValue) * 0.1;
|
}
|
else
|
{
|
//小数点需要一位
|
string strValue = data.AttriButeData.ToString();
|
strValue = strValue.Substring(0, strValue.Length - 1);
|
temperatureText.Text = strValue.Insert(strValue.Length - 1, ".") + "℃";
|
room.Temperatrue = int.Parse(strValue) * 0.1;
|
}
|
}
|
}
|
}));
|
//发送获取温度的命令
|
var dev = Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice);
|
if (dev != null)
|
{
|
(dev as ZigBee.Device.TemperatureSensor).ReadTemperatureOrHumidity();
|
}
|
}
|
|
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%";
|
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;
|
}
|
}
|
}
|
});
|
//发送获取湿度的命令
|
var dev = Common.LocalDevice.Current.GetDevice(room.HumidityDevice);
|
if (dev != null)
|
{
|
(dev as ZigBee.Device.TemperatureSensor).ReadTemperatureOrHumidity();
|
}
|
}
|
|
|
var roomListBtn = new Button()
|
{
|
X = roomBackView.Width - Application.GetRealWidth(100 + 20),
|
Y = Application.GetRealHeight(20),
|
Width = Application.GetMinRealAverage(100),
|
Height = Application.GetMinRealAverage(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 += () =>
|
{
|
action?.Invoke();
|
};
|
};
|
}
|
}
|
}
|