黄学彪
2021-01-28 1fcf2302f79f9cbea5ef17c3688311ed65cfabb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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;
 
        /// <summary>
        /// 声必可面板基本信息
        /// </summary>
        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();
        }
 
        /// <summary>
        /// 接收数据处理
        /// </summary>
        /// <param name="receiveBytes"></param>
        void ReceiveEvent(string receiveData)
        {
            try
            {
                sbk_Device = JsonConvert.DeserializeObject<SBK_DeviceObj>(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}");
            }
        }
 
        /// <summary>
        /// 加载场景数据行
        /// </summary>
        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);
        }
 
        /// <summary>
        /// 获取场景列表 
        /// </summary>
        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);
 
        }
        /// <summary>
        /// 管理场景列表
        /// </summary>
        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;
            };
        }
    }
}