using System;
|
using System.Collections.Generic;
|
using Shared.Common;
|
namespace Shared.Phone.Device.Room
|
{
|
/// <summary>
|
/// Add devices same type list.
|
/// </summary>
|
public class AddDevicesSameTypeList : FrameLayout
|
{
|
#region ◆ 变量____________________________
|
|
/// <summary>
|
/// 设备列表
|
/// </summary>
|
private List<DeviceUI> sameTypeList;
|
/// <summary>
|
/// The top view.
|
/// </summary>
|
private FrameLayout topView;
|
/// <summary>
|
/// The top BGView.
|
/// </summary>
|
private FrameLayout topBGView;
|
/// <summary>
|
/// 中部视图
|
/// </summary>
|
private VerticalScrolViewLayout midFL;
|
|
#endregion
|
|
#region ◆ 构造方法_________________________
|
|
/// <summary>
|
/// 构造方法
|
/// </summary>
|
public AddDevicesSameTypeList()
|
{
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
|
Tag = "categoryAddScene";
|
}
|
|
public override void RemoveFromParent()
|
{
|
base.RemoveFromParent();
|
}
|
|
#endregion
|
|
#region ◆ 显示界面_________________________
|
|
/// <summary>
|
/// 显示界面
|
/// </summary>
|
/// <param name="deviceType">设备类型</param>
|
/// <param name="room">Room.</param>
|
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_____________________
|
|
/// <summary>
|
/// Adds the top view.
|
/// </summary>
|
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_____________________
|
|
/// <summary>
|
/// Adds the middle view.
|
/// </summary>
|
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 ◆ 显示设备列表______________________
|
|
/// <summary>
|
/// 将设备显示出来
|
/// </summary>
|
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<MouseEventArgs> 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 ◆ 是否有设备可以添加__________________
|
/// <summary>
|
/// 提示用户没有设备可以添加到该房间
|
/// </summary>
|
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();
|
};
|
}
|
|
/// <summary>
|
/// 是否有可以添加到当前当前房间的设备
|
/// </summary>
|
/// <returns><c>true</c>, if had device to add was ised, <c>false</c> otherwise.</returns>
|
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<DeviceUI>();
|
|
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
|
}
|
}
|