using System;
|
using System.Collections.Generic;
|
using System.Globalization;
|
using Shared.Common;
|
using Shared.Phone.Device.Room;
|
using static ZigBee.Device.Scene;
|
|
namespace Shared.Phone.Device.Category
|
{
|
public class CategoryAddScene:FrameLayout
|
{
|
public static string ImagePath;
|
public static string SceneText;
|
public static Shared.Common.Room CurrentRoom;
|
public static List<SceneTargetDeviceUI> sceneTargetDevicesList=new List<SceneTargetDeviceUI>{};
|
/// <summary>
|
/// 记录编辑前的设备列表
|
/// </summary>
|
public static List<SceneTargetDeviceUI> beforeSceneTargetDevicesList = new List<SceneTargetDeviceUI> { };
|
public static bool Modify = false;
|
public static SceneUI ModifySceneUI = null;
|
/// <summary>
|
/// 图片来源 0--本地图库 1--拍照 2--系统图库
|
/// </summary>
|
public static int IconType = 0;
|
/// <summary>
|
/// 添加目标后的展示列表
|
/// </summary>
|
public VerticalScrolViewLayout TargetListScrolView;
|
/// <summary>
|
/// 添加的执行目标的行高
|
/// </summary>
|
private readonly int TargetListScrolView_RowHeight = 170;
|
/// <summary>
|
/// The confirm button.
|
/// </summary>
|
private CommonForm.CompleteButton confirmBtn;
|
/// <summary>
|
/// 确定按钮最开始的坐标
|
/// </summary>
|
private readonly int ConfirmButton_Y = CommonPage.AppRealHeight - 300;
|
/// <summary>
|
/// 确定按钮下移后的坐标
|
/// </summary>
|
private readonly int ConfirmButton_Change_Y = CommonPage.AppRealHeight - 130;
|
/// <summary>
|
/// 记录更改前的房间
|
/// </summary>
|
private Shared.Common.Room oldRoom;
|
|
public CategoryAddScene()
|
{
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
|
Tag = "categoryAddScene";
|
}
|
public override void RemoveFromParent()
|
{
|
Category.instance?.RefreshBodyView();
|
base.RemoveFromParent();
|
}
|
/// <summary>
|
///刷新添加目标后的展示列表
|
/// </summary>
|
public void RefreshTargetListView()
|
{
|
TargetListScrolView.RemoveAll();
|
if (sceneTargetDevicesList.Count >= 2)
|
{
|
TargetListScrolView.Height = Application.GetRealHeight(TargetListScrolView_RowHeight * 3);
|
confirmBtn.Y = Application.GetRealHeight(ConfirmButton_Change_Y);
|
}
|
else
|
{
|
TargetListScrolView.Height = Application.GetRealHeight(TargetListScrolView_RowHeight * 2);
|
confirmBtn.Y = Application.GetRealHeight(ConfirmButton_Y);
|
}
|
|
if (sceneTargetDevicesList.Count > 0)
|
{
|
foreach (var targetDevice in sceneTargetDevicesList)
|
{
|
string devImgPath = string.Empty;
|
string devNameText = string.Empty;
|
if (targetDevice.Type==0)
|
{
|
if (targetDevice.DeviceUI == null || targetDevice.DeviceUI.CommonDevice == null) continue;
|
devImgPath = targetDevice.DeviceUI.IconPath;
|
devNameText = targetDevice.DeviceUI.CommonDevice.DeviceEpointName;
|
}
|
else if(targetDevice.Type==1)
|
{
|
devImgPath = "Item/Timer.png";
|
devNameText = $"{targetDevice.DelayTime} {Language.StringByID(R.MyInternationalizationString.Second)}";
|
}
|
else if(targetDevice.Type==2)
|
{
|
devImgPath = "Item/Scene.png";
|
devNameText = targetDevice.SceneName;
|
}
|
var targetRowLayout = new RowLayout()
|
{
|
LineColor = ZigbeeColor.Current.GXCLineColor,
|
Height = Application.GetRealHeight(170)
|
};
|
TargetListScrolView.AddChidren(targetRowLayout);
|
|
var targetFL = new FrameLayout()
|
{
|
|
};
|
targetRowLayout.AddChidren(targetFL);
|
|
var devIMG = new Button()
|
{
|
X = Application.GetRealWidth(CommonPage.XLeft),
|
Width = Application.GetMinRealAverage(110),
|
Height = Application.GetMinRealAverage(110),
|
UnSelectedImagePath = devImgPath,
|
Gravity = Gravity.CenterVertical
|
};
|
targetRowLayout.AddChidren(devIMG);
|
var devName = new Button()
|
{
|
X = devIMG.Right,
|
Width = Application.GetRealWidth(500),
|
Height = Application.GetRealHeight(100),
|
Gravity = Gravity.CenterVertical,
|
Text = devNameText,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
TextAlignment = TextAlignment.CenterLeft
|
};
|
targetRowLayout.AddChidren(devName);
|
var devTimer = new Button()
|
{
|
X = targetRowLayout.Width - Application.GetRealWidth(150),
|
Width = Application.GetMinRealAverage(110),
|
Height = Application.GetMinRealAverage(110),
|
UnSelectedImagePath = "Item/Timer.png",
|
Gravity = Gravity.CenterVertical
|
};
|
/////******暂时先不加延时,安卓控件有问题*******////
|
//targetRowLayout.AddChidren(devTimer);
|
var devRight = new Button()
|
{
|
BackgroundColor = ZigbeeColor.Current.GXCRedColor,
|
TextID = R.MyInternationalizationString.Delete,
|
TextColor = ZigbeeColor.Current.GXCTextWhiteColor
|
};
|
targetRowLayout.AddRightView(devRight);
|
//延时
|
devTimer.MouseUpEventHandler += (sender, e) =>
|
{
|
/////******暂时先不加延时,安卓控件有问题*******////
|
var tList = new List<string> { };
|
for(int i=1;i<=60;i++)
|
{
|
tList.Add($"{i} {Language.StringByID(R.MyInternationalizationString.Second)}");
|
}
|
//1-60秒
|
PickerView.Show(tList, (obj) =>
|
{
|
targetDevice.DelayTime =int.Parse(tList[obj].Split(' ')[0]);
|
},0,"",Language.StringByID(R.MyInternationalizationString.Confrim));
|
};
|
//删除设备
|
devRight.MouseUpEventHandler += (sender, e) =>
|
{
|
sceneTargetDevicesList.Remove(targetDevice);
|
RefreshTargetListView();
|
};
|
|
//设备详细设置界面
|
void detailMouseUpEventHandler(object sender, MouseEventArgs e)
|
{
|
//设备
|
if (targetDevice.Type == 0)
|
{
|
if (targetDevice.DeviceUI == null || targetDevice.DeviceUI.CommonDevice == null)
|
{
|
return;
|
}
|
if (targetDevice.DeviceUI.CommonDevice.Type == ZigBee.Device.DeviceType.OnOffOutput)
|
{
|
//开关灯
|
var taskList = targetDevice.TaskList;
|
if (taskList.Count == 0)
|
{
|
return;
|
}
|
var detail = new CategorySceneSelectLightSetting();
|
UserView.HomePage.Instance.AddChidren(detail);
|
UserView.HomePage.Instance.PageIndex += 1;
|
detail.Show(targetDevice.DeviceUI,targetDevice.SceneTargetDeviceUIID, taskList[0].Data1);
|
}
|
else if (targetDevice.DeviceUI.CommonDevice.Type == ZigBee.Device.DeviceType.AirSwitch)
|
{
|
//空气开关
|
var taskList = targetDevice.TaskList;
|
if (taskList.Count == 0)
|
{
|
return;
|
}
|
var detail = new CategorySceneSelectAirSwitchSetting();
|
UserView.HomePage.Instance.AddChidren(detail);
|
UserView.HomePage.Instance.PageIndex += 1;
|
detail.Show(targetDevice.DeviceUI, targetDevice.SceneTargetDeviceUIID, taskList[0].Data1);
|
}
|
else if (targetDevice.DeviceUI.CommonDevice.Type == ZigBee.Device.DeviceType.WindowCoveringDevice)
|
{
|
//卷帘
|
var taskList = targetDevice.TaskList;
|
if (taskList.Count == 0)
|
{
|
return;
|
}
|
var detail = new CategorySceneSelectCurtainSetting();
|
UserView.HomePage.Instance.AddChidren(detail);
|
UserView.HomePage.Instance.PageIndex += 1;
|
UserView.HomePage.Instance.ScrollEnabled = false;
|
detail.Show(targetDevice.DeviceUI, targetDevice.SceneTargetDeviceUIID, taskList[0].Data1, taskList[0].Data2);
|
}
|
else if (targetDevice.DeviceUI.CommonDevice.Type == ZigBee.Device.DeviceType.DimmableLight)
|
{
|
//调光灯
|
var taskList = targetDevice.TaskList;
|
if (taskList.Count == 0)
|
{
|
return;
|
}
|
var detail = new CategorySceneSelectedDimmableLightSetting();
|
UserView.HomePage.Instance.AddChidren(detail);
|
UserView.HomePage.Instance.PageIndex += 1;
|
UserView.HomePage.Instance.ScrollEnabled = false;
|
if(taskList[0].TaskType==1)
|
{
|
detail.Show(targetDevice.DeviceUI, targetDevice.SceneTargetDeviceUIID, taskList[0].Data1, taskList[0].Data2);
|
}
|
else if(taskList[0].TaskType==3)
|
{
|
detail.Show(targetDevice.DeviceUI, targetDevice.SceneTargetDeviceUIID, taskList[0].TaskType, taskList[0].Data1);
|
|
}
|
|
|
}
|
|
}
|
//时间间隔
|
else if (targetDevice.Type == 1)
|
{
|
var delayTimeView = new CategorySceneSelectedDelayTime();
|
UserView.HomePage.Instance.AddChidren(delayTimeView);
|
UserView.HomePage.Instance.PageIndex += 1;
|
delayTimeView.Show(1,targetDevice.SceneTargetDeviceUIID);
|
}
|
//场景
|
else if (targetDevice.Type == 2)
|
{
|
var sceneView = new CategorySceneSelectedScene();
|
UserView.HomePage.Instance.AddChidren(sceneView);
|
UserView.HomePage.Instance.PageIndex += 1;
|
sceneView.Show(sceneTargetDevicesList,1,targetDevice.SceneTargetDeviceUIID);
|
}
|
}
|
devIMG.MouseUpEventHandler += detailMouseUpEventHandler;
|
devName.MouseUpEventHandler += detailMouseUpEventHandler;
|
targetRowLayout.MouseUpEventHandler += detailMouseUpEventHandler;
|
targetFL.MouseUpEventHandler += detailMouseUpEventHandler;
|
}
|
}
|
}
|
/// <summary>
|
/// Show this instance.
|
/// </summary>
|
public void Show()
|
{
|
#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()
|
{
|
TextAlignment = TextAlignment.Center,
|
TextID = R.MyInternationalizationString.AddScence,
|
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 FrameLayout()
|
{
|
Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
|
Y = topView.Bottom,
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
|
};
|
this.AddChidren(midFL);
|
#endregion
|
#region 背景图 名称 区域 执行目标
|
|
var backGround = new Button()
|
{
|
Y = Application.GetRealHeight(50),
|
Width = Application.GetRealWidth(980),
|
Height = Application.GetRealHeight(350),
|
Gravity = Gravity.CenterHorizontal,
|
Radius = CommonPage.BigFormRadius,
|
UnSelectedImagePath = ImagePath
|
};
|
midFL.AddChidren(backGround);
|
//--场景名
|
var sceneNameFL = new FrameLayout()
|
{
|
Y = backGround.Bottom + Application.GetRealHeight(100),
|
Height = Application.GetRealHeight(170),
|
};
|
midFL.AddChidren(sceneNameFL);
|
var sceneNameTip = new Button()
|
{
|
X = Application.GetRealWidth(50),
|
Height = Application.GetRealHeight(70),
|
Width = Application.GetRealWidth(300),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 12,
|
TextColor = ZigbeeColor.Current.GXCButtonTipColor,
|
TextID = R.MyInternationalizationString.SceneName,
|
};
|
sceneNameFL.AddChidren(sceneNameTip);
|
var sceneNameET = new EditText()
|
{
|
X = Application.GetRealWidth(50),
|
Y = sceneNameTip.Bottom,
|
Height = Application.GetRealHeight(100) - 1,
|
Width = Application.GetRealWidth(700),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 20,
|
PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputSceneName),
|
PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
};
|
sceneNameFL.AddChidren(sceneNameET);
|
var sceneNameLine = new Button()
|
{
|
Y = sceneNameET.Bottom,
|
Height = 1,
|
BackgroundColor = ZigbeeColor.Current.GXCLineColor
|
};
|
sceneNameFL.AddChidren(sceneNameLine);
|
//zone
|
var zoneFL = new FrameLayout()
|
{
|
Y = sceneNameFL.Bottom,
|
Height = Application.GetRealHeight(170),
|
};
|
midFL.AddChidren(zoneFL);
|
var zoneTip = new Button()
|
{
|
X = Application.GetRealWidth(50),
|
Height = Application.GetRealHeight(70),
|
Width = Application.GetRealWidth(300),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 12,
|
TextColor = ZigbeeColor.Current.GXCButtonTipColor,
|
TextID = R.MyInternationalizationString.BelongZone,
|
};
|
zoneFL.AddChidren(zoneTip);
|
var zone = new Button()
|
{
|
X = Application.GetRealWidth(50),
|
Y = sceneNameTip.Bottom,
|
Height = Application.GetRealHeight(100) - 1,
|
Width = Application.GetRealWidth(500),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 20,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
Text = CurrentRoom.Name
|
};
|
zoneFL.AddChidren(zone);
|
var zoneRight = 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
|
};
|
zoneFL.AddChidren(zoneRight);
|
var zoneLine = new Button()
|
{
|
Y = zone.Bottom,
|
Height = 1,
|
BackgroundColor = ZigbeeColor.Current.GXCLineColor
|
};
|
zoneFL.AddChidren(zoneLine);
|
//添加执行目标
|
var targetFL = new FrameLayout()
|
{
|
Y = zoneFL.Bottom,
|
Height = Application.GetRealHeight(170),
|
};
|
midFL.AddChidren(targetFL);
|
var target = new Button()
|
{
|
X = Application.GetRealWidth(50),
|
Y = sceneNameTip.Bottom,
|
Height = Application.GetRealHeight(170) - 1,
|
Width = Application.GetRealWidth(500),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 20,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
TextID = R.MyInternationalizationString.AddRoomScentTargetAction,
|
Gravity = Gravity.CenterVertical
|
};
|
targetFL.AddChidren(target);
|
var targetAdd = new Device.CommonForm.SelectedStatuButton()
|
{
|
X = Application.GetRealWidth(1080 - 150),
|
Width = Application.GetMinRealAverage(110),
|
Height = Application.GetMinRealAverage(110),
|
UnSelectedImagePath = "Item/Add.png",
|
SelectedImagePath="Item/AddSelected.png",
|
Gravity = Gravity.CenterVertical
|
};
|
targetFL.AddChidren(targetAdd);
|
var targetLine = new Button()
|
{
|
Y = target.Bottom,
|
Height = 1,
|
BackgroundColor = ZigbeeColor.Current.GXCLineColor
|
};
|
targetFL.AddChidren(targetLine);
|
//添加目标后的展示列表
|
TargetListScrolView = new VerticalScrolViewLayout()
|
{
|
Y = targetFL.Bottom,
|
Height = Application.GetRealHeight(340+170),
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
|
};
|
midFL.AddChidren(TargetListScrolView);
|
confirmBtn = new CommonForm.CompleteButton()
|
{
|
TextID = R.MyInternationalizationString.NextStep,
|
};
|
AddChidren(confirmBtn);
|
|
RefreshTargetListView();
|
if (!string.IsNullOrEmpty(SceneText))
|
{
|
sceneNameET.Text = SceneText;
|
}
|
if(CurrentRoom!=null)
|
{
|
|
}
|
if(Modify)
|
{
|
title.TextID = R.MyInternationalizationString.ModifyScene;
|
oldRoom = CurrentRoom;
|
if (ModifySceneUI != null && ModifySceneUI.IsSharedScene)
|
{
|
sceneNameET.Enable = false;
|
}
|
}
|
#endregion
|
#region event
|
//记录输入场景名
|
sceneNameET.TextChangeEventHandler += (sender, e) =>
|
{
|
SceneText = sceneNameET.Text.Trim();
|
};
|
|
//选择背景图
|
EventHandler<MouseEventArgs> backGroundIMGHander = (sender, e) =>
|
{
|
if(CurrentRoom.IsSharedRoom)
|
{
|
RoomCommon.ShowTipRoomIsShared();
|
return;
|
}
|
|
var localPic = new CategorySceneSelectImgByLocal();
|
Shared.Phone.UserView.HomePage.Instance.AddChidren(localPic);
|
Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
|
localPic.Show();
|
localPic.action = () =>
|
{
|
backGround.UnSelectedImagePath = ImagePath;
|
IconType = 0;
|
};
|
|
//var selectDialog = new Dialog()
|
//{
|
//};
|
//selectDialog.Show();
|
|
//var itemFL = new FrameLayout()
|
//{
|
// Y = Application.GetRealHeight(1920 - 600),
|
// Width = Application.GetRealWidth(900),
|
// Height = Application.GetRealHeight(550),
|
// Radius = CommonPage.BigFormRadius,
|
// //BackgroundColor=ZigbeeColor.Current.GXCBackgroundColor,
|
// Gravity = Gravity.CenterHorizontal
|
//};
|
//selectDialog.AddChidren(itemFL);
|
|
//var localPicBtn = new Button()
|
//{
|
// Height = Application.GetRealHeight(130) - 1,
|
// TextID = R.MyInternationalizationString.LocalPic,
|
// TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
// TextAlignment = TextAlignment.Center,
|
// BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
|
//};
|
//itemFL.AddChidren(localPicBtn);
|
//var localPicLine = new Button()
|
//{
|
// Y = localPicBtn.Bottom,
|
// Height = 1,
|
// BackgroundColor = ZigbeeColor.Current.GXCLineColor,
|
//};
|
//itemFL.AddChidren(localPicLine);
|
|
//var takePhotoBtn = new Button()
|
//{
|
// Y = localPicLine.Bottom,
|
// Height = Application.GetRealHeight(130) - 1,
|
// TextID = R.MyInternationalizationString.TakePhoto,
|
// TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
// TextAlignment = TextAlignment.Center,
|
// BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
|
//};
|
//itemFL.AddChidren(takePhotoBtn);
|
//var takePhotoLine = new Button()
|
//{
|
// Y = takePhotoBtn.Bottom,
|
// Height = 1,
|
// BackgroundColor = ZigbeeColor.Current.GXCLineColor,
|
//};
|
//itemFL.AddChidren(takePhotoLine);
|
|
//var systemPicBtn = new Button()
|
//{
|
// Y = takePhotoLine.Bottom,
|
// Height = Application.GetRealHeight(130),
|
// TextID = R.MyInternationalizationString.SystemPic,
|
// TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
// TextAlignment = TextAlignment.Center,
|
// BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
|
//};
|
//itemFL.AddChidren(systemPicBtn);
|
|
|
//var cancelBtn = new Button()
|
//{
|
// Y = systemPicBtn.Bottom + Application.GetRealHeight(30),
|
// Height = Application.GetRealHeight(150),
|
// TextID = R.MyInternationalizationString.Cancel,
|
// TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
// BackgroundColor = ZigbeeColor.Current.GXCButtonBlueColor,
|
// TextAlignment = TextAlignment.Center,
|
//};
|
//itemFL.AddChidren(cancelBtn);
|
|
////本地图库
|
//localPicBtn.MouseUpEventHandler += (send, ee) =>
|
//{
|
// selectDialog.Close();
|
// var localPic = new CategorySceneSelectImgByLocal();
|
// Shared.Phone.UserView.HomePage.Instance.AddChidren(localPic);
|
// Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
|
// localPic.Show();
|
// localPic.action = () =>
|
// {
|
// backGround.UnSelectedImagePath = ImagePath;
|
// IconType = 0;
|
// };
|
//};
|
////拍照
|
//takePhotoBtn.MouseUpEventHandler += (send, ee) =>
|
//{
|
// var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
|
// selectDialog.Close();
|
// Camera.TakePicture((obj) =>
|
// {
|
// if (obj == null)
|
// {
|
// return;
|
// }
|
// backGround.UnSelectedImagePath = $"ScenePicture{tradeTime}.png";
|
// ImagePath = $"{Config.Instance.HomeId}/{backGround.UnSelectedImagePath}";
|
// IconType = 1;
|
// }, $"ScenePicture{tradeTime}.png");
|
//};
|
////系统图库
|
//systemPicBtn.MouseUpEventHandler += (send, ee) =>
|
//{
|
// var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
|
// selectDialog.Close();
|
// Camera.SelectPicture((obj) =>
|
// {
|
// if (obj == null)
|
// {
|
// return;
|
// }
|
// backGround.UnSelectedImagePath = $"ScenePicture{tradeTime}.png";
|
// ImagePath = $"{Config.Instance.HomeId}/{backGround.UnSelectedImagePath}";
|
// IconType = 2;
|
// }, $"ScenePicture{tradeTime}.png");
|
//};
|
//cancelBtn.MouseUpEventHandler += (send, ee) =>
|
//{
|
// selectDialog.Close();
|
//};
|
};
|
backGround.MouseUpEventHandler += backGroundIMGHander;
|
//区域
|
EventHandler<MouseEventArgs> zoneHander = (sender, e) =>
|
{
|
if (CurrentRoom.IsSharedRoom)
|
{
|
RoomCommon.ShowTipRoomIsShared();
|
return;
|
}
|
var selectRoom = new CategorySceneSelectRoomList();
|
UserView.HomePage.Instance.AddChidren(selectRoom);
|
UserView.HomePage.Instance.PageIndex += 1;
|
selectRoom.SelectedRoomAction = (room) =>
|
{
|
CurrentRoom = room;
|
zone.Text = CurrentRoom.Name;
|
};
|
selectRoom.Show();
|
};
|
zoneRight.MouseUpEventHandler += zoneHander;
|
zoneFL.MouseUpEventHandler += zoneHander;
|
zone.MouseUpEventHandler += zoneHander;
|
//执行目标-添加执行设备
|
EventHandler<MouseEventArgs> targetAddHander = (sender, e) =>
|
{
|
if (CurrentRoom.IsSharedRoom)
|
{
|
RoomCommon.ShowTipRoomIsShared();
|
return;
|
}
|
|
int selectRow_Height = 130;
|
var selectFL = new FrameLayout()
|
{
|
BackgroundColor = ZigbeeColor.Current.GXCDailogBackGroundColor
|
};
|
AddChidren(selectFL);
|
|
var itemFL = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(CommonPage.AppRealHeight - selectRow_Height * 4 - 20),
|
Height = Application.GetRealHeight(selectRow_Height * 4 + 20)
|
};
|
selectFL.AddChidren(itemFL);
|
|
var selectedFunctionBtn = new Device.CommonForm.SelectedStatuButton()
|
{
|
Height = Application.GetRealHeight(selectRow_Height) - 1,
|
TextID = R.MyInternationalizationString.Function,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
SelectedBackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
|
};
|
itemFL.AddChidren(selectedFunctionBtn);
|
var selectedFunctionLine = new Button()
|
{
|
Y = selectedFunctionBtn.Bottom,
|
Height = 1,
|
BackgroundColor = ZigbeeColor.Current.GXCLineColor,
|
};
|
itemFL.AddChidren(selectedFunctionLine);
|
|
var selectedSceneBtn = new Device.CommonForm.SelectedStatuButton()
|
{
|
Y = selectedFunctionLine.Bottom,
|
Height = Application.GetRealHeight(selectRow_Height) - 1,
|
TextID = R.MyInternationalizationString.Scence,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
SelectedBackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
|
};
|
itemFL.AddChidren(selectedSceneBtn);
|
var selectedSceneLine = new Button()
|
{
|
Y = selectedSceneBtn.Bottom,
|
Height = 1,
|
BackgroundColor = ZigbeeColor.Current.GXCLineColor,
|
};
|
itemFL.AddChidren(selectedSceneLine);
|
|
var selectedTimerBtn = new Device.CommonForm.SelectedStatuButton()
|
{
|
Y = selectedSceneLine.Bottom,
|
Height = Application.GetRealHeight(selectRow_Height)-1,
|
TextID = R.MyInternationalizationString.TimeSpan,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
SelectedBackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
|
};
|
itemFL.AddChidren(selectedTimerBtn);
|
|
var cancelBtn = new Device.CommonForm.SelectedStatuButton()
|
{
|
Y = selectedTimerBtn.Bottom + Application.GetRealHeight(20),
|
Height = Application.GetRealHeight(selectRow_Height),
|
TextID = R.MyInternationalizationString.Cancel,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
SelectedBackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
|
};
|
itemFL.AddChidren(cancelBtn);
|
|
itemFL.Animate = Animate.DownToUp;
|
//添加功能
|
selectedFunctionBtn.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
var deviceTypeList = new CategorySceneSelectDevice();
|
UserView.HomePage.Instance.AddChidren(deviceTypeList);
|
UserView.HomePage.Instance.PageIndex += 1;
|
deviceTypeList.Show(sceneTargetDevicesList);
|
};
|
//添加场景
|
selectedSceneBtn.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
var sceneView = new CategorySceneSelectedScene();
|
UserView.HomePage.Instance.AddChidren(sceneView);
|
UserView.HomePage.Instance.PageIndex += 1;
|
if(Modify)
|
{
|
sceneView.Show(sceneTargetDevicesList,-1, "", false, ModifySceneUI.Id);
|
}
|
else
|
{
|
sceneView.Show(sceneTargetDevicesList);
|
}
|
};
|
//添加时间间隔
|
selectedTimerBtn.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
var delayTimeView = new CategorySceneSelectedDelayTime();
|
UserView.HomePage.Instance.AddChidren(delayTimeView);
|
UserView.HomePage.Instance.PageIndex += 1;
|
delayTimeView.Show();
|
};
|
cancelBtn.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
};
|
selectFL.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
};
|
};
|
targetAdd.MouseUpEventHandler += targetAddHander;
|
targetFL.MouseUpEventHandler += targetAddHander;
|
target.MouseUpEventHandler += targetAddHander;
|
//确定添加目标
|
confirmBtn.MouseUpEventHandler += async (sender, e) =>
|
{
|
if (CurrentRoom.IsSharedRoom)
|
{
|
RemoveFromParent();
|
return;
|
}
|
if (Modify)
|
{
|
try
|
{
|
CommonPage.Loading.Start();
|
//修改--先判断场景名是否改变,再移除设备,再添加设备
|
ModifySceneUI.IconPath = ImagePath;
|
if (ModifySceneUI.Name != sceneNameET.Text.Trim())
|
{
|
if (Shared.Common.Room.AllRoomSceneUIList.Find(s => s.Name == sceneNameET.Text.Trim()) != null)
|
{
|
Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneHadExist);
|
return;
|
}
|
//修改名字
|
var r = await ZigBee.Device.Scene.RenameSceneAsync(ModifySceneUI.Id, sceneNameET.Text.Trim());
|
var reName = r.sceneRenameResponseData.Result;
|
if (reName == 0)
|
{
|
//失败
|
return;
|
}
|
else if (reName == 1)
|
{
|
//成功
|
ModifySceneUI.Name = sceneNameET.Text.Trim();
|
|
}
|
else if (reName == 2)
|
{
|
//没有该场景
|
return;
|
}
|
}
|
//修改设备
|
var memberDataList = new List<AddSceneMemberData>();
|
int AddedDelayTime = 0;
|
for (int i = 0; i < sceneTargetDevicesList.Count; i++)
|
{
|
//合并延时
|
var sceneTarget = sceneTargetDevicesList[i];
|
SceneTargetDeviceUI beforeSceneTarget = null;
|
if (i - 1 >= 0)
|
{
|
beforeSceneTarget = sceneTargetDevicesList[i - 1];
|
}
|
if (sceneTarget.Type == 0)
|
{
|
if (beforeSceneTarget != null && beforeSceneTarget.Type == 1)
|
{
|
if (i - 1 >= 0)
|
{
|
for (int k = i - 1; k >= 0; k--)
|
{
|
if (sceneTargetDevicesList[k] == null || sceneTargetDevicesList[k].Type != 1)
|
{
|
break;
|
}
|
AddedDelayTime += sceneTargetDevicesList[k].DelayTime;
|
}
|
}
|
}
|
if (sceneTarget.DeviceUI == null || sceneTarget.DeviceUI.CommonDevice == null)
|
{
|
continue;
|
}
|
var memberData = new ZigBee.Device.Scene.AddSceneMemberData
|
{
|
DeviceAddr = sceneTarget.DeviceUI.CommonDevice.DeviceAddr,
|
Type = 0,
|
ScenesId = 0,
|
Epoint = sceneTarget.DeviceUI.CommonDevice.DeviceEpoint,
|
TaskList = sceneTarget.TaskList,
|
DelayTime = AddedDelayTime
|
};
|
memberDataList.Add(memberData);
|
}
|
else if (sceneTarget.Type == 2)
|
{
|
if (beforeSceneTarget != null && beforeSceneTarget.Type == 1)
|
{
|
if (i - 1 >= 0)
|
{
|
for (int k = i - 1; k >= 0; k--)
|
{
|
if (sceneTargetDevicesList[k] == null || sceneTargetDevicesList[k].Type != 1)
|
{
|
break;
|
}
|
AddedDelayTime += sceneTargetDevicesList[k].DelayTime;
|
}
|
}
|
}
|
var memberData = new ZigBee.Device.Scene.AddSceneMemberData
|
{
|
Type = 1,
|
ScenesId = 0,
|
ElseScenesId = sceneTarget.ElseScenesId,
|
DelayTime = AddedDelayTime
|
};
|
memberDataList.Add(memberData);
|
}
|
}
|
var sceneRemoveMemberData = new SceneRemoveMemberData { };
|
var removeSceneDeviceListInfoList = new List<RemoveSceneDeviceListInfo> { };
|
for (int i = 0; i < beforeSceneTargetDevicesList.Count; i++)
|
{
|
//合并延时
|
var sceneTarget = beforeSceneTargetDevicesList[i];
|
if (sceneTarget.Type == 0)
|
{
|
if (sceneTarget.DeviceUI == null || sceneTarget.DeviceUI.CommonDevice == null)
|
{
|
continue;
|
}
|
var removeDevice = new RemoveSceneDeviceListInfo
|
{
|
Type = 0,
|
DeviceAddr = sceneTarget.DeviceUI.CommonDevice.DeviceAddr,
|
Epoint = sceneTarget.DeviceUI.CommonDevice.DeviceEpoint,
|
};
|
removeSceneDeviceListInfoList.Add(removeDevice);
|
}
|
else if (sceneTarget.Type == 2)
|
{
|
var removeDevice = new ZigBee.Device.Scene.RemoveSceneDeviceListInfo
|
{
|
Type = 1,
|
ElseScenesId = sceneTarget.ElseScenesId
|
};
|
removeSceneDeviceListInfoList.Add(removeDevice);
|
}
|
}
|
sceneRemoveMemberData.DeviceList = removeSceneDeviceListInfoList;
|
sceneRemoveMemberData.ScenesId = ModifySceneUI.Id;
|
var result = await CurrentRoom.ModifyScene(ModifySceneUI,sceneRemoveMemberData, memberDataList);
|
if (result == 1)
|
{
|
if(oldRoom!=CurrentRoom)
|
{
|
oldRoom.SceneUIList.Remove(ModifySceneUI);
|
oldRoom.SceneUIFilePathList.Remove(ModifySceneUI.FileName);
|
CurrentRoom.SceneUIList.Add(ModifySceneUI);
|
CurrentRoom.SceneUIFilePathList.Add(ModifySceneUI.FileName);
|
oldRoom.Save();
|
CurrentRoom.Save();
|
}
|
|
RemoveFromParent();
|
}
|
else if (result == 0)
|
{
|
//失败
|
Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
|
}
|
else if (result == -1)
|
{
|
//已存在
|
Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneHadExist);
|
}
|
}
|
catch (Exception ex)
|
{
|
System.Console.WriteLine($"分类添加场景出错{ex.Message}");
|
}
|
finally
|
{
|
CommonPage.Loading.Hide();
|
}
|
}
|
//新增
|
else
|
{
|
if (string.IsNullOrEmpty(sceneNameET.Text))
|
{
|
var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.SceneNameCannotBeNull), Language.StringByID(R.MyInternationalizationString.Close));
|
alert.Show();
|
alert.ResultEventHandler += (sendAlert, eAlert) =>
|
{
|
return;
|
};
|
}
|
else
|
{
|
try
|
{
|
if (Shared.Common.Room.AllRoomSceneUIList.Find(s => s.Name == sceneNameET.Text.Trim()) != null)
|
{
|
Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneHadExist);
|
return;
|
}
|
CommonPage.Loading.Start();
|
var memberDataList = new List<ZigBee.Device.Scene.AddSceneMemberData>();
|
//累加延时
|
int AddedDelayTime = 0;
|
for (int i = 0; i < sceneTargetDevicesList.Count; i++)
|
{
|
var sceneTarget = sceneTargetDevicesList[i];
|
SceneTargetDeviceUI beforeSceneTarget = null;
|
if (i - 1 >= 0)
|
{
|
beforeSceneTarget = sceneTargetDevicesList[i - 1];
|
}
|
if (sceneTarget.Type == 0)
|
{
|
if (sceneTarget.DeviceUI == null || sceneTarget.DeviceUI.CommonDevice == null)
|
{
|
continue;
|
}
|
|
if (beforeSceneTarget != null && beforeSceneTarget.Type == 1)
|
{
|
if(i-1>=0)
|
{
|
for(int k=i-1;k>=0;k--)
|
{
|
if(sceneTargetDevicesList[k] == null || sceneTargetDevicesList[k].Type != 1)
|
{
|
break;
|
}
|
AddedDelayTime += sceneTargetDevicesList[k].DelayTime;
|
}
|
}
|
}
|
|
var memberData = new ZigBee.Device.Scene.AddSceneMemberData
|
{
|
DeviceAddr = sceneTarget.DeviceUI.CommonDevice.DeviceAddr,
|
Type = 0,
|
ScenesId = 0,
|
Epoint = sceneTarget.DeviceUI.CommonDevice.DeviceEpoint,
|
TaskList = sceneTarget.TaskList,
|
DelayTime = AddedDelayTime
|
};
|
memberDataList.Add(memberData);
|
}
|
else if (sceneTarget.Type == 2)
|
{
|
if (beforeSceneTarget != null && beforeSceneTarget.Type == 1)
|
{
|
if (i - 1 >= 0)
|
{
|
for (int k = i - 1; k >= 0; k--)
|
{
|
if (sceneTargetDevicesList[k] == null || sceneTargetDevicesList[k].Type != 1)
|
{
|
break;
|
}
|
AddedDelayTime += sceneTargetDevicesList[k].DelayTime;
|
}
|
}
|
}
|
var memberData = new ZigBee.Device.Scene.AddSceneMemberData
|
{
|
Type = 1,
|
ScenesId = 0,
|
ElseScenesId = sceneTarget.ElseScenesId,
|
DelayTime = AddedDelayTime
|
};
|
memberDataList.Add(memberData);
|
}
|
}
|
|
var result = await CurrentRoom.AddScene(sceneNameET.Text, backGround.UnSelectedImagePath, memberDataList);
|
if (result == 1)
|
{
|
RemoveFromParent();
|
}
|
else if (result == 0)
|
{
|
//失败
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.AddSceneFail);
|
}
|
else if (result == -1)
|
{
|
//已存在
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneHadExist);
|
}
|
}
|
catch (Exception ex)
|
{
|
System.Console.WriteLine($"分类添加场景出错{ex.Message}");
|
}
|
finally
|
{
|
CommonPage.Loading.Hide();
|
}
|
|
}
|
}
|
};
|
#endregion
|
}
|
}
|
}
|