using System;
using System.Collections.Generic;
using Shared.SimpleControl;
namespace Shared.SimpleControl.Phone
{
///
/// 空调控制界面
///
public class UserLongXiACPage : FrameLayout
{
///
/// 当前视图
///
static UserLongXiACPage curView;
FrameLayout acBodyView;
LongXiAC ac;
Room room;
ACMethod acBLL;
Button btnInterior;
Button btnInteriorH;
Button btnACSwitch;
//Button btnTVOC ;//Text = "VOC:" + ac.TVOC.ToString () + "ppm"
Button btnOutTemp;//Text = "室外:" + ac.OutTemp.ToString () + "°"
Button btnPM25 ;//Text = "PM2.5:" + ac.PM25.ToString () + @"mg/m³"
Button btnAuto;
Button btnManual;
Button btnModeChange;
Button btnLowWind;
Button btnMiddleWind;
Button btnHighWind;
Button btnElectricHeating;
///
/// 构造函数
///
/// Room.
public UserLongXiACPage (LongXiAC ac, Room room)
{
this.ac = ac;
this.room = room;
curView = this;
acBLL = new ACMethod ();
BackgroundColor = SkinStyle.Current.MainColor;
readStatus (ac);
}
///
/// 更新空调
///
public static void UpdateStatus (LongXiAC ac)
{
Application.RunOnMainThread (() => {
if (curView == null) {
return;
}
if (curView.ac != ac) {
return;
}
try {
if (ac.Power == 1) {
curView.btnACSwitch.IsSelected = true;
curView.btnInterior.Text = ac.IndoorTemperature.ToString () + "°";
curView.btnInteriorH.Text = ac.Humidity.ToString () + "%";
//curView.btnTVOC.Text = "VOC:" + ac.TVOC.ToString () + "ppm";
curView.btnOutTemp.Text = "室外:" + ac.OutTemp.ToString () + "°";
curView.btnPM25.Text = "PM2.5:" + ac.PM25.ToString () + @"mg/m³";
curView.btnAuto.IsSelected = false;
curView.btnManual.IsSelected = false;
curView.btnLowWind.IsSelected = false;
curView.btnMiddleWind.IsSelected = false;
curView.btnHighWind.IsSelected = false;
curView.btnAuto.Enable = true;
curView.btnManual.Enable = true;
curView.btnLowWind.Enable = true;
curView.btnMiddleWind.Enable = true;
curView.btnHighWind.Enable = true;
if (ac.LongXiDeviceType == 1 ) {
curView.btnElectricHeating.Enable = true;
curView.btnElectricHeating.IsSelected = false;
curView.btnModeChange.Enable = true;
if (ac.Wave == 0) {
curView.btnModeChange.Text = "手动关";
} else {
curView.btnModeChange.Text = "自动开";
}
}
if (ac.ElectricHeating == 1) {
curView.btnElectricHeating.IsSelected = true;
}
if (ac.SetMode == 0) {
curView.btnManual.IsSelected = true;
}
if (ac.SetMode == 3) {
curView.btnAuto.IsSelected = true;
}
switch (ac.SetFanSpeed) {
case 3:
curView.btnLowWind.IsSelected = true;
break;
case 2:
curView.btnMiddleWind.IsSelected = true;
break;
default:
curView.btnHighWind.IsSelected = true;
break;
}
} else {
curView.btnACSwitch.IsSelected = false;
curView.btnInterior.Text = ac.IndoorTemperature.ToString () + "°";
//curView.btnTVOC.Text = "VOC:" + ac.TVOC.ToString () + "ppm";
curView.btnOutTemp.Text = "室外:" + ac.OutTemp.ToString () + "°";
curView.btnPM25.Text = "PM2.5:" + ac.PM25.ToString () + @"mg/m³";
curView.btnAuto.IsSelected = false;
curView.btnManual.IsSelected = false;
curView.btnLowWind.IsSelected = false;
curView.btnMiddleWind.IsSelected = false;
curView.btnHighWind.IsSelected = false;
curView.btnAuto.Enable = false;
curView.btnManual.Enable = false;
curView.btnLowWind.Enable = false;
curView.btnMiddleWind.Enable = false;
curView.btnHighWind.Enable = false;
if (ac.LongXiDeviceType == 1 ) {
curView.btnElectricHeating.Enable = false;
curView.btnElectricHeating.IsSelected = false;
curView.btnModeChange.Enable = false;
if (ac.Wave == 0) {
curView.btnModeChange.Text = "手动关";
} else {
curView.btnModeChange.Text = "自动开";
}
}
}
} catch (Exception ex) {
Console.WriteLine (ex.ToString ());
}
});
}
///
/// 显示出当前房间所有的空调
///
public void showRoomAC ()
{
#region 标题
var topView = new FrameLayout () {
Y = Application.GetRealHeight (36),
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (640),
};
AddChidren (topView);
var title = new Button () {
TextAlignment = TextAlignment.Center,
Text = room.Name,
TextColor = SkinStyle.Current.TextColor1,
TextSize = 19,
};
topView.AddChidren (title);
var logo = new Button () {
Width = Application.GetRealWidth (154),
Height = Application.GetRealHeight (90),
X = Application.GetRealWidth (486),
UnSelectedImagePath = MainPage.LogoString,
};
topView.AddChidren (logo);
var back = new Button () {
Height = Application.GetRealHeight (100),
Width = Application.GetRealWidth (85),
UnSelectedImagePath = "Item/Back.png",
SelectedImagePath = "Item/BackSelected.png",
};
topView.AddChidren (back);
back.MouseUpEventHandler += (sender, e) => {
(Parent as PageLayout).PageIndex -= 1;
curView = null;
};
#endregion
acBodyView = new FrameLayout {
Width = Application.GetRealWidth (640),
Height = Application.GetRealHeight (Application.DesignHeight - 126),
Y = Application.GetRealHeight (126)
};
AddChidren (acBodyView);
#region roomBackgroundImage
var roomBackgroundImageView = new FrameLayout () {
Height = Application.GetRealHeight (360),
Width = Application.GetRealWidth (640),
};
acBodyView.AddChidren (roomBackgroundImageView);
roomBackgroundImageView.BackgroundImagePath = room.BackGroundImage;
//长按更换背景
roomBackgroundImageView.MouseLongEventHandler += (sender, e) => {
Camera.SelectPicture ((obj) => {
if (obj != null) {
room.BackGroundImage = obj;
roomBackgroundImageView.BackgroundImagePath = obj;
room.Save (typeof (Room).Name + "_" + room.Name);
}
}, room.Name, false);
};
FrameLayout valuesView = new FrameLayout () {
Y = roomBackgroundImageView.Height - Application.GetRealHeight (80),
Height = Application.GetRealHeight (80),
BackgroundColor = SkinStyle.Current.Black50Transparent,
};
roomBackgroundImageView.AddChidren (valuesView);
//btnTVOC = new Button () {
// X = Application.GetRealWidth (30),
// Width = Application.GetRealWidth (640 / 3),
// TextAlignment = TextAlignment.CenterLeft,
// Text = "VOC:" + ac.TVOC.ToString () + "ppm"
//};
//valuesView.AddChidren (btnTVOC);
btnOutTemp = new Button () {
X = Application.GetRealWidth (30),
Width = Application.GetRealWidth (640 / 3),
TextAlignment = TextAlignment.CenterLeft,
Text = "室外:" + ac.OutTemp.ToString () + "°"
};
valuesView.AddChidren (btnOutTemp);
btnPM25 = new Button () {
X = Application.GetRealWidth (420),
Width = Application.GetRealWidth (200),
TextAlignment = TextAlignment.CenterLeft,
Text = "PM2.5:" + ac.PM25.ToString () + @"mg/m³"
};
valuesView.AddChidren (btnPM25);
#endregion
FrameLayout setACTemp = new FrameLayout () {
Height = Application.GetMinRealAverage (106),
Width = Application.GetRealWidth (640),
BackgroundColor = SkinStyle.Current.MainColor,
Y = roomBackgroundImageView.Bottom
};
acBodyView.AddChidren (setACTemp);
btnACSwitch = new Button () {
Width = Application.GetMinRealAverage (115),
Height = Application.GetMinRealAverage (115),
X = Application.GetRealWidth (640 - 130),
UnSelectedImagePath = "FH/FH_Switch.png",
SelectedImagePath = "FH/FH_Switch_on.png",
};
btnACSwitch.IsSelected = ac.Power == 1;
btnACSwitch.MouseUpEventHandler += (sender, e) => {
btnACSwitch.IsSelected = !btnACSwitch.IsSelected;
ac.Power = btnACSwitch.IsSelected ? (byte)1 : (byte)0;
UpdateStatus (ac);
acBLL.ControlAC (ac);
};
setACTemp.AddChidren (btnACSwitch);
var btnText = new Button () {
Width = Application.GetRealWidth (150),
Height = Application.GetRealHeight (40),
X = Application.GetRealWidth (15),
Y = Application.GetRealHeight (22),
TextID = R.MyInternationalizationString.ACInterior,
TextAlignment = TextAlignment.BottomCenter,
TextColor = SkinStyle.Current.TextColor1
};
setACTemp.AddChidren (btnText);
btnInterior = new Button () {
Width = Application.GetRealWidth (150),
Height = Application.GetRealHeight (40),
X = Application.GetRealWidth (10),
Y = btnText.Bottom,
Text = ac.IndoorTemperature.ToString () + "°",
TextSize = 14,
TextAlignment = TextAlignment.Center,
TextColor = SkinStyle.Current.TextColor1
};
setACTemp.AddChidren (btnInterior);
var btnTextH = new Button () {
Width = Application.GetRealWidth (150),
Height = Application.GetRealHeight (40),
Gravity = Gravity.CenterHorizontal,
Y = Application.GetRealHeight (22),
Text = "湿度",
TextAlignment = TextAlignment.BottomCenter,
TextColor = SkinStyle.Current.TextColor1
};
setACTemp.AddChidren (btnTextH);
btnInteriorH = new Button () {
Width = Application.GetRealWidth (150),
Height = Application.GetRealHeight (40),
Gravity = Gravity.CenterHorizontal,
Y = btnTextH.Bottom,
Text = ac.Humidity.ToString () + "%",
TextSize = 14,
TextAlignment = TextAlignment.Center,
TextColor = SkinStyle.Current.TextColor1
};
setACTemp.AddChidren (btnInteriorH);
#region 模式
var acModeView = new FrameLayout () {
Height = Application.GetRealHeight (200),
Width = Application.GetRealWidth (640),
BackgroundColor = SkinStyle.Current.ViewColor,
Y = setACTemp.Bottom,
};
acBodyView.AddChidren (acModeView);
FrameLayout modeView = new FrameLayout () {
Width = Application.GetRealWidth (416),
X = ac.LongXiDeviceType > 1 ? Application.GetRealWidth (90) : 0,
Y = Application.GetRealHeight (50),
};
acModeView.AddChidren (modeView);
btnAuto = new Button () {
X = Application.GetRealWidth (90),
Width = Application.GetMinRealAverage (100),
Height = Application.GetMinRealAverage (100),
Radius = 5,
BorderColor = 0xFFFFFFFF,
BorderWidth = 1,
TextSize = 18,
Text = "自动",
TextColor = SkinStyle.Current.TextColor1,
BackgroundColor = SkinStyle.Current.Transparent,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
};
modeView.AddChidren (btnAuto);
btnManual = new Button () {
X = btnAuto.Right + Application.GetRealWidth (90),
Width = Application.GetMinRealAverage (100),
Height = Application.GetMinRealAverage (100),
Radius = 5,
BorderColor = 0xFFFFFFFF,
BorderWidth = 1,
TextSize = 18,
Text = "手动",//制冷
TextColor = SkinStyle.Current.TextColor1,
BackgroundColor = SkinStyle.Current.Transparent,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
};
modeView.AddChidren (btnManual);
btnAuto.MouseUpEventHandler += (sdfa, asdfe) => {
btnAuto.IsSelected = true;
btnManual.IsSelected = false;
ac.SetMode = 3;
acBLL.ControlAC (ac);
};
btnManual.MouseUpEventHandler += (sdfa, asdfe) => {
btnAuto.IsSelected = false;
btnManual.IsSelected = true;
ac.SetMode = 0;
acBLL.ControlAC (ac);
};
if (ac.LongXiDeviceType < 2) {
btnModeChange = new Button () {
X = modeView.Right + Application.GetRealWidth (50),
Width = Application.GetMinRealAverage (100),
Height = Application.GetMinRealAverage (100),
Radius = 5,
BorderColor = 0xFFFFFFFF,
BorderWidth = 1,
TextSize = 14,
Text = "手动关",
TextColor = SkinStyle.Current.TextColor1,
BackgroundColor = SkinStyle.Current.Transparent,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
Y = Application.GetRealHeight (50),
};
acModeView.AddChidren (btnModeChange);
btnModeChange.MouseUpEventHandler += (sdfa, asdfe) => {
ac.Wave = ac.Wave == (byte)0 ? (byte)1 : (byte)0;
if (ac.Wave == 0) {
btnModeChange.Text = "手动关";
} else {
btnModeChange.Text = "自动开";
}
acBLL.ControlAC (ac);
};
}
#endregion
var btnLine1 = new Button () {
Height = 3,
BackgroundColor = SkinStyle.Current.MainColor,
Y = acModeView.Bottom,
};
acBodyView.AddChidren (btnLine1);
#region 风速
var acWindView = new FrameLayout () {
Height = Application.GetRealHeight (600),
Width = Application.GetRealWidth (640),
Y = btnLine1.Bottom + Application.GetRealHeight (30),
BackgroundColor = SkinStyle.Current.ViewColor,
};
acBodyView.AddChidren (acWindView);
btnLowWind = new Button () {
X = Application.GetRealWidth (90),
Y = Application.GetRealHeight (90),
Width = Application.GetMinRealAverage (100),
Height = Application.GetMinRealAverage (100),
Radius = 5,
BorderColor = 0xFFFFFFFF,
BorderWidth = 1,
TextSize = 18,
Text = "低风",
TextColor = SkinStyle.Current.TextColor1,
BackgroundColor = SkinStyle.Current.Transparent,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
};
acWindView.AddChidren (btnLowWind);
btnMiddleWind = new Button () {
X = btnLowWind.Right + Application.GetRealWidth (90),
Y = Application.GetRealHeight (90),
Width = Application.GetMinRealAverage (100),
Height = Application.GetMinRealAverage (100),
Radius = 5,
BorderColor = 0xFFFFFFFF,
BorderWidth = 1,
TextSize = 18,
Text = "中风",
TextColor = SkinStyle.Current.TextColor1,
BackgroundColor = SkinStyle.Current.Transparent,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
};
acWindView.AddChidren (btnMiddleWind);
btnHighWind = new Button () {
X = btnMiddleWind.Right + Application.GetRealWidth (90) ,
Y = Application.GetRealHeight (90),
Width = Application.GetMinRealAverage (100),
Height = Application.GetMinRealAverage (100),
Radius = 5,
BorderColor = 0xFFFFFFFF,
BorderWidth = 1,
TextSize = 18,
Text = "高风",
TextColor = SkinStyle.Current.TextColor1,
BackgroundColor = SkinStyle.Current.Transparent,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
};
acWindView.AddChidren (btnHighWind);
btnLowWind.MouseUpEventHandler += (sdfa, asdfe) => {
btnLowWind.IsSelected = true;
btnMiddleWind.IsSelected = false;
btnHighWind.IsSelected = false;
ac.SetFanSpeed = 3;
acBLL.ControlAC (ac);
};
btnMiddleWind.MouseUpEventHandler += (sdfa, asdfe) => {
btnLowWind.IsSelected = false;
btnMiddleWind.IsSelected = true;
btnHighWind.IsSelected = false;
ac.SetFanSpeed = 2;
acBLL.ControlAC (ac);
};
btnHighWind.MouseUpEventHandler += (sdfa, asdfe) => {
btnLowWind.IsSelected = false;
btnMiddleWind.IsSelected = false;
btnHighWind.IsSelected = true;
ac.SetFanSpeed = 1;
acBLL.ControlAC (ac);
};
if (ac.LongXiDeviceType < 2) {
btnLowWind.X = Application.GetRealWidth (50);
btnMiddleWind.X = btnLowWind.Right + Application.GetRealWidth (50);
btnHighWind.X = btnMiddleWind.Right + Application.GetRealWidth (50);
btnElectricHeating = new Button () {
X = btnHighWind.Right + Application.GetRealWidth (50),
Y = Application.GetRealHeight (90),
Width = Application.GetMinRealAverage (100),
Height = Application.GetMinRealAverage (100),
Radius = 5,
BorderColor = 0xFFFFFFFF,
BorderWidth = 1,
TextSize = 14,
Text = "电辅热",
TextColor = SkinStyle.Current.TextColor1,
BackgroundColor = SkinStyle.Current.Transparent,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
IsSelected = ac.ElectricHeating == 1 ? true : false
};
acWindView.AddChidren (btnElectricHeating);
btnElectricHeating.MouseUpEventHandler += (sdfa, asdfe) => {
btnElectricHeating.IsSelected = !btnElectricHeating.IsSelected;
if (btnElectricHeating.IsSelected)
ac.ElectricHeating = 1;
else
ac.ElectricHeating = 0;
acBLL.ControlAC (ac);
};
}
#endregion
UpdateStatus (ac);
}
///
/// 读取设备状态
///
static void readStatus (LongXiAC ac)
{
System.Threading.Tasks.Task.Run (() => {
if (ac.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now) {
Control.ControlBytesSendHasReturn (Command.ReadACMode, ac.SubnetID, ac.DeviceID, new byte [] { ac.LoopID });
}
});
}
}
}