using System;
namespace Shared.SimpleControl.Phone
{
public class SystemFan : FrameLayout
{
public SystemFan ()
{
}
public void SystemFanShow (FanModule fanModule, Common fanDevice)
{
#region top
RowLayout frameLayout = new RowLayout () {
Height = Application.GetRealHeight (100),
Width = LayoutParams.MatchParent,
BackgroundColor = SkinStyle.Current.MainColor
};
AddChidren (frameLayout);
Button backButton = new Button () {
X = Application.GetRealWidth (0),
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (85),
UnSelectedImagePath = "Item/Back.png",
SelectedImagePath = "Item/BackSelected.png",
Gravity = Gravity.CenterVertical,
};
backButton.MouseUpEventHandler += (sender, e) => {
(Parent as PageLayout).PageIndex -= 1;
//SystemEquipmentBase.RefreshView (fanDevice);
};
frameLayout.AddChidren (backButton);
EditText textButton = new EditText () {
X = Application.GetRealWidth (20) + backButton.Right,
Height = Application.GetRealHeight (50),
Width = Application.GetRealWidth (400),
Text = fanModule.Name,
Gravity = Gravity.CenterVertical,
TextAlignment = TextAlignment.CenterLeft,
BackgroundColor = SkinStyle.Current.Transparent,
SelectedBackgroundColor = SkinStyle.Current.SysEditBox,
Enable = false,
TextColor = SkinStyle.Current.TextColor1
};
frameLayout.AddChidren (textButton);
Button editor = new Button () {
X = Application.GetRealWidth(520),
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (70),
UnSelectedImagePath = "Item/Editor.png",
SelectedImagePath = "Item/EditorSelected.png",
Gravity = Gravity.CenterVertical,
};
frameLayout.AddChidren (editor);
editor.MouseUpEventHandler += (sender, e) => {
if (editor.IsSelected) {
MainPage.Loading.Start ();
editor.IsSelected = textButton.IsSelected = textButton.Enable = false;
byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (textButton.Text.Trim ());
System.Threading.Tasks.Task.Run (() => {
byte [] updateBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, fanModule.SubnetID, fanModule.DeviceID, new byte [] {
fanModule.BigClass,fanModule.MinClass,fanModule.LoopID
});
if (updateBytes == null) {
Application.RunOnMainThread (() => {
new Alert ("", Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
MainPage.Loading.Hide ();
});
return;
}
byte [] uBytes = new byte [20];
Array.Copy (remakeBytes, 0, uBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20);
Array.Copy (uBytes, 0, updateBytes, 3, 20 < uBytes.Length ? 20 : uBytes.Length);
var reBytes = Control.ControlBytesSendHasReturn (Command.SetDeviceLoopInfo, fanModule.SubnetID, fanModule.DeviceID, updateBytes);
if (reBytes != null) {
Application.RunOnMainThread (() => {
fanModule.Name = textButton.Text.Trim ();
IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
MainPage.Loading.Hide ();
});
} else {
Application.RunOnMainThread (() => {
new Alert ("", Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
MainPage.Loading.Hide ();
});
}
});
} else {
textButton.Enable = textButton.IsSelected = editor.IsSelected = true;
}
};
#endregion
#region MyRegion
FrameLayout frameLayoutBody = new FrameLayout () {
Y = Application.GetRealHeight (100),
Height = Application.GetRealHeight (700),
Width = LayoutParams.MatchParent,
};
AddChidren (frameLayoutBody);
Button btnWindSpeedTitle = new Button () {
Width = Application.GetRealWidth (310),
Height = Application.GetRealHeight (80),
X = Application.GetRealWidth (30),
TextAlignment = TextAlignment.CenterLeft,
Y = Application.GetRealHeight (60),
TextID = R.MyInternationalizationString.WindSpeed
};
frameLayoutBody.AddChidren (btnWindSpeedTitle);
Button btnWindSpeedReduce = new Button () {
Width = Application.GetRealWidth (80),
Height = Application.GetRealHeight (78),
X = Application.GetRealWidth (135),
Y = btnWindSpeedTitle.Bottom,
UnSelectedImagePath = "Fan/Fan-.png",
SelectedImagePath = "Fan/Fan-On.png",
};
frameLayoutBody.AddChidren (btnWindSpeedReduce);
Button btnWindSpeedText = new Button () {
Width = Application.GetRealWidth (225),
Height = Application.GetRealHeight (78),
X = btnWindSpeedReduce.Right,
Y = btnWindSpeedReduce.Y,
BackgroundColor = SkinStyle.Current.ViewColor,
Text = fanModule.WindSpeed.ToString (),
TextSize = 12,
};
frameLayoutBody.AddChidren (btnWindSpeedText);
Button btnWindSpeedAdd = new Button () {
Width = Application.GetRealWidth (80),
Height = Application.GetRealHeight (78),
X = btnWindSpeedText.Right,
Y = btnWindSpeedReduce.Y,
UnSelectedImagePath = "Fan/Fan+.png",
SelectedImagePath = "Fan/Fan+On.png",
};
frameLayoutBody.AddChidren (btnWindSpeedAdd);
btnWindSpeedAdd.MouseDownEventHandler += (sender2, e2) => {
btnWindSpeedAdd.IsSelected = true;
if (fanModule.WindSpeed <8) {
fanModule.WindSpeed++;
//Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
// new byte [] { fanModule.LoopID,fanModule.WindSpeed });
SendControlFan (fanModule, fanModule.WindSpeed);
btnWindSpeedText.Text = fanModule.WindSpeed.ToString ();
IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
}
};
btnWindSpeedAdd.MouseUpEventHandler += (sender2, e2) => {
btnWindSpeedAdd.IsSelected = false;
};
btnWindSpeedReduce.MouseDownEventHandler += (sender2, e2) => {
btnWindSpeedReduce.IsSelected = true;
if (fanModule.WindSpeed >0) {
fanModule.WindSpeed--;
//Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
//new byte [] { fanModule.LoopID,fanModule.WindSpeed });
SendControlFan (fanModule, fanModule.WindSpeed);
btnWindSpeedText.Text = fanModule.WindSpeed.ToString ();
IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
}
};
btnWindSpeedReduce.MouseUpEventHandler += (sender2, e2) => {
btnWindSpeedReduce.IsSelected = false;
};
#endregion
//SystemMiddle.hideBottom ();
}
///
/// //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 ();
});
});
}
}
}