黄学彪
2019-12-09 163777d8a2cb7cfa469f54a7042528870ebc10a3
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
using System;
using System.Collections.Generic;
using Shared;
using Shared.Common;
using Shared.Phone;
using Shared.R;
using ZigBee.Device;
 
 
 
namespace Shared.Phone.Device.Logic
{
    public class DelayTime : FrameLayout
    {
        public DelayTime()
        {
            Tag = "Logic";
        }
 
        public void Show(int isInt = 0, bool edit = false)
        {
 
            #region  最上面的布局代码
            var topRowLayout = new RowLayout
            {
                BackgroundColor = ZigbeeColor.Current.LogicTopBackgroundColor,
                Height = Application.GetRealHeight(184),
                LineColor = ZigbeeColor.Current.LogicRowLayoutTopLineColor,
            };
            this.AddChidren(topRowLayout);
 
            var titleName = new Button
            {
                TextSize = 17,
                TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                TextAlignment = TextAlignment.CenterLeft,
                X = Application.GetRealWidth(176),
                Width = Application.GetRealWidth(400),
                Height = Application.GetRealHeight(69),
                Y = Application.GetRealHeight(92),
                TextID = MyInternationalizationString.adddelay,
            };
            topRowLayout.AddChidren(titleName);
 
            var clickBtn = new Button
            {
                Width = Application.GetRealWidth(81 + 51),
                Height = Application.GetRealHeight(58 + 40),
                Y = Application.GetRealHeight(98 - 40),
            };
            topRowLayout.AddChidren(clickBtn);
            clickBtn.MouseDownEventHandler += (sender, e) =>
            {
                RemoveFromParent();
            };
 
            var back = new Button
            {
                Width = Application.GetRealWidth(30),
                Height = Application.GetRealHeight(51),
                X = Application.GetRealWidth(81),
                Y = Application.GetRealHeight(98),
                //Gravity = Gravity.CenterVertical;
                UnSelectedImagePath = "ZigeeLogic/back.png",
            };
            topRowLayout.AddChidren(back);
            back.MouseDownEventHandler += (sender, e) =>
            {
                RemoveFromParent();
            };
            #endregion
 
            var middle = new FrameLayout
            {
                Y = topRowLayout.Bottom,
                Height = Application.GetRealHeight(1920 - 184),
                BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
            };
            this.AddChidren(middle);
 
            var blancolor = new FrameLayout
            {
                Width = Application.GetMinRealAverage(200),
                Height = Application.GetMinRealAverage(200),
                Y = Application.GetRealHeight(130),
                BackgroundColor = 0xFFFFFFFF,
                Radius = (uint)Application.GetMinRealAverage(100),
                X = Application.GetRealWidth(440),
            };
            middle.AddChidren(blancolor);
            var color = new FrameLayout
            {
                Width = blancolor.Width - Application.GetMinRealAverage(24),
                Height = blancolor.Height - Application.GetMinRealAverage(24),
                Y = Application.GetRealHeight(12),
                BackgroundColor = 0xFFFEF1ED,
                Radius = (uint)Application.GetMinRealAverage(86),
                X = Application.GetRealWidth(12),
            };
            blancolor.AddChidren(color);
            var btnicon = new Button
            {
                X = Application.GetRealWidth(48),
                Width = Application.GetRealWidth(80),
                Height = Application.GetRealHeight(80),
                Y = Application.GetRealHeight(48),
                UnSelectedImagePath = "ZigeeLogic/delay.png",
            };
            color.AddChidren(btnicon);
            var titleText = new Button
            {
                Width = Application.GetMinRealAverage(480),
                Height = Application.GetMinRealAverage(60),
                X = Application.GetRealWidth(300),
                Y = blancolor.Bottom + Application.GetRealHeight(50),
                TextID = MyInternationalizationString.createtimetext,
                TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                TextSize = 15,
 
            };
            middle.AddChidren(titleText);
 
            var PickerViewfra = new FrameLayout
            {
                Y = titleText.Bottom + Application.GetRealHeight(250),
                Height = Application.GetRealHeight(1046),
                BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor,
            };
            middle.AddChidren(PickerViewfra);
            PickerViewfra.SetCornerWithSameRadius(Application.GetRealHeight(50), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
 
            var mUIPickerView = new UIPickerView
            {
                Y = Application.GetRealHeight(50),
                Height = Application.GetRealHeight(600),
            };
            PickerViewfra.AddChidren(mUIPickerView);
 
            var mList1 = new List<string>();
            var mList2 = new List<string>();
            for (int i = 0; i < 61; i++)
            {
                if (i < 10)
                {
                    var a = "0" + i.ToString();
                    mList1.Add(a + " " + Language.StringByID(MyInternationalizationString.minute));
                    mList2.Add(a + " " + Language.StringByID(MyInternationalizationString.second));
                }
                else
                {
                    mList1.Add(i.ToString() + " " + Language.StringByID(MyInternationalizationString.minute));
                    mList2.Add(i.ToString() + " " + Language.StringByID(MyInternationalizationString.second));
                }
 
            }
            mUIPickerView.setNPicker(mList1, mList2, new List<string>());
            ///默认状态
            mUIPickerView.setCurrentItems(0, 5, 0);
            int timevalue = 5;
            int value = 0;
            if (edit)
            {
 
                timevalue = int.Parse(Common.Logic.CurrentLogic.Actions[isInt]["DelayTime"].ToString());
                if (timevalue > 3600)
                {
                    //更新最新状态
                    mUIPickerView.setCurrentItems(60, timevalue - 3600, 0);
                }
                else
                {
 
                    var minutevalue1 = timevalue / 60;
                    var secondvalue1 = timevalue % 60;
                    //更新最新状态
                    mUIPickerView.setCurrentItems(minutevalue1, secondvalue1, 0);
                }
 
                value = timevalue;
            }
            string selectde = "";
            mUIPickerView.OnSelectChangeEvent += (s1, s2, s3) =>
            {
                var minutevalue = int.Parse(mList1[s1].Split(' ')[0]);
                var secondvalue = int.Parse(mList2[s2].Split(' ')[0]);
                timevalue = minutevalue * 60 + secondvalue;
                selectde = "yes";
 
            };
 
            var btnsave = new Button
            {
                Y = PickerViewfra.Height - Application.GetRealHeight(260),
                X = Application.GetRealWidth(85),
                Height = Application.GetRealHeight(130),
                Width = Application.GetRealWidth(910),
                Radius = (uint)Application.GetRealHeight(60),
                BackgroundColor = ZigbeeColor.Current.LogicBtnSaveBackgroundColor,
                TextID = MyInternationalizationString.Save,
                TextColor = ZigbeeColor.Current.LogicBtnSaveTextColor,
            };
            PickerViewfra.AddChidren(btnsave);
 
            ///完成点击事件
            btnsave.MouseUpEventHandler += (sender, e) =>
            {
                if (timevalue == 0)
                {
                    return;
                }
                if (selectde != "" || timevalue == 5)
                {
                    Dictionary<string, object> actionsInfo = new Dictionary<string, object>();
                    actionsInfo.Add("LinkType", 7);
                    actionsInfo.Add("DelayTime", timevalue);
                    if (edit)
                    {
                        Common.Logic.CurrentLogic.Actions.RemoveAt(isInt);
                        Common.Logic.CurrentLogic.Actions.Insert(isInt, actionsInfo);
                    }
                    else
                    {
                        Common.Logic.CurrentLogic.Actions.Add(actionsInfo);
 
                    }
                }
                else
                {
                    if (!edit)
                    {
                        var alert = new Alert(Language.StringByID(MyInternationalizationString.Prompt),
                                              Language.StringByID(MyInternationalizationString.selectdevicestatuscondition),
                                              Language.StringByID(MyInternationalizationString.complete));
                        alert.Show();
                        return;
                    }
                }
                var logicCommunalPage = new LogicCommunalPage { };
                UserView.HomePage.Instance.AddChidren(logicCommunalPage);
                UserView.HomePage.Instance.PageIndex += 1;
                logicCommunalPage.Show(() => { });
            };
 
        }
    }
}