using System; using System.Threading; namespace Shared.SimpleControl.Phone { public class UserDeviceToUniversalDevice : FrameLayout { /// /// 当前设备界面 /// static UserDeviceToUniversalDevice curView; VerticalScrolViewLayout equipmentListScrolView; VerticalScrolViewLayout bodyScrolView; /// /// 构造函数 /// public UserDeviceToUniversalDevice () { curView = this; } /// /// 更新当前灯光 /// public static void UpdateStatus (string updataFlag, byte brightness) { System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { if (curView == null) { return; } if (curView.equipmentListScrolView.Decelerating) { return; } for (int i = 0; i < curView.equipmentListScrolView.ChildrenCount; i++) { if (curView.equipmentListScrolView.GetChildren (i).GetType () == typeof (FrameLayout)) { var lightRow = (FrameLayout)curView.equipmentListScrolView.GetChildren (i); var o = lightRow.GetTagByKey ("UpdataKey"); if (o != null && o.ToString () == updataFlag) { for (int j = 0; j < lightRow.ChildrenCount; j++) { if (lightRow.GetChildren (j).GetType () == typeof (Button)) { } } } } } }); }); } /// /// 通过设备类型方式选择设备 /// public void ShowUniversalDevice () { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.MainColor, }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = Language.StringByID (R.MyInternationalizationString.UniversalDevice), TextColor = SkinStyle.Current.TextColor1, TextSize = 19, }; topView.AddChidren (title); var logo = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), UnSelectedImagePath = MainPage.LogoString, }; topView.AddChidren (logo); 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) => { (Parent as PageLayout).PageIndex -= 1; curView = null; }; #endregion bodyScrolView = new VerticalScrolViewLayout () { Height = Application.GetRealHeight (1136 - 126), Y = Application.GetRealHeight (126), }; AddChidren (bodyScrolView); //显示有多少个房间,每个房间有多少个灯开 foreach (var room in Room.Lists) { if (string.IsNullOrEmpty(room.Name)) { continue; } var udList = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.UniversalDevice; }); if (udList == null || udList.Count == 0) { continue; } FrameLayout roomView = new FrameLayout () { Height = Application.GetRealHeight (110), BackgroundColor = SkinStyle.Current.ViewColor, Tag = room.Name }; bodyScrolView.AddChidren (roomView); Button btnRoomNull = new Button () { Height = 1, SelectedBackgroundColor = SkinStyle.Current.MainColor, BackgroundColor = SkinStyle.Current.MainColor, }; bodyScrolView.AddChidren (btnRoomNull); Button btnPoint = new Button () { Width = Application.GetRealWidth (10), Height = Application.GetRealHeight (10), X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/Point.png", SelectedImagePath = "Item/Point.png", }; roomView.AddChidren (btnPoint); Button btnRoomName = new Button () { Text = room.Name, X = btnPoint.Right + Application.GetRealWidth (20), TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.TextColor1, }; roomView.AddChidren (btnRoomName); EditText btnNumber = new EditText () { Width = Application.GetMinRealAverage (50), Height = Application.GetMinRealAverage (35), X = Application.GetRealWidth (640 - 100 - 50 - 20), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/LightingCount.png", SelectedImagePath = "Item/LightingCount.png", Enable = false, Text = udList.Count.ToString (), TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.Center, Tag = room.Name }; roomView.AddChidren (btnNumber); Button btnLightIcon = new Button () { Width = Application.GetRealWidth (50), Height = Application.GetRealHeight (50), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "UniversalDevice/UniversalDevice.png", SelectedImagePath = "UniversalDevice/UniversalDeviceOn.png", X = btnNumber.Right + Application.GetRealWidth(30) }; roomView.AddChidren (btnLightIcon); btnRoomName.MouseUpEventHandler += (sender, e) => { var userUniversalPage = new UserUniversalPage (room); UserMiddle.DevicePageView.AddChidren (userUniversalPage); userUniversalPage.ShowUniversalRoom (); UserMiddle.DevicePageView.PageIndex = 2; }; } #region 显示全部的灯光 FrameLayout ShowAllView = new FrameLayout () { Height = Application.GetRealHeight (85), BackgroundColor = SkinStyle.Current.MainColor, }; bodyScrolView.AddChidren (ShowAllView); Button btnShowAll = new Button () { X = Application.GetRealWidth (20), TextAlignment = TextAlignment.CenterLeft, Text = Language.StringByID (R.MyInternationalizationString.Device), TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.TextColor1 }; ShowAllView.AddChidren (btnShowAll); Button downSelectedButton = new Button () { X = Application.GetRealWidth (550), Height = Application.GetRealHeight (50), Width = Application.GetRealWidth (55), UnSelectedImagePath = "Item/Down.png", SelectedImagePath = "Item/DownSelected.png", Gravity = Gravity.CenterVertical, IsSelected = true, }; ShowAllView.AddChidren (downSelectedButton); //显示出所有的灯 equipmentListScrolView = new VerticalScrolViewLayout () { Height = bodyScrolView.Height - ShowAllView.Height, }; bodyScrolView.AddChidren (equipmentListScrolView); int LightCount = 0; EventHandler eHandler = (sender, e) => { btnShowAll.IsSelected = !btnShowAll.IsSelected; downSelectedButton.IsSelected = btnShowAll.IsSelected; UserConfig.Instance.ShowRoomLightList = btnShowAll.IsSelected; UserConfig.Instance.SaveUserConfig (); if (btnShowAll.IsSelected) { equipmentListScrolView.RemoveAll (); foreach (var room in Room.Lists) { if (string.IsNullOrEmpty(room.Name)) { continue; } foreach (var common in room.DeviceList) { if (common.Type == DeviceType.UniversalDevice) { LightCount++; var udDevice = common as UniversalDevice; byte sendLoopID = udDevice.LoopID; FrameLayout lightView = new FrameLayout () { Height = Application.GetRealHeight (130), Radius = 1, BorderColor = SkinStyle.Current.Transparent, BorderWidth = (uint)Application.GetMinRealAverage (5), }; lightView.AddTag ("UpdataKey", common.CommonLoopID); equipmentListScrolView.AddChidren (lightView); Button btnLightViewBottomNull = new Button () { Y = Application.GetRealHeight (127), Height = Application.GetRealHeight (3), BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.MainColor, }; lightView.AddChidren (btnLightViewBottomNull); //灯名 var tempDeviceName = new Button () { X = Application.GetRealWidth (20), TextAlignment = TextAlignment.CenterLeft, Text = room.Name + "-" + udDevice.Name, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.TextColor1, Enable = false, }; lightView.AddChidren (tempDeviceName); Button tempSiwtch = new Button () { Width = Application.GetRealWidth (110), Height = Application.GetRealHeight (70), X = Application.GetRealWidth (640 - 110 - 20), Gravity = Gravity.CenterVertical, Radius = 2, BorderColor = SkinStyle.Current.BorderColor, TextColor = SkinStyle.Current.TextColor1, BorderWidth = 2, }; lightView.AddChidren (tempSiwtch); if (udDevice.ActionType == 0) { tempSiwtch.TextID = R.MyInternationalizationString.ON; } else if (udDevice.ActionType == 1) { tempSiwtch.TextID = R.MyInternationalizationString.OFF; } else if (udDevice.ActionType == 2) { tempSiwtch.TextID = R.MyInternationalizationString.OFF; Button tempON = new Button () { Width = Application.GetRealWidth (110), Height = Application.GetRealHeight (70), X = Application.GetRealWidth (640 - 250 - 20), Gravity = Gravity.CenterVertical, Radius = 2, BorderColor = SkinStyle.Current.BorderColor, BorderWidth = 2, TextID = R.MyInternationalizationString.ON, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.TextColor1, }; lightView.AddChidren (tempON); tempON.MouseUpEventHandler += (sender3, e3) => { if (udDevice.UniversalType == 0xE01C) { Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 255 },SendCount.Zero); } lightView.BorderColor = SkinStyle.Current.Transparent; }; tempON.MouseDownEventHandler += (sende3r, e3) => { lightView.BorderColor = SkinStyle.Current.SelectedColor; }; } tempSiwtch.MouseUpEventHandler += (sender3, e3) => { if (udDevice.UniversalType == 0xE01C) { if (udDevice.ActionType == 0) { Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 255 }, SendCount.Zero); } else if (udDevice.ActionType == 1) { Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 }, SendCount.Zero); } else if (udDevice.ActionType == 2) { Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 }, SendCount.Zero); } } lightView.BorderColor = SkinStyle.Current.Transparent; }; tempSiwtch.MouseDownEventHandler += (sende3r, e3) => { lightView.BorderColor = SkinStyle.Current.SelectedColor; }; } } equipmentListScrolView.Height = LightCount * Application.GetRealHeight (130); } } else { equipmentListScrolView.Height = 0; LightCount = 0; } }; btnShowAll.MouseUpEventHandler += eHandler; downSelectedButton.MouseUpEventHandler += eHandler; //默认是选中状态 if (UserConfig.Instance.ShowRoomLightList) eHandler (btnShowAll, new MouseEventArgs ()); #endregion } } }