using System; using System.Collections.Generic; using HDL_ON.DriverLayer; using HDL_ON.Entity; using HDL_ON.UI.CSS; using Shared; namespace HDL_ON.UI { public class AcstSubPage : FrameLayout { static AcstSubPage bodyView; Button btnTempValues; Button btnHumiValues; Button btnSetTempValues; DiyImageSeekBar tempBar; Button btnPowerControl; Function function; uint curColor; string colorString; string imageFolder = "blue"; public static void UpdateStatus(Function temp) { if(bodyView == null || bodyView.function.sid != temp.sid) { return; } Application.RunOnMainThread(() => { bodyView.btnTempValues.Text = temp.GetAttrState(AcstSub_AttrEnum.room_temp.ToString()); bodyView.btnHumiValues.Text = temp.GetAttrState(AcstSub_AttrEnum.room_humidity.ToString()); int setTempValue = 0; double dd = 0; double.TryParse(temp.GetAttrState(AcstSub_AttrEnum.set_temp.ToString(), "--"), out dd); setTempValue = Convert.ToInt32(dd); if (setTempValue != 0) bodyView.btnSetTempValues.Text = setTempValue.ToString(); //bodyView.btnSetTempValues.Width = bodyView.btnSetTempValues.GetTextWidth() + Application.GetRealWidth(10); //int progress = 0; //int.TryParse(temp.GetAttrState(AcstSub_AttrEnum.set_temp.ToString()), out progress); if (bodyView.tempBar.Progress != setTempValue - 16) bodyView.tempBar.Progress = setTempValue - 16; if(temp.trait_on_off.curValue.ToString() == "on") { bodyView.btnPowerControl.IsSelected = true; bodyView.tempBar.ProgressBarColor = bodyView.curColor; //bodyView.tempBar.IsClickable = function.trait_on_off.curValue.ToString() == "off", //bodyView.tempBar.IsOffline = false; } else { bodyView.btnPowerControl.IsSelected = false; bodyView.tempBar.ProgressBarColor = CSS_Color.DividingLineColor; //bodyView.tempBar.IsOffline = true; } }); } public AcstSubPage(Function temp, string path) { function = temp; imageFolder = path; switch (imageFolder) { case "blue": curColor = CSS_Color.MainColor; colorString = "#4484F4"; break; case "orange": curColor = 0xFFFFB848; colorString = "#FFB848"; break; case "purple": curColor = 0xFF9175F3; colorString = "#9175F3"; break; } bodyView = this; } public void LoadPage(Action action) { new TopViewDiv(bodyView, function.name).LoadTopView_FunctionTop(function,action); var contentView = new FrameLayout() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(79), Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(570), BackgroundColor = CSS.CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(6), }; bodyView.AddChidren(contentView); #region 温湿度数据 var tempHumiView = new FrameLayout() { Y = Application.GetRealWidth(58), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(303), Height = Application.GetRealWidth(175), BackgroundImagePath = $"FunctionIcon/Acst/{imageFolder}/TempAndHumiBack.png" }; contentView.AddChidren(tempHumiView); var tempValuesView = new FrameLayout() { X = Application.GetRealWidth(21), Y = Application.GetRealWidth(22), Width = Application.GetRealWidth(130), Height = Application.GetRealWidth(132), }; tempHumiView.AddChidren(tempValuesView); btnTempValues = new Button() { Y = Application.GetRealWidth(38), Height = Application.GetRealWidth(66), IsBold = true, TextSize = 30, TextColor = CSS.CSS_Color.FirstLevelTitleColor, TextAlignment = TextAlignment.TopRight, Text = function.GetAttrState(AcstSub_AttrEnum.room_temp.ToString(),"---"), }; #if __IOS__ btnTempValues.Width = btnTempValues.GetTextWidth() + Application.GetRealWidth(10); #else btnTempValues.Width = btnTempValues.GetTextWidth(); #endif btnTempValues.Gravity = Gravity.CenterHorizontal; tempValuesView.AddChidren(btnTempValues); var btnTempValuesUint = new Button() { X = btnTempValues.Right, //Y = Application.GetRealWidth(48), Y = Application.GetRealWidth(45), Height = Application.GetRealWidth(66), TextAlignment = TextAlignment.TopLeft, Width = Application.GetRealWidth(30), //Height = Application.GetRealWidth(30), TextSize = 10, TextColor = CSS.CSS_Color.FirstLevelTitleColor, Text = "°C" }; tempValuesView.AddChidren(btnTempValuesUint); var humiValuesView = new FrameLayout() { X = Application.GetRealWidth(130+21), Y = Application.GetRealWidth(22), Width = Application.GetRealWidth(130), Height = Application.GetRealWidth(132), }; tempHumiView.AddChidren(humiValuesView); btnHumiValues = new Button() { Y = Application.GetRealWidth(39), Height = Application.GetRealWidth(66), IsBold = true, TextSize = 30, TextColor = CSS.CSS_Color.FirstLevelTitleColor, Text = function.GetAttrState(AcstSub_AttrEnum.room_humidity.ToString(),"---"), TextAlignment = TextAlignment.TopRight, }; btnHumiValues.Width = btnTempValues.GetTextWidth(); btnHumiValues.Gravity = Gravity.CenterHorizontal; humiValuesView.AddChidren(btnHumiValues); var btnHumiValuesUint = new Button() { X = btnTempValues.Right, Y = Application.GetRealWidth(45), TextAlignment = TextAlignment.TopLeft, Width = Application.GetRealWidth(30), Height = Application.GetRealWidth(66), TextSize = 10, TextColor = CSS.CSS_Color.FirstLevelTitleColor, Text = "%" }; humiValuesView.AddChidren(btnHumiValuesUint); EventHandler eventHandler = (sender, e) => { var page = new AcstSubHistoryPage(function, colorString); MainPage.BasePageView.AddChidren(page); page.LoadPage(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }; var btnClick = new Button(); tempHumiView.AddChidren(btnClick); btnClick.MouseUpEventHandler = eventHandler; #endregion int setTempValue = 0; string setTempStr = "--"; double dd = 0; double.TryParse(function.GetAttrState(AcstSub_AttrEnum.set_temp.ToString(), "--"), out dd); setTempValue = Convert.ToInt32(dd); if (setTempValue != 0) setTempStr = setTempValue.ToString(); btnSetTempValues = new Button() { X = Application.GetRealWidth((375 - 77 -30)/2), Y = Application.GetRealHeight(260), Width = Application.GetRealWidth(73), Height = Application.GetRealHeight(90), TextAlignment = TextAlignment.TopCenter, TextColor = CSS.CSS_Color.FirstLevelTitleColor, IsBold = true, TextSize = 60, Text = setTempStr }; contentView.AddChidren(btnSetTempValues); #if __IOS__ bodyView.btnSetTempValues.Width = bodyView.btnSetTempValues.GetTextWidth() + Application.GetRealWidth(10); #endif var btnSetTempUnit = new Button() { X = btnSetTempValues.Right + Application.GetRealWidth(3), Y = Application.GetRealHeight(267), Width = Application.GetRealWidth(50), Height = Application.GetRealHeight(50), TextSize = 23, TextColor = CSS.CSS_Color.FirstLevelTitleColor, Text = "°C", TextAlignment = TextAlignment.TopLeft, }; contentView.AddChidren(btnSetTempUnit); var btnMinValuesText = new Button() { X = Application.GetRealWidth(35), Y = Application.GetRealHeight(388), Width = Application.GetRealWidth(30), Height = Application.GetRealHeight(52), Text = "16", TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, }; contentView.AddChidren(btnMinValuesText); //int progress = 0; //int.TryParse(function.GetAttrState(FunctionAttributeKey.SetTemp),out progress); tempBar = new DiyImageSeekBar() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(378), Width = Application.GetRealWidth(238), Height = Application.GetRealHeight(72), SeekBarViewHeight = Application.GetRealHeight(14), ThumbImagePath = "FunctionIcon/Acst/ThumbImage.png", ThumbImageHeight = Application.GetRealHeight(51), ProgressBarColor = function.trait_on_off.curValue.ToString() == "on" ? curColor : CSS_Color.DividingLineColor, MaxValue = 14, Progress = setTempValue - 16, SeekBarPadding = Application.GetRealWidth(20), IsProgressTextShow = false, ProgressChangeDelayTime = 0, //IsClickable = function.trait_on_off.curValue.ToString() == "off", //Enable = function.trait_on_off.curValue.ToString() == "off", //IsOffline = true,// function.trait_on_off.curValue.ToString() == "off", }; contentView.AddChidren(tempBar); tempBar.OnProgressChangedEvent = (sender, e) => { btnSetTempValues.Text = (e + 16).ToString(); }; tempBar.OnStopTrackingTouchEvent = (sender, e) => { new System.Threading.Thread(() => { var d = new Dictionary(); d.Add(FunctionAttributeKey.SetTemp, (e+16).ToString()); Control.Ins.SendWriteCommand(function, d); }) { IsBackground = true }.Start(); }; var btnMaxValuesText = new Button() { X = tempBar.Right + Application.GetRealWidth(10), Y = btnMinValuesText.Y, Width = Application.GetRealWidth(45), Height = Application.GetRealHeight(52), Text = "30", TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, }; contentView.AddChidren(btnMaxValuesText); btnPowerControl = new Button() { Y = Application.GetRealHeight(496), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(46), Height = Application.GetRealWidth(46), UnSelectedImagePath = "FunctionIcon/Acst/grey/PowerOffIcon.png", SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/PowerIcon.png", TextAlignment = TextAlignment.Center, IsSelected = function.trait_on_off.curValue.ToString() == "on" }; contentView.AddChidren(btnPowerControl); btnPowerControl.MouseUpEventHandler = (sender, e) => { btnPowerControl.IsSelected = !btnPowerControl.IsSelected; new System.Threading.Thread(() => { Dictionary d = new Dictionary(); d.Add(FunctionAttributeKey.OnOff, btnPowerControl.IsSelected ? "on" : "off"); Control.Ins.SendWriteCommand(function, d); }) { IsBackground = true }.Start(); }; Control.Ins.SendReadCommand(function); } } }