黄学彪
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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
using System;
using System.Collections.Generic;
using Shared.Common;
namespace Shared.Phone.Device.Room
{
    /// <summary>
    /// Add devices same type list.
    /// </summary>
    public class AddDevicesSameTypeList : FrameLayout
    {
        #region ◆ 变量____________________________
 
        /// <summary>
        /// 设备列表
        /// </summary>
        private List<DeviceUI> sameTypeList;
        /// <summary>
        /// The top view.
        /// </summary>
        private FrameLayout topView;
        /// <summary>
        /// The top BGView.
        /// </summary>
        private FrameLayout topBGView;
        /// <summary>
        /// 中部视图
        /// </summary>
        private VerticalScrolViewLayout midFL;
 
        #endregion
 
        #region ◆ 构造方法_________________________
 
        /// <summary>
        /// 构造方法
        /// </summary>
        public AddDevicesSameTypeList()
        {
            BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
            Tag = "categoryAddScene";
        }
 
        public override void RemoveFromParent()
        {
            base.RemoveFromParent();
        }
 
        #endregion
 
        #region ◆ 显示界面_________________________
 
        /// <summary>
        /// 显示界面
        /// </summary>
        /// <param name="deviceType">设备类型</param>
        /// <param name="room">Room.</param>
        public void Show(ZigBee.Device.DeviceType deviceType, Shared.Common.Room room)
        {
            //添加topview
            AddTopView(deviceType);
            //加载当前相同类型设备类型
            AddDeviceToList(deviceType, room);
            //如果没有可添加的设备,提示用户返回
            if (IsHadDeviceToAdd() == false)
            {
                ShowNoDeviceTip();
                return;
            }
            //添加midview
            AddMidView();
            //显示设备列表
            ShowDeviceList(room);
        }
 
        #endregion
 
        #region ◆ 添加topview_____________________
 
        /// <summary>
        /// Adds the top view.
        /// </summary>
        private void AddTopView(ZigBee.Device.DeviceType deviceType)
        {
            topBGView = new FrameLayout()
            {
                Height = Application.GetRealHeight(CommonPage.Navigation_Height),
                BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor
            };
            AddChidren(topBGView);
            topView = new FrameLayout()
            {
                Y = Application.GetRealHeight(CommonPage.NavigationTitle_Y),
                Height = Application.GetRealHeight(CommonPage.Navigation_Height - CommonPage.NavigationTitle_Y),
                BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor,
            };
            AddChidren(topView);
 
 
            var title = new Button()
            {
                TextAlignment = TextAlignment.Center,
                Text = DeviceUI.GetDeviceTypeName(deviceType),
                TextSize = 20,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                Width = Application.GetRealWidth(CommonPage.AppRealWidth - 500),
                Gravity = Gravity.CenterHorizontal
            };
            topView.AddChidren(title);
 
            var back = new Device.CommonForm.BackButton() { };
            topView.AddChidren(back);
            back.MouseUpEventHandler += (sender, e) =>
            {
                this.RemoveFromParent();
            };
        }
 
        #endregion
 
        #region ◆ 添加midView_____________________
 
        /// <summary>
        /// Adds the middle view.
        /// </summary>
        private void AddMidView()
        {
            midFL = new VerticalScrolViewLayout()
            {
                Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
                Y = topView.Bottom,
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
            };
            this.AddChidren(midFL);
        }
 
        #endregion
 
        #region ◆ 显示设备列表______________________
 
        /// <summary>
        /// 将设备显示出来
        /// </summary>
        private void ShowDeviceList(Shared.Common.Room room)
        {
            foreach (var device in sameTypeList)
            {
                if (device == null || device.CommonDevice == null)
                {
                    continue;
                }
                var deviceItemFL = new FrameLayout()
                {
                    Height = Application.GetRealHeight(170)
                };
                midFL.AddChidren(deviceItemFL);
                var deviceIMG = new Button()
                {
                    X = Application.GetRealWidth(50),
                    Width = Application.GetMinRealAverage(110),
                    Height = Application.GetMinRealAverage(110),
                    UnSelectedImagePath = device.IconPath,
                    SelectedImagePath = device.IconPath,
                    Gravity = Gravity.CenterVertical
                };
                deviceItemFL.AddChidren(deviceIMG);
                var deviceName = new Button()
                {
                    X = deviceIMG.Right + Application.GetRealWidth(50),
                    Width = Application.GetRealWidth(700),
                    Height = Application.GetRealHeight(110),
                    TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                    SelectedTextColor = ZigbeeColor.Current.GXCButtonBlueColor,
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = 16,
                    Text = device.CommonDevice.DeviceEpointName,
                    Gravity = Gravity.CenterVertical
                };
                deviceItemFL.AddChidren(deviceName);
                var deviceRight = new Device.CommonForm.SelectedStatuButton()
                {
                    X = Application.GetRealWidth(1080 - 150),
                    Width = Application.GetMinRealAverage(110),
                    Height = Application.GetMinRealAverage(110),
                    UnSelectedImagePath = "Item/Next.png",
                    SelectedImagePath = "Item/NextSelected.png",
                    Gravity = Gravity.CenterVertical
                };
                deviceItemFL.AddChidren(deviceRight);
                var line = new Button()
                {
                    Y = Application.GetRealHeight(170) - 1,
                    Height = 1,
                    BackgroundColor = ZigbeeColor.Current.GXCLineColor,
                    Tag = device
                };
                deviceItemFL.AddChidren(line);
 
                //跳转详细设置
                EventHandler<MouseEventArgs> deviceHandler = (sender, e) =>
                {
                    var detail = new Room.AddDevieDetailFromAddFunction();
                    UserView.HomePage.Instance.AddChidren(detail);
                    UserView.HomePage.Instance.PageIndex += 1;
                    detail.Show(device, room);
                };
                deviceRight.MouseUpEventHandler += deviceHandler;
                deviceIMG.MouseUpEventHandler += deviceHandler;
                deviceName.MouseUpEventHandler += deviceHandler;
            }
        }
 
        #endregion
 
        #region ◆ 是否有设备可以添加__________________
        /// <summary>
        /// 提示用户没有设备可以添加到该房间
        /// </summary>
        private void ShowNoDeviceTip()
        {
            var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.NoDeviceCanAddToRoom), Language.StringByID(R.MyInternationalizationString.Close));
            alert.Show();
            alert.ResultEventHandler += (sender, e) =>
            {
                this.RemoveFromParent();
            };
        }
 
        /// <summary>
        /// 是否有可以添加到当前当前房间的设备
        /// </summary>
        /// <returns><c>true</c>, if had device to add was ised, <c>false</c> otherwise.</returns>
        private bool IsHadDeviceToAdd()
        {
            if (sameTypeList.Count == 0)
            {
                return false;
            }
            return true;
        }
 
        #endregion
 
        #region ◆ 添加设备到列表______________________
 
        private void AddDeviceToList(ZigBee.Device.DeviceType deviceType, Shared.Common.Room room)
        {
            sameTypeList = new List<DeviceUI>();
 
            foreach (var device in LocalDevice.Current.listAllDevice)
            {
                if (device.Type != deviceType)
                {
                    continue;
                }
                var dev = LocalDevice.Current.GetDeviceUI(device);
                if (dev == null || dev.CommonDevice == null)
                {
                    continue;
                }
                //去掉改房间已包含的设备
                if (room.DeviceUIList.Contains(dev) == false)
                {
                    sameTypeList.Add(dev);
                }
            }
        }
 
        #endregion
    }
}