using Shared.SimpleControl.Phone;
using System;
namespace Shared.SimpleControl.Pad
{
public class UserFHPage : FrameLayout
{
///
/// 当前视图
///
static UserFHPage curView;
FrameLayout fhBodyView;
FoolHeat fh;
Room room;
Button btnInterior;
Button btnFHSwitch;
Button btnSetTemperature;
VerticalSeekBar VertTempSeekBar;
Button FH_Day;
Button FH_Night;
Button FH_Common;
Button Go_away;
Button FH_Auto;
///
/// 构造函数
///
/// Room.
public UserFHPage (FoolHeat fh, Room room)
{
this.fh = fh;
this.room = room;
curView = this;
BackgroundColor = 0xFF2f2f2f;
readStatus ();
showRoomFH ();
}
///
/// 更新地热
///
/// Subnet identifier.
/// Device identifier.
/// Ac host bytes for updata.
public static void UpdateStatus (FoolHeat updataFH)
{
if (curView == null) {
return;
}
if (curView.fh.SubnetID != updataFH.SubnetID && curView.fh.DeviceID != updataFH.DeviceID && curView.fh.LoopID != updataFH.LoopID) {
return;
}
Application.RunOnMainThread (() => {
for (int i = 0; i < curView.fhBodyView.ChildrenCount; i++) {
try {
var indoorT = updataFH.IndoorTemperature;
string indoorTstr = Convert.ToString (indoorT, 2);
if (indoorT > 127) {
indoorTstr = "-" + (indoorT - 128) + "°C";
} else if (indoorT == 128) {
indoorTstr = "--";
} else
indoorTstr = indoorT.ToString () + "°C";
curView.btnSetTemperature.Text = updataFH.WorkingTemperature.ToString () + "°C";
curView.VertTempSeekBar.Progress = updataFH.WorkingTemperature - 5;
curView.btnInterior.Text = indoorTstr;
if (updataFH.Status == 1) {
//考虑到其他人控制的情况下,得使当前界面更新的数据和别人控制的一样
curView.btnFHSwitch.IsSelected = true;
curView.FH_Day.Enable = true;
curView.FH_Auto.Enable = true;
curView.FH_Night.Enable = true;
curView.FH_Common.Enable = true;
curView.Go_away.Enable = true;
} else {
curView.btnFHSwitch.IsSelected = false;
curView.FH_Day.Enable = false;
curView.FH_Auto.Enable = false;
curView.FH_Night.Enable = false;
curView.FH_Common.Enable = false;
curView.Go_away.Enable = false;
}
switch (updataFH.TemperatureType)
{
case 1:
curView.FH_Day.IsSelected = false;
curView.FH_Auto.IsSelected = false;
curView.FH_Night.IsSelected = false;
curView.FH_Common.IsSelected = true;
curView.Go_away.IsSelected = false;
break;
case 2:
curView.FH_Day.IsSelected = true;
curView.FH_Auto.IsSelected = false;
curView.FH_Night.IsSelected = false;
curView.FH_Common.IsSelected = false;
curView.Go_away.IsSelected = false;
break;
case 3:
curView.FH_Day.IsSelected = false;
curView.FH_Auto.IsSelected = false;
curView.FH_Night.IsSelected = true;
curView.FH_Common.IsSelected = false;
curView.Go_away.IsSelected = false;
break;
case 4:
curView.FH_Day.IsSelected = false;
curView.FH_Auto.IsSelected = false;
curView.FH_Night.IsSelected = false;
curView.FH_Common.IsSelected = false;
curView.Go_away.IsSelected = true;
break;
case 5:
curView.FH_Day.IsSelected = false;
curView.FH_Auto.IsSelected = true;
curView.FH_Night.IsSelected = false;
curView.FH_Common.IsSelected = false;
curView.Go_away.IsSelected = false;
break;
}
} catch (Exception ex) {
Console.WriteLine ("UserACPage " + ex.ToString ());
}
}
});
}
///
/// 显示出当前房间所有的地热
///
public void showRoomFH ()
{
fhBodyView = new FrameLayout ();
AddChidren (fhBodyView);
#region roomBackgroundImageView
var roomBackgroundImageView = new FrameLayout () {
X = Application.GetRealWidth (10),
Y = Application.GetRealHeight (10),
Width = Application.GetRealWidth (920),
Height = Application.GetRealHeight (520),
};
fhBodyView.AddChidren (roomBackgroundImageView);
roomBackgroundImageView.BackgroundImagePath = room.BackGroundImage;
//长按更换背景
roomBackgroundImageView.MouseLongEventHandler += (sender, e) => {
Camera.SelectPicture ((obj) => {
if (obj != null) {
roomBackgroundImageView.BackgroundImagePath = room.Name;
}
}, room.Name);
};
#endregion
#region 工作模式,开关按钮
FrameLayout WrokView = new FrameLayout () {
X = roomBackgroundImageView.Right + Application.GetRealWidth (10),
Y = roomBackgroundImageView.Y,
Width = Application.GetRealWidth(600),
Height = Application.GetRealHeight(680),
};
fhBodyView.AddChidren (WrokView);
btnFHSwitch = new Button () {
Width = Application.GetRealWidth (200),
Height = Application.GetRealHeight (130),
X = Application.GetRealWidth (50),
Y = Application.GetRealHeight (40),
UnSelectedImagePath = "PadAdding/Black.png",
SelectedImagePath = "PadAdding/ModeBlackOn.png",
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
Text = "ON"
};
if (fh.Status == 1) {
btnFHSwitch.IsSelected = true;
} else {
btnFHSwitch.IsSelected = false;
}
btnFHSwitch.MouseUpEventHandler += (sender, e) => {
if (btnFHSwitch.IsSelected == false) {
btnFHSwitch.IsSelected = true;
fh.Status = 1;
btnSetTemperature.Text = fh.WorkingTemperature.ToString () + "°C";
btnInterior.Text = fh.IndoorTemperature.ToString () + "°C";
FH_Day.Enable = true;
FH_Night.Enable = true;
FH_Common.Enable = true;
Go_away.Enable = true;
FH_Auto.Enable = true;
//updateMode (ac.SetMode);
//updateWind (ac.SetFanSpeed);
} else {
btnFHSwitch.IsSelected = false;
fh.Status = 0;
btnSetTemperature.Text = fh.WorkingTemperature.ToString () + "°C";
btnInterior.Text = fh.IndoorTemperature.ToString () + "°C";
FH_Day.Enable = false;
FH_Night.Enable = false;
FH_Common.Enable = false;
Go_away.Enable = false;
FH_Auto.Enable = false;
// updateMode (-1);
//updateWind (-1);
}
System.Threading.Tasks.Task.Run (() => {
fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.Switch);
});
};
WrokView.AddChidren (btnFHSwitch);
btnSetTemperature = new Button () {
X = Application.GetRealWidth (20),
Y = Application.GetRealHeight (330),
Width = Application.GetRealWidth (320),
Height = Application.GetRealHeight (220),
Text = fh.WorkingTemperature.ToString () + "°C",
TextSize = 68,
TextAlignment = TextAlignment.Center,
Enable = false,
};
WrokView.AddChidren (btnSetTemperature);
Button btnHorTemp = new Button () {
X = btnSetTemperature.Right + Application.GetRealWidth (30),
Y = Application.GetRealHeight (20),
Width = Application.GetRealWidth (100),
Height = Application.GetRealHeight (620),
UnSelectedImagePath = "PadAdding/FHPadTemp.png",
};
WrokView.AddChidren (btnHorTemp);
VertTempSeekBar = new VerticalSeekBar () {
X = btnHorTemp.Right,
Y = btnHorTemp.Y - Application.GetRealHeight (10),
Width = Application.GetRealWidth (100),
Height = Application.GetRealHeight (640),
Max = 30,
ProgressColor = SkinStyle.Current.SelectedColor,
SleepTime = 0,
Progress = (fh.WorkingTemperature - 5)
};
WrokView.AddChidren (VertTempSeekBar);
VertTempSeekBar.ProgressChanged += (sender, e) => {
btnSetTemperature.Text = (e + 5).ToString () + "°C";
fh.WorkingTemperature = (byte)(e + 5);
};
VertTempSeekBar.MouseUpEventHandler += (sender, e) => {
fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.Temperatrue);
};
#endregion
#region 温度
FrameLayout indoorTempView = new FrameLayout () {
X = roomBackgroundImageView.X,
Y = roomBackgroundImageView.Bottom + Application.GetRealHeight (10),
Width = Application.GetRealWidth (920),
Height = Application.GetRealHeight (150),
BackgroundColor = 0xFF333333,
};
fhBodyView.AddChidren (indoorTempView);
var FH_Heat = new Button () {
Width = Application.GetRealWidth (200),
Height = Application.GetRealHeight (130),
Y = Application.GetRealHeight (10),
UnSelectedImagePath = "PadAdding/FHHeating.png",
SelectedImagePath = "PadAdding/FHCooling.png",
};
if (fh.WorkingMode == 0) {
FH_Heat.IsSelected = false;
} else {
FH_Heat.IsSelected = true;
}
FH_Heat.MouseUpEventHandler += (sender, e) => {
if (FH_Heat.IsSelected == false) {
FH_Heat.IsSelected = true;
fh.WorkingMode = 1;
} else {
FH_Heat.IsSelected = false;
fh.WorkingMode = 0;
}
fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.WorkMode);
};
indoorTempView.AddChidren (FH_Heat);
var indoorT = fh.IndoorTemperature;
string indoorTstr = Convert.ToString (indoorT, 2);
if (indoorT > 127) {
indoorTstr = "-" + (indoorT - 128) + "°C";
} else
indoorTstr = indoorT.ToString();
Button btnText = new Button () {
X = Application.GetRealWidth(550),
Width = Application.GetRealWidth (200),
TextID = R.MyInternationalizationString.ACInterior,
TextSize = 20,
};
indoorTempView.AddChidren (btnText);
btnInterior = new Button () {
Width = Application.GetRealWidth (150),
X = btnText.Right,
Text = indoorTstr ,
TextSize = 30,
TextAlignment = TextAlignment.Center,
};
indoorTempView.AddChidren (btnInterior);
#endregion
#region FHTemperatrueTypeView
var FHTemperatrueTypeView = new FrameLayout () {
Height = Application.GetRealHeight (500),
Y = indoorTempView.Bottom + Application.GetRealHeight(150),
};
fhBodyView.AddChidren (FHTemperatrueTypeView);
Button btnModeTitle = new Button () {
X = Application.GetRealWidth (10),
Width = Application.GetRealWidth (300),
Height = Application.GetRealHeight (70),
TextID = R.MyInternationalizationString.Mode,
TextAlignment = TextAlignment.CenterLeft,
TextColor = 0xFF333333,
TextSize = 16,
};
FHTemperatrueTypeView.AddChidren (btnModeTitle);
FH_Day = new Button () {
X = Application.GetRealWidth (10),
Y = Application.GetRealHeight (100),
Width = Application.GetRealWidth (300),
Height = Application.GetRealHeight (260),
UnSelectedImagePath = "PadAdding/Day.png",
SelectedImagePath = "PadAdding/DayOn.png",
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
TextSize = 16,
TextID = R.MyInternationalizationString.Day,
Padding = new Padding(40,0,0,0),
};
if (fh.TemperatureType == 2) {
FH_Day.IsSelected = true;
} else {
FH_Day.IsSelected = false;
}
FHTemperatrueTypeView.AddChidren (FH_Day);
FH_Night = new Button () {
X = FH_Day.Right + Application.GetRealWidth (9),
Y = Application.GetRealHeight (100),
Width = Application.GetRealWidth (300),
Height = Application.GetRealHeight (260),
UnSelectedImagePath = "PadAdding/AtNight.png",
SelectedImagePath = "PadAdding/AtNightOn.png",
TextID = R.MyInternationalizationString.AtNight,
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
TextSize = 16,
Padding = new Padding (40,0,0,0),
};
if (fh.TemperatureType == 3) {
FH_Night.IsSelected = true;
} else {
FH_Night.IsSelected = false;
}
FHTemperatrueTypeView.AddChidren (FH_Night);
FH_Common = new Button () {
X = FH_Night.Right + Application.GetRealWidth (9),
Y = Application.GetRealHeight (100),
Width = Application.GetRealWidth (300),
Height = Application.GetRealHeight (260),
UnSelectedImagePath = "PadAdding/Ordinary.png",
SelectedImagePath = "PadAdding/OrdinaryOn.png",
TextID = R.MyInternationalizationString.Ordinary,
Padding = new Padding (40,0,0,0),
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
TextSize = 16,
};
if (fh.TemperatureType == 1) {
FH_Common.IsSelected = true;
} else {
FH_Common.IsSelected = false;
}
FHTemperatrueTypeView.AddChidren (FH_Common);
Go_away = new Button () {
X = FH_Common.Right + Application.GetRealWidth (9),
Y = Application.GetRealHeight (100),
Width = Application.GetRealWidth (300),
Height = Application.GetRealHeight (260),
UnSelectedImagePath = "PadAdding/GoAway.png",
SelectedImagePath = "PadAdding/GoAwayOn.png",
TextID = R.MyInternationalizationString.GoAway,
Padding = new Padding (40,0,0,0),
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
TextSize = 16,
};
if (fh.TemperatureType == 4) {
Go_away.IsSelected = true;
} else {
Go_away.IsSelected = false;
}
FHTemperatrueTypeView.AddChidren (Go_away);
FH_Auto = new Button () {
X = Go_away.Right + Application.GetRealWidth (9),
Y = Application.GetRealHeight (100),
Width = Application.GetRealWidth (300),
Height = Application.GetRealHeight (260),
UnSelectedImagePath = "PadAdding/Automatic.png",
SelectedImagePath = "PadAdding/AutomaticOn.png",
TextID = R.MyInternationalizationString.Timer,
Padding = new Padding (40,0,0,0),
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
TextSize = 16,
};
if (fh.TemperatureType == 5) {
FH_Auto.IsSelected = true;
} else {
FH_Auto.IsSelected = false;
}
FHTemperatrueTypeView.AddChidren (FH_Auto);
FH_Day.MouseDownEventHandler += (sender, e) => {
if (btnFHSwitch.IsSelected == false) {
return;
}
FH_Day.IsSelected = true;
};
FH_Day.MouseUpEventHandler += (sender, e) => {
if (btnFHSwitch.IsSelected == false) {
return;
}
FH_Day.IsSelected = true;
FH_Common.IsSelected = false;
FH_Night.IsSelected = false;
FH_Auto.IsSelected = false;
Go_away.IsSelected = false;
fh.TemperatureType = 2;
System.Threading.Tasks.Task.Run (() => {
fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.TemperatrueMode);
Application.RunOnMainThread (() => {
btnSetTemperature.Text = fh.WorkingTemperature + "°C";
VertTempSeekBar.Progress = fh.WorkingTemperature - 5;
});
});
};
FH_Night.MouseDownEventHandler += (sender, e) => {
if (btnFHSwitch.IsSelected == false) {
return;
}
FH_Night.IsSelected = true;
};
FH_Night.MouseUpEventHandler += (sender, e) => {
if (btnFHSwitch.IsSelected == false) {
return;
}
FH_Common.IsSelected = false;
FH_Night.IsSelected = true;
FH_Auto.IsSelected = false;
FH_Day.IsSelected = false;
Go_away.IsSelected = false;
fh.TemperatureType = 3;
System.Threading.Tasks.Task.Run (() => {
fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.TemperatrueMode);
Application.RunOnMainThread (() => {
btnSetTemperature.Text = fh.WorkingTemperature + "°C";
VertTempSeekBar.Progress = fh.WorkingTemperature - 5;
});
});
};
Go_away.MouseDownEventHandler += (sender, e) => {
if (btnFHSwitch.IsSelected == false) {
return;
}
Go_away.IsSelected = true;
};
Go_away.MouseUpEventHandler += (sender, e) => {
if (btnFHSwitch.IsSelected == false) {
return;
}
FH_Common.IsSelected = false;
Go_away.IsSelected = true;
FH_Night.IsSelected = false;
FH_Day.IsSelected = false;
FH_Auto.IsSelected = false;
fh.TemperatureType = 4;
System.Threading.Tasks.Task.Run (() => {
fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.TemperatrueMode);
Application.RunOnMainThread (() => {
btnSetTemperature.Text = fh.WorkingTemperature + "°C";
VertTempSeekBar.Progress = fh.WorkingTemperature - 5;
});
});
};
FH_Common.MouseDownEventHandler += (sender, e) => {
if (btnFHSwitch.IsSelected == false) {
return;
}
FH_Common.IsSelected = true;
};
FH_Common.MouseUpEventHandler += (sender, e) => {
if (btnFHSwitch.IsSelected == false) {
return;
}
FH_Auto.IsSelected = false;
FH_Common.IsSelected = true;
FH_Night.IsSelected = false;
FH_Day.IsSelected = false;
Go_away.IsSelected = false;
fh.TemperatureType = 1;
System.Threading.Tasks.Task.Run (() => {
fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.TemperatrueMode);
Application.RunOnMainThread (() => {
btnSetTemperature.Text = fh.WorkingTemperature + "°C";
VertTempSeekBar.Progress = fh.WorkingTemperature - 5;
});
});
};
FH_Auto.MouseDownEventHandler += (sender, e) => {
if (btnFHSwitch.IsSelected == false) {
return;
}
FH_Auto.IsSelected = true;
};
FH_Auto.MouseUpEventHandler += (sender, e) => {
if (btnFHSwitch.IsSelected == false) {
return;
}
FH_Common.IsSelected = false;
FH_Night.IsSelected = false;
FH_Day.IsSelected = false;
Go_away.IsSelected = false;
FH_Auto.IsSelected = true;
fh.TemperatureType = 5;
System.Threading.Tasks.Task.Run (() => {
fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.TemperatrueMode);
Application.RunOnMainThread (() => {
btnSetTemperature.Text = fh.WorkingTemperature + "°C";
VertTempSeekBar.Progress = fh.WorkingTemperature - 5;
});
});
};
#endregion
readStatus ();
}
///
/// 读取设备状态
///
void readStatus ()
{
System.Threading.Tasks.Task.Run (() => {
if (fh.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now) {
if (fh.Type == DeviceType.FoolHeatPanel) {
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 20, fh.LoopID, fh.LoopID });
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 21, fh.LoopID, fh.LoopID });
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 24, fh.LoopID, fh.LoopID });
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 25, fh.LoopID, fh.LoopID });
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 26, fh.LoopID, fh.LoopID });
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 27, fh.LoopID, fh.LoopID });
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 28, fh.LoopID, fh.LoopID });
} else if (fh.Type == DeviceType.FoolHeat) {
fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.Read);
}
UpdateStatus (fh);
}
});
}
}
}