黄学彪
2019-12-20 23fb45dd846ed8b62304c408c6bbe64265d4ac8b
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.Device.CommonForm;
 
namespace Shared.Phone.Device.Category
{
    public class SelectScene : FrameLayout
    {
        #region ◆ 变量____________________________
        /// <summary>
        /// bodyFrameLayout
        /// </summary>
        private FrameLayout bodyFrameLayout;
        /// <summary>
        /// selectedTimeAction
        /// </summary>
        public Action<SceneTargetDeviceUI> selectedAction;
        /// <summary>
        /// sceneTargetDevice
        /// </summary>
        public SceneTargetDeviceUI sceneTargetDevice;
        /// <summary>
        /// BeforesceneTargetDeviceUIs
        /// </summary>
        public List<SceneTargetDeviceUI> beforeSceneTargetDeviceUIs=new List<SceneTargetDeviceUI> { };
        /// <summary>
        /// 楼层
        /// </summary>
        private Button floorBtn;
        /// <summary>
        /// 选择楼层
        /// </summary>
        private Button selectFloorBtn;
        /// <summary>
        /// 场景功能中部背景bodyView
        /// </summary>
        public FrameLayout functionSceneBodyView;
        /// <summary>
        /// sceneUI
        /// </summary>
        public SceneUI sceneUI;
        /// <summary>
        /// 当前场景本身,添加场景时使用
        /// </summary>
        public SceneUI currentSceneUI;
 
        #endregion
 
        /// <summary>
        /// SelectScene
        /// </summary>
        public SelectScene()
        {
            BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
        }
 
 
        /// <summary>
        /// Show
        /// </summary>
        public void Show()
        {
            if (sceneTargetDevice == null)
            {
                sceneTargetDevice = new SceneTargetDeviceUI { Type = 1 };
            }
            AddTop();
 
            AddBodyView();
 
            RefreshBodyView(Config.Instance.Home.CurrentFloorId);
        }
 
 
        #region Add____________________________________
        /// <summary>
        /// AddTop
        /// </summary>
        private void AddTop()
        {
            var top = new TopFrameLayout();
            AddChidren(top);
            top.InitTopview();
            top.SetTopTitle(R.MyInternationalizationString.AddScence);
            top.backButton.MouseUpEventHandler += (sender, e) =>
            {
                RemoveFromParent();
            };
 
            floorBtn = new Button()
            {
                X = Application.GetRealWidth(750),
                Width = Application.GetRealWidth(200),
                Height = Application.GetRealHeight(60),
                Gravity = Gravity.CenterVertical,
                TextAlignment = TextAlignment.CenterRight,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
            };
 
            selectFloorBtn = new Button()
            {
                X = Application.GetRealWidth(950),
                Width = Application.GetMinRealAverage(69),
                Height = Application.GetMinRealAverage(69),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "Item/Drop_Down.png"
            };
 
            if (Config.Instance.Home.FloorDics.Count > 0)
            {
                floorBtn.Text = Config.Instance.Home.GetCurrentFloorName;
                top.topView.AddChidren(floorBtn);
                top.topView.AddChidren(selectFloorBtn);
                floorBtn.MouseUpEventHandler += SelectedFloor_MouseUpEventHandler;
                selectFloorBtn.MouseUpEventHandler += SelectedFloor_MouseUpEventHandler;
            }
        }
 
        /// <summary>
        /// 选择楼层
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param>
        private void SelectedFloor_MouseUpEventHandler(object sender, MouseEventArgs mouseEventArgs)
        {
            var floors = new SelectFloor();
            AddChidren(floors);
            floors.Init(580, 184, Direction.Right);
            floors.FloorAction += (floorId) =>
            {
                floorBtn.Text = Config.Instance.Home.GetFloorNameById(floorId);
                RefreshBodyView(floorId);
            };
        }
        /// <summary>
        /// AddBodyView
        /// </summary>
        private void AddBodyView()
        {
            bodyFrameLayout = new FrameLayout()
            {
                Y = Application.GetRealHeight(184),
                Height = Application.GetRealHeight(1737),
                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
            };
            AddChidren(bodyFrameLayout);
 
            var confirmBtn = new CommonForm.CompleteButton(1656, 907, 127);
            AddChidren(confirmBtn);
            confirmBtn.SetTitle(R.MyInternationalizationString.Save);
            confirmBtn.MouseUpEventHandler += (sender, e) =>
            {
                sceneTargetDevice.ElseScenesId = sceneUI.Id ;
                sceneTargetDevice.SceneUI = sceneUI;
                sceneTargetDevice.SceneName = sceneUI.Name;
                selectedAction?.Invoke(sceneTargetDevice);
                RemoveFromParent();
            };
        }
 
        #endregion
 
        /// <summary>
        /// RefreshBodyView
        /// </summary>
        private void RefreshBodyView(string floorId)
        {
            AddRoomView(floorId);
        }
 
