using System;
using System.Collections.Generic;
using Shared.Common;
namespace Shared.Phone.Device.Category
{
public class CategorySceneSelectedDimmableLightSetting : FrameLayout
{
///
/// 最大亮度调节-254
///
private readonly int MaxLevel = 254;
public override void RemoveFromParent()
{
UserView.HomePage.Instance.ScrollEnabled = true;
base.RemoveFromParent();
}
public CategorySceneSelectedDimmableLightSetting()
{
BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor;
Tag = "categoryAddScene";
}
///
/// 显示卷帘的详细设置界面 默认state = -1(新增--默认打开) 0 关闭 1打开 3百分比, percent =-1不选择 百分比
///
/// Device.
/// Target device identifier.
/// State.
/// Percent.
/// If set to true is from room.
public void Show(DeviceUI device, string targetDeviceID = "", int state = -1, int percent = -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 percentRowView = new RowLayout()
{
Height = Application.GetRealHeight(170),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
LineColor = ZigbeeColor.Current.GXCLineColor
};
midFL.AddChidren(percentRowView);
var percentBtn = new Button()
{
X = Application.GetRealWidth(50),
Width = Application.GetRealWidth(500),
TextID = R.MyInternationalizationString.Percent,
TextAlignment = TextAlignment.CenterLeft,
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor,
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
//SelectedBackgroundColor = ZigbeeColor.Current.GXCBlack70Color,
Gravity = Gravity.CenterVertical
};
percentRowView.AddChidren(percentBtn);
//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
//};
//percentRowView.AddChidren(dimmingNextBtn);
var percentSliderRowView = new RowLayout()
{
Height = Application.GetRealHeight(240),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
LineColor = ZigbeeColor.Current.GXCBackgroundColor,
Tag = "deviceRowViewDetail"
};
midFL.AddChidren(percentSliderRowView);
var seekBar = new HorizontalSeekBar()
{
X = Application.GetRealWidth(CommonPage.XLeft),
Width = Application.GetRealWidth(CommonPage.AppRealWidth - 200 - CommonPage.XLeft),
Gravity = Gravity.CenterVertical,
BackgroundColor = ZigbeeColor.Current.GXCSliderUnSelectedColor,
ProgressColor = ZigbeeColor.Current.GXCButtonBlueColor,
ThumbColor = ZigbeeColor.Current.GXCButtonBlueColor,
Max = MaxLevel,
Progress = (state == 3 && percent != -1) ? percent : 0
};
percentSliderRowView.AddChidren(seekBar);
var seekBarTitle = new Button()
{
X = Application.GetRealWidth(CommonPage.AppRealWidth - 200),
Width = Application.GetRealWidth(200),
Gravity = Gravity.CenterVertical,
Text = $"{(int)(seekBar.Progress/(MaxLevel*1.0)*100)} %",
TextColor = ZigbeeColor.Current.GXCTextBlackColor
};
percentSliderRowView.AddChidren(seekBarTitle);
var confirmBtn = new Device.CommonForm.CompleteButton(1,2,3);
AddChidren(confirmBtn);
if (state == -1)
{
closeBtn.IsSelected = false;
closeBtnSelected.Visible = false;
openBtn.IsSelected = true;
openBtnSelected.Visible = true;
percentBtn.IsSelected = false;
}
else if (state == 1)
{
closeBtn.IsSelected = false;
closeBtnSelected.Visible = false;
openBtn.IsSelected = true;
openBtnSelected.Visible = true;
percentBtn.IsSelected = false;
}
else if (state == 0)
{
closeBtn.IsSelected = true;
closeBtnSelected.Visible = true;
openBtn.IsSelected = false;
openBtnSelected.Visible = false;
percentBtn.IsSelected = false;
}
else if (state == 3)
{
closeBtn.IsSelected = false;
closeBtnSelected.Visible = false;
openBtn.IsSelected = false;
openBtnSelected.Visible = false;
percentBtn.IsSelected = true;
}
#endregion
#region event
seekBar.ProgressChanged += (sender2, e2) =>
{
openBtn.IsSelected = false;
openBtnSelected.Visible = false;
closeBtn.IsSelected = false;
closeBtnSelected.Visible = false;
percentBtn.IsSelected = true;
seekBarTitle.Text = $"{(int)(seekBar.Progress/ (MaxLevel*1.0)*100)}%";
};
EventHandler openEvent = (sender, e) =>
{
openBtn.IsSelected = true;
openBtnSelected.Visible = true;
closeBtn.IsSelected = false;
closeBtnSelected.Visible = false;
percentBtn.IsSelected = false;
seekBar.Progress = 0;
seekBarTitle.Text = "0%";
};
openBtn.MouseUpEventHandler += openEvent;
openRowView.MouseUpEventHandler += openEvent;
openFL.MouseUpEventHandler += openEvent;
EventHandler closeEvent = (sender, e) =>
{
openBtn.IsSelected = false;
openBtnSelected.Visible = false;
closeBtn.IsSelected = true;
closeBtnSelected.Visible = true;
percentBtn.IsSelected = false;
seekBar.Progress = 0;
seekBarTitle.Text = "0%";
};
closeBtn.MouseUpEventHandler += closeEvent;
closeRowView.MouseUpEventHandler += closeEvent;
closeFL.MouseUpEventHandler += closeEvent;
EventHandler nextHandler = (sender, e) =>
{
//openBtn.IsSelected = false;
//closeBtn.IsSelected = false;
//percentBtn.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;
//percentRowView.MouseUpEventHandler += nextHandler;
//确定
confirmBtn.MouseUpEventHandler += (sender, e) =>
{
if (device.CommonDevice == null) return;
var taskList = new List { };
/// 任务类型。
///1:开关 (设备具有开关功能时可用)
///3:亮度调整(设备具有亮度调节功能时可用)
/// Data1取值
/// 开关 :Data1(数值): 0关/1开
///亮度调整 Data1(数值):亮度值
/// Data2取值
/// 开关 Data2(数值): 0
/// 亮度调整 Data2(数值): 0
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;
}
else if (percentBtn.IsSelected)
{
//百分比
taskType = 3;
data1 = seekBar.Progress;
data2 = 0;
}
var taskInfo = new ZigBee.Device.Scene.TaskListInfo
{
TaskType = taskType,
Data1 = data1,
Data2 = data2
};
taskList.Add(taskInfo);
var sceneTargetDevice = new SceneTargetDeviceUI { };
sceneTargetDevice.DeviceUI = device;
sceneTargetDevice.TaskList = taskList;
sceneTargetDevice.Type = 0;
//新增的
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.DeviceUI = sceneTargetDevice.DeviceUI;
targetDeviceUI.TaskList = sceneTargetDevice.TaskList;
targetDeviceUI.Type = sceneTargetDevice.Type;
}
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.DeviceUI = sceneTargetDevice.DeviceUI;
// targetDeviceUI.TaskList = sceneTargetDevice.TaskList;
// targetDeviceUI.Type = sceneTargetDevice.Type;
//}
//UserView.HomePage.Instance.RemoveViewByTag("categoryAddScene");
//var categoryAddScene = new CategoryAddScene();
//UserView.HomePage.Instance.AddChidren(categoryAddScene);
//UserView.HomePage.Instance.PageIndex += 1;
//categoryAddScene.Show();
}
}
};
#endregion
}
}
}