using System;
|
using Shared.Common;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.Device.Light
|
{
|
public class DimmableLightControl:FrameLayout, ZigBee.Common.IStatus
|
{
|
#region ◆ 变量__________________________
|
|
/// <summary>
|
/// The action.
|
/// </summary>
|
public Action action;
|
///// <summary>
|
///// The top view.
|
///// </summary>
|
private CommonForm.TopFrameLayout top;
|
/// <summary>
|
/// 更多设置
|
/// </summary>
|
private Button moreBtn;
|
/// <summary>
|
/// 传过来的设备
|
/// </summary>
|
private DeviceUI device;
|
/// <summary>
|
/// 传过来的ac
|
/// </summary>
|
private ZigBee.Device.DimmableLight dimmableLight;
|
/// <summary>
|
/// 传过来的房间
|
/// </summary>
|
private Shared.Common.Room room;
|
/// <summary>
|
/// The middle fl.
|
/// </summary>
|
private FrameLayout midFL;
|
/// <summary>
|
/// 收藏按钮
|
/// </summary>
|
private Button collectionBtn;
|
/// <summary>
|
/// 设备是否在线标识--Online
|
/// </summary>
|
private readonly string DeviceStatus_Online = "Online";
|
/// <summary>
|
/// 设备状态开关标识--Switch
|
/// </summary>
|
private readonly string DeviceStatus_OnOffStatus = "Switch";
|
/// <summary>
|
/// The light image.
|
/// </summary>
|
private Button deviceIMG;
|
/// <summary>
|
/// 开关
|
/// </summary>
|
private Button switchBtn;
|
/// <summary>
|
/// 滑条
|
/// </summary>
|
private HorizontalSeekBar levelSeekBar;
|
/// <summary>
|
/// 延时 300毫秒
|
/// </summary>
|
private int sleepSpan = 300;
|
|
#endregion
|
|
#region ◆ 接口__________________________
|
/// <summary>
|
/// 处理变化事件 --将弃用 改用DeviceInfoChange()
|
/// </summary>
|
/// <returns>The changed.</returns>
|
/// <param name="common">Common.</param>
|
public void Changed(CommonDevice common)
|
{
|
|
}
|
/// <summary>
|
/// Changeds the IL ogic status.
|
/// </summary>
|
/// <param name="logic">Logic.</param>
|
public void ChangedILogicStatus(ZigBee.Device.Logic logic)
|
{
|
//throw new NotImplementedException();
|
}
|
/// <summary>
|
/// Changeds the IS cene status.
|
/// </summary>
|
/// <param name="scene">Scene.</param>
|
public void ChangedISceneStatus(Scene scene)
|
{
|
//throw new NotImplementedException();
|
}
|
/// <summary>
|
/// 设备状态更新接口
|
/// <para>type:如果为 DeviceInComingRespon:设备新上报</para>
|
/// <para>type:如果为 IASInfoReport:RemoveDeviceRespon</para>
|
/// <para>type:如果为 DeviceStatusReport:设备上报</para>
|
/// <para>type:如果为 IASInfoReport:IAS安防信息上报</para>
|
/// <para>type:如果为 OnlineStatusChange: 设备在线状态更新</para>
|
/// </summary>
|
/// <param name="common">Common.</param>
|
/// <param name="typeTag">Type tag.</param>
|
public void DeviceInfoChange(CommonDevice common, string typeTag)
|
{
|
if (typeTag == "DeviceStatusReport")
|
{
|
Application.RunOnMainThread(() =>
|
{
|
try
|
{
|
var deviceUI = device;
|
//设备为空
|
if (deviceUI.CommonDevice == null)
|
{
|
return;
|
}
|
//是否为当前设备
|
if (deviceUI.CommonDevice.DeviceEpoint != common.DeviceEpoint || deviceUI.CommonDevice.DeviceAddr != common.DeviceAddr)
|
{
|
return;
|
}
|
if (deviceUI.CommonDevice.Type == DeviceType.DimmableLight)
|
{
|
if ((common as DimmableLight).DeviceStatusReport.CluterID == 6)
|
{
|
dimmableLight = deviceUI.CommonDevice as DimmableLight;
|
dimmableLight.DeviceStatusReport = (common as DimmableLight).DeviceStatusReport;
|
//记录、更新状态
|
if (dimmableLight.DeviceStatusReport.AttriBute == null || dimmableLight.DeviceStatusReport.AttriBute.Count == 0)
|
{
|
return;
|
}
|
dimmableLight.OnOffStatus = dimmableLight.DeviceStatusReport.AttriBute[0].AttriButeData;
|
switchBtn.IsSelected = dimmableLight.OnOffStatus == 1;
|
dimmableLight.LastDateTime = DateTime.Now;
|
}
|
//亮度
|
if ((common as ZigBee.Device.DimmableLight).DeviceStatusReport.CluterID == 8)
|
{
|
dimmableLight = deviceUI.CommonDevice as ZigBee.Device.DimmableLight;
|
dimmableLight.DeviceStatusReport = (common as ZigBee.Device.DimmableLight).DeviceStatusReport;
|
var attriButeList = dimmableLight.DeviceStatusReport.AttriBute;
|
if (attriButeList == null || attriButeList.Count == 0)
|
{
|
return;
|
}
|
switch (attriButeList[0].AttributeId)
|
{
|
case 0:
|
//此属性表明当前亮度程度
|
dimmableLight.Level = attriButeList[0].AttriButeData;
|
dimmableLight.LastDateTime = DateTime.Now;
|
levelSeekBar.Progress = dimmableLight.Level;
|
break;
|
}
|
}
|
//***新改***设备状态上报中,当CluterID=3,证明设备在线,直接标记
|
else if ((common as DimmableLight).DeviceStatusReport.CluterID == 3)
|
{
|
dimmableLight = deviceUI.CommonDevice as DimmableLight;
|
dimmableLight.IsOnline = 1;
|
deviceIMG.IsSelected = dimmableLight.IsOnline == 1;
|
dimmableLight.LastDateTime = DateTime.Now;
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
System.Console.WriteLine($"Error:{ex.Message}");
|
}
|
});
|
}
|
else if (typeTag == "OnlineStatusChange")
|
{
|
Application.RunOnMainThread(() =>
|
{
|
try
|
{
|
var deviceUI = device;
|
//设备为空
|
if (deviceUI.CommonDevice == null)
|
{
|
return;
|
}
|
//是否为当前设备
|
if (deviceUI.CommonDevice.DeviceEpoint != common.DeviceEpoint || deviceUI.CommonDevice.DeviceAddr != common.DeviceAddr)
|
{
|
return;
|
}
|
if (deviceUI.CommonDevice.Type == DeviceType.DimmableLight)
|
{
|
dimmableLight = deviceUI.CommonDevice as DimmableLight;
|
dimmableLight.IsOnline = (common as DimmableLight).IsOnline;
|
deviceIMG.IsSelected = dimmableLight.IsOnline == 1;
|
dimmableLight.LastDateTime = DateTime.Now;
|
}
|
}
|
catch (Exception ex)
|
{
|
System.Console.WriteLine($"Error:{ex.Message}");
|
}
|
});
|
}
|
}
|
|
#endregion
|
|
#region ◆ 重写移除_______________________
|
|
/// <summary>
|
/// Removes from parent.
|
/// </summary>
|
public override void RemoveFromParent()
|
{
|
ZbGateway.StatusList.Remove(this);
|
UserView.HomePage.Instance.ScrollEnabled = true;
|
action();
|
action = null;
|
base.RemoveFromParent();
|
}
|
|
#endregion
|
|
#region ◆ 构造方法_______________________
|
/// <summary>
|
/// 构造方法
|
/// </summary>
|
public DimmableLightControl()
|
{
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
|
}
|
|
#endregion
|
|
#region ◆ 显示界面_______________________
|
/// <summary>
|
/// 显示界面
|
/// </summary>
|
/// <param name="device">Device.</param>
|
/// <param name="room">Room.</param>
|
public void Show(DeviceUI device, Shared.Common.Room room)
|
{
|
ZbGateway.StatusList.Add(this);
|
this.device = device;
|
this.room = room;
|
this.dimmableLight = device.CommonDevice as ZigBee.Device.DimmableLight;
|
|
//添加topview
|
AddTopView();
|
//添加midview
|
AddMidview();
|
//绑定事件
|
BindEvent();
|
//收藏
|
InitCollection();
|
|
if (dimmableLight.Gateway.IsVirtual)
|
{
|
//发送读取状态命令
|
UserView.UserHomeView.ReadStatus(dimmableLight, () =>
|
{
|
dimmableLight.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
|
dimmableLight.ReadOnOffStatus();
|
dimmableLight.ReadLevel();
|
});
|
}
|
else
|
{
|
//防止短时间内多次读取设备状态
|
if ((DateTime.Now - dimmableLight.LastDateTime).TotalSeconds > CommonPage.ReadDeviceStatuSpan)
|
{
|
dimmableLight.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
|
dimmableLight.ReadOnOffStatus();
|
dimmableLight.ReadLevel();
|
}
|
}
|
}
|
|
#endregion
|
|
#region ◆ topview_______________________
|
|
/// <summary>
|
/// Adds the top view.
|
/// </summary>
|
private void AddTopView()
|
{
|
top = new CommonForm.TopFrameLayout();
|
AddChidren(top);
|
top.InitTopview();
|
top.backButton.MouseUpEventHandler += (sender, e) =>
|
{
|
RemoveFromParent();
|
};
|
|
AddMoreview();
|
}
|
|
/// <summary>
|
/// Adds the moreview.
|
/// </summary>
|
private void AddMoreview()
|
{
|
moreBtn = new CommonForm.SelectedStatuButton()
|
{
|
X = Application.GetRealWidth(CommonPage.AppRealWidth - 150),
|
Width = Application.GetMinReal(110),
|
Height = Application.GetMinReal(110),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/More.png",
|
SelectedImagePath = "Item/MoreSelected.png",
|
};
|
top.topView.AddChidren(moreBtn);
|
moreBtn.MouseUpEventHandler += MoreEvent;
|
}
|
|
/// <summary>
|
/// 更多设置
|
/// </summary>
|
/// <param name="sender">Sender.</param>
|
/// <param name="e">E.</param>
|
private void MoreEvent(object sender, MouseEventArgs e)
|
{
|
var detailInfo = new Device.CommonForm.DeviceDetailInfo { };
|
UserView.HomePage.Instance.AddChidren(detailInfo);
|
UserView.HomePage.Instance.PageIndex += 1;
|
detailInfo.Show(device, room);
|
detailInfo.action = () =>
|
{
|
Show(device, room);
|
};
|
}
|
|
#endregion
|
|
#region ◆ midview_______________________
|
|
/// <summary>
|
/// Adds the midview.
|
/// </summary>
|
private void AddMidview()
|
{
|
midFL = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
|
Y = top.Bottom,
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
|
};
|
AddChidren(midFL);
|
|
AddItemview();
|
}
|
|
#endregion
|
|
#region ◆ itemview_______________________
|
/// <summary>
|
/// Adds the itemview.
|
/// </summary>
|
private void AddItemview()
|
{
|
var itemView = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(115),
|
Width = Application.GetRealWidth(965),
|
Height = Application.GetRealHeight(1316),
|
Radius = CommonPage.BigFormRadius,
|
Gravity = Gravity.CenterHorizontal,
|
BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor
|
};
|
midFL.AddChidren(itemView);
|
var deviceView = new FrameLayout()
|
{
|
X = 2,
|
Y = 2,
|
Width = itemView.Width - 4,
|
Height = itemView.Height - Application.GetRealHeight(138),
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
|
Tag = device
|
};
|
itemView.AddChidren(deviceView);
|
|
collectionBtn = new Button()
|
{
|
X = deviceView.Width - Application.GetRealWidth(130),
|
Y = Application.GetRealHeight(20),
|
Width = Application.GetMinReal(110),
|
Height = Application.GetMinReal(110),
|
UnSelectedImagePath = "Item/Collection.png",
|
SelectedImagePath = "Item/CollectionSelected.png"
|
};
|
deviceView.AddChidren(collectionBtn);
|
|
deviceIMG = new Button()
|
{
|
Y = Application.GetRealHeight(100),
|
Height = Application.GetMinRealAverage(240),
|
Width = Application.GetMinRealAverage(240),
|
Gravity = Gravity.CenterHorizontal,
|
UnSelectedImagePath = device.IconPath,
|
SelectedImagePath = device.OnlineIconPath,
|
IsSelected = dimmableLight.IsOnline == 1,
|
Tag = DeviceStatus_Online
|
};
|
deviceView.AddChidren(deviceIMG);
|
|
var lightName = new Button()
|
{
|
Y = deviceIMG.Bottom,
|
Height = Application.GetRealHeight(85),
|
Gravity = Gravity.CenterHorizontal,
|
Text = device.CommonDevice.DeviceEpointName,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor
|
};
|
deviceView.AddChidren(lightName);
|
|
levelSeekBar = new HorizontalSeekBar()
|
{
|
Y = lightName.Bottom + Application.GetRealHeight(150),
|
Width = Application.GetRealWidth(800),
|
Height = Application.GetRealHeight(80),
|
Gravity = Gravity.CenterHorizontal,
|
BackgroundColor = ZigbeeColor.Current.GXCSliderUnSelectedColor,
|
ThumbColor = ZigbeeColor.Current.GXCButtonBlueColor,
|
BorderColor = ZigbeeColor.Current.GXCButtonBlueColor,
|
ProgressColor = ZigbeeColor.Current.GXCButtonBlueColor,
|
Max = 254,
|
Tag = "LevelSeekBar",
|
Progress = dimmableLight.Level,
|
SleepTime=sleepSpan,
|
};
|
deviceView.AddChidren(levelSeekBar);
|
levelSeekBar.ProgressChanged += (send2, e2) =>
|
{
|
dimmableLight.SetLevel(levelSeekBar.Progress);
|
};
|
|
switchBtn = new Button()
|
{
|
Y = levelSeekBar.Bottom + Application.GetRealHeight(150),
|
Gravity = Gravity.CenterHorizontal,
|
Width = Application.GetMinRealAverage(180),
|
Height = Application.GetMinRealAverage(120),
|
UnSelectedImagePath = "Item/Switch.png",
|
SelectedImagePath = "Item/SwitchSelected.png",
|
Tag = DeviceStatus_OnOffStatus,
|
IsSelected = dimmableLight.OnOffStatus == 1
|
};
|
deviceView.AddChidren(switchBtn);
|
|
var roomBtn = new Button()
|
{
|
X = Application.GetRealWidth(50),
|
Y = Application.GetRealHeight(25) + deviceView.Bottom,
|
Width = Application.GetMinReal(80),
|
Height = Application.GetMinReal(80),
|
UnSelectedImagePath = "Item/Room.png",
|
SelectedImagePath = "Item/RoomSelected.png"
|
};
|
itemView.AddChidren(roomBtn);
|
|
var roomName = new Button()
|
{
|
X = roomBtn.Right + Application.GetRealWidth(20),
|
Y = roomBtn.Y,
|
Width = Application.GetRealWidth(400),
|
Height = Application.GetRealHeight(80),
|
Text = room.Name,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor
|
};
|
itemView.AddChidren(roomName);
|
}
|
|
#endregion
|
|
#region ◆ 绑定按钮_______________________
|
/// <summary>
|
/// 绑定按钮的事件
|
/// </summary>
|
private void BindEvent()
|
{
|
switchBtn.MouseUpEventHandler += Switch_MouseUpEvent;
|
collectionBtn.MouseUpEventHandler += Collection;
|
moreBtn.MouseUpEventHandler += MoreEvent;
|
}
|
|
#endregion
|
|
#region ◆ 开关__________________________
|
|
/// <summary>
|
/// 开关设置
|
/// </summary>
|
/// <param name="sender">Sender.</param>
|
/// <param name="eventArgs">Event arguments.</param>
|
private void Switch_MouseUpEvent(object sender, MouseEventArgs eventArgs)
|
{
|
switchBtn.IsSelected = !switchBtn.IsSelected;
|
if (switchBtn.IsSelected == true)
|
{
|
dimmableLight.SwitchControl(1);
|
}
|
else
|
{
|
dimmableLight.SwitchControl(0);
|
}
|
}
|
|
#endregion
|
|
#region ◆ 收藏__________________________
|
|
/// <summary>
|
/// Inits the collection.
|
/// </summary>
|
private void InitCollection()
|
{
|
var dev = Shared.Common.Room.LoveRoomDeviceUIFilePathList.Find((obj) => obj == device.FileName);
|
if (dev == null)
|
{
|
collectionBtn.IsSelected = false;
|
}
|
else
|
{
|
collectionBtn.IsSelected = true;
|
}
|
}
|
/// <summary>
|
/// 收藏到主页
|
/// </summary>
|
/// <param name="sender">Sender.</param>
|
/// <param name="e">E.</param>
|
private void Collection(object sender, MouseEventArgs e)
|
{
|
//collection
|
if (collectionBtn.IsSelected)
|
{
|
Shared.Common.Room.Lists[0].DeleteDevice(device.FileName);
|
collectionBtn.IsSelected = false;
|
}
|
else
|
{
|
Shared.Common.Room.Lists[0].AddDevice(device.FileName);
|
collectionBtn.IsSelected = true;
|
}
|
}
|
|
#endregion
|
}
|
}
|