BruceLee
2019-09-24 a9f88790c31c8b61d9b90241c4df258a980f1c00
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
using System;
using System.Collections.Generic;
using System.Globalization;
using Shared.Common;
 
namespace Shared.Phone.Device.CommonForm
{
    public class DeviceDetailInfo : FrameLayout
    {
        public List<string> RoomNameList;
        public string BelongZoneStr;
        public Action action;
        public override void RemoveFromParent()
        {
            action();
            base.RemoveFromParent();
        }
        public DeviceDetailInfo()
        {
            BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
        }
        public void Show(DeviceUI device, Common.Room room)
        {
            RoomNameList = new List<string> { };
            RoomNameList = Common.Room.CurrentRoom.GetRoomListNameByDevice(device.CommonDevice);
            #region topview
            var topBGView = new FrameLayout()
            {
                Height = Application.GetRealHeight(CommonPage.Navigation_Height),
                BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor
            };
            AddChidren(topBGView);
            var 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,
                TextID = R.MyInternationalizationString.ChangeDeviceInfo,
                TextSize = 20,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                Width = Application.GetRealWidth(CommonPage.AppRealWidth - 500),
                Gravity = Gravity.CenterHorizontal
            };
            topView.AddChidren(title);
 
            var back = new BackButton() { };
            topView.AddChidren(back);
            back.MouseUpEventHandler += (sender, e) =>
            {
                this.RemoveFromParent();
            };
            #endregion
 
            #region midFL
            var midFL = new FrameLayout()
            {
                Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
                Y = topView.Bottom,
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
            };
            this.AddChidren(midFL);
            var r = new R.MyInternationalizationString();
            object t;
            try
            {
                t = r.GetType().InvokeMember(device.CommonDevice.Type.ToString(), System.Reflection.BindingFlags.GetField, null, r, null);
            }
            catch
            {
                t = 11070;
            }
            var deviceIMG = new Button()
            {
                Y = Application.GetRealHeight(30),
                Width = Application.GetMinRealAverage(320),
                Height = Application.GetMinRealAverage(320),
                UnSelectedImagePath = device.IconPath,
                SelectedImagePath = device.OnlineIconPath,
                IsSelected=device.CommonDevice.IsOnline==1,
                Gravity = Gravity.CenterHorizontal
            };
            midFL.AddChidren(deviceIMG);
            var deviceTypeName = new Button()
            {
                Y = deviceIMG.Bottom,
                Width = Application.GetRealWidth(900),
                Height = Application.GetRealHeight(100),
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextID = (int)t,
                Gravity = Gravity.CenterHorizontal
            };
            midFL.AddChidren(deviceTypeName);
 
            var deviceNameFL = new FrameLayout()
            {
                Y = deviceTypeName.Bottom,
                Height = Application.GetRealHeight(170),
            };
            midFL.AddChidren(deviceNameFL);
            var deviceNameTip = new Button()
            {
                X = Application.GetRealWidth(50),
                Height = Application.GetRealHeight(70),
                Width = Application.GetRealWidth(900),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 12,
                TextColor = ZigbeeColor.Current.GXCButtonTipColor,
                TextID = R.MyInternationalizationString.DeviceName,
            };
            deviceNameFL.AddChidren(deviceNameTip);
            var deviceName = new EditText()
            {
                X = Application.GetRealWidth(50),
                Y = deviceNameTip.Bottom,
                Height = Application.GetRealHeight(100) - 1,
                Width = Application.GetRealWidth(900),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 20,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                Text = device.CommonDevice.DeviceEpointName,
            };
            deviceNameFL.AddChidren(deviceName);
            var deviceNameLine = new Button()
            {
                Y = deviceName.Bottom,
                Height = 1,
                BackgroundColor = ZigbeeColor.Current.GXCLineColor
            };
            deviceNameFL.AddChidren(deviceNameLine);
 
            var zoneFL = new FrameLayout()
            {
                Y = deviceNameFL.Bottom,
                Height = Application.GetRealHeight(170),
            };
            midFL.AddChidren(zoneFL);
            var zoneTip = new Button()
            {
                X = Application.GetRealWidth(50),
                Height = Application.GetRealHeight(70),
                Width = Application.GetRealWidth(900),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 12,
                TextColor = ZigbeeColor.Current.GXCButtonTipColor,
                TextID = R.MyInternationalizationString.BelongZone,
            };
            zoneFL.AddChidren(zoneTip);
            var zone = new Button()
            {
                X = Application.GetRealWidth(50),
                Y = deviceNameTip.Bottom,
                Height = Application.GetRealHeight(100) - 1,
                Width = Application.GetRealWidth(900),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 20,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                Text = Common.Room.CurrentRoom.GetRoomName(RoomNameList),
            };
            zoneFL.AddChidren(zone);
            var zoneRight = new 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
            };
            zoneFL.AddChidren(zoneRight);
            var zoneLine = new Button()
            {
                Y = zone.Bottom,
                Height = 1,
                BackgroundColor = ZigbeeColor.Current.GXCLineColor
            };
            zoneFL.AddChidren(zoneLine);
 
