JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
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
using System;
using System.Collections.Generic;
using Shared;
using Shared.SimpleControl;
using Shared.SimpleControl.R;
using SmartHome;
 
namespace SuperGateWay
{
    public class SelectedLogicState : FrameLayout
    {
        public SelectedLogicState ()
        {
            Tag = "Logic";
        }
        public bool IsDeviceEditor;
        public void Show (GateWay gateWay, Logic logic)
        {
            this.BackgroundColor = 0xFF1F1F1F;
            this.AddChidren (new Button {
                Height = Application.GetRealHeight (30),
            });
 
            var topFrameLayout = new FrameLayout {
                Height = Application.GetRealHeight (100),
                Y = Application.GetRealHeight (30),
            };
            AddChidren (topFrameLayout);
 
            var titleName = new Button {
                TextID = MyInternationalizationString.automation,
                TextSize = 17,
            };
            topFrameLayout.AddChidren (titleName);
 
            var back = new Button {
                Width = Application.GetRealWidth (82),
                Height = Application.GetRealHeight (89),
                X = Application.GetRealWidth (10),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "MusicIcon/HomepageBack.png",
            };
            topFrameLayout.AddChidren (back);
            back.MouseDownEventHandler += (sender, e) => {
                RemoveFromParent ();
                IsDeviceEditor = false;
            };
 
            var tetleframeLayout = new FrameLayout {
                Y = topFrameLayout.Bottom,
                Height = Application.GetRealHeight (100),
                BackgroundColor = 0xff0f0f0f,
            };
            AddChidren (tetleframeLayout);
 
            var tetlebtn = new Button {
                Width = Application.GetRealWidth (400),
                TextID = MyInternationalizationString.selectsavedautomationstate,
                //Text = "请选择已保存自动化",
                TextSize = 16,
                TextAlignment = TextAlignment.CenterLeft,
                X = Application.GetRealWidth (40),
            };
            tetleframeLayout.AddChidren (tetlebtn);
 
            var middle = new VerticalScrolViewLayout ();
            middle.Y = tetleframeLayout.Bottom;
            middle.Height = Application.GetRealHeight (Application.DesignHeight - 130 - 100 - 80);
            middle.BackgroundColor = 0xff2F2F2F;
            this.AddChidren (middle);
 
 
            Output outputifon = new Output ();
            Dictionary<string, object> dictionary = new Dictionary<string, object> ();
            outputifon.objects.Add (dictionary);
            dictionary.Add ("sid", logic.sid);
 
            var openRowLayout = new RowLayout {
                Height = Application.GetRealHeight (100),
            };
            middle.AddChidren (openRowLayout);
 
            var btnlogicopen = new Button {
                Width = Application.GetRealWidth (200),
                TextID = MyInternationalizationString.open1,
                TextAlignment = TextAlignment.CenterLeft,
                X = Application.GetRealWidth (40),
            };
            openRowLayout.AddChidren (btnlogicopen);
 
            string IsselectedLogic = null;
            var disableRowLayout = new RowLayout {
                Height = Application.GetRealHeight (100),
            };
            middle.AddChidren (disableRowLayout);
 
            var btnlogicdisable = new Button {
                Width = Application.GetRealWidth (200),
                TextID = MyInternationalizationString.disable,
                TextAlignment = TextAlignment.CenterLeft,
                X = Application.GetRealWidth (40),
            };
            disableRowLayout.AddChidren (btnlogicdisable);
 
            ///开启点击事件
            EventHandler<MouseEventArgs> copenclick = (seder, e) => {
                openRowLayout.BackgroundColor = 0xfffe5e00;
                disableRowLayout.BackgroundColor = 0x00000000;
                IsselectedLogic = "true";
                if (dictionary.ContainsKey ("value")) {
                    dictionary.Remove ("value");
                }
                dictionary.Add ("value", 1);
            };
            openRowLayout.MouseUpEventHandler += copenclick;
            btnlogicopen.MouseUpEventHandler += copenclick;
 
            ///禁止点击事件
            EventHandler<MouseEventArgs> disableclick = (seder, e) => {
                openRowLayout.BackgroundColor = 0x00000000;
                disableRowLayout.BackgroundColor = 0xfffe5e00;
                IsselectedLogic = "false";
                if (dictionary.ContainsKey ("value")) {
                    dictionary.Remove ("value");
                }
                dictionary.Add ("value", 0);
            };
            disableRowLayout.MouseUpEventHandler += disableclick;
            btnlogicdisable.MouseUpEventHandler += disableclick;
 
          
            if (IsDeviceEditor) {
                foreach (var deviceoutput in Logic.CurrentLogic.output) {
                    foreach (var device in deviceoutput.objects) {
                        if (!device.ContainsKey ("sid") || device ["sid"]?.ToString () == null) {
                            continue;
                        }
                        var tempSid = device ["sid"]?.ToString ();
                        var value = device ["value"]?.ToString ();
                        //判断SID是否有效的,如果不是有效的当前这个场景数据就不处理
                        Convert.ToUInt64 (tempSid, 16);
                        var sidUlong = Convert.ToUInt64 (tempSid, 16);
                        ///1:设备;
                        var type = (byte)((sidUlong >> 60) & 0xF);
 
                        if (type == 3) {
                          if (logic.sid == tempSid) {
                                //Logic当前状态值
                                if (value== "1") {
                                    openRowLayout.BackgroundColor = 0xfffe5e00;
                                    disableRowLayout.BackgroundColor = 0x00000000;
                                } else {
                                    openRowLayout.BackgroundColor = 0x00000000;
                                    disableRowLayout.BackgroundColor = 0xfffe5e00;
                                }
                                break;
                            }
                        }
                    }
                }
            }
 
 
 
            var btncomplete = new Button {
                Y = middle.Bottom,
                Height = Application.GetRealHeight (80),
                TextID = MyInternationalizationString.complete,
                TextSize=16,
            };
            AddChidren (btncomplete);
 
 
            btncomplete.MouseUpEventHandler += (sedder, e) => {
                if (IsselectedLogic != null) {
                    Logic.CurrentLogic.AddOutput (outputifon);
                } else {
                    if (!IsDeviceEditor) {
                        var alert = new Alert (Language.StringByID (MyInternationalizationString.Prompt),
                                              Language.StringByID (MyInternationalizationString.selectlogiccondition),
                                              Language.StringByID (MyInternationalizationString.OK)); alert.Show ();
                        return;
                    }
                    IsDeviceEditor = false;
                }
                this.RemoveFromParent ();
                var logicCommunalPage = new LogicCommunalPage ();
                MainPage.MainFrameLayout.AddChidren (logicCommunalPage);
                logicCommunalPage.Show (gateWay, () => { });
            };
        }
 
    }
}