gxc
2019-11-04 b7b3e92bed9c4553e30e2901a1877f088a5f8823
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
using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.Device.CommonForm;
using ZigBee.Device;
 
namespace Shared.Phone.Device.Room
{
    public class RoomHumiditySetting:FrameLayout
    {
        #region ◆ 变量____________________________
        /// <summary>
        /// bodyFrameLayout
        /// </summary>
        private FrameLayout bodyFrameLayout;
        /// <summary>
        /// verticalScrolView
        /// </summary>
        private VerticalScrolViewLayout verticalScrolView;
        /// <summary>
        /// The room.
        /// </summary>
        public Shared.Common.Room room;
        /// <summary>
        /// The action.
        /// </summary>
        public Action<CommonDevice> selectDeviceAction;
 
        /// <summary>
        /// tempDeviceRow
        /// </summary>
        private DeviceInfoWithZoneRow tempDeviceRow = null;
        /// <summary>
        /// tempDevice
        /// </summary>
        public CommonDevice tempDevice;
 
        #endregion
 
        public RoomHumiditySetting()
        {
            BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
        }
 
        /// <summary>
        /// Show this instance.
        /// </summary>
        public void Show(Shared.Common.Room r)
        {
            room = r;
 
            AddTop();
 
            AddBodyView();
 
        }
 
        #region Add____________________________________
 
        /// <summary>
        /// AddTop
        /// </summary>
        public void AddTop()
        {
            var top = new TopFrameLayout();
            AddChidren(top);
            top.InitTopview();
            top.SetTopTitle(R.MyInternationalizationString.Humidity);
            top.backButton.MouseUpEventHandler += (sender, e) =>
            {
                RemoveFromParent();
            };
        }
 
        /// <summary>
        /// AddBodyView
        /// </summary>
        public void AddBodyView()
        {
            bodyFrameLayout = new FrameLayout()
            {
                Y = Application.GetRealHeight(184),
                Height = Application.GetRealHeight(1737),
                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
            };
            AddChidren(bodyFrameLayout);
 
            verticalScrolView = new VerticalScrolViewLayout
            {
                Height = Application.GetRealHeight(1737)
            };
            bodyFrameLayout.AddChidren(verticalScrolView);
 
            var confirm = new Device.CommonForm.CompleteButton(1700, 700, 127);
            confirm.SetTitle(R.MyInternationalizationString.Save);
            AddChidren(confirm);
            confirm.MouseUpEventHandler += (sender, e) =>
            {
                RemoveFromParent();
                if (tempDevice != null)
                {
                    selectDeviceAction?.Invoke(tempDevice);
                }
            };
 
            var deviceList = GetHumidityDevice();
 
            for (int i = 0; i < deviceList.Count; i++)
            {
                var device = deviceList[i];
                var devRow = new DeviceInfoWithZoneRow(20 + i * (127 + 20));
                verticalScrolView.AddChidren(devRow);
                devRow.Init();
                devRow.SetIcon(device.IconPath);
                devRow.SetName(device.DeviceName);
                devRow.SetZone(room.FloorName + ", " + room.Name);
 
                if (tempDevice != null && tempDevice == device)
                {
                    tempDeviceRow = devRow;
                    tempDevice = device;
                    devRow.SetStatu(true);
                }
                else
                {
                    if (i == 0 && tempDevice == null)
                    {
                        tempDeviceRow = devRow;
                        tempDevice = device;
                        devRow.SetStatu(true);
                    }
                }
 
                devRow.ClickButton.MouseUpEventHandler += (sender, e) =>
                {
                    tempDeviceRow.SetStatu(false);
                    devRow.SetStatu(true);
                    tempDeviceRow = devRow;
                    tempDevice = device;
                };
            }
 
        }
 
        /// <summary>
        /// AddItem
        /// </summary>
        /// <param name="vertical"></param>
        public void AddItem(VerticalScrolViewLayout vertical, int y)
        {
            var dev = new DeviceInfoWithZoneRow(y);
            vertical.AddChidren(dev);
            dev.Init();
            dev.SetIcon("DeviceIcon/1.png");
            dev.SetName("湿度传感器" + y);
            dev.SetZone(room.FloorName + ", " + room.Name);
        }
 
        /// <summary>
        /// 湿度传感器列表
        /// </summary>
        private List<ZigBee.Device.CommonDevice> GetHumidityDevice()
        {
            var listDevice = new List<ZigBee.Device.CommonDevice>();
            foreach (var device in Common.LocalDevice.Current.listAllDevice)
            {
                //获取湿度传感器
                if (device is ZigBee.Device.TemperatureSensor && ((ZigBee.Device.TemperatureSensor)device).SensorDiv == 2)
                {
                    listDevice.Add(device);
                }
            }
            return listDevice;
        }
        #endregion
    }
}