using System;
|
namespace Shared.SimpleControl.Phone
|
{
|
public class UserDeviceToCurtains : FrameLayout
|
{
|
/// <summary>
|
/// 当前界面
|
/// </summary>
|
static UserDeviceToCurtains curView;
|
VerticalScrolViewLayout equipmentListScrolView;
|
|
|
/// <summary>
|
///构造函数
|
/// </summary>
|
public UserDeviceToCurtains ()
|
{
|
BackgroundColor = SkinStyle.Current.MainColor;
|
}
|
/// <summary>
|
/// 通过设备类型方式选择设备
|
/// </summary>
|
public void showAllRoomCurtain ()
|
{
|
#region 标题
|
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.Curtains),
|
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 (90),
|
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
|
|
#region 全开-全关
|
var powerView = new FrameLayout () {
|
Height = Application.GetRealHeight (110),
|
BackgroundColor = SkinStyle.Current.TitileView,
|
Y = topView.Bottom
|
};
|
AddChidren (powerView);
|
var btnAllON = new Button () {
|
Width = Application.GetRealWidth (320),
|
TextSize = 16,
|
TextID = R.MyInternationalizationString.ALLON,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
powerView.AddChidren (btnAllON);
|
var btnAllOff = new Button () {
|
Width = Application.GetRealWidth (320),
|
X = btnAllON.Right,
|
TextSize = 16,
|
TextID = R.MyInternationalizationString.ALLOFF,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
powerView.AddChidren (btnAllOff);
|
var btnLine = new Button () {
|
Width = 1,
|
BackgroundColor = SkinStyle.Current.White20Transparent,
|
X = btnAllON.Right,
|
};
|
powerView.AddChidren (btnLine);
|
|
#endregion
|
|
equipmentListScrolView = new VerticalScrolViewLayout () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (1136 - 126 - 110),
|
Y = powerView.Bottom,
|
BackgroundColor = SkinStyle.Current.ViewColor
|
};
|
AddChidren (equipmentListScrolView);
|
#region 显示全部的窗帘
|
int devcieCount = 0;
|
|
//显示出所有的窗帘
|
foreach (var room in Room.Lists) {
|
if (string.IsNullOrEmpty(room.Name)) {
|
continue;
|
}
|
foreach (var common in room.DeviceList) {
|
if (common.Type == DeviceType.CurtainModel) {
|
var curtainmodel = common as CurtainModel;
|
devcieCount++;
|
EventHandler<MouseEventArgs> openCurtainControlPageEvent = (button, mouseEventArgs) => {
|
var userCurtainPageView = new UserCurtainPage (curtainmodel, room);
|
UserMiddle.DevicePageView.AddChidren (userCurtainPageView);
|
UserMiddle.DevicePageView.PageIndex = 2;
|
userCurtainPageView.showCurtainsRoom ();
|
};
|
var curtainView = new FrameLayout () {
|
Height = Application.GetRealHeight (130),
|
};
|
curtainView.Tag = curtainmodel;
|
equipmentListScrolView.AddChidren (curtainView);
|
curtainView.MouseUpEventHandler += openCurtainControlPageEvent;
|
Button btnCurtainViewBottomNull = new Button () {
|
Y = Application.GetRealHeight (127),
|
Height = Application.GetRealHeight (3),
|
SelectedBackgroundColor = SkinStyle.Current.MainColor,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
curtainView.AddChidren (btnCurtainViewBottomNull);
|
//窗名
|
var tempDeviceName = new Button () {
|
X = Application.GetRealWidth (30),
|
Height = Application.GetRealHeight (60),
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = room.Name + "-" + curtainmodel.Name,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
curtainView.AddChidren (tempDeviceName);
|
tempDeviceName.MouseUpEventHandler += openCurtainControlPageEvent;
|
|
Button btnCurtain = new Button () {
|
X = Application.GetRealWidth (20),
|
Y = Application.GetRealHeight (40),
|
Width = Application.GetRealWidth (105),
|
Height = Application.GetRealHeight (105),
|
UnSelectedImagePath = "Curtain/curtain1.png",
|
//SelectedImagePath = "Item/RH_CurtainsSelected.png",
|
};
|
curtainView.AddChidren (btnCurtain);
|
btnCurtain.MouseUpEventHandler += openCurtainControlPageEvent;
|
|
var btnOpenCurtain = new Button () {
|
Width = Application.GetMinRealAverage (100),
|
Height = Application.GetMinRealAverage (100),
|
X = Application.GetRealWidth (280),
|
Y = Application.GetRealHeight (35),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Curtain/CurtainOpen.png",
|
SelectedImagePath = "Curtain/CurtainOpenSelected.png",
|
Tag = CurtainStatus.Open
|
};
|
curtainView.AddChidren (btnOpenCurtain);
|
|
var btnStopCurtain = new Button () {
|
Width = Application.GetMinRealAverage (100),
|
Height = Application.GetMinRealAverage (100),
|
X = Application.GetRealWidth (400),
|
Y = Application.GetRealHeight (35),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Curtain/CurtainTimeOut.png",
|
SelectedImagePath = "Curtain/CurtainTimeOutSelected.png",
|
Tag = CurtainStatus.Stop
|
};
|
curtainView.AddChidren (btnStopCurtain);
|
|
var btnCloseCurtain = new Button () {
|
Width = Application.GetMinRealAverage (100),
|
Height = Application.GetMinRealAverage (100),
|
X = Application.GetRealWidth (520),
|
Y = Application.GetRealHeight (35),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Curtain/CurtainClose.png",
|
SelectedImagePath = "Curtain/CurtainCloseSelected.png",
|
Tag = CurtainStatus.Close
|
};
|
curtainView.AddChidren (btnCloseCurtain);
|
|
btnCloseCurtain.MouseDownEventHandler += (sender3, e3) => {
|
Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainmodel.SubnetID, curtainmodel.DeviceID, new byte [] { curtainmodel.LoopID, 2 });
|
(sender3 as Button).IsSelected = true;
|
};
|
btnCloseCurtain.MouseUpEventHandler += (sender3, e3) => {
|
(sender3 as Button).IsSelected = false;
|
};
|
btnOpenCurtain.MouseDownEventHandler += (sender3, e3) => {
|
Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainmodel.SubnetID, curtainmodel.DeviceID, new byte [] { curtainmodel.LoopID, 1 });
|
(sender3 as Button).IsSelected = true;
|
};
|
btnOpenCurtain.MouseUpEventHandler += (sender3, e3) => {
|
(sender3 as Button).IsSelected = false;
|
};
|
btnStopCurtain.MouseDownEventHandler += (sender3, e3) => {
|
Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainmodel.SubnetID, curtainmodel.DeviceID, new byte [] { curtainmodel.LoopID, 0 });
|
(sender3 as Button).IsSelected = true;
|
};
|
btnStopCurtain.MouseUpEventHandler += (sender3, e3) => {
|
(sender3 as Button).IsSelected = false;
|
};
|
|
}
|
//foreach (var common in room.DeviceList) {
|
if (common.Type == DeviceType.CurtainRoller) {
|
var curtainroller = common as CurtainRoller;
|
devcieCount++;
|
EventHandler<MouseEventArgs> openCurtainControlPageEvent = (button, mouseEventArgs) => {
|
var userCurtainPageView = new UserCurtainPage (curtainroller, room);
|
UserMiddle.DevicePageView.AddChidren (userCurtainPageView);
|
UserMiddle.DevicePageView.PageIndex = 2;
|
userCurtainPageView.showCurtainsRoom ();
|
};
|
var curtainView = new FrameLayout () {
|
Height = Application.GetRealHeight (130),
|
};
|
curtainView.Tag = curtainroller;
|
equipmentListScrolView.AddChidren (curtainView);
|
curtainView.MouseUpEventHandler += openCurtainControlPageEvent;
|
Button btnCurtainViewBottomNull = new Button () {
|
Y = Application.GetRealHeight (127),
|
Height = Application.GetRealHeight (3),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
SelectedBackgroundColor = SkinStyle.Current.MainColor,
|
};
|
curtainView.AddChidren (btnCurtainViewBottomNull);
|
|
//窗名
|
var tempDeviceName = new Button () {
|
X = Application.GetRealWidth (30),
|
Height = Application.GetRealHeight (60),
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = room.Name + "-" + curtainroller.Name,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
curtainView.AddChidren (tempDeviceName);
|
tempDeviceName.MouseUpEventHandler += openCurtainControlPageEvent;
|
|
Button btnCurtain = new Button () {
|
X = Application.GetRealWidth (25),
|
Y = Application.GetRealHeight (40),
|
Width = Application.GetRealWidth (105),
|
Height = Application.GetRealHeight (105),
|
UnSelectedImagePath = "Curtain/rollerCurtain.png",
|
//SelectedImagePath = "Item/RH_CurtainsSelected.png",
|
};
|
curtainView.AddChidren (btnCurtain);
|
btnCurtain.MouseUpEventHandler += openCurtainControlPageEvent;
|
|
var btnOpenCurtain = new Button () {
|
Width = Application.GetMinRealAverage (100),
|
Height = Application.GetMinRealAverage (100),
|
X = Application.GetRealWidth (280),
|
Y = Application.GetRealHeight (35),
|
UnSelectedImagePath = "Curtain/CurtainRollerUp.png",
|
SelectedImagePath = "Curtain/CurtainRollerUpOn.png",
|
Tag = CurtainStatus.Open
|
};
|
curtainView.AddChidren (btnOpenCurtain);
|
|
var btnStopCurtain = new Button () {
|
Width = Application.GetMinRealAverage (100),
|
Height = Application.GetMinRealAverage (100),
|
X = Application.GetRealWidth (400),
|
Y = Application.GetRealHeight (35),
|
UnSelectedImagePath = "Curtain/CurtainTimeOut.png",
|
SelectedImagePath = "Curtain/CurtainTimeOutSelected.png",
|
Tag = CurtainStatus.Stop
|
};
|
curtainView.AddChidren (btnStopCurtain);
|
|
var btnCloseCurtain = new Button () {
|
Width = Application.GetMinRealAverage (100),
|
Height = Application.GetMinRealAverage (100),
|
X = Application.GetRealWidth (520),
|
Y = Application.GetRealHeight (35),
|
UnSelectedImagePath = "Curtain/CurtainRollerDown.png",
|
SelectedImagePath = "Curtain/CurtainRollerDownOn.png",
|
Tag = CurtainStatus.Close
|
};
|
curtainView.AddChidren (btnCloseCurtain);
|
|
btnCloseCurtain.MouseDownEventHandler += (sender3, e3) => {
|
Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainroller.SubnetID, curtainroller.DeviceID, new byte [] { 1, 2 });
|
(sender3 as Button).IsSelected = true;
|
};
|
btnCloseCurtain.MouseUpEventHandler += (sender3, e3) => {
|
(sender3 as Button).IsSelected = false;
|
};
|
btnOpenCurtain.MouseDownEventHandler += (sender3, e3) => {
|
Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainroller.SubnetID, curtainroller.DeviceID, new byte [] { 1, 1 });
|
(sender3 as Button).IsSelected = true;
|
};
|
btnOpenCurtain.MouseUpEventHandler += (sender3, e3) => {
|
(sender3 as Button).IsSelected = false;
|
};
|
btnStopCurtain.MouseDownEventHandler += (sender3, e3) => {
|
Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainroller.SubnetID, curtainroller.DeviceID, new byte [] { 1, 0 });
|
(sender3 as Button).IsSelected = true;
|
};
|
btnStopCurtain.MouseUpEventHandler += (sender3, e3) => {
|
(sender3 as Button).IsSelected = false;
|
};
|
|
}
|
//foreach (var common in room.DeviceList) {
|
if (common.Type == DeviceType.CurtainTrietex) {
|
var curtaintrietex = common as CurtainTrietex;
|
devcieCount++;
|
EventHandler<MouseEventArgs> openCurtainControlPageEvent = (button, mouseEventArgs) => {
|
var userCurtainPageView = new UserCurtainPage (curtaintrietex, room);
|
UserMiddle.DevicePageView.AddChidren (userCurtainPageView);
|
UserMiddle.DevicePageView.PageIndex = 2;
|
userCurtainPageView.showCurtainsRoom ();
|
};
|
var curtainView = new FrameLayout () {
|
Height = Application.GetRealHeight (130),
|
};
|
curtainView.Tag = curtaintrietex;
|
equipmentListScrolView.AddChidren (curtainView);
|
curtainView.MouseUpEventHandler += openCurtainControlPageEvent;
|
Button btnCurtainViewBottomNull = new Button () {
|
Y = Application.GetRealHeight (127),
|
Height = Application.GetRealHeight (3),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
SelectedBackgroundColor = SkinStyle.Current.MainColor,
|
};
|
curtainView.AddChidren (btnCurtainViewBottomNull);
|
|
//窗名
|
var tempDeviceName = new Button () {
|
X = Application.GetRealWidth (30),
|
Height = Application.GetRealHeight (60),
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = room.Name + "-" + curtaintrietex.Name,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
curtainView.AddChidren (tempDeviceName);
|
|
Button btnCurtain = new Button () {
|
X = Application.GetRealWidth (22),
|
Y = Application.GetRealHeight (40),
|
Width = Application.GetRealWidth (105),
|
Height = Application.GetRealHeight (105),
|
UnSelectedImagePath = "Curtain/curtain1.png",
|
//SelectedImagePath = "Item/RH_CurtainsSelected.png",
|
};
|
curtainView.AddChidren (btnCurtain);
|
btnCurtain.MouseUpEventHandler += openCurtainControlPageEvent;
|
|
var btnOpenCurtain = new Button () {
|
Width = Application.GetMinRealAverage (100),
|
Height = Application.GetMinRealAverage (100),
|
X = Application.GetRealWidth (280),
|
Y = Application.GetRealHeight (35),
|
UnSelectedImagePath = "Curtain/CurtainOpen.png",
|
SelectedImagePath = "Curtain/CurtainOpenSelected.png",
|
Tag = CurtainStatus.Open
|
};
|
curtainView.AddChidren (btnOpenCurtain);
|
|
var btnStopCurtain = new Button () {
|
Width = Application.GetMinRealAverage (100),
|
Height = Application.GetMinRealAverage (100),
|
X = Application.GetRealWidth (400),
|
Y = Application.GetRealHeight (35),
|
UnSelectedImagePath = "Curtain/CurtainTimeOut.png",
|
SelectedImagePath = "Curtain/CurtainTimeOutSelected.png",
|
Tag = CurtainStatus.Stop
|
};
|
curtainView.AddChidren (btnStopCurtain);
|
|
var btnCloseCurtain = new Button () {
|
Width = Application.GetMinRealAverage (100),
|
Height = Application.GetMinRealAverage (100),
|
X = Application.GetRealWidth (520),
|
Y = Application.GetRealHeight (35),
|
UnSelectedImagePath = "Curtain/CurtainClose.png",
|
SelectedImagePath = "Curtain/CurtainCloseSelected.png",
|
Tag = CurtainStatus.Close
|
};
|
curtainView.AddChidren (btnCloseCurtain);
|
|
btnCloseCurtain.MouseDownEventHandler += (sender3, e3) => {
|
Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtaintrietex.SubnetID, curtaintrietex.DeviceID, new byte [] { 1, 2 });
|
(sender3 as Button).IsSelected = true;
|
};
|
btnCloseCurtain.MouseUpEventHandler += (sender3, e3) => {
|
(sender3 as Button).IsSelected = false;
|
};
|
btnOpenCurtain.MouseDownEventHandler += (sender3, e3) => {
|
Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtaintrietex.SubnetID, curtaintrietex.DeviceID, new byte [] { 1, 1 });
|
(sender3 as Button).IsSelected = true;
|
};
|
btnOpenCurtain.MouseUpEventHandler += (sender3, e3) => {
|
(sender3 as Button).IsSelected = false;
|
};
|
btnStopCurtain.MouseDownEventHandler += (sender3, e3) => {
|
Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtaintrietex.SubnetID, curtaintrietex.DeviceID, new byte [] { 1, 0 });
|
(sender3 as Button).IsSelected = true;
|
};
|
btnStopCurtain.MouseUpEventHandler += (sender3, e3) => {
|
(sender3 as Button).IsSelected = false;
|
};
|
}
|
}
|
}
|
#endregion
|
curView = this;
|
|
if (devcieCount > 0) {
|
btnAllON.MouseUpEventHandler += (sender, e) => {
|
btnAllON.TextColor = SkinStyle.Current.SelectedColor;
|
btnAllOff.TextColor = SkinStyle.Current.TextColor1;
|
Alert alert = new Alert ("",
|
Language.StringByID (R.MyInternationalizationString.SureOpenAllCurtian),
|
Language.StringByID (R.MyInternationalizationString.Cancel),
|
Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.Show ();
|
alert.ResultEventHandler += (sender2, e2) => {
|
if (e2) {
|
|
controlAllCurtain (1);
|
}
|
};
|
};
|
btnAllON.MouseDownEventHandler += (dd, ff) => {
|
|
};
|
btnAllOff.MouseUpEventHandler += (sender, e) => {
|
btnAllON.TextColor = SkinStyle.Current.TextColor1;
|
btnAllOff.TextColor = SkinStyle.Current.SelectedColor;
|
Alert alert = new Alert ("",
|
Language.StringByID (R.MyInternationalizationString.SureCloseAllCurtian),
|
Language.StringByID (R.MyInternationalizationString.Cancel),
|
Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.Show ();
|
alert.ResultEventHandler += (sender2, e2) => {
|
if (e2) {
|
controlAllCurtain (2);
|
}
|
};
|
};
|
}
|
}
|
|
/// <summary>
|
/// 控制所有窗帘
|
/// </summary>
|
/// <param name="status">1:开,2:关.</param>
|
void controlAllCurtain (byte status)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
foreach (var room in Room.Lists) {
|
if (room == null)
|
continue;
|
if (string.IsNullOrEmpty(room.Name)) {
|
continue;
|
}
|
foreach (var common in room.DeviceList) {
|
if (common.Type == DeviceType.CurtainModel) {
|
var curtainmodel = common as CurtainModel;
|
Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, curtainmodel.SubnetID, curtainmodel.DeviceID, new byte [] { curtainmodel.LoopID, status });
|
} else if (common.Type == DeviceType.CurtainRoller) {
|
var curtainroller = common as CurtainRoller;
|
Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, curtainroller.SubnetID, curtainroller.DeviceID, new byte [] { curtainroller.LoopID, status });
|
} else if (common.Type == DeviceType.CurtainTrietex) {
|
var curtaintrietex = common as CurtainTrietex;
|
Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, curtaintrietex.SubnetID, curtaintrietex.DeviceID, new byte [] { curtaintrietex.LoopID, status });
|
}
|
}
|
}
|
});
|
}
|
|
/// <summary>
|
/// 读取设备状态
|
/// </summary>
|
static void readAllStatus ()
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
System.Collections.Generic.List<string> readList = new System.Collections.Generic.List<string> ();
|
foreach (Room room in Room.Lists) {
|
var list = room.DeviceList.FindAll ((obj) => {
|
return obj.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now && (obj.Type == DeviceType.CurtainModel || obj.Type == DeviceType.CurtainRoller || obj.Type == DeviceType.CurtainTrietex);
|
});
|
foreach (Common common in list) {
|
var s = common.Type + "_" + common.SubnetID + "_" + common.DeviceID + "_" + common.LoopID;
|
//已经读取过当前设备就不再读取
|
if (readList.Contains (s)) {
|
continue;
|
}
|
|
if (common.Type == DeviceType.CurtainModel) {
|
var curtainModel = common as CurtainModel;
|
readList.Add (s);
|
Control.ControlBytesSend (Command.ReadCurtainStatus, curtainModel.SubnetID, curtainModel.DeviceID, new byte [] { curtainModel.LoopID });
|
}
|
if (common.Type == DeviceType.CurtainRoller) {
|
var curtainroller = common as CurtainRoller;
|
readList.Add (s);
|
Control.ControlBytesSend (Command.ReadCurtainStatus, curtainroller.SubnetID, curtainroller.DeviceID, new byte [] { 17 });
|
}
|
if (common.Type == DeviceType.CurtainTrietex) {
|
var curtaintrietex = common as CurtainTrietex;
|
readList.Add (s);
|
Control.ControlBytesSend (Command.ReadCurtainStatus, curtaintrietex.SubnetID, curtaintrietex.DeviceID, new byte [] { 17 });
|
}
|
}
|
}
|
});
|
}
|
}
|
}
|