using System;
|
using System.Collections.Generic;
|
using Newtonsoft.Json.Linq;
|
using Shared;
|
using Shared.SimpleControl;
|
using Shared.SimpleControl.R;
|
using SmartHome;
|
namespace SuperGateWay
|
{
|
public class AddScenePage : FrameLayout
|
{
|
GateWay gateWay;
|
Button beforeClickButton = new Button ();
|
Scene scene = null;
|
public AddScenePage ()
|
{
|
Tag = "Logic";
|
}
|
public void Show (GateWay gateWay)
|
{
|
this.gateWay = gateWay;
|
|
|
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 {
|
//Text = "添加场景",
|
TextID = MyInternationalizationString.addscene,
|
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 ();
|
};
|
|
var searchdevice = new Button {
|
Width = Application.GetMinRealAverage (60),
|
Height = Application.GetMinRealAverage (80),
|
X = Application.GetRealWidth (550),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/seekdevice.png",
|
};
|
topFrameLayout.AddChidren (searchdevice);
|
|
var tetleframeLayout = new FrameLayout {
|
Y = topFrameLayout.Bottom,
|
Height = Application.GetRealHeight (100),
|
BackgroundColor = 0xff0f0f0f,
|
};
|
AddChidren (tetleframeLayout);
|
|
var tetlebtn = new Button {
|
Width = Application.GetRealWidth (200),
|
TextID = MyInternationalizationString.selectscene,
|
//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);
|
|
var btncomplete = new Button {
|
Y = middle.Bottom,
|
Height = Application.GetRealHeight (80),
|
TextID = MyInternationalizationString.complete,
|
TextSize=16,
|
};
|
AddChidren (btncomplete);
|
|
|
if (gateWay.Scenes.Count == 0) {
|
///刷新场景界面的方法
|
middle.RemoveAll ();
|
refreshscenelist (() => {
|
///刷新场景界面的方法
|
refreshsceneView (middle);
|
});
|
} else {
|
///刷新场景界面的方法
|
refreshsceneView (middle);
|
}
|
///读取场景图标点击事件
|
searchdevice.MouseUpEventHandler += (sender, e) => {
|
middle.RemoveAll ();
|
scene = null;
|
refreshscenelist (() => {
|
///刷新场景界面的方法
|
refreshsceneView (middle);
|
});
|
};
|
|
Output outputifon = new Output ();
|
Dictionary<string, object> dictionary = new Dictionary<string, object> ();
|
outputifon.objects.Add (dictionary);
|
dictionary.Add ("value", 1);///暂时先默认(因为没有选择设备状态直接按保存会崩溃)
|
|
btncomplete.MouseUpEventHandler += (sedder, e) => {
|
if (gateWay.Scenes.Count == 0 || scene == null) {
|
var alert = new Alert (Language.StringByID (MyInternationalizationString.Prompt),
|
Language.StringByID (MyInternationalizationString.selectlogicscene),
|
Language.StringByID (MyInternationalizationString.OK));
|
alert.Show ();
|
return;
|
}
|
dictionary.Add ("sid",scene.sid);
|
Logic.CurrentLogic.AddOutput (outputifon);
|
// MainPage.MainFrameLayout.RemoveViewByTag ("Logic");
|
var logicCommunalPage = new LogicCommunalPage ();
|
MainPage.MainFrameLayout.AddChidren (logicCommunalPage);
|
logicCommunalPage.Show (gateWay,() => { });
|
};
|
}
|
|
|
/// <summary>
|
/// 获取场景列表以及场景设备信息
|
/// </summary>
|
async void refreshscenelist (Action action)
|
{
|
gateWay.Scenes.Clear ();
|
MainPage.Loading.Start ();
|
await System.Threading.Tasks.Task.Run (() => {
|
try {
|
var tempList = Control.getSceneList ();
|
if (tempList == null) {
|
return;
|
}
|
var array = tempList.ToArray ();
|
Array.Sort (array);
|
foreach (var uid in array) {
|
try {
|
var result = Control.getSceneByUID (uid.Replace (".json", ""));
|
if (result == null) {
|
continue;
|
}
|
var scene = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene> (result);
|
if (scene != null) {
|
scene.SidToDevice ();
|
gateWay.Scenes.Add (scene);
|
}
|
|
} catch { }
|
}
|
} catch { }
|
});
|
MainPage.Loading.Hide ();
|
action ();
|
}
|
|
void refreshsceneView (VerticalScrolViewLayout middle)
|
{
|
|
foreach (var tempScene in gateWay.Scenes) {
|
var deviceRowLayout = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
};
|
middle.AddChidren (deviceRowLayout);
|
|
var btn = new Button {
|
Height = Application.GetRealHeight (100),
|
Width = LayoutParams.MatchParent,
|
SelectedBackgroundColor = 0xfffe5e00,
|
};
|
deviceRowLayout.AddChidren (btn);
|
|
var devicetypename = new Button {
|
Width = Application.GetRealWidth (200),
|
Text = tempScene.name,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (40),
|
//SelectedBackgroundColor = 0xfffe5e00,
|
};
|
deviceRowLayout.AddChidren (devicetypename);
|
|
EventHandler<MouseEventArgs> sceneclick = (sender, e) => {
|
scene = tempScene;
|
beforeClickButton.IsSelected = false;
|
beforeClickButton = btn;
|
btn.IsSelected = true;
|
};
|
|
deviceRowLayout.MouseUpEventHandler += sceneclick;
|
btn.MouseUpEventHandler += sceneclick;
|
devicetypename.MouseUpEventHandler += sceneclick;
|
|
}
|
|
}
|
|
}
|
}
|