using System; using System.Collections.Generic; using Shared.SimpleControl.Phone.Music; namespace Shared.SimpleControl.Pad {/// /// 用户界面的中间块 /// public static class UserMiddle { /// /// 不可滚动的父窗体 /// public static readonly FrameLayout FrameLayoutMain = new FrameLayout () { Height = Application.GetRealHeight (Application.DesignHeight - 150), Y = Application.GetRealHeight (150), BackgroundColor = 0xFF000000 }; /// /// 可滚动的用户view,加入到不可滚动的父窗体,当y不为0是,则有一行标题栏会一直显示在父窗体之上,要重新设置高度 /// public static readonly VerticalScrolViewLayout VerticalScrolView_InUserMiddleView = new VerticalScrolViewLayout (); /// /// 初始化用户界面 /// /// The user middle view. public static void Init () { if (null != FrameLayoutMain.Parent) { return; } MainPage.LoginUser = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (UserInfo.GlobalRegisterFile))); if(MainPage.LoginUser == null){ MainPage.LoginUser = new UserInfo (); MainPage.LoginUser.SaveUserInfo (); } UserHomePage.FrameLayoutMain.AddChidren (FrameLayoutMain); FrameLayoutMain.AddChidren (VerticalScrolView_InUserMiddleView); //默认以设备显示方式 DeviceMode (); //MainPage.LoginUser = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (UserInfo.GlobalRegisterFile))); } public static void Refresh () { } /// /// 设备到房间模式的加载界面方法 /// /// The 1. public static void DeviceMode () { Room.InitAllRoom (); VerticalScrolView_InUserMiddleView.RemoveAll (); VerticalScrolView_InUserMiddleView.Y = 0; //VerticalScrolView_InUserMiddleView.Height = Application.GetRealHeight (1010); //要显示的设备类型先在这里加进文本选择 List deviceTypes = new List (){ Language.StringByID (R.MyInternationalizationString.AC), Language.StringByID (R.MyInternationalizationString.Lights), Language.StringByID (R.MyInternationalizationString.Curtain), Language.StringByID (R.MyInternationalizationString.Scenes), Language.StringByID (R.MyInternationalizationString.FoolHeat), Language.StringByID(R.MyInternationalizationString.Monitor), //Language.StringByID (R.MyInternationalizationString.Security), Language.StringByID (R.MyInternationalizationString.TV), Language.StringByID (R.MyInternationalizationString.Music), Language.StringByID (R.MyInternationalizationString.ElectricalControl), Language.StringByID (R.MyInternationalizationString.Fan) //Language.StringByID(R.MyInternationalizationString.Projector), }; foreach (int hideTypes in UserConfig.Instance.HideDeviceTypes) { string hideTypeString = Language.StringByID (hideTypes); deviceTypes.Remove (hideTypeString); } Button btnrow = new Button () { Height = Application.GetRealHeight (30), }; VerticalScrolView_InUserMiddleView.AddChidren (btnrow); FrameLayout rowLayout = null; for (int i = 0; i < deviceTypes.Count; i++) { if (i % 3 == 0) { rowLayout = new FrameLayout () { Height = Application.GetRealWidth (400), //Height = Application.GetRealHeight (Convert.ToInt32(400 * MainPage.HeightProportion)), //Height =Convert.ToInt32(400 * MainPage.HeightProportion), }; VerticalScrolView_InUserMiddleView.AddChidren (rowLayout); Button btnrow2 = new Button () { Height = Application.GetRealHeight (40), }; VerticalScrolView_InUserMiddleView.AddChidren (btnrow2); } FrameLayout equipmentLayout = new FrameLayout () { X = Application.GetRealWidth (75), Width = Application.GetRealWidth (600), }; equipmentLayout.AddTag ("DeviceType", deviceTypes [i]); rowLayout.AddChidren (equipmentLayout); if (i % 3 == 1) { equipmentLayout.X = Application.GetRealWidth (720); } else if (i % 3 == 2) { equipmentLayout.X = Application.GetRealWidth (1370); } Button btnEquipmentIcon = new Button () { Width = Application.GetRealWidth (240), Height = Application.GetRealHeight (260), Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight (40), }; equipmentLayout.AddChidren (btnEquipmentIcon); Button btnEquipmentName = new Button () { Width = Application.GetRealWidth (232), Height = Application.GetRealHeight (50), Gravity = Gravity.CenterHorizontal, Y = btnEquipmentIcon.Bottom, Text = deviceTypes [i], Enable = false, }; equipmentLayout.AddChidren (btnEquipmentName); Button btnOpenNumber = new Button () { Width = Application.GetRealWidth (80), Height = Application.GetRealHeight (55), X = Application.GetRealWidth (448), Y = Application.GetRealHeight (50), UnSelectedImagePath = "Item/LightingCount.png", SelectedImagePath = "Item/LightingCountSelected.png", Enable = false, Text = "0", TextAlignment = TextAlignment.Center, }; btnOpenNumber.AddTag ("DeviceType", deviceTypes [i]); equipmentLayout.AddChidren (btnOpenNumber); setEquipmentsBackGroud (deviceTypes [i], btnEquipmentIcon, equipmentLayout, btnOpenNumber, equipmentLayout); } UserDeviceToLight.readAllStatus (); UserDeviceToSocket.readAllStatus (); UserDeviceToAC.readAllStatus (); } public static void UpdataLightLightingCount (int count, string tagFalg) { try { for (int i = 0; i < VerticalScrolView_InUserMiddleView.ChildrenCount; i++) { if (VerticalScrolView_InUserMiddleView.GetChildren (i).GetType () == typeof (FrameLayout)) { FrameLayout rowView = (FrameLayout)VerticalScrolView_InUserMiddleView.GetChildren (i); for (int j = 0; j < rowView.ChildrenCount; j++) { if (rowView.GetChildren (j).GetType () == typeof (FrameLayout)) { FrameLayout frameView = (FrameLayout)rowView.GetChildren (j); if (frameView.GetTagByKey ("DeviceType").ToString () == tagFalg) { for (int k = 0; k < frameView.ChildrenCount; k++) { if (frameView.GetChildren (k).GetType () == typeof (Button)) { Button btn = (Button)frameView.GetChildren (k); if (btn.GetTagByKey ("DeviceType") != null && btn.GetTagByKey ("DeviceType").ToString () == tagFalg && count > 0) { Application.RunOnMainThread (() => { btn.Text = count.ToString (); btn.IsSelected = true; }); } else if (btn.GetTagByKey ("DeviceType") != null && btn.GetTagByKey ("DeviceType").ToString () == tagFalg && count == 0) { Application.RunOnMainThread (() => { try { int eCount = 0; foreach (var room in Room.Lists) { if (room.Name == "") { continue; } if (tagFalg == Language.StringByID (R.MyInternationalizationString.Lights)) { var devices = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.LightDimming || obj.Type == DeviceType.LightSwitch || obj.Type == DeviceType.LightRGB || obj.Type == DeviceType.LightMixDimming || obj.Type == DeviceType.LightMixSwitch; }); eCount += devices.Count; } else if (tagFalg == Language.StringByID (R.MyInternationalizationString.AC)) { var devices = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.HVAC || obj.Type == DeviceType.ACInfrared || obj.Type == DeviceType.ACPanel; }); eCount += devices.Count; } else if (tagFalg == Language.StringByID (R.MyInternationalizationString.ElectricalControl)) { var devices = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.LightSwitchSocket || obj.Type == DeviceType.LightEnergySwitch; }); eCount += devices.Count; } else if (tagFalg == Language.StringByID (R.MyInternationalizationString.Fan)) { var devices = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.FanModule; }); eCount += devices.Count; } } btn.Text = eCount.ToString (); btn.IsSelected = false; } catch (Exception ex) { Console.WriteLine ("更新主界面角标异常2:" + ex.Message.ToString ()); //new Alert ("Eorr", "主线程更新角标2异常 :" + ex.Message, "Close").Show (); } }); } } } return; } } } } } } catch (Exception ex) { Application.RunOnMainThread (() => { Console.WriteLine ("更新主界面角标异常:" + ex.Message.ToString ()); //new Alert ("Eorr", "更新主界面角标异常:" + ex.Message.ToString (), "Close").Show (); }); } } static void DelUserEquipmentView (int deviceCount, int deviceType) { if (deviceCount == 0) { Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.DeleteDeviceCategories), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.Show (); alert.ResultEventHandler += (sender2, e2) => { if (e2) { UserConfig.Instance.HideDeviceTypes.Add (deviceType); UserConfig.Instance.SaveUserConfig (); DeviceMode (); } }; } } /// /// 设备到房间模式显示用户主界面的 /// static void setEquipmentsBackGroud (string equipmentType, Button btnEquipment, FrameLayout fl, Button btnOpenNumber, FrameLayout equipmentLayout) { if (equipmentType == Shared.Language.StringByID (R.MyInternationalizationString.Lights)) { btnEquipment.UnSelectedImagePath = "Item/Light.png"; btnEquipment.SelectedImagePath = "Item/LightSelected.png"; int eCount = 0; foreach (var room in Room.Lists) { if (room.Name == "") { continue; } var devices = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.LightDimming || obj.Type == DeviceType.LightSwitch || obj.Type == DeviceType.LightRGB; }); eCount += devices.Count; } btnOpenNumber.Text = eCount.ToString (); btnEquipment.MouseUpEventHandler += (sender, e) => { new UserDeviceToLight ().Show (); }; fl.MouseUpEventHandler += (sender, e) => { new UserDeviceToLight ().Show (); }; btnEquipment.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.Lights); }; fl.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.Lights); }; equipmentLayout.BackgroundImagePath = "Item/LightBackground.png"; } else if (equipmentType == Shared.Language.StringByID (R.MyInternationalizationString.AC)) { btnEquipment.UnSelectedImagePath = "AC/AC.png"; btnEquipment.SelectedImagePath = "AC/ACSelected.png"; int eCount = 0; foreach (var room in Room.Lists) { if (room.Name == "") { continue; } var devices = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.HVAC || obj.Type == DeviceType.ACInfrared || obj.Type == DeviceType.ACPanel; }); eCount += devices.Count; } btnOpenNumber.Text = eCount.ToString (); btnEquipment.MouseUpEventHandler += (sender, e) => { new UserDeviceToAC ().Show (); }; fl.MouseUpEventHandler += (sender, e) => { new UserDeviceToAC ().Show (); }; btnEquipment.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.AC); }; fl.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.AC); }; equipmentLayout.BackgroundImagePath = "AC/ACBackground.png"; } else if (equipmentType == Shared.Language.StringByID (R.MyInternationalizationString.TV)) { btnEquipment.UnSelectedImagePath = "Item/TV.png"; btnEquipment.SelectedImagePath = "Item/TVSelected.png"; int eCount = 0; foreach (var room in Room.Lists) { if (room.Name == "") { continue; } var devices = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.InfraredMode && ((InfraredMode)obj).InfraredType == InfraredType.TV; }); eCount += devices.Count; } btnOpenNumber.Text = eCount.ToString (); btnEquipment.MouseUpEventHandler += (sender, e) => { new UserDeviceToTV ().Show (); }; fl.MouseUpEventHandler += (sender, e) => { new UserDeviceToTV ().Show (); }; btnEquipment.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.TV); }; fl.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.TV); }; equipmentLayout.BackgroundImagePath = "Item/TVBackground.png"; } else if (equipmentType == Shared.Language.StringByID (R.MyInternationalizationString.Curtain)) { btnEquipment.UnSelectedImagePath = "Curtain/Curtain.png"; //btnEquipment.SelectedImagePath = "Item/CurtainSelected.png"; int eCount = 0; foreach (var room in Room.Lists) { if (room.Name == "") { continue; } var devices = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.CurtainModel || obj.Type == DeviceType.CurtainRoller || obj.Type == DeviceType.CurtainTrietex; }); eCount += devices.Count; } btnOpenNumber.Text = eCount.ToString (); btnEquipment.MouseUpEventHandler += (sender, e) => { new Pad.UserDeviceToCurtains ().Show (); }; fl.MouseUpEventHandler += (sender, e) => { new Pad.UserDeviceToCurtains ().Show (); }; btnEquipment.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.Curtain); }; fl.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.Curtain); }; equipmentLayout.BackgroundImagePath = "Curtain/CurtainBackground.png"; } else if (equipmentType == Shared.Language.StringByID (R.MyInternationalizationString.Scenes)) { btnEquipment.UnSelectedImagePath = "Scene/Scene.png"; int eCount = 0; foreach (var room in Room.Lists) { if (room.Name == "") { continue; } if (room != null) { foreach (var sceneFilePath in room.SceneFilePathList) { var scene = Scene.GetSceneByFilePath (sceneFilePath); if (scene != null) eCount += scene.LoopCount; } } } var globalSceneList = Newtonsoft.Json.JsonConvert.DeserializeObject> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (Scene.GlobalSceneFilePath))); if (globalSceneList != null) { foreach (var sceneFilePath in globalSceneList) { var scene = Scene.GetSceneByFilePath (sceneFilePath); eCount += scene.LoopCount; } } btnOpenNumber.Text = eCount.ToString (); btnEquipment.MouseUpEventHandler += (sender, e) => { //场景-房间 Room.InitAllRoom (); new Pad.UserDeviceToScene ().Show (); }; fl.MouseUpEventHandler += (sender, e) => { Room.InitAllRoom (); new Pad.UserDeviceToScene ().Show (); }; equipmentLayout.BackgroundImagePath = "Item/SceneBackground.png"; } else if (equipmentType == Shared.Language.StringByID (R.MyInternationalizationString.Music)) { btnEquipment.UnSelectedImagePath = "Item/Music.png"; btnEquipment.SelectedImagePath = "Item/MusicSelected.png"; int eCount = 0; foreach (var room in Room.Lists) { if (room.Name == "") { continue; } var devices = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.MusicModel; }); eCount += devices.Count; } btnOpenNumber.Text = eCount.ToString (); btnEquipment.MouseUpEventHandler += (sender, e) => { new UserDeviceToMusic ().ShowRoomMusciList (); }; fl.MouseUpEventHandler += (sender, e) => { new UserDeviceToMusic ().ShowRoomMusciList (); }; btnEquipment.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.Music); }; fl.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.Music); }; equipmentLayout.BackgroundImagePath = "Item/MusicBackground.png"; } else if (equipmentType == Shared.Language.StringByID (R.MyInternationalizationString.Security)) { btnEquipment.UnSelectedImagePath = "Item/Security.png"; btnEquipment.SelectedImagePath = "Item/SecuritySelected.png"; equipmentLayout.BackgroundImagePath = "Item/SecurityBackground.png"; int eCount = 0; foreach (var room in Room.Lists) { if (room.Name == "") { continue; } var devices = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.SecurityPanel || obj.Type == DeviceType.SecurityModule; }); eCount += devices.Count; } btnOpenNumber.Text = eCount.ToString (); btnEquipment.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.Security); }; fl.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.Security); }; } else if (equipmentType == Shared.Language.StringByID (R.MyInternationalizationString.Monitor)) { btnEquipment.UnSelectedImagePath = "Item/Monitor.png"; btnEquipment.SelectedImagePath = "Item/MonitorSelected.png"; //btnEquipment.SelectedImagePath = "Item/SecuritySelected.png"; equipmentLayout.BackgroundImagePath = "Item/SecurityBackground.png"; btnEquipment.MouseUpEventHandler += (sender, e) => { new Pad.MonitorType ().Show (); }; fl.MouseUpEventHandler += (sender, e) => { new Pad.MonitorType ().Show (); }; btnOpenNumber.Text = MonitorInfo.FilePathList.Count.ToString (); //btnEquipment.MouseLongEventHandler += (sender, e) => { // DelUserEquipmentView (eCount, R.MyInternationalizationString.Monitor); //}; //fl.MouseLongEventHandler += (sender, e) => { // DelUserEquipmentView (eCount, R.MyInternationalizationString.Monitor); //}; } else if (equipmentType == Shared.Language.StringByID (R.MyInternationalizationString.Projector)) { btnEquipment.UnSelectedImagePath = "Item/Projector.png"; btnEquipment.SelectedImagePath = "Item/ProjectorSelected.png"; } else if (equipmentType == Shared.Language.StringByID (R.MyInternationalizationString.FoolHeat)) { btnEquipment.UnSelectedImagePath = "Item/FloorHeating.png"; btnEquipment.SelectedImagePath = "Item/FloorHeatingSelected.png"; int eCount = 0; foreach (var room in Room.Lists) { if (room.Name == "") { continue; } var devices = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.FoolHeat; }); eCount += devices.Count; } btnOpenNumber.Text = eCount.ToString (); btnEquipment.MouseUpEventHandler += (sender, e) => { new UserDeviceToFH ().Show (); }; fl.MouseUpEventHandler += (sender, e) => { new UserDeviceToFH ().Show (); }; btnEquipment.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.FoolHeat); }; fl.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.FoolHeat); }; equipmentLayout.BackgroundImagePath = "Item/FloorHeatingBackground.png"; } else if (equipmentType == Shared.Language.StringByID (R.MyInternationalizationString.ElectricalControl)) { btnEquipment.UnSelectedImagePath = "Light/Socket.png"; btnEquipment.SelectedImagePath = "Light/SocketOn.png"; equipmentLayout.BackgroundImagePath = "Light/SocketBackground.png"; int eCount = 0; foreach (var room in Room.Lists) { if (room.Name == "") { continue; } var devices = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.LightSwitchSocket || obj.Type == DeviceType.LightEnergySwitch; }); eCount += devices.Count; } btnOpenNumber.Text = eCount.ToString (); btnEquipment.MouseUpEventHandler += (sender, e) => { new UserDeviceToSocket ().Show (); }; fl.MouseUpEventHandler += (sender, e) => { new UserDeviceToSocket ().Show (); }; btnEquipment.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.ElectricalControl); }; fl.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.ElectricalControl); }; } else if (equipmentType == Shared.Language.StringByID (R.MyInternationalizationString.Fan)) { btnEquipment.UnSelectedImagePath = "Fan/Fan.png"; btnEquipment.SelectedImagePath = "Fan/FanOn.png"; equipmentLayout.BackgroundImagePath = "Fan/FanBackground.png"; int eCount = 0; foreach (var room in Room.Lists) { if (room.Name == "") { continue; } var devices = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.FanModule; }); eCount += devices.Count; } btnOpenNumber.Text = eCount.ToString (); btnEquipment.MouseUpEventHandler += (sender, e) => { new UserDeviceToFan ().Show (); }; fl.MouseUpEventHandler += (sender, e) => { new UserDeviceToFan ().Show (); }; btnEquipment.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.Fan); }; fl.MouseLongEventHandler += (sender, e) => { DelUserEquipmentView (eCount, R.MyInternationalizationString.Fan); }; } } } }