using Shared.SimpleControl.Phone; using System; using System.Collections.Generic; namespace Shared.SimpleControl.Pad { /// /// 用户房间灯光控制界面 /// public class UserLightPage : FrameLayout { /// /// 当前打开的灯光界面 /// public static UserLightPage curView; VerticalScrolViewLayout lightListView; VerticalScrolViewLayout lightSceneListView; Button btnLastClickScene; /// /// 显示当前房间灯光设备 /// /// Room. public UserLightPage (Room room) { curView = this; readStatus (room); BackgroundColor = SkinStyle.Current.MainColor; } /// /// 接受到灯光发出的数据之后更新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 (HorizontalScrolViewLayout)) { var rowView = (HorizontalScrolViewLayout)curView.lightListView.GetChildren (i); for (int k = 0; k < rowView.ChildrenCount; k++) { if (rowView.GetChildren (k).GetType () == typeof (RowLayout)) { var frameLayout = (RowLayout)rowView.GetChildren (k); 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 (Room room) { VerticalScrolViewLayout bodyMainView = new VerticalScrolViewLayout () { ScrollEnabled = false }; AddChidren (bodyMainView); FrameLayout LightTopVIew = new FrameLayout () { Height = Application.GetRealHeight (520) }; bodyMainView.AddChidren (LightTopVIew); FrameLayout roomBackgroundImage = new FrameLayout () { X = Application.GetRealWidth (10), Y = Application.GetRealHeight (10), Width = Application.GetRealWidth (920), Height = Application.GetRealHeight (520), }; LightTopVIew.AddChidren (roomBackgroundImage); roomBackgroundImage.BackgroundImagePath = room.BackGroundImage; 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); }; #region --灯光场景-- FrameLayout LightSceneView = new FrameLayout () { X = roomBackgroundImage.Right, Y = roomBackgroundImage.Y, Width = Application.GetRealWidth (640), Height = Application.GetRealHeight (520), }; LightTopVIew.AddChidren (LightSceneView); var btnAddLightScene = new Button () { Height = Application.GetRealHeight (80+40), BackgroundColor = 0xFF2f2f2f, TextID = R.MyInternationalizationString.AddLightScene, }; LightSceneView.AddChidren (btnAddLightScene); lightSceneListView = new VerticalScrolViewLayout () { Y = btnAddLightScene.Bottom, Height = Application.GetRealHeight (520 - 120), }; LightSceneView.AddChidren (lightSceneListView); btnAddLightScene.MouseUpEventHandler += (sender, e) => { Dialog dialog = new Dialog () { BackgroundColor = SkinStyle.Current.TextColor1, Width = Application.GetRealWidth (1050), Height = Application.GetRealHeight (1050), }; Button btnTitle = new Button () { Height = Application.GetRealHeight (90), TextAlignment = TextAlignment.Center, Enable = false, TextID = R.MyInternationalizationString.AddLightScene, BackgroundColor = 0xFF333333 }; dialog.AddChidren (btnTitle); FrameLayout remarkView = new FrameLayout () { Height = Application.GetRealHeight (135), Y = btnTitle.Bottom, BackgroundColor = SkinStyle.Current.MainColor }; dialog.AddChidren (remarkView); Button btnRemark = new Button () { Width = Application.GetRealWidth (110), X = Application.GetRealWidth (20), TextID = R.MyInternationalizationString.Remark }; remarkView.AddChidren (btnRemark); EditText etRemark = new EditText () { Width = Application.GetRealWidth (840), Height = Application.GetRealHeight (80), X = btnRemark.Right + Application.GetRealWidth (10), Y = Application.GetRealHeight (25), BorderColor = 0xFF333333, BorderWidth = 1, BackgroundColor = 0xFF2f2f2f, Radius = 5, }; remarkView.AddChidren (etRemark); VerticalScrolViewLayout verticalScrolView = new VerticalScrolViewLayout () { Height = Application.GetRealHeight (500), Y = remarkView.Bottom, }; dialog.AddChidren (verticalScrolView); FrameLayout inScrolView_DeviceListView = new FrameLayout (); 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); }); List lightScenePathList = new List (); List lightSceneList = new List (); if (lights.Count > 10) { inScrolView_DeviceListView.Height = Application.GetRealHeight (lights.Count / 2 * 100); } var scene = new Scene (); foreach (var light in lights) { Button btnEquipment = new Button () { Width = Application.GetRealWidth (330), Height = Application.GetRealHeight (115), X = Application.GetRealHeight (30), Y = Application.GetRealHeight (5), TextAlignment = TextAlignment.Center, UnSelectedImagePath = "Item/BorderAlphaSave.png", SelectedImagePath = "Item/BorderAlphaSaveSelected.png", TextColor = 0xFF000000, Tag = light }; if (btnEquipmentCont < 3) { btnEquipment.X = btnEquipmentCont * btnEquipment.Width + Application.GetRealWidth (20); btnEquipment.Y = Application.GetRealHeight (5); btnEquipmentCont++; } else { btnEquipment.X = btnEquipmentCont % 3 * btnEquipment.Width + Application.GetRealWidth (20); btnEquipment.Y = (int)btnEquipmentCont / 3 * btnEquipment.Height + Application.GetRealHeight (5); btnEquipmentCont++; } btnEquipment.Text = light.Name; inScrolView_DeviceListView.AddChidren (btnEquipment); btnEquipment.MouseUpEventHandler += (sende3r, e3) => { Common common = (Common)btnEquipment.Tag; //btnEquipment.IsSelected = !btnEquipment.IsSelected; if (btnEquipment.IsSelected) { var filePath = scene.DeviceFilePathList.Find ((obj) => { return obj.EndsWith (common.GetType ().Name + "_" + common.SubnetID.ToString () + "_" + common.DeviceID.ToString () + "_" + (common.LoopID < 10 ? "0" + common.LoopID : common.LoopID.ToString ())); }); scene.DeviceFilePathList.Remove (filePath); 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 ()); scene.DeviceFilePathList.Add (filePath); lightScenePathList.Add (filePath); lightSceneList.Add (common); btnEquipment.IsSelected = true; } }; } FrameLayout iconLayout = new FrameLayout () { Y = verticalScrolView.Bottom + Application.GetRealHeight (10), Height = Application.GetRealHeight (175), Width = Application.GetRealWidth (1048), BackgroundColor = SkinStyle.Current.TextColor1 }; dialog.AddChidren (iconLayout); HorizontalScrolViewLayout iconView = new HorizontalScrolViewLayout () { Height = Application.GetRealHeight (170), BackgroundColor = 0xFF333333, }; iconLayout.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 (170), Height = Application.GetRealHeight (170), 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 (5), BackgroundColor = SkinStyle.Current.TextColor1 }; 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; else scene.SceneIconPath = ""; }; } FrameLayout bottomView = new FrameLayout () { Y = iconLayout.Bottom, Height = Application.GetRealHeight (150), BackgroundColor = SkinStyle.Current.MainColor }; dialog.AddChidren (bottomView); Button btnCancel = new Button () { Width = Application.GetRealWidth (522), TextID = R.MyInternationalizationString.Cancel, }; bottomView.AddChidren (btnCancel); btnCancel.MouseUpEventHandler += (sender2, e2) => { dialog.Close (); }; Button btnLine = new Button () { BackgroundColor = 0xFF333333, Width = Application.GetRealWidth (6), X = btnCancel.Right, }; bottomView.AddChidren (btnLine); Button btnSave = new Button () { Width = Application.GetRealWidth (522), X = btnLine.Right, TextID = R.MyInternationalizationString.SAVE }; bottomView.AddChidren (btnSave); btnSave.MouseUpEventHandler += (sender3, e3) => { if (string.IsNullOrEmpty (etRemark.Text.Trim ())) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterSceneName), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } string lightSceneRemark = room.Name + "_LightScene_" + etRemark.Text.Trim (); if (room.LightScenePathList.Contains (lightSceneRemark)) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } room.LightScenePathList.Add (lightSceneRemark); for (int i = 0; i < lightScenePathList.Count; i++) { //Common commonDevice = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (commonBytes)); // IO.FileUtils.WriteFileByBytes (filePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (commonDevice))); 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))); } //scene.DeviceFilePathList.Add (filePath); } scene.Name = etRemark.Text.Trim (); scene.Save (lightSceneRemark); room.Save (typeof (Room).Name + "_" + room.Name); addLightScenes (room); dialog.Close (); }; dialog.Show (); }; #endregion Button btnGGBlack = new Button () { BackgroundColor = 0xFF000000, Height = Application.GetRealHeight (30) }; bodyMainView.AddChidren (btnGGBlack); Button btnNull = new Button () { Height = Application.GetRealHeight (40), }; bodyMainView.AddChidren (btnNull); lightListView = new VerticalScrolViewLayout () { Height = Application.GetRealHeight (800), }; bodyMainView.AddChidren (lightListView); //加载灯光场景 addLightScenes (room); //加载灯光 addLights (room); } void addLightScenes (Room room) { lightSceneListView.RemoveAll (); HorizontalScrolViewLayout hView = new HorizontalScrolViewLayout () { Height = Application.GetRealHeight (130), ScrollEnabled = false, }; lightSceneListView.AddChidren (hView); btnLastClickScene = new Button () { Height = Application.GetRealHeight (10), BackgroundColor = SkinStyle.Current.SelectedColor, Y = Application.GetRealHeight (120), }; 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 (room);//移除空的场景,重新加载界面 return; } if (room.LightScenePathList.IndexOf (lightSceneFilePath) > 1) { if (room.LightScenePathList.IndexOf (lightSceneFilePath) % 2 == 0) { hView = new HorizontalScrolViewLayout () { Height = Application.GetRealHeight (130), }; lightSceneListView.AddChidren (hView); } } RowLayout lightSceneView = new RowLayout () { X = Application.GetRealWidth ((room.LightScenePathList.IndexOf (lightSceneFilePath) % 2) * 110) - 1, Width = Application.GetRealWidth (320), Radius = 1, BorderColor = SkinStyle.Current.MainColor, BorderWidth = 1, }; hView.AddChidren (lightSceneView); if (room.LightScenePathList.IndexOf (lightSceneFilePath) % 2 == 0) { Button btnLineV = new Button () { Width = 1, BackgroundColor = 0xFF333333, }; hView.AddChidren (btnLineV); } Button 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 (room); }; Button btnSIcon = new Button () { Y = Application.GetRealHeight (20), Height = Application.GetRealHeight (100), Width = Application.GetRealWidth (111), 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 }; lightSceneView.AddChidren (btnSceneRemark); btnSceneRemark.MouseLongEventHandler += (sender, e) => { #region ---修改灯管场景--- Dialog dialog = new Dialog () { BackgroundColor = SkinStyle.Current.TextColor1, Width = Application.GetRealWidth (1050), Height = Application.GetRealHeight (1050), }; Button btnTitle = new Button () { Height = Application.GetRealHeight (90), TextAlignment = TextAlignment.Center, Enable = false, TextID = R.MyInternationalizationString.ModifyLightScene, BackgroundColor = 0xFF333333 }; dialog.AddChidren (btnTitle); FrameLayout remarkView = new FrameLayout () { Height = Application.GetRealHeight (135), Y = btnTitle.Bottom, BackgroundColor = SkinStyle.Current.MainColor }; dialog.AddChidren (remarkView); Button btnRemark = new Button () { Width = Application.GetRealWidth (110), X = Application.GetRealWidth (20), TextID = R.MyInternationalizationString.Remark }; remarkView.AddChidren (btnRemark); EditText etRemark = new EditText () { Width = Application.GetRealWidth (840), Height = Application.GetRealHeight (80), X = btnRemark.Right + Application.GetRealWidth (10), Y = Application.GetRealHeight (25), BorderColor = 0xFF333333, BorderWidth = 1, BackgroundColor = 0xFF2f2f2f, Radius = 5, Text = scene.Name, }; remarkView.AddChidren (etRemark); VerticalScrolViewLayout verticalScrolView = new VerticalScrolViewLayout () { Height = Application.GetRealHeight (500), Y = remarkView.Bottom + Application.GetRealHeight (10), }; dialog.AddChidren (verticalScrolView); FrameLayout inScrolView_DeviceListView = new FrameLayout (); 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.LightLogic || obj.Type == DeviceType.LightRGB); }); List lightScenePathList = new List (); List lightSceneList = new List (); if (lights.Count > 10) { inScrolView_DeviceListView.Height = Application.GetRealHeight (lights.Count / 2 * 100); } foreach (var light in lights) { Button btnEquipment = new Button () { Width = Application.GetRealWidth (330), Height = Application.GetRealHeight (115), X = Application.GetRealHeight (30), Y = Application.GetRealHeight (5), TextAlignment = TextAlignment.Center, UnSelectedImagePath = "Item/BorderAlphaSave.png", SelectedImagePath = "Item/BorderAlphaSaveSelected.png", TextColor = 0xFF000000, Tag = light, }; 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 < 3) { btnEquipment.X = btnEquipmentCont * btnEquipment.Width + Application.GetRealWidth (20); btnEquipment.Y = Application.GetRealHeight (5); btnEquipmentCont++; } else { btnEquipment.X = btnEquipmentCont % 3 * btnEquipment.Width + Application.GetRealWidth (20); btnEquipment.Y = (int)btnEquipmentCont / 3 * btnEquipment.Height + Application.GetRealHeight (5); btnEquipmentCont++; } btnEquipment.Text = light.Name; inScrolView_DeviceListView.AddChidren (btnEquipment); btnEquipment.MouseUpEventHandler += (sende3r, e3) => { Common common = (Common)btnEquipment.Tag; if (btnEquipment.IsSelected) { 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 ())); }); scene.DeviceFilePathList.Remove (filePath); IO.FileUtils.DeleteFile (filePath); lightScenePathList.Remove (filePath); lightSceneList.Remove (common); btnEquipment.IsSelected = false; } else { var filePath = "RoomLightScene" + DateTime.Now.Ticks + "_" + common.Type + "_" + common.SubnetID.ToString () + "_" + common.DeviceID.ToString () + "_" + (common.LoopID < 10 ? "0" + common.LoopID : common.LoopID.ToString ()); scene.DeviceFilePathList.Add (filePath); lightScenePathList.Add (filePath); lightSceneList.Add (common); btnEquipment.IsSelected = true; } }; } FrameLayout iconLayout = new FrameLayout () { Y = verticalScrolView.Bottom + Application.GetRealHeight (10), Height = Application.GetRealHeight (175), Width = Application.GetRealWidth (1048), BackgroundColor = SkinStyle.Current.TextColor1 }; dialog.AddChidren (iconLayout); HorizontalScrolViewLayout iconView = new HorizontalScrolViewLayout () { Height = Application.GetRealHeight (170), BackgroundColor = 0xFF333333, }; iconLayout.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 (170), Height = Application.GetRealHeight (170), UnSelectedImagePath = iconPath, SelectedImagePath = iconPathOn, IsSelected = scene.SceneIconPath == iconPath ? true : false, Tag = i }; iconView.AddChidren (btnIcon); 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; else scene.SceneIconPath = ""; }; if (i < 6) { Button btnLineIcon = new Button () { Width = Application.GetRealWidth (2), BackgroundColor = SkinStyle.Current.TextColor1, }; iconView.AddChidren (btnLineIcon); } } FrameLayout bottomView = new FrameLayout () { Y = iconLayout.Bottom, Height = Application.GetRealHeight (150), BackgroundColor = SkinStyle.Current.MainColor }; dialog.AddChidren (bottomView); Button btnCancel = new Button () { Width = Application.GetRealWidth (522), TextID = R.MyInternationalizationString.Cancel, }; bottomView.AddChidren (btnCancel); btnCancel.MouseUpEventHandler += (sender2, e2) => { dialog.Close (); }; Button btnLine = new Button () { BackgroundColor = 0xFF333333, Width = Application.GetRealWidth (6), X = btnCancel.Right, }; bottomView.AddChidren (btnLine); Button btnSave = new Button () { Width = Application.GetRealWidth (522), X = btnLine.Right, TextID = R.MyInternationalizationString.SAVE }; bottomView.AddChidren (btnSave); btnSave.MouseUpEventHandler += (sender3, e3) => { if (string.IsNullOrEmpty (etRemark.Text.Trim ())) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterSceneName), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } string lightSceneRemark = room.Name + "_LightScene_" + etRemark.Text.Trim (); if (etRemark.Text.Trim () != scene.Name) { if (room.LightScenePathList.Contains (etRemark.Text.Trim ())) { 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 (lightSceneRemark); room.Save (typeof (Room).Name + "_" + room.Name); scene.Name = etRemark.Text.Trim (); } 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))); } } scene.Save (lightSceneRemark); addLightScenes (room); dialog.Close (); }; dialog.Show (); #endregion }; btnSceneRemark.MouseUpEventHandler += (sender, e) => { try { btnLastClickScene.RemoveFromParent (); lightSceneView.AddChidren (btnLastClickScene); MainPage.Loading.Start (); System.Threading.Tasks.Task.Run (() => { foreach (var deviceFilePath in scene.DeviceFilePathList) { if (deviceFilePath.Split ('_') [1] == DeviceType.LightDimming.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 (deviceFilePath.Split ('_') [1] == DeviceType.LightSwitch.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 (deviceFilePath.Split ('_') [1] == 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 (); } }; } } /// /// 显示该房间里面的所有灯光 /// public static void addLights (Room room, int lightCount = 0, VerticalScrolViewLayout allView = null) { var lightSwitchList = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.LightSwitch ||obj.Type == DeviceType.LightMixSwitch; }); //继电器 HorizontalScrolViewLayout HorizontalScrolView = new HorizontalScrolViewLayout () { X = Application.GetRealWidth (0), Width = Application.GetRealWidth (760), Height = Application.GetRealHeight (200), ScrollEnabled = false }; foreach (var common in lightSwitchList) { if (lightCount % 2 == 0) { HorizontalScrolView = new HorizontalScrolViewLayout () { X = Application.GetRealWidth (0), Height = Application.GetRealHeight (200), Enable = false, ScrollEnabled = false }; if (allView != null) allView.AddChidren (HorizontalScrolView); else curView.lightListView.AddChidren (HorizontalScrolView); } Button btnNull = new Button () { Width = Application.GetRealWidth (20), }; HorizontalScrolView.AddChidren (btnNull); lightCount++; LightSwitch lightSwitch = common as LightSwitch; FrameLayout lightView = new FrameLayout () { Y = Application.GetRealHeight (10), Width = Application.GetRealWidth (750), Height = Application.GetRealHeight (180), BackgroundColor = 0xFF2f2f2f, BorderWidth = 0, BorderColor = SkinStyle.Current.Transparent, }; lightView.AddTag ("UpdataKey", lightSwitch.CommonLoopID); HorizontalScrolView.AddChidren (lightView); //灯名 var tempLightName = new Button () { X = Application.GetRealWidth (20), TextAlignment = TextAlignment.CenterLeft, Text = lightSwitch.Name, Enable = false, //TextSize = 15, }; lightView.AddChidren (tempLightName); var tempSiwtch = new Button () { Width = Application.GetRealWidth (85), Height = Application.GetRealHeight (53), X = Application.GetRealWidth (750 - 90 - 50), 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; } 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; }); foreach (var common in ligthDimmingList) { if (lightCount % 2 == 0) { HorizontalScrolView = new HorizontalScrolViewLayout () { X = Application.GetRealWidth (0), Height = Application.GetRealHeight (200), ScrollEnabled = false }; if (allView != null) allView.AddChidren (HorizontalScrolView); else curView.lightListView.AddChidren (HorizontalScrolView); } Button btnNull = new Button () { Width = Application.GetRealWidth (20), }; HorizontalScrolView.AddChidren (btnNull); lightCount++; LightDimming lightDimming = common as LightDimming; FrameLayout lightView = new FrameLayout () { Y = Application.GetRealHeight (10), Width = Application.GetRealWidth (750), Height = Application.GetRealHeight (180), BackgroundColor = 0xFF2f2f2f, BorderWidth = 0, BorderColor = SkinStyle.Current.Transparent }; lightView.AddTag ("UpdataKey", lightDimming.CommonLoopID); HorizontalScrolView.AddChidren (lightView); // 灯光名称 var tempLightName = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (20), Height = Application.GetRealHeight (40), TextAlignment = TextAlignment.CenterLeft, //TextAlignment = lightDimming.DimmingFunction ? TextAlignment.TopLeft : TextAlignment.CenterLeft, Text = lightDimming.Name, }; if (!lightDimming.DimmingFunction) { tempLightName.Gravity = Gravity.CenterVertical; } if (!lightDimming.DimmingFunction) { tempLightName.Y = 0; } lightView.AddChidren (tempLightName); //进度条 var tempLightSeekBar = new HorizontalSeekBar () { Width = Application.GetRealWidth (450), Height = Application.GetRealHeight (130 - 20 - 40), X = Application.GetRealWidth (20), Y = Application.GetRealHeight (30 + 40), Visible = lightDimming.DimmingFunction, Progress = lightDimming.CurrentBrightness, ThumbColor = 0xFFFFFFFF, Tag = DateTime.MinValue }; lightView.AddChidren (tempLightSeekBar); Button btnLightSetting = new Button () { Width = Application.GetRealWidth (80), Height = Application.GetRealHeight (80), Radius = (uint)Application.GetRealHeight (30), X = tempLightSeekBar.Right + Application.GetRealWidth (40), Y = Application.GetRealHeight (65), UnSelectedImagePath = "Light/DimmingSetting.png", SelectedImagePath = "Light/DimmingSetting.png", Visible = lightDimming.DimmingFunction, }; lightView.AddChidren (btnLightSetting); btnLightSetting.MouseUpEventHandler += (sender, e) => { Dialog dialog = new Dialog () { BackgroundColor = SkinStyle.Current.TextColor1, Width = Application.GetRealWidth (480), Height = Application.GetRealHeight (520), }; Button btnTitle = new Button () { Height = Application.GetRealHeight (70), TextAlignment = TextAlignment.Center, Enable = false, TextID = R.MyInternationalizationString.DelayTime2, BackgroundColor = 0xFF333333 }; dialog.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 = 0xFF000000, TextID = R.MyInternationalizationString.DelayTimeON }; dialog.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", }; dialog.AddChidren (btnDelayTimeOnReduce); Button btnDelayTimeOnText = new Button () { Width = Application.GetRealWidth (180), Height = Application.GetRealHeight (62), X = btnDelayTimeOnReduce.Right, Y = btnDelayTimeOnReduce.Y, BackgroundColor = 0xFFDBDDDF, Text = lightDimming.CustomDelayTimeOpen.ToString () + "s", TextSize = 12, TextColor = 0xFF000000 }; 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 = 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 = 0xFF000000, TextID = R.MyInternationalizationString.DelayTimeOFF }; dialog.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", }; dialog.AddChidren (btnDelayTimeOffReduce); Button btnDelayTimeOffText = new Button () { Width = Application.GetRealWidth (180), Height = Application.GetRealHeight (62), X = btnDelayTimeOffReduce.Right, Y = btnDelayTimeOffReduce.Y, BackgroundColor = 0xFFDBDDDF, Text = lightDimming.CustomDelayTimeClose.ToString () + "s", TextSize = 12, TextColor = 0xFF000000 }; 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 = 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.MainColor }; dialog.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 = 0xFF333333, 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); dialog.Close (); }; dialog.Show (); }; //开关按键 var tempSwitch = new Button () { Width = Application.GetRealWidth (90), Height = Application.GetRealHeight (53), X = Application.GetRealWidth (750 - 90 - 50), Y = Application.GetRealHeight (75), 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.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { lightDimming.LoopID, (byte)ep, 0, 0 }, SendCount.Zero); if (tempLightSeekBar.Progress > 0) { tempSwitch.IsSelected = true; } else { tempSwitch.IsSelected = false; } lightDimming.CurrentBrightness = (byte)ep; }; tempLightSeekBar.MouseUpEventHandler += (sender, e) => { //弹起的时候发最后的数据 tempLightSeekBar.Tag = DateTime.Now; lightDimming.LastOpenBrightness = Convert.ToByte (tempLightSeekBar.Progress); Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { lightDimming.LoopID, (byte)tempLightSeekBar.Progress, 0, 0 }); 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); } Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { lightDimming.LoopID, lightDimming.CurrentBrightness,delayHeight, delayLow}); tempLightSeekBar.Progress = lightDimming.CurrentBrightness; }; if (lightDimming.CurrentBrightness > 0) { tempSwitch.IsSelected = true; } } var ligthRGBList = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.LightRGB; }); foreach (var common in ligthRGBList) { if (lightCount % 2 == 0) { HorizontalScrolView = new HorizontalScrolViewLayout () { X = Application.GetRealWidth (0), Height = Application.GetRealHeight (200), ScrollEnabled = false }; if (allView != null) allView.AddChidren (HorizontalScrolView); else curView.lightListView.AddChidren (HorizontalScrolView); } Button btnNull = new Button () { Width = Application.GetRealWidth (20), }; HorizontalScrolView.AddChidren (btnNull); lightCount++; LightLogic lightRGB = common as LightLogic; FrameLayout lightView = new FrameLayout () { //X = Application.GetRealWidth ((lightCount % 2) * 200), Y = Application.GetRealHeight (10), Width = Application.GetRealWidth (750), Height = Application.GetRealHeight (160), BackgroundColor = 0xFF2f2f2f, //Radius = 5, BorderWidth = 0, BorderColor = SkinStyle.Current.Transparent }; lightView.AddTag ("UpdataKey", lightRGB.CommonLoopID + "RGB"); HorizontalScrolView.AddChidren (lightView); // 灯光名称 var tempLightName = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (20), Height = Application.GetRealHeight (40), TextAlignment = TextAlignment.CenterLeft, Text = lightRGB.Name, }; if (!lightRGB.DimmingFunction) { tempLightName.Gravity = Gravity.CenterVertical; } if (!lightRGB.DimmingFunction) { tempLightName.Y = 0; } lightView.AddChidren (tempLightName); //进度条 var tempLightSeekBar = new HorizontalSeekBar () { Width = Application.GetRealWidth (450), Height = Application.GetRealHeight (130 - 20 - 40), X = Application.GetRealWidth (20), Y = Application.GetRealHeight (30 + 40), Visible = lightRGB.DimmingFunction, Progress = lightRGB.CurrentBrightness, ThumbColor = 0xFFFFFFFF, Tag = DateTime.MinValue }; lightView.AddChidren (tempLightSeekBar); #region ---逻辑灯颜色--- Button btnLightSetting = new Button () { Width = Application.GetRealWidth (70), Height = Application.GetRealHeight (70), Radius = (uint)Application.GetRealHeight (35), X = tempLightSeekBar.Right + Application.GetRealWidth (40), Y = Application.GetRealHeight (50), 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 (70), Height = Application.GetRealHeight (70), Radius = (uint)Application.GetRealHeight (35), X = tempLightSeekBar.Right + Application.GetRealWidth (40), Y = Application.GetRealHeight (50), 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 (() => { Application.RunOnMainThread (() => { MainPage.Loading.Start ("Loading.."); }); lightLigicBytes = Control.ControlBytesSendHasReturn (Command.ReadLogicLoopColor, lightRGB.SubnetID, lightRGB.DeviceID, new byte [] { lightRGB.LoopID }); if (lightLigicBytes == null) { lightLigicBytes = new byte [11]; } Application.RunOnMainThread (() => { MainPage.Loading.Hide (); Dialog dialog = new Dialog () { BackgroundColor = SkinStyle.Current.TextColor1, Width = Application.GetRealWidth (1060), Height = Application.GetRealHeight (880), }; Button btnTitle = new Button () { Height = Application.GetRealHeight (100), TextAlignment = TextAlignment.Center, Enable = false, TextID = R.MyInternationalizationString.Setting, BackgroundColor = 0xFF333333 }; 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 = 0xFF000000, Text = "Color" }; dialog.AddChidren (btnColorText); ColorPicker c = new ColorPicker () { X = Application.GetRealWidth (50), Y = btnTitle.Bottom + Application.GetRealHeight (130), 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 = c.Right + Application.GetRealWidth (50), TextAlignment = TextAlignment.CenterLeft, Y = btnColor.Y, TextColor = 0xFF000000, TextID = R.MyInternationalizationString.DelayTimeON }; dialog.AddChidren (btnDelayTimeONTitle); Button btnDelayTimeOnReduce = new Button () { Width = Application.GetRealWidth (64), Height = Application.GetRealHeight (62), X = btnDelayTimeONTitle.X, Y = btnDelayTimeONTitle.Bottom, UnSelectedImagePath = "Light/Light-.png", SelectedImagePath = "Light/Light-On.png", }; dialog.AddChidren (btnDelayTimeOnReduce); Button btnDelayTimeOnText = new Button () { Width = Application.GetRealWidth (330), Height = Application.GetRealHeight (62), X = btnDelayTimeOnReduce.Right, Y = btnDelayTimeOnReduce.Y, BackgroundColor = 0xFFDBDDDF, Text = lightRGB.CustomDelayTimeOpen.ToString () + "s", TextSize = 12, TextColor = 0xFF000000 }; 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 = btnDelayTimeONTitle.X, TextAlignment = TextAlignment.CenterLeft, Y = btnDelayTimeOnReduce.Bottom + Application.GetRealHeight (100), TextColor = 0xFF000000, TextID = R.MyInternationalizationString.DelayTimeOFF }; dialog.AddChidren (btnDelayTimeOFFTitle); Button btnDelayTimeOffReduce = new Button () { Width = Application.GetRealWidth (64), Height = Application.GetRealHeight (62), X = btnDelayTimeOFFTitle.X, Y = btnDelayTimeOFFTitle.Bottom, UnSelectedImagePath = "Light/Light-.png", SelectedImagePath = "Light/Light-On.png", }; dialog.AddChidren (btnDelayTimeOffReduce); Button btnDelayTimeOffText = new Button () { Width = Application.GetRealWidth (330), Height = Application.GetRealHeight (62), X = btnDelayTimeOffReduce.Right, Y = btnDelayTimeOffReduce.Y, BackgroundColor = 0xFFDBDDDF, Text = lightRGB.CustomDelayTimeClose.ToString () + "s", TextSize = 12, TextColor = 0xFF000000 }; 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 HorizontalSeekBar seekBarLighting = new HorizontalSeekBar () { X = btnDelayTimeONTitle.X, Y = btnDelayTimeOffReduce.Bottom + Application.GetRealHeight (100), Width = Application.GetRealWidth (410), Height = Application.GetRealHeight (50), Progress = lightLigicBytes [1], ThumbColor = (uint)(0xFF000000 + lightLigicBytes [6] * 256 * 256 + lightLigicBytes [7] * 256 + lightLigicBytes [8]), Max = 100, ProgressColor = SkinStyle.Current.SelectedColor, }; dialog.AddChidren (seekBarLighting); Button btnLightingText = new Button () { X = seekBarLighting.Right + Application.GetRealWidth (5), Y = seekBarLighting.Y, Width = Application.GetRealWidth (80), Height = Application.GetRealHeight (50), TextColor = 0xFF000000, 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; } }; FrameLayout 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 (528), TextID = R.MyInternationalizationString.Cancel, }; bottomView.AddChidren (btnCancel); btnCancel.MouseUpEventHandler += (sender2, e2) => { dialog.Close (); }; Button btnLine = new Button () { BackgroundColor = 0xFF333333, Width = 1, X = btnCancel.Right, }; bottomView.AddChidren (btnLine); Button btnSave = new Button () { Width = Application.GetRealWidth (528), X = btnLine.Right, 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 (); }); }); }; #endregion //开关按键 var tempSwitch = new Button () { Width = Application.GetRealWidth (90), Height = Application.GetRealHeight (53), X = Application.GetRealWidth (750 - 90 - 50), Y = Application.GetRealHeight (75), 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) { System.Threading.Tasks.Task.Run (() => { System.Collections.Generic.List readList = new System.Collections.Generic.List (); //foreach (Room room in Room.Lists) { var list = room.DeviceList.FindAll ((obj) => { return obj.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now && (obj.Type == DeviceType.LightDimming || obj.Type == DeviceType.LightSwitch); }); 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 [] { }); } //} }); } } }