using Shared.SimpleControl.Phone; using System; namespace Shared.SimpleControl.Pad { public class UserFan : FrameLayout { public static UserFan curView; FrameLayout speedView; Button btnBottomSwitch; Button btnSwitch; FanModule fanModule; public UserFan (FanModule fan) { curView = this; fanModule = fan; showLightsRoom (); BackgroundColor = 0xFF2f2f2f; } public void showLightsRoom () { var roomBackgroundImage = new FrameLayout () { Height = Application.GetRealHeight (Application.DesignHeight), BackgroundImagePath = "Fan/FanSpeedBackground.png" }; AddChidren (roomBackgroundImage); int padX = 570; speedView = new FrameLayout () { X = Application.GetRealWidth (padX - 70), Y = Application.GetRealHeight (100), Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (500), BackgroundImagePath = "Fan/Speed0.png", }; roomBackgroundImage.AddChidren (speedView); Button btnSpeed8 = new Button () { X = Application.GetRealWidth (100), Y = Application.GetRealHeight (20), Width = Application.GetRealWidth (140), Height = Application.GetRealHeight (90), Radius = 5, }; speedView.AddChidren (btnSpeed8); btnSpeed8.MouseDownEventHandler += (sender, e) => { fanModule.WindSpeed = 8; Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, 8 }); speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png"; IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ()); }; Button btnSpeed1 = new Button () { X = btnSpeed8.Right + Application.GetRealWidth (20), Y = btnSpeed8.Y, Width = Application.GetRealWidth (140), Height = Application.GetRealHeight (90), Radius = 5, }; speedView.AddChidren (btnSpeed1); btnSpeed1.MouseDownEventHandler += (sender, e) => { fanModule.WindSpeed = 1; Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, 1 }); speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png"; IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ()); }; Button btnSpeed2 = new Button () { X = Application.GetRealWidth (380), Y = Application.GetRealHeight (130), Width = Application.GetRealWidth (105), Height = Application.GetRealHeight (105), Radius = 5, }; speedView.AddChidren (btnSpeed2); btnSpeed2.MouseDownEventHandler += (sender, e) => { fanModule.WindSpeed = 2; Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, 2 }); speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png"; IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ()); }; Button btnSpeed3 = new Button () { X = Application.GetRealWidth (380), Y = btnSpeed2.Bottom + Application.GetRealHeight (20), Width = Application.GetRealWidth (105), Height = Application.GetRealHeight (105), Radius = 5, }; speedView.AddChidren (btnSpeed3); btnSpeed3.MouseDownEventHandler += (sender, e) => { fanModule.WindSpeed = 3; Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, 3 }); speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png"; IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ()); }; Button btnSpeed4 = new Button () { X = btnSpeed1.X, Y = btnSpeed3.Bottom + Application.GetRealHeight (20), Width = Application.GetRealWidth (140), Height = Application.GetRealHeight (90), Radius = 5, }; speedView.AddChidren (btnSpeed4); btnSpeed4.MouseDownEventHandler += (sender, e) => { fanModule.WindSpeed = 4; Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, 4 }); speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png"; IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ()); }; Button btnSpeed5 = new Button () { X = btnSpeed8.X, Y = btnSpeed4.Y, Width = Application.GetRealWidth (140), Height = Application.GetRealHeight (90), Radius = 5, }; speedView.AddChidren (btnSpeed5); btnSpeed5.MouseDownEventHandler += (sender, e) => { fanModule.WindSpeed = 5; Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, 5 }); speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png"; IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ()); }; Button btnSpeed6 = new Button () { X = Application.GetRealWidth (20), Y = btnSpeed3.Y, Width = Application.GetRealWidth (105), Height = Application.GetRealHeight (105), Radius = 5, }; speedView.AddChidren (btnSpeed6); btnSpeed6.MouseDownEventHandler += (sender, e) => { fanModule.WindSpeed = 6; Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, 6 }); speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png"; IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ()); }; Button btnSpeed7 = new Button () { X = Application.GetRealWidth (20), Y = btnSpeed2.Y, Width = Application.GetRealWidth (105), Height = Application.GetRealHeight (105), Radius = 5, }; speedView.AddChidren (btnSpeed7); btnSpeed7.MouseDownEventHandler += (sender, e) => { fanModule.WindSpeed = 7; Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, 7 }); speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png"; IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ()); }; btnSwitch = new Button () { Gravity = Gravity.Center, Width = Application.GetMinRealAverage (260), Height = Application.GetMinRealAverage (260), SelectedImagePath = "Fan/FanIconSwitchOn.png", UnSelectedImagePath = "Fan/FanIconSwitch.png", Radius = (uint)Application.GetMinRealAverage(100), IsSelected = false }; speedView.AddChidren (btnSwitch); btnBottomSwitch = new Button () { X = Application.GetRealWidth (620), Y = speedView.Bottom + Application.GetRealHeight (250), Width = Application.GetRealWidth (215), Height = Application.GetRealHeight (95), SelectedImagePath = "Fan/FanSwitchOn.png", UnSelectedImagePath = "Fan/FanSwitch.png", IsSelected = false }; AddChidren (btnBottomSwitch); btnSwitch.MouseDownEventHandler += (sender, e) => { if (btnSwitch.IsSelected) { btnBottomSwitch.IsSelected = false; btnSwitch.IsSelected = false; Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, 0 }); fanModule.Switch = fanModule.WindSpeed; speedView.BackgroundImagePath = "Fan/Speed0.png"; } else { btnSwitch.IsSelected = true; btnBottomSwitch.IsSelected = true; Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, fanModule.Switch }); speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png"; } IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ()); }; btnBottomSwitch.MouseDownEventHandler += (sender, e) => { if (btnBottomSwitch.IsSelected) { btnBottomSwitch.IsSelected = false; btnSwitch.IsSelected = false; Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, 0 }); fanModule.Switch = fanModule.WindSpeed; speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png"; } else { btnBottomSwitch.IsSelected = true; btnSwitch.IsSelected = true; Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, fanModule.Switch }); speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png"; } IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ()); }; Control.ControlBytesSend (Command.ReadLightEquipmentAllLoopBrightness, fanModule.SubnetID, fanModule.DeviceID, new byte [] { }); } public static void UpdataFanView (string updataFlag, byte windSpeed) { Application.RunOnMainThread (() => { if (curView == null) return; if (curView.fanModule.CommonLoopID != updataFlag) return; if (windSpeed == 0) { curView.btnBottomSwitch.IsSelected = false; curView.btnSwitch.IsSelected = false; curView.speedView.BackgroundImagePath = "Fan/Speed" + windSpeed.ToString () + ".png"; } else { curView.btnBottomSwitch.IsSelected = true; curView.btnSwitch.IsSelected = true; curView.speedView.BackgroundImagePath = "Fan/Speed" + windSpeed.ToString () + ".png"; } }); } } }