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
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
using System;
using Shared;
using Shared.SimpleControl;
using Shared.SimpleControl.R;
 
namespace SmartHome.UI.SimpleControl.Phone
{
    public class Etid : FrameLayout
    {
        
        Button IocnClickButton = new Button ();
        EditText sceneTextBox;
        public string name = "";
        public byte munber;
        public void Show (YIPanel yipanel,YiPanelScene scene,Action action)
        {
            ///定义一个变量记录当前场景名称和图标索引;
            name = scene.Name;
            munber = scene.IconIndex;
            AddChidren (new Button {
                Height = Application.GetRealHeight (36),
                BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
            });
 
 
            var topFrameLayout = new FrameLayout {
                Height = Application.GetRealHeight (90),
                Y = Application.GetRealHeight (36),
                BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
            };
            AddChidren (topFrameLayout);
 
            var btnTitle = new Button {
                TextID = MyInternationalizationString.etidscene,
                TextColor = SkinStyle.Current.MusicTextColor,
                //Text = "编辑场景",
                TextSize = 17,
            };
            topFrameLayout.AddChidren (btnTitle);
 
            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) => {
 
                var scenename = sceneTextBox.Text.Trim ();
                if (string.IsNullOrEmpty (scenename)) {
                    new Alert (Language.StringByID (MyInternationalizationString.Tip), Language.StringByID (MyInternationalizationString.thename), Language.StringByID (MyInternationalizationString.Close)).Show ();
                    return;
                }
                ///发送修改场景名称命令
                if (name != scenename) {
                    scene.Name = sceneTextBox.Text.Trim ();
                    System.Threading.Tasks.Task.Run (() => {
                        try {
                            var bytes = new byte [24];
                            bytes [0] = scene.LargeClass;
                            bytes [1] = 1;
                            bytes [2] = scene.Channelnumber;
                            bytes [3] = 0;
                            var pathBytes = System.Text.Encoding.UTF8.GetBytes (scene.Name);
                            Array.Copy (pathBytes, 0, bytes, 4, pathBytes.Length > 20 ? 20 : pathBytes.Length);
                            Control.ControlBytesSend (Command.YIPanelDeviceModify, yipanel.SubnetID, yipanel.DeviceID, bytes);
                        } catch { }
                    });
                }
                ///发送修改场景图标命令
                if (munber != scene.IconIndex) {
                    System.Threading.Tasks.Task.Run (() => {
                        try {
                            var iconbytes = new byte [5];
                            iconbytes [0] = scene.LargeClass;
                            iconbytes [1] = 1;
                            iconbytes [2] = scene.Channelnumber;
                            iconbytes [3] = 8;
                            iconbytes [4] = scene.IconIndex;
                            var iocndata = Control.ControlBytesSendHasReturn (Command.YIPanelDeviceModify, yipanel.SubnetID, yipanel.DeviceID, iconbytes);
                        } catch { }
                    });
                }
                RemoveFromParent ();
                action ();
 
            };
 
            var hdl = new Button {
                Width = Application.GetRealWidth (154),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (486),
                Gravity = Gravity.CenterVertical,
                //UnSelectedImagePath = MainPage.LogoString,
            };
            topFrameLayout.AddChidren (hdl);
 
            var tempFrameLayout = new FrameLayout {
                Y = topFrameLayout.Bottom,
                Height = Application.GetRealHeight (1136 - 126),
                //BackgroundImagePath = "MusicIcon/HomepageBackgroun.png",
                BackgroundColor = SkinStyle.Current.MusicVerticalScrolViewLayout,
            };
            AddChidren (tempFrameLayout);
 
 
            #region -------
         
 
            var txet = new Button {
                Width = Application.GetRealWidth (200),
                Height = Application.GetRealHeight (60),
                X = Application.GetRealWidth (30),
                Y=Application.GetRealHeight(40),
                //Text="场景信息",
                TextAlignment=TextAlignment.CenterLeft,
                TextID = MyInternationalizationString.sceneinformation,
 
 
            };
            tempFrameLayout.AddChidren (txet);
 
