using System;
using System.Collections.Generic;
using Shared.Common;
namespace Shared.Phone.Device.Room
{
///
/// Add devices same type list.
///
public class AddDevicesSameTypeList : FrameLayout
{
#region ◆ 变量____________________________
///
/// 设备列表
///
private List sameTypeList;
///
/// The top view.
///
private FrameLayout topView;
///
/// The top BGView.
///
private FrameLayout topBGView;
///
/// 中部视图
///
private VerticalScrolViewLayout midFL;
#endregion
#region ◆ 构造方法_________________________
///
/// 构造方法
///
public AddDevicesSameTypeList()
{
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
Tag = "categoryAddScene";
}
public override void RemoveFromParent()
{
base.RemoveFromParent();
}
#endregion
#region ◆ 显示界面_________________________
///
/// 显示界面
///
/// 设备类型
/// Room.
public void Show(ZigBee.Device.DeviceType deviceType, Shared.Common.Room room)
{
//添加topview
AddTopView(deviceType);
//加载当前相同类型设备类型
AddDeviceToList(deviceType, room);
//如果没有可添加的设备,提示用户返回
if (IsHadDeviceToAdd() == false)
{
ShowNoDeviceTip();
return;
}
//添加midview
AddMidView();
//显示设备列表
ShowDeviceList(room);
}
#endregion
#region ◆ 添加topview_____________________
///
/// Adds the top view.
///
private void AddTopView(ZigBee.Device.DeviceType deviceType)
{
topBGView = new FrameLayout()
{
Height = Application.GetRealHeight(CommonPage.Navigation_Height),
BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor
};
AddChidren(topBGView);
topView = new FrameLayout()
{
Y = Application.GetRealHeight(CommonPage.NavigationTitle_Y),
Height = Application.GetRealHeight(CommonPage.Navigation_Height - CommonPage.NavigationTitle_Y),
BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor,
};
AddChidren(topView);
var title = new Button()
{
TextAlignment = TextAlignment.Center,
Text = DeviceUI.GetDeviceTypeName(deviceType),
TextSize = 20,
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
Width = Application.GetRealWidth(CommonPage.AppRealWidth - 500),
Gravity = Gravity.CenterHorizontal
};
topView.AddChidren(title);
var back = new Device.CommonForm.BackButton() { };
topView.AddChidren(back);
back.MouseUpEventHandler += (sender, e) =>
{
this.RemoveFromParent();
};
}
#endregion
#region ◆ 添加midView_____________________
///
/// Adds the middle view.
///
private void AddMidView()
{
midFL = new VerticalScrolViewLayout()
{
Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
Y = topView.Bottom,
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
};
this.AddChidren(midFL);
}
#endregion
#region ◆ 显示设备列表______________________
///
/// 将设备显示出来
///
private void ShowDeviceList(Shared.Common.Room room)
{
foreach (var device in sameTypeList)
{
if (device == null || device.CommonDevice == null)
{
continue;
}
var deviceItemFL = new FrameLayout()
{
Height = Application.GetRealHeight(170)
};
midFL.AddChidren(deviceItemFL);
var deviceIMG = new Button()
{
X = Application.GetRealWidth(50),
Width = Application.GetMinRealAverage(110),
Height = Application.GetMinRealAverage(110),
UnSelectedImagePath = device.IconPath,
SelectedImagePath = device.IconPath,
Gravity = Gravity.CenterVertical
};
deviceItemFL.AddChidren(deviceIMG);
var deviceName = new Button()
{
X = deviceIMG.Right + Application.GetRealWidth(50),
Width = Application.GetRealWidth(700),
Height = Application.GetRealHeight(110),
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
SelectedTextColor = ZigbeeColor.Current.GXCButtonBlueColor,
TextAlignment = TextAlignment.CenterLeft,
TextSize = 16,
Text = device.CommonDevice.DeviceEpointName,
Gravity = Gravity.CenterVertical
};
deviceItemFL.AddChidren(deviceName);
var deviceRight = new Device.CommonForm.SelectedStatuButton()
{
X = Application.GetRealWidth(1080 - 150),
Width = Application.GetMinRealAverage(110),
Height = Application.GetMinRealAverage(110),
UnSelectedImagePath = "Item/Next.png",
SelectedImagePath = "Item/NextSelected.png",
Gravity = Gravity.CenterVertical
};
deviceItemFL.AddChidren(deviceRight);
var line = new Button()
{
Y = Application.GetRealHeight(170) - 1,
Height = 1,
BackgroundColor = ZigbeeColor.Current.GXCLineColor,
Tag = device
};
deviceItemFL.AddChidren(line);
//跳转详细设置
EventHandler deviceHandler = (sender, e) =>
{
var detail = new Room.AddDevieDetailFromAddFunction();
UserView.HomePage.Instance.AddChidren(detail);
UserView.HomePage.Instance.PageIndex += 1;
detail.Show(device, room);
};
deviceRight.MouseUpEventHandler += deviceHandler;
deviceIMG.MouseUpEventHandler += deviceHandler;
deviceName.MouseUpEventHandler += deviceHandler;
}
}
#endregion
#region ◆ 是否有设备可以添加__________________
///
/// 提示用户没有设备可以添加到该房间
///
private void ShowNoDeviceTip()
{
var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.NoDeviceCanAddToRoom), Language.StringByID(R.MyInternationalizationString.Close));
alert.Show();
alert.ResultEventHandler += (sender, e) =>
{
this.RemoveFromParent();
};
}
///
/// 是否有可以添加到当前当前房间的设备
///
/// true, if had device to add was ised, false otherwise.
private bool IsHadDeviceToAdd()
{
if (sameTypeList.Count == 0)
{
return false;
}
return true;
}
#endregion
#region ◆ 添加设备到列表______________________
private void AddDeviceToList(ZigBee.Device.DeviceType deviceType, Shared.Common.Room room)
{
sameTypeList = new List();
foreach (var device in LocalDevice.Current.listAllDevice)
{
if (device.Type != deviceType)
{
continue;
}
var dev = LocalDevice.Current.GetDeviceUI(device);
if (dev == null || dev.CommonDevice == null)
{
continue;
}
//去掉改房间已包含的设备
if (room.DeviceUIList.Contains(dev) == false)
{
sameTypeList.Add(dev);
}
}
}
#endregion
}
}