using System; using System.Collections.Generic; using System.Threading; namespace Shared.SimpleControl.Phone { /// /// 通过灯光设备类型,显示出所有房间的灯光 /// public class UserDeviceToLight : FrameLayout { /// /// 当前设备界面 /// static UserDeviceToLight curView; VerticalScrolViewLayout equipmentListScrolView; VerticalScrolViewLayout bodyScrolView; /// /// 是否需要更新界面 /// static bool updateView = true; /// /// 构造函数 /// public UserDeviceToLight () { curView = this; readAllStatus (); } public static void UpdateBrighingCount (string updataFlag) { #region 更新用户主界面灯光点亮总数 int brighingCount = 0; int LightSwitchSocketBrightingCount = 0; foreach (var room in Room.Lists) { if (room == null || string.IsNullOrEmpty (room.Name)) { continue; } foreach (var light in room.DeviceList) { if (light.Type == DeviceType.LightDimming || light.Type == DeviceType.LightMixDimming ) { if ((light as LightDimming).CurrentBrightness > 0) brighingCount++; } else if (light.Type == DeviceType.LightSwitch || light.Type == DeviceType.LightMixSwitch) { if ((light as LightSwitch).CurrentBrightness == 100) brighingCount++; } else if (light.Type == DeviceType.LightRGB) { if ((light as LightLogic).CurrentBrightness > 0) brighingCount++; } else if (light.Type == DeviceType.LightDALI) { if ((light as LightDALI).CurrentBrightness > 0) brighingCount++; } else if (light.Type == DeviceType.LightSwitchSocket) { if ((light as LightSwitch).CurrentBrightness == 100 || light.Type == DeviceType.LightEnergySwitch) LightSwitchSocketBrightingCount++; } } } if (UserDeviceView.LightingCount != brighingCount) { UserDeviceView.UpdataDeviceCountNumber (brighingCount, R.MyInternationalizationString.Lights); } if (UserDeviceView.SwitchSocketBrightingCount != LightSwitchSocketBrightingCount) { UserDeviceView.UpdataDeviceCountNumber (LightSwitchSocketBrightingCount, R.MyInternationalizationString.ElectricalControl); } if (curView != null) curView.updateLigthOnCount (updataFlag); #endregion } /// /// 更新当前灯光 /// public static void UpdateStatus (string updataFlag, byte brightness) { System.Threading.Tasks.Task.Run (() => { //if(!updateView) //{ // System.Threading.Thread.Sleep (100); //} Application.RunOnMainThread (() => { if (curView == null) { return; } if (UserConfig.Instance.ShowRoomLightList) { 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)) { var btn = (Button)lightRow.GetChildren (j); if (brightness == 0) { btn.IsSelected = false; } else { btn.IsSelected = true; } } else if (lightRow.GetChildren (j).GetType () == typeof (HorizontalSeekBar) && 3 < (DateTime.Now - (DateTime)lightRow.GetChildren (j).Tag).TotalSeconds) { (lightRow.GetChildren (j) as HorizontalSeekBar).Progress = brightness; } } } } } } curView.updateLigthOnCount (updataFlag); }); }); } /// /// 显示当前多少个灯是亮的 /// 灯光模块如果很多的话,这么会频繁更新 /// void updateLigthOnCount (string updataFlag) { //if (!UserConfig.Instance.ShowRoomLightList) //return; if (curView == null) return; System.Threading.Tasks.Task.Run (() => { int oCount = 0; bool update = false; Room updateRoom = null; foreach (var room in Room.Lists) { if (string.IsNullOrEmpty (room.Name)) { continue; } var findLight = room.DeviceList.Find ((obj) => obj.CommonLoopID == updataFlag); if (findLight == null) continue; update = true; oCount = 0; updateRoom = room; foreach (var light in room.DeviceList) { if (light.Type == DeviceType.LightDimming || light.Type == DeviceType.LightMixDimming ) { if ((light as LightDimming).CurrentBrightness > 0) oCount++; } else if (light.Type == DeviceType.LightRGB) { if ((light as LightLogic).CurrentBrightness > 0) oCount++; } else if (light.Type == DeviceType.LightDALI) { if ((light as LightDALI).CurrentBrightness > 0) oCount++; } else if (light.Type == DeviceType.LightSwitch || light.Type == DeviceType.LightMixSwitch) { if ((light as LightSwitch).CurrentBrightness > 0) oCount++; } } } if (!update) { Console.WriteLine ("退出更新灯光"); return; } Application.RunOnMainThread (() => { try { for (int i = 0; i < curView.bodyScrolView.ChildrenCount; i++) { if (curView.bodyScrolView == null) { return; } if (curView.bodyScrolView.GetChildren (i).GetType () == typeof (FrameLayout)) { var roomRow = (FrameLayout)curView.bodyScrolView.GetChildren (i); if (roomRow.Tag == null) { continue; } if (roomRow.Tag.ToString () == updateRoom.Name) { for (int j = 0; j < roomRow.ChildrenCount; j++) { if (roomRow.GetChildren (j).GetType () == typeof (EditText)) { var et = (EditText)roomRow.GetChildren (j); et.Text = oCount.ToString (); if (oCount > 0) { et.TextColor = SkinStyle.Current.SelectedColor; } else { et.TextColor = SkinStyle.Current.TextColor1; et.Text = updateRoom.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.LightRGB || obj.Type == DeviceType.LightDimming || obj.Type == DeviceType.LightMixSwitch || obj.Type == DeviceType.LightMixDimming || obj.Type == DeviceType.LightDALI || obj.Type == DeviceType.LightSwitch; }).Count.ToString (); } } if (roomRow.GetChildren (j).GetType () == typeof (Button)) { var btn = (Button)roomRow.GetChildren (j); if (oCount > 0) { btn.IsSelected = true; } else { btn.IsSelected = false; } } } } } } } catch { return; } }); }); //Console.WriteLine ("U1"); } bool showTip = true; /// /// 控制所有的灯 /// /// The blue component. void controlAllLight (byte b) { showTip = true; MainPage.Loading.Start ("Sending..."); System.Threading.Tasks.Task.Run (() => { foreach (var room in Room.Lists) { if (room == null) continue; if (string.IsNullOrEmpty (room.Name)) { continue; } foreach (var common in room.DeviceList) { byte [] returnBytes = null; if (common.Type == DeviceType.LightDimming || common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightRGB || common.Type == DeviceType.LightMixDimming || common.Type == DeviceType.LightMixSwitch || common.Type == DeviceType.LightDALI) { if (common.Type == DeviceType.LightDimming || common.Type == DeviceType.LightDALI) { var light = (LightDimming)common; if (b == 100) { if (light.LastOpenBrightness == 0) { returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.LoopID, b, light.DelayTimeHeight, light.DelayTimeLow }); } else returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.LoopID, light.LastOpenBrightness, light.DelayTimeHeight, light.DelayTimeLow }); } else returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.LoopID, b, light.DelayTimeHeight, light.DelayTimeLow }); } else if (common.Type == DeviceType.LightSwitch) { returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.LoopID, b, ((LightSwitch)common).DelayTimeHeight, ((LightSwitch)common).DelayTimeLow }); } else if (common.Type == DeviceType.LightRGB) { var light = (LightLogic)common; byte b2 = b; if (b2 == 100) { if (light.LastOpenBrightness != 0) { b2 = light.LastOpenBrightness; } } returnBytes = Control.ControlBytesSendHasReturn (Command.SetLogicLoopColor, common.SubnetID, common.DeviceID, new byte [] { common.LoopID, b2, 254, light.CustomDelayTimeOpen,light.CustomDelayTimeClose, 3,light.RStatus,light.GStatus,light.BStatus,0,0}); } else if (common.Type == DeviceType.LightMixDimming) { var light = (LightMixDimming)common; if (b == 100) { if (light.LastOpenBrightness == 0) { returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.PhysicsLoopID, b, light.DelayTimeHeight, light.DelayTimeLow }); } else returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.PhysicsLoopID, light.LastOpenBrightness, light.DelayTimeHeight, light.DelayTimeLow }); } else returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.PhysicsLoopID, b, light.DelayTimeHeight, light.DelayTimeLow }); } else if (common.Type == DeviceType.LightMixSwitch) { var light = (LightMixSwitch)common; returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.PhysicsLoopID, b, light.DelayTimeHeight, light.DelayTimeLow }); } if (showTip) { Application.RunOnMainThread (() => { if (returnBytes == null) { string showTipText = common.Name + Language.StringByID (R.MyInternationalizationString.ControlFailure); MainPage.AddTip (showTipText); } }); } } } } Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); }); } /// /// 通过设备类型方式选择设备 /// public void showAllRoomLights () { #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.Lights), 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); logo.MouseUpEventHandler += (sender, e) => { UserMiddle.ShowSettingView (); }; 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.SureOpenAllLight), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.Show (); alert.ResultEventHandler += (sender2, e2) => { if (e2) { controlAllLight (100); } }; }; 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.SureCloseAllLight), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.Show (); alert.ResultEventHandler += (sender2, e2) => { if (e2) { controlAllLight (0); } }; }; #endregion bodyScrolView = new VerticalScrolViewLayout () { Height = Application.GetRealHeight (Application.DesignHeight - 126 - 110), Y = powerView.Bottom, }; AddChidren (bodyScrolView); //显示有多少个房间,每个房间有多少个灯开 foreach (var room in Room.Lists) { if (string.IsNullOrEmpty (room.Name)) { continue; } var lightList = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.LightDimming || obj.Type == DeviceType.LightSwitch || obj.Type == DeviceType.LightRGB || obj.Type == DeviceType.LightMixSwitch || obj.Type == DeviceType.LightMixDimming || obj.Type == DeviceType.LightDALI; }); if (lightList == null) { 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 = lightList.Count.ToString (), TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.Center, Tag = room.Name }; roomView.AddChidren (btnNumber); Button btnLightIcon = new Button () { Width = Application.GetMinRealAverage (100), Height = Application.GetMinRealAverage (80), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/RH_Lights.png", SelectedImagePath = "Item/RH_LightsSelected.png", X = btnNumber.Right }; roomView.AddChidren (btnLightIcon); btnRoomName.MouseUpEventHandler += (sender, e) => { var userLightView = new UserLightPage (room); UserMiddle.DevicePageView.AddChidren (userLightView); userLightView.showLightsRoom (); UserMiddle.DevicePageView.PageIndex = 2; }; System.Threading.Tasks.Task.Run (() => { int num = 0; foreach (var light in room.DeviceList) { if (light.Type == DeviceType.LightDimming || light.Type == DeviceType.LightMixDimming) { if ((light as LightDimming).CurrentBrightness > 0) num++; } else if (light.Type == DeviceType.LightRGB) { if ((light as LightLogic).CurrentBrightness > 0) num++; } else if (light.Type == DeviceType.LightSwitch || light.Type == DeviceType.LightMixSwitch) { if ((light as LightSwitch).CurrentBrightness == 100) num++; } else if ( light.Type == DeviceType.LightDALI) { if ((light as LightDALI).CurrentBrightness == 100) num++; } } if (num > 0) { Application.RunOnMainThread (() => { btnNumber.TextColor = SkinStyle.Current.SelectedColor; btnNumber.Text = num.ToString (); btnLightIcon.IsSelected = true; }); } }); } #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.AllLight), 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) => { //return; MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load)); btnShowAll.IsSelected = !btnShowAll.IsSelected; downSelectedButton.IsSelected = btnShowAll.IsSelected; UserConfig.Instance.ShowRoomLightList = btnShowAll.IsSelected; UserConfig.Instance.SaveUserConfig (); System.Threading.Tasks.Task.Run (() => { try { Application.RunOnMainThread (() => { if (btnShowAll.IsSelected) { equipmentListScrolView.RemoveAll (); foreach (var room in Room.Lists) { if (room == null) { //Console.WriteLine ("Null is Room"); continue; } //Console.WriteLine ("RoomCount : " + Room.Lists.Count); //Console.WriteLine (room.Name); if (string.IsNullOrEmpty (room.Name)) { //Console.WriteLine ("Null is Room Name"); continue; } try { foreach (var common in room.DeviceList) { Console.WriteLine (common.Name + " : " + common.Type.ToString ()); if (common.Type == DeviceType.LightMixSwitch) { LightCount++; var light = common as LightMixSwitch; FrameLayout lightView = new FrameLayout () { Height = Application.GetRealHeight (130), }; 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 + "-" + light.Name, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.TextColor1, Enable = false, }; lightView.AddChidren (tempDeviceName); var 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", }; lightView.AddChidren (tempSiwtch); tempSiwtch.MouseUpEventHandler += (sender3, e3) => { tempSiwtch.IsSelected = !tempSiwtch.IsSelected; if (tempSiwtch.IsSelected) { light.CurrentBrightness = 100; } else { light.CurrentBrightness = 0; } Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.PhysicsLoopID, (byte)light.CurrentBrightness, light.DelayTimeHeight, light.DelayTimeLow }); }; if (light.CurrentBrightness == 100) { tempSiwtch.IsSelected = true; } } else if (common.Type == DeviceType.LightSwitch) { LightCount++; var light = common as LightSwitch; FrameLayout lightView = new FrameLayout () { Height = Application.GetRealHeight (130), }; 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 + "-" + light.Name, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.TextColor1, Enable = false, }; lightView.AddChidren (tempDeviceName); var 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", }; lightView.AddChidren (tempSiwtch); tempSiwtch.MouseUpEventHandler += (sender3, e3) => { tempSiwtch.IsSelected = !tempSiwtch.IsSelected; if (tempSiwtch.IsSelected) { light.CurrentBrightness = 100; } else { light.CurrentBrightness = 0; } Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, (byte)light.CurrentBrightness, light.DelayTimeHeight, light.DelayTimeLow }); }; if (light.CurrentBrightness == 100) { tempSiwtch.IsSelected = true; } } else if (common.Type == DeviceType.LightDimming) { LightCount++; var light = common as LightDimming; var lightView = new FrameLayout () { Height = Application.GetRealHeight (130), }; lightView.AddTag ("UpdataKey", light.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 tempLightName = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (10), TextAlignment = light.DimmingFunction ? TextAlignment.TopLeft : TextAlignment.CenterLeft, Text = room.Name + "-" + light.Name, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.TextColor1, Enable = false, }; if (!light.DimmingFunction) { tempLightName.Y = 0; } lightView.AddChidren (tempLightName); //进度条 var tempLightSeekBar = new HorizontalSeekBar () { Width = Application.GetRealWidth (440 - 20), Height = Application.GetRealHeight (130 - 20), X = Application.GetRealWidth (20), Y = Application.GetRealHeight (20), Visible = light.DimmingFunction, Tag = DateTime.MinValue, Progress = light.CurrentBrightness, ThumbColor = SkinStyle.Current.ThumbColor }; lightView.AddChidren (tempLightSeekBar); Console.WriteLine (common.Name + " : 3"); //开关按键 var tempSwitch = new Button () { Width = Application.GetMinRealAverage (90), Height = Application.GetMinRealAverage (53), X = Application.GetRealWidth (640 - 90 - 20), Y = Application.GetRealHeight (50), UnSelectedImagePath = "Item/SwitchClose.png", SelectedImagePath = "Item/SwitchOpen.png", }; lightView.AddChidren (tempSwitch); tempLightSeekBar.AddTag ("UpdataKey", light.CommonLoopID); tempLightSeekBar.ProgressChanged += (senderp, ep) => { if (ep > 0) { tempSwitch.IsSelected = true; } else { tempSwitch.IsSelected = false; } if (ep == 0 || ep == 100) { light.CurrentBrightness = (byte)ep; Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, (byte)ep, 0, 0 }, SendCount.Zero); tempLightSeekBar.Tag = DateTime.Now; return; } if ((System.DateTime.Now - (DateTime)(tempLightSeekBar.Tag)).TotalMilliseconds < 800) { return; } tempLightSeekBar.Tag = DateTime.Now; Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, (byte)ep, 0, 0 }, SendCount.Zero); light.CurrentBrightness = (byte)ep; }; tempLightSeekBar.MouseUpEventHandler += (sender1, e1) => { //弹起的时候发最后的数据 tempLightSeekBar.Tag = DateTime.Now; light.LastOpenBrightness = Convert.ToByte (tempLightSeekBar.Progress); Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, (byte)tempLightSeekBar.Progress, 0, 0 }); if (tempLightSeekBar.Progress > 0) { tempSwitch.IsSelected = true; } else { tempSwitch.IsSelected = false; } light.CurrentBrightness = (byte)tempLightSeekBar.Progress; }; tempSwitch.MouseUpEventHandler += (sender3, e3) => { tempSwitch.IsSelected = !tempSwitch.IsSelected; if (light.LastOpenBrightness == 0) { light.LastOpenBrightness = 100; } if (tempSwitch.IsSelected) { tempLightSeekBar.Progress = light.LastOpenBrightness > 0 ? light.LastOpenBrightness : 100; } else { tempLightSeekBar.Progress = 0; } light.CurrentBrightness = (byte)tempLightSeekBar.Progress; Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, light.CurrentBrightness, light.DelayTimeHeight, light.DelayTimeLow }); }; if (light.CurrentBrightness > 0) { tempSwitch.IsSelected = true; } } else if (common.Type == DeviceType.LightMixDimming) { LightCount++; var light = common as LightMixDimming; var lightView = new FrameLayout () { Height = Application.GetRealHeight (130), }; lightView.AddTag ("UpdataKey", light.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 tempLightName = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (10), TextAlignment = light.DimmingFunction ? TextAlignment.TopLeft : TextAlignment.CenterLeft, Text = room.Name + "-" + light.Name, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.TextColor1, Enable = false, }; if (!light.DimmingFunction) { tempLightName.Y = 0; } lightView.AddChidren (tempLightName); //进度条 var tempLightSeekBar = new HorizontalSeekBar () { Width = Application.GetRealWidth (440 - 20), Height = Application.GetRealHeight (130 - 20), X = Application.GetRealWidth (20), Y = Application.GetRealHeight (20), Visible = light.DimmingFunction, Tag = DateTime.MinValue, Progress = light.CurrentBrightness, ThumbColor = SkinStyle.Current.ThumbColor }; lightView.AddChidren (tempLightSeekBar); //开关按键 var tempSwitch = new Button () { Width = Application.GetMinRealAverage (90), Height = Application.GetMinRealAverage (53), X = Application.GetRealWidth (640 - 90 - 20), Y = Application.GetRealHeight (50), UnSelectedImagePath = "Item/SwitchClose.png", SelectedImagePath = "Item/SwitchOpen.png", }; lightView.AddChidren (tempSwitch); tempLightSeekBar.AddTag ("UpdataKey", light.CommonLoopID); tempLightSeekBar.ProgressChanged += (senderp, ep) => { if (ep > 0) { tempSwitch.IsSelected = true; } else { tempSwitch.IsSelected = false; } if (ep == 0 || ep == 100) { light.CurrentBrightness = (byte)ep; Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.PhysicsLoopID, (byte)ep, 0, 0 }, SendCount.Zero); tempLightSeekBar.Tag = DateTime.Now; return; } if ((System.DateTime.Now - (DateTime)(tempLightSeekBar.Tag)).TotalMilliseconds < 500) { return; } tempLightSeekBar.Tag = DateTime.Now; light.CurrentBrightness = (byte)ep; Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.PhysicsLoopID, (byte)ep, 0, 0 }, SendCount.Zero); if (tempLightSeekBar.Progress > 0) { tempSwitch.IsSelected = true; } else { tempSwitch.IsSelected = false; } }; tempLightSeekBar.MouseUpEventHandler += (sender1, e1) => { //弹起的时候发最后的数据 tempLightSeekBar.Tag = DateTime.Now; light.LastOpenBrightness = Convert.ToByte (tempLightSeekBar.Progress); Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.PhysicsLoopID, (byte)tempLightSeekBar.Progress, 0, 0 }); if (tempLightSeekBar.Progress > 0) { tempSwitch.IsSelected = true; } else { tempSwitch.IsSelected = false; } light.CurrentBrightness = (byte)tempLightSeekBar.Progress; }; tempSwitch.MouseUpEventHandler += (sender3, e3) => { tempSwitch.IsSelected = !tempSwitch.IsSelected; if (light.LastOpenBrightness == 0) { light.LastOpenBrightness = 100; } if (tempSwitch.IsSelected) { tempLightSeekBar.Progress = light.LastOpenBrightness > 0 ? light.LastOpenBrightness : 100; } else { tempLightSeekBar.Progress = 0; } light.CurrentBrightness = (byte)tempLightSeekBar.Progress; Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.PhysicsLoopID, light.CurrentBrightness, light.DelayTimeHeight, light.DelayTimeLow }); }; if (light.CurrentBrightness > 0) { tempSwitch.IsSelected = true; } } else if (common.Type == DeviceType.LightDALI) { LightCount++; //---- var light = common as LightDALI; if (light == null) { Console.WriteLine (" lightDali is null "); } var lightView = new FrameLayout () { Height = Application.GetRealHeight (140), }; lightView.AddTag ("UpdataKey", light.CommonLoopID); if (light.TonesFunction) { lightView.Height = Application.GetRealHeight (230); } equipmentListScrolView.AddChidren (lightView); Button btnLightViewBottomNull = new Button () { Y = light.TonesFunction ? Application.GetRealHeight (227) : Application.GetRealHeight (127), Height = Application.GetRealHeight (3), BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.MainColor, }; lightView.AddChidren (btnLightViewBottomNull); // 灯光名称 var tempLightName = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (10), TextAlignment = light.DimmingFunction ? TextAlignment.TopLeft : TextAlignment.CenterLeft, Text = room.Name + "-" + light.Name, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.TextColor1, Enable = false, }; if (!light.DimmingFunction) { tempLightName.Y = 0; } lightView.AddChidren (tempLightName); var btnTipBrightness = new Button () { Width = Application.GetRealWidth (440 - 20), Height = Application.GetRealHeight (25), X = Application.GetRealWidth (20), Y = Application.GetRealHeight (60), TextSize = 10, TextID = R.MyInternationalizationString.brightness, TextAlignment = TextAlignment.CenterLeft, }; lightView.AddChidren (btnTipBrightness); //进度条 var tempLightSeekBar = new HorizontalSeekBar () { Width = Application.GetRealWidth (440 - 20), Height = Application.GetRealHeight (130 - 60), X = Application.GetRealWidth (20), Y = btnTipBrightness.Bottom, Visible = light.DimmingFunction, Tag = DateTime.MinValue, Progress = light.CurrentBrightness, ThumbColor = SkinStyle.Current.ThumbColor }; lightView.AddChidren (tempLightSeekBar); if (light.TonesFunction) { var btnTipTones = new Button () { Width = Application.GetRealWidth (440 - 20), Height = Application.GetRealHeight (25), X = Application.GetRealWidth (20), Y = tempLightSeekBar.Bottom, TextID = R.MyInternationalizationString.Tones, TextAlignment = TextAlignment.CenterLeft, TextSize = 10, }; lightView.AddChidren (btnTipTones); //色温 var lightTonesSeekBar = new HorizontalSeekBar () { Width = Application.GetRealWidth (440 - 20), Height = Application.GetRealHeight (60), X = Application.GetRealWidth (20), Y = btnTipTones.Bottom, Tag = DateTime.MinValue, Max = light.TonesRange / 100, Progress = (light.CurTone - light.WarmTones) / 100, ThumbColor = SkinStyle.Current.ThumbColor }; lightView.AddChidren (lightTonesSeekBar); lightTonesSeekBar.ProgressChanged += (sender2, e4) => { //Console.WriteLine (DateTime.Now.ToString ()); var tonesValues = e4 * 100 + light.WarmTones; light.CurTones_High = (byte)(tonesValues / 256); light.CurTones_Low = (byte)(tonesValues % 256); System.Threading.Tasks.Task.Run (() => { if ((System.DateTime.Now - (DateTime)(lightTonesSeekBar.Tag)).TotalMilliseconds < 100) { return; } lightTonesSeekBar.Tag = DateTime.Now; Control.ControlBytesSend (Command.control_lamp_color_Temperature, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, light.CurTones_High, light.CurTones_Low }, SendCount.Zero); }); }; lightTonesSeekBar.MouseUpEventHandler += (sender2, e4) => { lightTonesSeekBar.Tag = DateTime.Now; var tonesValues = lightTonesSeekBar.Progress * 100 + light.WarmTones; light.CurTones_High = (byte)(tonesValues / 256); light.CurTones_Low = (byte)(tonesValues % 256); Control.ControlBytesSend (Command.control_lamp_color_Temperature, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, light.CurTones_High, light.CurTones_Low }, SendCount.Zero); IO.FileUtils.SaveEquipmentMessage (light, light.LoopID.ToString ()); }; } //开关按键 var tempSwitch = new Button () { Width = Application.GetMinRealAverage (90), Height = Application.GetMinRealAverage (53), X = Application.GetRealWidth (640 - 90 - 20), Y = Application.GetRealHeight (50), UnSelectedImagePath = "Item/SwitchClose.png", SelectedImagePath = "Item/SwitchOpen.png", }; lightView.AddChidren (tempSwitch); tempLightSeekBar.AddTag ("UpdataKey", light.CommonLoopID); tempLightSeekBar.ProgressChanged += (senderp, ep) => { tempLightSeekBar.Tag = DateTime.Now; if (tempLightSeekBar.Progress > 0) { tempSwitch.IsSelected = true; } else { tempSwitch.IsSelected = false; } light.LastOpenBrightness = light.CurrentBrightness = (byte)ep; if ((System.DateTime.Now - (DateTime)(tempLightSeekBar.Tag)).TotalMilliseconds < 500) { if (tempLightSeekBar.Progress == 0 || tempLightSeekBar.Progress == 100) { Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, (byte)ep, 0, 0 }, SendCount.Zero); } return; } else { Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, (byte)ep, 0, 0 }, SendCount.Zero); } }; tempLightSeekBar.MouseUpEventHandler += (sender1, e1) => { //弹起的时候发最后的数据 tempLightSeekBar.Tag = DateTime.Now; light.LastOpenBrightness = Convert.ToByte (tempLightSeekBar.Progress); Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, (byte)tempLightSeekBar.Progress, 0, 0 }); if (tempLightSeekBar.Progress > 0) { tempSwitch.IsSelected = true; light.LastOpenBrightness = light.CurrentBrightness = (byte)tempLightSeekBar.Progress; } else { tempSwitch.IsSelected = false; } }; tempSwitch.MouseUpEventHandler += (sender3, e3) => { tempSwitch.IsSelected = !tempSwitch.IsSelected; var brightness = 0; if (tempSwitch.IsSelected) { brightness = light.LastOpenBrightness > 0 ? light.LastOpenBrightness : 100; } Console.WriteLine ("ssssd " + brightness); light.CurrentBrightness = (byte)brightness; tempLightSeekBar.Progress = brightness; Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, light.CurrentBrightness, 0, 0 }); }; if (light.CurrentBrightness > 0) { tempSwitch.IsSelected = true; } } else if (common.Type == DeviceType.LightRGB) { LightCount++; var light = common as LightLogic; if (light == null) { light = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (common.SavePath))); } var lightView = new FrameLayout () { Height = Application.GetRealHeight (130), }; lightView.AddTag ("UpdataKey", light.CommonLoopID + "RGB"); 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 tempLightName = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (10), TextAlignment = light.DimmingFunction ? TextAlignment.TopLeft : TextAlignment.CenterLeft, Text = room.Name + "-" + light.Name, TextColor = SkinStyle.Current.TextColor1, Enable = false, }; if (!light.DimmingFunction) { tempLightName.Y = 0; } lightView.AddChidren (tempLightName); //进度条 var tempLightSeekBar = new HorizontalSeekBar () { Width = Application.GetRealWidth (440 - 20), Height = Application.GetRealHeight (130 - 20), X = Application.GetRealWidth (20), Y = Application.GetRealHeight (20), Visible = light.DimmingFunction, Tag = DateTime.MinValue, Progress = light.CurrentBrightness, ThumbColor = SkinStyle.Current.ThumbColor, }; lightView.AddChidren (tempLightSeekBar); //开关按键 var tempSwitch = new Button () { Width = Application.GetMinRealAverage (90), Height = Application.GetMinRealAverage (53), X = Application.GetRealWidth (640 - 90 - 20), Y = Application.GetRealHeight (50), //Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/SwitchClose.png", SelectedImagePath = "Item/SwitchOpen.png", }; lightView.AddChidren (tempSwitch); tempLightSeekBar.AddTag ("UpdataKey", light.CommonLoopID); tempLightSeekBar.ProgressChanged += (senderp, ep) => { if ((System.DateTime.Now - (DateTime)(tempLightSeekBar.Tag)).TotalMilliseconds < 500) { return; } tempLightSeekBar.Tag = DateTime.Now; light.CurrentBrightness = (byte)ep; Control.ControlBytesSend (Command.SetLogicLoopColor, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, light.CurrentBrightness, 254, 0,0, 3,light.RStatus,light.GStatus,light.BStatus,0,0}, SendCount.Zero); if (light.CurrentBrightness > 0) { tempSwitch.IsSelected = true; } else { tempSwitch.IsSelected = false; } light.CurrentBrightness = (byte)ep; }; tempLightSeekBar.MouseUpEventHandler += (sender1, e1) => { //弹起的时候发最后的数据 tempLightSeekBar.Tag = DateTime.Now; light.CurrentBrightness = light.LastOpenBrightness = Convert.ToByte (tempLightSeekBar.Progress); Control.ControlBytesSend (Command.SetLogicLoopColor, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, light.CurrentBrightness, 254, 0,0, 3,light.RStatus,light.GStatus,light.BStatus,0,0}, SendCount.Zero); if (light.CurrentBrightness > 0) { tempSwitch.IsSelected = true; IO.FileUtils.WriteFileByBytes ("Equipment_LightRGB_" + light.SubnetID.ToString () + "_" + light.DeviceID.ToString () + "_" + (light.LoopID < 10 ? "0" + light.LoopID.ToString () : light.LoopID.ToString ()), CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (light))); } else { tempSwitch.IsSelected = false; } light.CurrentBrightness = (byte)tempLightSeekBar.Progress; }; tempSwitch.MouseUpEventHandler += (sender3, e3) => { tempSwitch.IsSelected = !tempSwitch.IsSelected; if (light.LastOpenBrightness == 0) { light.LastOpenBrightness = 100; } if (tempSwitch.IsSelected) { tempLightSeekBar.Progress = light.LastOpenBrightness; Control.ControlBytesSend (Command.SetLogicLoopColor, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, light.CurrentBrightness, 254, light.CustomDelayTimeOpen,light.CustomDelayTimeClose, 3,light.RStatus,light.GStatus,light.BStatus,0,0}, SendCount.Zero); } else { tempLightSeekBar.Progress = 0; } light.CurrentBrightness = (byte)tempLightSeekBar.Progress; Control.ControlBytesSendHasReturn (Command.SetLogicLoopColor, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, light.CurrentBrightness, 254, light.CustomDelayTimeOpen,light.CustomDelayTimeClose, 3,light.RStatus,light.GStatus,light.BStatus,0,0}); }; if (light.CurrentBrightness > 0) { tempSwitch.IsSelected = true; } } } } catch (NullReferenceException exNull) { Console.WriteLine ("null exception : " + exNull.Source); } equipmentListScrolView.Height = bodyScrolView.Height; } Console.WriteLine ("Run ended!!"); } else { equipmentListScrolView.Height = 0; LightCount = 0; } }); } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; btnShowAll.MouseUpEventHandler += eHandler; downSelectedButton.MouseUpEventHandler += eHandler; //默认是选中状态 if (UserConfig.Instance.ShowRoomLightList) eHandler (btnShowAll, new MouseEventArgs ()); #endregion Console.WriteLine ("L6"); } static System.Threading.Thread thread; /// /// 读取设备状态 /// public static void readAllStatus (bool isRead = false) { if (isRead) { foreach (Room room in Room.Lists) { if (room == null) { continue; } var list = room.DeviceList.FindAll ((obj) => { return (obj.Type == DeviceType.LightDimming || obj.Type == DeviceType.LightSwitch || obj.Type == DeviceType.LightLogic || obj.Type == DeviceType.LightMixDimming || obj.Type == DeviceType.LightMixSwitch || obj.Type == DeviceType.FanModule); }); foreach (Common common in list) { common.LastUpdateTime = DateTime.MinValue; } var listGRB = room.DeviceList.FindAll ((obj) => { return (obj.Type == DeviceType.LightRGB); }); foreach (Common common in listGRB) { common.LastUpdateTime = DateTime.MinValue; } } } if (thread != null) { thread.Abort (); } thread = new Thread (() => { try { List readList = new List (); foreach (Room room in Room.Lists) { //if (string.IsNullOrEmpty(room.Name)) { // continue; //} var list = room.DeviceList.FindAll ((obj) => { return obj.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now && (obj.Type == DeviceType.LightDimming || obj.Type == DeviceType.LightSwitch || obj.Type == DeviceType.LightLogic || obj.Type == DeviceType.LightDALI || obj.Type == DeviceType.LightMixDimming || obj.Type == DeviceType.LightMixSwitch || obj.Type == DeviceType.FanModule); }); foreach (Common common in list) { var s = common.Type + "_" + common.SubnetID + "_" + common.DeviceID; if (common.LoopID > 64 ) {//&& common.Type == DeviceType.LightDALI Control.ControlBytesSendHasReturn (Command.ReadLightSingleLoopBrightness, common.SubnetID, common.DeviceID, new byte [] { common.LoopID }); continue; } //已经读取过当前设备就不再读取 if (readList.Contains (s)) { continue; } readList.Add (s); Control.ControlBytesSendHasReturn (Command.ReadLightEquipmentAllLoopBrightness, common.SubnetID, common.DeviceID, new byte [] { }); Thread.Sleep (500); } var listGRB = room.DeviceList.FindAll ((obj) => { return obj.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now && (obj.Type == DeviceType.LightRGB); }); foreach (Common common in listGRB) { var s = common.Type + "_" + common.SubnetID + "_" + common.DeviceID; //已经读取过当前设备就不再读取 if (readList.Contains (s)) { continue; } readList.Add (s); Control.ControlBytesSendHasReturn (Command.ReadLogicLoopColor, common.SubnetID, common.DeviceID, new byte [] { common.LoopID }); Thread.Sleep (500); } } } catch { } finally { thread = null; } }); thread.Start (); } } }