using System; using Shared; using HDL_ON.Entity; using HDL_ON.UI.CSS; using Newtonsoft.Json; namespace HDL_ON.UI { public class VoicePanelSceneListPage : FrameLayout { FrameLayout bodyView; VerticalRefreshLayout contentView; Button btnAddScene; /// /// 声必可面板基本信息 /// DeviceModule device; SBK_DeviceObj sbk_Device; public VoicePanelSceneListPage(DeviceModule device) { bodyView = this; this.device = device; } public void LoadPage() { Action skipAction = () => { var page = new VoicePanelScenePage(sbk_Device); MainPage.BasePageView.AddChidren(page); page.LoadPage(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }; bodyView.BackgroundColor = CSS_Color.BackgroundColor; new TopViewDiv(bodyView, device.device_name).LoadTopView_SettingIcon(skipAction); FrameLayout divTopTitle = new FrameLayout() { Y = Application.GetRealHeight(64), Height = Application.GetRealHeight(44), BackgroundColor = CSS_Color.MainBackgroundColor, }; bodyView.AddChidren(divTopTitle); Button btnTitle = new Button() { X = Application.GetRealWidth(16), Width = Application.GetRealWidth(300), TextID = StringId.PanelScene, TextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.SubheadingFontSize, TextAlignment = TextAlignment.CenterLeft, IsBold = true, }; divTopTitle.AddChidren(btnTitle); DriverLayer.Control.Ins.reportIp = device.ip_address; //DriverLayer.Control.ins.OpenTcpClent(); DriverLayer.Control.Ins.myTcpClient.ReceiveEvent = ReceiveEvent; contentView = new VerticalRefreshLayout() { Y = Application.GetRealHeight(64 + 44), Height = Application.GetRealHeight(603 - 44), }; bodyView.AddChidren(contentView); contentView.BeginHeaderRefreshingAction += () => { contentView.RemoveAll(); GetSceneListEvent(); contentView.EndHeaderRefreshing(); }; contentView.BeginHeaderRefreshing(); btnAddScene = new Button() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(582), Width = Application.GetRealWidth(220), Height = Application.GetRealWidth(44), Radius = (uint)Application.GetRealWidth(22), BackgroundColor = CSS_Color.MainColor, TextColor = CSS_Color.MainBackgroundColor, TextSize = CSS_FontSize.SubheadingFontSize, TextAlignment = TextAlignment.Center, IsBold = true, TextID = StringId.AddScene, }; bodyView.AddChidren(btnAddScene); LoadEvent_AddScene(); } /// /// 接收数据处理 /// /// void ReceiveEvent(string receiveData) { try { sbk_Device = JsonConvert.DeserializeObject(receiveData); if(sbk_Device == null) { sbk_Device = new SBK_DeviceObj(); } sbk_Device.name = device.device_name; if (sbk_Device.from_oid == "on+" && sbk_Device.type == "scene" && sbk_Device.command == "get_list_response") { foreach (var scene in sbk_Device.number) { Application.RunOnMainThread(() => { LoadSceneRow(scene); }); } } } catch (Exception ex) { MainPage.Log($"读取声必可场景异常:{ex.Message}"); } } /// /// 加载场景数据行 /// void LoadSceneRow(SBK_Scene sbk_Scene) { var bodyDiv = new FrameLayout() { Gravity = Gravity.CenterHorizontal, Height = Application.GetRealHeight(50), BackgroundColor = CSS_Color.MainBackgroundColor, }; contentView.AddChidren(bodyDiv); bodyDiv.AddChidren(new Button() { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(1), BackgroundColor = CSS_Color.DividingLineColor }); Button btnIcon = new Button() { X = Application.GetRealWidth(10), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(32), Height = Application.GetRealWidth(32), UnSelectedImagePath = "FunctionIcon/DeviceIcon/VoicePanelIcon.png", }; bodyDiv.AddChidren(btnIcon); Button btnName = new Button() { X = Application.GetRealWidth(54), Width = Application.GetRealWidth(200), Text = sbk_Scene.name, TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.TextFontSize, }; bodyDiv.AddChidren(btnName); //SkipVoicePanelScenePage(device, bodyDiv, btnIcon, btnName); } /// /// 获取场景列表 /// void GetSceneListEvent() { AProtocolSendingObject sendingObject = new AProtocolSendingObject() { command = "get_list", type = "scene", }; var sendJson = JsonConvert.SerializeObject(sendingObject); var sendBytes = System.Text.Encoding.ASCII.GetBytes(sendJson); DriverLayer.Control.Ins.myTcpClient.SendMessage(sendBytes); } /// /// 管理场景列表 /// void LoadEvent_AddScene() { btnAddScene.MouseUpEventHandler = (sender, e) => { var page = new VoicePanelScenePage(sbk_Device); MainPage.BasePageView.AddChidren(page); page.LoadPage(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }; } } }