using System; namespace Shared.SimpleControl.Phone { public class UserDeviceToFan : FrameLayout { VerticalScrolViewLayout bodyScrolView; static UserDeviceToFan curView; public UserDeviceToFan () { curView = this; BackgroundColor = SkinStyle.Current.MainColor; UserDeviceToLight.readAllStatus (); } /// /// 通过设备类型方式选择设备 /// public void ShowAllRoomCurtain () { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = Language.StringByID (R.MyInternationalizationString.Fan), TextSize = 19, TextColor = SkinStyle.Current.TextColor1, }; topView.AddChidren (title); var logo = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), UnSelectedImagePath = MainPage.LogoString, }; topView.AddChidren (logo); var back = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { (Parent as PageLayout).PageIndex -= 1; curView = null; }; #endregion #region 全开-全关 var powerView = new FrameLayout () { Height = Application.GetRealHeight (110), BackgroundColor = SkinStyle.Current.TitileView, Y = topView.Bottom }; AddChidren (powerView); var btnAllON = new Button () { Width = Application.GetRealWidth (320), TextSize = 16, TextID = R.MyInternationalizationString.ALLON, TextColor = SkinStyle.Current.TextColor1 }; powerView.AddChidren (btnAllON); var btnAllOff = new Button () { Width = Application.GetRealWidth (320), X = btnAllON.Right, TextSize = 16, TextID = R.MyInternationalizationString.ALLOFF, TextColor = SkinStyle.Current.TextColor1 }; powerView.AddChidren (btnAllOff); var btnLine = new Button () { Width = 1, BackgroundColor = SkinStyle.Current.White20Transparent, X = btnAllON.Right, }; powerView.AddChidren (btnLine); #endregion bodyScrolView = new VerticalScrolViewLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (1136 - 126 - 110), Y = powerView.Bottom, BackgroundColor = SkinStyle.Current.ViewColor }; AddChidren (bodyScrolView); #region 显示 int devcieCount = 0; foreach (var room in Room.Lists) { if (string.IsNullOrEmpty (room.Name)) { continue; } foreach (var common in room.DeviceList) { if (common.Type == DeviceType.FanModule) { devcieCount++; var fanModule = common as FanModule; EventHandler openCurtainControlPageEvent = (button, mouseEventArgs) => { UserFan userFanView = new UserFan (fanModule); UserMiddle.DevicePageView.AddChidren (userFanView); userFanView.ShowRoomFan (); UserMiddle.DevicePageView.PageIndex = 2; }; FrameLayout fanView = new FrameLayout () { Height = Application.GetRealHeight (130), Tag = fanModule.CommonLoopID }; bodyScrolView.AddChidren (fanView); fanView.MouseUpEventHandler += openCurtainControlPageEvent; Button btnCurtainViewBottomNull = new Button () { Y = Application.GetRealHeight (127), Height = Application.GetRealHeight (3), BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.MainColor, }; fanView.AddChidren (btnCurtainViewBottomNull); Button tempDeviceName = new Button () { X = Application.GetRealWidth (30), TextAlignment = TextAlignment.CenterLeft, Text = room.Name + "-" + fanModule.Name, TextColor = SkinStyle.Current.TextColor1, }; fanView.AddChidren (tempDeviceName); tempDeviceName.MouseUpEventHandler += openCurtainControlPageEvent; Button tempSiwtch = new Button () { Width = Application.GetMinRealAverage (90), Height = Application.GetMinRealAverage (53), X = Application.GetRealWidth (640 - 90 - 20), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/SwitchClose.png", SelectedImagePath = "Item/SwitchOpen.png", IsSelected = fanModule.Switch > 0 ? true : false, Tag = fanModule.CommonLoopID }; fanView.AddChidren (tempSiwtch); tempSiwtch.MouseUpEventHandler += (sender3, e3) => { //tempSiwtch.IsSelected = !tempSiwtch.IsSelected; //if (tempSiwtch.IsSelected) { // fanModule.Switch = fanModule.WindSpeed; //} else { // fanModule.Switch = 0; //} //Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, fanModule.Switch }); //2020-02-10 MainPage.Loading.Start ("Sending..."); //tempSiwtch.IsSelected = !tempSiwtch.IsSelected; //if (tempSiwtch.IsSelected) { // fanModule.Switch = fanModule.WindSpeed; //} else { // fanModule.Switch = 0; //} if (fanModule.WindSpeed == 0) fanModule.WindSpeed = 1; int mSetSwitch = tempSiwtch.IsSelected ? 0 : fanModule.WindSpeed; System.Threading.Tasks.Task.Run (() => { byte [] returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, (byte)mSetSwitch }); Application.RunOnMainThread (() => { if (returnBytes == null) { //string tipString = Language.StringByID (R.MyInternationalizationString.ControlFailure); new Alert ("", fanModule.Name + ErrorCode.ControlFailure, "Close").Show (); } MainPage.Loading.Hide (); }); }); }; Button btnViewNull = new Button () { Y = Application.GetRealHeight (127), Height = Application.GetRealHeight (3), BackgroundColor = SkinStyle.Current.MainColor, }; fanView.AddChidren (btnViewNull); } } } if (devcieCount > 0) { btnAllON.MouseUpEventHandler += (sender, e) => { btnAllON.TextColor = SkinStyle.Current.TextColor1; Alert alert = new Alert ("", Language.StringByID (R.MyInternationalizationString.SureOpenAllFan), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.Show (); alert.ResultEventHandler += (sender2, e2) => { if (e2) { ControlAllFan (true); } }; }; btnAllON.MouseDownEventHandler += (sender, e) => { btnAllON.TextColor = SkinStyle.Current.SelectedColor; }; btnAllOff.MouseDownEventHandler += (sender, e) => { btnAllOff.TextColor = SkinStyle.Current.SelectedColor; }; btnAllOff.MouseUpEventHandler += (sender, e) => { btnAllOff.TextColor = SkinStyle.Current.TextColor1; Alert alert = new Alert ("", Language.StringByID (R.MyInternationalizationString.SureCloseAllFan), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.Show (); alert.ResultEventHandler += (sender2, e2) => { if (e2) { ControlAllFan (false); } }; }; } #endregion } public static void UpdataStatus (string updataFlag, byte windSpeed) { #region 更新用户主界面灯光点亮总数 Application.RunOnMainThread (() => { int brighingCount = 0; foreach (var room in Room.Lists) { if (string.IsNullOrEmpty (room.Name)) { continue; } foreach (var light in room.DeviceList) { if (light.Type == DeviceType.FanModule) { if ((light as FanModule).Switch != 0) { brighingCount++; } } } } UserDeviceView.UpdataDeviceCountNumber (brighingCount, Language.StringByID (R.MyInternationalizationString.Fan)); }); #endregion //if (curView == null || curView.bodyScrolView.Decelerating) { // return; //} Application.RunOnMainThread (() => { if (curView == null || curView.bodyScrolView.Decelerating) { return; } for (int i = 0; i < curView.bodyScrolView.ChildrenCount; i++) { if (curView.bodyScrolView.GetChildren (i).GetType () == typeof (FrameLayout)) { var lightRow = (FrameLayout)curView.bodyScrolView.GetChildren (i); for (int j = 0; j < lightRow.ChildrenCount; j++) { if (lightRow.GetChildren (j).GetType () == typeof (Button)) { var btn = (Button)lightRow.GetChildren (j); var o = btn.Tag; if (o != null && o.ToString () == updataFlag) { if (windSpeed == 0) { btn.IsSelected = false; } else { btn.IsSelected = true; } } } } } } }); } void ControlAllFan (bool open) { if (CommonPage.IsRemote) { if (!SmartHome.MqttCommon.IsGatewayOnline) { new Alert ("", "Gateway offline" + ErrorCode.ControlFailure, "Close").Show (); return; } } MainPage.Loading.Start ("Sending..."); bool showTip = true; System.Threading.Tasks.Task.Run (() => { foreach (var room in Room.Lists) { if (room == null) continue; if (string.IsNullOrEmpty (room.Name)) { continue; } foreach (var fanD in room.DeviceList) { //2020-02-10 byte [] returnBytes = null; if (fanD.Type == DeviceType.FanModule) { if (open) { if ((fanD as FanModule).WindSpeed == 0) (fanD as FanModule).WindSpeed = 1; returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, fanD.SubnetID, fanD.DeviceID, new byte [] { fanD.LoopID, (fanD as FanModule).WindSpeed }); } else { returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, fanD.SubnetID, fanD.DeviceID, new byte [] { fanD.LoopID, 0 }); } if (showTip) { if (returnBytes == null) { Application.RunOnMainThread (() => { string tipString = Language.StringByID (R.MyInternationalizationString.ControlFailure); var btnTip = new Button () { Height = Application.GetRealHeight (140), Text = fanD.Name + tipString,// + "..." + controlDeviceIndex.ToString () + @"/" + sceneDeviceCount.ToString (), BackgroundColor = 0xFFD7D7D7, }; MainPage.MainFrameLayout.AddChidren (btnTip); btnTip.MouseUpEventHandler += (sender, e) => { btnTip.RemoveFromParent (); //MainPage.MainFrameLayout.Remove (btnTip); showTip = false; }; System.Threading.Tasks.Task.Run (() => { System.Threading.Thread.Sleep (3000); Application.RunOnMainThread (() => { btnTip.RemoveFromParent (); //MainPage.MainFrameLayout.Remove (btnTip); }); }); }); } } } } } Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); }); } void ControlAllFanNew (bool open) { if (CommonPage.IsRemote) { if (!SmartHome.MqttCommon.IsGatewayOnline) { new Alert ("", "Gateway offline" + ErrorCode.ControlFailure, "Close").Show (); return; } } MainPage.Loading.Start ("Sending..."); bool showTip = true; System.Threading.Tasks.Task.Run (() => { int mSendCount = 0; foreach (var room in Room.Lists) { if (room == null) continue; if (string.IsNullOrEmpty (room.Name)) { continue; } foreach (var fanD in room.DeviceList) { //2020-02-10 byte [] returnBytes = null; if (fanD.Type == DeviceType.FanModule) { System.Threading.Tasks.Task.Run (() => { mSendCount++; if (open) { returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, fanD.SubnetID, fanD.DeviceID, new byte [] { fanD.LoopID, (fanD as FanModule).WindSpeed }); } else { returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, fanD.SubnetID, fanD.DeviceID, new byte [] { fanD.LoopID, 0 }); } if (showTip) { if (returnBytes == null) { Application.RunOnMainThread (() => { string tipString = Language.StringByID (R.MyInternationalizationString.ControlFailure); var btnTip = new Button () { Height = Application.GetRealHeight (140), Text = fanD.Name + tipString,// + "..." + controlDeviceIndex.ToString () + @"/" + sceneDeviceCount.ToString (), BackgroundColor = 0xFFD7D7D7, }; MainPage.MainFrameLayout.AddChidren (btnTip); btnTip.MouseUpEventHandler += (sender, e) => { btnTip.RemoveFromParent (); //MainPage.MainFrameLayout.Remove (btnTip); showTip = false; }; System.Threading.Tasks.Task.Run (() => { System.Threading.Thread.Sleep (3000); Application.RunOnMainThread (() => { btnTip.RemoveFromParent (); //MainPage.MainFrameLayout.Remove (btnTip); }); }); }); } } mSendCount--; }); //等待100ms再发送第二个设备数据 System.Threading.Thread.Sleep (100); } } } while (mSendCount > 0) { System.Threading.Thread.Sleep (100); } Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); }); } } }