using System; namespace Shared.SimpleControl.Phone { public class UserDeviceToFan : FrameLayout { VerticalScrolViewLayout bodyScrolView; static UserDeviceToFan curView; public UserDeviceToFan () { curView = this; BackgroundColor = SkinStyle.Current.MainColor; UserDeviceToLight.readAllStatus (); } /// /// 通过设备类型方式选择设备 /// public void ShowAllRoomCurtain () { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = Language.StringByID (R.MyInternationalizationString.Fan), TextSize = 19, TextColor = SkinStyle.Current.TextColor1, }; 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 #region 全开-全关 var powerView = new FrameLayout () { Height = Application.GetRealHeight (110), BackgroundColor = SkinStyle.Current.TitileView, Y = topView.Bottom }; AddChidren (powerView); var btnAllON = new Button () { Width = Application.GetRealWidth (320), TextSize = 16, TextID = R.MyInternationalizationString.ALLON, TextColor = SkinStyle.Current.TextColor1 }; powerView.AddChidren (btnAllON); var btnAllOff = new Button () { Width = Application.GetRealWidth (320), X = btnAllON.Right, TextSize = 16, TextID = R.MyInternationalizationString.ALLOFF, TextColor = SkinStyle.Current.TextColor1 }; var btnLine = new Button () { Width = 1, BackgroundColor = SkinStyle.Current.White20Transparent, X = btnAllON.Right, }; powerView.AddChidren (btnLine); btnAllON.MouseUpEventHandler += (sender, e) => { btnAllON.TextColor = SkinStyle.Current.SelectedColor; btnAllOff.TextColor = SkinStyle.Current.TextColor1; Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.SureOpenAllFan), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.Show (); alert.ResultEventHandler += (sender2, e2) => { if (e2) { ControlAllFan (true); } }; }; powerView.AddChidren (btnAllOff); btnAllOff.MouseUpEventHandler += (sender, e) => { btnAllON.TextColor = SkinStyle.Current.TextColor1; btnAllOff.TextColor = SkinStyle.Current.SelectedColor; Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.SureCloseAllFan), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.Show (); alert.ResultEventHandler += (sender2, e2) => { if (e2) { ControlAllFan (false); } }; }; #endregion bodyScrolView = new VerticalScrolViewLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (Application.DesignHeight - 126 - 110), Y = powerView.Bottom, BackgroundColor = SkinStyle.Current.ViewColor }; AddChidren (bodyScrolView); #region 显示 int devcieCount = 0; foreach (var room in Room.Lists) { if (string.IsNullOrEmpty(room.Name)) { continue; } foreach (var common in room.DeviceList) { if (common.Type == DeviceType.FanModule) { devcieCount++; var fanModule = common as FanModule; EventHandler openCurtainControlPageEvent = (button, mouseEventArgs) => { UserFan userFanView = new UserFan (fanModule); UserMiddle.DevicePageView.AddChidren (userFanView); userFanView.ShowRoomFan (); UserMiddle.DevicePageView.PageIndex = 2; }; FrameLayout fanView = new FrameLayout () { Height = Application.GetRealHeight (130), Tag = fanModule.CommonLoopID }; bodyScrolView.AddChidren (fanView); fanView.MouseUpEventHandler += openCurtainControlPageEvent; Button btnCurtainViewBottomNull = new Button () { Y = Application.GetRealHeight (127), Height = Application.GetRealHeight (3), BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.MainColor, }; fanView.AddChidren (btnCurtainViewBottomNull); Button tempDeviceName = new Button () { X = Application.GetRealWidth (30), TextAlignment = TextAlignment.CenterLeft, Text = room.Name + "-" + fanModule.Name, TextColor = SkinStyle.Current.TextColor1, }; fanView.AddChidren (tempDeviceName); tempDeviceName.MouseUpEventHandler += openCurtainControlPageEvent; Button tempSiwtch = new Button () { Width = Application.GetMinRealAverage (90), Height = Application.GetMinRealAverage (53), X = Application.GetRealWidth (640 - 90 - 20), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/SwitchClose.png", SelectedImagePath = "Item/SwitchOpen.png", IsSelected = fanModule.Switch > 0 ? true : false, Tag = fanModule.CommonLoopID }; fanView.AddChidren (tempSiwtch); tempSiwtch.MouseUpEventHandler += (sender3, e3) => { tempSiwtch.IsSelected = !tempSiwtch.IsSelected; if (tempSiwtch.IsSelected) { fanModule.Switch = fanModule.WindSpeed; } else { fanModule.Switch = 0; } Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, fanModule.Switch }); }; Button btnViewNull = new Button () { Y = Application.GetRealHeight (127), Height = Application.GetRealHeight (3), BackgroundColor = SkinStyle.Current.MainColor, }; fanView.AddChidren (btnViewNull); } } } #endregion } public static void UpdataStatus (string updataFlag, byte windSpeed) { #region 更新用户主界面灯光点亮总数 Application.RunOnMainThread (() => { int brighingCount = 0; foreach (var room in Room.Lists) { if (string.IsNullOrEmpty(room.Name)) { continue; } foreach (var light in room.DeviceList) { if (light.Type == DeviceType.FanModule) { if ((light as FanModule).WindSpeed > 0) { brighingCount++; } } } } UserDeviceView.UpdataDeviceCountNumber (brighingCount, R.MyInternationalizationString.Fan); }); #endregion if (curView == null || curView.bodyScrolView.Decelerating) { return; } Application.RunOnMainThread (() => { for (int i = 0; i < curView.bodyScrolView.ChildrenCount; i++) { if (curView.bodyScrolView.GetChildren (i).GetType () == typeof (FrameLayout)) { var lightRow = (FrameLayout)curView.bodyScrolView.GetChildren (i); for (int j = 0; j < lightRow.ChildrenCount; j++) { if (lightRow.GetChildren (j).GetType () == typeof (Button)) { var btn = (Button)lightRow.GetChildren (j); var o = btn.Tag; if (o != null && o.ToString () == updataFlag) { if (windSpeed == 0) { btn.IsSelected = false; } else { btn.IsSelected = true; } } } } } } }); } void ControlAllFan (bool open) { foreach (var room in Room.Lists) { if (room == null) continue; if (string.IsNullOrEmpty(room.Name)) { continue; } foreach (var fanD in room.DeviceList) { if (fanD.Type == DeviceType.FanModule) { if (open) { Control.ControlBytesSend (Command.SetSingleLight, fanD.SubnetID, fanD.DeviceID, new byte [] { fanD.LoopID, (fanD as FanModule).WindSpeed }); } else { Control.ControlBytesSend (Command.SetSingleLight, fanD.SubnetID, fanD.DeviceID, new byte [] { fanD.LoopID, 0 }); } } } } } } }