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;
namespace Shared.SimpleControl.Phone
{
    public class UserUniversalPage : FrameLayout
    {
        /// <summary>
        /// 当前打开的灯光界面
        /// </summary>
        static UserUniversalPage curView;
        VerticalScrolViewLayout lightListView;
        Room room;
 
        /// <summary>
        /// 显示当前房间灯光设备
        /// </summary>
        /// <param name="room">Room.</param>
        public UserUniversalPage (Room Room)
        {
            curView = this;
            room = Room;
            BackgroundColor = SkinStyle.Current.ViewColor;
        }
 
        /// <summary>
        /// 房间模式进入的灯光界面
        /// </summary>
        /// <returns>The lights room.</returns>
        public void ShowUniversalRoom ()
        {
            #region 标题
            var topView = new FrameLayout () {
                Y = Application.GetRealHeight (36),
                Height = Application.GetRealHeight (90),
                BackgroundColor = SkinStyle.Current.MainColor,
            };
            AddChidren (topView);
 
            var title = new Button () {
                TextAlignment = TextAlignment.Center,
                Text = room.Name,
                TextColor = SkinStyle.Current.TextColor1,
                TextSize = 19,
            };
            topView.AddChidren (title);
 
            var logo = new Button () {
                Width = Application.GetRealWidth (154),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (486),
                UnSelectedImagePath = MainPage.LogoString,
            };
            topView.AddChidren (logo);
            var back = new Button () {
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (85),
                UnSelectedImagePath = "Item/Back.png",
                SelectedImagePath = "Item/BackSelected.png",
            };
            topView.AddChidren (back);
            back.MouseUpEventHandler += (sender, e) => {
                (Parent as PageLayout).PageIndex -= 1;
                curView = null;
            };
            #endregion
 
            VerticalScrolViewLayout bodyMainView = new VerticalScrolViewLayout () {
                Height = Application.GetRealHeight (Application.DesignHeight) - topView.Bottom,
                Y = topView.Bottom,
            };
            AddChidren (bodyMainView);
 
            var roomBackgroundImage = new FrameLayout () {
                Height = Application.GetRealHeight (360),
            };
            bodyMainView.AddChidren (roomBackgroundImage);
            roomBackgroundImage.BackgroundImagePath = room.BackGroundImage;
            roomBackgroundImage.MouseLongEventHandler += (sender, e) => {
                Camera.SelectPicture ((obj) => {
                    if (obj != null) {
                        room.BackGroundImage = obj;
                        roomBackgroundImage.BackgroundImagePath = obj;
                        room.Save (typeof (Room).Name + "_" + room.Name);
                    }
                }, room.Name, false);
            };
 
            lightListView = new VerticalScrolViewLayout () {
                BackgroundColor = SkinStyle.Current.ViewColor,
                Y = roomBackgroundImage.Bottom,
                Height = Application.GetRealHeight (Application.DesignHeight) - topView.Bottom,
            };
            lightListView.Y = roomBackgroundImage.Bottom;
            bodyMainView.AddChidren (lightListView);
 
            var universalDeviceList = room.DeviceList.FindAll ((obj) => {
                return obj.Type == DeviceType.UniversalDevice;
            });
            //
            foreach (var common in universalDeviceList) {
                UniversalDevice udDevice = common as UniversalDevice;
                FrameLayout lightView = new FrameLayout () {
                    Height = Application.GetRealHeight (130),
                    Radius = 1,
                    BorderColor = SkinStyle.Current.Transparent,
                    BorderWidth = (uint)Application.GetMinRealAverage (5),
                };
                lightView.AddTag ("UpdataKey", udDevice.CommonLoopID);
                lightListView.AddChidren (lightView);
                Button BtnLightViewNull = new Button () {
                    Y = Application.GetRealHeight (127),
                    Height = Application.GetRealHeight (3),
                    BackgroundColor = SkinStyle.Current.MainColor,
                    SelectedBackgroundColor = SkinStyle.Current.MainColor,
                };
                lightView.AddChidren (BtnLightViewNull);
 
                //
                var tempLightName = new Button () {
                    X = Application.GetRealWidth (20),
                    TextAlignment = TextAlignment.CenterLeft,
                    Text = udDevice.Name,
                    Enable = false,
                    TextColor = SkinStyle.Current.TextColor1,
                    SelectedTextColor = SkinStyle.Current.TextColor1,
                    //TextSize = 15,
                };
                lightView.AddChidren (tempLightName);
 
                var tempSiwtch = new Button () {
                    Width = Application.GetRealWidth (110),
                    Height = Application.GetRealHeight (70),
                    X = Application.GetRealWidth (640 - 110 - 20),
                    Gravity = Gravity.CenterVertical,
                    Radius = 2,
                    BorderColor = SkinStyle.Current.BorderColor,
                    TextColor = SkinStyle.Current.TextColor1,
                    SelectedTextColor = SkinStyle.Current.TextColor1,
                    BorderWidth = 2,
                };
                lightView.AddChidren (tempSiwtch);
 
                if (udDevice.ActionType == 0) {
                    tempSiwtch.Text = udDevice.ON_Text;
                } else if (udDevice.ActionType == 1) {
                    tempSiwtch.Text = udDevice.OFF_Text;
                } else if (udDevice.ActionType == 2) {
                    tempSiwtch.Text = udDevice.OFF_Text;
 
                    Button tempON = new Button () {
                        Width = Application.GetRealWidth (110),
                        Height = Application.GetRealHeight (70),
                        X = Application.GetRealWidth (640 - 250 - 20),
                        Gravity = Gravity.CenterVertical,
                        Radius = 2,
                        BorderColor = SkinStyle.Current.BorderColor,
                        TextColor = SkinStyle.Current.TextColor1,
                        SelectedTextColor = SkinStyle.Current.TextColor1,
                        BorderWidth = 2,
                        Text = udDevice.ON_Text
                };
                    lightView.AddChidren (tempON);
                    tempON.MouseUpEventHandler += (sender3, e3) => {
                        if (udDevice.UniversalType == 0xE01C) {
                            Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 255 },SendCount.Zero);
                        }
                        tempON.BorderColor = SkinStyle.Current.Transparent;
                        lightView.BorderColor = SkinStyle.Current.Transparent;
                    };
                    tempON.MouseDownEventHandler += (sende3r, e3) => {
                        tempON.BorderColor = SkinStyle.Current.SelectedColor;
                        lightView.BorderColor = SkinStyle.Current.SelectedColor;
                    };
                }
                tempSiwtch.MouseUpEventHandler += (sender3, e3) => {
                    if (udDevice.UniversalType == 0xE01C) {
                        if (udDevice.ActionType == 0) {
                            Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 255 },SendCount.Zero);
                        } else if (udDevice.ActionType == 1) {
                            Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 },SendCount.Zero);
                        } else if (udDevice.ActionType == 2) {
                            Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 },SendCount.Zero);
                        }
                    }
                    tempSiwtch.BorderColor = SkinStyle.Current.Transparent;
                    lightView.BorderColor = SkinStyle.Current.Transparent;
                };
                tempSiwtch.MouseDownEventHandler += (sende3r, e3) => {
                    tempSiwtch.BorderColor = SkinStyle.Current.SelectedColor;
                    lightView.BorderColor = SkinStyle.Current.SelectedColor;
                };
            }
        }
    }
}