using System; namespace Shared.SimpleControl.Phone { public class SystemLightLogic : FrameLayout { public void SystemLightLogicShow (LightLogic lightLogic, Common common) { //SystemMiddle.hideBottom (); byte [] lightLigicBytes = new byte [11]; System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load)); }); lightLigicBytes = Control.ControlBytesSendHasReturn (Command.ReadLogicLoopColor, lightLogic.SubnetID, lightLogic.DeviceID, new byte [] { lightLogic.LoopID }); if (lightLigicBytes == null) { lightLigicBytes = new byte [11]; } Application.RunOnMainThread (() => { MainPage.Loading.Hide (); #region top RowLayout topTitleView = new RowLayout () { Height = Application.GetRealHeight (100), BackgroundColor = SkinStyle.Current.MainColor }; AddChidren (topTitleView); Button backButton = new Button () { X = Application.GetRealWidth (0), Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", Gravity = Gravity.CenterVertical, }; backButton.MouseUpEventHandler += (sender, e) => { (Parent as PageLayout).PageIndex -= 1; //SystemEquipmentBase.RefreshView (common); }; topTitleView.AddChidren (backButton); EditText textButton = new EditText () { X = Application.GetRealWidth (30) + backButton.Right, Height = Application.GetRealHeight (50), Width = Application.GetRealWidth (400), Text = lightLogic.Name, TextAlignment = TextAlignment.CenterLeft, Gravity = Gravity.CenterVertical, BackgroundColor = SkinStyle.Current.Transparent, SelectedBackgroundColor = SkinStyle.Current.SysEditBox, Enable = false, TextColor = SkinStyle.Current.TextColor1 }; topTitleView.AddChidren (textButton); Button editor = new Button () { X = Application.GetRealWidth (520), Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (70), UnSelectedImagePath = "Item/Editor.png", SelectedImagePath = "Item/EditorSelected.png", Gravity = Gravity.CenterVertical, }; topTitleView.AddChidren (editor); EventHandler eHandler = new EventHandler ((sender, e) => { if (editor.IsSelected) { MainPage.Loading.Start (); byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (textButton.Text.Trim ()); textButton.IsSelected = editor.IsSelected = textButton.Enable = false; System.Threading.Tasks.Task.Run (() => { byte [] updateBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, lightLogic.SubnetID, lightLogic.DeviceID, new byte [] { lightLogic.BigClass,lightLogic.MinClass,lightLogic.LoopID }); if (updateBytes == null) { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show (); MainPage.Loading.Hide (); }); return; } byte [] uBytes = new byte [20]; Array.Copy (remakeBytes, 0, uBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20); Array.Copy (uBytes, 0, updateBytes, 3, 20 < uBytes.Length ? 20 : uBytes.Length); var reBytes = Control.ControlBytesSendHasReturn (Command.SetDeviceLoopInfo, lightLogic.SubnetID, lightLogic.DeviceID, updateBytes); if (reBytes != null) { Application.RunOnMainThread (() => { lightLogic.Name = textButton.Text.Trim (); IO.FileUtils.SaveEquipmentMessage (lightLogic, lightLogic.LoopID.ToString ()); MainPage.Loading.Hide (); }); } else { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show (); MainPage.Loading.Hide (); }); } }); } else { textButton.Enable = textButton.IsSelected = editor.IsSelected = true; } }); editor.MouseUpEventHandler += eHandler; #endregion #region ---RGB--- FrameLayout frameLayoutBody = new FrameLayout () { Y = Application.GetRealHeight (100), Height = Application.GetRealHeight (800), }; AddChidren (frameLayoutBody); ColorPicker c = new ColorPicker () { X = Application.GetRealWidth (100), Y = Application.GetRealHeight (30), Width = Application.GetMinRealAverage (440), Height = Application.GetMinRealAverage (440), ColorImagePath = "Item/PickerColorWheel.png", }; frameLayoutBody.AddChidren (c); DateTime colorChangeTime = DateTime.MinValue; uint colorByte = (uint)(0xFF000000 + lightLigicBytes [6] * 256 * 256 + lightLigicBytes [7] * 256 + lightLigicBytes [8]); HorizontalSeekBar seekBarLighting = new HorizontalSeekBar () { X = Application.GetRealWidth (55), Y = c.Bottom + Application.GetRealHeight (50), Width = Application.GetRealWidth (460), Height = Application.GetRealHeight (50), Progress = lightLigicBytes [1], Max = 100, ThumbColor = SkinStyle.Current.ThumbColor, }; frameLayoutBody.AddChidren (seekBarLighting); Button btnLightingText = new Button () { X = seekBarLighting.Right + Application.GetRealWidth (5), Y = seekBarLighting.Y, Width = Application.GetRealWidth (80), Height = Application.GetRealHeight (50), Text = lightLigicBytes [1].ToString () + "%" }; frameLayoutBody.AddChidren (btnLightingText); Button btnColorSwitch = new Button () { X = Application.GetRealWidth (250), Y = btnLightingText.Bottom + Application.GetRealHeight (50), Width = Application.GetMinRealAverage (140), Height = Application.GetMinRealAverage (60), Radius = (uint)Application.GetMinRealAverage (10), BackgroundColor = colorByte, TextColor = SkinStyle.Current.TextColor1, TextID = R.MyInternationalizationString.OnOrOff }; frameLayoutBody.AddChidren (btnColorSwitch); c.ColorChaged += (sender, e) => { if ((DateTime.Now - colorChangeTime).TotalMilliseconds > 50) { lightLigicBytes [6] = e [0]; lightLigicBytes [7] = e [1]; lightLigicBytes [8] = e [2]; Control.ControlBytesSend (Command.SetLogicLoopColor, lightLogic.SubnetID, lightLogic.DeviceID, lightLigicBytes, SendCount.Zero); colorChangeTime = DateTime.Now; btnColorSwitch.BackgroundColor = (uint)(0xFF000000 + lightLigicBytes [6] * 256 * 256 + lightLigicBytes [7] * 256 + lightLigicBytes [8]); lightLogic.RStatus = e [0]; lightLogic.GStatus = e [1]; lightLogic.BStatus = e [2]; //IO.FileUtils.SaveEquipmentMessage (lightLogic, lightLogic.LoopID.ToString ()); } }; seekBarLighting.ProgressChanged += (sender, e) => { if ((DateTime.Now - colorChangeTime).TotalMilliseconds > 50) { lightLigicBytes [1] = (byte)e; Control.ControlBytesSend (Command.SetLogicLoopColor, lightLogic.SubnetID, lightLogic.DeviceID, lightLigicBytes, SendCount.Zero); colorChangeTime = DateTime.Now; btnLightingText.Text = e.ToString () + "%"; lightLogic.LastOpenBrightness = (byte)e; } }; btnColorSwitch.MouseUpEventHandler += (sender, e) => { if ((DateTime.Now - colorChangeTime).TotalMilliseconds > 100) { lightLigicBytes [1] = lightLigicBytes [1] > (byte)0 ? (byte)0 : (lightLogic.LastOpenBrightness == (byte)0 ? (byte)100 : lightLogic.LastOpenBrightness); Control.ControlBytesSend (Command.SetLogicLoopColor, lightLogic.SubnetID, lightLogic.DeviceID, lightLigicBytes, SendCount.Zero); colorChangeTime = DateTime.Now; seekBarLighting.Progress = lightLigicBytes [1]; btnLightingText.Text = lightLigicBytes [1].ToString () + "%"; } }; #endregion }); }); } } }