        /// <summary>
        /// AddRoomView
        /// </summary>
        private void AddRoomView(string floorId)
        {
            var roomFL = new HorizontalScrolViewLayout()
            {
                X = Application.GetRealWidth(CommonFormResouce.X_Left),
                Height = Application.GetRealHeight(204),
                Width = Application.GetRealWidth(CommonPage.AppRealWidth - CommonFormResouce.X_Left),
                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor
            };
            bodyFrameLayout.AddChidren(roomFL);
 
            //功能和场景bodyView
            functionSceneBodyView = new FrameLayout()
            {
                Y = roomFL.Bottom,
                Height = Application.GetRealHeight(910+622),
                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor
            };
            bodyFrameLayout.AddChidren(functionSceneBodyView);
 
            Button curBtn = new Button();
            foreach (var room in Common.Room.CurrentRoom.GetRoomsByFloorIdAppendLoveRoom(floorId))
            {
                var row = new FrameLayout()
                {
                    Width = Application.GetRealWidth(187 + 50),
                    Height = Application.GetRealHeight(204),
                };
                roomFL.AddChidren(row);
 
                var roomBtn = new Button()
                {
                    Width = Application.GetRealWidth(187),
                    Height = Application.GetRealHeight(78),
                    Radius = (uint)Application.GetRealHeight(78 / 2),
                    Gravity = Gravity.Center,
                    Text = room.Name,
                    TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                    SelectedTextColor = ZigbeeColor.Current.GXCTextWhiteColor,
                    BackgroundColor = ZigbeeColor.Current.GXCButtonUnSelectedColor3,
                    SelectedBackgroundColor = ZigbeeColor.Current.GXCButtonSelectedColor,
                    BorderColor = ZigbeeColor.Current.GXCBorderUnSelectedColor,
                    BorderWidth = 1
                };
                row.AddChidren(roomBtn);
 
                if (room.IsLove)
                {
                    roomBtn.IsSelected = true;
                    curBtn = roomBtn;
 
                    RefreshScene(room);
                }
                roomBtn.MouseUpEventHandler += (sender, e) =>
                {
                    if ((sender as Button) == curBtn)
                    {
                        return;
                    }
                    (sender as Button).IsSelected = true;
                    curBtn.IsSelected = false;
                    curBtn = sender as Button;
 
                    RefreshScene(room);
                };
            }
 
        }
 
 
        /// <summary>
        /// RefreshScene
        /// </summary>
        /// <param name="room"></param>
        public void RefreshScene(Common.Room room)
        {
            functionSceneBodyView.RemoveAll();
            var sceneList = room.SceneUIList;
            if (sceneList.Count == 0)
            {
                ShowNoSceneTip();
            }
            else
            {
                var sceneScrolView = new VerticalScrolViewLayout
                {
                    //Y = Application.GetRealHeight(58)
                };
                functionSceneBodyView.AddChidren(sceneScrolView);
                SelectSceneRow tempSceneRow = new SelectSceneRow();
                EventHandler<MouseEventArgs> selectScene = (sender, e) => {
                    tempSceneRow.IsSelected = false;
                    tempSceneRow = ((sender as Button).Parent as SelectSceneRow);
                    ((sender as Button).Parent as SelectSceneRow).IsSelected = true;
                    tempSceneRow.IsSelected = true;
                    sceneUI = (sender as Button).Tag as SceneUI;
                };
 
                for (int i = 0; i < sceneList.Count; i++)
                {
                    var scene = sceneList[i];
                    if (currentSceneUI?.Id == scene.Id)
                    {
                        continue;
                    }
                    if (beforeSceneTargetDeviceUIs.Find((obj) => obj.SceneUI.Id == scene.Id) != null)
                    {
                        continue;
                    }
                    var sceneFL = new FrameLayout()
                    {
                        Height = Application.GetRealHeight(127 + 23),
                        BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
                        Tag = scene
                    };
                    sceneScrolView.AddChidren(sceneFL);
                    var sceneRowLayout = new SelectSceneRow(0, 23);
                    sceneFL.AddChidren(sceneRowLayout);
                    sceneRowLayout.Init();
                    sceneRowLayout.SetTitle(scene.Name);
                    sceneRowLayout.ClickButton.Tag = scene;
                    if (sceneUI == null)
                    {
                        if (i == 0)
                        {
                            tempSceneRow = sceneRowLayout;
                            sceneUI = scene;
                            sceneRowLayout.IsSelected = true;
                        }
                    }
                    else
                    {
                        if (sceneUI.Id == scene.Id)
                        {
                            tempSceneRow = sceneRowLayout;
                            sceneUI = scene;
                            sceneRowLayout.IsSelected = true;
                        }
                    }
                    
                    sceneRowLayout.ClickButton.MouseUpEventHandler += selectScene;
                }
            }
        }
 
        /// <summary>
        /// 显示没有场景
        /// </summary>
        private void ShowNoSceneTip()
        {
            var noFunction = new Button()
            {
                Y = Application.GetRealHeight(320),
                Width = Application.GetMinRealAverage(757),
                Height = Application.GetMinRealAverage(435),
                UnSelectedImagePath = "Item/NoFunction.png",
                Gravity = Gravity.CenterHorizontal
            };
            functionSceneBodyView.AddChidren(noFunction);
 
            var noScenceTip = new Button()
            {
                Y = noFunction.Bottom + Application.GetRealHeight(32),
                Height = Application.GetRealHeight(200),
                Width = Application.GetRealWidth(700),
                Gravity = Gravity.CenterHorizontal,
                Text = Language.StringByID(R.MyInternationalizationString.NoScene).Replace("{\\r\\n}", "\r\n"),
                TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
                TextAlignment = TextAlignment.Center,
                IsMoreLines = true
            };
            functionSceneBodyView.AddChidren(noScenceTip);
        }
    }
}