using System; using HDL_ON.Entity; using Shared; namespace HDL_ON.UI { /// /// 绿建科技系统 /// 总控主页 /// public class AcstParentPage : FrameLayout { VerticalScrolViewLayout bodyView; Function function; /// /// 当前时段颜色 /// uint curColor = CSS.CSS_Color.MainColor; public AcstParentPage() { this.function = FunctionList.List.GetAcstParentList()[0]; this.BackgroundColor = CSS.CSS_Color.BackgroundColor; bodyView = new VerticalScrolViewLayout(); this.AddChidren(bodyView); } public void InitGetWeatherAction() { MainPage.CityWeatherAction = () => { }; } public void LoadPage() { #region 头部信息区域 FrameLayout topView = new FrameLayout() { Height = Application.GetRealHeight(181), BackgroundColor = 0xFFb0eafa, }; bodyView.AddChidren(topView); var backView = new FrameLayout() { Y = Application.GetRealHeight(32), Width = Application.GetRealWidth(100), Height = Application.GetRealHeight(34), BackgroundColor = 0x33333333, }; topView.AddChidren(backView); Button btnBackIcon = new Button() { X = Application.GetRealWidth(16), Width = Application.GetRealWidth(40), Height = Application.GetRealWidth(28), UnSelectedImagePath = "Public/BackIcon.png", }; backView.AddChidren(btnBackIcon); btnBackIcon.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, TextColor = 0xFFFFFFFF, TextAlignment = TextAlignment.CenterLeft, }; topView.AddChidren(btnHelloText); var curTime = DateTime.Now; if (curTime.Hour >= 8 && curTime.Hour < 12) { btnHelloText.Text = "上午好"; } else if (curTime.Hour >= 12 && curTime.Hour < 18) { btnHelloText.Text = "下午好"; } else { btnHelloText.Text = "晚上好"; } var 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); var 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); var 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); var 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 bodyView.AddChidren(new Button { Height = Application.GetRealHeight(8), }); #region 数据 var infoView = new FrameLayout() { Y = topView.Bottom, Height = Application.GetRealHeight(104), BackgroundColor = CSS.CSS_Color.MainBackgroundColor, }; bodyView.AddChidren(infoView); var infoContentView = new FrameLayout() { Gravity = Gravity.Center, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(72), BackgroundColor = 0x22222222, }; infoView.AddChidren(infoContentView); #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++; } var sensorListView = new HorizontalScrolViewLayout() { Width = Application.GetRealWidth(60 * sensorCount), Gravity = Gravity.Center, }; infoContentView.AddChidren(sensorListView); if (tempObj != null) { new SensorDiyView(sensorListView, curColor, tempObj.curValue.ToString() + "°", "温度"); } if (humiObj != null) { new SensorDiyView(sensorListView, curColor, humiObj.curValue.ToString() + "%", "湿度"); } if (pm25Obj != null) { new SensorDiyView(sensorListView, curColor, pm25Obj.curValue.ToString(), "PM2.5"); } if (co2Obj != null) { new SensorDiyView(sensorListView, curColor, co2Obj.curValue.ToString(), "CO2"); } if (tvocObj != null) { new SensorDiyView(sensorListView, curColor, tvocObj.curValue.ToString(), "TVOC"); } #endregion #region 能耗数据 int energyCount = 0; 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++; } var totalObj = function.GetAttribute(AcstParent_AttrEnum.total_electricity.ToString()); if (totalObj != null) { energyCount++; } var energyListView = new HorizontalScrolViewLayout() { Width = Application.GetRealWidth(60 * energyCount), Gravity = Gravity.Center, Visible = false, }; infoContentView.AddChidren(energyListView); if (dayObj != null) { new SensorDiyView(energyListView, curColor, dayObj.curValue.ToString(), "今日耗电"); } if (monthObj != null) { new SensorDiyView(energyListView, curColor, monthObj.curValue.ToString(), "本月耗电"); } if (totalObj != null) { new SensorDiyView(energyListView, curColor, totalObj.curValue.ToString(), "总耗电量"); } 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; } }; btnChangeClick.MouseUpEventHandler = changeInfoEvent; #endregion #endregion #region 子控列表 var subTitleView = new FrameLayout() { Height = Application.GetRealHeight(54), }; bodyView.AddChidren(subTitleView); var btnCollection = new Button() { X = Application.GetRealWidth(6), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(39), Height = Application.GetRealHeight(39), UnSelectedImagePath = "Function/Acst/CollectionIcon_bule.png", }; subTitleView.AddChidren(btnCollection); var btnTitleText = new Button() { X = btnCollection.Right, Text = "我的家庭", TextSize = 16, TextColor = 0xFF242424, TextAlignment = TextAlignment.CenterLeft, IsBold = true, }; subTitleView.AddChidren(btnTitleText); int subFunctionCount = 0; var subFunctionListView = new HorizontalScrolViewLayout() { Height = Application.GetRealHeight(88), }; bodyView.AddChidren(subFunctionListView); foreach(var sub in FunctionList.List.GetAcstSubList()) { if(subFunctionCount > 0 && subFunctionCount % 2 == 0) { subFunctionListView = new HorizontalScrolViewLayout() { Height = Application.GetRealHeight(88), }; bodyView.AddChidren(subFunctionListView); } subFunctionListView.AddChidren(new Button { Width = Application.GetRealWidth(16) }); var subFunctionView = new FrameLayout() { Width = Application.GetRealWidth(164), Height = Application.GetRealHeight(72), BackgroundColor = CSS.CSS_Color.MainBackgroundColor, }; subFunctionListView.AddChidren(subFunctionView); var btnRoomInfo = new Button() { X = Application.GetRealWidth(18), Height = Application.GetRealHeight(40), TextAlignment = TextAlignment.CenterLeft, TextColor = 0xFF1b3053, TextSize = 13, Text = sub.GetRoomListName(), }; subFunctionView.AddChidren(btnRoomInfo); var btnSubTempIcon = new Button() { X = Application.GetRealWidth(16), Y = Application.GetRealHeight(47), Width = Application.GetMinRealAverage(11), Height = Application.GetMinRealAverage(11), UnSelectedImagePath = "FunctionIcon/CAC/HvacCacTempIcon.png", }; subFunctionView.AddChidren(btnSubTempIcon); var btnSubTempValues = new TextButton() { X = btnSubTempIcon.Right, Y = Application.GetRealHeight(45), Height = Application.GetRealHeight(14), Width = Application.GetRealWidth(22), 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), Width = Application.GetMinRealAverage(11), Height = Application.GetMinRealAverage(11), UnSelectedImagePath = "FunctionIcon/CAC/HvacCacHumidityIcon.png", }; subFunctionView.AddChidren(btnSubHumidityIcon); var btnSubHumidityValues = new TextButton() { X = btnSubHumidityIcon.Right, Y = Application.GetRealHeight(45), Height = Application.GetRealHeight(14), Width = Application.GetRealWidth(22), TextColor = 0xFF1b3053, TextSize = 10, Text = sub.GetAttrState(AcstSub_AttrEnum.room_humidity.ToString()) + "%", TextAlignment = TextAlignment.CenterLeft, }; subFunctionView.AddChidren(btnSubHumidityValues); var btnSubPower = new Button() { X = Application.GetRealWidth(121), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(28), Height = Application.GetRealWidth(28), BackgroundColor = curColor, Text = "开关", TextAlignment = TextAlignment.Center, }; subFunctionView.AddChidren(btnSubPower); subFunctionCount++; } #endregion bodyView.AddChidren(new Button() { Height = Application.GetRealHeight(72), }); #region 底部控制栏 var bottomView = new FrameLayout() { Y = Application.GetRealHeight(667 - 56), Height = Application.GetRealHeight(56), BackgroundColor = CSS.CSS_Color.MainBackgroundColor, }; this.AddChidren(bottomView); var btnModeControl = new Button() { X = Application.GetRealWidth(89), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(38), Height = Application.GetRealWidth(38), BackgroundColor = curColor, Text = "模式", TextAlignment = TextAlignment.Center, }; bottomView.AddChidren(btnModeControl); btnModeControl.MouseUpEventHandler = (sender, e) => { }; var btnPowerControl = new Button() { Gravity = Gravity.Center, Width = Application.GetRealWidth(38), Height = Application.GetRealWidth(38), BackgroundColor = curColor, Text = "开关", TextAlignment = TextAlignment.Center, }; bottomView.AddChidren(btnPowerControl); var btnWorkSceneControl = new Button() { Gravity = Gravity.CenterVertical, X = Application.GetRealWidth(249), Width = Application.GetRealWidth(38), Height = Application.GetRealWidth(38), BackgroundColor = curColor, Text = "场景", TextAlignment = TextAlignment.Center, }; bottomView.AddChidren(btnWorkSceneControl); #endregion InitGetWeatherAction(); } } public class SensorDiyView { private FrameLayout contentView; private Button btnValue; private Button btnText; public string Tag; public SensorDiyView(HorizontalScrolViewLayout view,uint color,string value,string text) { contentView = new FrameLayout() { Width = Application.GetRealWidth(60), 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, }; 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); } public void UpdateValue(string value) { btnText.Text = value; } } }