黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.Safety
{
    /// <summary>
    /// 灯光类的安防报警设置界面
    /// </summary>
    public class AlarmTargetStatuSelectLightForm : DialogCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 结束选择的事件(key:全部状态的翻译文本)
        /// </summary>
        public Action<string, List<Safeguard.TaskListInfo>> FinishSelectEvent = null;
        /// <summary>
        /// 动作信息  1 开关/ 3亮度调节
        /// </summary>
        private Dictionary<int, Safeguard.TaskListInfo> dicTaskinfo = new Dictionary<int, Safeguard.TaskListInfo>();
        /// <summary>
        /// 进度条最大值
        /// </summary>
        private int MaxValue = 254;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="device"></param>
        /// <param name="i_listTaskInfo"></param>
        public void ShowForm(CommonDevice device, List<Safeguard.TaskListInfo> i_listTaskInfo)
        {
            if (i_listTaskInfo != null)
            {
                foreach (var data in i_listTaskInfo)
                {
                    //以防万一,剔除不合法数据
                    if (data.TaskType == 1 || data.TaskType == 3)
                    {
                        dicTaskinfo[data.TaskType] = data;
                    }
                }
            }
 
            //初始化中部信息
            this.InitMiddleFrame(device);
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame(CommonDevice device)
        {
            //弧度的圆的一半的高度(固定)
            int halfRoundHeigth = Application.GetRealHeight(116) / 2;
 
            //搞一个透明的框
            var frameTransparent = new FrameLayout();
            frameTransparent.Y = Application.GetRealHeight(1169);
            frameTransparent.Height = Application.GetRealHeight(900);//高度就是要它超过,随便搞的
            frameTransparent.BackgroundColor = UserCenterColor.Current.Transparent;
            bodyFrameLayout.AddChidren(frameTransparent);
 
            //瞎搞的一个白框,用来挡住头部半弧度
            var frameBack = new FrameLayout();
            frameBack.Y = halfRoundHeigth;
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            frameBack.Height = Application.GetRealHeight(300);
            frameTransparent.AddChidren(frameBack);
 
            //弧度的圆
            var rowRound = new FrameLayout();
            rowRound.Width = bodyFrameLayout.Width;
            rowRound.Height = halfRoundHeigth * 2;
            rowRound.BackgroundColor = UserCenterColor.Current.White;
            rowRound.Radius = (uint)halfRoundHeigth;
            frameTransparent.AddChidren(rowRound);
 
            //头部信息
            var btnTitle = new NormalViewControl(frameTransparent.Width, Application.GetRealHeight(70), false);
            btnTitle.Y = Application.GetRealHeight(28);
            btnTitle.Text = HdlDeviceCommonLogic.Current.GetDeviceEpointName(device);
            btnTitle.TextColor = UserCenterColor.Current.TextColor4;
            btnTitle.TextSize = 16;
            btnTitle.TextAlignment = TextAlignment.Center;
            rowRound.AddChidren(btnTitle);
 
            //取消
            var btnCancel = new NormalViewControl(200, 60, true);
            btnCancel.X = Application.GetRealWidth(81);
            btnCancel.Y = Application.GetRealHeight(38);
            btnCancel.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnCancel.TextID = R.MyInternationalizationString.uCancel;
            rowRound.AddChidren(btnCancel);
            btnCancel.ButtonClickEvent += (sender, e) =>
            {
                this.CloseForm();
            };
 
            //完成
            var btnFinish = new NormalViewControl(200, 60, true);
            btnFinish.X = Application.GetRealWidth(800);
            btnFinish.Y = Application.GetRealHeight(38);
            btnFinish.TextAlignment = TextAlignment.CenterRight;
            btnFinish.TextColor = 0xfffb744a;
            btnFinish.TextID = R.MyInternationalizationString.uFinish;
            rowRound.AddChidren(btnFinish);
 
            //线
            var btnLine1 = new NormalViewControl(frameTransparent.Width, HdlControlResourse.BottomLineHeight, false);
            btnLine1.Y = Application.GetRealHeight(138);
            btnLine1.BackgroundColor = UserCenterColor.Current.ButtomLine;
            frameTransparent.AddChidren(btnLine1);
 
            //明细列表的桌布,白色背景
            var detailBackFrame = new FrameLayout();
            detailBackFrame.Y = btnLine1.Bottom;
            detailBackFrame.Height = Application.GetRealHeight(700);//随便定的
            detailBackFrame.BackgroundColor = UserCenterColor.Current.White;
            frameTransparent.AddChidren(detailBackFrame);
 
            //百分比
            var btnPersent = new NormalViewControl(150, 50, true);
            btnPersent.Y = Application.GetRealHeight(196);
            btnPersent.Gravity = Gravity.CenterHorizontal;
            btnPersent.TextAlignment = TextAlignment.Center;
            btnPersent.TextColor = UserCenterColor.Current.TextGrayColor2;
            btnPersent.TextSize = 12;
            detailBackFrame.AddChidren(btnPersent);
            if (dicTaskinfo.ContainsKey(3) == true)
            {
                btnPersent.Text = ((int)(dicTaskinfo[3].Data1 * 1.0 / MaxValue * 100)) + "%";
            }
 
            //进度条
            var seekBar = new SeekBarControl(919);
            seekBar.Y = Application.GetRealHeight(268);
            seekBar.ProgressBarColor = 0xfffdb500;
            seekBar.MaxValue = this.MaxValue;
            seekBar.Enable = false;
            if (dicTaskinfo.ContainsKey(3) == true)
            {
                //3:亮度调节
                seekBar.Progress = dicTaskinfo[3].Data1;
            }
            detailBackFrame.AddChidren(seekBar);
            seekBar.ProgressChangedEvent += (div, value) =>
            {
                btnPersent.Text = ((int)(value * 1.0 / MaxValue * 100)) + "%";
            };
 
            //线
            var btnLine2 = new NormalViewControl(Application.GetRealWidth(919), HdlControlResourse.BottomLineHeight, false);
            btnLine2.Y = Application.GetRealHeight(417);
            btnLine2.Gravity = Gravity.CenterHorizontal;
            btnLine2.BackgroundColor = UserCenterColor.Current.ButtomLine;
            detailBackFrame.AddChidren(btnLine2);
 
            //开
            var rowOpen = new FrameRowControl();
            rowOpen.Y = Application.GetRealHeight(69);
            rowOpen.LeftOffset = Application.GetRealWidth(81) - HdlControlResourse.XXLeft;
            rowOpen.RightOffset = HdlControlResourse.XXLeft - Application.GetRealWidth(81);
            detailBackFrame.AddChidren(rowOpen);
            var btnOpen = rowOpen.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uSimpleOpen), 400);
            btnOpen.TextColor = UserCenterColor.Current.TextGrayColor3;
            var btnOpenSelect = rowOpen.AddMostRightEmptyIcon(58, 58);
            btnOpenSelect.UnSelectedImagePath = "Item/ItemSelected.png";
            btnOpenSelect.Visible = false;
 
            //关
            var rowClose = new FrameRowControl();
            rowClose.Y = btnLine2.Bottom + Application.GetRealHeight(12);
            rowClose.LeftOffset = Application.GetRealWidth(81) - HdlControlResourse.XXLeft;
            rowClose.RightOffset = HdlControlResourse.XXLeft - Application.GetRealWidth(81);
            detailBackFrame.AddChidren(rowClose);
            var btnClose = rowClose.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uSimpleClose), 400);
            btnClose.TextColor = UserCenterColor.Current.TextGrayColor3;
            var btnCloseSelect = rowClose.AddMostRightEmptyIcon(58, 58);
            btnCloseSelect.UnSelectedImagePath = "Item/ItemSelected.png";
            btnCloseSelect.Visible = false;
 
            //点击开
            rowOpen.ButtonClickEvent += (sender, e) =>
            {
                if (btnOpenSelect.Visible == true)
                {
                    //取消,开 不可用
                    btnOpenSelect.Visible = false;
                    btnOpen.TextColor = UserCenterColor.Current.TextGrayColor3;
                    seekBar.Enable = false;
 
                    dicTaskinfo.Remove(1);
                }
                else
                {
                    //选择图标切换
                    btnOpenSelect.Visible = true;
                    btnCloseSelect.Visible = false;
 
                    //开 可用
                    btnOpen.TextColor = UserCenterColor.Current.TextColor1;
                    seekBar.Enable = true;
                    if (seekBar.Progress == 0)
                    {
                        seekBar.Progress = MaxValue;
                        btnPersent.Text = "100%";
                    }
 
                    //关 不可用
                    btnClose.TextColor = UserCenterColor.Current.TextGrayColor3;
 
                    dicTaskinfo[1] = new Safeguard.TaskListInfo();
                    dicTaskinfo[1].TaskType = 1;
                    dicTaskinfo[1].Data1 = 1;
                }
            };
            //点击关
            rowClose.ButtonClickEvent += (sender, e) =>
            {
                if (btnCloseSelect.Visible == true)
                {
                    //取消,关 不可用
                    btnCloseSelect.Visible = false;
                    btnClose.TextColor = UserCenterColor.Current.TextGrayColor3;
 
                    dicTaskinfo.Remove(1);
                }
                else
                {
                    //选择图标切换
                    btnCloseSelect.Visible = true;
                    btnOpenSelect.Visible = false;
 
                    //关 可用
                    btnClose.TextColor = UserCenterColor.Current.TextColor1;
 
                    //开 不可用
                    btnOpen.TextColor = UserCenterColor.Current.TextGrayColor3;
                    seekBar.Enable = false;
 
                    dicTaskinfo[1] = new Safeguard.TaskListInfo();
                    dicTaskinfo[1].TaskType = 1;
                    dicTaskinfo[1].Data1 = 0;
                }
            };
 
            //设置开的默认值
            if (dicTaskinfo.ContainsKey(1) == true && dicTaskinfo[1].Data1 == 1)
            {
                rowOpen.ButtonClickEvent?.Invoke(null, null);
            }
            //设置关的默认值
            if (dicTaskinfo.ContainsKey(1) == true && dicTaskinfo[1].Data1 == 0)
            {
                rowClose.ButtonClickEvent?.Invoke(null, null);
            }
 
            //完成事件
            btnFinish.ButtonClickEvent += (sender, e) =>
            {
                if (btnOpenSelect.Visible == false || seekBar.Progress == 0)
                {
                    //移除百分比
                    dicTaskinfo.Remove(3);
                }
                else
                {
                    //百分比调节
                    dicTaskinfo[3] = new Safeguard.TaskListInfo();
                    dicTaskinfo[3].TaskType = 3;
                    dicTaskinfo[3].Data1 = seekBar.Progress;
                }
 
                var listData = new List<Safeguard.TaskListInfo>();
                foreach (var data in dicTaskinfo.Values)
                {
                    listData.Add(data);
                }
                dicTaskinfo = null;
 
                //获取状态的显示文本
                string statuText = HdlSafeguardLogic.Current.GetAdjustTargetStatuText(listData);
                this.FinishSelectEvent?.Invoke(statuText, listData);
 
                this.CloseForm();
            };
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            this.FinishSelectEvent = null;
            base.CloseFormBefore();
        }
 
        #endregion
    }
}