            var sceneicon = new Button {
                Y = txet.Y + txet.Height + Application.GetRealHeight (40),
                Height = Application.GetRealHeight (80),
                Width = Application.GetRealWidth (83),
                UnSelectedImagePath = $"Yipanel/{scene.IconIndex}.png",
                X = Application.GetRealWidth (30),
                TextAlignment = TextAlignment.CenterLeft,
            };
            tempFrameLayout.AddChidren (sceneicon);
 
            
             sceneTextBox = new EditText{
                Y = txet.Y + txet.Height + Application.GetRealHeight (40),
                Width = Application.GetRealWidth (440),
                Height = Application.GetRealHeight (80),
                X = sceneicon.X + sceneicon.Width + Application.GetRealWidth (30),
                Radius = (uint)Application.GetRealHeight (2),
                Text = scene.Name,
                //BorderWidth = 1,
                //BorderColor = 0xff838383,
                TextColor = 0xff838383,
                //TextAlignment = TextAlignment.Center,
            };
            tempFrameLayout.AddChidren (sceneTextBox);
 
 
            var btnline = new Button {
                Y = sceneTextBox.Bottom,
                Width = Application.GetRealWidth (440),
                Height = Application.GetRealHeight (2),
                X = sceneicon.X + sceneicon.Width + Application.GetRealWidth (30),
                BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
            };
            tempFrameLayout.AddChidren (btnline);
 
 
            var selectedicon = new Button {
                Width = Application.GetRealWidth (200),
                Height = Application.GetRealHeight (60),
                X = Application.GetRealWidth (30),
                Y = sceneTextBox.Y+sceneTextBox.Height+ Application.GetRealHeight (100),
                //Text = "选中图标",
                TextAlignment = TextAlignment.CenterLeft,
                TextID = MyInternationalizationString.selectedicon,
            };
            tempFrameLayout.AddChidren (selectedicon);
 
 
            #endregion
 
            var iconlistview = new FrameLayout {
                Y = selectedicon.Y + selectedicon.Height + Application.GetRealHeight (30),
                Height = Application.GetRealHeight (320),
                Width = Application.GetRealWidth (640-120),
                X = Application.GetRealWidth (60),
                //BackgroundColor = SkinStyle.Current.MusicVerticalScrolViewLayout,
                //BorderWidth = 2,
                //BorderColor = 0xffffffff,
 
            };
            tempFrameLayout.AddChidren (iconlistview);
 
            var middle = new VerticalScrolViewLayout ();
            iconlistview.AddChidren (middle);
            int k = 1;
            for (int i = 1; i <= 3; i++) {
                var iconfra = new FrameLayout {
                    Height = Application.GetRealHeight (100),
                };
                middle.AddChidren (iconfra);
 
                for (int j = 1; j <= 4; j++) {
                    var sceneiconbtn = new Button {
                        Height = Application.GetRealHeight (80),
                        Width = Application.GetRealWidth (83),
                        UnSelectedImagePath = $"Yipanel/{k}.png",
                        SelectedImagePath = $"Yipanel/{k}Selected.png",
                        Gravity = Gravity.CenterVertical,
                        X = Application.GetRealWidth (37 * j + (83 * (j - 1))),
                        Tag = k,
                    };
                    iconfra.AddChidren (sceneiconbtn);
                    k++;
                    ///显示之前状态
                    if (scene.IconIndex== (byte)int.Parse (sceneiconbtn.Tag.ToString ())) {
                      IocnClickButton.IsSelected = false;
                        IocnClickButton = sceneiconbtn;
                        sceneiconbtn.IsSelected = true;
                    }
                    sceneiconbtn.MouseDownEventHandler += (sender, e) => {
                        IocnClickButton.IsSelected = false;
                        IocnClickButton = sceneiconbtn;
                        sceneiconbtn.IsSelected = true;
                        scene.IconIndex = (byte)int.Parse (sceneiconbtn.Tag.ToString ());
                        sceneicon.UnSelectedImagePath = $"Yipanel/{scene.IconIndex}.png";
                    };
                }
            }
        }
    }
}