using System; using System.Collections.Generic; using System.Text; using HDL_ON.DAL; using HDL_ON.Entity; using HDL_ON.UI.CSS; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Shared; namespace HDL_ON.UI { public partial class HomePage : FrameLayout { #region 控件列表 static HomePage bodyView; /// /// 顶部信息区域 /// FrameLayout topView; /// ///住宅名称显示 /// Button btnResidenceName; /// /// 环境质量显示区域 /// FrameLayout environmentalView; /// /// 当前温度信息 /// Button btnTempValues; /// /// 当前湿度信息 /// Button btnHumidityValues; /// /// 当前pm2.5状态 /// Button btnPm25Values; /// /// 切换显示功能类型区域 /// FrameLayout changeView; /// /// 切换显示设备功能按钮 /// Button btnChangeFunction; /// /// 切换显示场景功能按钮 /// Button btnChangeScene; /// /// 功能显示区域 /// PageLayout contentView; /// /// 设备功能控制区域 /// VerticalScrolViewLayout deviceFunctionView; /// /// 场景功能控制区域 /// VerticalScrolViewLayout sceneFunctionView; /// /// 功能区域集合 /// List functionViews; #endregion #region 区域变量 /// /// 当前显示对控制类型是否是设备功能控制 /// bool CurShowTypeIsFunction = true; #endregion public HomePage() { bodyView = this; bodyView.BackgroundColor = CSS_Color.BackgroundColor; } public void LoadPage() { try { #region topView topView = new FrameLayout() { Height = Application.GetRealHeight(216), BackgroundImagePath = DB_ResidenceData.residenceData.residenceImage, }; bodyView.AddChidren(topView); Button btnTop; btnTop = new Button() { BackgroundColor = CSS_Color.DialogTransparentColor2, }; topView.AddChidren(btnTop); btnResidenceName = new Button() { X = Application.GetRealWidth(16), Y = Application.GetRealHeight(32), Width = Application.GetRealWidth(400), Height = Application.GetRealHeight(33), TextColor = CSS_Color.MainBackgroundColor, TextSize = CSS_FontSize.EmphasisFontSize_FirstLevel, TextAlignment = TextAlignment.CenterLeft, Text = DB_ResidenceData.residenceData.residecenInfo.Name, IsBold = true }; topView.AddChidren(btnResidenceName); #if DEBUG btnResidenceName.MouseUpEventHandler = (sender, e) => { System.Threading.Tasks.Task.Run( async () => { await DAL.Net.MqttCommon.StartMqtt(); }); }; #endif environmentalView = new FrameLayout() { Y = Application.GetRealHeight(1) + btnResidenceName.Bottom, Height = Application.GetRealHeight(32), }; topView.AddChidren(environmentalView); #region 环境数据 Button btnTempIcon = new Button() { X = Application.GetRealWidth(12), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(16), Height = Application.GetMinRealAverage(16), UnSelectedImagePath = "Public/DeviceInfoIcon/TempIcon.png", }; environmentalView.AddChidren(btnTempIcon); btnTempValues = new Button() { X = btnTempIcon.Right + Application.GetRealWidth(4), Width = Application.GetRealWidth(30), Gravity = Gravity.CenterVertical, TextColor = CSS_Color.MainBackgroundColor, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, Text = MainPage.cityInfo.temperature + "°", TextAlignment = TextAlignment.CenterLeft, }; environmentalView.AddChidren(btnTempValues); Button btnHumidityIcon = new Button() { X = btnTempValues.Right + Application.GetRealWidth(2), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(16), Height = Application.GetMinRealAverage(16), UnSelectedImagePath = "Public/DeviceInfoIcon/HumidityIcon.png", }; environmentalView.AddChidren(btnHumidityIcon); btnHumidityValues = new Button() { X = btnHumidityIcon.Right + Application.GetRealWidth(4), Width = Application.GetRealWidth(30), Gravity = Gravity.CenterVertical, TextColor = CSS_Color.MainBackgroundColor, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, Text = MainPage.cityInfo.humidity + "%", TextAlignment = TextAlignment.CenterLeft, }; environmentalView.AddChidren(btnHumidityValues); Button btnPm25Icon = new Button() { X = btnHumidityValues.Right + Application.GetRealWidth(2), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(16), Height = Application.GetMinRealAverage(16), UnSelectedImagePath = "Public/DeviceInfoIcon/Pm25Icon.png", }; environmentalView.AddChidren(btnPm25Icon); btnPm25Values = new Button() { X = btnPm25Icon.Right + Application.GetRealWidth(4), Width = Application.GetRealWidth(30), Gravity = Gravity.CenterVertical, TextColor = CSS_Color.MainBackgroundColor, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, Text = MainPage.cityInfo.pm25, TextAlignment = TextAlignment.CenterLeft, }; environmentalView.AddChidren(btnPm25Values); #endregion #region msg FrameLayout msgView; msgView = new FrameLayout() { Y = Application.GetRealHeight(164), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(28), }; topView.AddChidren(msgView); var btngb = new Button() { BackgroundColor = CSS_Color.MainColor,//0x3F4484F4,// Alpha = 0.4f, }; msgView.AddChidren(btngb); Button btnMsgIcon; btnMsgIcon = new Button() { X = Application.GetRealWidth(12), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(24), Height = Application.GetMinRealAverage(24), UnSelectedImagePath = "Collection/MsgIcon.png", SelectedImagePath = "Collection/MsgIconTip.png", }; msgView.AddChidren(btnMsgIcon); Button btnMsg; btnMsg = new Button() { X = Application.GetRealWidth(10) + btnMsgIcon.Right, Width = Application.GetRealWidth(240), Text = "无", TextColor = CSS_Color.MainBackgroundColor, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, TextAlignment = TextAlignment.CenterLeft, }; msgView.AddChidren(btnMsg); Button btnMsgTime; btnMsgTime = new Button() { X = Application.GetRealWidth(299), Width = Application.GetRealWidth(44), Text = "00:00", TextSize = CSS_FontSize.PromptFontSize_FirstLevel, TextAlignment = TextAlignment.CenterLeft, }; msgView.AddChidren(btnMsgTime); #endregion #endregion #region 功能场景切换 changeView = new FrameLayout() { Y = Application.GetRealHeight(20) + topView.Bottom, Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(230), Height = Application.GetRealHeight(62), BackgroundImagePath = "Collection/ChangeViewbg.png", }; bodyView.AddChidren(changeView); btnChangeFunction = new Button() { Width = Application.GetRealWidth(114), TextID = StringId.Functions, SelectedTextColor = CSS_Color.MainColor, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.HeadlineFontSize, TextAlignment = TextAlignment.Center, IsSelected = true, IsBold = true }; changeView.AddChidren(btnChangeFunction); Button btnLine = new Button() { X = btnChangeFunction.Right, Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(1), Height = Application.GetRealHeight(14), BackgroundColor = CSS_Color.PromptingColor1, }; changeView.AddChidren(btnLine); btnChangeScene = new Button() { X = btnLine.Right, Width = Application.GetRealWidth(114), TextID = StringId.Scenes, SelectedTextColor = CSS_Color.MainColor, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.TextFontSize, TextAlignment = TextAlignment.Center, }; changeView.AddChidren(btnChangeScene); #endregion #region ContextView contentView = new PageLayout() { Y = changeView.Bottom , Height = Application.GetRealHeight(310 + 30 + 10), //20为超出部分 }; bodyView.AddChidren(contentView); functionViews = new List(); deviceFunctionView = new VerticalScrolViewLayout(); contentView.AddChidren(deviceFunctionView); LoadDeviceFunctionControlZone(); sceneFunctionView = new VerticalScrolViewLayout(); contentView.AddChidren(sceneFunctionView); LoadSceneFunctionControlZone(); contentView.PageIndex = 0; #endregion bodyView.AddChidren(new Button() { Y = changeView.Bottom, Height = Application.GetRealHeight(4), BackgroundColor = 0xAAF2F3F7 }); LoadEvent_ChangeShowedFunctionType(); } catch (Exception ex) { MainPage.Log($"HomePage LoadPage Error : {ex.Message}"); } } /// /// 加载设备功能显示区域 /// void LoadDeviceFunctionControlZone() { #region ContextView deviceFunctionView.RemoveAll(); functionViews.Clear(); var rowView = new FrameLayout(); try { int index = 0; foreach (var function in DB_ResidenceData.residenceData.functionList.GetAllDeviceFunctionList()) { //音乐模块有主从关系,需要特殊处理 if (function.functionCategory == FunctionCategory.Music) { var music = function as HDL_ON.UI.Music.A31MusicModel; if (music.ServerClientType == -1) { continue; } else if (music.ServerClientType == 1) { if (!music.MainPlayCollection) { continue; } } else { if (!music.collection) { continue; } } } else { if (!function.collection) continue; if (function.roomIdList.Count == 0)//如何在房间已经移除了这个功能,则收藏界面也不会再显示 { function.collection = false; continue; } } if (index % 2 == 0) { rowView = new FrameLayout() { Height = Application.GetRealWidth(140), }; deviceFunctionView.AddChidren(rowView); } var functionView_X = Application.GetRealWidth((182 + 7) * (index % 2)); if (index % 2 == 0) { functionView_X += Application.GetRealWidth(7); } var functionView = new FrameLayout() { X = functionView_X, Width = Application.GetRealWidth(182), Height = Application.GetRealWidth(140), Radius = (uint)Application.GetRealWidth(12), Tag = function.sid }; rowView.AddChidren(functionView); var btnbg = new Button() { UnSelectedImagePath = "Collection/Functionbg.png", SelectedImagePath = "Collection/FunctionOnbg.png", Tag = function.sid }; functionView.AddChidren(btnbg); functionViews.Add(functionView); LoadDeviceFunctionDiv(functionView, function); index++; } if (index == 0) { var view = new FrameLayout(); deviceFunctionView.AddChidren(view); var btnNoCollectionBg = new Button() { Y = Application.GetRealHeight(20), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(180), Height = Application.GetRealWidth(180), UnSelectedImagePath = "Collection/NoCollectionBg.png", }; view.AddChidren(btnNoCollectionBg); var btnNoCollectionTip = new Button() { Height = Application.GetRealHeight(42), Y = btnNoCollectionBg.Bottom, TextAlignment = TextAlignment.Center, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, TextID = StringId.TipNoFunctionCollcetion, }; view.AddChidren(btnNoCollectionTip); } } catch (Exception ex) { MainPage.Log("homepage error : " + ex.Message); } deviceFunctionView.AddChidren(new Button { Height = Application.GetRealHeight(30) }); #endregion } /// /// 加载场景功能显示区域 /// void LoadSceneFunctionControlZone() { sceneFunctionView.RemoveAll(); var rowView = new FrameLayout(); try { int index = 0; foreach (var function in DB_ResidenceData.residenceData.functionList.scenes) { if (!function.collection) continue; if (function.roomIdList.Count == 0)//如何在房间已经移除了这个功能,则收藏界面也不会再显示 { function.collection = false; continue; } if (index % 2 == 0) { sceneFunctionView.AddChidren(new Button() { Height = Application.GetRealHeight(7) }); rowView = new FrameLayout() { Height = Application.GetRealWidth(122), }; sceneFunctionView.AddChidren(rowView); sceneFunctionView.AddChidren(new Button() { Height = Application.GetRealHeight(7) }); } var functionView_X = Application.GetRealWidth((16 + 164) * (index % 2) + 16); var functionView = new FrameLayout() { X = functionView_X, Width = Application.GetRealWidth(164), Height = Application.GetRealWidth(122), Tag = function.sid, BackgroundImagePath = (function as Scene).ImagePath, }; rowView.AddChidren(functionView); LoadSceneFunctionDiv( functionView, function); index++; } if (index == 0) { var view = new FrameLayout(); sceneFunctionView.AddChidren(view); var btnNoCollectionBg = new Button() { Y = Application.GetRealHeight(20), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(180), Height = Application.GetRealWidth(180), UnSelectedImagePath = "Collection/NoCollectionBg.png", }; view.AddChidren(btnNoCollectionBg); var btnNoCollectionTip = new Button() { Height = Application.GetRealHeight(42), Y = btnNoCollectionBg.Bottom, TextAlignment = TextAlignment.Center, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, TextID = StringId.TipNoSceneCollcetion, }; view.AddChidren(btnNoCollectionTip); } } catch (Exception ex) { MainPage.Log("homepage erorr : " + ex.Message); } sceneFunctionView.AddChidren(new Button { Height = Application.GetRealHeight(30) }); } /// /// 加载功能控制卡片 /// void LoadDeviceFunctionDiv(FrameLayout view, Function function) { try { Button btnIcon; btnIcon = new Button() { X = Application.GetRealWidth(16), Y = Application.GetRealWidth(16), Width = Application.GetMinRealAverage(32), Height = Application.GetMinRealAverage(32), }; view.AddChidren(btnIcon); Button btnName; btnName = new Button() { X = Application.GetRealWidth(21), Y = Application.GetRealWidth(10) + btnIcon.Bottom, Text = function.name, IsBold = true, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.TextFontSize, Height = Application.GetRealWidth(24), Width = Application.GetRealWidth(140), TextAlignment = TextAlignment.CenterLeft, }; view.AddChidren(btnName); Button btnZone; btnZone = new Button() { X = Application.GetRealWidth(21), Y = btnName.Bottom, Height = Application.GetRealWidth(18), Width = Application.GetRealWidth(113), TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel, TextAlignment = TextAlignment.CenterLeft, SelectedTextColor = CSS_Color.MainBackgroundColor, Text = function.GetRoomListName() }; view.AddChidren(btnZone); Button btnState; btnState = new Button() { X = Application.GetRealWidth(21), Y = btnZone.Bottom, Height = Application.GetRealWidth(18), Width = Application.GetRealWidth(113), SelectedTextColor = CSS_Color.MainBackgroundColor, TextColor = 0x00000000, TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel, TextAlignment = TextAlignment.CenterLeft, Tag = "state", Text = function.lastState }; view.AddChidren(btnState); Button btnCollection; btnCollection = new Button() { X = Application.GetRealWidth(130), Y = Application.GetRealWidth(16), Width = Application.GetMinRealAverage(32), Height = Application.GetMinRealAverage(32), SelectedImagePath = "Collection/CollectionWhiteIcon.png", UnSelectedImagePath = "Collection/CollectionIcon.png", }; view.AddChidren(btnCollection); LoadEvent_FunctionCollection(btnCollection, function, true); if (function.functionCategory == FunctionCategory.Curtain) { btnIcon.UnSelectedImagePath = "FunctionIcon/Curtain/CurtainIcon.png"; btnIcon.SelectedImagePath = "FunctionIcon/Curtain/CurtainOnIcon.png"; Button btnCurtainClose; btnCurtainClose = new Button() { X = Application.GetRealWidth(84), Y = Application.GetRealWidth(89), Width = Application.GetRealWidth(44), Height = Application.GetRealWidth(44), UnSelectedImagePath = "FunctionIcon/Curtain/CurtainCloseBlueIcon_Shadow.png", SelectedImagePath = "FunctionIcon/Curtain/CurtainCloseWhiteIcon_Shadow.png", }; view.AddChidren(btnCurtainClose); Button btnCurtainOpen; btnCurtainOpen = new Button() { X = btnCurtainClose.Right, Y = Application.GetRealWidth(89), Width = Application.GetRealWidth(44), Height = Application.GetRealWidth(44), UnSelectedImagePath = "FunctionIcon/Curtain/CurtainOpenBlueIcon_Shadow.png", SelectedImagePath = "FunctionIcon/Curtain/CurtainOpenWhiteIcon_Shadow.png", }; view.AddChidren(btnCurtainOpen); LoadEvent_ControlCurtain(function as Curtain, btnCurtainClose, btnCurtainOpen); } else if (function.functionType == FunctionType.TV) { btnIcon.UnSelectedImagePath = "FunctionIcon/Electrical/TVIcon.png"; Button btnPower; btnPower = new Button() { X = Application.GetRealWidth(131), Y = Application.GetRealHeight(86), Width = Application.GetRealWidth(32), Height = Application.GetRealWidth(32), UnSelectedImagePath = "Public/PowerClose.png", }; view.AddChidren(btnPower); LoadEvent_ControlTV(function as TV, btnPower); } else if (function.functionCategory == FunctionCategory.Music) { btnIcon.UnSelectedImagePath = "FunctionIcon/Music/MusicIcon.png"; btnIcon.SelectedImagePath = "FunctionIcon/Music/MusicOnIcon.png"; Button btnPower; btnPower = new Button() { X = Application.GetRealWidth(118), Y = Application.GetRealWidth(83), Width = Application.GetRealWidth(44), Height = Application.GetRealWidth(44), UnSelectedImagePath = "FunctionIcon/Music/MusicPlayIcon.png", SelectedImagePath = "FunctionIcon/Music/MusicPlayOnIcon.png", }; view.AddChidren(btnPower); var a31player = (function as UI.Music.A31MusicModel); btnState.Text = a31player.A31PlayStatus.Title; btnState.SelectedTextColor = CSS_Color.MainBackgroundColor; btnState.TextColor = CSS_Color.MainBackgroundColor;//PromptingColor1 //Music.SendMethod.ReadStatus(a31player); btnPower.MouseUpEventHandler = (sender, e) => { if (btnPower.IsSelected) { btnPower.IsSelected = false; Music.SendMethod.Pause(a31player); a31player.A31PlayStatus.status = "pause"; a31player.on_off = "off"; } else { btnPower.IsSelected = true; Music.SendMethod.Play(a31player); a31player.A31PlayStatus.status = "play"; a31player.on_off = "on"; } UpdataFunctionStates(a31player); }; } else { Button btnSwitch; btnSwitch = new Button() { X = Application.GetRealWidth(122), Y = Application.GetRealWidth(92), Width = Application.GetMinRealAverage(48), Height = Application.GetMinRealAverage(36), UnSelectedImagePath = "Public/Switch.png", SelectedImagePath = "Public/SwitchOn.png", }; view.AddChidren(btnSwitch); switch (function.functionCategory) { case FunctionCategory.Light: #region 灯光 Light btnIcon.UnSelectedImagePath = "FunctionIcon/Light/LightIcon.png"; btnIcon.SelectedImagePath = "FunctionIcon/Light/LightOnIcon.png"; UpdataFunctionStates(function as Light); #endregion break; case FunctionCategory.Thermostat: switch (function.functionType) { case FunctionType.AC: #region 空调 AC btnIcon.UnSelectedImagePath = "FunctionIcon/AC/AcIcon.png"; btnIcon.SelectedImagePath = "FunctionIcon/AC/AcOnIcon.png"; #endregion break; case FunctionType.FloorHeating: #region 地热 btnIcon.UnSelectedImagePath = "FunctionIcon/FloorHeating/FloorHeatingIcon.png"; btnIcon.SelectedImagePath = "FunctionIcon/FloorHeating/FloorHeatingOnIcon.png"; #endregion break; } break; case FunctionCategory.SwitchDevice: switch (function.functionType) { case FunctionType.Socket: btnIcon.UnSelectedImagePath = "FunctionIcon/Socket/SocketIcon.png"; btnIcon.SelectedImagePath = "FunctionIcon/Socket/SocketOnIcon.png"; break; } break; case FunctionCategory.Electrical: switch (function.functionType) { case FunctionType.Fan: btnIcon.UnSelectedImagePath = "FunctionIcon/Electrical/FanIcon.png"; btnIcon.SelectedImagePath = "FunctionIcon/Electrical/FanOnIcon.png"; break; } break; } LoadEvent_SwitchFunction(function, btnSwitch); } var skipControlPageEvent = new PublicAssmebly().LoadEvent_SkipFunctionControlPage(function, new Button(), new Button(), new Button()); view.MouseUpEventHandler = skipControlPageEvent; btnName.MouseUpEventHandler = skipControlPageEvent; btnIcon.MouseUpEventHandler = skipControlPageEvent; btnState.MouseUpEventHandler = skipControlPageEvent; //电视不需要更新状态 if(function.functionType!= FunctionType.TV) { UpdataFunctionStates(function); } } catch (Exception ex) { MainPage.Log("homepage LoadControlView error : " + ex.Message); } } /// /// 加载场景控制卡片 /// void LoadSceneFunctionDiv(FrameLayout view, Function function) { try { Button btnName; btnName = new Button() { X = Application.GetRealWidth(12), Y = Application.GetRealWidth(68), Width = Application.GetRealWidth(150), Height = Application.GetRealHeight(24), Text = function.name, TextSize = CSS_FontSize.TextFontSize, TextColor = CSS_Color.MainBackgroundColor, TextAlignment = TextAlignment.CenterLeft, }; view.AddChidren(btnName); Button btnZone; btnZone = new Button() { X = Application.GetRealWidth(12), Y = btnName.Bottom, Height = Application.GetRealWidth(18), Width = Application.GetRealWidth(113), TextColor = CSS_Color.MainBackgroundColor, TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel, TextAlignment = TextAlignment.CenterLeft, SelectedTextColor = CSS_Color.MainBackgroundColor, Text = function.GetRoomListName(), }; view.AddChidren(btnZone); Button btnCoverd = new Button() { UnSelectedImagePath = "Collection/SceneCovered.png", }; view.AddChidren(btnCoverd); Button btnDelayIcon; btnDelayIcon = new Button() { X = Application.GetRealWidth(12), Y = Application.GetRealWidth(12), Height = Application.GetRealWidth(24), Width = Application.GetRealWidth(24), UnSelectedImagePath = "FunctionIcon/Scene/DelayIcon.png" }; view.AddChidren(btnDelayIcon); Button btnCollection; btnCollection = new Button() { X = Application.GetRealWidth(116), Y = Application.GetRealWidth(8), Width = Application.GetMinRealAverage(32), Height = Application.GetMinRealAverage(32), SelectedImagePath = "Collection/CollectionWhiteIcon.png", UnSelectedImagePath = "Collection/CollectionIcon.png", }; view.AddChidren(btnCollection); LoadEvent_FunctionCollection(btnCollection, function, false); LoadEvent_ControlScene(btnCoverd, function); } catch (Exception ex) { MainPage.Log("homepage LoadControlView error : " + ex.Message); } } } }