using Shared.SimpleControl.Phone;
|
using System;
|
using System.Collections.Generic;
|
using Shared.SimpleControl;
|
|
namespace Shared.SimpleControl.Pad
|
{
|
/// <summary>
|
/// 空调控制界面
|
/// </summary>
|
public class UserACPage : FrameLayout
|
{
|
/// <summary>
|
/// 当前视图
|
/// </summary>
|
static UserACPage curView;
|
FrameLayout acBodyView;
|
AC ac;
|
Room room;
|
SystemACHostMethod acM;
|
Button btnInterior;
|
Button btnACSwitch;
|
Button btnSetTemperature;
|
VerticalSeekBar VertTempSeekBar;
|
FrameLayout WindSpeedView;
|
FrameLayout ModeView;
|
|
public UserACPage (AC ac, Room room)
|
{
|
this.ac = ac;
|
this.room = room;
|
curView = this;
|
acM = new SystemACHostMethod ();
|
}
|
|
/// <summary>
|
/// 更新空调
|
/// </summary>
|
public static void UpdateStatus (AC 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 () + "°C";
|
curView.acM.UpdataACModeTemperature (ac, ac.SetMode, curView.btnSetTemperature);
|
curView.VertTempSeekBar.Progress = Convert.ToInt32 (ac.SetTemperature) - 16;
|
for (int b = 0; b < curView.WindSpeedView.ChildrenCount; b++) {
|
var btn = curView.WindSpeedView.GetChildren (b);
|
btn.Enable = true;
|
if(btn.Tag!=null)
|
(btn as Button).IsSelected = btn.Tag.ToString () == ac.SetFanSpeed.ToString () ? true : false;
|
}
|
for (int b = 0; b < curView.ModeView.ChildrenCount; b++) {
|
var btn = curView.ModeView.GetChildren (b);
|
btn.Enable = true;
|
if(btn.Tag!=null)
|
(btn as Button).IsSelected = btn.Tag.ToString () == ac.SetMode.ToString () ? true : false;
|
}
|
} else {
|
curView.btnACSwitch.IsSelected = false;
|
for (int b = 0; b < curView.WindSpeedView.ChildrenCount; b++) {
|
var btn = curView.WindSpeedView.GetChildren (b);
|
if(btn.Tag!=null)
|
(btn as Button).IsSelected = btn.Enable = false;
|
}
|
for (int b = 0; b < curView.ModeView.ChildrenCount; b++) {
|
var btn = curView.ModeView.GetChildren (b);
|
if(btn.Tag!=null)
|
(btn as Button).IsSelected = btn.Enable = false;
|
}
|
}
|
} catch {
|
}
|
});
|
}
|
|
/// <summary>
|
/// 显示出当前房间所有的空调
|
/// </summary>
|
public void showRoomAC ()
|
{
|
acBodyView = new FrameLayout ();
|
AddChidren (acBodyView);
|
#region Top View
|
FrameLayout roomBackgroundImageView = new FrameLayout () {
|
X = Application.GetRealWidth (10),
|
Y = Application.GetRealHeight (10),
|
Width = Application.GetRealWidth (920),
|
Height = Application.GetRealHeight (520),
|
};
|
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);
|
};
|
FrameLayout indoorTempView = new FrameLayout () {
|
X = roomBackgroundImageView.X,
|
Y = roomBackgroundImageView.Bottom + Application.GetRealHeight (10),
|
Width = Application.GetRealWidth (920),
|
Height = Application.GetRealHeight (150),
|
BackgroundColor = 0xFF333333,
|
};
|
acBodyView.AddChidren (indoorTempView);
|
|
Button btnText = new Button () {
|
Width = Application.GetRealWidth (200),
|
TextID = R.MyInternationalizationString.ACInterior,
|
TextSize = 20,
|
};
|
indoorTempView.AddChidren (btnText);
|
|
btnInterior = new Button () {
|
Width = Application.GetRealWidth (150),
|
X = btnText.Right,
|
Text = ac.IndoorTemperature.ToString () + "°C",
|
TextSize = 30,
|
TextAlignment = TextAlignment.Center,
|
};
|
indoorTempView.AddChidren (btnInterior);
|
|
FrameLayout SetTemperatureView = new FrameLayout () {
|
X = roomBackgroundImageView.Right + Application.GetRealWidth (10),
|
Y = roomBackgroundImageView.Y,
|
Width = Application.GetRealWidth(600),
|
Height = Application.GetRealHeight(680),
|
};
|
acBodyView.AddChidren (SetTemperatureView);
|
|
btnSetTemperature = new Button () {
|
X = Application.GetRealWidth (20),
|
Y = Application.GetRealHeight (330),
|
Width = Application.GetRealWidth (320),
|
Height = Application.GetRealHeight (220),
|
Text = ac.SetTemperature.ToString () + "°C",
|
TextSize = 68,
|
TextAlignment = TextAlignment.Center,
|
Enable = false,
|
};
|
SetTemperatureView.AddChidren (btnSetTemperature);
|
|
btnACSwitch = 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",
|
Text = "ON"
|
};
|
btnACSwitch.IsSelected = ac.Power == 1;
|
btnACSwitch.MouseUpEventHandler += (sender, e) => {
|
btnACSwitch.IsSelected = !btnACSwitch.IsSelected;
|
ac.Power = btnACSwitch.IsSelected ? (byte)1 : (byte)0;
|
if (ac.Type == DeviceType.ACPanel) {
|
Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 3, ac.Power });
|
} else if (ac.Type == DeviceType.ACDevice || ac.Type == DeviceType.ACInfrared) {
|
Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] { ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature, ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature, ac.ChuShiTemperature, ac.RealModeAndFanSpeed, ac.Power, ac.SetMode, ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode });
|
}
|
|
};
|
SetTemperatureView.AddChidren (btnACSwitch);
|
|
Button btnHorTemp = new Button () {
|
X = btnSetTemperature.Right + Application.GetRealWidth (30),
|
Y = Application.GetRealHeight (20),
|
Width = Application.GetRealWidth (100),
|
Height = Application.GetRealHeight (620),
|
UnSelectedImagePath = "PadAdding/PadTemp.png",
|
};
|
SetTemperatureView.AddChidren (btnHorTemp);
|
|
VertTempSeekBar = new VerticalSeekBar () {
|
X = btnHorTemp.Right,
|
Y = btnHorTemp.Y - Application.GetRealHeight (10),
|
Width = Application.GetRealWidth (100),
|
Height = Application.GetRealHeight (640),
|
Max = 14,
|
ProgressColor = SkinStyle.Current.SelectedColor,
|
Progress = ac.SetTemperature - 16
|
};
|
SetTemperatureView.AddChidren (VertTempSeekBar);
|
VertTempSeekBar.ProgressChanged += (sender, e) => {
|
btnSetTemperature.Text = (e + 16).ToString () + "°C";
|
};
|
VertTempSeekBar.MouseUpEventHandler += (sender, e) => {
|
ac.SetTemperature = (byte)(VertTempSeekBar.Progress + 16);
|
Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] { ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature, ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature, ac.ChuShiTemperature, ac.RealModeAndFanSpeed, ac.Power, ac.SetMode, ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode });
|
};
|
#endregion
|
|
#region 风速
|
WindSpeedView = new FrameLayout () {
|
X = Application.GetRealWidth(10),
|
Y = indoorTempView.Bottom + Application.GetRealHeight (50),
|
Height = Application.GetRealHeight (300),
|
//BackgroundColor = SkinStyle.Current.BackgroundColor,
|
};
|
acBodyView.AddChidren (WindSpeedView);
|
|
Button btnWindTitle = new Button () {
|
X = Application.GetRealWidth(30),
|
Width= Application.GetRealWidth(300),
|
Height = Application.GetRealHeight(70),
|
TextID = R.MyInternationalizationString.WindSpeed,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
WindSpeedView.AddChidren (btnWindTitle);
|
#region Wind
|
Button btnHighWind = new Button () {
|
X = Application.GetRealWidth (10),
|
Y = btnWindTitle.Bottom + Application.GetRealHeight (20),
|
Width = Application.GetRealWidth (368),
|
Height = Application.GetRealHeight (180),
|
UnSelectedImagePath = "PadAdding/ACHigh.png",
|
SelectedImagePath = "PadAdding/ACHighOn.png",
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextID = R.MyInternationalizationString.High,
|
Tag = 1,
|
Padding = new Padding (40,0,0,0),
|
TextSize = 12,
|
TextAlignment = TextAlignment.Center
|
};
|
WindSpeedView.AddChidren (btnHighWind);
|
btnHighWind.MouseUpEventHandler += (sender, e) => {
|
ac.SetFanSpeed = 1;
|
Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] {
|
ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature,
|
ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature,
|
ac.ChuShiTemperature, ac.RealModeAndFanSpeed,
|
btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode,
|
ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode });
|
};
|
|
Button btnMedium = new Button () {
|
Width = Application.GetRealWidth (368),
|
Height = Application.GetRealHeight (180),
|
X = btnHighWind.Right + Application.GetRealWidth (10),
|
Y = btnHighWind.Y,
|
UnSelectedImagePath = "PadAdding/ACMedium.png",
|
SelectedImagePath = "PadAdding/ACMediumOn.png",
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextID = R.MyInternationalizationString.Stroke,
|
Tag = 2,
|
Padding = new Padding (40,0,0,0),
|
TextSize = 12,
|
TextAlignment = TextAlignment.Center
|
};
|
WindSpeedView.AddChidren (btnMedium);
|
btnMedium.MouseUpEventHandler += (sender, e) => {
|
ac.SetFanSpeed = 2;
|
Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] {
|
ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature,
|
ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature,
|
ac.ChuShiTemperature, ac.RealModeAndFanSpeed,
|
btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode,
|
ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode });
|
};
|
Button btnLow = new Button () {
|
Width = Application.GetRealWidth (368),
|
Height = Application.GetRealHeight (180),
|
X = btnMedium.Right + Application.GetRealWidth (10),
|
Y = btnHighWind.Y,
|
UnSelectedImagePath = "PadAdding/ACLow.png",
|
SelectedImagePath = "PadAdding/ACLowOn.png",
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextID = R.MyInternationalizationString.Low,
|
Tag = 3,
|
Padding = new Padding (40,0,0,0),
|
TextSize = 12,
|
TextAlignment = TextAlignment.Center
|
};
|
WindSpeedView.AddChidren (btnLow);
|
btnLow.MouseUpEventHandler += (sender, e) => {
|
ac.SetFanSpeed = 3;
|
Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] {
|
ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature,
|
ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature,
|
ac.ChuShiTemperature, ac.RealModeAndFanSpeed,
|
btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode,
|
ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode });
|
};
|
|
Button btnAuto = new Button () {
|
Width = Application.GetRealWidth (368),
|
Height = Application.GetRealHeight (180),
|
X = btnLow.Right + Application.GetRealWidth (10),
|
Y = btnHighWind.Y,
|
UnSelectedImagePath = "PadAdding/ACAuto.png",
|
SelectedImagePath = "PadAdding/ACAutoOn.png",
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextID = R.MyInternationalizationString.Auto,
|
Tag = 0,
|
Padding = new Padding (40,0,0,0),
|
TextSize = 12,
|
TextAlignment = TextAlignment.Center
|
};
|
WindSpeedView.AddChidren (btnAuto);
|
btnAuto.MouseUpEventHandler += (sender, e) => {
|
ac.SetFanSpeed = 0;
|
Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] {
|
ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature,
|
ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature,
|
ac.ChuShiTemperature, ac.RealModeAndFanSpeed,
|
btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode,
|
ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode });
|
};
|
#endregion
|
#endregion
|
|
#region 模式
|
ModeView = new FrameLayout () {
|
Height = Application.GetRealHeight (300),
|
Width = LayoutParams.MatchParent,
|
X = Application.GetRealWidth(10),
|
Y = WindSpeedView.Bottom + Application.GetRealHeight (50),
|
//BackgroundColor = SkinStyle.Current.BackgroundColor,
|
};
|
acBodyView.AddChidren (ModeView);
|
|
Button btnModeTitle = new Button () {
|
X = Application.GetRealWidth (30),
|
Width = Application.GetRealWidth (300),
|
Height = Application.GetRealHeight (70),
|
TextID = R.MyInternationalizationString.UserACMode,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
ModeView.AddChidren (btnModeTitle);
|
|
Button btnCoolMode = new Button () {
|
X = Application.GetRealWidth (10),
|
Y = btnModeTitle.Bottom + Application.GetRealHeight (10),
|
Width = Application.GetRealWidth (293),
|
Height = Application.GetRealHeight (180),
|
UnSelectedImagePath = "PadAdding/ACCool.png",
|
SelectedImagePath = "PadAdding/ACCoolOn.png",
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextID = R.MyInternationalizationString.Cool,
|
Tag = 0,
|
Padding = new Padding (40,0,0,0),
|
TextSize = 12,
|
TextAlignment = TextAlignment.Center
|
};
|
ModeView.AddChidren (btnCoolMode);
|
btnCoolMode.MouseUpEventHandler += (sender, e) => {
|
ac.SetMode = 0;
|
Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] {
|
ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature,
|
ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature,
|
ac.ChuShiTemperature, ac.RealModeAndFanSpeed,
|
btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode,
|
ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode });
|
};
|
//Button btnCoolIcon = new Button () {
|
// X = btnCoolMode.X + Application.GetRealWidth(100),
|
// Y = btnCoolMode.Y + Application.GetRealHeight(20),
|
// Width = Application.GetRealWidth(60),
|
// Height = Application.GetRealHeight(60),
|
// UnSelectedImagePath = "AC/ACRefrigeration.png",
|
// SelectedImagePath = "AC/ACRefrigeration.png",
|
//};
|
//ModeView.AddChidren (btnCoolIcon);
|
Button btnHotMode = new Button () {
|
X =btnCoolMode.Right + Application.GetRealWidth (10),
|
Y = btnCoolMode.Y,
|
Width = Application.GetRealWidth (290),
|
Height = Application.GetRealHeight (180),
|
UnSelectedImagePath = "PadAdding/ACHot.png",
|
SelectedImagePath = "PadAdding/ACHotOn.png",
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextID = R.MyInternationalizationString.Hot,
|
Tag = 1,
|
Padding = new Padding (40,0,0,0),
|
TextSize = 12,
|
TextAlignment = TextAlignment.Center
|
};
|
ModeView.AddChidren (btnHotMode);
|
btnHotMode.MouseUpEventHandler += (sender, e) => {
|
ac.SetMode = 1;
|
Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] {
|
ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature,
|
ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature,
|
ac.ChuShiTemperature, ac.RealModeAndFanSpeed,
|
btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode,
|
ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode });
|
};
|
|
Button btnFanMode = new Button () {
|
X =btnHotMode.Right+ Application.GetRealWidth (10),
|
Y = btnCoolMode.Y,
|
Width = Application.GetRealWidth (293),
|
Height = Application.GetRealHeight (180),
|
UnSelectedImagePath = "PadAdding/ACWindMode.png",
|
SelectedImagePath = "PadAdding/ACWindModeOn.png",
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextID = R.MyInternationalizationString.Ventila,
|
Tag = 2,
|
Padding = new Padding (40,0,0,0),
|
TextSize = 12,
|
TextAlignment = TextAlignment.Center
|
};
|
ModeView.AddChidren (btnFanMode);
|
btnFanMode.MouseUpEventHandler += (sender, e) => {
|
ac.SetMode = 2;
|
Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] {
|
ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature,
|
ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature,
|
ac.ChuShiTemperature, ac.RealModeAndFanSpeed,
|
btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode,
|
ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode });
|
};
|
|
Button btnAutoMode = new Button () {
|
X =btnFanMode.Right + Application.GetRealWidth (10),
|
Y = btnModeTitle.Bottom + Application.GetRealHeight (10),
|
Width = Application.GetRealWidth (293),
|
Height = Application.GetRealHeight (180),
|
UnSelectedImagePath = "PadAdding/ACAutoMode.png",
|
SelectedImagePath = "PadAdding/ACAutoModeOn.png",
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextID = R.MyInternationalizationString.Auto,
|
Tag = 3,
|
Padding = new Padding (40,0,0,0),
|
TextSize = 12,
|
TextAlignment = TextAlignment.Center
|
};
|
ModeView.AddChidren (btnAutoMode);
|
btnAutoMode.MouseUpEventHandler += (sender, e) => {
|
ac.SetMode = 3;
|
Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] {
|
ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature,
|
ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature,
|
ac.ChuShiTemperature, ac.RealModeAndFanSpeed,
|
btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode,
|
ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode });
|
};
|
|
Button btnDehumidify = new Button () {
|
X = btnAutoMode.Right + Application.GetRealWidth (10),
|
Y = btnCoolMode.Y,
|
Width = Application.GetRealWidth (293),
|
Height = Application.GetRealHeight (180),
|
UnSelectedImagePath = "PadAdding/ACChuShi.png",
|
SelectedImagePath = "PadAdding/ACChushiOn.png",
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextID = R.MyInternationalizationString.Dehumidify,
|
Tag = 4,
|
Padding = new Padding(40,0,0,0),
|
TextSize = 12,
|
TextAlignment = TextAlignment.Center
|
};
|
ModeView.AddChidren (btnDehumidify);
|
btnDehumidify.MouseUpEventHandler += (sender, e) => {
|
ac.SetMode = 4;
|
Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] {
|
ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature,
|
ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature,
|
ac.ChuShiTemperature, ac.RealModeAndFanSpeed,
|
btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode,
|
ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode });
|
};
|
#endregion
|
|
UpdateStatus (ac);
|
readStatus (ac);
|
}
|
|
/// <summary>
|
/// 读取设备状态
|
/// </summary>
|
static void readStatus (AC ac)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
if (ac.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now) {
|
var s = ac.Type + "_" + ac.SubnetID + "_" + ac.DeviceID + "_" + ac.LoopID;
|
Control.ControlBytesSendHasReturn (Command.ReadACMode, ac.SubnetID, ac.DeviceID, new byte [] { ac.LoopID });
|
}
|
});
|
}
|
|
public void controlPanelAC () {
|
|
}
|
|
}
|
}
|