using System;
|
using System.Collections.Generic;
|
using Shared;
|
using Shared.Common;
|
using Shared.Phone;
|
using Shared.R;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.Device.Logic
|
{
|
public class SelectedLogicState : FrameLayout
|
{
|
public SelectedLogicState ()
|
{
|
Tag = "Logic";
|
}
|
public bool IsDeviceEditor;
|
Dictionary<string,object> actionsInfo = new Dictionary<string, object>();
|
public void Show (Common.Logic currlogicIfon)
|
{
|
this.BackgroundColor = ZigbeeColor.Current.LogicTopViewBackgroundColor;
|
this.AddChidren (new Button {
|
Height = Application.GetRealHeight (80),
|
});
|
|
var topFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (140),
|
Y = Application.GetRealHeight (80),
|
};
|
AddChidren (topFrameLayout);
|
|
var titleName = new Button {
|
TextID = MyInternationalizationString.automation,
|
TextSize = 16,
|
TextColor = ZigbeeColor.Current.LogicTextBlackColor,
|
IsBold = true,
|
};
|
topFrameLayout.AddChidren (titleName);
|
|
var back = new Button {
|
Width = Application.GetRealWidth (110),
|
Height = Application.GetRealHeight (110),
|
X = Application.GetRealWidth (20),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "ZigeeLogic/Back.png",
|
};
|
topFrameLayout.AddChidren (back);
|
back.MouseDownEventHandler += (sender, e) => {
|
RemoveFromParent ();
|
IsDeviceEditor = false;
|
};
|
|
var tetleframeLayout = new FrameLayout {
|
Y = topFrameLayout.Bottom,
|
Height = Application.GetRealHeight (180),
|
//BackgroundColor = 0xff0f0f0f,
|
};
|
AddChidren (tetleframeLayout);
|
|
var tetlebtn = new Button {
|
Width = Application.GetRealWidth (600),
|
TextID = MyInternationalizationString.selectsavedautomationstate,
|
//Text = "请选择已保存自动化",
|
TextSize = 16,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (40),
|
TextColor = ZigbeeColor.Current.LogicTextBlackColor,
|
};
|
tetleframeLayout.AddChidren (tetlebtn);
|
|
var middle = new VerticalScrolViewLayout ();
|
middle.Y = tetleframeLayout.Bottom;
|
middle.Height = Application.GetRealHeight (1920 - 220 - 180 - 174);
|
middle.BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor;
|
this.AddChidren (middle);
|
|
|
|
|
|
var openRowLayout = new RowLayout {
|
Height = Application.GetRealHeight (180),
|
};
|
middle.AddChidren (openRowLayout);
|
|
var btnlogicopen = new Button {
|
Width = Application.GetRealWidth (600),
|
TextID = MyInternationalizationString.open1,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (40),
|
TextColor = ZigbeeColor.Current.LogicTextBlackColor,
|
};
|
openRowLayout.AddChidren (btnlogicopen);
|
|
string IsselectedLogic = null;
|
var disableRowLayout = new RowLayout {
|
Height = Application.GetRealHeight (180),
|
};
|
middle.AddChidren (disableRowLayout);
|
|
var btnlogicdisable = new Button {
|
Width = Application.GetRealWidth (600),
|
TextID = MyInternationalizationString.disable,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (40),
|
TextColor = ZigbeeColor.Current.LogicTextBlackColor,
|
|
};
|
disableRowLayout.AddChidren (btnlogicdisable);
|
|
///开启点击事件
|
EventHandler<MouseEventArgs> copenclick = (seder, e) => {
|
openRowLayout.BackgroundColor = 0xfffe5e00;
|
disableRowLayout.BackgroundColor = 0x00000000;
|
IsselectedLogic = "true";
|
if(actionsInfo.ContainsKey("EnableLogic")){
|
actionsInfo.Remove("EnableLogic");
|
}
|
actionsInfo.Add("EnableLogic",1);
|
|
};
|
openRowLayout.MouseUpEventHandler += copenclick;
|
btnlogicopen.MouseUpEventHandler += copenclick;
|
|
///禁止点击事件
|
EventHandler<MouseEventArgs> disableclick = (seder, e) =>
|
{
|
openRowLayout.BackgroundColor = 0x00000000;
|
disableRowLayout.BackgroundColor = 0xfffe5e00;
|
IsselectedLogic = "false";
|
if (actionsInfo.ContainsKey("EnableLogic"))
|
{
|
actionsInfo.Remove("EnableLogic");
|
}
|
actionsInfo.Add("EnableLogic", 0);
|
};
|
disableRowLayout.MouseUpEventHandler += disableclick;
|
btnlogicdisable.MouseUpEventHandler += disableclick;
|
|
if(IsDeviceEditor){
|
foreach (var actions in Common.Logic.CurrentLogic.Actions)
|
{
|
if (currlogicIfon.LogicId.ToString()==actions["DeviceAddr"].ToString() && actions["LinkType"].ToString() == "4")
|
{
|
if (actions["EnableLogic"].ToString()== "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 (174),
|
TextID = MyInternationalizationString.complete,
|
TextSize=16,
|
TextColor = ZigbeeColor.Current.LogicTextBlackColor,
|
};
|
AddChidren (btncomplete);
|
|
if (actionsInfo.ContainsKey("DeviceAddr"))
|
{
|
actionsInfo.Remove("DeviceAddr");
|
}
|
if (actionsInfo.ContainsKey("LinkType"))
|
{
|
actionsInfo.Remove("LinkType");
|
}
|
actionsInfo.Add("DeviceAddr", currlogicIfon.LogicId);
|
actionsInfo.Add("LinkType", 4);
|
|
btncomplete.MouseUpEventHandler += (sedder, e) => {
|
if (IsselectedLogic != null) {
|
LogicIfon.AddLogicactions(currlogicIfon,actionsInfo);
|
} else {
|
if (!IsDeviceEditor) {
|
var alert = new Alert (Language.StringByID (MyInternationalizationString.Prompt),
|
Language.StringByID (MyInternationalizationString.selectlogiccondition),
|
Language.StringByID(MyInternationalizationString.complete));
|
alert.Show ();
|
return;
|
}
|
IsDeviceEditor = false;
|
}
|
this.RemoveFromParent ();
|
var logicCommunalPage = new LogicCommunalPage ();
|
UserView.HomePage.Instance.AddChidren (logicCommunalPage);
|
UserView.HomePage.Instance.PageIndex += 1;
|
logicCommunalPage.Show (() => { });
|
};
|
}
|
|
}
|
}
|