using System; using System.Collections.Generic; namespace Shared.SimpleControl.Phone { /// /// 用户房间灯光控制界面 /// public class UserLightPage : FrameLayout { /// /// 当前打开的灯光界面 /// static UserLightPage curView; VerticalScrolViewLayout lightListView; VerticalScrolViewLayout lightSceneListView; Button btnLineInSceneViewBottom; Button btnLastClickScene; Room room; /// /// 显示当前房间灯光设备 /// /// Room. public UserLightPage (Room Room) { curView = this; room = Room; BackgroundColor = SkinStyle.Current.MainColor; readStatus (room); } /// /// 接受到灯光发出的数据之后更新UI /// /// The user lights. public static void UpdateStatus (string updataFlag, byte brightness) { Application.RunOnMainThread (() => { if (curView == null) { return; } for (int i = 0; i < curView.lightListView.ChildrenCount; i++) { if (curView.lightListView.GetChildren (i).GetType () == typeof (FrameLayout)) { var frameLayout = (FrameLayout)curView.lightListView.GetChildren (i); var o = frameLayout.GetTagByKey ("UpdataKey"); if (o != null && o.ToString () == updataFlag) { for (int j = 0; j < frameLayout.ChildrenCount; j++) { var childView = frameLayout.GetChildren (j); if (childView.GetType () == typeof (Button)) { Button btn = (Button)childView; if (brightness == 0) { btn.IsSelected = false; } else { btn.IsSelected = true; } } else if (childView.GetType () == typeof (HorizontalSeekBar) && 3 < (DateTime.Now - (DateTime)childView.Tag).TotalSeconds) { (childView as HorizontalSeekBar).Progress = brightness; } } } } } }); } /// /// 房间模式进入的灯光界面 /// /// The lights room. public void showLightsRoom () { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = room.Name, 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 VerticalScrolViewLayout bodyMainView = new VerticalScrolViewLayout () { Height = Application.GetRealHeight (Application.DesignHeight) - topView.Bottom, Y = topView.Bottom, }; AddChidren (bodyMainView); var roomBackgroundImage = new FrameLayout () { Height = Application.GetRealHeight (360), }; bodyMainView.AddChidren (roomBackgroundImage); roomBackgroundImage.BackgroundImagePath = room.BackGroundImage; #if wallon #else roomBackgroundImage.MouseLongEventHandler += (sender, e) => { Camera.SelectPicture ((obj) => { if (obj != null) { room.BackGroundImage = obj; roomBackgroundImage.BackgroundImagePath = obj; room.Save (typeof (Room).Name + "_" + room.Name); } }, room.Name, false); }; #endif var btnAddLightScene = new Button () { Width = Application.GetMinRealAverage (100), Height = Application.GetMinRealAverage (100), X = Application.GetRealWidth (640 - 120), Y = Application.GetRealHeight (20), UnSelectedImagePath = "Light/UserLightAddScene.png", }; roomBackgroundImage.AddChidren (btnAddLightScene); #region --灯光场景-- btnAddLightScene.MouseUpEventHandler += (sender, e) => { LightSceneDialog (); }; #endregion Button btnGGBlack = new Button () { BackgroundColor = 0xFF000000, Height = Application.GetRealHeight(5) }; bodyMainView.AddChidren (btnGGBlack); lightSceneListView = new VerticalScrolViewLayout () { BackgroundColor = SkinStyle.Current.ViewColor, Height = Application.GetRealHeight (0), Y = roomBackgroundImage.Bottom }; bodyMainView.AddChidren (lightSceneListView); btnLineInSceneViewBottom = new Button { BackgroundColor = SkinStyle.Current.MainColor, Height = 0 }; lightListView = new VerticalScrolViewLayout () { BackgroundColor = SkinStyle.Current.ViewColor, Y = lightSceneListView.Bottom, }; //加载灯光场景 addLightScenes (); bodyMainView.AddChidren (btnLineInSceneViewBottom); lightListView.Y = lightSceneListView.Bottom; bodyMainView.AddChidren (lightListView); //加载灯光 addLights (); } void addLightScenes ( ) { lightSceneListView.RemoveAll (); int height = 0; if (room.LightScenePathList.Count < 3) { if (room.LightScenePathList.Count == 0) height = 0; else height = Application.GetRealHeight (108); } else { height = Application.GetRealHeight (218); } lightSceneListView.Height = height; lightListView.Height = Application.GetRealHeight (Application.DesignHeight - 126 - 0 - 10) - height; if (height > 0) btnLineInSceneViewBottom.Height = Application.GetRealHeight (5); btnLineInSceneViewBottom.Y = lightSceneListView.Bottom; var hView = new HorizontalScrolViewLayout () { Height = Application.GetRealHeight (110), ScrollEnabled = false, }; lightSceneListView.AddChidren (hView); btnLastClickScene = new Button () { Height = Application.GetRealHeight (7), BackgroundColor = SkinStyle.Current.SelectedColor, Y = Application.GetRealHeight (103), }; //room.LightScenePathList. foreach (string lightSceneFilePath in room.LightScenePathList) { var scene = Scene.GetSceneByFilePath (lightSceneFilePath); if (scene == null) { room.LightScenePathList.Remove (lightSceneFilePath); room.Save (typeof (Room).Name + "_" + room.Name); addLightScenes ();//移除空的场景,重新加载界面 return; } if (room.LightScenePathList.IndexOf (lightSceneFilePath) > 1) { if (room.LightScenePathList.IndexOf (lightSceneFilePath) % 2 == 0) { hView = new HorizontalScrolViewLayout () { Height = Application.GetRealHeight (110), }; lightSceneListView.AddChidren (hView); } } var lightSceneView = new RowLayout () { Height = Application.GetRealHeight (110), Width = Application.GetRealWidth (636 / 2), X = Application.GetRealWidth ((room.LightScenePathList.IndexOf (lightSceneFilePath) % 2) * 110) }; hView.AddChidren (lightSceneView); var btnlsViewNull = new Button () { Y = Application.GetRealHeight(107), Height = Application.GetRealHeight(3), BackgroundColor = SkinStyle.Current.MainColor, }; lightSceneView.AddChidren (btnlsViewNull); if (room.LightScenePathList.IndexOf (lightSceneFilePath) % 2 == 0) { Button btnLineV = new Button () { Width = Application.GetRealWidth(4), Height = Application.GetRealHeight(110), BackgroundColor = SkinStyle.Current.MainColor, }; hView.AddChidren (btnLineV); } var btnDel = new Button () { TextID = R.MyInternationalizationString.Del, BackgroundColor = SkinStyle.Current.DelColor, }; lightSceneView.AddRightView (btnDel); btnDel.MouseUpEventHandler += (sender, e) => { foreach (var file in scene.DeviceFilePathList) { IO.FileUtils.DeleteFile (file); } IO.FileUtils.DeleteFile (lightSceneFilePath); room.LightScenePathList.Remove (lightSceneFilePath); room.Save (typeof (Room).Name + "_" + room.Name); addLightScenes (); }; Button btnSIcon = new Button () { Width = Application.GetRealWidth(111), Height = Application.GetRealHeight(110), Gravity = Gravity.CenterVertical, UnSelectedImagePath = scene.SceneIconPath, SelectedImagePath = scene.SceneIconPath, }; lightSceneView.AddChidren (btnSIcon); Button btnSceneRemark = new Button () { Width = Application.GetRealWidth (638 / 2 -75), X = Application.GetRealWidth(111), BorderColor = SkinStyle.Current.Transparent, BorderWidth = 1, Radius = 1, Text = scene.Name, TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, }; lightSceneView.AddChidren (btnSceneRemark); btnSceneRemark.MouseLongEventHandler += (sender, e) => { LightSceneDialog (scene); }; btnSceneRemark.MouseUpEventHandler += (sender, e) => { try { btnLastClickScene.RemoveFromParent (); lightSceneView.AddChidren (btnLastClickScene); MainPage.Loading.Start (); System.Threading.Tasks.Task.Run (() => { foreach (var deviceFilePath in scene.DeviceFilePathList) { var devictTypeStr = deviceFilePath.Split ('_') [1]; if (devictTypeStr == DeviceType.LightDimming.ToString () || devictTypeStr == DeviceType.LightDALI.ToString() || devictTypeStr == DeviceType.LightMixDimming.ToString()) { var device = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); if (device == null) { continue; } byte delayTime = 0; if (device.Type == DeviceType.LightDimming) { if (device.CurrentBrightness > 0) { try { delayTime = room.DelayTime [device.CommonLoopID + "Open"]; } catch { delayTime = 0; } } else { try { delayTime = room.DelayTime [device.CommonLoopID + "Close"]; } catch { delayTime = 0; } } } Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, 0, delayTime }); } else if (devictTypeStr == DeviceType.LightSwitch.ToString () || devictTypeStr == DeviceType.LightMixSwitch.ToString()) { var device = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); if (device == null) { continue; } Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, 0, 0 }); } else if (devictTypeStr == DeviceType.LightLogic.ToString ()) { var device = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); if (device != null) { byte delayTime = 0; if (device.Type == DeviceType.LightLogic) { if (device.CurrentBrightness > 0) { try { delayTime = room.DelayTime [device.LightDimmingID + "Open"]; } catch { delayTime = 0; } } else { try { delayTime = room.DelayTime [device.LightDimmingID + "Close"]; } catch { delayTime = 0; } } } Control.ControlBytesSend (Command.SetLogicLoopColor, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, 254, device.CustomDelayTimeOpen,device.CustomDelayTimeClose, 3,device.RStatus,device.GStatus,device.BStatus,0,0}, SendCount.Zero); } } } }); } catch { } finally { MainPage.Loading.Hide (); } }; } } void LightSceneDialog (Scene scene = null) { Dialog dialog = new Dialog (); FrameLayout dialogBodyView = new FrameLayout () { BackgroundColor = SkinStyle.Current.DialogColor, Width = Application.GetRealWidth (478), Height = Application.GetRealHeight (640 + 70), Gravity = Gravity.Center, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, Radius = 5, }; dialog.AddChidren (dialogBodyView); Button btnTitle = new Button () { Height = Application.GetRealHeight (80), TextAlignment = TextAlignment.Center, Enable = false, TextID = R.MyInternationalizationString.AddLightScene, BackgroundColor = SkinStyle.Current.DialogTitle, }; dialogBodyView.AddChidren (btnTitle); FrameLayout remarkView = new FrameLayout () { Height = Application.GetRealHeight (80), Y = btnTitle.Bottom, BackgroundColor = SkinStyle.Current.SubtitleView, }; dialogBodyView.AddChidren (remarkView); Button btnRemark = new Button () { Width = Application.GetRealWidth (110), X = Application.GetRealWidth (20), TextID = R.MyInternationalizationString.Remark, TextColor = SkinStyle.Current.DialogTextColor, }; remarkView.AddChidren (btnRemark); EditText etRemark = new EditText () { Width = Application.GetRealWidth (300), Height = Application.GetRealHeight (50), X = btnRemark.Right + Application.GetRealWidth (10), Y = Application.GetRealHeight (15), BorderColor = SkinStyle.Current.White20Transparent, TextColor = SkinStyle.Current.TextColor, TextAlignment = TextAlignment.Center, BackgroundColor = SkinStyle.Current.DialogColor, BorderWidth = 1, Radius = 5, }; if (scene != null) { etRemark.Text = scene.Name; btnTitle.TextID = R.MyInternationalizationString.ModifyLightScene; } remarkView.AddChidren (etRemark); var verticalScrolView = new VerticalScrolViewLayout () { Height = Application.GetRealHeight (380), Y = remarkView.Bottom + Application.GetRealHeight (10), }; dialogBodyView.AddChidren (verticalScrolView); FrameLayout inScrolView_DeviceListView = new FrameLayout () { BackgroundColor = SkinStyle.Current.DialogColor }; verticalScrolView.AddChidren (inScrolView_DeviceListView); int btnEquipmentCont = 0; var lights = room.DeviceList.FindAll ((obj) => { return (obj.Type == DeviceType.LightSwitch || obj.Type == DeviceType.LightDimming || obj.Type == DeviceType.LightRGB || obj.Type == DeviceType.LightDALI || obj.Type == DeviceType.LightMixSwitch || obj.Type == DeviceType.LightMixDimming); }); List lightScenePathList = new List (); List lightSceneList = new List (); if (lights.Count > 10) { inScrolView_DeviceListView.Height = Application.GetRealHeight (lights.Count / 2 * 105); } if (scene == null) { scene = new Scene (); } foreach (var light in lights) { Button btnEquipment = new Button () { Width = (inScrolView_DeviceListView.Width - Application.GetRealWidth (50)) / 2, Height = Application.GetRealHeight (85), X = Application.GetRealHeight (30), Y = Application.GetRealHeight (5), TextAlignment = TextAlignment.Center, BackgroundColor = SkinStyle.Current.ButtonColor, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextColor = SkinStyle.Current.TextColor1, Tag = light, Text = light.Name }; foreach (var lightPath in scene.DeviceFilePathList) { string selecteLight = light.GetType ().Name.Replace ("LightLogic", "LightRGB") + "_" + light.SubnetID + "_" + light.DeviceID + "_" + (light.LoopID < 10 ? "0" + light.LoopID.ToString () : light.LoopID.ToString ()); if (lightPath.Contains (selecteLight)) { btnEquipment.IsSelected = true; Common common = (Common)btnEquipment.Tag; var filePath = scene.DeviceFilePathList.Find ((obj) => { return obj.EndsWith (common.Type + "_" + common.SubnetID.ToString () + "_" + common.DeviceID.ToString () + "_" + (common.LoopID < 10 ? "0" + common.LoopID : common.LoopID.ToString ())); }); lightScenePathList.Add (filePath); lightSceneList.Add (common); } } if (btnEquipmentCont < 2) { btnEquipment.X = btnEquipmentCont * (btnEquipment.Width + Application.GetRealWidth (10)) + Application.GetRealWidth (20); //btnEquipment.Y = Application.GetRealHeight(10); btnEquipmentCont++; } else { btnEquipment.X = btnEquipmentCont % 2 * (btnEquipment.Width + Application.GetRealWidth (10)) + Application.GetRealWidth (20); btnEquipment.Y = (int)btnEquipmentCont / 2 * (btnEquipment.Height + Application.GetRealHeight (10)) + Application.GetRealHeight (10); btnEquipmentCont++; } inScrolView_DeviceListView.AddChidren (btnEquipment); btnEquipment.MouseUpEventHandler += (sende3r, e3) => { Common common = (Common)btnEquipment.Tag; //btnEquipment.IsSelected = !btnEquipment.IsSelected; if (btnEquipment.IsSelected) { var filePath = lightScenePathList.Find ((obj) => { return obj.EndsWith (common.GetType ().Name + "_" + common.SubnetID.ToString () + "_" + common.DeviceID.ToString () + "_" + (common.LoopID < 10 ? "0" + common.LoopID : common.LoopID.ToString ())); }); lightScenePathList.Remove (filePath); lightSceneList.Remove (common); btnEquipment.IsSelected = false; } else { var filePath = "RoomLightScene" + DateTime.Now.Ticks + "_" + common.GetType ().Name + "_" + common.SubnetID.ToString () + "_" + common.DeviceID.ToString () + "_" + (common.LoopID < 10 ? "0" + common.LoopID : common.LoopID.ToString ()); lightScenePathList.Add (filePath); lightSceneList.Add (common); btnEquipment.IsSelected = true; } }; } var iconView = new HorizontalScrolViewLayout () { Y = verticalScrolView.Bottom + Application.GetRealHeight (5), Height = Application.GetRealHeight (75), BackgroundColor = SkinStyle.Current.SubtitleView, }; dialogBodyView.AddChidren (iconView); for (int i = 1; i < 7; i++) { string iconPath = @"Light/LightSceneIcon" + i.ToString () + @".png"; string iconPathOn = @"Light/LightSceneIcon" + i.ToString () + @"On.png"; Button btnIcon = new Button () { Width = Application.GetRealWidth (79), UnSelectedImagePath = iconPath, SelectedImagePath = iconPathOn, IsSelected = scene.SceneIconPath == iconPath ? true : false, Tag = i }; iconView.AddChidren (btnIcon); if (i < 6) { Button btnLineIcon = new Button () { Width = Application.GetRealWidth (2), BackgroundColor = SkinStyle.Current.DialogColor }; iconView.AddChidren (btnLineIcon); } btnIcon.MouseUpEventHandler += (sende2r, e2) => { for (int j = 0; j < iconView.ChildrenCount; j++) { if (iconView.GetChildren (j).Tag != btnIcon.Tag) ((Button)iconView.GetChildren (j)).IsSelected = false; } btnIcon.IsSelected = btnIcon.IsSelected ? false : true; if (btnIcon.IsSelected) scene.SceneIconPath = btnIcon.UnSelectedImagePath; }; if (i == 0) { scene.SceneIconPath = btnIcon.UnSelectedImagePath; } } FrameLayout bottomView = new FrameLayout () { Y = iconView.Bottom + Application.GetRealHeight (1), Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.DialogTitle }; dialogBodyView.AddChidren (bottomView); Button btnCancel = new Button () { Width = Application.GetRealWidth (239), TextID = R.MyInternationalizationString.Cancel, }; bottomView.AddChidren (btnCancel); btnCancel.MouseUpEventHandler += (sender2, e2) => { dialog.Close (); }; Button btnLine = new Button () { BackgroundColor = SkinStyle.Current.DialogColor, Width = 1, X = btnCancel.Right, Y = 3 }; bottomView.AddChidren (btnLine); Button btnSave = new Button () { Width = Application.GetRealWidth (239), X = btnLine.Right, TextID = R.MyInternationalizationString.SAVE }; bottomView.AddChidren (btnSave); btnSave.MouseUpEventHandler += (sender3, e3) => { string lightSceneRemark = etRemark.Text.Trim (); if (string.IsNullOrEmpty (lightSceneRemark)) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterSceneName), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } string lightScenePath = room.Name + "_LightScene_" + lightSceneRemark; if (lightSceneRemark != scene.Name) { if (room.LightScenePathList.Contains (lightScenePath)) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } IO.FileUtils.DeleteFile (room.Name + "_LightScene_" + scene.Name); room.LightScenePathList.Remove (room.Name + "_LightScene_" + scene.Name); room.LightScenePathList.Add (lightScenePath); } scene.DeviceFilePathList.Clear (); for (int i = 0; i < lightScenePathList.Count; i++) { var filePath = lightScenePathList [i]; var common = lightSceneList [i]; if (common.Type == DeviceType.LightDimming) { IO.FileUtils.WriteFileByBytes (filePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject ((LightDimming)common))); } else if (common.Type == DeviceType.LightSwitch) { IO.FileUtils.WriteFileByBytes (filePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject ((LightSwitch)common))); } else if (common.Type == DeviceType.LightRGB) { IO.FileUtils.WriteFileByBytes (filePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject ((LightLogic)common))); } else if (common.Type == DeviceType.LightDALI) { IO.FileUtils.WriteFileByBytes (filePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject ((LightDALI)common))); } else if (common.Type == DeviceType.LightMixDimming) { IO.FileUtils.WriteFileByBytes (filePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject ((LightMixDimming)common))); } else if (common.Type == DeviceType.LightMixSwitch) { IO.FileUtils.WriteFileByBytes (filePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject ((LightMixSwitch)common))); } else if (common.Type == DeviceType.LightRGB) { IO.FileUtils.WriteFileByBytes (filePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject ((LightLogic)common))); } } scene.DeviceFilePathList.AddRange (lightScenePathList); scene.Name = etRemark.Text.Trim (); room.Save (typeof (Room).Name + "_" + room.Name); scene.Save (lightScenePath); addLightScenes (); dialog.Close (); }; dialog.Show (); } /// /// 显示该房间里面的所有灯光 /// void addLights () { var lightSwitchList = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.LightSwitch || obj.Type == DeviceType.LightMixSwitch; }); //继电器 foreach (var common in lightSwitchList) { LightSwitch lightSwitch = common as LightSwitch; FrameLayout lightView = new FrameLayout () { Height = Application.GetRealHeight (130), }; lightView.AddTag ("UpdataKey", common.CommonLoopID); lightListView.AddChidren (lightView); Button BtnLightViewNull = new Button () { Y = Application.GetRealHeight(127), Height = Application.GetRealHeight(3), BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.MainColor, }; lightView.AddChidren (BtnLightViewNull); //灯名 var tempLightName = new Button () { X = Application.GetRealWidth (20), TextAlignment = TextAlignment.CenterLeft, Text = common.Name, Enable = false, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.TextColor1, //TextSize = 15, }; lightView.AddChidren (tempLightName); var tempSiwtch = new Button () { Width = Application.GetMinRealAverage (85), 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) { lightSwitch.CurrentBrightness = 100; } else { lightSwitch.CurrentBrightness = 0; } if (lightSwitch.Type == DeviceType.LightMixSwitch) { Control.ControlBytesSend (Command.SetSingleLight, lightSwitch.SubnetID, lightSwitch.DeviceID, new byte [] { (lightSwitch as LightMixSwitch).PhysicsLoopID, (byte)lightSwitch.CurrentBrightness, lightSwitch.DelayTimeHeight, lightSwitch.DelayTimeLow }); } else Control.ControlBytesSend (Command.SetSingleLight, lightSwitch.SubnetID, lightSwitch.DeviceID, new byte [] { lightSwitch.LoopID, lightSwitch.CurrentBrightness, lightSwitch.DelayTimeHeight, lightSwitch.DelayTimeLow }); }; if (lightSwitch.CurrentBrightness == 100) { tempSiwtch.IsSelected = true; } } var ligthDimmingList = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.LightDimming || obj.Type == DeviceType.LightMixDimming || obj.Type == DeviceType.LightDALI; }); foreach (var common in ligthDimmingList) { if (common.Type == DeviceType.LightDALI) { //---- 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); } lightListView.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; 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, 0, 0 }); }; if (light.CurrentBrightness > 0) { tempSwitch.IsSelected = true; } } else { LightDimming lightDimming = common as LightDimming; var lightView = new FrameLayout () { Height = Application.GetRealHeight (130), }; lightView.AddTag ("UpdataKey", common.CommonLoopID); lightListView.AddChidren (lightView); Button BtnLightViewNull = new Button () { Y = Application.GetRealHeight (127), Height = Application.GetRealHeight (3), BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.MainColor, }; lightView.AddChidren (BtnLightViewNull); // 灯光名称 var tempLightName = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (10), Height = Application.GetRealHeight (40), TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.TextColor1, Text = common.Name, }; if (!lightDimming.DimmingFunction) { tempLightName.Gravity = Gravity.CenterVertical; tempLightName.Y = 0; } lightView.AddChidren (tempLightName); //进度条 var tempLightSeekBar = new HorizontalSeekBar () { Width = Application.GetRealWidth (400 - 20), Height = Application.GetRealHeight (130 - 20 - 40), X = Application.GetRealWidth (20), Y = Application.GetRealHeight (10 + 40), Visible = lightDimming.DimmingFunction, Progress = lightDimming.CurrentBrightness, ThumbColor = SkinStyle.Current.ThumbColor, Tag = DateTime.MinValue }; lightView.AddChidren (tempLightSeekBar); Button btnLightSetting = new Button () { Width = Application.GetMinRealAverage (60), Height = Application.GetMinRealAverage (60), Radius = (uint)Application.GetRealHeight (30), X = tempLightSeekBar.Right + Application.GetRealWidth (40), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Light/DimmingSetting.png", SelectedImagePath = "Light/DimmingSetting.png", Visible = lightDimming.DimmingFunction, }; lightView.AddChidren (btnLightSetting); btnLightSetting.MouseUpEventHandler += (sender, e) => { Dialog dialog = new Dialog (); FrameLayout dialogView = new FrameLayout () { BackgroundColor = SkinStyle.Current.DialogColor, Width = Application.GetRealWidth (480), Height = Application.GetRealHeight (520), Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, Gravity = Gravity.Center, }; dialog.AddChidren (dialogView); Button btnTitle = new Button () { Height = Application.GetRealHeight (70), TextAlignment = TextAlignment.Center, Enable = false, TextID = R.MyInternationalizationString.DelayTime2, BackgroundColor = SkinStyle.Current.DialogTitle }; dialogView.AddChidren (btnTitle); #region ---延时开--- Button btnDelayTimeONTitle = new Button () { Width = Application.GetRealWidth (310), Height = Application.GetRealHeight (80), X = Application.GetRealWidth (30), TextAlignment = TextAlignment.CenterLeft, Y = btnTitle.Bottom, TextColor = SkinStyle.Current.TextColor, TextID = R.MyInternationalizationString.DelayTimeON }; dialogView.AddChidren (btnDelayTimeONTitle); Button btnDelayTimeOnReduce = new Button () { Width = Application.GetRealWidth (64), Height = Application.GetRealHeight (62), X = Application.GetRealWidth (90), Y = btnDelayTimeONTitle.Bottom, UnSelectedImagePath = "Light/Light-.png", SelectedImagePath = "Light/Light-On.png", }; dialogView.AddChidren (btnDelayTimeOnReduce); Button btnDelayTimeOnText = new Button () { Width = Application.GetRealWidth (180), Height = Application.GetRealHeight (62), X = btnDelayTimeOnReduce.Right, Y = btnDelayTimeOnReduce.Y, BackgroundColor = SkinStyle.Current.LightDialogTextColor, Text = lightDimming.CustomDelayTimeOpen.ToString () + "s", TextSize = 12, TextColor = SkinStyle.Current.TextColor }; dialogView.AddChidren (btnDelayTimeOnText); Button btnDelayTimeOnAdd = new Button () { Width = Application.GetRealWidth (64), Height = Application.GetRealHeight (62), X = btnDelayTimeOnText.Right, Y = btnDelayTimeOnReduce.Y, UnSelectedImagePath = "Light/Light+.png", SelectedImagePath = "Light/Light+On.png", }; dialogView.AddChidren (btnDelayTimeOnAdd); DateTime newTime = DateTime.MaxValue; byte delayTimeOn = lightDimming.CustomDelayTimeOpen; btnDelayTimeOnAdd.MouseDownEventHandler += (sender2, e2) => { btnDelayTimeOnAdd.IsSelected = true; if (delayTimeOn > 59) return; delayTimeOn++; btnDelayTimeOnText.Text = delayTimeOn.ToString () + "s"; newTime = DateTime.Now; System.Threading.Tasks.Task.Run (() => { while (newTime != DateTime.MaxValue) { System.Threading.Thread.Sleep (100); if ((DateTime.Now - newTime).TotalSeconds > 1) { if (delayTimeOn > 59) break; delayTimeOn++; Application.RunOnMainThread (() => { btnDelayTimeOnText.Text = delayTimeOn.ToString () + "s"; }); } } }); }; btnDelayTimeOnAdd.MouseUpEventHandler += (sender2, e2) => { btnDelayTimeOnAdd.IsSelected = false; newTime = DateTime.MaxValue; }; btnDelayTimeOnReduce.MouseDownEventHandler += (sender2, e2) => { btnDelayTimeOnReduce.IsSelected = true; if (delayTimeOn == 0) return; delayTimeOn--; btnDelayTimeOnText.Text = delayTimeOn.ToString () + "s"; newTime = DateTime.Now; System.Threading.Tasks.Task.Run (() => { while (newTime != DateTime.MaxValue) { System.Threading.Thread.Sleep (100); if ((DateTime.Now - newTime).TotalSeconds > 1) { if (delayTimeOn == 0) break; delayTimeOn--; Application.RunOnMainThread (() => { btnDelayTimeOnText.Text = delayTimeOn.ToString () + "s"; }); } } }); }; btnDelayTimeOnReduce.MouseUpEventHandler += (sender2, e2) => { btnDelayTimeOnReduce.IsSelected = false; newTime = DateTime.MaxValue; }; #endregion #region ---延时关--- Button btnDelayTimeOFFTitle = new Button () { Width = Application.GetRealWidth (310), Height = Application.GetRealHeight (80), X = Application.GetRealWidth (30), TextAlignment = TextAlignment.CenterLeft, Y = btnDelayTimeOnReduce.Bottom, TextColor = SkinStyle.Current.TextColor, TextID = R.MyInternationalizationString.DelayTimeOFF }; dialogView.AddChidren (btnDelayTimeOFFTitle); Button btnDelayTimeOffReduce = new Button () { Width = Application.GetRealWidth (64), Height = Application.GetRealHeight (62), X = Application.GetRealWidth (90), Y = btnDelayTimeOFFTitle.Bottom, UnSelectedImagePath = "Light/Light-.png", SelectedImagePath = "Light/Light-On.png", }; dialogView.AddChidren (btnDelayTimeOffReduce); Button btnDelayTimeOffText = new Button () { Width = Application.GetRealWidth (180), Height = Application.GetRealHeight (62), X = btnDelayTimeOffReduce.Right, Y = btnDelayTimeOffReduce.Y, BackgroundColor = SkinStyle.Current.LightDialogTextColor, Text = lightDimming.CustomDelayTimeClose.ToString () + "s", TextSize = 12, TextColor = SkinStyle.Current.TextColor }; dialogView.AddChidren (btnDelayTimeOffText); Button btnDelayTimeOffAdd = new Button () { Width = Application.GetRealWidth (64), Height = Application.GetRealHeight (62), X = btnDelayTimeOffText.Right, Y = btnDelayTimeOffReduce.Y, UnSelectedImagePath = "Light/Light+.png", SelectedImagePath = "Light/Light+On.png", }; dialogView.AddChidren (btnDelayTimeOffAdd); byte delayTimeOff = lightDimming.CustomDelayTimeClose; btnDelayTimeOffAdd.MouseDownEventHandler += (sender2, e2) => { btnDelayTimeOffAdd.IsSelected = true; if (delayTimeOff > 59) return; delayTimeOff++; btnDelayTimeOffText.Text = delayTimeOff.ToString () + "s"; newTime = DateTime.Now; System.Threading.Tasks.Task.Run (() => { while (newTime != DateTime.MaxValue) { System.Threading.Thread.Sleep (100); if ((DateTime.Now - newTime).TotalSeconds > 1) { if (delayTimeOff > 59) break; delayTimeOff++; Application.RunOnMainThread (() => { btnDelayTimeOffText.Text = delayTimeOff.ToString () + "s"; }); } } }); }; btnDelayTimeOffAdd.MouseUpEventHandler += (sender2, e2) => { btnDelayTimeOffAdd.IsSelected = false; newTime = DateTime.MaxValue; }; btnDelayTimeOffReduce.MouseDownEventHandler += (sender2, e2) => { btnDelayTimeOffReduce.IsSelected = true; if (delayTimeOff == 0) return; delayTimeOff--; btnDelayTimeOffText.Text = delayTimeOff.ToString () + "s"; newTime = DateTime.Now; System.Threading.Tasks.Task.Run (() => { while (newTime != DateTime.MaxValue) { System.Threading.Thread.Sleep (100); if ((DateTime.Now - newTime).TotalSeconds > 1) { if (delayTimeOff == 0) break; delayTimeOff--; Application.RunOnMainThread (() => { btnDelayTimeOffText.Text = delayTimeOff.ToString () + "s"; }); } } }); }; btnDelayTimeOffReduce.MouseUpEventHandler += (sender2, e2) => { btnDelayTimeOffReduce.IsSelected = false; newTime = DateTime.MaxValue; }; #endregion FrameLayout bottomView = new FrameLayout () { Y = Application.GetRealHeight (520 - 80), Height = Application.GetRealHeight (80), BackgroundColor = SkinStyle.Current.DialogTitle }; dialogView.AddChidren (bottomView); Button btnCancel = new Button () { Width = Application.GetRealWidth (239), TextID = R.MyInternationalizationString.Cancel, }; bottomView.AddChidren (btnCancel); btnCancel.MouseUpEventHandler += (sender2, e2) => { dialog.Close (); }; Button btnLine = new Button () { BackgroundColor = SkinStyle.Current.White20Transparent, Width = 1, X = btnCancel.Right, }; bottomView.AddChidren (btnLine); Button btnSave = new Button () { Width = Application.GetRealWidth (239), X = btnLine.Right, TextID = R.MyInternationalizationString.SAVE }; bottomView.AddChidren (btnSave); btnSave.MouseUpEventHandler += (send3er, e3) => { string keyString = lightDimming.CommonLoopID; lightDimming.CustomDelayTimeOpen = delayTimeOn; lightDimming.CustomDelayTimeClose = delayTimeOff; if (room.DelayTime.ContainsKey (lightDimming.CommonLoopID + "Open")) { room.DelayTime [keyString + "Open"] = delayTimeOn; } else { room.DelayTime.Add (keyString + "Open", delayTimeOn); } if (room.DelayTime.ContainsKey (keyString + "Close")) { room.DelayTime [keyString + "Close"] = delayTimeOff; } else { room.DelayTime.Add (keyString + "Close", delayTimeOff); } room.Save (typeof (Room).Name + "_" + room.Name); IO.FileUtils.SaveEquipmentMessage (lightDimming, lightDimming.LoopID.ToString ()); dialog.Close (); }; dialog.Show (); }; //开关按键 var tempSwitch = new Button () { Width = Application.GetRealWidth (90), Height = Application.GetRealHeight (53), X = Application.GetRealWidth (640 - 90 - 20), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/SwitchClose.png", SelectedImagePath = "Item/SwitchOpen.png", }; lightView.AddChidren (tempSwitch); tempLightSeekBar.ProgressChanged += (senderp, ep) => { if (ep > 0) { tempSwitch.IsSelected = true; } else { tempSwitch.IsSelected = false; } if (ep == 0 || ep == 100) { lightDimming.LastOpenBrightness = lightDimming.CurrentBrightness = (byte)ep; if (lightDimming.Type == DeviceType.LightMixDimming) { Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { (lightDimming as LightMixDimming).PhysicsLoopID, (byte)ep, 0, 0 }, SendCount.Zero); } else { Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { lightDimming.LoopID, (byte)ep, 0, 0 }, SendCount.Zero); } tempLightSeekBar.Tag = DateTime.Now; return; } if ((System.DateTime.Now - (DateTime)(tempLightSeekBar.Tag)).TotalMilliseconds < 300) { return; } tempLightSeekBar.Tag = DateTime.Now; if (lightDimming.Type == DeviceType.LightMixDimming) { Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { (lightDimming as LightMixDimming).PhysicsLoopID, (byte)ep, 0, 0 }, SendCount.Zero); } else { Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { lightDimming.LoopID, (byte)ep, 0, 0 }, SendCount.Zero); } lightDimming.LastOpenBrightness = lightDimming.CurrentBrightness = (byte)ep; }; tempLightSeekBar.MouseUpEventHandler += (sender, e) => { //弹起的时候发最后的数据 tempLightSeekBar.Tag = DateTime.Now; if (lightDimming.Type == DeviceType.LightMixDimming) { Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { (lightDimming as LightMixDimming).PhysicsLoopID, (byte)tempLightSeekBar.Progress, 0, 0 }, SendCount.Zero); } else Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { lightDimming.LoopID, (byte)tempLightSeekBar.Progress, 0, 0 }, SendCount.Zero); if (tempLightSeekBar.Progress > 0) { tempSwitch.IsSelected = true; IO.FileUtils.WriteFileByBytes ("Equipment_" + typeof (LightDimming).Name + "_" + lightDimming.SubnetID.ToString () + "_" + lightDimming.DeviceID.ToString () + "_" + (lightDimming.LoopID < 10 ? "0" + lightDimming.LoopID.ToString () : lightDimming.LoopID.ToString ()), CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (lightDimming))); } else { tempSwitch.IsSelected = false; } lightDimming.CurrentBrightness = (byte)tempLightSeekBar.Progress; }; tempLightSeekBar.AddTag ("UpdataKey", lightDimming.CommonLoopID); tempSwitch.MouseUpEventHandler += (sender3, e3) => { tempSwitch.IsSelected = !tempSwitch.IsSelected; if (lightDimming.LastOpenBrightness == 0) { lightDimming.LastOpenBrightness = 100; } if (tempSwitch.IsSelected) { tempLightSeekBar.Progress = lightDimming.LastOpenBrightness; IO.FileUtils.WriteFileByBytes ("Equipment_" + typeof (LightDimming).Name + "_" + lightDimming.SubnetID.ToString () + "_" + lightDimming.DeviceID.ToString () + "_" + (lightDimming.LoopID < 10 ? "0" + lightDimming.LoopID.ToString () : lightDimming.LoopID.ToString ()), CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (lightDimming))); } else { tempLightSeekBar.Progress = 0; } lightDimming.CurrentBrightness = (byte)tempLightSeekBar.Progress; byte delayHeight = 0; byte delayLow = 0; if (lightDimming.CurrentBrightness == 0) { delayHeight = Convert.ToByte (lightDimming.CustomDelayTimeClose / 256); delayLow = Convert.ToByte (lightDimming.CustomDelayTimeClose % 256); } else { delayHeight = Convert.ToByte (lightDimming.CustomDelayTimeOpen / 256); delayLow = Convert.ToByte (lightDimming.CustomDelayTimeOpen % 256); } if (lightDimming.Type == DeviceType.LightMixDimming) { Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { (lightDimming as LightMixDimming).PhysicsLoopID, (byte)tempLightSeekBar.Progress, delayHeight, delayLow }, SendCount.Zero); } else Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { lightDimming.LoopID, (byte)tempLightSeekBar.Progress, delayHeight, delayLow }, SendCount.Zero); tempLightSeekBar.Progress = lightDimming.CurrentBrightness; if (tempSwitch.IsSelected) { tempLightSeekBar.Progress = lightDimming.LastOpenBrightness > 0 ? lightDimming.LastOpenBrightness : 100; } else { tempLightSeekBar.Progress = 0; } }; if (lightDimming.CurrentBrightness > 0) { tempSwitch.IsSelected = true; } } } var ligthRGBList = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.LightRGB; }); foreach (var common in ligthRGBList) { LightLogic lightRGB = common as LightLogic; lightRGB.Type = DeviceType.LightRGB; var lightView = new FrameLayout () { Height = Application.GetRealHeight (130), }; lightView.AddTag ("UpdataKey", lightRGB.CommonLoopID + "RGB"); lightListView.AddChidren (lightView); Button BtnLightViewNull = new Button () { Y = Application.GetRealHeight (127), Height = Application.GetRealHeight (3), BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.MainColor, }; lightView.AddChidren (BtnLightViewNull); // 灯光名称 var tempLightName = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (10), Height = Application.GetRealHeight (40), TextAlignment = TextAlignment.CenterLeft, Text = lightRGB.Name, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.TextColor1, }; if (!lightRGB.DimmingFunction) { tempLightName.Gravity = Gravity.CenterVertical; } if (!lightRGB.DimmingFunction) { tempLightName.Y = 0; } lightView.AddChidren (tempLightName); //进度条 var tempLightSeekBar = new HorizontalSeekBar () { Width = Application.GetRealWidth (400 - 20), Height = Application.GetRealHeight (130 - 20 - 40), X = Application.GetRealWidth (20), Y = Application.GetRealHeight (10 + 40), Visible = lightRGB.DimmingFunction, Progress = lightRGB.CurrentBrightness, Tag = DateTime.MinValue, ThumbColor = SkinStyle.Current.ThumbColor, }; lightView.AddChidren (tempLightSeekBar); #region ---逻辑灯颜色--- Button btnLightSetting = new Button () { Width = Application.GetRealWidth (60), Height = Application.GetRealHeight (60), Radius = (uint)Application.GetRealHeight (30), X = tempLightSeekBar.Right +Application.GetRealWidth(20), Gravity = Gravity.CenterVertical, BackgroundColor = (uint)(0xFF000000 + lightRGB.RStatus * 256 * 256 + lightRGB.GStatus * 256 + lightRGB.BStatus), SelectedBackgroundColor = (uint)(0xFF000000 + lightRGB.RStatus* 256 * 256 + lightRGB.GStatus* 256 + lightRGB.BStatus), }; lightView.AddChidren (btnLightSetting); Button btnRGBSetting = new Button () { Width = Application.GetRealWidth (60), Height = Application.GetRealHeight (60), Radius = (uint)Application.GetRealHeight (30), X = tempLightSeekBar.Right + Application.GetRealWidth (20), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Light/RGBSetting.png", SelectedImagePath = "Light/RGBSetting.png", }; lightView.AddChidren (btnRGBSetting); btnRGBSetting.MouseUpEventHandler += (sender, e) => { byte [] lightLigicBytes = new byte [11]; System.Threading.Tasks.Task.Run (() => { try { Application.RunOnMainThread (() => { MainPage.Loading.Start ("Loading.."); }); lightLigicBytes = Control.ControlBytesSendHasReturn (Command.ReadLogicLoopColor, lightRGB.SubnetID, lightRGB.DeviceID, new byte [] { lightRGB.LoopID }); Application.RunOnMainThread (() => { try { MainPage.Loading.Hide (); if (lightLigicBytes == null) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } if(lightLigicBytes.Length!= 11) { lightLigicBytes = new byte [11]; } Dialog dialog = new Dialog () { BackgroundColor = SkinStyle.Current.ViewColor, }; Button btnTopNull = new Button () { Height = Application.GetRealHeight (36), BackgroundColor = SkinStyle.Current.MainColor, }; dialog.AddChidren (btnTopNull); Button btnTitle = new Button () { Y = btnTopNull.Bottom, Height = Application.GetRealHeight (90), TextAlignment = TextAlignment.Center, Enable = false, TextID = R.MyInternationalizationString.Setting, TextColor = SkinStyle.Current.TextColor1, BackgroundColor = SkinStyle.Current.MainColor, TextSize = 19 }; dialog.AddChidren (btnTitle); Button btnColor = new Button () { Width = Application.GetRealWidth (100), Height = Application.GetRealHeight (40), X = Application.GetRealWidth (20), Y = btnTitle.Bottom + Application.GetRealHeight (50), Radius = 5, BackgroundColor = (uint)(0xFF000000 + lightLigicBytes [6] * 256 * 256 + lightLigicBytes [7] * 256 + lightLigicBytes [8]) }; dialog.AddChidren (btnColor); Button btnColorText = new Button () { Width = Application.GetRealWidth (100), Height = Application.GetRealHeight (40), X = btnColor.X, Y = btnColor.Bottom, TextColor = SkinStyle.Current.TextColor1, Text = "Color" }; dialog.AddChidren (btnColorText); ColorPicker c = new ColorPicker () { X = Application.GetRealWidth (100), Y = btnTitle.Bottom + Application.GetRealHeight (30), Width = Application.GetMinRealAverage (440), Height = Application.GetMinRealAverage (440), ColorImagePath = "Item/PickerColorWheel.png", }; dialog.AddChidren (c); DateTime colorChangeTime = DateTime.MinValue; c.ColorChaged += (sender2, e2) => { if ((DateTime.Now - colorChangeTime).TotalMilliseconds > 500) { lightLigicBytes [6] = e2 [0]; lightLigicBytes [7] = e2 [1]; lightLigicBytes [8] = e2 [2]; Control.ControlBytesSend (Command.SetLogicLoopColor, lightRGB.SubnetID, lightRGB.DeviceID, lightLigicBytes, SendCount.Zero); colorChangeTime = DateTime.Now; btnColor.BackgroundColor = (uint)(0xFF000000 + lightLigicBytes [6] * 256 * 256 + lightLigicBytes [7] * 256 + lightLigicBytes [8]); } }; #region ---延时开--- Button btnDelayTimeONTitle = new Button () { Width = Application.GetRealWidth (310), Height = Application.GetRealHeight (80), X = Application.GetRealWidth (30), TextAlignment = TextAlignment.CenterLeft, Y = c.Bottom, TextColor = SkinStyle.Current.TextColor1, TextID = R.MyInternationalizationString.DelayTimeON }; dialog.AddChidren (btnDelayTimeONTitle); Button btnDelayTimeOnReduce = new Button () { Width = Application.GetRealWidth (64), Height = Application.GetRealHeight (62), X = Application.GetRealWidth (170), Y = btnDelayTimeONTitle.Bottom, UnSelectedImagePath = "Light/Light-.png", SelectedImagePath = "Light/Light-On.png", }; dialog.AddChidren (btnDelayTimeOnReduce); Button btnDelayTimeOnText = new Button () { Width = Application.GetRealWidth (180), Height = Application.GetRealHeight (62), X = btnDelayTimeOnReduce.Right, Y = btnDelayTimeOnReduce.Y, BackgroundColor = SkinStyle.Current.LightDialogTextColor, Text = lightRGB.CustomDelayTimeOpen.ToString () + "s", TextSize = 12, TextColor = SkinStyle.Current.TextColor1, }; dialog.AddChidren (btnDelayTimeOnText); Button btnDelayTimeOnAdd = new Button () { Width = Application.GetRealWidth (64), Height = Application.GetRealHeight (62), X = btnDelayTimeOnText.Right, Y = btnDelayTimeOnReduce.Y, UnSelectedImagePath = "Light/Light+.png", SelectedImagePath = "Light/Light+On.png", }; dialog.AddChidren (btnDelayTimeOnAdd); DateTime newTime = DateTime.MaxValue; byte delayTimeOn = lightRGB.CustomDelayTimeOpen; btnDelayTimeOnAdd.MouseDownEventHandler += (sender2, e2) => { btnDelayTimeOnAdd.IsSelected = true; if (delayTimeOn > 59) return; delayTimeOn++; btnDelayTimeOnText.Text = delayTimeOn.ToString () + "s"; newTime = DateTime.Now; System.Threading.Tasks.Task.Run (() => { while (newTime != DateTime.MaxValue) { System.Threading.Thread.Sleep (100); if ((DateTime.Now - newTime).TotalSeconds > 1) { if (delayTimeOn > 59) break; delayTimeOn++; Application.RunOnMainThread (() => { btnDelayTimeOnText.Text = delayTimeOn.ToString () + "s"; }); } } }); }; btnDelayTimeOnAdd.MouseUpEventHandler += (sender2, e2) => { btnDelayTimeOnAdd.IsSelected = false; newTime = DateTime.MaxValue; }; btnDelayTimeOnReduce.MouseDownEventHandler += (sender2, e2) => { btnDelayTimeOnReduce.IsSelected = true; if (delayTimeOn == 0) return; delayTimeOn--; btnDelayTimeOnText.Text = delayTimeOn.ToString () + "s"; newTime = DateTime.Now; System.Threading.Tasks.Task.Run (() => { while (newTime != DateTime.MaxValue) { System.Threading.Thread.Sleep (100); if ((DateTime.Now - newTime).TotalSeconds > 1) { if (delayTimeOn == 0) break; delayTimeOn--; Application.RunOnMainThread (() => { btnDelayTimeOnText.Text = delayTimeOn.ToString () + "s"; }); } } }); }; btnDelayTimeOnReduce.MouseUpEventHandler += (sender2, e2) => { btnDelayTimeOnReduce.IsSelected = false; newTime = DateTime.MaxValue; }; #endregion #region ---延时关--- Button btnDelayTimeOFFTitle = new Button () { Width = Application.GetRealWidth (310), Height = Application.GetRealHeight (80), X = Application.GetRealWidth (30), TextAlignment = TextAlignment.CenterLeft, Y = btnDelayTimeOnReduce.Bottom + Application.GetRealHeight (10), TextColor = SkinStyle.Current.TextColor1, TextID = R.MyInternationalizationString.DelayTimeOFF }; dialog.AddChidren (btnDelayTimeOFFTitle); Button btnDelayTimeOffReduce = new Button () { Width = Application.GetRealWidth (64), Height = Application.GetRealHeight (62), X = Application.GetRealWidth (170), Y = btnDelayTimeOFFTitle.Bottom, UnSelectedImagePath = "Light/Light-.png", SelectedImagePath = "Light/Light-On.png", }; dialog.AddChidren (btnDelayTimeOffReduce); Button btnDelayTimeOffText = new Button () { Width = Application.GetRealWidth (180), Height = Application.GetRealHeight (62), X = btnDelayTimeOffReduce.Right, Y = btnDelayTimeOffReduce.Y, BackgroundColor = SkinStyle.Current.LightDialogTextColor, Text = lightRGB.CustomDelayTimeClose.ToString () + "s", TextSize = 12, TextColor = SkinStyle.Current.TextColor1, }; dialog.AddChidren (btnDelayTimeOffText); Button btnDelayTimeOffAdd = new Button () { Width = Application.GetRealWidth (64), Height = Application.GetRealHeight (62), X = btnDelayTimeOffText.Right, Y = btnDelayTimeOffReduce.Y, UnSelectedImagePath = "Light/Light+.png", SelectedImagePath = "Light/Light+On.png", }; dialog.AddChidren (btnDelayTimeOffAdd); byte delayTimeOff = lightRGB.CustomDelayTimeClose; btnDelayTimeOffAdd.MouseDownEventHandler += (sender2, e2) => { btnDelayTimeOffAdd.IsSelected = true; if (delayTimeOff > 59) return; delayTimeOff++; btnDelayTimeOffText.Text = delayTimeOff.ToString () + "s"; newTime = DateTime.Now; System.Threading.Tasks.Task.Run (() => { while (newTime != DateTime.MaxValue) { System.Threading.Thread.Sleep (100); if ((DateTime.Now - newTime).TotalSeconds > 1) { if (delayTimeOff > 59) break; delayTimeOff++; Application.RunOnMainThread (() => { btnDelayTimeOffText.Text = delayTimeOff.ToString () + "s"; }); } } }); }; btnDelayTimeOffAdd.MouseUpEventHandler += (sender2, e2) => { btnDelayTimeOffAdd.IsSelected = false; newTime = DateTime.MaxValue; }; btnDelayTimeOffReduce.MouseDownEventHandler += (sender2, e2) => { btnDelayTimeOffReduce.IsSelected = true; if (delayTimeOff == 0) return; delayTimeOff--; btnDelayTimeOffText.Text = delayTimeOff.ToString () + "s"; newTime = DateTime.Now; System.Threading.Tasks.Task.Run (() => { while (newTime != DateTime.MaxValue) { System.Threading.Thread.Sleep (100); if ((DateTime.Now - newTime).TotalSeconds > 1) { if (delayTimeOff == 0) break; delayTimeOff--; Application.RunOnMainThread (() => { btnDelayTimeOffText.Text = delayTimeOff.ToString () + "s"; }); } } }); }; btnDelayTimeOffReduce.MouseUpEventHandler += (sender2, e2) => { btnDelayTimeOffReduce.IsSelected = false; newTime = DateTime.MaxValue; }; #endregion var curSeekBarColor = (uint)(0xFF000000 + lightLigicBytes [6] * 256 * 256 + lightLigicBytes [7] * 256 + lightLigicBytes [8]); var seekBarLighting = new HorizontalSeekBar () { X = Application.GetRealWidth (50), Y = btnDelayTimeOffReduce.Bottom + Application.GetRealHeight (50), Width = Application.GetRealWidth (480), Height = Application.GetRealHeight (50), Progress = lightLigicBytes [1], ThumbColor = curSeekBarColor == 0xFFFFFFFF ? SkinStyle.Current.ThumbColor : curSeekBarColor, Max = 100, }; dialog.AddChidren (seekBarLighting); var btnLightingText = new Button () { X = seekBarLighting.Right + Application.GetRealWidth (15), Y = seekBarLighting.Y, Width = Application.GetRealWidth (80), Height = Application.GetRealHeight (50), TextColor = SkinStyle.Current.TextColor1, Text = lightLigicBytes [1].ToString () + "%" }; dialog.AddChidren (btnLightingText); seekBarLighting.ProgressChanged += (sender3, e3) => { if ((DateTime.Now - colorChangeTime).TotalMilliseconds > 50) { lightLigicBytes [1] = (byte)e3; Control.ControlBytesSend (Command.SetLogicLoopColor, lightRGB.SubnetID, lightRGB.DeviceID, lightLigicBytes, SendCount.Zero); colorChangeTime = DateTime.Now; btnLightingText.Text = e3.ToString () + "%"; lightRGB.LastOpenBrightness = (byte)e3; } }; var bottomView = new FrameLayout () { Y = dialog.Height - Application.GetRealHeight (100), Height = Application.GetRealHeight (100), BackgroundColor = SkinStyle.Current.MainColor }; dialog.AddChidren (bottomView); Button btnCancel = new Button () { Width = Application.GetRealWidth (319), TextID = R.MyInternationalizationString.Cancel, TextColor = SkinStyle.Current.TextColor1 }; bottomView.AddChidren (btnCancel); btnCancel.MouseUpEventHandler += (sender2, e2) => { dialog.Close (); }; Button btnLine = new Button () { BackgroundColor = SkinStyle.Current.White20Transparent, Width = 1, X = btnCancel.Right, }; bottomView.AddChidren (btnLine); Button btnSave = new Button () { Width = Application.GetRealWidth (319), X = btnLine.Right, TextColor = SkinStyle.Current.TextColor1, TextID = R.MyInternationalizationString.SAVE }; bottomView.AddChidren (btnSave); btnSave.MouseUpEventHandler += (send3er, e3) => { if (lightRGB.CustomDelayTimeOpen != delayTimeOn || lightRGB.CustomDelayTimeClose != delayTimeOff) { string keyString = lightRGB.SubnetID.ToString () + "_" + lightRGB.DeviceID.ToString () + "_" + lightRGB.LoopID.ToString (); lightRGB.CustomDelayTimeOpen = delayTimeOn; lightRGB.CustomDelayTimeClose = delayTimeOff; if (room.DelayTime.ContainsKey (keyString + "Open")) { room.DelayTime [keyString + "Open"] = delayTimeOn; } else { room.DelayTime.Add (keyString + "Open", delayTimeOn); } if (room.DelayTime.ContainsKey (keyString + "Close")) { room.DelayTime [keyString + "Close"] = delayTimeOff; } else { room.DelayTime.Add (keyString + "Close", delayTimeOff); } room.Save (typeof (Room).Name + "_" + room.Name); } if (lightLigicBytes [6] != lightRGB.RStatus || lightLigicBytes [7] != lightRGB.GStatus || lightLigicBytes [8] != lightRGB.BStatus) { lightRGB.RStatus = lightLigicBytes [6]; lightRGB.GStatus = lightLigicBytes [7]; lightRGB.BStatus = lightLigicBytes [8]; btnLightSetting.BackgroundColor = (uint)(0xFF000000 + lightLigicBytes [6] * 256 * 256 + lightLigicBytes [7] * 256 + lightLigicBytes [8]); IO.FileUtils.SaveEquipmentMessage (lightRGB, lightRGB.LoopID.ToString ()); } dialog.Close (); }; dialog.Show (); } catch { } }); } catch { } }); }; #endregion //开关按键 var tempSwitch = new Button () { Width = Application.GetRealWidth (90), Height = Application.GetRealHeight (53), X = Application.GetRealWidth (640 - 90 - 20), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/SwitchClose.png", SelectedImagePath = "Item/SwitchOpen.png", }; lightView.AddChidren (tempSwitch); tempLightSeekBar.ProgressChanged += (senderp, ep) => { if ((System.DateTime.Now - (DateTime)(tempLightSeekBar.Tag)).TotalMilliseconds < 500) { return; } tempLightSeekBar.Tag = DateTime.Now; Control.ControlBytesSend (Command.SetLogicLoopColor, lightRGB.SubnetID, lightRGB.DeviceID, new byte [] { lightRGB.LoopID, lightRGB.CurrentBrightness, 254, 0,0, 3,lightRGB.RStatus,lightRGB.GStatus,lightRGB.BStatus,0,0}, SendCount.Zero); if (tempLightSeekBar.Progress > 0) { tempSwitch.IsSelected = true; } else { tempSwitch.IsSelected = false; } lightRGB.CurrentBrightness = (byte)ep; }; tempLightSeekBar.MouseUpEventHandler += (sender, e) => { //弹起的时候发最后的数据 tempLightSeekBar.Tag = DateTime.Now; lightRGB.CurrentBrightness = Convert.ToByte (tempLightSeekBar.Progress); Control.ControlBytesSend (Command.SetLogicLoopColor, lightRGB.SubnetID, lightRGB.DeviceID, new byte [] { lightRGB.LoopID, lightRGB.CurrentBrightness, 254, 0,0, 3,lightRGB.RStatus,lightRGB.GStatus,lightRGB.BStatus,0,0}, SendCount.Zero); if (tempLightSeekBar.Progress > 0) { tempSwitch.IsSelected = true; lightRGB.LastOpenBrightness = (byte)tempLightSeekBar.Progress; IO.FileUtils.WriteFileByBytes ("Equipment_" + typeof (LightDimming).Name + "_" + lightRGB.SubnetID.ToString () + "_" + lightRGB.DeviceID.ToString () + "_" + (lightRGB.LoopID < 10 ? "0" + lightRGB.LoopID.ToString () : lightRGB.LoopID.ToString ()), CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (lightRGB))); } else { tempSwitch.IsSelected = false; } lightRGB.CurrentBrightness = (byte)tempLightSeekBar.Progress; }; tempLightSeekBar.AddTag ("UpdataKey", lightRGB.CommonLoopID + "RGB"); tempSwitch.MouseUpEventHandler += (sender3, e3) => { tempSwitch.IsSelected = !tempSwitch.IsSelected; if (lightRGB.LastOpenBrightness == 0) { lightRGB.LastOpenBrightness = 100; } if (tempSwitch.IsSelected) { tempLightSeekBar.Progress = lightRGB.LastOpenBrightness; IO.FileUtils.WriteFileByBytes ("Equipment_" + typeof (LightDimming).Name + "_" + lightRGB.SubnetID.ToString () + "_" + lightRGB.DeviceID.ToString () + "_" + (lightRGB.LoopID < 10 ? "0" + lightRGB.LoopID.ToString () : lightRGB.LoopID.ToString ()), CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (lightRGB))); } else { tempLightSeekBar.Progress = 0; } lightRGB.CurrentBrightness = (byte)tempLightSeekBar.Progress; byte delayHeight = 0; byte delayLow = 0; if (lightRGB.CurrentBrightness == 0) { delayHeight = Convert.ToByte (lightRGB.CustomDelayTimeClose / 256); delayLow = Convert.ToByte (lightRGB.CustomDelayTimeClose % 256); } else { delayHeight = Convert.ToByte (lightRGB.CustomDelayTimeOpen / 256); delayLow = Convert.ToByte (lightRGB.CustomDelayTimeOpen % 256); } Control.ControlBytesSend (Command.SetLogicLoopColor, lightRGB.SubnetID, lightRGB.DeviceID, new byte [] { lightRGB.LoopID, lightRGB.CurrentBrightness, 254, lightRGB.CustomDelayTimeOpen,lightRGB.CustomDelayTimeClose, 3,lightRGB.RStatus,lightRGB.GStatus,lightRGB.BStatus,0,0}, SendCount.Zero); tempLightSeekBar.Progress = lightRGB.CurrentBrightness; }; if (lightRGB.CurrentBrightness > 0) { tempSwitch.IsSelected = true; } } } /// /// 读取设备状态 /// static void readStatus (Room room) { new System.Threading.Thread (() => { System.Collections.Generic.List readList = new System.Collections.Generic.List (); 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.LightMixDimming || obj.Type == DeviceType.LightMixSwitch); }); foreach (Common common in list) { var s = common.Type + "_" + common.SubnetID + "_" + common.DeviceID; //已经读取过当前设备就不再读取 if (readList.Contains (s)) { continue; } readList.Add (s); Control.ControlBytesSendHasReturn (Command.ReadLightEquipmentAllLoopBrightness, common.SubnetID, common.DeviceID, new byte [] { }); } //var rcuLightList = room.DeviceList.FindAll ((obj) => { // return obj.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now && (); //}); //foreach (Common common in rcuLightList) { // var s = common.Type + "_" + common.SubnetID + "_" + common.DeviceID + "_" + common.LoopID; // //已经读取过当前设备就不再读取 // if (readList.Contains (s)) { // continue; // } // readList.Add (s); // Control.ControlBytesSendHasReturn (Command.ReadLightEquipmentAllLoopBrightness, common.SubnetID, common.DeviceID, new byte [] { }); //} }) { IsBackground = true}.Start(); } } }