黄学彪
2019-11-25 5727cf0b9b54da0a191dd1e23cb5abf21320fbff
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
using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.Device.CommonForm;
using ZigBee.Device;
 
namespace Shared.Phone.Device.Room
{
    public class RoomTemperatureSetting : FrameLayout
    {
        #region ◆ 变量____________________________
        /// <summary>
        /// bodyFrameLayout
        /// </summary>
        private FrameLayout bodyFrameLayout;
        /// <summary>
        /// The action.
        /// </summary>
        public Action<CommonDevice> selectDeviceAction;
        /// <summary>
        /// verticalScrolView
        /// </summary>
        private VerticalScrolViewLayout verticalScrolView;
        /// <summary>
        /// The room.
        /// </summary>
        public Shared.Common.Room room;
        /// <summary>
        /// tempDeviceRow
        /// </summary>
        private DeviceInfoWithZoneRow tempDeviceRow = null;
        /// <summary>
        /// tempDevice
        /// </summary>
        public CommonDevice tempDevice;
 
        #endregion
 
        public RoomTemperatureSetting()
        {
            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.Temperature);
            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 = GetTemperatrueDevices();
            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>
        /// 温度传感器列表
        /// </summary>
        private List<ZigBee.Device.CommonDevice> GetTemperatrueDevices()
        {
            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 == 1)
                {
                    listDevice.Add(device);
                }
            }
            return listDevice;
        }
 
        #endregion
    }
}