wxr
2021-07-01 b409ece9569247d7e7b44fc15e8a02556ca05a57
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
using System;
using Shared;
using System.Collections.Generic;
namespace HDL_ON.UI.UI2.Intelligence.Automation.LogicView
{
    public class TimeView
    {
        /// <summary>
        /// 主控件
        /// </summary>
        public FrameLayout frameLayout = new FrameLayout
        {
            Y = Application.GetRealHeight(350),
            Height = Application.GetRealHeight(297),
            Width = Application.GetRealWidth(343),
            X = Application.GetRealWidth(16),
            BackgroundColor = CSS.CSS_Color.view,
            Radius =(uint)Application.GetRealHeight(12),
        };
        /// <summary>
        /// 时间控件UIPickerView 
        /// </summary>
        public UIPickerView mUIPickerView = new UIPickerView
        {
            X= Application.GetRealWidth(12),
            Height = Application.GetRealHeight(297),
            Width = Application.GetRealWidth(343-12*2),
            BackgroundColor =CSS.CSS_Color.viewTranslucence,
            Radius = (uint)Application.GetRealHeight(12),
 
        };
        /// <summary>
        /// 取消Btn
        /// </summary>
        public Button btnCancel = new Button
        {
            TextID = StringId.cancelSelected,
            TextSize = TextSize.text14,
            TextColor = CSS.CSS_Color.textCancelColor,
            Width = Application.GetRealWidth(52),
            Height = Application.GetRealHeight(32),
            Y = Application.GetRealHeight(6),
            X = Application.GetRealWidth(8),
            
        };
        /// <summary>
        /// 确定Btn
        /// </summary>
        public Button btnConfirm = new Button
        {
            TextID = StringId.confirmSelected,
            TextSize = TextSize.text14,
            TextColor = CSS.CSS_Color.textConfirmColor,
            Width = Application.GetRealWidth(52),
            Height = Application.GetRealHeight(32),
            X = Application.GetRealWidth(283),
            Y = Application.GetRealHeight(6),
        };
        /// <summary>
        ///  线
        /// </summary>
        public Button btnLine = new Button
        {
            BackgroundColor = CSS.CSS_Color.viewLine,
            Width = Application.GetRealWidth(343),
            Height = 1,
            Y = Application.GetRealWidth(44),
           
        };
        /// <summary>
        /// 时间View的方法
        /// </summary>
        /// <returns></returns>
        public void FLayoutView(FrameLayout fLayout)
        {
           
            fLayout.AddChidren(frameLayout);
            frameLayout.AddChidren(mUIPickerView);
            frameLayout.AddChidren(btnCancel);
            frameLayout.AddChidren(btnConfirm);
            frameLayout.AddChidren(btnLine);
        }
        /// <summary>
        /// 选中时间的方法
        /// </summary>
        /// <param name="fLayout">父控件</param>
        /// <param name="currState">之前状态值</param>
        /// <param name="action">返回时间值</param>
        public void TimePoint(FrameLayout fLayout, string currState, Action<string> action)
        {
            //取消点击事件
            btnCancel.MouseUpEventHandler += (sender, e1) =>
            {
                //移除fLayout界面
                fLayout.RemoveFromParent();
            };
            //加载数据界面的设置方法(列表互不联动)
            mUIPickerView.setNPicker(GethStringList(), GetmStringList(), null);
            var systemHour = DateTime.Now.Hour; //获取小时
            var systeMinute = DateTime.Now.Minute;//获取分钟
            int systemHourIndex = 0;
            int systeMinuteIndex = 0;
            for (int i = 0; i < GethIntList().Count; i++)
            {
                var currhour = GethIntList()[i];
                if (systemHour == currhour)
                {
                    systemHourIndex = i;
                    break;
                }
            }
            for (int i = 0; i < GetmIntList().Count; i++)
            {
                var currminute = GetmIntList()[i];
                if (systeMinute == currminute)
                {
                    systeMinuteIndex = i;
                    break;
                }
            }
 
            //默认初始选中状态
            mUIPickerView.setCurrentItems(systemHourIndex, systeMinuteIndex, 0);
            string currH = "";
            string currM = "";
            if (systemHour < 10)
            {
                currH = "0" + systemHour.ToString();
            }
            else
            {
                currH = systemHour.ToString();
            }
            if (systeMinute < 10)
            {
                currM = "0" + systeMinute.ToString();
            }
            else
            {
                currM = systeMinute.ToString();
            }
            //定义一个局部变量记录选中时间
            string timepoint = currH + ":" + currM;
            if (currState != "")
            {
                int hIndex = GetValueIndex(currState, 0, 1, GethIntList());
                int mIndex = GetValueIndex(currState, 1, 0, GetmIntList());
                //更新初始状态
                mUIPickerView.setCurrentItems(hIndex, mIndex, 0);
                timepoint = currState;
            }
 
            //选中时间回调方法,时间变化一次回调一次
            mUIPickerView.OnSelectChangeEvent += (index1, index2, index3) =>
            {
                string hour = GethStringList()[index1].Split(' ')[0];
                string minuet = GetmStringList()[index2].Split(' ')[0];
                timepoint = hour + ":" + minuet;
            };
            //确定点击事件
            btnConfirm.MouseUpEventHandler += (sender, e3) =>
            {
                action(timepoint);
                //移除fLayout界面
                fLayout.RemoveFromParent();
 
            };
        }
        /// <summary>
        /// 获取1-24小时列表
        /// </summary>
        /// <returns></returns>
        public List<string> GethStringList()
        {
            //初始化列表
            var hList = new List<string>();
            for (int i = 0; i < 24; i++)
            {
                if (i < 10)
                {
                    var a = "0" + i.ToString();
                    //添加数据
                    hList.Add(a + " " + Language.StringByID(StringId.h));
                }
                else
                {
                    //添加数据
                    hList.Add(i.ToString() + " " + Language.StringByID(StringId.h));
                }
 
            }
            return hList;
 
 
        }
        /// <summary>
        /// 获取0-23小时列表
        /// </summary>
        /// <returns></returns>
        public List<string> GethStringList0()
        {
            //初始化列表
            var hList = new List<string>();
            for (int i = 0; i < 24; i++)
            {
                if (i < 10)
                {
                    var a = "0" + i.ToString();
                    //添加数据
                    hList.Add(a + " " + Language.StringByID(StringId.h));
                }
                else
                {
                    //添加数据
                    hList.Add(i.ToString() + " " + Language.StringByID(StringId.h));
                }
 
            }
            return hList;
 
 
        }
        /// <summary> 
        /// 获取60分钟列表
        /// </summary>
        /// <returns></returns>
        public List<string> GetmStringList()
        {
            //初始化列表
            var mList = new List<string>();
            for (int i = 0; i < 60; i++)
            {
                if (i < 10)
                {
                    var a = "0" + i.ToString();
                    //添加数据
                    mList.Add(a + " " + Language.StringByID(StringId.m));
                }
                else
                {
                    //添加数据
                    mList.Add(i.ToString() + " " + Language.StringByID(StringId.m));
                }
 
            }
 
            return mList;
        }
        /// <summary> 
        /// 获取60秒列表
        /// </summary>
        /// <returns></returns>
        public List<string> GetsStringList()
        {
            //初始化列表
            var mList = new List<string>();
            for (int i = 0; i < 60; i++)
            {
                if (i < 10)
                {
                    var a = "0" + i.ToString();
                    //添加数据
                    mList.Add(a + " " + Language.StringByID(StringId.s));
                }
                else
                {
                    //添加数据
                    mList.Add(i.ToString() + " " + Language.StringByID(StringId.s));
                }
 
            }
 
            return mList;
        }
 
        /// <summary>
        /// 获取023小时列表
        /// </summary>
        /// <returns></returns>
        public List<int> GethIntList()
        {
            //初始化列表
            var hList = new List<int>();
            for (int i = 0; i < 24; i++)
            {
                //添加数据
                hList.Add(i);
            }
            return hList;
 
 
        }
        
        /// <summary>
        /// 获取60分钟列表
        /// </summary>
        /// <returns></returns>
        public List<int> GetmIntList()
        {
            //初始化列表
            var mList = new List<int>();
            for (int i = 0; i < 60; i++)
            {
                //添加数据
                mList.Add(i);
            }
            return mList;
        }
       
        /// <summary>
        /// 获取时间值
        /// </summary>
        /// <param name="str">源数据</param>
        /// <param name="digit">返回源数据数组里面某个值索引</param>
        /// <param name="startIndex"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public int GetValueIndex(string str, int digit, int startIndex, List<int> list)
        {
            int index = 0;
            int value = 0;
            if (str.Contains(":"))
            {
                value = int.Parse(str.Split(':')[digit]);
            }
            for (int i = startIndex; i < list.Count; i++)
            {
                if (value == i)
                {
                    index = i;
                    break;
                }
            }
            return index;
        }
 
    }
}