黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone
{
    /// <summary>
    /// 做成一个显示设备类型+设备MAC备注的RowLayout
    /// </summary>
    public class DeviceObjectControl : RowLayoutControl
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 设备的Mac地址
        /// </summary>
        public string deviceMac = string.Empty;
        /// <summary>
        /// 只会刷新一次
        /// </summary>
        private bool hadRefresh = false;
        /// <summary>
        /// 传感器推送中
        /// </summary>
        private bool sensorPushing = false;
        /// <summary>
        /// 在线状态
        /// </summary>
        private bool m_isOnline = true;
        /// <summary>
        /// 在线状态
        /// </summary>
        public bool IsOnline
        {
            get { return m_isOnline; }
            set
            {
                if (m_isOnline != value)
                {
                    m_isOnline = value;
                    //设置在线状态的特效
                    this.SetOnlineStatu(m_isOnline);
                }
            }
        }
 
        /// <summary>
        /// 图标控件
        /// </summary>
        public IconViewControl btnIcon = null;
        /// <summary>
        /// 设备备注控件
        /// </summary>
        private NormalViewControl btnDeviceName = null;
        /// <summary>
        /// 设备房间控件
        /// </summary>
        private NormalViewControl btnDeviceRoom = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 做成一个显示设备类型+设备MAC备注的RowLayout
        /// </summary>
        /// <param name="i_deviceMac">设备的Mac地址</param>
        /// <param name="i_ChidrenYaxis">子控件Y轴偏移量(【列表控件的rowSpace/2】即可,不懂默认为0即可)</param>
        public DeviceObjectControl(string i_deviceMac, int i_ChidrenYaxis = 0) : base(i_ChidrenYaxis)
        {
            this.deviceMac = i_deviceMac;
        }
 
        /// <summary>
        /// 初始化内部控件
        /// </summary>
        public void InitControl()
        {
            var listDevice = HdlDeviceCommonLogic.Current.GetDevicesByMac(this.deviceMac);
            if (listDevice.Count == 0)
            {
                //针对单纯只有一个200端点的设备
                listDevice.Add(HdlDeviceCommonLogic.Current.GetOTADevice(this.deviceMac));
            }
            //图标
            btnIcon = frameTable.AddLeftIcon(81);
            HdlDeviceCommonLogic.Current.SetDeviceObjectIconToControl(btnIcon, listDevice);
 
            //设备
            string deviceName = HdlDeviceCommonLogic.Current.GetDeviceMacName(listDevice[0]);
            btnDeviceName = frameTable.AddTopView(deviceName, 800);
            frameTable.AddChidren(btnDeviceName, ChidrenBindMode.BindEvent);
 
            //房间
            string roomName = HdlRoomLogic.Current.GeteRealDeviceRoomName(listDevice[0]);
            btnDeviceRoom = frameTable.AddBottomView(roomName, 800);
 
            //底线
            frameTable.AddBottomLine();
 
            //设置在线状态的特效
            this.IsOnline = HdlDeviceCommonLogic.Current.CheckDeviceIsOnline(listDevice[0]);
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 设置在线状态的特效
        /// </summary>
        /// <param name="i_isOnline"></param>
        private void SetOnlineStatu(bool i_isOnline)
        {
            if (i_isOnline == false)
            {
                btnDeviceName.TextColor = UserCenterColor.Current.TextGrayColor1;
            }
            else
            {
                btnDeviceName.TextColor = UserCenterColor.Current.TextColor1;
            }
        }
 
        /// <summary>
        /// 刷新全部显示信息
        /// </summary>
        /// <param name="compel">是否强制执行</param>
        public void RefreshControlInfo(bool compel = false)
        {
            if (hadRefresh == true && compel == false)
            {
                return;
            }
            hadRefresh = true;
 
            var listDevice = HdlDeviceCommonLogic.Current.GetDevicesByMac(this.deviceMac);
            if (listDevice.Count == 0)
            {
                //针对单纯只有一个200端点的设备
                listDevice.Add(HdlDeviceCommonLogic.Current.GetOTADevice(this.deviceMac));
            }
            //图标
            HdlDeviceCommonLogic.Current.SetDeviceObjectIconToControl(btnIcon, listDevice);
            //设备
            btnDeviceName.Text = HdlDeviceCommonLogic.Current.GetDeviceMacName(listDevice[0]);
            //设备房间
            btnDeviceRoom.Text = HdlRoomLogic.Current.GeteRealDeviceRoomName(listDevice[0]);
        }
 
 
        /// <summary>
        /// 显示传感器上报的特效
        /// </summary>
        public void StartSensorPushAppeal()
        {
            if (this.sensorPushing == true)
            {
                //传感器正在特效中
                return;
            }
            this.sensorPushing = true;
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //闪烁5秒,间隔400毫秒
                int count = 5000 / 400;
                bool isOpen = false;
                while (this.Parent != null && count >= 0)
                {
                    //闪烁特效
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        isOpen = !isOpen;
                        this.SwitchRowStatuAppeal(isOpen);
                    }, ShowErrorMode.NO);
                    System.Threading.Thread.Sleep(400);
                    count--;
                }
                if (this.Parent != null && isOpen == true)
                {
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        //结束时,默认为无特效
                        this.SwitchRowStatuAppeal(false);
                    }, ShowErrorMode.NO);
                }
                this.sensorPushing = false;
 
            }, ShowErrorMode.NO);
        }
 
        /// <summary>
        /// 切换行闪烁特效
        /// </summary>
        /// <param name="isOpen"></param>
        private void SwitchRowStatuAppeal(bool isOpen)
        {
            if (isOpen == true)
            {
                //图标
                btnIcon.IsSelected = true;
                //设备
                btnDeviceName.TextColor = UserCenterColor.Current.TextOrangeColor;
                //设备房间
                btnDeviceRoom.TextColor = UserCenterColor.Current.TextOrangeColor;
            }
            else
            {
                //图标
                btnIcon.IsSelected = false;
                //设备
                btnDeviceName.TextColor = UserCenterColor.Current.TextColor1;
                //设备房间
                btnDeviceRoom.TextColor = UserCenterColor.Current.TextGrayColor1;
            }
        }
 
        #endregion
    }
}