using System; using Shared; using HDL_ON.Entity; using HDL_ON.UI.CSS; using System.Collections.Generic; namespace HDL_ON.UI { public partial class EnvironmentalSciencePage : FrameLayout { #region 控件集合 static EnvironmentalSciencePage bodyView; /// /// 楼层显示 /// Button btnRoom; /// /// 房间选择下拉图标 /// Button btnFoorDownIcon; /// /// 房间选择触发区域 /// Button btnRoomClickRow; /// /// 传感器列表区域 /// FrameLayout sensorListView; /// /// 天气名称文本 /// Button btnWatherText; /// /// 湿度数据文本 /// Button btnHumidityText; /// /// pm25数据文本 /// Button btnPm25Values; /// /// 风速数据文本 /// Button btnFanSpeedValues; #endregion #region 区域变量 Room room; #endregion public EnvironmentalSciencePage() { bodyView = this; } /// /// 加载界面 /// /// 收藏按钮 /// 功能名称信息按钮 /// 功能楼层信息按钮 public void LoadPage() { bodyView.BackgroundColor = CSS_Color.MainBackgroundColor; #region 顶部天气部分 var topWeatherView = new FrameLayout() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(76), Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(151), BackgroundColor = CSS_Color.MainColor, Radius = (uint)Application.GetRealWidth(12), }; bodyView.AddChidren(topWeatherView); var btnTemp = new Button() { X = Application.GetRealWidth(24), Y = Application.GetRealHeight(16), Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(48), TextSize = 42, IsBold = true, TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.MainBackgroundColor, Text = MainPage.cityInfo.temperature, }; topWeatherView.AddChidren(btnTemp); var btnTempUint = new Button() { X = Application.GetRealWidth(79), Y = Application.GetRealHeight(16), Width = Application.GetRealWidth(20), Height = Application.GetRealHeight(20), TextSize = 12, TextColor = CSS_Color.MainBackgroundColor, Text = "°C", }; topWeatherView.AddChidren(btnTempUint); var btnWeatherIcon = new Button() { X = Application.GetRealWidth(115), Y = Application.GetRealHeight(16), Width = Application.GetRealWidth(20), Height = Application.GetRealWidth(20), UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/SmogIcon.png", }; topWeatherView.AddChidren(btnWeatherIcon); LoadEvent_ChangeWeatherIcon(btnWeatherIcon); btnWatherText = new Button() { X = Application.GetRealWidth(139), Y = Application.GetRealHeight(16), Width = Application.GetRealWidth(28 * 3), Height = Application.GetRealHeight(20), TextColor = CSS_Color.MainBackgroundColor, TextSize = CSS_FontSize.TextFontSize, TextAlignment = TextAlignment.CenterLeft, Text = MainPage.cityInfo.weather }; topWeatherView.AddChidren(btnWatherText); var btnTempUpperLimit = new Button() { X = btnWeatherIcon.X, Y = Application.GetRealHeight(46), Width = Application.GetRealWidth(16), Height = Application.GetRealWidth(16), UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/UpArrow.png", }; topWeatherView.AddChidren(btnTempUpperLimit); var btnTempUpperLimitText = new Button() { X = btnTempUpperLimit.Right, Y = Application.GetRealHeight(44), Width = Application.GetRealWidth(42), Height = Application.GetRealHeight(20), TextColor = CSS_Color.MainBackgroundColor, TextAlignment = TextAlignment.CenterLeft, TextSize = CSS_FontSize.TextFontSize, Text = "10°C", }; topWeatherView.AddChidren(btnTempUpperLimitText); var btnTempLowerLimit = new Button() { X = btnTempUpperLimitText.Right, Y = Application.GetRealHeight(46), Width = Application.GetRealWidth(16), Height = Application.GetRealWidth(16), UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/UpArrow.png", }; btnTempLowerLimit.SetRotation(180f); topWeatherView.AddChidren(btnTempLowerLimit); var btnTempLowerLimitText = new Button() { X = btnTempLowerLimit.Right, Y = Application.GetRealHeight(44), Width = Application.GetRealWidth(42), Height = Application.GetRealHeight(20), TextColor = CSS_Color.MainBackgroundColor, TextAlignment = TextAlignment.CenterLeft, TextSize = CSS_FontSize.TextFontSize, Text = "2°C", }; topWeatherView.AddChidren(btnTempLowerLimitText); var btnLocationText = new Button() { X = Application.GetRealWidth(233), Y = Application.GetRealHeight(18), Width = Application.GetRealWidth(74), Height = Application.GetRealHeight(17), TextAlignment = TextAlignment.CenterRight, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, TextColor = CSS_Color.MainBackgroundColor, Text = MainPage.cityInfo.location, }; topWeatherView.AddChidren(btnLocationText); var btnLocationIcon = new Button() { X = btnLocationText.Right, Y = Application.GetRealHeight(18), Width = Application.GetRealWidth(16), Height = Application.GetRealHeight(16), UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/LocationIcon.png", }; topWeatherView.AddChidren(btnLocationIcon); Button btnHumidityIcon = new Button() { X = Application.GetRealWidth(26), Y = Application.GetRealHeight(90), Width = Application.GetRealWidth(24), Height = Application.GetRealWidth(24), UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/HumidityIcon.png", }; topWeatherView.AddChidren(btnHumidityIcon); btnHumidityText = new Button() { X = Application.GetRealWidth(15), Y = btnHumidityIcon.Bottom, Width = Application.GetRealWidth(46), Height = Application.GetRealHeight(25), TextSize = CSS_FontSize.PromptFontSize_FirstLevel, TextAlignment = TextAlignment.Center, TextColor = CSS_Color.MainBackgroundColor, Text = MainPage.cityInfo.humidity + "%", }; topWeatherView.AddChidren(btnHumidityText); Button btnPm25Icon = new Button() { X = Application.GetRealWidth(104), Y = Application.GetRealHeight(90), Width = Application.GetRealWidth(24), Height = Application.GetRealWidth(24), UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/Pm25Icon.png", }; topWeatherView.AddChidren(btnPm25Icon); btnPm25Values = new Button() { X = Application.GetRealWidth(90), Y = btnHumidityIcon.Bottom, Width = Application.GetRealWidth(52), Height = Application.GetRealHeight(25), TextSize = CSS_FontSize.PromptFontSize_FirstLevel, TextAlignment = TextAlignment.Center, TextColor = CSS_Color.MainBackgroundColor, Text = MainPage.cityInfo.pm25, }; topWeatherView.AddChidren(btnPm25Values); Button btnFanSpeedIcon = new Button() { X = Application.GetRealWidth(182), Y = Application.GetRealHeight(90), Width = Application.GetRealWidth(24), Height = Application.GetRealWidth(24), UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/WeatherFanSpeedIcon.png", }; topWeatherView.AddChidren(btnFanSpeedIcon); btnFanSpeedValues = new Button() { X = Application.GetRealWidth(162), Y = btnFanSpeedIcon.Bottom, Width = Application.GetRealWidth(63), Height = Application.GetRealHeight(25), TextSize = CSS_FontSize.PromptFontSize_FirstLevel, TextAlignment = TextAlignment.Center, TextColor = CSS_Color.MainBackgroundColor, Text = MainPage.cityInfo.windLevel, }; topWeatherView.AddChidren(btnFanSpeedValues); #endregion #region contentView FrameLayout contentView = new FrameLayout() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(239), Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(418), Radius = (uint)Application.GetRealWidth(12), BorderColor = 0x00000000, BorderWidth = 0, BackgroundColor = CSS_Color.BackgroundColor, }; bodyView.AddChidren(contentView); #region 房间顶部切换显示区域 room = new Room(); if (DB_ResidenceData.rooms.Count > 0) { room = DB_ResidenceData.rooms[0]; } btnFoorDownIcon = new Button() { Width = Application.GetMinRealAverage(16), Height = Application.GetMinRealAverage(16), X = Application.GetRealWidth(16), Y = Application.GetRealHeight(18), UnSelectedImagePath = "Public/DownIcon.png", }; contentView.AddChidren(btnFoorDownIcon); btnRoom = new Button() { X = btnFoorDownIcon.Right, Y = Application.GetRealHeight(18), Width = Application.GetRealWidth(200), Height = Application.GetMinRealAverage(16), TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, TextAlignment = TextAlignment.CenterLeft, Text = room.name, }; contentView.AddChidren(btnRoom); btnRoomClickRow = new Button() { Height = Application.GetRealHeight(40), }; contentView.AddChidren(btnRoomClickRow); #endregion sensorListView = new FrameLayout() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(50), Width = Application.GetRealWidth(308), Height = Application.GetRealHeight(456), Radius = (uint)Application.GetRealWidth(12), BorderColor = 0x00000000, BorderWidth = 0, }; contentView.AddChidren(sensorListView); int index = 0; foreach(var sensor in DB_ResidenceData.functionList.sensorsEnvironmentalScience) { LoadSensorDiv(sensor, index); index++; } #endregion //LoadEventList(); LoadDialog_ChangeRoom(); new TopViewDiv(bodyView, Language.StringByID(StringId.EnvironmentalScience)).LoadTopView(); } /// /// 加载传感器列表 /// void LoadSensorDiv(Sensor sensor,int index) { if (sensor.roomIdList.Contains(room.sid)) { var sensorTag = sensor.sid; if (sensor.bus_Data != null) { sensorTag = ((int)sensor.functionType % 256) + "_" + sensor.bus_Data.SubnetID + "_" + sensor.bus_Data.DeviceID + "_" + sensor.bus_Data.LoopID; } FrameLayout sensorView = new FrameLayout() { Width = Application.GetRealWidth(148), Height = Application.GetRealWidth(80), Radius = (uint)Application.GetRealWidth(8), BorderColor = 0x00000000, BorderWidth = 0, BackgroundColor = CSS_Color.MainBackgroundColor, Y = Application.GetRealWidth(92 * (index / 2)), Tag = sensorTag }; if (index % 2 != 0) { sensorView.X = Application.GetRealWidth(160); } sensorListView.AddChidren(sensorView); var arcBar = new DiyArcSeekBar() { X = Application.GetRealWidth(7), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(48), Height = Application.GetRealWidth(48), OpenAngle = 10, ProgressBarColor = sensor.levelColorList[sensor.curLevel - 1], MinValue = 0, MaxValue = 96, Progress = (96 / sensor.levelColorList.Count) * sensor.curLevel, IsClickable = false, ArcColor = CSS_Color.BackgroundColor, ArcWidth = Application.GetRealWidth(4), IsThumbImgBtnShow = false, SeekBarPadding = Application.GetRealWidth(2), }; sensorView.AddChidren(arcBar); var btnSensorTitle = new Button() { X = Application.GetRealWidth(7), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(48), Height = Application.GetRealWidth(48), TextAlignment = TextAlignment.Center, TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel, TextColor = CSS_Color.FirstLevelTitleColor, TextID = sensor.functionTypeNameId, Tag = "SensorTitle" }; sensorView.AddChidren(btnSensorTitle); btnSensorTitle.MouseUpEventHandler = (sender, e) => { var esp = new EnvironmentalSensorPage(sensor); MainPage.BasePageView.AddChidren(esp); esp.LoadPage(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }; var btnInfoIcon = new Button() { X = Application.GetRealWidth(120), Width = Application.GetRealWidth(28), Height = Application.GetRealWidth(28), UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/TipInfoIcon.png", }; sensorView.AddChidren(btnInfoIcon); btnInfoIcon.MouseUpEventHandler = (sender, e) => { LoadInfo(sensor); }; var btnSensorValues = new Button() { X = Application.GetRealWidth(72), Y = Application.GetRealWidth(17), Width = Application.GetRealWidth(70), Height = Application.GetRealWidth(30), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.EmphasisFontSize_Secondary, IsBold = true, Text = sensor.values.ToString(), Tag = "SensorValues" }; sensorView.AddChidren(btnSensorValues); var btnLevel = new Button() { X = Application.GetRealWidth(70), Y = btnSensorValues.Bottom, Width = Application.GetRealWidth(50), Height = Application.GetRealWidth(18), TextAlignment = TextAlignment.CenterLeft, TextColor = sensor.levelColorList[sensor.curLevel - 1], TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel, TextID = sensor.levelTextList[sensor.curLevel - 1], Tag = "SensorLevel" }; sensorView.AddChidren(btnLevel); //Control.Send(CommandType_A.read, sensor); Control.SendReadCommand(sensor); } } /// /// 加载传感器等级相关信息 /// void LoadInfo(Sensor sensor) { Dialog dialog = new Dialog(); FrameLayout dialogBodyView = new FrameLayout(); dialog.AddChidren(dialogBodyView); dialogBodyView.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; VerticalScrolViewLayout infoView = new VerticalScrolViewLayout() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(667 - 94 - (sensor.levelColorList.Count * 44) - 20), Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(94 + (sensor.levelColorList.Count * 44) + sensor.levelColorList.Count), Radius = (uint)Application.GetRealWidth(12), BackgroundColor = CSS_Color.MainBackgroundColor, Animate = Animate.DownToUp, ScrollEnabled = false, AnimateSpeed = 0.3f, }; dialogBodyView.AddChidren(infoView); Button btnTitle = new Button() { Height = Application.GetRealHeight(50), TextColor = CSS_Color.FirstLevelTitleColor, IsBold = true, TextSize = CSS_FontSize.SubheadingFontSize, TextAlignment = TextAlignment.Center, }; infoView.AddChidren(btnTitle); switch (sensor.functionType) { case FunctionType.PM25: btnTitle.Text = "PM2.5(ug/m²)"; break; case FunctionType.Temp: btnTitle.Text = Language.StringByID(StringId.Temp) + "(°C)"; break; case FunctionType.TVOC: btnTitle.Text = "TVOC(PPM)"; break; case FunctionType.CO2: btnTitle.Text = "CO2(PPM)"; break; case FunctionType.Humidity: btnTitle.Text = Language.StringByID(StringId.Humidity) + "(%)"; break; } FrameLayout subTitleView = new FrameLayout() { Height = Application.GetRealHeight(44), }; infoView.AddChidren(subTitleView); subTitleView.AddChidren(new Button() { X = Application.GetRealWidth(20), Width = Application.GetRealWidth(100), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.TextFontSize, IsBold = true, TextID = StringId.IntervalValue, }); subTitleView.AddChidren(new Button() { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(100), TextAlignment = TextAlignment.Center, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.TextFontSize, IsBold = true, TextID = StringId.LevelSensor, }); subTitleView.AddChidren(new Button() { X = Application.GetRealWidth(223), Width = Application.GetRealWidth(100), TextAlignment = TextAlignment.CenterRight, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.TextFontSize, IsBold = true, TextID = StringId.ColorValue, }); for (int index = 0; index < sensor.levelTextList.Count; index++) { infoView.AddChidren(new Button() { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(303), Height = Application.GetRealWidth(1), BackgroundColor = CSS_Color.DividingLineColor, }); FrameLayout subInfoView = new FrameLayout() { Height = Application.GetRealHeight(44), }; infoView.AddChidren(subInfoView); subInfoView.AddChidren(new Button() { X = Application.GetRealWidth(20), Width = Application.GetRealWidth(100), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.TextFontSize, IsBold = true, Text = sensor.intervalValue[index] }); subInfoView.AddChidren(new Button() { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(100), TextAlignment = TextAlignment.Center, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.TextFontSize, IsBold = true, TextID = sensor.levelTextList[index] }); subInfoView.AddChidren(new Button() { X = Application.GetRealWidth(285), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(38), Height = Application.GetRealHeight(18), Radius = (uint)Application.GetRealWidth(4), BackgroundColor = sensor.levelColorList[index] }); } dialog.Show(); } /// /// 房间列表点击事件 /// void LoadDialog_ChangeRoom() { EventHandler eventHandler = (sender, e) => { var dialog = new Dialog(); var dialogBody = new FrameLayout(); dialog.AddChidren(dialogBody); dialogBody.MouseUpEventHandler += (sender1, e1) => { dialog.Close(); }; var dispalyView = new FrameLayout() { X = Application.GetRealWidth(10), Y = Application.GetRealHeight(100), Width = Application.GetRealWidth(160), Height = Application.GetRealHeight(110), BackgroundImagePath = "PersonalCenter/HomeList1bg.png", }; dialogBody.AddChidren(dispalyView); var contentView = new VerticalScrolViewLayout() { X = Application.GetRealWidth(8), Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(150), Height = Application.GetRealHeight(45 * 2), ScrollEnabled = false }; dispalyView.AddChidren(contentView); if (DB_ResidenceData.rooms.Count < 2) { } else if (DB_ResidenceData.rooms.Count < 3) { dispalyView = new FrameLayout() { X = Application.GetRealWidth(10), Y = Application.GetRealHeight(100), Width = Application.GetRealWidth(160), Height = Application.GetRealHeight(155), BackgroundImagePath = "PersonalCenter/HomeList2bg.png", }; dialogBody.AddChidren(dispalyView); contentView.Height = Application.GetRealHeight(45 * 3); dispalyView.AddChidren(contentView); } else if (DB_ResidenceData.rooms.Count < 4) { dispalyView = new FrameLayout() { X = Application.GetRealWidth(10), Y = Application.GetRealHeight(100), Width = Application.GetRealWidth(160), Height = Application.GetRealHeight(200), BackgroundImagePath = "PersonalCenter/HomeList3bg.png", }; dialogBody.AddChidren(dispalyView); contentView.Height = Application.GetRealHeight(45 * 4); dispalyView.AddChidren(contentView); } else { dispalyView = new FrameLayout() { X = Application.GetRealWidth(10), Y = Application.GetRealHeight(100), Width = Application.GetRealWidth(160), Height = Application.GetRealHeight(245), BackgroundImagePath = "PersonalCenter/HomeList4bg.png", }; dialogBody.AddChidren(dispalyView); contentView.Height = Application.GetRealHeight(45 * 5); contentView.ScrollEnabled = true; dispalyView.AddChidren(contentView); } foreach (var roomTemp in DB_ResidenceData.rooms) { string roomName = roomTemp.name; var btnRoomName = new Button() { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(112), Height = Application.GetRealHeight(44), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS.CSS_Color.FirstLevelTitleColor, SelectedTextColor = CSS.CSS_Color.MainColor, Text = roomName, TextSize = CSS.CSS_FontSize.SubheadingFontSize, IsSelected = btnRoom.Text == roomName, IsMoreLines = true, Tag = roomName }; contentView.AddChidren(btnRoomName); btnRoomName.MouseUpEventHandler += (senderH, en) => { dialog.Close(); btnRoom.Text = roomName; room = roomTemp; }; } dialog.Show(); }; btnRoomClickRow.MouseUpEventHandler = eventHandler; //btnFoorDownIcon.MouseUpEventHandler = eventHandler; } } }