using System;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class SystemLightSwitch : FrameLayout
|
{
|
public void SystemLightSwitchShow (LightSwitch lightSwitch, Common common)
|
{
|
#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 (common);
|
};
|
frameLayout.AddChidren (backButton);
|
|
EditText textButton = new EditText () {
|
X = Application.GetRealWidth (30) + backButton.Right,
|
Height = Application.GetRealHeight (50),
|
Width = Application.GetRealWidth (400),
|
Text = lightSwitch.Name,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1,
|
BackgroundColor = SkinStyle.Current.Transparent,
|
SelectedBackgroundColor = SkinStyle.Current.SysEditBox,
|
};
|
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, lightSwitch.SubnetID, lightSwitch.DeviceID, new byte [] {
|
lightSwitch.BigClass,1,lightSwitch.LoopID
|
});
|
if (updateBytes == null) {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), 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, lightSwitch.SubnetID, lightSwitch.DeviceID, updateBytes);
|
if (reBytes != null) {
|
Application.RunOnMainThread (() => {
|
lightSwitch.Name = textButton.Text.Trim ();
|
IO.FileUtils.SaveEquipmentMessage (lightSwitch, lightSwitch.LoopID.ToString ());
|
MainPage.Loading.Hide ();
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), 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 (798),
|
Width = LayoutParams.MatchParent,
|
};
|
AddChidren (frameLayoutBody);
|
|
//---output test
|
Button btnOutput = new Button () {
|
Width = Application.GetRealWidth (200),
|
Height = Application.GetRealHeight (50),
|
X = backButton.Right,
|
Y = Application.GetRealHeight (40),
|
Text = Language.StringByID( R.MyInternationalizationString.Test)+" :",
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayoutBody.AddChidren (btnOutput);
|
|
Button btnSwitch = new Button () {
|
Width = Application.GetRealWidth (150),
|
Height = Application.GetRealHeight (50),
|
TextAlignment = TextAlignment.Center,
|
X = btnOutput.Right,
|
Y = btnOutput.Y,
|
BackgroundColor = SkinStyle.Current.ButtonColor,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
BorderWidth = 1,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
};
|
if (lightSwitch.CurrentBrightness == 100) {
|
btnSwitch.IsSelected = true;
|
btnSwitch.TextID = R.MyInternationalizationString.ON;
|
} else {
|
btnSwitch.IsSelected = false;
|
btnSwitch.TextID = R.MyInternationalizationString.OFF;
|
}
|
frameLayoutBody.AddChidren (btnSwitch);
|
btnSwitch.MouseUpEventHandler += (sender, e) => {
|
if (btnSwitch.IsSelected) {
|
lightSwitch.CurrentBrightness = 0;
|
btnSwitch.TextID = R.MyInternationalizationString.OFF;
|
btnSwitch.IsSelected = false;
|
} else {
|
lightSwitch.CurrentBrightness = 100;
|
btnSwitch.TextID = R.MyInternationalizationString.ON;
|
btnSwitch.IsSelected = true;
|
}
|
System.Threading.Tasks.Task.Run (() => {
|
Control.ControlBytesSend (Command.SetSingleLight, lightSwitch.SubnetID, lightSwitch.DeviceID,
|
new byte [] { lightSwitch.LoopID, lightSwitch.CurrentBrightness, lightSwitch.DelayTimeHeight, lightSwitch.DelayTimeLow }, SendCount.Zero);
|
IO.FileUtils.SaveEquipmentMessage (lightSwitch, lightSwitch.LoopID.ToString ());
|
});
|
};
|
|
Button btnSocketText = new Button () {
|
X = backButton.Right,
|
Y = btnSwitch.Bottom + Application.GetRealHeight (50),
|
Width = Application.GetRealWidth (200),
|
Height = Application.GetRealHeight (60),
|
TextID = R.MyInternationalizationString.ElectricalControl,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayoutBody.AddChidren (btnSocketText);
|
|
Button btnSocket = new Button () {
|
X = btnSocketText.Right,
|
Y = btnSocketText.Y,
|
Width = Application.GetRealWidth (60),
|
Height = Application.GetRealHeight (59),
|
SelectedImagePath = "Light/CheckOn.png",
|
UnSelectedImagePath = "Light/Check.png",
|
};
|
frameLayoutBody.AddChidren (btnSocket);
|
btnSocket.IsSelected = lightSwitch.IsSocket;
|
btnSocket.MouseUpEventHandler += (sender, e) => {
|
btnSocket.IsSelected = !btnSocket.IsSelected;
|
if (!btnSocket.IsSelected) {
|
if (UserConfig.Instance.SocketList.Contains (lightSwitch.CommonLoopID)){
|
UserConfig.Instance.SocketList.Remove (lightSwitch.CommonLoopID);
|
lightSwitch.Type = DeviceType.LightSwitch;
|
lightSwitch.DeviceTextID = SimpleControl.R.MyInternationalizationString.Lights;
|
}
|
} else {
|
UserConfig.Instance.SocketList.Add (lightSwitch.CommonLoopID);
|
lightSwitch.Type = DeviceType.LightSwitchSocket;
|
lightSwitch.DeviceTextID = SimpleControl.R.MyInternationalizationString.ElectricalControl;
|
}
|
UserConfig.Instance.SaveUserConfig ();
|
IO.FileUtils.SaveEquipmentMessage (lightSwitch, lightSwitch.LoopID.ToString ());
|
};
|
#endregion
|
|
}
|
}
|
}
|