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
using System;
namespace Shared.SimpleControl.Phone
{
    public class SystemLightLogic : FrameLayout
    {
        public void SystemLightLogicShow (LightLogic lightLogic, Common common)
        {
            //SystemMiddle.hideBottom ();
            byte [] lightLigicBytes = new byte [11];
            System.Threading.Tasks.Task.Run (() => {
                Application.RunOnMainThread (() => {
                    MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load));
                });
                lightLigicBytes = Control.ControlBytesSendHasReturn (Command.ReadLogicLoopColor, lightLogic.SubnetID, lightLogic.DeviceID, new byte [] { lightLogic.LoopID });
                if (lightLigicBytes == null) {
                    lightLigicBytes = new byte [11];
                }
                Application.RunOnMainThread (() => {
                    MainPage.Loading.Hide ();
                    #region  top
                    RowLayout topTitleView = new RowLayout () {
                        Height = Application.GetRealHeight (100),
                        BackgroundColor = SkinStyle.Current.MainColor
                    };
                    AddChidren (topTitleView);
                    Button backButton = new Button () {
                        X = Application.GetRealWidth (0),
                        Height = Application.GetRealHeight (90),
                        Width = Application.GetRealWidth (85),
                        UnSelectedImagePath = "Item/Back.png",
                        SelectedImagePath = "Item/BackSelected.png",
                        Gravity = Gravity.CenterVertical,
                    };
                    backButton.MouseUpEventHandler += (sender, e) => {
                        (Parent as PageLayout).PageIndex -= 1;
                        //SystemEquipmentBase.RefreshView (common);
                    };
                    topTitleView.AddChidren (backButton);
 
                    EditText textButton = new EditText () {
                        X = Application.GetRealWidth (30) + backButton.Right,
                        Height = Application.GetRealHeight (50),
                        Width = Application.GetRealWidth (400),
                        Text = lightLogic.Name,
                        TextAlignment = TextAlignment.CenterLeft,
                        Gravity = Gravity.CenterVertical,
                        BackgroundColor = SkinStyle.Current.Transparent,
                        SelectedBackgroundColor = SkinStyle.Current.SysEditBox,
                        Enable = false,
                        TextColor = SkinStyle.Current.TextColor1
                    };
                    topTitleView.AddChidren (textButton);
 
                    Button editor = new Button () {
                        X = Application.GetRealWidth (520),
                        Height = Application.GetRealHeight (90),
                        Width = Application.GetRealWidth (70),
                        UnSelectedImagePath = "Item/Editor.png",
                        SelectedImagePath = "Item/EditorSelected.png",
                        Gravity = Gravity.CenterVertical,
                    };
                    topTitleView.AddChidren (editor);
                    EventHandler<MouseEventArgs> eHandler = new EventHandler<MouseEventArgs> ((sender, e) => {
                        if (editor.IsSelected) {
                            MainPage.Loading.Start ();
                            byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (textButton.Text.Trim ());
                            textButton.IsSelected = editor.IsSelected = textButton.Enable = false;
                            System.Threading.Tasks.Task.Run (() => {
                                byte [] updateBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, lightLogic.SubnetID, lightLogic.DeviceID, new byte [] {
                             lightLogic.BigClass,lightLogic.MinClass,lightLogic.LoopID
                        });
                                if (updateBytes == null) {
                                    Application.RunOnMainThread (() => {
                                        new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                        MainPage.Loading.Hide ();
                                    });
                                    return;
                                }
                                byte [] uBytes = new byte [20];
                                Array.Copy (remakeBytes, 0, uBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20);
                                Array.Copy (uBytes, 0, updateBytes, 3, 20 < uBytes.Length ? 20 : uBytes.Length);
                                var reBytes = Control.ControlBytesSendHasReturn (Command.SetDeviceLoopInfo, lightLogic.SubnetID, lightLogic.DeviceID, updateBytes);
                                if (reBytes != null) {
                                    Application.RunOnMainThread (() => {
                                        lightLogic.Name = textButton.Text.Trim ();
                                        IO.FileUtils.SaveEquipmentMessage (lightLogic, lightLogic.LoopID.ToString ());
                                        MainPage.Loading.Hide ();
                                    });
                                } else {
                                    Application.RunOnMainThread (() => {
                                        new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                        MainPage.Loading.Hide ();
                                    });
                                }
                            });
                        } else {
                            textButton.Enable = textButton.IsSelected = editor.IsSelected = true;
                        }
                    });
                    editor.MouseUpEventHandler += eHandler;
                    #endregion
 
                    #region ---RGB---
                    FrameLayout frameLayoutBody = new FrameLayout () {
                        Y = Application.GetRealHeight (100),
                        Height = Application.GetRealHeight (800),
                    };
                    AddChidren (frameLayoutBody);
 
                    ColorPicker c = new ColorPicker () {
                        X = Application.GetRealWidth (100),
                        Y = Application.GetRealHeight (30),
                        Width = Application.GetMinRealAverage (440),
                        Height = Application.GetMinRealAverage (440),
                        ColorImagePath = "Item/PickerColorWheel.png",
                    };
                    frameLayoutBody.AddChidren (c);
                    DateTime colorChangeTime = DateTime.MinValue;
 
                    uint colorByte = (uint)(0xFF000000 + lightLigicBytes [6] * 256 * 256 + lightLigicBytes [7] * 256 + lightLigicBytes [8]);
 
 
                    HorizontalSeekBar seekBarLighting = new HorizontalSeekBar () {
                        X = Application.GetRealWidth (55),
                        Y = c.Bottom + Application.GetRealHeight (50),
                        Width = Application.GetRealWidth (460),
                        Height = Application.GetRealHeight (50),
                        Progress = lightLigicBytes [1],
                        Max = 100,
                        ThumbColor = SkinStyle.Current.ThumbColor,
                    };
                    frameLayoutBody.AddChidren (seekBarLighting);
                    Button btnLightingText = new Button () {
                        X = seekBarLighting.Right + Application.GetRealWidth (5),
                        Y = seekBarLighting.Y,
                        Width = Application.GetRealWidth (80),
                        Height = Application.GetRealHeight (50),
                        Text = lightLigicBytes [1].ToString () + "%"
                    };
                    frameLayoutBody.AddChidren (btnLightingText);
                    Button btnColorSwitch = new Button () {
                        X = Application.GetRealWidth (250),
                        Y = btnLightingText.Bottom + Application.GetRealHeight (50),
                        Width = Application.GetMinRealAverage (140),
                        Height = Application.GetMinRealAverage (60),
                        Radius = (uint)Application.GetMinRealAverage (10),
                        BackgroundColor = colorByte,
                        TextColor = SkinStyle.Current.TextColor1,
                        TextID = R.MyInternationalizationString.OnOrOff
                    };
                    frameLayoutBody.AddChidren (btnColorSwitch);
 
                    c.ColorChaged += (sender, e) => {
                        if ((DateTime.Now - colorChangeTime).TotalMilliseconds > 50) {
                            lightLigicBytes [6] = e [0];
                            lightLigicBytes [7] = e [1];
                            lightLigicBytes [8] = e [2];
                            Control.ControlBytesSend (Command.SetLogicLoopColor, lightLogic.SubnetID, lightLogic.DeviceID, lightLigicBytes, SendCount.Zero);
                            colorChangeTime = DateTime.Now;
                            btnColorSwitch.BackgroundColor = (uint)(0xFF000000 + lightLigicBytes [6] * 256 * 256 + lightLigicBytes [7] * 256 + lightLigicBytes [8]);
                            lightLogic.RStatus = e [0];
                            lightLogic.GStatus = e [1];
                            lightLogic.BStatus = e [2];
                            //IO.FileUtils.SaveEquipmentMessage (lightLogic, lightLogic.LoopID.ToString ());
                        }
                    };
                    seekBarLighting.ProgressChanged += (sender, e) => {
                        if ((DateTime.Now - colorChangeTime).TotalMilliseconds > 50) {
                            lightLigicBytes [1] = (byte)e;
                            Control.ControlBytesSend (Command.SetLogicLoopColor, lightLogic.SubnetID, lightLogic.DeviceID, lightLigicBytes, SendCount.Zero);
                            colorChangeTime = DateTime.Now;
                            btnLightingText.Text = e.ToString () + "%";
                            lightLogic.LastOpenBrightness = (byte)e;
                        }
                    };
                    btnColorSwitch.MouseUpEventHandler += (sender, e) => {
                        if ((DateTime.Now - colorChangeTime).TotalMilliseconds > 100) {
                            lightLigicBytes [1] = lightLigicBytes [1] > (byte)0 ? (byte)0 : (lightLogic.LastOpenBrightness == (byte)0 ? (byte)100 : lightLogic.LastOpenBrightness);
                            Control.ControlBytesSend (Command.SetLogicLoopColor, lightLogic.SubnetID, lightLogic.DeviceID, lightLigicBytes, SendCount.Zero);
                            colorChangeTime = DateTime.Now;
                            seekBarLighting.Progress = lightLigicBytes [1];
                            btnLightingText.Text = lightLigicBytes [1].ToString () + "%";
                        }
                    };
                    #endregion
 
                });
            });
 
        }
    }
}