using Shared.SimpleControl.Phone;
using System;
using Shared;
using System.Collections.Generic;
/*
2017-02-10 :去掉房间里面的新增修改场景,改为在用户节目新增修改
*/
namespace Shared.SimpleControl.Pad
{
public class SystemRoom
{
///
/// 显示房间列表界面
///
public void ShowRoomList ()
{
SystemMiddle.FristScrolView.RemoveAll ();
SystemMiddle.SecondScrolView.RemoveAll ();
SystemMiddle.ThirdScrolView.RemoveAll ();
foreach (var roomFilePath in Room.FilePathList) {
if(roomFilePath == Room.FavoriteRoom)
{
continue;
}
RowLayout frameLayout = new RowLayout () {
Height = Application.GetRealHeight (131),
};
EventHandler roomEvent = (sender, e) => {
SystemMiddle.FristScrolView.SelectedInVerticalScrolViewFrameLayoutButton (roomFilePath);
ShowRoom (roomFilePath);
ShowDevcieListView (roomFilePath);
};
frameLayout.MouseUpEventHandler += roomEvent;
SystemMiddle.FristScrolView.AddChidren (frameLayout);
var btnDelFile = new Button () {
TextID = R.MyInternationalizationString.Del,
BackgroundColor = SkinStyle.Current.DelColor
};
btnDelFile.MouseUpEventHandler += (sender, e) => {//删除房间确认
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipDeleteRoomMessage), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
alert.ResultEventHandler += (object sender2, bool e2) => {
if (e2) {
Room.Remove (roomFilePath);
ShowRoomList ();
}
};
alert.Show ();
};
frameLayout.AddRightView (btnDelFile);
Button btnIcon = new Button () {
Width = Application.GetRealHeight (13),
Height = Application.GetRealHeight (13),
X = Application.GetRealWidth (40),
UnSelectedImagePath = "Item/Point.png",
SelectedImagePath = "Item/PointSelected.png",
Gravity = Gravity.CenterVertical,
Tag = roomFilePath
};
frameLayout.AddChidren (btnIcon);
Button btnName = new Button () {
Width = Application.GetRealWidth (342),
Height = LayoutParams.MatchParent,
Text = roomFilePath.Split ('_') [1],
TextAlignment = TextAlignment.CenterLeft,
X = btnIcon.X + btnIcon.Width + Application.GetRealWidth (20),
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
Tag = roomFilePath
};
frameLayout.AddChidren (btnName);
btnName.MouseUpEventHandler += roomEvent;
frameLayout.MouseUpEventHandler += roomEvent;
Button btnNul = new Button () {
Y = Application.GetRealHeight (131) - 2,
Height = 1,
BackgroundColor = SkinStyle.Current.MainColor,
};
frameLayout.AddChidren (btnNul);
Button btnNull = new Button () {
Y = Application.GetRealHeight (131) - 1,
Height = 1,
BackgroundColor = 0xFF2f2f2f,
};
frameLayout.AddChidren (btnNull);
}
// top
Button btnTopButton = new Button () {
TextID = R.MyInternationalizationString.AddNewRoom,
TextSize = 16
};
SystemMiddle.FristScrolView.TitleView.AddChidren (btnTopButton);
btnTopButton.MouseUpEventHandler += (sender, e) => {
SystemRoomScenesMethod.AddOrUpdateRoomForPad (ShowRoomList, null, "");
};
}
///
/// 显示指定房间界面
///
public void ShowRoom (string roomFilePath)
{
MainPage.Loading.Start ("Loading...");
System.Threading.Tasks.Task.Run (() => {
Application.RunOnMainThread (() => {
Room.InitAllRoom ();
Room room = Room.GetRoomByFilePath (roomFilePath);
if (room == null)
return;
SystemMiddle.SecondScrolView.RemoveAll ();
#region top
EditText textButton = new EditText () {
X = Application.GetRealWidth (40),
Height = Application.GetRealHeight (50),
Width = Application.GetRealWidth (400),
Text = roomFilePath.Split ('_') [1],
Gravity = Gravity.CenterVertical,
TextAlignment = TextAlignment.CenterLeft,
SelectedBackgroundColor = 0xFF000000,
Enable = false,
TextSize = 16,
};
SystemMiddle.SecondScrolView.TitleView.AddChidren (textButton);
Button editor = new Button () {
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (70),
UnSelectedImagePath = "Item/Editor.png",
SelectedImagePath = "Item/EditorSelected.png",
Gravity = Gravity.CenterVertical,
X = Application.GetRealWidth (550),
};
SystemMiddle.SecondScrolView.TitleView.AddChidren (editor);
editor.MouseUpEventHandler += (sender, e) => {
if (editor.IsSelected) {
} else {
SystemRoomScenesMethod.AddOrUpdateRoomForPad (ShowRoomList, ShowRoom, roomFilePath, ShowDevcieListView);
}
};
#endregion
//显示已经添加进房间的设备
foreach (string deviceFilePath in room.DeviceFilePathList) {
initEquipmentsBase (deviceFilePath, roomFilePath);
}
MainPage.Loading.Hide ();
});
});
}
void initEquipmentsBase (string deviceFilePath,string roomFilePath)
{
if (!deviceFilePath.StartsWith ("Equipment_")) {
return;
}
if (deviceFilePath.Split ('_') [1] == DeviceType.FanModule.ToString ()) {
#region 风扇
FanModule fanModule = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (
IO.FileUtils.ReadFile (deviceFilePath)));
if (fanModule == null)
return;
initEquipments (fanModule.Name, roomFilePath, "Fan/Fan.png", deviceFilePath);
#endregion
} else if (deviceFilePath.Split ('_') [1] == DeviceType.LightDimming.ToString () || deviceFilePath.Split ('_') [1] == DeviceType.LightMixDimming.ToString ()) {
#region 调光器
LightDimming dimming = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (
IO.FileUtils.ReadFile (deviceFilePath)));
if (dimming == null)
return;
initEquipments (dimming.Name, roomFilePath, "Item/Light.png", deviceFilePath);
#endregion
} else if (deviceFilePath.Split ('_') [1] == DeviceType.LightRGB.ToString ()) {
#region RGB
LightLogic rgbLight = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (
IO.FileUtils.ReadFile (deviceFilePath)));
if (rgbLight == null)
return;
initEquipments (rgbLight.Name, roomFilePath, "Item/Light.png", deviceFilePath);
#endregion
} else if (deviceFilePath.Split ('_') [1] == DeviceType.LightSwitch.ToString () || deviceFilePath.Split ('_') [1] == DeviceType.LightMixSwitch.ToString ()
|| deviceFilePath.Split ('_') [1] == DeviceType.LightEnergySwitch.ToString ()) {
#region 继电器
LightSwitch switchLight = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (
IO.FileUtils.ReadFile (deviceFilePath)));
if (switchLight == null)
return;
initEquipments (switchLight.Name, roomFilePath, "Item/Light.png", deviceFilePath);
#endregion
} else if (deviceFilePath.Split ('_') [1] == DeviceType.CurtainModel.ToString ()) {
#region 窗帘
CurtainModel curtain = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (
IO.FileUtils.ReadFile (deviceFilePath)));
if (curtain == null)
return;
initEquipments (curtain.Name, roomFilePath, "Curtain/Curtain.png", deviceFilePath);
#endregion
} else if (deviceFilePath.Split ('_') [1] == DeviceType.CurtainTrietex.ToString ()) {
#region 开合帘窗帘
CurtainTrietex curtain = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (
IO.FileUtils.ReadFile (deviceFilePath)));
if (curtain == null)
return;
initEquipments (curtain.Name, roomFilePath, "Curtain/Curtain.png", deviceFilePath);
#endregion
} else if (deviceFilePath.Split ('_') [1] == DeviceType.CurtainRoller.ToString ()) {
#region 卷帘
CurtainRoller curtain = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (
IO.FileUtils.ReadFile (deviceFilePath)));
if (curtain == null)
return;
initEquipments (curtain.Name, roomFilePath, "Curtain/Curtain.png", deviceFilePath);
#endregion
} else if (deviceFilePath.Split ('_') [1] == DeviceType.MusicModel.ToString ()) {
#region 音乐模块
MusicModel musicMode = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (
IO.FileUtils.ReadFile (deviceFilePath)));
if (musicMode == null)
return;
string loopID = (Convert.ToInt32 (musicMode.LoopID) < 10 ? "0" + musicMode.LoopID.ToString () : musicMode.LoopID.ToString ());
initEquipments (musicMode.Name, roomFilePath, "Item/Music.png", deviceFilePath);
#endregion
} else if (deviceFilePath.Split ('_') [1] == DeviceType.HVAC.ToString ()) {
#region AC
HVAC acHost = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (
IO.FileUtils.ReadFile (deviceFilePath)));
if (acHost == null)
return;
initEquipments (acHost.Name, roomFilePath, @"AC/AC.png", deviceFilePath);
} else if (deviceFilePath.Split ('_') [1] == typeof (ACInfrared).Name) {
ACInfrared acHost = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (
IO.FileUtils.ReadFile (deviceFilePath)));
if (acHost == null)
return;
initEquipments (acHost.Name, roomFilePath, @"AC/AC.png", deviceFilePath);
#endregion
} else if (deviceFilePath.Split ('_') [1] == DeviceType.FoolHeat.ToString ()) {
#region 地热模块
FoolHeat th = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (
IO.FileUtils.ReadFile (deviceFilePath)));
if (th == null)
return;
initEquipments (th.Name, roomFilePath, @"Item/FloorHeating.png", deviceFilePath);
#endregion
} else if (deviceFilePath.Split ('_') [1] == DeviceType.DryContact.ToString ()) {
#region 干接点
DryContact dc = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (
IO.FileUtils.ReadFile (deviceFilePath)));
if (dc == null)
return;
initEquipments (dc.Name, roomFilePath, "Item/DryContact.png", deviceFilePath);
#endregion
} else if (deviceFilePath.Split ('_') [1] == DeviceType.InfraredMode.ToString ()) {
#region 红外电视
try {
InfraredMode infraredTV = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
if (infraredTV != null)
Console.WriteLine (infraredTV.InfraredType);
if (infraredTV.InfraredType == InfraredType.TV) {
initEquipments (infraredTV.Name, roomFilePath, "Item/InfraredTV.png", deviceFilePath);
}
} catch (Exception ex) {
Console.WriteLine (ex.ToString ());
return;
}
#endregion
}
}
///
/// 显示设备的方法
///
void initEquipments (string remark, string roomFilePath, string iconPath, string deviceFilePath)
{
RowLayout frameLayout2 = new RowLayout () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (131),
Tag = deviceFilePath
};
SystemMiddle.SecondScrolView.AddChidren (frameLayout2);
Button btnIcon = new Button () {
Width = Application.GetRealHeight (60),
Height = Application.GetRealHeight (60),
X = Application.GetRealWidth (30),
UnSelectedImagePath = iconPath,
Gravity = Gravity.CenterVertical
};
frameLayout2.AddChidren (btnIcon);
Button btnName = new Button () {
Width = Application.GetRealWidth (342),
Height = LayoutParams.MatchParent,
Text = remark,
TextAlignment = TextAlignment.CenterLeft,
X = btnIcon.X + btnIcon.Width + Application.GetRealWidth (10),
};
frameLayout2.AddChidren (btnName);
Button btnRight = new Button () {
Width = Application.GetRealWidth (28),
Height = Application.GetRealHeight (40),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Item/Right.png",
SelectedImagePath = "Item/RightSelected.png",
};
btnRight.X = frameLayout2.Width - btnRight.Width - Application.GetRealWidth (20);
Button btnDelFile = new Button () {
TextID = R.MyInternationalizationString.Del,
BackgroundColor = SkinStyle.Current.DelColor,
};
frameLayout2.AddRightView (btnDelFile);
btnDelFile.MouseUpEventHandler += (sender, e) => {
Room room = Room.GetRoomByFilePath (roomFilePath);
if (room == null)
return;
room.DeviceFilePathList.Remove (deviceFilePath);
room.Save (roomFilePath);
ShowRoomList ();
};
Button btnNul = new Button () {
Y = Application.GetRealHeight (131) - 2,
Height = 1,
BackgroundColor = SkinStyle.Current.MainColor,
};
frameLayout2.AddChidren (btnNul);
Button btnNull = new Button () {
Y = Application.GetRealHeight (131) - 1,
Height = 1,
BackgroundColor = 0xFF2f2f2f,
};
frameLayout2.AddChidren (btnNull);
}
void ShowDevcieListView (string roomFilePath)
{
SystemMiddle.ThirdScrolView.RemoveAll ();
FrameLayout dropDownLayout = new FrameLayout ();
SystemMiddle.ThirdScrolView.TitleView.AddChidren (dropDownLayout);
Button btnEquipmentIcon = new Button () {
Width = Application.GetRealHeight (65),
Height = Application.GetRealHeight (65),
UnSelectedImagePath = "Item/PointBig.png",
X = Application.GetRealWidth (10),
Gravity = Gravity.CenterVertical,
};
dropDownLayout.AddChidren (btnEquipmentIcon);
FrameLayout DeviceListView = new FrameLayout ();
SystemMiddle.ThirdScrolView.AddChidren (DeviceListView);
Button btnEquipmentType = new Button () {
Height = Application.GetRealHeight (70),
X = btnEquipmentIcon.Right + Application.GetRealWidth (20),
Gravity = Gravity.CenterVertical,
TextAlignment = TextAlignment.CenterLeft,
Text = Language.StringByID (R.MyInternationalizationString.All),
TextSize = 16
};
dropDownLayout.AddChidren (btnEquipmentType);
//存放设备的view
VerticalScrolViewLayout DeviceListScrolView = new VerticalScrolViewLayout ();
DeviceListView.AddChidren (DeviceListScrolView);
FrameLayout inScrolView_DeviceListView = new FrameLayout ();
DeviceListScrolView.AddChidren (inScrolView_DeviceListView);
// ---显示在本地找到的所有设备---
initAllLocalEquipment (roomFilePath,inScrolView_DeviceListView);
VerticalScrolViewLayout typeLayout = new VerticalScrolViewLayout () {
Height = 0,
};
DeviceListView.AddChidren (typeLayout);
#region ---Add Device Dialog---
btnEquipmentType.MouseUpEventHandler += (sender33, e55) => {
//下拉列表的数据源(选项为设备类型有关)
List typeTemp = new List{
Language.StringByID(R.MyInternationalizationString.All),
Language.StringByID(R.MyInternationalizationString.Lights),
Language.StringByID(R.MyInternationalizationString.Curtains),
Language.StringByID(R.MyInternationalizationString.AC),
Language.StringByID(R.MyInternationalizationString.FoolHeat),
Language.StringByID(R.MyInternationalizationString.TV),
Language.StringByID(R.MyInternationalizationString.ElectricalControl),
Language.StringByID(R.MyInternationalizationString.Fan),
Language.StringByID (R.MyInternationalizationString.MusicModel)
};
//如果当前显示的是所有的设备,就隐藏
if (DeviceListScrolView.Height != 0) {
DeviceListScrolView.Height = 0;
typeLayout.Height = Application.GetRealHeight (1080);
if (typeLayout.ChildrenCount != 0) {
return;
}
foreach (string typeName in typeTemp) {
FrameLayout typeDropDownLayout1 = new FrameLayout () {
Height = Application.GetRealHeight (131),
};
typeLayout.AddChidren (typeDropDownLayout1);
Button btnEquipmentIcon2 = new Button () {
Width = Application.GetRealHeight (65),
Height = Application.GetRealHeight (65),
X = Application.GetRealWidth (40),
UnSelectedImagePath = "Item/PointBig.png",
Gravity = Gravity.CenterVertical,
};
typeDropDownLayout1.AddChidren (btnEquipmentIcon2);
Button btnTypeName = new Button () {
Width = Application.GetRealHeight (500),
X = btnEquipmentIcon.Right + Application.GetRealWidth (10),
Text = typeName,
TextAlignment = TextAlignment.CenterLeft,
Gravity = Gravity.CenterVertical,
};
typeDropDownLayout1.AddChidren (btnTypeName);
EventHandler typeEvent = (sender1, e1) => {
typeLayout.Height = 0;
DeviceListScrolView.Height = Application.GetRealHeight (1080);
btnEquipmentType.Text = typeName;
string deviceType = typeName;
if (typeName == Language.StringByID (R.MyInternationalizationString.Lights)) {
btnEquipmentIcon.UnSelectedImagePath = "Item/Light.png";
deviceType = "Light";
} else if (typeName == Language.StringByID (R.MyInternationalizationString.Curtains)) {
btnEquipmentIcon.UnSelectedImagePath = "Curtain/Curtain.png";
deviceType = "Curtain";
} else if (typeName == Language.StringByID (R.MyInternationalizationString.AC)) {
btnEquipmentIcon.UnSelectedImagePath = "AC/AC.png";
deviceType = "AC";
} else if (typeName == Language.StringByID (R.MyInternationalizationString.FoolHeat)) {
btnEquipmentIcon.UnSelectedImagePath = "Item/FloorHeating.png";
deviceType = "FoolHeat";
} else if (typeName == Language.StringByID (R.MyInternationalizationString.DryContactPanel)) {
btnEquipmentIcon.UnSelectedImagePath = "Item/DryContact.png";
deviceType = "DryContact";
} else if (typeName == Language.StringByID (R.MyInternationalizationString.MusicModel)) {
btnEquipmentIcon.UnSelectedImagePath = "Item/Music.png";
deviceType = "Music";
} else if (typeName == Language.StringByID (R.MyInternationalizationString.InfraredMode)) {
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredTV.png";
deviceType = "InfraredMode";
} else if (typeName == Language.StringByID (R.MyInternationalizationString.TV)) {
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredTV.png";
deviceType = "InfraredMode";
} else if (typeName == Language.StringByID (R.MyInternationalizationString.ElectricalControl)) {
btnEquipmentIcon.UnSelectedImagePath = "Light/Socket.png";
deviceType = "EC";//电器控制
} else if (typeName == Language.StringByID (R.MyInternationalizationString.Fan)) {
btnEquipmentIcon.UnSelectedImagePath = "Fan/Fan.png";
deviceType = "Fan";
} else if (typeName == Language.StringByID (R.MyInternationalizationString.LogicModule)) {
btnEquipmentIcon.UnSelectedImagePath = "Item/PointBig.png";
deviceType = "LogicModule";
} else {
btnEquipmentIcon.UnSelectedImagePath = "Item/LogicModule.png";
deviceType = "All";
}
initAllLocalEquipment (roomFilePath, inScrolView_DeviceListView, deviceType);
};
typeDropDownLayout1.MouseUpEventHandler += typeEvent;
btnTypeName.MouseUpEventHandler += typeEvent;
btnEquipmentIcon2.MouseUpEventHandler += typeEvent;
Button btnNul = new Button () {
Y = Application.GetRealHeight (131) - 2,
Height = 1,
BackgroundColor = SkinStyle.Current.MainColor,
};
typeDropDownLayout1.AddChidren (btnNul);
Button btnNull = new Button () {
Y = Application.GetRealHeight (131) - 1,
Height = 1,
BackgroundColor = 0xFF2f2f2f,
};
typeDropDownLayout1.AddChidren (btnNull);
}
} else {
typeLayout.Height = Application.GetRealHeight (0);
DeviceListScrolView.Height = Application.GetRealHeight (1080);
}
};
#endregion
}
///
/// 显示在本地找到的所有设备
///
void initAllLocalEquipment (string roomFilePath,FrameLayout inScrolView_DeviceListView, string selectedDeviceType = null)
{
var filesList = IO.FileUtils.ReadFiles ();
inScrolView_DeviceListView.RemoveAll ();
var room = Room.GetRoomByFilePath (roomFilePath);
int btnEquipmentIndex = 0;
//找出需要显示的设备
var localEquipments = filesList.FindAll ((obj) => {
string [] str = obj.Split ('_');
return obj.StartsWith ("Equipment_") && str.Length == 5
&& (str [1] == DeviceType.LightSwitch.ToString () || str [1] == DeviceType.LightDimming.ToString () || str [1] == DeviceType.LightRGB.ToString ()
|| str [1] == DeviceType.LightMixSwitch.ToString () || str [1] == DeviceType.LightMixDimming.ToString () || str [1] == DeviceType.LightEnergySwitch.ToString ()
|| str [1] == DeviceType.CurtainModel.ToString () || str [1] == DeviceType.CurtainRoller.ToString ()
|| str [1] == DeviceType.CurtainTrietex.ToString ()
|| str [1] == DeviceType.ACInfrared.ToString ()
|| str [1] == DeviceType.HVAC.ToString ()
|| str [1] == DeviceType.FoolHeat.ToString ()
|| str [1] == DeviceType.InfraredMode.ToString ()
|| str [1] == DeviceType.MusicModel.ToString ()
|| str [1] == DeviceType.FanModule.ToString ()
//|| str [1] == DeviceType.LogicModule.ToString ()
);
});
int i = 0;
foreach (string deviceFilePath in localEquipments) {
i++;
string [] str = deviceFilePath.Split ('_');
if (str [4].Length == 2 && str [4] [0] == '0') {
str [4] = str [4] [1].ToString ();
}
if (selectedDeviceType != null && selectedDeviceType != "All") {
//只显示当前选择的设备类型的设备
if (selectedDeviceType == "EC") {
if (str [1].Contains (DeviceType.LightSwitch.ToString ())) {
var b = IO.FileUtils.ReadFile (deviceFilePath);
LightSwitch c = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (b));
if (!c.IsSocket) {
continue;
}
} else
continue;
} else if (selectedDeviceType == "Light") {
if (str [1].Contains (DeviceType.LightSwitch.ToString ())) {
var b = IO.FileUtils.ReadFile (deviceFilePath);
LightSwitch c = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (b));
if (c.IsSocket) {
continue;
}
} else if (!str [1].Contains (selectedDeviceType))
continue;
} else {
if (!str [1].Contains (selectedDeviceType)) {
continue;
}
}
}
var deviceType = str [1];
Button btnEquipment = new Button () {
Width = (inScrolView_DeviceListView.Width - Application.GetRealWidth (70)) / 2,
Height = Application.GetRealHeight (110),
X = Application.GetRealHeight (30),
Y = Application.GetRealHeight (20),
TextAlignment = TextAlignment.Center,
BackgroundColor = 0xFFDBDDDF,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
TextColor = 0xFF000000,
Text = i.ToString ()
};
var commonBytes = IO.FileUtils.ReadFile (deviceFilePath);
if (commonBytes.Length == 0) {
Console.WriteLine ("length loss");
continue;
}
if (commonBytes.Length == 1) {
Console.WriteLine ("length loss 1");
continue;
}
Common commonDevice = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (commonBytes));
if (btnEquipmentIndex < 2) {
btnEquipment.X = btnEquipmentIndex * (btnEquipment.Width + Application.GetRealWidth (25)) + Application.GetRealWidth (20);
btnEquipment.Y = Application.GetRealHeight (30);
btnEquipmentIndex++;
} else {
btnEquipment.X = btnEquipmentIndex % 2 * (btnEquipment.Width + Application.GetRealWidth (25)) + Application.GetRealWidth (20);
btnEquipment.Y = (int)btnEquipmentIndex / 2 * (btnEquipment.Height + Application.GetRealHeight (30)) + Application.GetRealHeight (30);
btnEquipmentIndex++;
}
btnEquipment.Text = commonDevice.Name;
btnEquipment.Tag = deviceFilePath;
inScrolView_DeviceListView.AddChidren (btnEquipment);
if (room.DeviceFilePathList.Contains (btnEquipment.Tag.ToString ())) {
btnEquipment.IsSelected = true;
} else {
foreach (var roomF in Room.Lists) {
if (roomF.DeviceFilePathList.Contains (btnEquipment.Tag.ToString ())) {
btnEquipment.BackgroundColor = 0xFB757575;
}
}
}
btnEquipment.MouseUpEventHandler += (sendere, ee) => {
btnEquipment.IsSelected = !btnEquipment.IsSelected;
if (btnEquipment.IsSelected) {
if (!room.DeviceFilePathList.Contains (btnEquipment.Tag.ToString ())) {
room.DeviceFilePathList.Add (btnEquipment.Tag.ToString ());
}
room.Save (roomFilePath);
initEquipmentsBase (deviceFilePath, roomFilePath);
} else {
room.DeviceFilePathList.Remove (btnEquipment.Tag.ToString ());
this.ShowRoom (roomFilePath);
room.Save (roomFilePath);
}
};
if (btnEquipmentIndex > 14) {
inScrolView_DeviceListView.Height = (btnEquipmentIndex / 2 + 1) * Application.GetRealHeight (150);
} else {
inScrolView_DeviceListView.Height = Application.GetRealHeight (1080);
}
}
}
}
}