黄学彪
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone
{
    /// <summary>
    /// 设备信息界面的设备图标控件(兼容网关)
    /// </summary>
    public class DeviceInfoIconControl : FrameLayoutStatuControl
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 设备Mac地址
        /// </summary>
        private string deviceMac = null;
        /// <summary>
        /// 设备端点
        /// </summary>
        private int deviceEpoint = -1;
        /// <summary>
        /// 网关对象
        /// </summary>
        private ZbGateway zbGateway = null;
        /// <summary>
        /// 图标控件
        /// </summary>
        private NormalViewControl btnIcon = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 设备信息界面的设备图标控件
        /// </summary>
        public DeviceInfoIconControl()
        {
            //第一层底色
            this.Height = this.GetPictrueRealSize(207);
            this.Width = this.GetPictrueRealSize(207);
            this.BackgroundColor = UserCenterColor.Current.White;
            this.Radius = (uint)this.GetPictrueRealSize(207) / 2;
            this.UseClickStatu = false;
        }
 
        /// <summary>
        /// 初始化(设备)
        /// </summary>
        /// <param name="i_device">设备对象</param>
        public void InitControl(CommonDevice i_device)
        {
            this.deviceMac = i_device.DeviceAddr;
            //防止出现误差
            int iconWidth = this.GetPictrueRealSize(207) - this.GetPictrueRealSize(12) - this.GetPictrueRealSize(12);
            //第二层底色
            var btnIcon2 = new NormalViewControl(iconWidth, iconWidth, false);
            btnIcon2.BackgroundColor = 0xfffef1ed;
            btnIcon2.Radius = (uint)iconWidth / 2;
            btnIcon2.Gravity = Gravity.Center;
            this.AddChidren(btnIcon2, ChidrenBindMode.BindEvent);
 
            //设备图标
            var listDevice = HdlDeviceCommonLogic.Current.GetDevicesByMac(deviceMac);
            if (listDevice.Count == 0)
            {
                //对应单纯只有200回路的设备
                listDevice.Add(HdlDeviceCommonLogic.Current.GetOTADevice(deviceMac));
            }
            btnIcon = new NormalViewControl(this.GetPictrueRealSize(121), this.GetPictrueRealSize(121), false);
            btnIcon.Gravity = Gravity.Center;
            HdlDeviceCommonLogic.Current.SetDeviceObjectIconToControl(btnIcon, listDevice);
            this.AddChidren(btnIcon, ChidrenBindMode.BindEvent);
        }
 
        /// <summary>
        /// 初始化(设备端点)
        /// </summary>
        /// <param name="i_device">设备对象</param>
        public void InitControl(string deviceMacAddr, int epoint)
        {
            this.deviceMac = deviceMacAddr;
            this.deviceEpoint = epoint;
            //防止出现误差
            int iconWidth = this.GetPictrueRealSize(207) - this.GetPictrueRealSize(12) - this.GetPictrueRealSize(12);
            //第二层底色
            var btnIcon2 = new NormalViewControl(iconWidth, iconWidth, false);
            btnIcon2.BackgroundColor = 0xfffef1ed;
            btnIcon2.Radius = (uint)iconWidth / 2;
            btnIcon2.Gravity = Gravity.Center;
            this.AddChidren(btnIcon2, ChidrenBindMode.BindEvent);
 
            //设备图标
            btnIcon = new NormalViewControl(this.GetPictrueRealSize(121), this.GetPictrueRealSize(121), false);
            btnIcon.Gravity = Gravity.Center;
            HdlDeviceCommonLogic.Current.SetDeviceIconToControl(btnIcon, HdlDeviceCommonLogic.Current.GetDevice(deviceMacAddr, epoint));
            this.AddChidren(btnIcon, ChidrenBindMode.BindEvent);
        }
 
        /// <summary>
        /// 初始化(网关)
        /// </summary>
        /// <param name="i_gateway">网关对象</param>
        public void InitControl(ZbGateway i_gateway)
        {
            this.zbGateway = i_gateway;
            //防止出现误差
            int iconWidth = this.GetPictrueRealSize(207) - this.GetPictrueRealSize(12) - this.GetPictrueRealSize(12);
            //第二层底色
            var btnIcon2 = new NormalViewControl(iconWidth, iconWidth, false);
            btnIcon2.BackgroundColor = 0xfffef1ed;
            btnIcon2.Radius = (uint)iconWidth / 2;
            btnIcon2.Gravity = Gravity.Center;
            this.AddChidren(btnIcon2, ChidrenBindMode.BindEvent);
 
            //设备图标
            btnIcon = new NormalViewControl(this.GetPictrueRealSize(121), this.GetPictrueRealSize(121), false);
            btnIcon.Gravity = Gravity.Center;
            HdlGatewayLogic.Current.SetGatewayIcon(btnIcon, i_gateway);
            this.AddChidren(btnIcon, ChidrenBindMode.BindEvent);
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 重新刷新控件
        /// </summary>
        public void RefreshControl()
        {
            if (this.deviceEpoint != -1)
            {
                //刷新图标
                HdlDeviceCommonLogic.Current.SetDeviceIconToControl(btnIcon, HdlDeviceCommonLogic.Current.GetDevice(this.deviceMac, this.deviceEpoint));
            }
            else if (this.deviceMac != null)
            {
                //刷新图标
                var listDevice = HdlDeviceCommonLogic.Current.GetDevicesByMac(deviceMac);
                if (listDevice.Count == 0)
                {
                    //对应单纯只有200回路的设备
                    listDevice.Add(HdlDeviceCommonLogic.Current.GetOTADevice(deviceMac));
                }
                HdlDeviceCommonLogic.Current.SetDeviceObjectIconToControl(btnIcon, listDevice);
            }
            else
            {
                //刷新图标
                HdlGatewayLogic.Current.SetGatewayIcon(btnIcon, this.zbGateway);
            }
        }
 
        #endregion
    }
}