using System;
namespace Shared.SimpleControl.Phone
{
public class UserFan : FrameLayout
{
public static UserFan curView;
FrameLayout speedView;
Button btnBottomSwitch;
Button btnSwitch;
FanModule fanModule;
public UserFan (FanModule fan)
{
curView = this;
fanModule = fan;
BackgroundColor = SkinStyle.Current.MainColor;
}
public void ShowRoomFan ()
{
#region 标题
var topView = new FrameLayout () {
Y = Application.GetRealHeight (36),
Height = Application.GetRealHeight (90),
};
AddChidren (topView);
var title = new Button () {
TextAlignment = TextAlignment.Center,
Text = fanModule.Name,
TextSize = 19,
TextColor = SkinStyle.Current.TextColor1,
};
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
var roomBackgroundImage = new FrameLayout () {
Y = topView.Bottom,
Height = Application.GetRealHeight (1136) - topView.Bottom,
BackgroundImagePath = "Fan/FanSpeedBackground.png"
};
AddChidren (roomBackgroundImage);
speedView = new FrameLayout () {
X = Application.GetRealWidth (70),
Y = Application.GetRealHeight (100),
Width = Application.GetMinRealAverage (500),
Height = Application.GetMinRealAverage (500),
BackgroundImagePath = "Fan/Speed0.png",
};
roomBackgroundImage.AddChidren (speedView);
Button btnSpeed8 = new Button () {
X = Application.GetRealWidth (100),
Y = Application.GetRealHeight (20),
Width = Application.GetRealWidth (140),
Height = Application.GetRealHeight (90),
Radius = 5,
};
speedView.AddChidren (btnSpeed8);
btnSpeed8.MouseDownEventHandler += (sender, e) => {
//fanModule.Switch = fanModule.WindSpeed = 8;
////Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,new byte [] { fanModule.LoopID, 8 });
//speedView.BackgroundImagePath = "Fan/Speed" + fanModule.Switch.ToString () + ".png";
//IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
SendControlFan (fanModule, 8);
};
Button btnSpeed1 = new Button () {
X = btnSpeed8.Right + Application.GetRealWidth (20),
Y = btnSpeed8.Y,
Width = Application.GetRealWidth (140),
Height = Application.GetRealHeight (90),
Radius = 5,
};
speedView.AddChidren (btnSpeed1);
btnSpeed1.MouseDownEventHandler += (sender, e) => {
//btnBottomSwitch.IsSelected = btnSwitch.IsSelected = true;
//fanModule.Switch = fanModule.WindSpeed = 1;
////Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,new byte [] { fanModule.LoopID, 1 });
//speedView.BackgroundImagePath = "Fan/Speed" + fanModule.Switch.ToString () + ".png";
//IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
SendControlFan (fanModule, 1);
};
Button btnSpeed2 = new Button () {
X = Application.GetRealWidth (380),
Y = Application.GetRealHeight (130),
Width = Application.GetRealWidth (105),
Height = Application.GetRealHeight (105),
Radius = 5,
};
speedView.AddChidren (btnSpeed2);
btnSpeed2.MouseDownEventHandler += (sender, e) => {
//btnBottomSwitch.IsSelected = btnSwitch.IsSelected = true;
//fanModule.Switch = fanModule.WindSpeed = 2;
////Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,new byte [] { fanModule.LoopID, 2 });
//speedView.BackgroundImagePath = "Fan/Speed" + fanModule.Switch.ToString () + ".png";
//IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
SendControlFan (fanModule, 2);
};
Button btnSpeed3 = new Button () {
X = Application.GetRealWidth (380),
Y = btnSpeed2.Bottom + Application.GetRealHeight (20),
Width = Application.GetRealWidth (105),
Height = Application.GetRealHeight (105),
Radius = 5,
};
speedView.AddChidren (btnSpeed3);
btnSpeed3.MouseDownEventHandler += (sender, e) => {
//btnBottomSwitch.IsSelected = btnSwitch.IsSelected = true;
//fanModule.Switch = fanModule.WindSpeed = 3;
////Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,new byte [] { fanModule.LoopID, 3 });
//speedView.BackgroundImagePath = "Fan/Speed" + fanModule.Switch.ToString () + ".png";
//IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
SendControlFan (fanModule, 3);
};
Button btnSpeed4 = new Button () {
X = btnSpeed1.X,
Y = btnSpeed3.Bottom + Application.GetRealHeight (20),
Width = Application.GetRealWidth (140),
Height = Application.GetRealHeight (90),
Radius = 5,
};
speedView.AddChidren (btnSpeed4);
btnSpeed4.MouseDownEventHandler += (sender, e) => {
//btnBottomSwitch.IsSelected = btnSwitch.IsSelected = true;
//fanModule.Switch = fanModule.WindSpeed = 4;
////Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,new byte [] { fanModule.LoopID, 4 });
//speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png";
//IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
SendControlFan (fanModule, 4);
};
Button btnSpeed5 = new Button () {
X = btnSpeed8.X,
Y = btnSpeed4.Y,
Width = Application.GetRealWidth (140),
Height = Application.GetRealHeight (90),
Radius = 5,
IsSelected = fanModule.Switch == 5 ? true : false
};
speedView.AddChidren (btnSpeed5);
btnSpeed5.MouseDownEventHandler += (sender, e) => {
//btnBottomSwitch.IsSelected = btnSwitch.IsSelected = true;
//fanModule.Switch = fanModule.WindSpeed = 5;
////Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,new byte [] { fanModule.LoopID, 5 });
//speedView.BackgroundImagePath = "Fan/Speed" + fanModule.Switch.ToString () + ".png";
//IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
SendControlFan (fanModule, 5);
};
Button btnSpeed6 = new Button () {
X = Application.GetRealWidth (20),
Y = btnSpeed3.Y,
Width = Application.GetRealWidth (105),
Height = Application.GetRealHeight (105),
Radius = 5,
};
speedView.AddChidren (btnSpeed6);
btnSpeed6.MouseDownEventHandler += (sender, e) => {
//btnBottomSwitch.IsSelected = btnSwitch.IsSelected = true;
//fanModule.Switch = fanModule.WindSpeed = 6;
////Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,new byte [] { fanModule.LoopID, 6 });
//speedView.BackgroundImagePath = "Fan/Speed" + fanModule.Switch.ToString () + ".png";
//IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
SendControlFan (fanModule, 6);
};
Button btnSpeed7 = new Button () {
X = Application.GetRealWidth (20),
Y = btnSpeed2.Y,
Width = Application.GetRealWidth (105),
Height = Application.GetRealHeight (105),
Radius = 5,
};
speedView.AddChidren (btnSpeed7);
btnSpeed7.MouseDownEventHandler += (sender, e) => {
//btnBottomSwitch.IsSelected = btnSwitch.IsSelected = true;
//fanModule.Switch = fanModule.WindSpeed = 7;
////Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,new byte [] { fanModule.LoopID, 7 });
//speedView.BackgroundImagePath = "Fan/Speed" + fanModule.Switch.ToString () + ".png";
//IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
SendControlFan (fanModule, 7);
};
btnSwitch = new Button () {
Gravity = Gravity.Center,
Width = Application.GetMinRealAverage (260),
Height = Application.GetMinRealAverage (260),
SelectedImagePath = "Fan/FanIconSwitchOn.png",
UnSelectedImagePath = "Fan/FanIconSwitch.png",
IsSelected = fanModule.Switch != 0
};
speedView.AddChidren (btnSwitch);
btnBottomSwitch = new Button () {
X = Application.GetRealWidth (212),
Y = speedView.Bottom + Application.GetRealHeight (250),
Width = Application.GetMinRealAverage (215),
Height = Application.GetMinRealAverage (95),
SelectedImagePath = "Fan/FanSwitchOn.png",
UnSelectedImagePath = "Fan/FanSwitch.png",
IsSelected = fanModule.Switch != 0
};
AddChidren (btnBottomSwitch);
btnSwitch.MouseDownEventHandler += (sender, e) => {
if (btnSwitch.IsSelected) {
//btnBottomSwitch.IsSelected = btnSwitch.IsSelected = false;
//fanModule.Switch = 0;
////Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,new byte [] { fanModule.LoopID, fanModule.Switch });
//SendControlFan (fanModule, fanModule.Switch);
//speedView.BackgroundImagePath = "Fan/Speed0.png";
SendControlFan (fanModule, 0);
} else {
//btnSwitch.IsSelected = btnBottomSwitch.IsSelected = true;
//fanModule.Switch = fanModule.WindSpeed;
////Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,new byte [] { fanModule.LoopID, fanModule.WindSpeed });
//SendControlFan (fanModule, fanModule.WindSpeed);
//speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png";
if (fanModule.WindSpeed == 0) fanModule.WindSpeed = 1;
SendControlFan (fanModule, fanModule.WindSpeed);
}
//IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
};
btnBottomSwitch.MouseDownEventHandler += (sender, e) => {
if (btnBottomSwitch.IsSelected) {
//btnBottomSwitch.IsSelected = btnSwitch.IsSelected = false;
//fanModule.Switch = 0;
////Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, fanModule.Switch });
//SendControlFan (fanModule, fanModule.Switch);
//speedView.BackgroundImagePath = "Fan/Speed0.png";
SendControlFan (fanModule, 0);
} else {
//btnBottomSwitch.IsSelected = btnSwitch.IsSelected = true;
//fanModule.Switch = fanModule.WindSpeed;
////Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, fanModule.WindSpeed });
//SendControlFan (fanModule, fanModule.WindSpeed);
//speedView.BackgroundImagePath = "Fan/Speed" + fanModule.Switch.ToString () + ".png";
if (fanModule.WindSpeed == 0) fanModule.WindSpeed = 1;
SendControlFan (fanModule, fanModule.WindSpeed);
}
//IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
};
Control.ControlBytesSend (Command.ReadLightEquipmentAllLoopBrightness, fanModule.SubnetID, fanModule.DeviceID,new byte [] { });
speedView.BackgroundImagePath = "Fan/Speed" + fanModule.Switch.ToString () + ".png";
}
public static void UpdataFanView (string updataFlag, byte windSpeed)
{
Application.RunOnMainThread (() => {
if (curView == null)
return;
if (curView.fanModule.CommonLoopID != updataFlag)
return;
if (windSpeed == 0) {
curView.btnBottomSwitch.IsSelected = false;
curView.btnSwitch.IsSelected = false;
curView.speedView.BackgroundImagePath = "Fan/Speed0.png";
} else {
curView.btnBottomSwitch.IsSelected = true;
curView.btnSwitch.IsSelected = true;
curView.speedView.BackgroundImagePath = "Fan/Speed" + windSpeed.ToString () + ".png";
}
});
}
///
/// //2020-02-10 带返回结果的风扇控制
///
///
///
void SendControlFan (FanModule mFanModule, byte sendByte) {
MainPage.Loading.Start ("Sending...");
System.Threading.Tasks.Task.Run (() => {
byte [] returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, mFanModule.SubnetID, mFanModule.DeviceID, new byte [] { mFanModule.LoopID, sendByte });
//byte [] returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, fanModule.Switch });
Application.RunOnMainThread (() => {
if (returnBytes == null) {
new Alert ("", mFanModule.Name + ErrorCode.ControlFailure, "Close").Show ();
}
MainPage.Loading.Hide ();
});
});
}
}
}