using System; using SmartHome; using Shared; using Shared.SimpleControl.R; using Shared.SimpleControl; using System.Collections.Generic; using Newtonsoft.Json.Linq; namespace SuperGateWay { public class DeviceStateCondition:FrameLayout { GateWay gateWay; public DeviceStateCondition(){ Tag = "Logic"; } public void Show (GateWay superGateWay) { this.gateWay = superGateWay; 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.devicestate, 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); searchdevice.MouseUpEventHandler += (sender, e) => { refreshDeviceList (superGateWay, () => { Application.RunOnMainThread (() => { RemoveFromParent (); var deviceStateCondition = new DeviceStateCondition (); MainPage.MainFrameLayout.AddChidren (deviceStateCondition); deviceStateCondition.Show (superGateWay); }); }); }; 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.selectdevice, //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); middle.BackgroundColor = 0xff2F2F2F; this.AddChidren (middle); ///没有在线设备不需要往下执行; if (superGateWay.Commons.Count == 0) { return; } ///创建一个string类型列表,添加所有设备类型; List devicemodullist = new List { Language.StringByID(MyInternationalizationString.Lights), Language.StringByID(MyInternationalizationString.Curtains), Language.StringByID(MyInternationalizationString.AC), Language.StringByID(MyInternationalizationString.MusicModel), Language.StringByID(MyInternationalizationString.FoolHeat), Language.StringByID(MyInternationalizationString.ReshAirRead), Language.StringByID(MyInternationalizationString.Button), Language.StringByID(MyInternationalizationString.Sensor), Language.StringByID(MyInternationalizationString.DoorLock), Language.StringByID(MyInternationalizationString.DryContactPanel), }; foreach (var devicetype in devicemodullist) { var deviceRowLayout = new RowLayout { Height = Application.GetRealHeight (100), BackgroundColor = 0xff323232, }; middle.AddChidren (deviceRowLayout); var devicetypename = new Button { Width = Application.GetRealWidth (200), Text = devicetype, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (40), }; deviceRowLayout.AddChidren (devicetypename); var btndeviceback = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550),//525 }; deviceRowLayout.AddChidren (btndeviceback); EventHandler deviicetypeclick = (sender, e) => { List list = new List { }; ///分类显示(例如灯光:{灯光1,灯光2...}) if (devicetype == Language.StringByID (MyInternationalizationString.Lights)) { // btnEquipmentIcon.UnSelectedImagePath = "Item/Light.png"; list.Add (DeviceType.LightDimming); list.Add (DeviceType.LightSwitch); } else if (devicetype == Language.StringByID (MyInternationalizationString.Curtains)) { //btnEquipmentIcon.UnSelectedImagePath = "Curtain/Curtain.png"; list.Add (DeviceType.CurtainModel); list.Add (DeviceType.CurtainRoller); } else if (devicetype == Language.StringByID (MyInternationalizationString.AC)) { //btnEquipmentIcon.UnSelectedImagePath = @"AC/AC.png"; //deviceType = DeviceType.AC; list.Add (DeviceType.HVAC); } else if (devicetype == Language.StringByID (MyInternationalizationString.MusicModel)) { //btnEquipmentIcon.UnSelectedImagePath = "Item/Music.png"; //deviceType = DeviceType.Music; list.Add (DeviceType.MusicModel); } else if (devicetype == Language.StringByID (MyInternationalizationString.FoolHeat)) { // btnEquipmentIcon.UnSelectedImagePath = "FH/FH_Heat.png"; list.Add (DeviceType.FoolHeat); } else if (devicetype == Language.StringByID (MyInternationalizationString.Button)) { //btnEquipmentIcon.UnSelectedImagePath = "Item/Panel.png"; list.Add (DeviceType.MechanicalSwitch); list.Add (DeviceType.AutomaticSwitch); } else if (devicetype == Language.StringByID (MyInternationalizationString.ReshAirRead)) { // btnEquipmentIcon.UnSelectedImagePath = "FreshAir/FreshAir.png"; list.Add (DeviceType.FreshAir); } else if (devicetype == Language.StringByID (MyInternationalizationString.Sensor)) { // btnEquipmentIcon.UnSelectedImagePath = "Sensor/Sensor.png"; list.Add (DeviceType.Sensor); } else if (devicetype == Language.StringByID (MyInternationalizationString.DoorLock)) { list.Add (DeviceType.DoorLock); // btnEquipmentIcon.UnSelectedImagePath = "DoorLockPic/doorLockHomePage.png"; } else if (devicetype == Language.StringByID (MyInternationalizationString.DryContactPanel)) { //btnEquipmentIcon.UnSelectedImagePath = "Item/DryContact.png"; list.Add (DeviceType.DryContact); } MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); var deviceStateTpye = new DeviceStateTpye (); MainPage.MainFrameLayout.AddChidren (deviceStateTpye); deviceStateTpye.Show (list, devicetypename.Text, superGateWay); }); }); }; deviceRowLayout.MouseUpEventHandler += deviicetypeclick; devicetypename.MouseUpEventHandler += deviicetypeclick; btndeviceback.MouseUpEventHandler += deviicetypeclick; } } /// /// 读取所有设备列表 /// async void refreshDeviceList (GateWay superGateWay, Action action) { superGateWay.Commons.Clear (); MainPage.Loading.Start (); await System.Threading.Tasks.Task.Run (() => { try { var uidList = Control.GetDevicesUidList (); if (uidList == null) { return; } foreach (var uid in uidList) { var result = Control.GetDeviceByUID (uid.Replace (".json", "")); if (result == null) { continue; } // result = "{\"module\":\"multi\",\"Name\":\"混合模块\",\"uid\":\"45678941\",\"objects\":[{\"name\":\"空调1\",\"type\":\"air_conditioner\",\"function\":[{\"sid\":\"1001560506000001\",\"attr\":{\"type\":\"switch\"}},{\"sid\":\"1001560506010001\",\"attr\":{\"type\":\"switch\"}}]},{\"name\":\"空调2\",\"type\":\"air_conditioner\",\"function\":[{\"sid\":\"1001660806000001\",\"attr\":{\"type\":\"switch\"}},{\"sid\":\"1001660806010001\",\"attr\":{\"type\":\"switch\"}}]}]}"; var common = Newtonsoft.Json.JsonConvert.DeserializeObject (result); if (common != null) { foreach (var @object in common.objects) { var functionString = @object ["function"]?.ToString (); if (functionString == null) { continue; } var functions = Newtonsoft.Json.JsonConvert.DeserializeObject> (functionString); if (functions == null) { continue; } foreach (var function in functions) { var device = SuperCommon.GetCommon (function.sid, superGateWay); if (device != null) { //前找出当前回路的对象有没有存在 var dev = superGateWay.Commons.Find ((c) => c.Type == device.Type && c.CommonLoopID == device.CommonLoopID); if (dev == null) { superGateWay.Commons.Add (device); if (@object ["name"] != null) { device.Name = @object ["name"]?.ToString (); } else { device.Name = ""; } superGateWay.save ("DeviceListFilePath"); } if (function.sid != null) { device.functions.Add (function); } } } } } } } catch { } finally { Application.RunOnMainThread (() => { action (); }); } }); MainPage.Loading.Hide (); } } }