using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.UserCenter
{
///
/// 做成一个显示网关信息的RowLayout(左边有个图标)
///
public class GatewayViewRow : StatuRowLayout
{
///
/// 网关对象
///
private ZbGateway m_zbGateway = null;
///
/// 网关对象(优先缓存的网关对象,其次才是真实网关)
///
public ZbGateway zbGateway
{
get { return m_zbGateway; }
set
{
string gwID = Common.LocalGateway.Current.GetGatewayId(value);
var way = Common.LocalGateway.Current.GetLocalGateway(gwID);
if (way != null)
{
m_zbGateway = way;
}
else
{
m_zbGateway = value;
}
}
}
///
/// 图标控件
///
public RowLeftIconView btnIcon = null;
///
/// 显示文本控件
///
public RowTopBlackView btnName = null;
///
/// 在线状态的控件
///
public RowSecondRightTextView btnOnline = null;
///
/// IP的控件
///
public RowBottomGrayView btnIP = null;
private bool m_IsOnline = false;
///
/// 在线状态
///
public bool IsOnline
{
get { return m_IsOnline; }
set
{
m_IsOnline = value;
//变更状态
this.SetOnlineStatu(m_IsOnline);
}
}
///
/// 显示主或者子网关的字样
///
private bool m_ShowMainGatewayTip = true;
///
/// 显示主或者子网关的字样
///
public bool ShowMainGatewayTip
{
get { return m_ShowMainGatewayTip; }
set
{
m_ShowMainGatewayTip = value;
//设置IP的文本信息
this.SetbtnIpText();
}
}
///
/// 做成一个显示网关信息的RowLayout(左边有个图标)
///
/// 列表控件
/// 网关对象
public GatewayViewRow(VerticalScrolViewLayout listView, ZbGateway i_zbGateway)
{
this.m_zbGateway = i_zbGateway;
listView.AddChidren(this);
//初始化内部控件之前
this.InitControlBefore(i_zbGateway);
//初始化内部控件
this.InitControl();
}
///
/// 做成一个显示网关信息的RowLayout(左边有个图标),添加此控件到容器后,调用【InitControl()】完成初始化
///
/// 网关对象
public GatewayViewRow(ZbGateway i_zbGateway)
{
this.m_zbGateway = i_zbGateway;
//初始化内部控件之前
this.InitControlBefore(i_zbGateway);
}
///
/// 初始化内部控件
///
public void InitControl()
{
//图标
this.AddChidren(this.btnIcon);
//显示文本
this.AddChidren(this.btnName);
//IP
this.AddChidren(this.btnIP);
//在线状态
this.AddChidren(this.btnOnline, ChidrenBindMode.BindEventOnly);
}
///
/// 刷新控件
///
///
public void RefreshControl(bool online)
{
this.IsOnline = online;
this.btnName.Text = Common.LocalGateway.Current.GetGatewayName(this.m_zbGateway);
this.SetbtnIpText();
}
///
/// 初始化内部控件之前
///
/// 网关
private void InitControlBefore(ZbGateway i_zbGateway)
{
this.btnIcon = new RowLeftIconView();
Common.LocalGateway.Current.SetGatewayIcon(btnIcon, i_zbGateway);
this.btnName = new RowTopBlackView();
this.btnName.Text = Common.LocalGateway.Current.GetGatewayName(i_zbGateway);
if (this.btnName.Text == string.Empty)
{
//无法识别的网关设备
this.btnName.TextID = R.MyInternationalizationString.uUnDistinguishTheGatewayDevice;
}
this.btnOnline = new RowSecondRightTextView();
this.btnOnline.Radius = 4;
ZbGateway realWay = null;
bool bonline = false;
if (Common.LocalGateway.Current.GetRealGateway(ref realWay, i_zbGateway) == true)
{
bonline = Common.LocalGateway.Current.CheckGatewayOnlineByFlag(realWay);
}
this.SetOnlineStatu(bonline);
this.btnIP = new RowBottomGrayView();
//设置IP的文本信息
this.SetbtnIpText();
}
///
/// 设置IP的文本信息
///
private void SetbtnIpText()
{
this.btnIP.Text = Common.LocalGateway.Current.GetGatewayBaseInfoAttribute(this.m_zbGateway, "IpAddress").ToString();
if (string.IsNullOrEmpty(this.btnIP.Text) == false && m_ShowMainGatewayTip == true && this.m_IsOnline == true)
{
int result = Common.LocalGateway.Current.IsMainGateway(this.m_zbGateway);
if (result == 1)
{
//主网关
this.btnIP.Text += " (" + Language.StringByID(R.MyInternationalizationString.uMainGateway) + ")";
}
else if (result == 0)
{
//子网关
this.btnIP.Text += " (" + Language.StringByID(R.MyInternationalizationString.uChidrenGateway) + ")";
}
}
}
///
/// 设置在线状态
///
///
private void SetOnlineStatu(bool online)
{
m_IsOnline = online;
if (btnOnline == null)
{
return;
}
if (online == false)
{
//初始值:离线
btnOnline.TextID = R.MyInternationalizationString.uOffLine;
//初始值:灰色
btnOnline.TextColor = UserCenterColor.Current.Gray;
}
else
{
//在线
btnOnline.TextID = R.MyInternationalizationString.uOnline;
//绿色
btnOnline.TextColor = UserCenterColor.Current.Green;
}
}
}
}