黄学彪
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
using System;
using System.Collections.Generic;
using Shared.Common;
 
namespace Shared.Phone.Device.CommonForm
{
    public class SelectTime : FrameLayoutBase
    {
        public Action<int> TimeAction;
 
        Button TempSelectBtn;
 
        Button TempTimeBtn;
 
        public int TempTime;
 
        /// <summary>
        /// Init
        /// </summary>
        public void Init()
        {
            var dialog = new FrameLayout()
            {
                BackgroundColor = ZigbeeColor.Current.GXCDailogBackGroundColor
            };
            AddChidren(dialog);
 
            dialog.MouseUpEventHandler += (sender, e) =>
            {
                RemoveFromParent();
            };
 
            var backgroundFL = new FrameLayout
            {
                Y = Application.GetRealHeight(596),
                Height = Application.GetRealHeight(1325),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
            };
            backgroundFL.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
            dialog.AddChidren(backgroundFL);
 
            var topView = new FrameLayout
            {
                Height = Application.GetRealHeight(138)
            };
            backgroundFL.AddChidren(topView);
 
            var cancle = new Button
            {
                X = Application.GetRealWidth(80),
                Width = Application.GetRealWidth(300),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                TextID = R.MyInternationalizationString.Cancel,
                TextSize = 14
            };
            topView.AddChidren(cancle);
 
            var title = new Button
            {
                Width = Application.GetRealWidth(300),
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor2,
                TextID = R.MyInternationalizationString.Delay,
                TextSize = 16
            };
            topView.AddChidren(title);
 
            var confrim = new Button
            {
                X = dialog.Width - Application.GetRealWidth(80 - 300),
                Width = Application.GetRealWidth(300),
                TextAlignment = TextAlignment.CenterRight,
                TextColor = ZigbeeColor.Current.GXCTextSelectedColor2,
                TextID = R.MyInternationalizationString.Complete,
                TextSize = 14
            };
            topView.AddChidren(confrim);
 
            var Line = new FrameLayout()
            {
                Y = topView.Height - 1,
                Height = 1,
                BackgroundColor = ZigbeeColor.Current.GXCGrayLineColor2
            };
            topView.AddChidren(Line);
 
            var timeLayout = new VerticalScrolViewLayout
            {
                Y = Application.GetRealHeight(207),
                Height = Application.GetRealHeight(703 + 127 * 2 + 12 + 12),
                ScrollEnabled = false,
                VerticalScrollBarEnabled = false,
            };
            backgroundFL.AddChidren(timeLayout);
 
            TempSelectBtn = new Button();
            TempTimeBtn = new Button();
 
 
            var notOpen = new Button
            {
                X = Application.GetRealWidth(80),
                Y = Application.GetRealHeight(1200),
                Width = Application.GetRealWidth(800),
                Height = Application.GetRealHeight(80),
                TextColor = ZigbeeColor.Current.GXCTextGrayColor4,
                TextID = R.MyInternationalizationString.NotOpen,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 14
            };
            backgroundFL.AddChidren(notOpen);
 
            cancle.MouseUpEventHandler += Close;
            confrim.MouseUpEventHandler += Confrim_MouseEvent;
            notOpen.MouseUpEventHandler += NotOpen_MouseEvent;
 
            var tList = new List<int>();
            tList.Add(15);
            tList.Add(30);
            tList.Add(60);
            tList.Add(60 * 5);
            tList.Add(60 * 15);
            tList.Add(60 * 30);
            tList.Add(60 * 60);
 
            foreach (var t in tList)
            {
                AddTime(timeLayout, t);
            }
        }
 
