using System; using System.Collections.Generic; using HDL_ON.DriverLayer; using HDL_ON.Entity; using Shared; namespace HDL_ON.UI { /// /// 绿建科技系统 /// 总控主页 /// public class AcstParentPage : FrameLayout { static AcstParentPage basePage; VerticalScrolViewLayout contentView; string helloText = "上午好"; #region 天气控件 Button btnOutdoorTemp; Button btnWeather; TextButton btnHumidityValues; TextButton btnPm25Values; #endregion #region 传感器、耗电量组件 SensorDiyView sensorDiyView_Temp; SensorDiyView sensorDiyView_Humi; SensorDiyView sensorDiyView_Pm25; SensorDiyView sensorDiyView_Co2; SensorDiyView sensorDiyView_Tvoc; SensorDiyView sensorDiyView_EleDay; SensorDiyView sensorDiyView_EleMonth; SensorDiyView sensorDiyView_EleActivePower; #endregion /// /// 子控区域列表 /// Dictionary subViewList; Button btnWorkSceneControl; Button btnModeControl; Button btnPowerControl; public override void RemoveFromParent() { base.RemoveFromParent(); basePage = null; } Function function; /// /// 当前时段颜色 /// uint curColor = CSS.CSS_Color.MainColor; string imageFolder = "blue"; public AcstParentPage() { basePage = this; var curTime = DateTime.Now; if (Language.CurrentLanguage != "Chinese") { helloText = "Good morning"; } if (curTime.Hour >= 8 && curTime.Hour < 12) { helloText = "上午好"; if (Language.CurrentLanguage != "Chinese") { helloText = "Good morning"; } curColor = CSS.CSS_Color.MainColor; imageFolder = "blue"; } else if (curTime.Hour >= 12 && curTime.Hour < 18) { helloText = "下午好"; if (Language.CurrentLanguage != "Chinese") { helloText = "Good afternoon"; } curColor = 0xFFE7914F; imageFolder = "orange"; } else { helloText = "晚上好"; if (Language.CurrentLanguage != "Chinese") { helloText = "Good evening"; } curColor = 0xFF9175F3; imageFolder = "purple"; } this.function = FunctionList.List.GetAcstParentList()[0]; this.BackgroundColor = CSS.CSS_Color.BackgroundColor; //this.AddChidren(new Button() { Height = Application.GetRealHeight(50), BackgroundColor = curColor }); contentView = new VerticalScrolViewLayout() { Height = Application.GetRealHeight(667 - 56), }; this.AddChidren(contentView); subViewList = new Dictionary(); } /// /// 更新天气信息 /// public void InitGetWeatherAction() { MainPage.CityWeatherAction = () => { Application.RunOnMainThread(() => { btnOutdoorTemp.Text = MainPage.cityInfo.temperature + "°"; btnWeather.Text = MainPage.cityInfo.weather; btnHumidityValues.Text = MainPage.cityInfo.humidity + "%"; btnHumidityValues.Width = btnHumidityValues.GetTextWidth() + Application.GetRealWidth(10); btnPm25Values.Text = MainPage.cityInfo.pm25; btnPm25Values.Width = btnPm25Values.GetTextWidth() + Application.GetRealWidth(10); }); }; } /// /// 更新主控数据信息 /// public static void UpdateAcstParentInfo(Function temp) { try { if (basePage == null) { return; } Application.RunOnMainThread(() => { if (basePage.sensorDiyView_Temp != null) basePage.sensorDiyView_Temp.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.room_temp.ToString()).state, true); if (basePage.sensorDiyView_Humi != null) basePage.sensorDiyView_Humi.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.room_humidity.ToString()).state, true); if (basePage.sensorDiyView_Pm25 != null) basePage.sensorDiyView_Pm25.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.pm25.ToString()).state, false); if (basePage.sensorDiyView_Co2 != null) basePage.sensorDiyView_Co2.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.co2.ToString()).state, false); if (basePage.sensorDiyView_Tvoc != null) basePage.sensorDiyView_Tvoc.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.tvoc.ToString()).state, false); if (basePage.sensorDiyView_EleDay != null) basePage.sensorDiyView_EleDay.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.day_electricity.ToString()).state, false); if (basePage.sensorDiyView_EleMonth != null) basePage.sensorDiyView_EleMonth.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.month_electricity.ToString()).state, false); if (basePage.sensorDiyView_EleActivePower != null) basePage.sensorDiyView_EleActivePower.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.active_power.ToString()).state, false); switch (temp.GetAttrState("mode")) { case "cool"://制冷 basePage.btnModeControl.UnSelectedImagePath = "FunctionIcon/Acst/grey/ModeCoolIcon2.png"; basePage.btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{basePage.imageFolder}/ModeCoolIcon2.png"; break; case "heat"://制热 basePage.btnModeControl.UnSelectedImagePath = "FunctionIcon/Acst/grey/ModeHeatIcon2.png"; basePage.btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{basePage.imageFolder}/ModeHeatIcon2.png"; break; case "fan"://通风 basePage.btnModeControl.UnSelectedImagePath = "FunctionIcon/Acst/grey/ModeFanIcon2.png"; basePage.btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{basePage.imageFolder}/ModeFanIcon2.png"; break; case "dry"://除湿 basePage.btnModeControl.UnSelectedImagePath = "FunctionIcon/Acst/grey/ModeDeHumiIcon2.png"; basePage.btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{basePage.imageFolder}/ModeDeHumiIcon2.png"; break; case "humidity"://加湿 basePage.btnModeControl.UnSelectedImagePath = "FunctionIcon/Acst/grey/ModeHumiIcon2.png"; basePage.btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{basePage.imageFolder}/ModeHumiIcon2.png"; break; case "heat_humidity"://制热加湿 basePage.btnModeControl.UnSelectedImagePath = "FunctionIcon/Acst/grey/ModeHeatHumiIcon2.png"; basePage.btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{basePage.imageFolder}/ModeHeatHumiIcon2.png"; break; } switch (temp.GetAttrState("scene")) { case "at_home"://在家 basePage.btnWorkSceneControl.UnSelectedImagePath = "FunctionIcon/Acst/grey/SceneAtHome2.png"; basePage.btnWorkSceneControl.SelectedImagePath = $"FunctionIcon/Acst/{basePage.imageFolder}/SceneAtHome2.png"; break; case "leave_home"://离家 basePage.btnWorkSceneControl.UnSelectedImagePath = "FunctionIcon/Acst/grey/SceneAwayHomeIcon2.png"; basePage.btnWorkSceneControl.SelectedImagePath = $"FunctionIcon/Acst/{basePage.imageFolder}/SceneAwayHomeIcon2.png"; break; case "sleep"://睡眠 basePage.btnWorkSceneControl.UnSelectedImagePath = "FunctionIcon/Acst/grey/SceneSleepIcon2.png"; basePage.btnWorkSceneControl.SelectedImagePath = $"FunctionIcon/Acst/{basePage.imageFolder}/SceneSleepIcon2.png"; break; } basePage.btnModeControl.IsSelected = basePage.btnWorkSceneControl.IsSelected = basePage.btnPowerControl.IsSelected = temp.GetAttrState("on_off") == "on"; }); }catch (Exception ex) { MainPage.Log("科技系统更新数据失败"); } } /// /// 更新子控信息 /// /// public static void UpdateAcstSubInfo(Function temp) { try { if (basePage == null) { return; } Application.RunOnMainThread(() => { try { AcstSubControlView view = null; basePage.subViewList.TryGetValue(temp.sid, out view); if (view != null) { view.btnSubHumidityValues.Text = temp.GetAttrState(AcstSub_AttrEnum.room_humidity.ToString()) + "%"; view.btnSubTempValues.Text = temp.GetAttrState(AcstSub_AttrEnum.room_temp.ToString()) + "°"; view.btnSubPower.IsSelected = temp.GetAttrState(AcstSub_AttrEnum.on_off.ToString()) == "on"; } } catch (Exception ex ) { MainPage.Log($"科技系统更新异常1:{ex.Message}"); } }); } catch (Exception ex) { MainPage.Log($"科技系统更新异常123:{ex.Message}"); } } public void LoadPage() { #region 头部信息区域 FrameLayout topView = new FrameLayout() { Height = Application.GetRealHeight(180), BackgroundImagePath = $"FunctionIcon/Acst/{imageFolder}/TopViewBg.png", }; contentView.AddChidren(topView); var backView = new FrameLayout() { Y = Application.GetRealHeight(32), Width = Application.GetRealWidth(100), Height = Application.GetRealHeight(34), }; topView.AddChidren(backView); Button btnBackIcon = new Button() { X = Application.GetRealWidth(16), Width = Application.GetRealWidth(12), Height = Application.GetRealHeight(20), UnSelectedImagePath = "FunctionIcon/Acst/BackIcon.png", }; backView.AddChidren(btnBackIcon); Button btnBackClick = new Button(); backView.AddChidren(btnBackClick); btnBackClick.MouseUpEventHandler = (sender, e) => { this.RemoveFromParent(); }; var btnHelloText = new Button() { X = Application.GetRealWidth(25), Y = Application.GetRealHeight(55), Width = Application.GetRealWidth(200), Height = Application.GetRealHeight(38), TextSize = 20, Text = helloText, TextColor = 0xFFFFFFFF, TextAlignment = TextAlignment.CenterLeft, }; topView.AddChidren(btnHelloText); btnOutdoorTemp = new Button() { X = Application.GetRealWidth(25), Y = Application.GetRealHeight(90), Width = Application.GetRealWidth(85), Height = Application.GetRealHeight(66), TextColor = 0xFFFFFFFF, TextSize = 50, TextAlignment = TextAlignment.TopLeft, Text = MainPage.cityInfo.temperature + "°" }; topView.AddChidren(btnOutdoorTemp); btnWeather = new Button() { X = btnOutdoorTemp.Right, Y = Application.GetRealHeight(95), Width = Application.GetRealWidth(80), Height = Application.GetRealHeight(26), Text = MainPage.cityInfo.weather, TextColor = 0xFFFFFFFF, TextSize = 14, TextAlignment = TextAlignment.CenterLeft, }; topView.AddChidren(btnWeather); var environmentalView = new FrameLayout() { Y = Application.GetRealHeight(150), Height = Application.GetRealHeight(32), }; topView.AddChidren(environmentalView); var btnHumidityIcon = new Button() { X = Application.GetRealWidth(25), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(16), Height = Application.GetMinRealAverage(16), UnSelectedImagePath = "Public/DeviceInfoIcon/HumidityIcon.png", }; environmentalView.AddChidren(btnHumidityIcon); btnHumidityValues = new TextButton() { X = btnHumidityIcon.Right + Application.GetRealWidth(4), Gravity = Gravity.CenterVertical, TextColor = 0xFFFFFFFF, TextSize = 16, Text = MainPage.cityInfo.humidity + "%", TextAlignment = TextAlignment.CenterLeft, }; btnHumidityValues.Width = btnHumidityValues.GetTextWidth(); environmentalView.AddChidren(btnHumidityValues); var btnPm25Icon = new Button() { X = btnHumidityValues.Right + Application.GetRealWidth(14), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(16), Height = Application.GetMinRealAverage(16), UnSelectedImagePath = "Public/DeviceInfoIcon/Pm25Icon.png", }; environmentalView.AddChidren(btnPm25Icon); btnPm25Values = new TextButton() { X = btnPm25Icon.Right + Application.GetRealWidth(4), Gravity = Gravity.CenterVertical, TextColor = 0xFFFFFFFF, TextSize = 16, Text = MainPage.cityInfo.pm25, TextAlignment = TextAlignment.CenterLeft, }; btnPm25Values.Width = btnPm25Values.GetTextWidth(); environmentalView.AddChidren(btnPm25Values); #endregion contentView.AddChidren(new Button { Height = Application.GetRealHeight(8), }); #region 数据 #region 传感器数据总计 int sensorCount = 0; var tempObj = function.GetAttribute(AcstParent_AttrEnum.room_temp.ToString()); if (tempObj != null) { sensorCount++; } var humiObj = function.GetAttribute(AcstParent_AttrEnum.room_humidity.ToString()); if (humiObj != null) { sensorCount++; } var pm25Obj = function.GetAttribute(AcstParent_AttrEnum.pm25.ToString()); if (pm25Obj != null) { sensorCount++; } var co2Obj = function.GetAttribute(AcstParent_AttrEnum.co2.ToString()); if (co2Obj != null) { sensorCount++; } var tvocObj = function.GetAttribute(AcstParent_AttrEnum.tvoc.ToString()); if (tvocObj != null) { sensorCount++; } #endregion #region 能耗数据统计 int energyCount = 0; var totalObj = function.GetAttribute(AcstParent_AttrEnum.active_power.ToString()); if (totalObj != null) { energyCount++; } var dayObj = function.GetAttribute(AcstParent_AttrEnum.day_electricity.ToString()); if (dayObj != null) { energyCount++; } var monthObj = function.GetAttribute(AcstParent_AttrEnum.month_electricity.ToString()); if (monthObj != null) { energyCount++; } #endregion if (energyCount > 0 || sensorCount > 0) { var infoView = new FrameLayout() { Y = topView.Bottom, Height = Application.GetRealHeight(104), BackgroundColor = CSS.CSS_Color.MainBackgroundColor, }; contentView.AddChidren(infoView); var infoContentView = new FrameLayout() { Gravity = Gravity.Center, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(72), BackgroundImagePath = $"FunctionIcon/Acst/{imageFolder}/MsgViewBg.png", }; infoView.AddChidren(infoContentView); #region 传感器数据 var sensorListView = new HorizontalScrolViewLayout() { Width = Application.GetRealWidth(60 * sensorCount), Gravity = Gravity.Center, }; if (sensorCount > 0) { infoContentView.AddChidren(sensorListView); } if (tempObj != null) { string tempValues = tempObj.state == "" ? "--" : tempObj.state; if (tempValues.Contains(".")) { tempValues = tempValues.Remove(tempValues.IndexOf('.'), tempValues.Length - tempValues.IndexOf('.')); } sensorDiyView_Temp = new SensorDiyView(sensorListView, curColor, tempValues, "°","", Language.StringByID(StringId.Temp)); } if (humiObj != null) { string humiValues = humiObj.state == "" ? "--" : humiObj.state; if (humiValues.Contains(".")) { humiValues = humiValues.Remove(humiValues.IndexOf('.'), humiValues.Length - humiValues.IndexOf('.')); } sensorDiyView_Humi = new SensorDiyView(sensorListView, curColor, humiValues , "%", "", Language.StringByID(StringId.Humidity)); } if (pm25Obj != null) { sensorDiyView_Pm25 = new SensorDiyView(sensorListView, curColor, pm25Obj.state == "" ? "--" : pm25Obj.state, "", "", "PM2.5"); } if (co2Obj != null) { sensorDiyView_Co2 = new SensorDiyView(sensorListView, curColor, co2Obj.state == "" ? "--" : co2Obj.state, "", "", "CO2"); } if (tvocObj != null) { sensorDiyView_Tvoc = new SensorDiyView(sensorListView, curColor, tvocObj.state == "" ? "--" : tvocObj.state, "", "", "TVOC"); } #endregion #region 能耗数据 var energyListView = new HorizontalScrolViewLayout() { Width = Application.GetRealWidth(100 * energyCount), Gravity = Gravity.Center, Visible = sensorCount == 0 }; if (energyCount > 0) { infoContentView.AddChidren(energyListView); } if (totalObj != null) { string text = "用电功率"; if (Language.CurrentLanguage != "Chinese") { text = "Power"; } sensorDiyView_EleActivePower = new SensorDiyView(energyListView, curColor, totalObj.state == "" ? "--" : totalObj.state, "", "KW", text, 100); } if (dayObj != null) { string text = "今日耗电"; if (Language.CurrentLanguage != "Chinese") { text = "Power of today"; } sensorDiyView_EleDay = new SensorDiyView(energyListView, curColor, dayObj.state == "" ? "--" : dayObj.state, "", "KWh", text, 100); } if (monthObj != null) { string text = "本月耗电"; if (Language.CurrentLanguage != "Chinese") { text = "Power of month"; } sensorDiyView_EleMonth = new SensorDiyView(energyListView, curColor, monthObj.state == "" ? "--" : monthObj.state, "", "KWh", text, 100); } var btnChangeClick = new Button(); infoView.AddChidren(btnChangeClick); bool showSensor = true; EventHandler changeInfoEvent = (sender, e) => { if (showSensor) { sensorListView.Visible = false; showSensor = false; energyListView.Visible = true; } else { sensorListView.Visible = true; showSensor = true; energyListView.Visible = false; } }; if (sensorCount > 0 && energyCount > 0) { btnChangeClick.MouseUpEventHandler = changeInfoEvent; } #endregion } #endregion #region 子控列表 var subTitleView = new FrameLayout() { Height = Application.GetRealHeight(54-11), }; contentView.AddChidren(subTitleView); var btnCollection = new Button() { X = Application.GetRealWidth(6), Y = Application.GetRealHeight(10), Width = Application.GetRealWidth(39), Height = Application.GetRealWidth(39), IsSelected = function.collect, UnSelectedImagePath = "FunctionIcon/Acst/grey/CollectionIcon.png", SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/CollectionIcon.png", }; subTitleView.AddChidren(btnCollection); //收藏 btnCollection.MouseUpEventHandler = (sender, e) => { function.collect = !function.collect; btnCollection.IsSelected = function.collect; //var http = new DAL.Server.HttpServerRequest(); //http.CollectDevice(function.deviceId); function.CollectFunction(); }; var btnTitleText2 = new Button() { X = btnCollection.Right, TextID = StringId.MyHome, TextSize = 16, TextColor = 0xFF242424, TextAlignment = TextAlignment.CenterLeft, IsBold = true, Height = Application.GetRealHeight(54), }; subTitleView.AddChidren(btnTitleText2); int subFunctionCount = 0; var subFunctionListView = new HorizontalScrolViewLayout() { Height = Application.GetRealHeight(88), }; contentView.AddChidren(subFunctionListView); subFunctionListView.AddChidren(new Button { Width = Application.GetRealWidth(9) }); new System.Threading.Thread(() => { try { #if DEBUG System.Threading.Thread.Sleep(200); #endif foreach (var sub in FunctionList.List.GetAcstSubList()) { if (subViewList.ContainsKey(sub.sid)) { continue; } Application.RunOnMainThread(() => { if (subFunctionCount > 0 && subFunctionCount % 2 == 0) { subFunctionListView = new HorizontalScrolViewLayout() { Height = Application.GetRealHeight(93), }; contentView.AddChidren(subFunctionListView); subFunctionListView.AddChidren(new Button { Width = Application.GetRealWidth(9) }); } AcstSubControlView subFunctionView = new AcstSubControlView(sub, subFunctionListView, imageFolder); subViewList.Add(sub.sid, subFunctionView); if (basePage != null) { new System.Threading.Thread(() => { Control.Ins.SendReadCommand(sub); }) { IsBackground = true }.Start(); } subFunctionCount++; }); System.Threading.Thread.Sleep(10); } } catch { } finally{ } }).Start(); #endregion #region 底部控制栏 var bottomView = new FrameLayout() { Y = Application.GetRealHeight(667 - 56), Height = Application.GetRealHeight(56), BackgroundColor = CSS.CSS_Color.MainBackgroundColor, }; this.AddChidren(bottomView); btnModeControl = new Button() { X = Application.GetRealWidth(89), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(38), Height = Application.GetRealWidth(38), UnSelectedImagePath = "FunctionIcon/Acst/grey/ModeCoolIcon2.png", SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/ModeCoolIcon2.png", TextAlignment = TextAlignment.Center, IsSelected = function.trait_on_off.state == "on" }; bottomView.AddChidren(btnModeControl); btnModeControl.MouseUpEventHandler = (sender3, e3) => { //if(function.trait_on_off.state == "off") //{ // return; //} Dialog dialog = new Dialog(); var dialogView = new FrameLayout(); dialog.AddChidren(dialogView); dialogView.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; var dialogContentView = new VerticalScrolViewLayout() { X = Application.GetRealWidth(34), Y = Application.GetRealHeight(291), Width = Application.GetRealWidth(148), Height = Application.GetRealHeight(319), BackgroundImagePath = "FunctionIcon/Acst/BgChooseMode.png", }; dialogView.AddChidren(dialogContentView); var titleView = new FrameLayout() { X = Application.GetRealWidth(2), Y = Application.GetRealHeight(3), Width = Application.GetRealWidth(144), Height = Application.GetRealHeight(44), }; dialogContentView.AddChidren(titleView); var btnTitleText = new Button() { X = Application.GetRealWidth(16), Width = Application.GetRealWidth(100), TextID = StringId.SelectMode, TextSize = 16, TextColor = CSS.CSS_Color.FirstLevelTitleColor, IsBold = true, TextAlignment = TextAlignment.CenterLeft, }; titleView.AddChidren(btnTitleText); if (function.GetAttribute(AcstParent_AttrEnum.mode.ToString()).value.Contains(AcstParent_Attr_ModeValueEnum.cool.ToString())) { #region 制冷 var coolView = new FrameLayout() { X = Application.GetRealWidth(2), Width = Application.GetRealWidth(144), Height = Application.GetRealHeight(44), }; dialogContentView.AddChidren(coolView); coolView.AddChidren(new Button { Width = Application.GetRealWidth(112), Gravity = Gravity.CenterHorizontal, Height = 1, BackgroundColor = CSS.CSS_Color.DividingLineColor, }); IconButton coolIconButton = new IconButton("FunctionIcon/Acst/grey/ModeCoolIcon.png", $"FunctionIcon/Acst/{imageFolder}/ModeCoolIcon.png", Language.StringByID(StringId.Cool), curColor, function.GetAttrState(AcstParent_AttrEnum.mode.ToString()) == "cool"); coolIconButton.Click(() => { dialog.Close(); btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/ModeCoolIcon2.png"; new System.Threading.Thread(() => { Dictionary d = new Dictionary(); d.Add(AcstParent_AttrEnum.mode.ToString(), AcstParent_Attr_ModeValueEnum.cool.ToString()); Control.Ins.SendWriteCommand(function, d); }) { IsBackground = true }.Start(); }); coolView.AddChidren(coolIconButton); #endregion } if (function.GetAttribute(AcstParent_AttrEnum.mode.ToString()).value.Contains(AcstParent_Attr_ModeValueEnum.heat.ToString())) { #region 制热 var heatView = new FrameLayout() { X = Application.GetRealWidth(2), Width = Application.GetRealWidth(144), Height = Application.GetRealHeight(44), }; dialogContentView.AddChidren(heatView); heatView.AddChidren(new Button { Width = Application.GetRealWidth(112), Gravity = Gravity.CenterHorizontal, Height = 1, BackgroundColor = CSS.CSS_Color.DividingLineColor, }); IconButton heatIconButton = new IconButton("FunctionIcon/Acst/grey/ModeHeatIcon.png", $"FunctionIcon/Acst/{imageFolder}/ModeHeatIcon.png", Language.StringByID(StringId.Heat), curColor, function.GetAttrState(AcstParent_AttrEnum.mode.ToString()) == "heat"); heatIconButton.Click(() => { dialog.Close(); btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/ModeHeatIcon2.png"; new System.Threading.Thread(() => { Dictionary d = new Dictionary(); d.Add("mode", "heat"); Control.Ins.SendWriteCommand(function, d); }) { IsBackground = true }.Start(); }); heatView.AddChidren(heatIconButton); #endregion } if (function.GetAttribute(AcstParent_AttrEnum.mode.ToString()).value.Contains(AcstParent_Attr_ModeValueEnum.fan.ToString())) { #region 通风 var fanView = new FrameLayout() { X = Application.GetRealWidth(2), Width = Application.GetRealWidth(144), Height = Application.GetRealHeight(44), }; dialogContentView.AddChidren(fanView); fanView.AddChidren(new Button { Width = Application.GetRealWidth(112), Gravity = Gravity.CenterHorizontal, Height = 1, BackgroundColor = CSS.CSS_Color.DividingLineColor, }); IconButton fanIconButton = new IconButton("FunctionIcon/Acst/grey/ModeFanIcon.png", $"FunctionIcon/Acst/{imageFolder}/ModeFanIcon.png", Language.StringByID(StringId.Ventilated), curColor, function.GetAttrState(AcstParent_AttrEnum.mode.ToString()) == AcstParent_Attr_ModeValueEnum.fan.ToString()); fanIconButton.Click(() => { btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/ModeFanIcon2.png"; dialog.Close(); new System.Threading.Thread(() => { Dictionary d = new Dictionary(); d.Add("mode", AcstParent_Attr_ModeValueEnum.fan.ToString()); Control.Ins.SendWriteCommand(function, d); }) { IsBackground = true }.Start(); }); fanView.AddChidren(fanIconButton); #endregion } if (function.GetAttribute(AcstParent_AttrEnum.mode.ToString()).value.Contains(AcstParent_Attr_ModeValueEnum.dry.ToString())) { #region 除湿 var dehumiView = new FrameLayout() { X = Application.GetRealWidth(2), Width = Application.GetRealWidth(144), Height = Application.GetRealHeight(44), }; dialogContentView.AddChidren(dehumiView); dehumiView.AddChidren(new Button { Width = Application.GetRealWidth(112), Gravity = Gravity.CenterHorizontal, Height = 1, BackgroundColor = CSS.CSS_Color.DividingLineColor, }); IconButton dehumiIconButton = new IconButton("FunctionIcon/Acst/grey/ModeDeHumiIcon.png", $"FunctionIcon/Acst/{imageFolder}/ModeDeHumiIcon.png", Language.StringByID(StringId.Dry), curColor, function.GetAttrState(AcstParent_AttrEnum.mode.ToString()) == AcstParent_Attr_ModeValueEnum.dry.ToString()); dehumiIconButton.Click(() => { btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/ModeDeHumiIcon2.png"; dialog.Close(); new System.Threading.Thread(() => { Dictionary d = new Dictionary(); d.Add("mode", AcstParent_Attr_ModeValueEnum.dry.ToString()); Control.Ins.SendWriteCommand(function, d); }) { IsBackground = true }.Start(); }); dehumiView.AddChidren(dehumiIconButton); #endregion } if (function.GetAttribute(AcstParent_AttrEnum.mode.ToString()).value.Contains(AcstParent_Attr_ModeValueEnum.heat_humidity.ToString())) { #region 制热除湿 var heatHumiView = new FrameLayout() { X = Application.GetRealWidth(2), Width = Application.GetRealWidth(144), Height = Application.GetRealHeight(44), }; dialogContentView.AddChidren(heatHumiView); heatHumiView.AddChidren(new Button { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(112), Height = 1, BackgroundColor = CSS.CSS_Color.DividingLineColor, }); IconButton heatHumiIconButton = new IconButton("FunctionIcon/Acst/grey/ModeHeatHumiIcon.png", $"FunctionIcon/Acst/{imageFolder}/ModeHeatHumiIcon.png", Language.StringByID(StringId.HeatingAndDehumidification), curColor, function.GetAttrState(AcstParent_AttrEnum.mode.ToString()) == AcstParent_Attr_ModeValueEnum.heat_humidity.ToString()); heatHumiIconButton.Click(() => { btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/ModeHeatHumiIcon2.png"; dialog.Close(); new System.Threading.Thread(() => { Dictionary d = new Dictionary(); d.Add("mode", AcstParent_Attr_ModeValueEnum.heat_humidity.ToString()); Control.Ins.SendWriteCommand(function, d); }) { IsBackground = true }.Start(); }); heatHumiView.AddChidren(heatHumiIconButton); #endregion } if (function.GetAttribute(AcstParent_AttrEnum.mode.ToString()).value.Contains(AcstParent_Attr_ModeValueEnum.humidity.ToString())) { #region 加湿 var humiView = new FrameLayout() { X = Application.GetRealWidth(2), Width = Application.GetRealWidth(144), Height = Application.GetRealHeight(44), }; dialogContentView.AddChidren(humiView); humiView.AddChidren(new Button { Width = Application.GetRealWidth(112), Gravity = Gravity.CenterHorizontal, Height = 1, BackgroundColor = CSS.CSS_Color.DividingLineColor, }); IconButton humiIconButton = new IconButton("FunctionIcon/Acst/grey/ModeHumiIcon.png", $"FunctionIcon/Acst/{imageFolder}/ModeHumiIcon.png", Language.StringByID(StringId.Humidification), curColor, function.GetAttrState(AcstParent_AttrEnum.mode.ToString()) == AcstParent_Attr_ModeValueEnum.humidity.ToString()); humiIconButton.Click(() => { btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/ModeHumiIcon2.png"; dialog.Close(); new System.Threading.Thread(() => { Dictionary d = new Dictionary(); d.Add("mode", AcstParent_Attr_ModeValueEnum.humidity.ToString()); Control.Ins.SendWriteCommand(function, d); }) { IsBackground = true }.Start(); }); humiView.AddChidren(humiIconButton); #endregion } dialog.Show(); }; btnPowerControl = new Button() { Gravity = Gravity.Center, Width = Application.GetRealWidth(38), Height = Application.GetRealWidth(38), UnSelectedImagePath = "FunctionIcon/Acst/grey/PowerOffIcon.png", SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/PowerIcon.png", TextAlignment = TextAlignment.Center, IsSelected = function.trait_on_off.state == "on" }; bottomView.AddChidren(btnPowerControl); btnPowerControl.MouseUpEventHandler = (sender, e) => { string msg = btnPowerControl.IsSelected ? "确定关闭总开关吗?" : "确定打开总开关吗?"; new PublicAssmebly().TipOptionMsg(StringId.Tip, msg, () => { 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(); }); }; btnWorkSceneControl = new Button() { Gravity = Gravity.CenterVertical, X = Application.GetRealWidth(249), Width = Application.GetRealWidth(38), Height = Application.GetRealWidth(38), UnSelectedImagePath = "FunctionIcon/Acst/grey/SceneSleepIcon2.png", SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/SceneSleepIcon2.png", TextAlignment = TextAlignment.Center, IsSelected = function.trait_on_off.state == "on" }; bottomView.AddChidren(btnWorkSceneControl); btnWorkSceneControl.MouseUpEventHandler = (sender2, e2) => { //if (function.trait_on_off.state == "off") //{ // return; //} Dialog dialog = new Dialog(); var dialogView = new FrameLayout(); dialog.AddChidren(dialogView); dialogView.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; var dialogContentView = new VerticalScrolViewLayout() { X = Application.GetRealWidth(194), Y = Application.GetRealHeight(419), ScrollEnabled = false, Width = Application.GetRealWidth(148), Height = Application.GetRealHeight(191), BackgroundImagePath = "FunctionIcon/Acst/BgChooseScene.png", }; dialogView.AddChidren(dialogContentView); var titleView = new FrameLayout() { X = Application.GetRealWidth(2), Y = Application.GetRealHeight(3), Width = Application.GetRealWidth(144), Height = Application.GetRealHeight(44), }; dialogContentView.AddChidren(titleView); var btnTitleText = new Button() { X = Application.GetRealWidth(16), Width = Application.GetRealWidth(100), TextID = StringId.SelectScene, TextSize = 16, TextColor = CSS.CSS_Color.FirstLevelTitleColor, IsBold = true, TextAlignment = TextAlignment.CenterLeft, }; titleView.AddChidren(btnTitleText); if (function.GetAttribute(AcstParent_AttrEnum.scene.ToString()).value.Contains(AcstParent_Attr_SceneValueEnum.at_home.ToString())) { #region 在家 var atHomeView = new VerticalScrolViewLayout() { X = Application.GetRealWidth(2), //Y = titleView.Bottom, Width = Application.GetRealWidth(144), Height = Application.GetRealHeight(44), }; dialogContentView.AddChidren(atHomeView); atHomeView.AddChidren(new Button { Width = Application.GetRealWidth(112), Gravity = Gravity.CenterHorizontal, Height = 1, BackgroundColor = CSS.CSS_Color.DividingLineColor, }); IconButton atHomeIconButton = new IconButton("FunctionIcon/Acst/grey/SceneAtHome.png", $"FunctionIcon/Acst/{imageFolder}/SceneAtHome.png", Language.StringByID(StringId.AtHome), curColor, function.GetAttrState(AcstParent_AttrEnum.scene.ToString()) == AcstParent_Attr_SceneValueEnum.at_home.ToString()); atHomeIconButton.Click(() => { btnWorkSceneControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/SceneAtHome2.png"; dialog.Close(); new System.Threading.Thread(() => { Dictionary d = new Dictionary(); d.Add(AcstParent_AttrEnum.scene.ToString(), AcstParent_Attr_SceneValueEnum.at_home.ToString()); Control.Ins.SendWriteCommand(function, d); }) { IsBackground = true }.Start(); }); atHomeView.AddChidren(atHomeIconButton); #endregion } if (function.GetAttribute(AcstParent_AttrEnum.scene.ToString()).value.Contains(AcstParent_Attr_SceneValueEnum.leave_home.ToString())) { #region 离家 var awayHomeView = new FrameLayout() { X = Application.GetRealWidth(2), //Y = atHomeView.Bottom, Width = Application.GetRealWidth(144), Height = Application.GetRealHeight(44), }; dialogContentView.AddChidren(awayHomeView); awayHomeView.AddChidren(new Button { Width = Application.GetRealWidth(112), Gravity = Gravity.CenterHorizontal, Height = 1, BackgroundColor = CSS.CSS_Color.DividingLineColor, }); IconButton awayHomeIconButton = new IconButton("FunctionIcon/Acst/grey/SceneAwayHomeIcon.png", $"FunctionIcon/Acst/{imageFolder}/SceneAwayHomeIcon.png", Language.StringByID(StringId.AwayHome), curColor, function.GetAttrState(AcstParent_AttrEnum.scene.ToString()) == AcstParent_Attr_SceneValueEnum.leave_home.ToString()); awayHomeIconButton.Click(() => { btnWorkSceneControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/SceneAwayHomeIcon2.png"; dialog.Close(); new System.Threading.Thread(() => { Dictionary d = new Dictionary(); d.Add("scene", "leave_home"); Control.Ins.SendWriteCommand(function, d); }) { IsBackground = true }.Start(); }); awayHomeView.AddChidren(awayHomeIconButton); #endregion } if (function.GetAttribute(AcstParent_AttrEnum.scene.ToString()).value.Contains(AcstParent_Attr_SceneValueEnum.sleep.ToString())) { #region 睡眠 var sleepView = new FrameLayout() { X = Application.GetRealWidth(2), //Y = awayHomeView.Bottom, Width = Application.GetRealWidth(144), Height = Application.GetRealHeight(44), }; dialogContentView.AddChidren(sleepView); sleepView.AddChidren(new Button { Height = 1, Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(112), BackgroundColor = CSS.CSS_Color.DividingLineColor, }); IconButton sleepIconButton = new IconButton("FunctionIcon/Acst/grey/SceneSleepIcon.png", $"FunctionIcon/Acst/{imageFolder}/SceneSleepIcon.png", Language.StringByID(StringId.Sleep), curColor, function.GetAttrState(AcstParent_AttrEnum.scene.ToString()) == AcstParent_Attr_SceneValueEnum.sleep.ToString()); sleepIconButton.Click(() => { btnWorkSceneControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/SceneSleepIcon2.png"; dialog.Close(); new System.Threading.Thread(() => { Dictionary d = new Dictionary(); d.Add("scene", "sleep"); Control.Ins.SendWriteCommand(function, d); }) { IsBackground = true }.Start(); }); sleepView.AddChidren(sleepIconButton); } #endregion dialog.Show(); }; #endregion InitGetWeatherAction(); new System.Threading.Thread(() => { Control.Ins.SendReadCommand(function); }) { IsBackground = true }.Start(); } } /// /// 传感器数据组件 /// public class SensorDiyView { private FrameLayout contentView; private Button btnValue; private Button btnText; public string Tag; public string unitString; public SensorDiyView(HorizontalScrolViewLayout view,uint color,string value,string unitStr, string unitStr2, string text,int setWidth = 60) { unitString = unitStr; if (string.IsNullOrEmpty(value)) { value = "--"; } ///默认Tag 为传进来的Text Tag = text; contentView = new FrameLayout() { Width = Application.GetRealWidth(setWidth), Height = Application.GetRealHeight(72), }; view.AddChidren(contentView); btnValue = new Button() { Y = Application.GetRealHeight(10), Height = Application.GetRealHeight(72 - 37), TextAlignment = TextAlignment.Center, TextColor = color, TextSize = 20, Text = value + unitString, }; contentView.AddChidren(btnValue); btnText = new Button() { Y = Application.GetRealHeight(72 - 37), Height = Application.GetRealHeight(37), TextAlignment = TextAlignment.Center, TextColor = 0xFF949AA5, TextSize = 12, Text = text , }; contentView.AddChidren(btnText); if(!string.IsNullOrEmpty(unitStr2)) { btnText.Text += "(" + unitStr2 + ")"; } } public void UpdateValue(string value,bool isInt) { if (value.Contains(".") && isInt) { value = value.Remove(value.IndexOf('.'), value.Length - value.IndexOf('.')); } btnValue.Text = value + unitString; } } /// /// 子控卡片组件 /// public class AcstSubControlView { public TextButton btnSubTempValues; public TextButton btnSubHumidityValues; public Button btnSubPower; public string Tag; public AcstSubControlView(Function sub, HorizontalScrolViewLayout subFunctionListView,string imageFolder) { Tag = sub.sid; var subFunctionView = new FrameLayout() { Width = Application.GetRealWidth(177), Height = Application.GetRealHeight(93), BackgroundImagePath = "FunctionIcon/Acst/grey/BgSubControlView.png", }; subFunctionListView.AddChidren(subFunctionView); var btnRoomInfo = new Button() { X = Application.GetRealWidth(18 + 7), Y = Application.GetRealHeight(11), Height = Application.GetRealHeight(40), TextAlignment = TextAlignment.CenterLeft, TextColor = 0xFF1b3053, TextSize = 13, Text = sub.name, }; subFunctionView.AddChidren(btnRoomInfo); var btnSubTempIcon = new Button() { X = Application.GetRealWidth(16 + 7), Y = Application.GetRealHeight(47 + 11), Width = Application.GetMinRealAverage(11), Height = Application.GetMinRealAverage(11), UnSelectedImagePath = "FunctionIcon/CAC/HvacCacTempIcon.png", }; subFunctionView.AddChidren(btnSubTempIcon); btnSubTempValues = new TextButton() { X = btnSubTempIcon.Right, Y = Application.GetRealHeight(45 + 11), Height = Application.GetRealHeight(14), Width = Application.GetRealWidth(35), TextColor = 0xFF1b3035, TextSize = 10, Text = sub.GetAttrState(AcstSub_AttrEnum.room_temp.ToString()) + "°C", TextAlignment = TextAlignment.CenterLeft, }; subFunctionView.AddChidren(btnSubTempValues); Button btnSubHumidityIcon = new Button() { X = btnSubTempValues.Right + Application.GetRealWidth(5), Y = Application.GetRealHeight(47 + 11), Width = Application.GetMinRealAverage(11), Height = Application.GetMinRealAverage(11), UnSelectedImagePath = "FunctionIcon/CAC/HvacCacHumidityIcon.png", }; subFunctionView.AddChidren(btnSubHumidityIcon); btnSubHumidityValues = new TextButton() { X = btnSubHumidityIcon.Right, Y = Application.GetRealHeight(45 + 11), Height = Application.GetRealHeight(14), Width = Application.GetRealWidth(35), TextColor = 0xFF1b3053, TextSize = 10, Text = sub.GetAttrState(AcstSub_AttrEnum.room_humidity.ToString()) + "%", TextAlignment = TextAlignment.CenterLeft, }; subFunctionView.AddChidren(btnSubHumidityValues); btnSubPower = new Button() { X = Application.GetRealWidth(121 + 7), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(28), Height = Application.GetRealWidth(28), UnSelectedImagePath = "FunctionIcon/Acst/grey/PowerOffIcon.png", SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/PowerIcon.png", TextAlignment = TextAlignment.Center, }; subFunctionView.AddChidren(btnSubPower); btnSubPower.MouseUpEventHandler = (sender, e) => { btnSubPower.IsSelected = !btnSubPower.IsSelected; string onoff = btnSubPower.IsSelected ? "on" : "off"; Dictionary d = new Dictionary(); d.Add(FunctionAttributeKey.OnOff, onoff); Control.Ins.SendWriteCommand(sub, d); }; EventHandler eventHandler = (sender, e) => { var page = new AcstSubPage(sub,imageFolder); MainPage.BasePageView.AddChidren(page); page.LoadPage(()=> { btnRoomInfo.Text = sub.name; }); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }; btnRoomInfo.MouseUpEventHandler = eventHandler; btnSubHumidityIcon.MouseUpEventHandler = eventHandler; btnSubHumidityValues.MouseUpEventHandler = eventHandler; btnSubTempIcon.MouseUpEventHandler = eventHandler; btnSubTempValues.MouseUpEventHandler = eventHandler; subFunctionView.MouseUpEventHandler = eventHandler; } } public class IconButton : FrameLayout { FrameLayout view; public Button btnIcon; public Button btnText; public IconButton(string iconPath,string iconPath2,string text,uint color,bool isSelect) { view = this; view.Width = Application.GetRealWidth(144); view.Height = Application.GetRealHeight(44); btnIcon = new Button() { X = Application.GetRealWidth(16), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(24), Height = Application.GetRealWidth(24), UnSelectedImagePath = iconPath, SelectedImagePath = iconPath2, IsSelected = isSelect, }; view.AddChidren(btnIcon); btnText = new Button() { X = Application.GetRealWidth(52), Width = Application.GetRealWidth(90), TextAlignment = TextAlignment.CenterLeft, Text = text, TextSize = 14, TextColor = CSS.CSS_Color.FirstLevelTitleColor, SelectedTextColor = color, IsSelected = isSelect, }; view.AddChidren(btnText); } public void Click(Action action) { view.MouseUpEventHandler = (sender, e) => { action(); }; btnText.MouseUpEventHandler = (sender, e) => { action(); }; btnIcon.MouseUpEventHandler = (sender, e) => { action(); }; } } }