using System; using System.Collections.Generic; using Shared; namespace Shared.SimpleControl.Phone { /// /// 加载云端的设备列表 /// public class AlexaSettingDevicePage : Dialog { //List showList = new List (); VerticalScrolViewLayout deviceScrolView; VerticalScrolViewLayout typeLayout; string selectedDeviceType = "All"; /// /// 设备、场景列表 /// List targetInfoList = new List (); int show = 99; FrameLayout bodyView; public AlexaSettingDevicePage (List list) { targetInfoList = new List(list); bodyView = new FrameLayout () { BackgroundColor = SkinStyle.Current.MainColor, }; AddChidren (bodyView); } /// /// /// /// /// public void ShowPage (Action> saveAction) { #region ---TopView--- var topView = new RowLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (640), BackgroundColor = SkinStyle.Current.MainColor, }; bodyView.AddChidren (topView); var back = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { this.Close (); }; Button NameButton = new Button () { Width = Application.GetRealWidth (400), Height = Application.GetMinReal (90), TextID = R.MyInternationalizationString.AddNewDevice, //Text = MainPage.SoftTitle, SelectedTextColor = SkinStyle.Current.TextColor1, TextColor = SkinStyle.Current.TextColor1, Gravity = Gravity.CenterHorizontal, TextAlignment = TextAlignment.Center, TextSize = 19, }; topView.AddChidren (NameButton); #endregion #region type view var chooseTypeView = new RowLayout () { Y = topView.Bottom, Height = Application.GetRealHeight (110), BackgroundColor = SkinStyle.Current.ViewColor, }; bodyView.AddChidren (chooseTypeView); Button btnEquipmentIcon = new Button () { Width = Application.GetRealHeight (65), Height = Application.GetRealHeight (65), UnSelectedImagePath = "Item/LogicModule.png", X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; chooseTypeView.AddChidren (btnEquipmentIcon); Button btnDrodIcon = new Button () { X = Application.GetRealWidth (540), Height = Application.GetRealHeight (46), Width = Application.GetRealWidth (47), UnSelectedImagePath = "Item/Down.png", SelectedImagePath = "Item/DownSelected.png", Gravity = Gravity.CenterVertical, }; chooseTypeView.AddChidren (btnDrodIcon); Button btnEquipmentType = new Button () { Width = Application.GetRealHeight (460), X = btnEquipmentIcon.Right + Application.GetRealWidth (20), TextAlignment = TextAlignment.CenterLeft, Text = Language.StringByID (R.MyInternationalizationString.All), TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.DialogTextColor }; chooseTypeView.AddChidren (btnEquipmentType); typeLayout = new VerticalScrolViewLayout () { Y = chooseTypeView.Bottom, Height = Application.GetRealHeight (0), BackgroundColor = SkinStyle.Current.ViewColor }; //EventHandler chooseTypeMethod = (sender, e) => { // if (show == 99) {//第一次需要先初始化选择设备类型界面 // InitEquipmentTypeView (btnEquipmentType, btnEquipmentIcon, chooseTypeView); // show = 0; // } else if (show == 0) { // typeLayout.Height = Application.GetRealHeight (1136 - 126 - 90); // chooseTypeView.BackgroundColor = SkinStyle.Current.MainColor; // show = 1; // } else if (show == 1) { // typeLayout.Height = 0; // chooseTypeView.BackgroundColor = SkinStyle.Current.ViewColor; // show = 0; // } //}; //btnEquipmentType.MouseUpEventHandler += chooseTypeMethod; //btnDrodIcon.MouseUpEventHandler += chooseTypeMethod; //chooseTypeView.MouseUpEventHandler += chooseTypeMethod; #endregion deviceScrolView = new VerticalScrolViewLayout () { Y = chooseTypeView.Bottom, Height = Application.GetRealHeight (1136 - 126 - 110 - 89), BackgroundColor = SkinStyle.Current.ViewColor, }; bodyView.AddChidren (deviceScrolView); var btnClose = new Button () { Height = Application.GetRealHeight (90), Y = deviceScrolView.Bottom, BackgroundColor = SkinStyle.Current.MainColor, //Text = "OK", TextID = R.MyInternationalizationString.Confrim, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.Center, TextSize = 16, }; bodyView.AddChidren (btnClose); btnClose.MouseUpEventHandler += (sender, e) => { saveAction?.Invoke (targetInfoList); ; this.Close (); }; GetDeviceList (); } /// /// /// void GetDeviceList () { System.Threading.Tasks.Task.Run (() => { try { Application.RunOnMainThread (() => { MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load)); }); var revertObj = HttpServerRequest.Current.GetDeviceList (); if (revertObj.Code == StateCode.SUCCESS) { var devcieFunctionRes = Newtonsoft.Json.JsonConvert.DeserializeObject (revertObj.Data.ToString ()); Application.RunOnMainThread (() => { if (devcieFunctionRes != null && devcieFunctionRes.list != null && devcieFunctionRes.list.Count > 0) { CommonConfig.Current.FunctionList = devcieFunctionRes.list; } else { CommonConfig.Current.FunctionList = new List (); } CommonConfig.Current.Save (); RefreshListView (); }); } else { //提示错误 IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); } } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); } /// /// /// void RefreshListView () { deviceScrolView.RemoveAll (); foreach (Function function in CommonConfig.Current.FunctionList) { //过滤通用开关不允许显示和添加 if (function.spk == SPK.UniversalDevice) continue; AddRowView (function); } } /// /// /// /// void AddRowView (Function function) { var deviceRow = new RowLayout () { Height = Application.GetRealHeight (120), }; deviceScrolView.AddChidren (deviceRow); var btnPoint = new Button () { Width = Application.GetMinRealAverage (10), Height = Application.GetMinRealAverage (10), Radius = (uint)Application.GetMinRealAverage (5), X = Application.GetRealWidth (50), Gravity = Gravity.CenterVertical, BackgroundColor = SkinStyle.Current.TextColor1, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, }; deviceRow.AddChidren (btnPoint); Button btnEquipment = new Button () { X = btnPoint.Right + Application.GetRealWidth (30), Width = Application.GetRealWidth (310), TextAlignment = TextAlignment.CenterLeft, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, SelectedTextColor = SkinStyle.Current.DialogTextColor, TextColor = SkinStyle.Current.TextColor1, Text = function.name, Tag = function.deviceId, }; deviceRow.AddChidren (btnEquipment); //if (selectedDeviceType != "Scene") { // //2020-01-10 隐藏修改按钮 // //return; // var btnEdit = new Button () { // X = btnEquipment.Right + Application.GetRealWidth (80), // Width = Application.GetMinRealAverage (75), // Height = Application.GetMinRealAverage (72), // Gravity = Gravity.CenterVertical, // UnSelectedImagePath = "CrabtreeAdd/Edit.png", // SelectedImagePath = "CrabtreeAdd/EditOn.png", // }; // deviceRow.AddChidren (btnEdit); // btnEdit.MouseUpEventHandler += (sd, ds) => { // //Action successAction = () => { // // GenericDialog.Current.RefreshRemark (commonDevice); // // if (!roomDeviceFilePathList.Contains (filePath)) { // // roomDeviceFilePathList.Add (filePath); // // } // //}; // //GenericDialog.Current.ShowModifyRemarksDialog (commonDevice, commonBytes, btnEquipment, successAction); // }; //} var btnChoose = new Button () { X = Application.GetRealWidth (472 + 80), Width = Application.GetMinRealAverage (75), Height = Application.GetMinRealAverage (72), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "CrabtreeAdd/Choose.png", SelectedImagePath = "CrabtreeAdd/ChooseOn.png", }; deviceRow.AddChidren (btnChoose); var targeDeviceData = targetInfoList.Find ((obj) => obj.targetId == function.deviceId); btnChoose.IsSelected = targeDeviceData != null; btnChoose.MouseUpEventHandler += (sendere, ee) => { btnChoose.IsSelected = !btnChoose.IsSelected; if (btnChoose.IsSelected) { var deviceData = targetInfoList.Find ((obj) => obj.targetId == function.deviceId); if (deviceData == null) { targetInfoList.Add (new TargetInfo () { targetId = function.deviceId, targetName = function.name, isDevice = true }); } } else { var deviceData = targetInfoList.Find ((obj) => obj.targetId == function.deviceId); if (deviceData != null) { targetInfoList.Remove (deviceData); } } }; } void InitEquipmentTypeView (Button btnEquipmentType, Button btnEquipmentIcon, RowLayout chooseTypeView) { bodyView.AddChidren (typeLayout); //下拉列表的数据源(选项为设备类型有关) List typeTemp = new List{ Language.StringByID(R.MyInternationalizationString.All), }; foreach (string typeName in typeTemp) { var dialogRow = new RowLayout () { Height = Application.GetRealHeight (110), }; typeLayout.AddChidren (dialogRow); var btnPoint = new Button () { Width = Application.GetMinRealAverage (10), Height = Application.GetMinRealAverage (10), Radius = (uint)Application.GetMinRealAverage (5), X = Application.GetRealWidth (70), Gravity = Gravity.CenterVertical, BackgroundColor = SkinStyle.Current.TextColor1, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, }; dialogRow.AddChidren (btnPoint); Button btnTypeName = new Button () { Width = Application.GetRealHeight (400), X = btnPoint.Right + Application.GetRealWidth (30), Text = typeName, TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1 }; dialogRow.AddChidren (btnTypeName); EventHandler typeEvent = (sender1, e1) => { typeLayout.Height = 0; btnEquipmentType.Text = typeName; //if (typeName == Language.StringByID (R.MyInternationalizationString.Lights)) { // btnEquipmentIcon.UnSelectedImagePath = "Item/Light.png"; // selectedDeviceType = "Light"; //} else if (typeName == Language.StringByID (R.MyInternationalizationString.Curtains)) { // btnEquipmentIcon.UnSelectedImagePath = "Curtain/Curtain.png"; // selectedDeviceType = "Curtain"; //} else if (typeName == Language.StringByID (R.MyInternationalizationString.AC)) { // btnEquipmentIcon.UnSelectedImagePath = "AC/AC.png"; // selectedDeviceType = "AC"; //} else if (typeName == Language.StringByID (R.MyInternationalizationString.FoolHeat)) { // btnEquipmentIcon.UnSelectedImagePath = "Item/FloorHeating.png"; // selectedDeviceType = "FoolHeat"; //} else if (typeName == Language.StringByID (R.MyInternationalizationString.DryContactPanel)) { // btnEquipmentIcon.UnSelectedImagePath = "Item/DryContact.png"; // selectedDeviceType = "DryContact"; //} else if (typeName == Language.StringByID (R.MyInternationalizationString.MusicModel)) { // btnEquipmentIcon.UnSelectedImagePath = "Item/Music.png"; // selectedDeviceType = "Music"; //} else if (typeName == Language.StringByID (R.MyInternationalizationString.InfraredMode)) { // btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredTV.png"; // selectedDeviceType = "InfraredMode"; //} else if (typeName == Language.StringByID (R.MyInternationalizationString.TV)) { // btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredTV.png"; // selectedDeviceType = "InfraredMode"; //} else if (typeName == Language.StringByID (R.MyInternationalizationString.ElectricalControl)) { // btnEquipmentIcon.UnSelectedImagePath = "Light/Socket.png"; // selectedDeviceType = "EC";//电器控制 //} else if (typeName == Language.StringByID (R.MyInternationalizationString.Fan)) { // btnEquipmentIcon.UnSelectedImagePath = "Fan/Fan.png"; // selectedDeviceType = "Fan"; // //} else if (typeName == Language.StringByID (R.MyInternationalizationString.LogicModule)) { // // btnEquipmentIcon.UnSelectedImagePath = "Item/PointBig.png"; // // selectedDeviceType = "LogicModule"; //} else if (typeName == Language.StringByID (R.MyInternationalizationString.Scenes)) { btnEquipmentIcon.UnSelectedImagePath = "Scene/Scene.png"; selectedDeviceType = "Scene"; } //else if (typeName == Language.StringByID (R.MyInternationalizationString.UniversalDevice)) { // btnEquipmentIcon.UnSelectedImagePath = "UniversalDevice/UniversalDevice.png"; // selectedDeviceType = "UniversalDevice"; //} else if (typeName == Language.StringByID (R.MyInternationalizationString.Sensor)) { // btnEquipmentIcon.UnSelectedImagePath = "UniversalDevice/UniversalDevice.png"; // selectedDeviceType = "Sensor"; //} else if (typeName == Language.StringByID (R.MyInternationalizationString.FreshAir)) { // btnEquipmentIcon.UnSelectedImagePath = "FreshAir/FreshAir.png"; // selectedDeviceType = "FreshAir"; //} else { btnEquipmentIcon.UnSelectedImagePath = "Item/LogicModule.png"; selectedDeviceType = "All"; } chooseTypeView.BackgroundColor = SkinStyle.Current.ViewColor; GetDeviceList (); }; dialogRow.MouseUpEventHandler += typeEvent; btnTypeName.MouseUpEventHandler += typeEvent; } } } }