using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter
{
///
/// 做成一个设备选择的行控件
///
public class DeviceSelectRow : StatuRowLayout
{
///
/// 设备
///
public ZigBee.Device.CommonDevice device = null;
///
/// 选择的状态是否能够取消
///
public bool SelectCancel = true;
///
/// 图标控件
///
private RowLeftIconView btnIcon = null;
///
/// 设备控件
///
private RowTopBlackView btnDevie = null;
///
/// 房间控件
///
private RowBottomGrayView btnRoom = null;
///
/// 选择控件
///
private MostRightEmptyView btnSelect = null;
///
/// 状态
///
private StatuMode Statu = StatuMode.UN_SELECT;
///
/// 是否处于选择状态
///
public bool IsSelected
{
get { return Statu == StatuMode.SELECT; }
set
{
if (value == false)
{
if (SelectCancel == true)
{
this.SetUnselectStatu();
}
}
else
{
this.SetSelectStatu();
}
}
}
///
/// 做成一个设备选择的行控件
///
/// 列表控件,可以为空
/// 设备对象
public DeviceSelectRow(VerticalScrolViewLayout listView, ZigBee.Device.CommonDevice i_device)
{
this.device = i_device;
this.MouseUpEvent += (sender, e) =>
{
this.IsSelected = Statu == StatuMode.SELECT ? false : true;
};
if (listView != null)
{
listView.AddChidren(this);
//初始化内部控件
this.InitControl();
}
}
///
/// 初始化内部控件
///
public void InitControl()
{
//图标
btnIcon = new RowLeftIconView();
Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device);
if (btnIcon.UnSelectedImagePath != null
&& btnIcon.UnSelectedImagePath.Contains(ZigBee.Device.DeviceType.OnOffSwitch.ToString()) == true)
{
//将控件适配为【点号】控件
btnIcon.ChangedControlInPointMode();
btnIcon.UnSelectedImagePath = "Device/OnOffSwitch.png";
btnIcon.SelectedImagePath = "Device/OnOffSwitchSelected.png";
}
this.AddChidren(btnIcon, ChidrenBindMode.BindEventOnly);
//设备
btnDevie = new RowTopBlackView();
btnDevie.Text = Common.LocalDevice.Current.GetDeviceEpointName(device);
this.AddChidren(btnDevie, ChidrenBindMode.BindEventOnly);
//房间
btnRoom = new RowBottomGrayView();
btnRoom.Text = Common.Room.CurrentRoom.GetRoomNameByDevice(device);
this.AddChidren(btnRoom, ChidrenBindMode.BindEventOnly);
//选择
btnSelect = new MostRightEmptyView();
btnSelect.Visible = false;
btnSelect.UnSelectedImagePath = "Item/TickSelected.png";
this.AddChidren(btnSelect, ChidrenBindMode.BindEventOnly);
}
///
/// 移除房间控件
///
public void RemoveRoomControl()
{
//移除事件
this.ChangedChidrenBindMode(btnRoom, ChidrenBindMode.NotBind);
this.btnRoom.RemoveFromParent();
this.btnDevie.Gravity = Gravity.CenterVertical;
}
///
/// 设定选择状态
///
public void SetSelectStatu()
{
if (Statu == StatuMode.SELECT)
{
return;
}
btnIcon.IsSelected = true;
btnDevie.TextColor = UserCenterColor.Current.SelectTextColor;
btnRoom.TextColor = UserCenterColor.Current.SelectTextColor;
btnSelect.Visible = true;
//状态变更
Statu = StatuMode.SELECT;
}
///
/// 设置非选择状态
///
public void SetUnselectStatu()
{
if (Statu == StatuMode.UN_SELECT)
{
return;
}
btnIcon.IsSelected = false;
btnDevie.TextColor = UserCenterColor.Current.TextColor;
btnRoom.TextColor = UserCenterColor.Current.TextGrayColor;
btnSelect.Visible = false;
//状态变更
Statu = StatuMode.UN_SELECT;
}
}
}