using System;
using System.Collections.Generic;
using System.Threading;
namespace Shared.SimpleControl.Phone
{
public class UserDeviceToSecurity : FrameLayout
{
///
/// 当前设备界面
///
static UserDeviceToSecurity curView;
VerticalScrolViewLayout equipmentListScrolView;
VerticalScrolViewLayout bodyScrolView;
///
/// 构造函数
///
public UserDeviceToSecurity ()
{
curView = this;
}
public void ShowSecurityView ()
{
#region 标题
var topView = new FrameLayout () {
Y = Application.GetRealHeight (36),
Height = Application.GetRealHeight (90),
BackgroundColor = SkinStyle.Current.MainColor,
};
AddChidren (topView);
var title = new Button () {
TextAlignment = TextAlignment.Center,
Text = Language.StringByID (R.MyInternationalizationString.Security),
TextColor = SkinStyle.Current.TextColor1,
TextSize = 19,
};
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
bodyScrolView = new VerticalScrolViewLayout () {
Height = Application.GetRealHeight (1136 - 126),
Y = Application.GetRealHeight (126),
};
AddChidren (bodyScrolView);
//显示有多少个
var securityModulFiles = IO.FileUtils.ReadFiles ().FindAll ((obj) => obj.Split ('_').Length == 4 && obj.Split ('_') [0] == "Equipment" && obj.Split ('_') [1] == DeviceType.SecurityModule.ToString ());
var securityFiles = IO.FileUtils.ReadFiles ().FindAll ((obj) => obj.Split ('_').Length == 5 && obj.Split ('_') [0] == "Equipment" && obj.Split ('_') [1] == DeviceType.SecurityModule.ToString ());
foreach (var securityFile in securityModulFiles) {
SecurityModul securityDevice = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (securityFile)));
if (securityDevice == null) {
continue;
}
FrameLayout roomView = new FrameLayout () {
Height = Application.GetRealHeight (110),
BackgroundColor = SkinStyle.Current.ViewColor,
Tag = securityDevice.Name
};
bodyScrolView.AddChidren (roomView);
Button btnRoomNull = new Button () {
Height = 1,
SelectedBackgroundColor = SkinStyle.Current.MainColor,
BackgroundColor = SkinStyle.Current.MainColor,
};
bodyScrolView.AddChidren (btnRoomNull);
Button btnPoint = new Button () {
Width = Application.GetRealWidth (10),
Height = Application.GetRealHeight (10),
X = Application.GetRealWidth (50),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Item/Point.png",
SelectedImagePath = "Item/Point.png",
};
roomView.AddChidren (btnPoint);
Button btnRoomName = new Button () {
Text = securityDevice.Name,
X = btnPoint.Right + Application.GetRealWidth (20),
TextAlignment = TextAlignment.CenterLeft,
TextColor = SkinStyle.Current.TextColor1,
SelectedTextColor = SkinStyle.Current.TextColor1,
};
roomView.AddChidren (btnRoomName);
btnRoomName.MouseUpEventHandler += (sender, e) => {
UserSecurityPage usp = new UserSecurityPage (securityDevice);
UserMiddle.DevicePageView.AddChidren (usp);
usp.ShowSecurityArea ();
UserMiddle.DevicePageView.PageIndex = 2;
};
}
#region
FrameLayout ShowAllView = new FrameLayout () {
Height = Application.GetRealHeight (85),
BackgroundColor = SkinStyle.Current.MainColor,
};
bodyScrolView.AddChidren (ShowAllView);
Button btnShowAll = new Button () {
X = Application.GetRealWidth (20),
TextAlignment = TextAlignment.CenterLeft,
Text = Language.StringByID (R.MyInternationalizationString.AreaList),
TextColor = SkinStyle.Current.TextColor1,
SelectedTextColor = SkinStyle.Current.TextColor1
};
ShowAllView.AddChidren (btnShowAll);
Button downSelectedButton = new Button () {
X = Application.GetRealWidth (550),
Height = Application.GetRealHeight (50),
Width = Application.GetRealWidth (55),
UnSelectedImagePath = "Item/Down.png",
SelectedImagePath = "Item/DownSelected.png",
Gravity = Gravity.CenterVertical,
IsSelected = true,
};
ShowAllView.AddChidren (downSelectedButton);
//显示出所有的灯
equipmentListScrolView = new VerticalScrolViewLayout () {
Height = bodyScrolView.Height - ShowAllView.Height,
};
bodyScrolView.AddChidren (equipmentListScrolView);
int LightCount = 0;
EventHandler eHandler = (sender, e) => {
btnShowAll.IsSelected = !btnShowAll.IsSelected;
downSelectedButton.IsSelected = btnShowAll.IsSelected;
UserConfig.Instance.SaveUserConfig ();
if (btnShowAll.IsSelected) {
equipmentListScrolView.RemoveAll ();
foreach (var securityModulFile in securityFiles) {
SecurityModul securityDevice = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (securityModulFile)));
if (securityDevice == null) {
continue;
}
LightCount++;
FrameLayout lightView = new FrameLayout () {
Width = Application.GetRealWidth(640),
Height = Application.GetRealHeight (110),
};
lightView.AddTag ("UpdataKey", securityDevice.CommonLoopID);
equipmentListScrolView.AddChidren (lightView);
Button btnLightViewBottomNull = new Button () {
Y = Application.GetRealHeight (107),
Height = Application.GetRealHeight (3),
BackgroundColor = SkinStyle.Current.MainColor,
SelectedBackgroundColor = SkinStyle.Current.MainColor,
};
lightView.AddChidren (btnLightViewBottomNull);
Button btnPoint2 = new Button () {
Width = Application.GetRealWidth (10),
Height = Application.GetRealHeight (10),
X = Application.GetRealWidth (50),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Item/Point.png",
SelectedImagePath = "Item/Point.png",
};
lightView.AddChidren (btnPoint2);
var tempDeviceName = new Button () {
X = btnPoint2.Right + Application.GetRealWidth (20),
TextAlignment = TextAlignment.CenterLeft,
Width = Application.GetRealWidth (640),
Text = securityDevice.Name,
TextColor = SkinStyle.Current.TextColor1,
SelectedTextColor = SkinStyle.Current.TextColor1,
};
lightView.AddChidren (tempDeviceName);
EventHandler eHandler2 = (sender2, e2) => {
UserSecurityAreaPage usap = new UserSecurityAreaPage (securityDevice);
UserMiddle.DevicePageView.AddChidren (usap);
usap.ShowSecurityArea ();
UserMiddle.DevicePageView.PageIndex = 2;
};
tempDeviceName.MouseUpEventHandler += eHandler2;
lightView.MouseUpEventHandler += eHandler2;
btnLightViewBottomNull.MouseUpEventHandler += eHandler2;
}
equipmentListScrolView.Height = LightCount * Application.GetRealHeight (130);
} else {
equipmentListScrolView.Height = 0;
LightCount = 0;
}
};
btnShowAll.MouseUpEventHandler += eHandler;
downSelectedButton.MouseUpEventHandler += eHandler;
//默认是选中状态
eHandler (btnShowAll, new MouseEventArgs ());
#endregion
}
}
}