using System; using System.Collections.Generic; using Shared.SimpleControl; namespace Shared.SimpleControl.Phone { public class UserCurtainPage : FrameLayout { /// /// 当前打开的窗帘界面 /// public static UserCurtainPage curView; FrameLayout roomBackgroundImage; Common curtain; Button btnCloseCurtain; Button btnOpenCurtain; Button btnStopCurtain; Button btnCurrentStatus; Button btnTitle; HorizontalSeekBar horizontalSeekBar; Room room; /// /// 显示当前房间窗帘设备 /// public UserCurtainPage (Common curtain, Room Room) { this.curtain = curtain; BackgroundColor = SkinStyle.Current.MainColor; room = Room; curView = this; } /// /// 接受到窗帘发出的数据之后更新UI /// 窗帘停止回复的命令没有必要调用UpdateStatus /// /// The user lights. public static void UpdateStatus (Common curtain) { Application.RunOnMainThread (() => { if (curView == null || curView.curtain != curtain) { return; } if (curView.curtain.Type == DeviceType.CurtainTrietex) { var curtainTrietex = curView.curtain as CurtainTrietex; //不在模拟进度时 if (curView.th == null) { curView.btnCurrentStatus.Text = curtainTrietex.CurtainProress.ToString () + "%"; curView.horizontalSeekBar.Progress = curtainTrietex.CurtainProress; } } else if (curView.curtain.Type == DeviceType.CurtainRoller) { var curtainRoller = curView.curtain as CurtainRoller; //不在模拟进度时 if (curView.th == null) { curView.btnCurrentStatus.Text = curtainRoller.CurtainProress.ToString () + "%"; curView.horizontalSeekBar.Progress = curtainRoller.CurtainProress; } } }); } /// /// 房间模式进入的窗帘界面 /// /// The lights room. public void showCurtainsRoom () { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), Width = Application.GetRealWidth(640), }; AddChidren (topView); btnTitle = new Button () { TextAlignment = TextAlignment.Center, Text = room.Name, TextColor = SkinStyle.Current.TextColor1, TextSize = 19, }; topView.AddChidren (btnTitle); 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 roomBackgroundImage = new FrameLayout () { Y = topView.Bottom, Height = Application.GetRealHeight (360), Width = Application.GetRealWidth(640), }; 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); }; if (curtain.Type == DeviceType.CurtainModel) { addCurtainModeul ( curtain as CurtainModel); } else if (curtain.Type == DeviceType.CurtainTrietex) { AddCurtainTrietex ( curtain as CurtainTrietex); } else if (curtain.Type == DeviceType.CurtainRoller) { AddCurtainRoller ( curtain as CurtainRoller); } UpdateStatus (curtain); } /// /// 加载窗帘的模块按钮界面 /// void addCurtainModeul ( CurtainModel curtainModel) { btnTitle.Text = curtainModel.Name; var curtainView = new FrameLayout () { Height = Application.GetRealHeight (400), Width = Application.GetRealWidth(640), Y = roomBackgroundImage.Bottom, }; AddChidren (curtainView); btnOpenCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth (80), Y = Application.GetRealHeight (50), UnSelectedImagePath = "Curtain/CurtainOpen.png", SelectedImagePath = "Curtain/CurtainOpenSelected.png", }; curtainView.AddChidren (btnOpenCurtain); btnStopCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth ((640 - 124) / 2), Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainTimeOut.png", SelectedImagePath = "Curtain/CurtainTimeOutSelected.png", }; curtainView.AddChidren (btnStopCurtain); btnCloseCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth (640 - 80 - 124), Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainClose.png", SelectedImagePath = "Curtain/CurtainCloseSelected.png", }; curtainView.AddChidren (btnCloseCurtain); var btnOpenLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (40), X = btnOpenCurtain.X, Y = btnOpenCurtain.Bottom + Application.GetRealHeight (5), TextID = R.MyInternationalizationString.Open, TextColor = SkinStyle.Current.TextColor1, }; curtainView.AddChidren (btnOpenLbl); var btnStopLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (40), X = btnStopCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Stop, TextColor = SkinStyle.Current.TextColor1, }; curtainView.AddChidren (btnStopLbl); var btnCloseLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (40), X = btnCloseCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Close2, TextColor = SkinStyle.Current.TextColor1, }; curtainView.AddChidren (btnCloseLbl); btnCloseCurtain.MouseDownEventHandler += (sender3, e3) => { Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainModel.SubnetID, curtainModel.DeviceID, new byte [] { curtainModel.LoopID, 2 }); (sender3 as Button).IsSelected = true; }; btnCloseCurtain.MouseUpEventHandler += (sender3, e3) => { new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { (sender3 as Button).IsSelected = false; }); }) { IsBackground = true }.Start (); }; btnOpenCurtain.MouseDownEventHandler += (sender3, e3) => { Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainModel.SubnetID, curtainModel.DeviceID, new byte [] { curtainModel.LoopID, 1 }); (sender3 as Button).IsSelected = true; }; btnOpenCurtain.MouseUpEventHandler += (sender3, e3) => { new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { (sender3 as Button).IsSelected = false; }); }) { IsBackground = true }.Start (); }; btnStopCurtain.MouseDownEventHandler += (sender3, e3) => { Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainModel.SubnetID, curtainModel.DeviceID, new byte [] { curtainModel.LoopID, 0}); (sender3 as Button).IsSelected = true; }; btnStopCurtain.MouseUpEventHandler += (sender3, e3) => { new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { (sender3 as Button).IsSelected = false; }); }) { IsBackground = true }.Start (); }; #region MyRegion System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { MainPage.Loading.Start ("Please wait..."); }); try { var runTimeBytes = Control.ControlBytesSendHasReturn (Command.ReadCurtainModelRunTime, curtain.SubnetID, curtain.DeviceID, new byte [] { curtain.LoopID }); int openRunTime = 0; if (runTimeBytes != null) { openRunTime = (runTimeBytes [1] * 256 + runTimeBytes [2])/10; } Application.RunOnMainThread (() => { FrameLayout runtimeView = new FrameLayout () { Height = Application.GetRealHeight (700), Width = LayoutParams.MatchParent, Y = curtainView.Bottom, }; AddChidren (runtimeView); Button btnOpenRunTimeText = new Button () { Width = Application.GetRealHeight (170), Height = Application.GetRealHeight (50), X = Application.GetRealWidth (80), Y = Application.GetRealHeight (40), Text = "Run time (s)", TextAlignment = TextAlignment.CenterLeft, Enable = false, TextColor = SkinStyle.Current.TextColor1, }; runtimeView.AddChidren (btnOpenRunTimeText); var etOpenRunTime = new EditText () { X = btnOpenRunTimeText.Right, Y = btnOpenRunTimeText.Y, Width = Application.GetRealWidth (80), Height = btnOpenRunTimeText.Height - Application.GetRealHeight (2), Text = openRunTime.ToString (), TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, }; runtimeView.AddChidren (etOpenRunTime); Button btnOpenRunTimeLine = new Button () { Height = Application.GetRealHeight (2), Width = etOpenRunTime.Width, BackgroundColor = SkinStyle.Current.ButtonColor, X = btnOpenRunTimeText.Right, Y = etOpenRunTime.Bottom, }; runtimeView.AddChidren (btnOpenRunTimeLine); Button btnSaveRunTime = new Button () { X = etOpenRunTime.Right + Application.GetRealWidth (70), Y = Application.GetRealHeight(50), Height = Application.GetRealHeight (60), Width = Application.GetRealWidth (120), BackgroundColor = SkinStyle.Current.ButtonColor, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.Transparent, TextID = R.MyInternationalizationString.SAVE, TextColor = SkinStyle.Current.TextColor1 }; runtimeView.AddChidren (btnSaveRunTime); btnSaveRunTime.MouseUpEventHandler += (sender, e) => { try { if (int.TryParse (etOpenRunTime.Text, out openRunTime)) { if (openRunTime < 2 || openRunTime > 300) { new Alert ("", "Please enter a number between 2 and 300.", Language.StringByID (R.MyInternationalizationString.Close)).Show (); } } else { new Alert ("", "Please enter a number between 2 and 300.", Language.StringByID (R.MyInternationalizationString.Close)).Show (); } } catch { new Alert ("", "Please enter a number between 2 and 300.", Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } System.Threading.Tasks.Task.Factory.StartNew (() => { try { Application.RunOnMainThread (() => { MainPage.Loading.Start ("Please wait..."); Application.HideSoftInput (); }); openRunTime = openRunTime * 10; byte [] setOpenRunTimeRev = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelRunTime, curtainModel.SubnetID, curtainModel.DeviceID, new byte [] { (curtainModel.LoopID ), (byte)(openRunTime / 256), (byte)(openRunTime % 256) }); if (setOpenRunTimeRev == null) { Application.RunOnMainThread (() => { new Alert ("", "Devices Offline!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); } } catch(Exception ex) { Console.WriteLine (ex.Message); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; }); } catch (Exception ex) { Console.WriteLine (ex.Message); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); #endregion } /// /// 加载开合帘界面 /// void AddCurtainTrietex ( CurtainTrietex curtainTrietex) { btnTitle.Text = curtainTrietex.Name; #region 进度条 FrameLayout progressControlView = new FrameLayout () { Height = Application.GetRealHeight (320), BackgroundColor = SkinStyle.Current.ViewColor, Width = Application.GetRealWidth(640), Y = roomBackgroundImage.Bottom, }; AddChidren (progressControlView); Button btnCurrentIcon = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (20), Width = Application.GetRealWidth (105), Height = Application.GetRealHeight (105), UnSelectedImagePath = "Curtain/curtain1.png", }; progressControlView.AddChidren (btnCurrentIcon); Button btnCurrentStatusText = new Button () { X = btnCurrentIcon.Right, Y = Application.GetRealHeight (20), Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (105), TextID = R.MyInternationalizationString.CurrentStatus, TextAlignment = TextAlignment.CenterLeft }; progressControlView.AddChidren (btnCurrentStatusText); FrameLayout trietexProgressView = new FrameLayout () { Width = Application.GetRealWidth (480), Height = Application.GetRealHeight (60), X = Application.GetRealWidth (60), Y = Application.GetRealHeight (150), }; progressControlView.AddChidren (trietexProgressView); horizontalSeekBar = new HorizontalSeekBar () { Progress = curtainTrietex.CurtainProress, ThumbColor = SkinStyle.Current.ThumbColor, ProgressColor = SkinStyle.Current.SelectedColor }; trietexProgressView.AddChidren (horizontalSeekBar); btnCurrentStatus = new Button () { Width = Application.GetRealWidth (80), Height = Application.GetRealHeight (60), X = trietexProgressView.Right, Y = trietexProgressView.Y, Text = curtainTrietex.CurtainProress.ToString () + "%", TextColor = SkinStyle.Current.TextColor1, }; progressControlView.AddChidren (btnCurrentStatus); horizontalSeekBar.ProgressChanged += (sender, e) => { btnCurrentStatus.Text = e.ToString () + "%"; curtainTrietex.CurtainProress = (byte)e; }; horizontalSeekBar.MouseDownEventHandler += (sender, e) => { stop (); }; horizontalSeekBar.MouseUpEventHandler += (sender, e) => { Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainTrietex.SubnetID, curtainTrietex.DeviceID, new byte [] { 17, Convert.ToByte (horizontalSeekBar.Progress) }); btnCurrentStatus.Text = curtainTrietex.CurtainProress.ToString () + "%"; th = new System.Threading.Thread ((obj) => { //如果后面没有什么操作,到时自动还原接收更新状态 System.Threading.Thread.Sleep (20 * 1000); th = null; }); th.Start (); }; #endregion FrameLayout curtainView = new FrameLayout () { Height = Application.GetRealHeight (350), Y = progressControlView.Bottom + Application.GetRealHeight(3), BackgroundColor = SkinStyle.Current.ViewColor }; AddChidren (curtainView); btnOpenCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth (40), Y = Application.GetRealHeight (50), UnSelectedImagePath = "Curtain/CurtainOpen.png", SelectedImagePath = "Curtain/CurtainOpenSelected.png", }; curtainView.AddChidren (btnOpenCurtain); btnStopCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth ((640 - 124) / 2), Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainTimeOut.png", SelectedImagePath = "Curtain/CurtainTimeOutSelected.png", }; curtainView.AddChidren (btnStopCurtain); btnCloseCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth (640 - 40 - 124), Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainClose.png", SelectedImagePath = "Curtain/CurtainCloseSelected.png", }; curtainView.AddChidren (btnCloseCurtain); var btnOpenLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnOpenCurtain.X, Y = btnOpenCurtain.Bottom + Application.GetRealHeight (5), TextID = R.MyInternationalizationString.Open, TextColor = SkinStyle.Current.TextColor1, }; curtainView.AddChidren (btnOpenLbl); var btnStopLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnStopCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Stop, TextColor = SkinStyle.Current.TextColor1, }; curtainView.AddChidren (btnStopLbl); var btnCloseLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnCloseCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Close2, TextColor = SkinStyle.Current.TextColor1, }; curtainView.AddChidren (btnCloseLbl); btnCloseCurtain.MouseDownEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = true; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainTrietex.SubnetID, curtainTrietex.DeviceID, new byte [] { 1, 2 }); stop (); int startProgress = horizontalSeekBar.Progress; if (0 < curtainTrietex.Speed) { th = new System.Threading.Thread ((obj) => { var startDateTime = DateTime.Now; while (curView != null) { System.Threading.Thread.Sleep (200); var v = startProgress - (int)((DateTime.Now - startDateTime).TotalMilliseconds * curtainTrietex.Speed); v = v < 0 ? 0 : v; Application.RunOnMainThread (() => { horizontalSeekBar.Progress = v; btnCurrentStatus.Text = v + "%"; }); if (v <= 0) { break; } } //防止跳动 System.Threading.Thread.Sleep (2000); th = null; }); th.Start (); } else { readProgressDateTime = DateTime.Now; //接近全开状态,这样初始化的值会是比较准确的 if (90 <= startProgress) { intSpped (0); } } }; btnCloseCurtain.MouseUpEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = false; }; btnOpenCurtain.MouseDownEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = true; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainTrietex.SubnetID, curtainTrietex.DeviceID, new byte [] { 1, 1 }); stop (); int startProgress = horizontalSeekBar.Progress; if (0 < curtainTrietex.Speed) { th = new System.Threading.Thread ((obj) => { var startDateTime = DateTime.Now; while (curView != null) { System.Threading.Thread.Sleep (200); var v = startProgress + (int)((DateTime.Now - startDateTime).TotalMilliseconds * curtainTrietex.Speed); v = 100 < v ? 100 : v; Application.RunOnMainThread (() => { horizontalSeekBar.Progress = v; btnCurrentStatus.Text = v + "%"; }); if (100 <= v) { break; } } //防止跳动 System.Threading.Thread.Sleep (2000); th = null; }); th.Start (); } else { readProgressDateTime = DateTime.Now; //接近全关状态,这样初始化的值会是比较准确的 if (startProgress <= 10) { intSpped (100); } } }; btnOpenCurtain.MouseUpEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = false; }; btnStopCurtain.MouseDownEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = true; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainTrietex.SubnetID, curtainTrietex.DeviceID, new byte [] { 1, 0 }); stop (); }; btnStopCurtain.MouseUpEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = false; }; curView = this; statrtReadProgress (); } /// /// 结束值 /// /// V. void intSpped (int v) { MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.Initiating)); DateTime dateTime = DateTime.Now; System.Threading.Tasks.Task.Run (() => { while (curView != null) { System.Threading.Thread.Sleep (500); var bytes = Control.ControlBytesSendHasReturn (Command.ReadCurtainStatus, curtain.SubnetID, curtain.DeviceID, new byte [] { 17 }); if (bytes == null) { break; } else { if (2 <= bytes.Length && v == bytes [1]) { if (curtain.Type == DeviceType.CurtainRoller) { (curtain as CurtainRoller).Speed = 100 / ((DateTime.Now - dateTime).TotalMilliseconds - 300); } else if (curtain.Type == DeviceType.CurtainTrietex) { (curtain as CurtainTrietex).Speed = 100 / ((DateTime.Now - dateTime).TotalMilliseconds - 300); } break; } } } Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); }); } void stop () { try { if (th != null) { th.Abort (); th = null; //Control.ControlBytesSend (Command.ReadCurtainStatus, curtain.SubnetID, curtain.DeviceID, new byte [] { 17 }); } } catch { } } /// /// 加载卷帘界面 /// void AddCurtainRoller (CurtainRoller curtainRoller) { btnTitle.Text = curtainRoller.Name; #region 进度条 FrameLayout ProgressControlView = new FrameLayout () { Height = Application.GetRealHeight (320), BackgroundColor = SkinStyle.Current.ViewColor, Y = roomBackgroundImage.Bottom, }; AddChidren (ProgressControlView); Button btnCurrentIcon = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (20), Width = Application.GetRealWidth (105), Height = Application.GetRealHeight (105), UnSelectedImagePath = "Curtain/rollerCurtain.png", }; ProgressControlView.AddChidren (btnCurrentIcon); Button btnCurrentStatusText = new Button () { X = btnCurrentIcon.Right, Y = Application.GetRealHeight (20), Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (105), TextID = R.MyInternationalizationString.CurrentStatus, TextAlignment = TextAlignment.CenterLeft }; ProgressControlView.AddChidren (btnCurrentStatusText); FrameLayout rollerProgressView = new FrameLayout () { Width = Application.GetRealWidth (480), Height = Application.GetRealHeight (60), X = Application.GetRealWidth (60), Y = Application.GetRealHeight (150), }; ProgressControlView.AddChidren (rollerProgressView); horizontalSeekBar = new HorizontalSeekBar () { Height = LayoutParams.MatchParent, Gravity = Gravity.CenterVertical, Progress = curtainRoller.CurtainProress, ThumbColor = SkinStyle.Current.ThumbColor, }; rollerProgressView.AddChidren (horizontalSeekBar); btnCurrentStatus = new Button () { Width = Application.GetRealWidth (90), Height = Application.GetRealHeight (60), X = rollerProgressView.Right, Y = rollerProgressView.Y, Text = curtainRoller.CurtainProress.ToString () + "%", TextColor = SkinStyle.Current.TextColor1, }; ProgressControlView.AddChidren (btnCurrentStatus); horizontalSeekBar.ProgressChanged += (sender, e) => { btnCurrentStatus.Text = e.ToString () + "%"; curtainRoller.CurtainProress = (byte)e; }; horizontalSeekBar.MouseDownEventHandler += (sender, e) => { stop (); }; horizontalSeekBar.MouseUpEventHandler += (sender, e) => { Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainRoller.SubnetID, curtainRoller.DeviceID, new byte [] { 17, Convert.ToByte (horizontalSeekBar.Progress) }); btnCurrentStatus.Text = curtainRoller.CurtainProress.ToString () + "%"; th = new System.Threading.Thread ((obj) => { //如果后面没有什么操作,到时自动还原接收更新状态 System.Threading.Thread.Sleep (20 * 1000); th = null; }); th.Start (); }; #endregion FrameLayout rollerView = new FrameLayout () { Y =ProgressControlView.Bottom + Application.GetRealHeight(3), Height = Application.GetRealHeight (350), BackgroundColor = SkinStyle.Current.ViewColor, }; rollerView.AddTag ("UpdataKey", curtainRoller.SubnetID.ToString () + curtainRoller.DeviceID.ToString () + curtainRoller.LoopID.ToString ()); AddChidren (rollerView); btnOpenCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth (40), Y = Application.GetRealHeight (50), UnSelectedImagePath = "Curtain/CurtainRollerUp.png", SelectedImagePath = "Curtain/CurtainRollerUpOn.png", }; rollerView.AddChidren (btnOpenCurtain); btnStopCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), Gravity = Gravity.CenterHorizontal, Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainTimeOut.png", SelectedImagePath = "Curtain/CurtainTimeOutSelected.png", }; rollerView.AddChidren (btnStopCurtain); btnCloseCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth (640 - 40 - 124), Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainRollerDown.png", SelectedImagePath = "Curtain/CurtainRollerDownOn.png", }; rollerView.AddChidren (btnCloseCurtain); var btnOpenLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnOpenCurtain.X, Y = btnOpenCurtain.Bottom + Application.GetRealHeight (5), TextID = R.MyInternationalizationString.Up, TextColor = SkinStyle.Current.TextColor1, }; rollerView.AddChidren (btnOpenLbl); var btnStopLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnStopCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Stop, TextColor = SkinStyle.Current.TextColor1, }; rollerView.AddChidren (btnStopLbl); var btnCloseLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnCloseCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Down, TextColor = SkinStyle.Current.TextColor1, }; rollerView.AddChidren (btnCloseLbl); btnCloseCurtain.MouseDownEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = true; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainRoller.SubnetID, curtainRoller.DeviceID, new byte [] { 1, 2 }); stop (); int startProgress = horizontalSeekBar.Progress; if (0 < curtainRoller.Speed) { th = new System.Threading.Thread ((obj) => { var startDateTime = DateTime.Now; while (curView != null) { System.Threading.Thread.Sleep (200); var v = startProgress - (int)((DateTime.Now - startDateTime).TotalMilliseconds * curtainRoller.Speed); v = v < 0 ? 0 : v; Application.RunOnMainThread (() => { horizontalSeekBar.Progress = v; btnCurrentStatus.Text = v + "%"; }); if (v <= 0) { break; } } //防止跳动 System.Threading.Thread.Sleep (2000); th = null; }); th.Start (); } else { readProgressDateTime = DateTime.Now; //接近全开状态,这样初始化的值会是比较准确的 if (90 <= startProgress) { intSpped (0); } } }; btnCloseCurtain.MouseUpEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = false; }; btnOpenCurtain.MouseDownEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = true; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainRoller.SubnetID, curtainRoller.DeviceID, new byte [] { 1, 1 }); stop (); int startProgress = horizontalSeekBar.Progress; if (0 < curtainRoller.Speed) { th = new System.Threading.Thread ((obj) => { var startDateTime = DateTime.Now; while (curView != null) { System.Threading.Thread.Sleep (200); var v = startProgress + (int)((DateTime.Now - startDateTime).TotalMilliseconds * curtainRoller.Speed); v = 100 < v ? 100 : v; Application.RunOnMainThread (() => { horizontalSeekBar.Progress = v; btnCurrentStatus.Text = v + "%"; }); if (100 <= v) { break; } } //防止跳动 System.Threading.Thread.Sleep (2000); th = null; }); th.Start (); } else { readProgressDateTime = DateTime.Now; //接近全关状态,这样初始化的值会是比较准确的 if (startProgress <= 10) { intSpped (100); } } }; btnOpenCurtain.MouseUpEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = false; }; btnStopCurtain.MouseDownEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = true; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainRoller.SubnetID, curtainRoller.DeviceID, new byte [] { 1, 0 }); stop (); }; btnStopCurtain.MouseUpEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = false; }; } DateTime readProgressDateTime = System.DateTime.MaxValue; System.Threading.Thread th; void statrtReadProgress () { int endProgress = 0; System.Threading.Tasks.Task.Run (() => { if (curtain.Type == DeviceType.CurtainRoller) { var curtainroller = curtain as CurtainRoller; Control.ControlBytesSend (Command.ReadCurtainStatus, curtainroller.SubnetID, curtainroller.DeviceID, new byte [] { 17 }); } else if (curtain.Type == DeviceType.CurtainTrietex) { var curtaintrietex = curtain as CurtainTrietex; Control.ControlBytesSend (Command.ReadCurtainStatus, curtaintrietex.SubnetID, curtaintrietex.DeviceID, new byte [] { 17 }); } while (curView != null) { System.Threading.Thread.Sleep (300); if (readProgressDateTime == DateTime.MaxValue) { continue; } if (curtain.Type == DeviceType.CurtainRoller) { var curtainroller = curtain as CurtainRoller; if (curtainroller.CurtainProress != endProgress) { endProgress = curtainroller.CurtainProress; readProgressDateTime = DateTime.Now; } if ((DateTime.Now - readProgressDateTime).TotalMilliseconds < 1000) { Control.ControlBytesSend (Command.ReadCurtainStatus, curtainroller.SubnetID, curtainroller.DeviceID, new byte [] { 17 }, SendCount.Zero); } else { readProgressDateTime = DateTime.MaxValue; } } else if (curtain.Type == DeviceType.CurtainTrietex) { var curtaintrietex = curtain as CurtainTrietex; if (curtaintrietex.CurtainProress != endProgress) { endProgress = curtaintrietex.CurtainProress; readProgressDateTime = DateTime.Now; } if ((DateTime.Now - readProgressDateTime).TotalMilliseconds < 1000) { Control.ControlBytesSend (Command.ReadCurtainStatus, curtaintrietex.SubnetID, curtaintrietex.DeviceID, new byte [] { 17 }, SendCount.Zero); } else { readProgressDateTime = DateTime.MaxValue; } } } }); } } }