黄学彪
2020-12-17 6c0c799c1f5da2d215ec8d9df9b92b3d1948dc14
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
using System;
using Shared;
using HDL_ON.UI.CSS;
using Newtonsoft.Json;
using HDL_ON.Entity;
using System.Collections.Generic;
using HDL_ON.DriverLayer;
 
namespace HDL_ON.UI
{
    public partial class SearchDevicePage : FrameLayout
    {
        FrameLayout bodyView;
        VerticalRefreshLayout contentView;
        List<string> deviceIpList = new List<string>();
        public SearchDevicePage()
        {
            bodyView = this;
        }
 
        public void LoadPage()
        {
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            new TopViewDiv(bodyView, Language.StringByID(StringId.Panel)).LoadTopView();
 
            contentView = new VerticalRefreshLayout()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(603),
            };
            bodyView.AddChidren(contentView);
 
            contentView.BeginHeaderRefreshingAction += () =>
            {
                deviceIpList.Clear();
                contentView.RemoveAll();
                //DriverLayer.Control.ins.ChangeCommunicationMode(DriverLayer.CommunicationMode.local_BusUdp);
                //                UdpSocket._BusSocket.SearchNetDeviceAction = (jto) =>
                //                {
                //                    var device = JsonConvert.DeserializeObject<DeviceModule>(jto.ToString());
                //                    if (device != null)
                //                    {
                //                        lock (deviceIpList)
                //                        {
                //                            if (!deviceIpList.Contains(device.ip_address))
                //                            {
                //                                deviceIpList.Add(device.ip_address);
                //                                MainPage.Log($"搜索到网络设备:{device.ip_address}");
                //                                Application.RunOnMainThread(() =>
                //                                {
                //#if DEBUG
                //#else
                //                                    if(device.gateway_type== 4)
                //#endif
                //                                    {
                //                                        LoadRow(device);
                //                                    }
                //                                });
                //                            }
                //                            else
                //                            {
                //                                MainPage.Log($"已加载该IP设备:{device.ip_address}");
                //                            }
                //                        }
                //                    }
                //                };
                new Control_Udp().SearchLocalGateway();
                contentView.EndHeaderRefreshing();
            };
 
            contentView.BeginHeaderRefreshing();
 
        }
        /// <summary>
        /// 
        /// </summary>
        void LoadRow(DeviceModule device)
        {
            contentView.AddChidren(new Button() { Height = Application.GetRealHeight(12) });
            var bodyDiv = new FrameLayout()
            {
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealHeight(80),
                Radius = (uint)Application.GetMinRealAverage(12),
                BorderColor = 0x00FFFFFF,
                BorderWidth = 1,
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            contentView.AddChidren(bodyDiv);
 
            Button btnIcon = new Button()
            {
                X = Application.GetRealWidth(10),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(32),
                Height = Application.GetRealWidth(32),
            };
            bodyDiv.AddChidren(btnIcon);
 
            switch (device.gateway_type)
            {
                case 4:
                    btnIcon.UnSelectedImagePath = "FunctionIcon/DeviceIcon/VoicePanelIcon.png";
                    break;
                default:
                    break;
            }
 
            Button btnName = new Button()
            {
                X = Application.GetRealWidth(54),
                Width = Application.GetRealWidth(200),
                Text = device.device_name,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.TextFontSize,
            };
            bodyDiv.AddChidren(btnName);
 
            SkipVoicePanelScenePage(device, bodyDiv, btnIcon, btnName);
        }
    }
 
 
    public partial class SearchDevicePage
    {
        void SkipVoicePanelScenePage(DeviceModule device,FrameLayout div,Button btn1,Button btn2)
        {
            EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
            {
                var page = new VoicePanelSceneListPage(device);
                MainPage.BasePageView.AddChidren(page);
                page.LoadPage();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            div.MouseUpEventHandler = eventHandler;
            btn1.MouseUpEventHandler = eventHandler;
            btn2.MouseUpEventHandler = eventHandler;
        }
 
    }
 
}