using System;
|
using System.Collections.Generic;
|
using Shared;
|
using Shared.SimpleControl;
|
using Shared.SimpleControl.R;
|
using SmartHome;
|
|
namespace SuperGateWay
|
{
|
public class SelectedLogicState : FrameLayout
|
{
|
public SelectedLogicState ()
|
{
|
Tag = "Logic";
|
}
|
public bool IsDeviceEditor;
|
public void Show (GateWay gateWay, Logic logic)
|
{
|
this.BackgroundColor = 0xFF1F1F1F;
|
this.AddChidren (new Button {
|
Height = Application.GetRealHeight (30),
|
});
|
|
var topFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (100),
|
Y = Application.GetRealHeight (30),
|
};
|
AddChidren (topFrameLayout);
|
|
var titleName = new Button {
|
TextID = MyInternationalizationString.automation,
|
TextSize = 17,
|
};
|
topFrameLayout.AddChidren (titleName);
|
|
var back = new Button {
|
Width = Application.GetRealWidth (82),
|
Height = Application.GetRealHeight (89),
|
X = Application.GetRealWidth (10),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/HomepageBack.png",
|
};
|
topFrameLayout.AddChidren (back);
|
back.MouseDownEventHandler += (sender, e) => {
|
RemoveFromParent ();
|
IsDeviceEditor = false;
|
};
|
|
var tetleframeLayout = new FrameLayout {
|
Y = topFrameLayout.Bottom,
|
Height = Application.GetRealHeight (100),
|
BackgroundColor = 0xff0f0f0f,
|
};
|
AddChidren (tetleframeLayout);
|
|
var tetlebtn = new Button {
|
Width = Application.GetRealWidth (400),
|
TextID = MyInternationalizationString.selectsavedautomationstate,
|
//Text = "请选择已保存自动化",
|
TextSize = 16,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (40),
|
};
|
tetleframeLayout.AddChidren (tetlebtn);
|
|
var middle = new VerticalScrolViewLayout ();
|
middle.Y = tetleframeLayout.Bottom;
|
middle.Height = Application.GetRealHeight (Application.DesignHeight - 130 - 100 - 80);
|
middle.BackgroundColor = 0xff2F2F2F;
|
this.AddChidren (middle);
|
|
|
Output outputifon = new Output ();
|
Dictionary<string, object> dictionary = new Dictionary<string, object> ();
|
outputifon.objects.Add (dictionary);
|
dictionary.Add ("sid", logic.sid);
|
|
var openRowLayout = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
};
|
middle.AddChidren (openRowLayout);
|
|
var btnlogicopen = new Button {
|
Width = Application.GetRealWidth (200),
|
TextID = MyInternationalizationString.open1,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (40),
|
};
|
openRowLayout.AddChidren (btnlogicopen);
|
|
string IsselectedLogic = null;
|
var disableRowLayout = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
};
|
middle.AddChidren (disableRowLayout);
|
|
var btnlogicdisable = new Button {
|
Width = Application.GetRealWidth (200),
|
TextID = MyInternationalizationString.disable,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (40),
|
};
|
disableRowLayout.AddChidren (btnlogicdisable);
|
|
///开启点击事件
|
EventHandler<MouseEventArgs> copenclick = (seder, e) => {
|
openRowLayout.BackgroundColor = 0xfffe5e00;
|
disableRowLayout.BackgroundColor = 0x00000000;
|
IsselectedLogic = "true";
|
if (dictionary.ContainsKey ("value")) {
|
dictionary.Remove ("value");
|
}
|
dictionary.Add ("value", 1);
|
};
|
openRowLayout.MouseUpEventHandler += copenclick;
|
btnlogicopen.MouseUpEventHandler += copenclick;
|
|
///禁止点击事件
|
EventHandler<MouseEventArgs> disableclick = (seder, e) => {
|
openRowLayout.BackgroundColor = 0x00000000;
|
disableRowLayout.BackgroundColor = 0xfffe5e00;
|
IsselectedLogic = "false";
|
if (dictionary.ContainsKey ("value")) {
|
dictionary.Remove ("value");
|
}
|
dictionary.Add ("value", 0);
|
};
|
disableRowLayout.MouseUpEventHandler += disableclick;
|
btnlogicdisable.MouseUpEventHandler += disableclick;
|
|
|
if (IsDeviceEditor) {
|
foreach (var deviceoutput in Logic.CurrentLogic.output) {
|
foreach (var device in deviceoutput.objects) {
|
if (!device.ContainsKey ("sid") || device ["sid"]?.ToString () == null) {
|
continue;
|
}
|
var tempSid = device ["sid"]?.ToString ();
|
var value = device ["value"]?.ToString ();
|
//判断SID是否有效的,如果不是有效的当前这个场景数据就不处理
|
Convert.ToUInt64 (tempSid, 16);
|
var sidUlong = Convert.ToUInt64 (tempSid, 16);
|
///1:设备;
|
var type = (byte)((sidUlong >> 60) & 0xF);
|
|
if (type == 3) {
|
if (logic.sid == tempSid) {
|
//Logic当前状态值
|
if (value== "1") {
|
openRowLayout.BackgroundColor = 0xfffe5e00;
|
disableRowLayout.BackgroundColor = 0x00000000;
|
} else {
|
openRowLayout.BackgroundColor = 0x00000000;
|
disableRowLayout.BackgroundColor = 0xfffe5e00;
|
}
|
break;
|
}
|
}
|
}
|
}
|
}
|
|
|
|
var btncomplete = new Button {
|
Y = middle.Bottom,
|
Height = Application.GetRealHeight (80),
|
TextID = MyInternationalizationString.complete,
|
TextSize=16,
|
};
|
AddChidren (btncomplete);
|
|
|
btncomplete.MouseUpEventHandler += (sedder, e) => {
|
if (IsselectedLogic != null) {
|
Logic.CurrentLogic.AddOutput (outputifon);
|
} else {
|
if (!IsDeviceEditor) {
|
var alert = new Alert (Language.StringByID (MyInternationalizationString.Prompt),
|
Language.StringByID (MyInternationalizationString.selectlogiccondition),
|
Language.StringByID (MyInternationalizationString.OK)); alert.Show ();
|
return;
|
}
|
IsDeviceEditor = false;
|
}
|
this.RemoveFromParent ();
|
var logicCommunalPage = new LogicCommunalPage ();
|
MainPage.MainFrameLayout.AddChidren (logicCommunalPage);
|
logicCommunalPage.Show (gateWay, () => { });
|
};
|
}
|
|
}
|
}
|