using System; using System.Collections.Generic; using System.Text; namespace Shared.Phone { /// /// 做成一个显示设备类型+设备MAC备注的RowLayout /// public class DeviceObjectControl : RowLayoutControl { #region ■ 变量声明___________________________ /// /// 设备的Mac地址 /// public string deviceMac = string.Empty; /// /// 只会刷新一次 /// private bool hadRefresh = false; /// /// 传感器推送中 /// private bool sensorPushing = false; /// /// 在线状态 /// private bool m_isOnline = true; /// /// 在线状态 /// public bool IsOnline { get { return m_isOnline; } set { if (m_isOnline != value) { m_isOnline = value; //设置在线状态的特效 this.SetOnlineStatu(m_isOnline); } } } /// /// 图标控件 /// public IconViewControl btnIcon = null; /// /// 设备备注控件 /// private NormalViewControl btnDeviceName = null; /// /// 设备房间控件 /// private NormalViewControl btnDeviceRoom = null; #endregion #region ■ 初始化_____________________________ /// /// 做成一个显示设备类型+设备MAC备注的RowLayout /// /// 设备的Mac地址 /// 子控件Y轴偏移量(【列表控件的rowSpace/2】即可,不懂默认为0即可) public DeviceObjectControl(string i_deviceMac, int i_ChidrenYaxis = 0) : base(i_ChidrenYaxis) { this.deviceMac = i_deviceMac; } /// /// 初始化内部控件 /// 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 ■ 一般方法___________________________ /// /// 设置在线状态的特效 /// /// private void SetOnlineStatu(bool i_isOnline) { if (i_isOnline == false) { btnDeviceName.TextColor = UserCenterColor.Current.TextGrayColor1; } else { btnDeviceName.TextColor = UserCenterColor.Current.TextColor1; } } /// /// 刷新全部显示信息 /// /// 是否强制执行 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]); } /// /// 显示传感器上报的特效 /// 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); } /// /// 切换行闪烁特效 /// /// 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 } }