using System;
using System.Collections.Generic;
namespace Shared.Phone.UserCenter.SmartSound.Forms
{
public class SmartSoundContentForDevice : EditorCommonForm
{
///
/// 当前选中的房间
///
private SmartSound.Room CurrentRoom = null;
private FrameLayout ContentLayout = null;
private VerticalListControl listView = null;
///
/// 没有数据的时候,提示用
///
private FrameLayout TipLayout = null;
private List TabList = new List()
{
Language.StringByID(R.MyInternationalizationString.uLight),
Language.StringByID(R.MyInternationalizationString.uDeviceBelongId100),
Language.StringByID(R.MyInternationalizationString.AC)
};
private int CurrentSelectIndex = 0;
private int imageWith = 683;
private int imageHeight = 392;
///
/// 选择房间中的设备
///
/// 当前房间
public SmartSoundContentForDevice(SmartSound.Room _room)
{
this.CurrentRoom = _room;
}
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
public void ShowForm()
{
//设置标题信息
base.SetTitleText(CurrentRoom.RoomName);
//初始化中部控件
this.InitMiddleFrame();
}
private void InitMiddleFrame()
{
//1.场景、功能导航条
var switchContr = new SceneFunctionSwitchControl();
this.bodyFrameLayout.AddChidren(switchContr);
switchContr.Gravity = Gravity.CenterVertical;
switchContr.Width = Application.GetRealWidth(650);
switchContr.Y = Application.GetRealHeight(40);
ContentLayout = new FrameLayout();
this.bodyFrameLayout.AddChidren(ContentLayout);
ContentLayout.Height = this.bodyFrameLayout.Height - switchContr.Height - Application.GetRealHeight(40);
ContentLayout.Y = switchContr.Height + Application.GetRealHeight(40);
var listTitle = new List();
listTitle.Add(Language.StringByID(R.MyInternationalizationString.uScence));
listTitle.Add(Language.StringByID(R.MyInternationalizationString.uFunction));
//设置初始值
switchContr.SetDefultIndex(0);
//选择事件
switchContr.SelectTabEvent += (selectIndex) =>
{
//刷新bodyView
if (selectIndex == 0)
{
LoadSceneView();
}
else
{
LoadFunction();
}
};
//开始初始化
switchContr.InitControl(listTitle);
//添加确认按钮
BottomClickButton bottomClickButton = new BottomClickButton();
this.bodyFrameLayout.AddChidren(bottomClickButton);
bottomClickButton.Text = "确认";
bottomClickButton.ButtonClickEvent += (sender, e) =>
{
//保存数据
base.CloseForm();
};
}
///
/// 加载场景界面
///
private void LoadSceneView()
{
try
{
//3.设备列表 ListView
ContentLayout.RemoveAll();
var tipLayout = new FrameLayout();
ContentLayout.AddChidren(tipLayout);
tipLayout.Visible = false;
ShowNoFunctionTip(tipLayout);
listView = new VerticalListControl();
ContentLayout.AddChidren(listView);
listView.Y = Application.GetRealHeight(40);
listView.RemoveAll();
for (int i = 0; i < CurrentRoom.SceneList.Count; i++)
{
SmartSound.Scene scene = CurrentRoom.SceneList[i];
var roomRowLayout = new SceneRowLayout(this, scene);
listView.AddChidren(roomRowLayout);
roomRowLayout.InitControl();
}
if (listView.ChildrenCount == 0)
{
tipLayout.Visible = true;
}
else
{
tipLayout.Visible = false;
}
if (listView.ChildrenCount > 5)
{
TextView textView = new TextView();
textView.Height = Application.GetRealHeight(127 * 3);
listView.AddChidren(textView);
}
}
catch (Exception ex)
{
string eoor = ex.Message;
}
}
private void LoadFunction()
{
try
{
//2.功能类型选择(灯光、遮阳、空调)
//3.设备列表 ListView
this.ContentLayout.RemoveAll();
FrameLayout tab_layout = new FrameLayout();
ContentLayout.AddChidren(tab_layout);
tab_layout.Height = Application.GetRealHeight(170);
tab_layout.Y = 0;
//添加 ListView 提示
TipLayout = new FrameLayout();
ContentLayout.AddChidren(TipLayout);
TipLayout.Visible = false;
TipLayout.Y= tab_layout.Height;
ShowNoFunctionTip(TipLayout);
//添加 ListView
listView = new VerticalListControl();
ContentLayout.AddChidren(listView);
listView.Y= tab_layout.Height;
listView.Height=ContentLayout.Height- tab_layout.Height;
Buttons.Clear();
//添加功能项
for (int i = 0; i < TabList.Count; i++)
{
Button button = new Button();
tab_layout.AddChidren(button);
button.Width = Application.GetRealWidth(250);
button.Text = TabList[i];
button.X = HdlControlResourse.XXLeft/2 + i * button.Width;
button.AddTag("Index", i);
Buttons.Add(button);
button.MouseUpEventHandler += (sender, e) =>
{
Button btn = sender as Button;
CurrentSelectIndex = (int)btn.GetTagByKey("Index");
RefreshButtonState();
RefreshFunctionListView();
};
}
RefreshButtonState();
RefreshFunctionListView();
}
catch (Exception ex)
{
string error = ex.Message;
}
}
private void RefreshFunctionListView()
{
try
{
listView.RemoveAll();
switch (CurrentSelectIndex)
{
case 0: // 灯光
{
for (int i = 0; i < CurrentRoom.DeviceList.Count; i++)
{
SmartSound.Device device = CurrentRoom.DeviceList[i];
// 灯光
if (device.DeviceType == 1 || device.DeviceType == 2 || device.DeviceType == 3)
{
var deviceRowLayout = new DeviceRowLayout(this, device);
listView.AddChidren(deviceRowLayout);
deviceRowLayout.InitControl();
}
}
}
break;
case 1: // 窗帘
{
for (int i = 0; i < CurrentRoom.DeviceList.Count; i++)
{
SmartSound.Device device = CurrentRoom.DeviceList[i];
//
if (device.DeviceType == 4 || device.DeviceType == 5 || device.DeviceType == 6)
{
var deviceRowLayout = new DeviceRowLayout(this, device);
listView.AddChidren(deviceRowLayout);
deviceRowLayout.InitControl();
}
}
}
break;
case 2: // 空调
{
for (int i = 0; i < CurrentRoom.DeviceList.Count; i++)
{
SmartSound.Device device = CurrentRoom.DeviceList[i];
//
if (device.DeviceType == 7)
{
var deviceRowLayout = new DeviceRowLayout(this, device);
listView.AddChidren(deviceRowLayout);
deviceRowLayout.InitControl();
}
}
}
break;
}
if (listView.ChildrenCount > 5)
{
TextView textView = new TextView();
textView.Height = Application.GetRealHeight(127 * 3);
listView.AddChidren(textView);
}
if (listView.ChildrenCount == 0)
{
TipLayout.Visible = true;
}
else
{
TipLayout.Visible = false;
}
}
catch (Exception e)
{
string error = e.Message;
}
}
///
/// 提示没有功能
///
private void ShowNoFunctionTip(FrameLayout layout,string tip="没有数据哦")
{
var noFunction = new Button()
{
Y = Application.GetRealHeight(320),
Width = Application.GetMinRealAverage(757),
Height = Application.GetMinRealAverage(435),
UnSelectedImagePath = "Item/NoFunction.png",
Gravity = Gravity.CenterHorizontal
};
layout.AddChidren(noFunction);
var noFunctionTip = new Button()
{
Y = noFunction.Bottom + Application.GetRealHeight(32),
Height = Application.GetRealHeight(200),
Width = Application.GetRealWidth(700),
Gravity = Gravity.CenterHorizontal,
Text = tip,
TextColor = UserCenterColor.Current.TextGrayColor1,
TextAlignment = TextAlignment.Center,
IsMoreLines = true
};
layout.AddChidren(noFunctionTip);
}
//为了方便更新状态,存起来
private List