JLChen
2020-06-05 f86c8b5dcf5c84386745b009fc4115fa9db3b76d
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
using System;
using System.Collections.Generic;
 
namespace Shared.SimpleControl.Phone
{
    public class UserDeviceToSensor : FrameLayout
    {
        VerticalScrolViewLayout bodyScrolView;
 
        FrameLayout LongPressFrameLayout = new FrameLayout ();
        Button beforeClickButton = new Button ();
        /// <summary>
        /// 构造函数
        /// </summary>
        public UserDeviceToSensor ()
        {
            BackgroundColor = SkinStyle.Current.MainColor;
            curView = this;
        }
 
        static UserDeviceToSensor curView;
        public static bool hasModify = false;
        public static void Refresh ()
        {
            if (curView == null)
                return;
            if (hasModify) {
                curView.ShowAllSensor ();
                hasModify = false;
            }
        }
 
        /// <summary>
        /// 显示房间的所有场景
        /// </summary>
        public void ShowAllSensor ()
        {
            this.RemoveAll ();
            #region 标题
            var topView = new FrameLayout () {
                Y = Application.GetRealHeight (36),
                Height = Application.GetRealHeight (90),
            };
            AddChidren (topView);
 
            var title = new Button () {
                TextAlignment = TextAlignment.Center,
                TextID = R.MyInternationalizationString.Environmental,
                TextSize = 19,
                TextColor = SkinStyle.Current.TextColor1,
            };
            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
 
            var bodyView = new FrameLayout () {
                Width = LayoutParams.MatchParent,
                Height = Application.GetRealHeight (Application.DesignHeight - 126),
                Y = Application.GetRealHeight(126),
                BackgroundColor = SkinStyle.Current.ViewColor
            };
            AddChidren (bodyView);
            bodyScrolView = new VerticalScrolViewLayout ();
            bodyView.AddChidren (bodyScrolView);
 
            InitView ();
        }
 
        void InitView ()
        {
            bodyScrolView.RemoveAll ();
 
            List<string> sensorPaths = new List<string> ();
            //List<string> localFileList = IO.FileUtils.ReadFiles ();
            //sensorPaths = localFileList.FindAll ((obj) => { return obj.Split ('_') [0] == "Equipment" && obj.Split ('_').Length == 4 && obj.Contains ("Sensor"); });
 
            foreach (var room in Room.Lists) {
                if (room == null || string.IsNullOrEmpty (room.Name))
                    continue;
                var sensor = room.DeviceList.FindAll ((obj) => obj.Type.ToString ().Contains (DeviceType.Sensor.ToString ()));
                if(sensor == null || sensor.Count == 0){
                    continue;
                }
                var rowView = new FrameLayout () {
                    Height = Application.GetRealHeight (130),
                };
                bodyScrolView.AddChidren (rowView);
 
                var tempDeviceName = new Button () {
                    X = Application.GetRealWidth (40),
                    TextAlignment = TextAlignment.CenterLeft,
                    Text = room.Name,
                    TextColor = SkinStyle.Current.TextColor1,
                    Enable = false,
                };
                rowView.AddChidren (tempDeviceName);
 
                Button rightButton = new Button () {
                    Width = Application.GetRealWidth (28),
                    Height = Application.GetRealHeight (40),
                    Gravity = Gravity.CenterVertical,
                    X = Application.GetRealWidth(580),
                    UnSelectedImagePath = "Item/Right.png",
                    SelectedImagePath = "Item/RightSelected.png",
                };
                rowView.AddChidren (rightButton);
 
 
                Button btnEnergyNull = new Button () {
                    Y = Application.GetRealHeight (127),
                    Height = Application.GetRealHeight (3),
                    BackgroundColor = SkinStyle.Current.MainColor,
                    SelectedBackgroundColor = SkinStyle.Current.MainColor,
                };
                rowView.AddChidren (btnEnergyNull);
 
                EventHandler<MouseEventArgs> clickEventHandler = (sender, e) => {
                    MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load));
                    System.Threading.Tasks.Task.Run (() => {
                        try {
                            Application.RunOnMainThread (() => {
                            UserSensorPage usp = new UserSensorPage ();
                            UserMiddle.DevicePageView.AddChidren (usp);
                            usp.ShowUserSensorPage (room);
                            UserMiddle.DevicePageView.PageIndex = 2;
                            });
                        }catch{}
                        finally{
                            Application.RunOnMainThread (() => {
                                MainPage.Loading.Hide ();
                            });
                        }
                    });
                };
 
                rightButton.MouseUpEventHandler += clickEventHandler;
                rowView.MouseUpEventHandler += clickEventHandler;
                tempDeviceName.MouseUpEventHandler += clickEventHandler;
                btnEnergyNull.MouseUpEventHandler += clickEventHandler;
                Button btnllll = new Button ();
                rowView.AddChidren (btnllll);
                btnllll.MouseUpEventHandler += clickEventHandler;
                //rowView.MouseUpEventHandler += (sender, e) => {
                //    UserSensorPage usp = new UserSensorPage ();
                //    UserMiddle.DevicePageView.AddChidren (usp);
                //    usp.ShowUserSensorPage (room);
                //    UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1;
                //};
                //tempDeviceName.MouseUpEventHandler += (sender, e) => {
                //    UserSensorPage usp = new UserSensorPage ();
                //    UserMiddle.DevicePageView.AddChidren (usp);
                //    usp.ShowUserSensorPage (room);
                //    UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1;
                //};
                //rightButton.MouseUpEventHandler += (sender, e) => {
                //    UserSensorPage usp = new UserSensorPage ();
                //    UserMiddle.DevicePageView.AddChidren (usp);
                //    usp.ShowUserSensorPage (room);
                //    UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1;
                //};
            }
        }
    }
}