        /// <summary>
        /// AddTime
        /// </summary>
        /// <param name="verticalScrolView"></param>
        private void AddTime(VerticalScrolViewLayout verticalScrolView, int timess)
        {
            var row = new FrameLayout
            {
                Height = Application.GetRealHeight(127 + 12),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
            };
            verticalScrolView.AddChidren(row);
 
            var trow = new FrameLayout
            {
                Y = Application.GetRealHeight(12),
                Height = Application.GetRealHeight(127),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
            };
            row.AddChidren(trow);
 
            var timeBtn = new Button
            {
                X = Application.GetRealWidth(80),
                Width = Application.GetRealWidth(500),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = ZigbeeColor.Current.GXCTextGrayColor4,
                SelectedTextColor = ZigbeeColor.Current.GXCTextBlackColor,
                IsSelected = false,
                TextSize = 14
            };
            trow.AddChidren(timeBtn);
 
            var selectBtn = new Button
            {
                X = Application.GetRealWidth(942),
                Width = this.GetPictrueRealSize(60),
                Height = this.GetPictrueRealSize(60),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "Item/ItemSelected.png",
                Visible = false
            };
            trow.AddChidren(selectBtn);
 
            var Line = new FrameLayout()
            {
                Y = row.Height - 1,
                Width = Application.GetRealWidth(919),
                Height = 1,
                Gravity = Gravity.CenterHorizontal,
                BackgroundColor = Common.ZigbeeColor.Current.GXCGrayLineColor2
            };
            row.AddChidren(Line);
 
 
            EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
            {
                TempTimeBtn.IsSelected = false;
                TempSelectBtn.Visible = false;
 
                timeBtn.IsSelected = true;
                selectBtn.Visible = true;
 
                TempTimeBtn = timeBtn;
                TempSelectBtn = selectBtn;
 
                TempTime = timess;
            };
 
            timeBtn.MouseUpEventHandler += eventHandler;
            trow.MouseUpEventHandler += eventHandler;
 
            timeBtn.Text = this.GetTimeString(timess);
 
            if (timess == TempTime)
            {
                timeBtn.IsSelected = true;
                selectBtn.Visible = true;
                TempTimeBtn = timeBtn;
                TempSelectBtn = selectBtn;
            }
 
        }
 
        /// <summary>
        /// 获取场景延时字符串
        /// </summary>
        /// <param name="second"></param>
        /// <returns></returns>
        private string GetTimeString(int second)
        {
            if (second == 0)
            {
                return null;
            }
            string timeStr = string.Empty;
            int hour = second / 3600;
            int minu = second % 3600 / 60;
            int sec = second % 60;
            if (hour > 0)
            {
                timeStr += $"{hour}{Language.StringByID(R.MyInternationalizationString.Hour)}";
                if (minu > 0)
                {
                    timeStr += $"{minu}{Language.StringByID(R.MyInternationalizationString.Minute)}";
                }
                if (sec > 0)
                {
                    timeStr += $"{sec}{Language.StringByID(R.MyInternationalizationString.Second)}";
                }
                return timeStr;
            }
            else if (minu > 0)
            {
                timeStr += $"{minu}{Language.StringByID(R.MyInternationalizationString.Minute)}";
                if (sec > 0)
                {
                    timeStr += $"{sec}{Language.StringByID(R.MyInternationalizationString.Second)}";
                }
                return timeStr;
            }
            else
            {
                return $"{sec}{Language.StringByID(R.MyInternationalizationString.Second)}";
            }
        }
 
        /// <summary>
        /// Close
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        private void Close(object sender, MouseEventArgs mouseEventArgs)
        {
            RemoveFromParent();
        }
 
        /// <summary>
        /// Confrim_MouseEvent
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        private void Confrim_MouseEvent(object sender, MouseEventArgs mouseEventArgs)
        {
            TimeAction.Invoke(TempTime);
            RemoveFromParent();
        }
 
        /// <summary>
        /// NotOpen_MouseEvent
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        private void NotOpen_MouseEvent(object sender, MouseEventArgs mouseEventArgs)
        {
            TimeAction.Invoke(0);
            RemoveFromParent();
        }
 
    }
}