using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.Device.Category;
using Shared.Phone.Device.CommonForm;
using Shared.Phone.UserView;
using ZigBee.Device;
namespace Shared.Phone.Device.Room
{
public class UnallocatedRoom:FrameLayout
{
#region ◆ 变量____________________________
///
/// bodyFrameLayout
///
private FrameLayout bodyFrameLayout;
///
/// top
///
private TopFrameLayout top;
private Button selectAllBtn;
private FrameLayout itemView;
///
/// low_High
///
private const int low_High = 127;
///
/// 功能
///
private ButtonLineForm functionBtn;
///
/// 场景
///
private ButtonLineForm sceneBtn;
///
/// 中部背景bodyView
///
public FrameLayout functionSceneBodyView;
///
/// 当前功能类型按钮
///
private FunctionButton tempFunctionTypeBtn;
///
/// 功能类型按钮
///
private FunctionButton functionTypeIMG;
///
/// 功能类型
///
private HorizontalScrolViewLayout functionTypeScrowView;
///
/// 设备类型RowLayout
///
private FrameLayout typeRowLayout;
///
/// 相同的设备列表
///
public VerticalScrolViewLayout deviceListScrolView;
///
/// dList
///
private List devList;
///
/// sceneList
///
private List sceneList;
///
/// 相同类型的设备列表
///
private Dictionary> typeDeviceDic;
///
/// 设备类型的图id
///
private Dictionary typeIdDic;
#endregion
///
/// UnallocatedRoom
///
public UnallocatedRoom()
{
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
}
///
/// 未分配房间管理
///
public void Show()
{
InitData();
AddTop();
AddBodyView();
}
///
/// InitData
///
private void InitData()
{
typeDeviceDic = new Dictionary> { };
typeIdDic = new Dictionary { };
RefreshData();
}
///
/// RefreshData
///
private void RefreshData()
{
devList = Shared.Common.Room.CurrentRoom.GetUnalloctedDeviceUIs();
sceneList = Shared.Common.Room.CurrentRoom.GetUnalloctedScenes();
typeDeviceDic.Clear();
typeIdDic.Clear();
if (devList == null)
{
return;
}
foreach (var device in devList)
{
var info = Common.LocalDevice.Current.GetNotHdlMyDeviceEnumInfo(new List { device?.CommonDevice });
if (typeDeviceDic.ContainsKey(info.BeloneTextId) == false)
{
var sameDevList = new List { };
sameDevList.Add(device);
typeDeviceDic[info.BeloneTextId] = sameDevList;
}
else
{
typeDeviceDic[info.BeloneTextId].Add(device);
}
typeIdDic[info.BeloneTextId] = info.ConcreteType;
}
}
/////
///// RefreshView
/////
//public void RefreshView()
//{
// InitData();
// RefreshBodyView();
//}
#region Add____________________________________
///
/// AddTop
///
public void AddTop()
{
top = new TopFrameLayout();
AddChidren(top);
top.InitTopview();
top.SetTopTitle(R.MyInternationalizationString.Unallocated);
top.backButton.MouseUpEventHandler += (sender, e) =>
{
RemoveFromParent();
};
}
///
/// AddBodyView
///
public void AddBodyView()
{
bodyFrameLayout = new FrameLayout()
{
Y = Application.GetRealHeight(184),
Height = Application.GetRealHeight(1737),
BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
};
AddChidren(bodyFrameLayout);
var functionSceneBG = new FrameLayout()
{
Height = Application.GetRealHeight(low_High),
BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor
};
bodyFrameLayout.AddChidren(functionSceneBG);
//场景
sceneBtn = new ButtonLineForm(CommonFormResouce.X_Left, 43);
functionSceneBG.AddChidren(sceneBtn);
sceneBtn.Init();
sceneBtn.SetTitle(R.MyInternationalizationString.Scence);
sceneBtn.IsSelected = true;
//功能
functionBtn = new ButtonLineForm(CommonFormResouce.X_Left + 150 + 20, 43);
functionSceneBG.AddChidren(functionBtn);
functionBtn.Init();
functionBtn.SetTitle(R.MyInternationalizationString.Function);
functionBtn.IsSelected = false;
functionBtn.X = sceneBtn.Right;
//选择功能分栏
functionBtn.NameBtn.MouseUpEventHandler += FunctionBtn_MouseUpEventHandler;
//选择场景分栏
sceneBtn.NameBtn.MouseUpEventHandler += SceneBtn_MouseUpEventHandler;
//功能和场景bodyView
functionSceneBodyView = new FrameLayout()
{
Y= Application.GetRealHeight(127),
Height = Application.GetRealHeight(1607),
BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor
};
bodyFrameLayout.AddChidren(functionSceneBodyView);
RefreshBodyView();
}
///
/// 选择功能分栏
///
/// Sender.
/// The ${ParameterType} instance containing the event data.
private void FunctionBtn_MouseUpEventHandler(object sender, MouseEventArgs mouseEventArgs)
{
functionBtn.IsSelected = true;
sceneBtn.IsSelected = false;
RefreshBodyView();
}
///
/// 选择场景分栏
///
/// Sender.
/// The ${ParameterType} instance containing the event data.
private void SceneBtn_MouseUpEventHandler(object sender, MouseEventArgs mouseEventArgs)
{
functionBtn.IsSelected = false;
sceneBtn.IsSelected = true;
RefreshBodyView();
}
#endregion
#region ◆ 刷新____________________________
///
/// 刷新bodyView
///
public void RefreshBodyView()
{
functionSceneBodyView.RemoveAll();
if (functionBtn.IsSelected)
{
ShowFunction();
}
else if (sceneBtn.IsSelected)
{
ShowScene();
}
}
#endregion
#region ◆ 功能____________________________
///
/// 功能
///
public void ShowFunction()
{
if (typeIdDic.Count == 0)
{
ShowNoFunctionTip();
}
else
{
var functionTypeView1 = new FrameLayout
{
X = Application.GetRealWidth(CommonFormResouce.X_Left),
Y = Application.GetRealHeight(58),
Height = Application.GetRealHeight(160),
Width = Application.GetRealWidth(1028),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
};
functionSceneBodyView.AddChidren(functionTypeView1);
functionTypeView1.SetCornerWithSameRadius(Application.GetRealHeight(17), HDLUtils.RectCornerTopLeft);
var functionTypeView2 = new FrameLayout
{
X = Application.GetRealWidth(CommonFormResouce.X_Left),
Y = Application.GetRealHeight(58+150),
Height = Application.GetRealHeight(279-150),
Width = Application.GetRealWidth(1028),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
};
functionSceneBodyView.AddChidren(functionTypeView2);
functionTypeView2.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerBottomLeft);
functionTypeScrowView = new HorizontalScrolViewLayout
{
X = Application.GetRealWidth(CommonFormResouce.X_Left),
Y=Application.GetRealHeight(58),
Height = Application.GetRealHeight(279),
Width = Application.GetRealWidth(1028)
};
functionSceneBodyView.AddChidren(functionTypeScrowView);
deviceListScrolView = new VerticalScrolViewLayout
{
X = Application.GetRealWidth(CommonFormResouce.X_Left),
Y = Application.GetRealHeight(372),
Width = Application.GetRealWidth(1028),
Height = Application.GetRealHeight(1034),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
};
functionSceneBodyView.AddChidren(deviceListScrolView);
deviceListScrolView.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft);
tempFunctionTypeBtn = new FunctionButton();
tempFunctionTypeBtn.Init("", "");
foreach (var deviceType in typeIdDic)
{
typeRowLayout = new FrameLayout()
{
Width = Application.GetRealWidth(220),
};
functionTypeScrowView.AddChidren(typeRowLayout);
functionTypeIMG = new FunctionButton()
{
Tag = deviceType.Key
};
string imgPath=string.Empty;
string imgSeletedPath=string.Empty;
Common.LocalDevice.Current.GetDeviceBeloneIcon(deviceType.Value, ref imgPath ,ref imgSeletedPath);
functionTypeIMG.Init(imgPath,imgSeletedPath);
functionTypeIMG.SetTitle(deviceType.Key);
typeRowLayout.AddChidren(functionTypeIMG);
functionTypeIMG.ClickBtn.MouseUpEventHandler += ShowSameTypeFunction;
if (functionTypeScrowView.ChildrenCount == 1)
{
ShowSameTypeFunction(functionTypeIMG.ImageBtn, null);
}
}
}
}
///
/// 显示相同类型的功能
///
/// typeSender.
/// The ${ParameterType} instance containing the event data.
private void ShowSameTypeFunction(object typeSender, MouseEventArgs mouseEventArgs)
{
//选择功能--直接从房间的devicelist中获取
tempFunctionTypeBtn.IsSelected = false;
tempFunctionTypeBtn = (typeSender as Button).Parent as FunctionButton;
((typeSender as Button).Parent as FunctionButton).IsSelected = true;
deviceListScrolView.RemoveAll();
var sameTypeList = new List { };
var selectedList = new List { };
sameTypeList = typeDeviceDic[int.Parse((typeSender as Button).Tag.ToString())];
foreach (var deviceUI in sameTypeList)
{
var deviceTypeRowLayout = new FrameLayout()
{
Height = Application.GetRealHeight(127 + 35),
Tag = deviceUI
};
deviceListScrolView.AddChidren(deviceTypeRowLayout);
var deviceRow = new SelectFunctionView(0, 35);
deviceRow.Init(deviceUI.IconPath, deviceUI.OnlineIconPath);
deviceRow.SetTitle(deviceUI.CommonDevice.DeviceEpointName);
deviceTypeRowLayout.AddChidren(deviceRow);
EventHandler eventHandler = (sender, e) =>
{
deviceRow.IsSelected = !deviceRow.IsSelected;
if (deviceRow.IsSelected)
{
if (!selectedList.Contains(deviceUI))
{
selectedList.Add(deviceUI);
}
}
else
{
if (selectedList.Contains(deviceUI))
{
selectedList.Remove(deviceUI);
}
}
};
deviceRow.ClickBtn.MouseUpEventHandler += eventHandler;
}
selectAllBtn?.RemoveFromParent();
selectAllBtn = new Button()
{
X = Application.GetRealWidth(1080 - 150 - 80),
Width = Application.GetRealWidth(150),
Height = Application.GetRealHeight(80),
Gravity = Gravity.CenterVertical,
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
SelectedTextColor = ZigbeeColor.Current.GXCTextBlackColor,
TextSize = CommonFormResouce.TopTitle_TextSize,
TextAlignment = TextAlignment.CenterRight,
TextID = R.MyInternationalizationString.AllSelect
};
top.topView.AddChidren(selectAllBtn);
selectAllBtn.MouseUpEventHandler += (sender, e) =>
{
try
{
(sender as Button).IsSelected = !(sender as Button).IsSelected;
for (int i = 0; i < deviceListScrolView.ChildrenCount; i++)
{
var frame = deviceListScrolView.GetChildren(i) as FrameLayout;
(frame.GetChildren(0) as SelectFunctionView).IsSelected = (sender as Button).IsSelected;
}
if ((sender as Button).IsSelected)
{
(sender as Button).TextID = R.MyInternationalizationString.Cancel;
selectedList.AddRange(sameTypeList);
}
else
{
(sender as Button).TextID = R.MyInternationalizationString.AllSelect;
selectedList.Clear();
}
}
catch
{
}
};
var addBackground = new Button
{
Y = Application.GetRealHeight(1405),
Width = Application.GetMinRealAverage(1080),
Height = Application.GetMinRealAverage(202),
UnSelectedImagePath = "Room/AddBackground.png"
};
functionSceneBodyView.AddChidren(addBackground);
var add = new Button
{
Y = Application.GetRealHeight(1428),
Width = Application.GetRealWidth(1034),
Height = Application.GetRealHeight(156),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
TextColor = ZigbeeColor.Current.GXCTextSelectedColor4,
Radius = (uint)Application.GetRealHeight(35),
TextID = R.MyInternationalizationString.AddTo,
Gravity = Gravity.CenterHorizontal,
TextSize = 17
};
functionSceneBodyView.AddChidren(add);
add.MouseUpEventHandler += (sender, e) =>
{
var selectZone = new SelectZone();
AddChidren(selectZone);
selectZone.Init();
selectZone.ZoneAction = (r) =>
{
foreach (var d in selectedList)
{
r.AddDevice(d.CommonDevice, true);
deviceListScrolView.RemoveViewByTag(d);
}
RefreshData();
};
};
}
///
/// 提示没有功能
///
private void ShowNoFunctionTip()
{
return;
var noFunction = new Button()
{
Y = Application.GetRealHeight(320),
Width = Application.GetMinRealAverage(757),
Height = Application.GetMinRealAverage(435),
UnSelectedImagePath = "Item/NoFunction.png",
Gravity = Gravity.CenterHorizontal
};
functionSceneBodyView.AddChidren(noFunction);
var noFunctionTip = new Button()
{
Y = noFunction.Bottom + Application.GetRealHeight(32),
Height = Application.GetRealHeight(200),
Width = Application.GetRealWidth(700),
Gravity = Gravity.CenterHorizontal,
Text= Language.StringByID(R.MyInternationalizationString.NoFunction_Tip).Replace("{\\r\\n}", "\r\n"),
TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
TextAlignment = TextAlignment.Center,
IsMoreLines = true
};
functionSceneBodyView.AddChidren(noFunctionTip);
}
#endregion
#region ◆ 场景____________________________
///
/// 选择场景--所有房间的所有场景
///
public void ShowScene()
{
List selectedList = new List();
if (sceneList == null || sceneList.Count == 0)
{
ShowNoSceneTip();
}
else
{
var sceneScrolView = new VerticalScrolViewLayout
{
Y = Application.GetRealHeight(22),
Height=Application.GetRealHeight(1405-22)
};
functionSceneBodyView.AddChidren(sceneScrolView);
foreach (var sceneUI in sceneList)
{
var sceneFL = new FrameLayout()
{
Width = Application.GetRealWidth(CommonFormResouce.AppRealWidth),
Height = Application.GetRealHeight(397 + 58),
Gravity = Gravity.CenterHorizontal,
BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
Tag = sceneUI,
Radius = (uint)Application.GetRealHeight(17)
};
sceneScrolView.AddChidren(sceneFL);
var sceneImg = new ImageView()
{
X = Application.GetRealWidth(179),
Y = Application.GetRealHeight(58),
Width = Application.GetRealWidth(844),
Height = Application.GetRealHeight(397),
ImagePath = sceneUI.IconPath,
Radius = (uint)Application.GetRealHeight(17)
};
sceneFL.AddChidren(sceneImg);
var selectedBtn = new Button
{
X = Application.GetRealWidth(919),
Y = Application.GetRealHeight(92),
Width = Application.GetMinRealAverage(60),
Height = Application.GetMinRealAverage(60),
UnSelectedImagePath = "Room/ItemUnSelected.png",
SelectedImagePath = "Room/ItemSelected.png",
};
sceneFL.AddChidren(selectedBtn);
var leftFL = new FrameLayout
{
X = Application.GetRealWidth(CommonFormResouce.X_Left),
Y = Application.GetRealHeight(58 + 58),
Width = Application.GetRealWidth(251),
Height = Application.GetRealHeight(282),
BackgroundColor = ZigbeeColor.Current.GXCBlackBackgroundColor2
};
sceneFL.AddChidren(leftFL);
var collectionBtn = new Button
{
X = Application.GetRealWidth(23),
Y = Application.GetRealHeight(23),
Width = Application.GetMinRealAverage(65),
Height = Application.GetMinRealAverage(65),
UnSelectedImagePath = "Item/Collection.png",
SelectedImagePath = "Item/CollectionSelected.png"
};
leftFL.AddChidren(collectionBtn);
var sceneNameBtn = new Button()
{
Width = Application.GetRealWidth(176),
Height = Application.GetRealHeight(200),
TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
Text = sceneUI.Name,
Gravity = Gravity.Center,
IsMoreLines = true
};
leftFL.AddChidren(sceneNameBtn);
EventHandler eventHandler = (sender, e) =>
{
selectedBtn.IsSelected = !selectedBtn.IsSelected;
if (selectedBtn.IsSelected)
{
if (!selectedList.Contains(sceneUI))
{
selectedList.Add(sceneUI);
}
}
else
{
if (selectedList.Contains(sceneUI))
{
selectedList.Remove(sceneUI);
}
}
};
selectedBtn.MouseUpEventHandler += eventHandler;
sceneImg.MouseUpEventHandler += eventHandler;
}
selectAllBtn?.RemoveFromParent();
selectAllBtn = new Button()
{
X = Application.GetRealWidth(1080 - 150 - 80),
Width = Application.GetRealWidth(150),
Height = Application.GetRealHeight(80),
Gravity = Gravity.CenterVertical,
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
SelectedTextColor = ZigbeeColor.Current.GXCTextBlackColor,
TextSize = CommonFormResouce.TopTitle_TextSize,
TextAlignment = TextAlignment.CenterRight,
TextID = R.MyInternationalizationString.AllSelect
};
top.topView.AddChidren(selectAllBtn);
selectAllBtn.MouseUpEventHandler += (sender, e) =>
{
try
{
(sender as Button).IsSelected = !(sender as Button).IsSelected;
for (int i = 0; i < sceneScrolView.ChildrenCount; i++)
{
var frame = sceneScrolView.GetChildren(i) as FrameLayout;
(frame.GetChildren(1) as Button).IsSelected = (sender as Button).IsSelected;
}
if ((sender as Button).IsSelected)
{
(sender as Button).TextID = R.MyInternationalizationString.Cancel;
selectedList.AddRange(sceneList);
}
else
{
(sender as Button).TextID = R.MyInternationalizationString.AllSelect;
selectedList.Clear();
}
}
catch
{
}
};
var addBackground = new Button
{
Y = Application.GetRealHeight(1405),
Width = Application.GetMinRealAverage(1080),
Height = Application.GetMinRealAverage(202),
UnSelectedImagePath = "Room/AddBackground.png"
};
functionSceneBodyView.AddChidren(addBackground);
var add = new Button
{
Y = Application.GetRealHeight(1428),
Width = Application.GetRealWidth(1034),
Height = Application.GetRealHeight(156),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
TextColor = ZigbeeColor.Current.GXCTextSelectedColor4,
Radius = (uint)Application.GetRealHeight(35),
TextID = R.MyInternationalizationString.AddTo,
Gravity = Gravity.CenterHorizontal,
TextSize=17,
};
functionSceneBodyView.AddChidren(add);
add.MouseUpEventHandler += (sender, e) =>
{
var selectZone = new SelectZone();
CommonPage.Instance.AddChidren(selectZone);
selectZone.Init();
selectZone.ZoneAction = (r) =>
{
foreach (var s in selectedList)
{
r.AddScene(s);
sceneScrolView.RemoveViewByTag(s);
}
RefreshData();
};
};
}
}
///
/// 显示没有场景
///
private void ShowNoSceneTip()
{
return;
var noFunction = new Button()
{
Y = Application.GetRealHeight(320),
Width = Application.GetMinRealAverage(757),
Height = Application.GetMinRealAverage(435),
UnSelectedImagePath = "Item/NoFunction.png",
Gravity = Gravity.CenterHorizontal
};
functionSceneBodyView.AddChidren(noFunction);
var noScenceTip = new Button()
{
Y = noFunction.Bottom + Application.GetRealHeight(32),
Height = Application.GetRealHeight(200),
Width = Application.GetRealWidth(700),
Gravity = Gravity.CenterHorizontal,
Text = Language.StringByID(R.MyInternationalizationString.NoScene_Tip).Replace("{\\r\\n}", "\r\n"),
TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
TextAlignment = TextAlignment.Center,
IsMoreLines = true
};
functionSceneBodyView.AddChidren(noScenceTip);
}
#endregion
}
}