using Shared.SimpleControl.Phone;
using System;
namespace Shared.SimpleControl.Pad
{
public class UserDeviceToFan : Shared.Dialog
{
VerticalScrolViewLayout RoomListScrolView;
UserFan ControlBodyView;
static UserDeviceToFan curView;
///
///构造函数
///
public UserDeviceToFan ()
{
curView = this;
showAllRoomCurtain ();
UserDeviceToLight.readAllStatus ();
}
///
/// 通过设备类型方式选择设备
///
void showAllRoomCurtain ()
{
#region 标题
FrameLayout topBackView = new FrameLayout () {
Height = Application.GetRealHeight (150),
BackgroundColor = 0xFF2f2f2f
};
AddChidren (topBackView);
var topView = new FrameLayout () {
Y = Application.GetRealHeight (36),
Height = Application.GetRealHeight (90),
};
AddChidren (topView);
var title = new Button () {
TextAlignment = TextAlignment.Center,
Text = Language.StringByID (R.MyInternationalizationString.Fan),
TextSize = 21,
};
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 (120),
Width = Application.GetRealWidth (95),
UnSelectedImagePath = "Item/Back.png",
SelectedImagePath = "Item/BackSelected.png",
Gravity = Gravity.CenterVertical,
};
topView.AddChidren (back);
back.MouseUpEventHandler += (sender, e) => {
Close ();
curView = null;
};
var btnl = new Button () {
Height = 1,
BackgroundColor = 0xFF2f2f2f,
Y = topView.Height - 1
};
topView.AddChidren (btnl);
#endregion
FrameLayout bordorView = new FrameLayout () {
Width = Application.GetRealWidth (480),
Height = Application.GetRealHeight (Application.DesignHeight - 150),
Y = Application.GetRealHeight (150),
BackgroundColor = 0xFF2f2f2f
};
AddChidren (bordorView);
#region 全开-全关
var powerView = new FrameLayout () {
Height = Application.GetRealHeight (140),
BackgroundColor = SkinStyle.Current.MainColor,
};
bordorView.AddChidren (powerView);
var btnAllON = new Button () {
Width = Application.GetRealWidth (240),
TextSize = 16,
TextID = R.MyInternationalizationString.ALLON,
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
};
powerView.AddChidren (btnAllON);
var btnAllOff = new Button () {
Width = Application.GetRealWidth (240),
X = btnAllON.Right,
TextSize = 16,
TextID = R.MyInternationalizationString.ALLOFF,
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
};
var btnLine = new Button () {
Width = 1,
BackgroundColor = 0xFF2f2f2f,
X = btnAllON.Right,
};
powerView.AddChidren (btnLine);
var btnLine1 = new Button () {
Height = 1,
Y = powerView.Height - 1,
BackgroundColor = 0xFF2f2f2f,
};
powerView.AddChidren (btnLine1);
btnAllON.MouseUpEventHandler += (sender, e) => {
btnAllON.TextColor = SkinStyle.Current.SelectedColor;
btnAllOff.TextColor = SkinStyle.Current.TextColor1;
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
Language.StringByID (R.MyInternationalizationString.SureOpenAllFan),
Language.StringByID (R.MyInternationalizationString.Cancel),
Language.StringByID (R.MyInternationalizationString.Confrim));
alert.Show ();
alert.ResultEventHandler += (sender2, e2) => {
if (e2) {
ControlAllFan (true);
}
};
};
powerView.AddChidren (btnAllOff);
btnAllOff.MouseUpEventHandler += (sender, e) => {
btnAllON.TextColor = SkinStyle.Current.TextColor1;
btnAllOff.TextColor = SkinStyle.Current.SelectedColor;
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
Language.StringByID (R.MyInternationalizationString.SureCloseAllFan),
Language.StringByID (R.MyInternationalizationString.Cancel),
Language.StringByID (R.MyInternationalizationString.Confrim));
alert.Show ();
alert.ResultEventHandler += (sender2, e2) => {
if (e2) {
ControlAllFan (false);
}
};
};
#endregion
RoomListScrolView = new VerticalScrolViewLayout () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (Application.DesignHeight - 300 - 140),
Y = powerView.Bottom,
};
bordorView.AddChidren (RoomListScrolView);
#region 显示
int devcieCount = 0;
foreach (var room in Room.Lists) {
if (room.Name == "") {
continue;
}
foreach (var common in room.DeviceList) {
if (common.Type == DeviceType.FanModule) {
var fanModule = common as FanModule;
EventHandler openCurtainControlPageEvent = (button, mouseEventArgs) => {
for (int i = 0; i < RoomListScrolView.ChildrenCount; i++) {
var view = RoomListScrolView.GetChildren (i);
if (view.Tag.ToString () == room.Name) {
for (int j = 0; j < (view as FrameLayout).ChildrenCount; j++) {
var btn = (view as FrameLayout).GetChildren (j);
if (btn.GetType () == typeof (Button))
(btn as Button).IsSelected = true;
}
} else {
for (int j = 0; j < (view as FrameLayout).ChildrenCount; j++) {
var btn = (view as FrameLayout).GetChildren (j);
if (btn.GetType () == typeof (Button))
(btn as Button).IsSelected = false;
}
}
}
if (ControlBodyView != null) {
ControlBodyView.RemoveFromParent ();
}
ControlBodyView = new UserFan (fanModule) {
Width = Application.GetRealWidth (Application.DesignWidth) - bordorView.Width,
Height = Application.GetRealHeight (Application.DesignHeight - 150),
X = bordorView.Right,
Y = bordorView.Y,
BackgroundColor = SkinStyle.Current.MainColor
};
AddChidren (ControlBodyView);
ControlBodyView.showLightsRoom ();
};
FrameLayout RoomView = new FrameLayout () {
Height = Application.GetRealHeight (140),
Tag = fanModule.ToString () + fanModule.DeviceID.ToString () + fanModule.LoopID.ToString ()
};
RoomListScrolView.AddChidren (RoomView);
RoomView.MouseUpEventHandler += openCurtainControlPageEvent;
var tempDeviceName = new Button () {
Height = Application.GetRealHeight (140),
TextAlignment = TextAlignment.CenterLeft,
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
BackgroundColor = SkinStyle.Current.Transparent,
SelectedBackgroundColor = SkinStyle.Current.MainColor,
Padding = new Padding (0, 35, 0, 0),
Text = room.Name + " - " + fanModule.Name,
};
RoomView.AddChidren (tempDeviceName);
tempDeviceName.MouseUpEventHandler += openCurtainControlPageEvent;
Button btnPoint = new Button () {
Width = Application.GetRealWidth (15),
Height = Application.GetRealHeight (15),
X = Application.GetRealWidth (45),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Item/Point.png",
SelectedImagePath = "Item/PointSelected.png",
};
RoomView.AddChidren (btnPoint);
Button btnNull = new Button () {
Y = Application.GetRealHeight (138),
Height = Application.GetRealHeight (5),
BackgroundColor = SkinStyle.Current.MainColor,
};
RoomView.AddChidren (btnNull);
Button btnNull2 = new Button () {
Width = 1,
X = RoomView.Width - 1,
BackgroundColor = 0xFF2f2f2f,
};
RoomView.AddChidren (btnNull2);
Button btnSelected = new Button () {
X = RoomView.Width - 5,
Width = 5,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
BackgroundColor = SkinStyle.Current.Transparent,
};
RoomView.AddChidren (btnSelected);
if (devcieCount == 0) {
tempDeviceName.IsSelected = true;
btnPoint.IsSelected = true;
ControlBodyView = new UserFan (fanModule) {
Width = Application.GetRealWidth (Application.DesignWidth) - bordorView.Width,
Height = Application.GetRealHeight (Application.DesignHeight - 150),
X = bordorView.Right,
Y = bordorView.Y,
};
AddChidren (ControlBodyView);
ControlBodyView.showLightsRoom ();
btnSelected.IsSelected = true;
tempDeviceName.IsSelected = true;
}
devcieCount++;
}
}
}
#endregion
}
public static void UpdataStatus (string updataFlag, byte windSpeed)
{
#region 更新用户主界面灯光点亮总数
Application.RunOnMainThread (() => {
int brighingCount = 0;
foreach (var room in Room.Lists) {
if (room.Name == "") {
continue;
}
foreach (var light in room.DeviceList) {
if (light.Type == DeviceType.FanModule) {
if ((light as FanModule).WindSpeed > 0) {
brighingCount++;
}
}
}
}
UserMiddle.UpdataLightLightingCount (brighingCount, Language.StringByID (R.MyInternationalizationString.Fan));
});
#endregion
if (curView == null) {
return;
}
Application.RunOnMainThread (() => {
while (curView.RoomListScrolView.Decelerating) {
System.Threading.Thread.Sleep (100);
}
for (int i = 0; i < curView.RoomListScrolView.ChildrenCount; i++) {
if (curView.RoomListScrolView.GetChildren (i).GetType () == typeof (RowLayout)) {
var lightRow = (RowLayout)curView.RoomListScrolView.GetChildren (i);
for (int j = 0; j < lightRow.ChildrenCount; j++) {
var btn = (Button)lightRow.GetChildren (j);
var o = btn.Tag;
if (o != null && o.ToString () == updataFlag) {
if (windSpeed == 0) {
btn.IsSelected = false;
} else {
btn.IsSelected = true;
}
}
}
}
}
});
}
void ControlAllFan (bool open)
{
foreach (var room in Room.Lists) {
if (room == null)
continue;
if (room.Name == "") {
continue;
}
foreach (var fanD in room.DeviceList) {
if (fanD.Type == DeviceType.FanModule) {
if (open) {
Control.ControlBytesSend (Command.SetSingleLight, fanD.SubnetID, fanD.DeviceID,
new byte [] { fanD.LoopID, (fanD as FanModule).WindSpeed });
} else {
Control.ControlBytesSend (Command.SetSingleLight, fanD.SubnetID, fanD.DeviceID,
new byte [] { fanD.LoopID, 0 });
}
}
}
}
}
}
}