using System;
using System.Collections.Generic;
using Shared.Common;
namespace Shared.Phone.Device.Category
{
///
/// Category scene select light setting.
///
public class CategorySceneSelectLightSetting:FrameLayout
{
///
/// Initializes a new instance of the
/// class.
///
public CategorySceneSelectLightSetting()
{
BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor;
Tag = "categoryAddScene";
}
///
/// 显示灯光的详细设置界面 默认-1(新增-默认开),0关 ,1开
///
/// Device.
/// Target device identifier.
/// 默认-1(新增-默认开),0关 ,1开..
/// If set to true is from room.
public void Show(DeviceUI device, string targetDeviceID="", int state=-1, bool isFromRoom = false)
{
#region topview
var topBGView = new FrameLayout()
{
Height = Application.GetRealHeight(CommonPage.Navigation_Height),
BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor
};
AddChidren(topBGView);
var 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()
{
Text = device.CommonDevice.DeviceEpointName != "" ? device.CommonDevice.DeviceEpointName : Language.StringByID(R.MyInternationalizationString.UnknowDevice),
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 midFL
var midFL = new VerticalScrolViewLayout()
{
Y = topView.Bottom,
Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
ScrollEnabled = false
};
AddChidren(midFL);
var openRowView = new RowLayout()
{
Height = Application.GetRealHeight(170),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
LineColor = ZigbeeColor.Current.GXCLineColor
};
midFL.AddChidren(openRowView);
var openFL = new FrameLayout()
{
Height = Application.GetRealHeight(170),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
};
openRowView.AddChidren(openFL);
var openBtn = new Button()
{
X = Application.GetRealWidth(50),
Width = Application.GetRealWidth(500),
TextID = R.MyInternationalizationString.Open,
TextAlignment = TextAlignment.CenterLeft,
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
SelectedTextColor=ZigbeeColor.Current.GXCTextBlueColor,
BackgroundColor=ZigbeeColor.Current.GXCBackgroundColor,
//SelectedBackgroundColor=ZigbeeColor.Current.GXCBlack70Color,
Gravity = Gravity.CenterVertical
};
openFL.AddChidren(openBtn);
var openBtnSelected = new Button()
{
X = openRowView.Width - Application.GetRealWidth(150),
Width = Application.GetMinRealAverage(110),
Height = Application.GetMinRealAverage(110),
UnSelectedImagePath = "Item/YesSelected.png",
Visible=false,
Gravity = Gravity.CenterVertical
};
openFL.AddChidren(openBtnSelected);
var closeRowView = new RowLayout()
{
Height = Application.GetRealHeight(170),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
LineColor = ZigbeeColor.Current.GXCLineColor
};
midFL.AddChidren(closeRowView);
var closeFL = new FrameLayout()
{
Height = Application.GetRealHeight(170),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
};
closeRowView.AddChidren(closeFL);
var closeBtn = new Button()
{
X = Application.GetRealWidth(50),
Width = Application.GetRealWidth(500),
TextID = R.MyInternationalizationString.uSimpleClose,
TextAlignment = TextAlignment.CenterLeft,
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor,
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
//SelectedBackgroundColor = ZigbeeColor.Current.GXCBlack70Color,
Gravity = Gravity.CenterVertical
};
closeFL.AddChidren(closeBtn);
var closeBtnSelected = new Button()
{
X = openRowView.Width - Application.GetRealWidth(150),
Width = Application.GetMinRealAverage(110),
Height = Application.GetMinRealAverage(110),
UnSelectedImagePath = "Item/YesSelected.png",
Visible = false,
Gravity = Gravity.CenterVertical
};
closeFL.AddChidren(closeBtnSelected);
var dimmingRowView = new RowLayout()
{
Height = Application.GetRealHeight(170),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
LineColor = ZigbeeColor.Current.GXCLineColor
};
//midFL.AddChidren(dimmingRowView);
var dimmingBtn = new Button()
{
X = Application.GetRealWidth(50),
Width = Application.GetRealWidth(500),
TextID = R.MyInternationalizationString.Dimming,
TextAlignment = TextAlignment.CenterLeft,
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor,
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
SelectedBackgroundColor = ZigbeeColor.Current.GXCBlack70Color,
Gravity = Gravity.CenterVertical
};
dimmingRowView.AddChidren(dimmingBtn);
var dimmingNextBtn = new Button()
{
X = closeRowView.Width - Application.GetRealWidth(150),
Height = Application.GetMinRealAverage(110),
Width = Application.GetMinRealAverage(110),
UnSelectedImagePath = "Item/Next.png",
SelectedImagePath = "Item/DownSelected.png",
Gravity = Gravity.CenterVertical
};
dimmingRowView.AddChidren(dimmingNextBtn);
var confirmBtn = new CommonForm.CompleteButton() { };
AddChidren(confirmBtn);
if (state == -1)
{
closeBtn.IsSelected = false;
openBtn.IsSelected = true;
closeBtnSelected.Visible = false;
openBtnSelected.Visible = true;
}
else if (state == 0)
{
closeBtn.IsSelected = true;
openBtn.IsSelected = false;
closeBtnSelected.Visible = true;
openBtnSelected.Visible = false;
}
else if (state == 1)
{
closeBtn.IsSelected = false;
openBtn.IsSelected = true;
closeBtnSelected.Visible = false;
openBtnSelected.Visible = true;
}
#endregion
#region event
EventHandler openEvent = (sender, e) =>
{
openBtn.IsSelected = true;
closeBtn.IsSelected = false;
openBtnSelected.Visible = true;
closeBtnSelected.Visible = false;
};
openBtn.MouseUpEventHandler += openEvent;
openFL.MouseUpEventHandler+= openEvent;
EventHandler closeEvent = (sender, e) =>
{
openBtn.IsSelected = false;
closeBtn.IsSelected = true;
openBtnSelected.Visible = false;
closeBtnSelected.Visible = true;
};
closeBtn.MouseUpEventHandler += closeEvent;
closeFL.MouseUpEventHandler+= closeEvent;
EventHandler nextHandler = (sender, e) =>
{
openBtn.IsSelected = false;
closeBtn.IsSelected = false;
dimmingBtn.IsSelected = true;
dimmingNextBtn.IsSelected = !dimmingNextBtn.IsSelected;
if (dimmingNextBtn.IsSelected)
{
var dimmingSliderRowView = new RowLayout()
{
Height = Application.GetRealHeight(240),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
LineColor = ZigbeeColor.Current.GXCBackgroundColor,
Tag = "deviceRowViewDetail"
};
midFL.AddChidren(dimmingSliderRowView);
var seekBar = new HorizontalSeekBar()
{
X=Application.GetRealWidth(50),
Width=Application.GetRealWidth(1080-200-50),
Gravity=Gravity.CenterVertical,
BackgroundColor=ZigbeeColor.Current.GXCSliderUnSelectedColor,
ProgressColor=ZigbeeColor.Current.GXCButtonBlueColor,
ThumbColor=ZigbeeColor.Current.GXCButtonBlueColor,
Max=100,
Progress=50
};
dimmingSliderRowView.AddChidren(seekBar);
var seekBarTitle = new Button()
{
X = Application.GetRealWidth(1080 - 200),
Width = Application.GetRealWidth(150),
Gravity = Gravity.CenterVertical,
Text = $"{seekBar.Progress}%",
TextColor = ZigbeeColor.Current.GXCTextBlackColor
};
dimmingSliderRowView.AddChidren(seekBarTitle);
seekBar.ProgressChanged += (sender2, e2) =>
{
seekBarTitle.Text = $"{seekBar.Progress}%";
};
}
else
{
midFL.RemoveViewByTag("deviceRowViewDetail");
}
};
dimmingNextBtn.MouseUpEventHandler += nextHandler;
dimmingRowView.MouseUpEventHandler += nextHandler;
//确定
confirmBtn.MouseUpEventHandler += (sender, e) =>
{
if (device.CommonDevice == null) return;
var taskList = new List { };
int taskType=1;
int data1=0;
int data2=0;
if(openBtn.IsSelected){
//开
taskType = 1;
data1 = 1;
data2 = 0;
}
else if(closeBtn.IsSelected){
//关
taskType = 1;
data1 = 0;
data2 = 0;
}
var taskInfo = new ZigBee.Device.Scene.TaskListInfo
{
TaskType = taskType,
Data1 = data1,
Data2 = data2
};
taskList.Add(taskInfo);
var sceneTargetDevice = new SceneTargetDeviceUI{};
sceneTargetDevice.Type = 0;
sceneTargetDevice.DeviceUI = device;
sceneTargetDevice.TaskList = taskList;
//新增的
if (state==-1)
{
if (isFromRoom)
{
//回到房间添加场景界面
var sameScene = Room.AddRoomScene.sceneTargetDevicesList.Find((obj) => obj.DeviceUI == sceneTargetDevice.DeviceUI);
if (sameScene == null)
{
Room.AddRoomScene.sceneTargetDevicesList.Add(sceneTargetDevice);
UserView.HomePage.Instance.RemoveViewByTag("categoryAddScene");
var roomAddScene = new Room.AddRoomScene();
UserView.HomePage.Instance.AddChidren(roomAddScene);
UserView.HomePage.Instance.PageIndex += 1;
roomAddScene.Show(Room.AddRoomScene.CurrentRoom);
}
else
{
//提示该设备已加入
var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.ThisSceneHadTheDevice), Language.StringByID(R.MyInternationalizationString.Close));
alert.Show();
alert.ResultEventHandler += (sendAlert, eAlert) =>
{
return;
};
}
}
else
{
//回到分类
var sameScene = CategoryAddScene.sceneTargetDevicesList.Find((obj) => obj.DeviceUI == sceneTargetDevice.DeviceUI);
if (sameScene == null)
{
CategoryAddScene.sceneTargetDevicesList.Add(sceneTargetDevice);
UserView.HomePage.Instance.RemoveViewByTag("categoryAddScene");
var categoryAddScene = new CategoryAddScene();
UserView.HomePage.Instance.AddChidren(categoryAddScene);
UserView.HomePage.Instance.PageIndex += 1;
categoryAddScene.Show();
}
else
{
//提示该设备已加入
var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.ThisSceneHadTheDevice), Language.StringByID(R.MyInternationalizationString.Close));
alert.Show();
alert.ResultEventHandler += (sendAlert, eAlert) =>
{
return;
};
}
}
}
//修改
else
{
if (isFromRoom)
{
var targetDeviceUI = Room.AddRoomScene.sceneTargetDevicesList.Find((obj) => obj.SceneTargetDeviceUIID == targetDeviceID);
if (targetDeviceUI != null)
{
targetDeviceUI.Type = sceneTargetDevice.Type;
targetDeviceUI.DeviceUI = sceneTargetDevice.DeviceUI;
targetDeviceUI.TaskList = sceneTargetDevice.TaskList;
}
UserView.HomePage.Instance.RemoveViewByTag("categoryAddScene");
var roomAddScene = new Room.AddRoomScene();
UserView.HomePage.Instance.AddChidren(roomAddScene);
UserView.HomePage.Instance.PageIndex += 1;
roomAddScene.Show(Room.AddRoomScene.CurrentRoom);
}
else
{
var targetDeviceUI = CategoryAddScene.sceneTargetDevicesList.Find((obj) => obj.SceneTargetDeviceUIID == targetDeviceID);
if (targetDeviceUI != null)
{
targetDeviceUI.Type = sceneTargetDevice.Type;
targetDeviceUI.DeviceUI = sceneTargetDevice.DeviceUI;
targetDeviceUI.TaskList = sceneTargetDevice.TaskList;
}
UserView.HomePage.Instance.RemoveViewByTag("categoryAddScene");
var categoryAddScene = new CategoryAddScene();
UserView.HomePage.Instance.AddChidren(categoryAddScene);
UserView.HomePage.Instance.PageIndex += 1;
categoryAddScene.Show();
}
}
};
#endregion
}
}
}