            var modelFL = new FrameLayout()
            {
                Y = zoneFL.Bottom,
                Height = Application.GetRealHeight(170),
            };
            midFL.AddChidren(modelFL);
            var modelTip = new Button()
            {
                X = Application.GetRealWidth(50),
                Height = Application.GetRealHeight(70),
                Width = Application.GetRealWidth(900),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 12,
                TextColor = ZigbeeColor.Current.GXCButtonTipColor,
                TextID = R.MyInternationalizationString.BelongModel,
            };
            modelFL.AddChidren(modelTip);
            var model = new Button()
            {
                X = Application.GetRealWidth(50),
                Y = deviceNameTip.Bottom,
                Height = Application.GetRealHeight(100) - 1,
                Width = Application.GetRealWidth(900),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 20,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                Text = device.CommonDevice.DeviceName==""?Language.StringByID(R.MyInternationalizationString.UNKnown):device.CommonDevice.DeviceName
            };
            modelFL.AddChidren(model);
            var modelLine = new Button()
            {
                Y = model.Bottom,
                Height = 1,
                BackgroundColor = ZigbeeColor.Current.GXCLineColor
            };
            modelFL.AddChidren(modelLine);
 
            var sharedFL = new FrameLayout()
            {
                Y = modelFL.Bottom,
                Height = Application.GetRealHeight(170),
            };
            //midFL.AddChidren(sharedFL);
            var sharedBtn = new Button()
            {
                X = Application.GetRealWidth(50),
                Y = Application.GetRealHeight(70),
                Height = Application.GetRealHeight(100) - 1,
                Width = Application.GetRealWidth(500),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 20,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextID = R.MyInternationalizationString.Shared
            };
            sharedFL.AddChidren(sharedBtn);
 
            var sharedRight = new Button()
            {
                X = Application.GetRealWidth(1080 - 150),
                Width = Application.GetMinRealAverage(110),
                Height = Application.GetMinRealAverage(110),
                UnSelectedImagePath = "Item/Next.png",
                Gravity = Gravity.CenterVertical
            };
            sharedFL.AddChidren(sharedRight);
 
            var sharedNum = new Button()
            {
                X = Application.GetRealWidth(1080 - 150 - 110),
                Width = Application.GetRealWidth(110),
                Height = Application.GetRealHeight(110),
                TextAlignment = TextAlignment.CenterRight,
                TextSize = 12,
                TextColor = ZigbeeColor.Current.GXCButtonTipColor,
                Text = "1人",
                Gravity = Gravity.CenterVertical
            };
            sharedFL.AddChidren(sharedNum);
 
            var sharedLine = new Button()
            {
                Y = sharedBtn.Bottom,
                Height = 1,
                BackgroundColor = ZigbeeColor.Current.GXCLineColor
            };
            sharedFL.AddChidren(sharedLine);
 
            var confirmBtn = new CommonForm.CompleteButton()
            {
            };
            AddChidren(confirmBtn);
 
            confirmBtn.MouseUpEventHandler += async (sender, e) =>
            {
                if (device.CommonDevice == null)
                {
                    CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
                    return;
                }
                var result = await Shared.Common.LocalDevice.Current.ReName(device.CommonDevice, deviceName.Text.Trim());
                if (result)
                {
                    var alertSuccess = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.Success), Language.StringByID(R.MyInternationalizationString.Confrim));
                    alertSuccess.Show();
                    alertSuccess.ResultEventHandler += (senderSuccess, eSuccess) =>
                    {
                        //改图片
                        device.CommonDevice.IconPath = deviceIMG.UnSelectedImagePath;
                        device.CommonDevice.IsCustomizeImage = true;
                        device.CommonDevice.ReSave();
                        //改房间
                        Shared.Common.Room.CurrentRoom.ChangedRoom(device.CommonDevice, RoomNameList);
                        RemoveFromParent();
                    };
                }
                else
                {
                    return;
                    //CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
                }
            };
            #endregion
 
            #region event
            EventHandler<MouseEventArgs> selectZoneEvent = (sender, e) =>
            {
                UserCenter.SelectRoomForm selectedRoom = new UserCenter.SelectRoomForm();
                selectedRoom.AddForm(selectedRoom, RoomNameList);
                selectedRoom.ActionSelectRoom += ((rList) =>
                {
                    RoomNameList = rList;
                    zone.Text = Shared.Common.Room.CurrentRoom.GetRoomName(RoomNameList);
                });
            };
            zoneRight.MouseUpEventHandler += selectZoneEvent;
            zoneFL.MouseUpEventHandler += selectZoneEvent;
            zone.MouseUpEventHandler += selectZoneEvent;
 
            EventHandler<MouseEventArgs> selectDeviceIconEvent = (sender, e) =>
             {
                 var localPic = new DeviceIconSelectedIMGByLocal();
                 UserView.HomePage.Instance.AddChidren(localPic);
                 UserView.HomePage.Instance.PageIndex += 1;
                 localPic.Show();
                 localPic.action = (unSelectedImagePath,selectedImagePath) =>
                 {
                     deviceIMG.UnSelectedImagePath = unSelectedImagePath;
                     deviceIMG.SelectedImagePath = selectedImagePath;
                 };
             };
            deviceIMG.MouseUpEventHandler += selectDeviceIconEvent;
 
            #endregion
        }
    }
}