using System;
|
using System.Collections.Generic;
|
using HDL_ON.DAL.Server;
|
using HDL_ON.Entity;
|
using HDL_ON.UI.CSS;
|
using Shared;
|
|
namespace HDL_ON.UI
|
{
|
public class AddInputPage : FrameLayout
|
{
|
FrameLayout bodyView;
|
VerticalScrolViewLayout functionListView;
|
|
Action<SecurityAlarm> refreshAction;
|
|
SecurityAlarm securityAlarm;
|
List<SecurityInput> inputList = new List<SecurityInput>();
|
|
public AddInputPage(SecurityAlarm alarm,Action<SecurityAlarm> action)
|
{
|
bodyView = this;
|
securityAlarm = alarm;
|
refreshAction = action;
|
}
|
|
|
/// <summary>
|
/// 加载界面
|
/// </summary>
|
public void LoadPage()
|
{
|
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
|
new TopViewDiv(bodyView, Language.StringByID(StringId.AddDefenseFunction)).LoadTopView();
|
|
#region 显示的功能类型切换区域
|
var showdFunctionTypeRow = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(64),
|
Height = Application.GetRealHeight(53),
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
};
|
bodyView.AddChidren(showdFunctionTypeRow);
|
|
|
var btnFloorDownIcon = new Button()
|
{
|
Width = Application.GetMinRealAverage(16),
|
Height = Application.GetMinRealAverage(16),
|
X = Application.GetRealWidth(16),
|
Y = Application.GetRealHeight(18),
|
UnSelectedImagePath = "Public/DownIcon.png",
|
};
|
showdFunctionTypeRow.AddChidren(btnFloorDownIcon);
|
|
var btnFloor = new Button()
|
{
|
X = btnFloorDownIcon.Right,
|
Y = Application.GetRealHeight(18),
|
Width = Application.GetRealWidth(200),
|
Height = Application.GetMinRealAverage(16),
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = DB_ResidenceData.Instance.CurFloor.roomName,
|
};
|
showdFunctionTypeRow.AddChidren(btnFloor);
|
btnFloor.MouseUpEventHandler += (sender, e) =>
|
{
|
string nowSelectId = null;
|
var listAllFun = FunctionList.List.GetArmSensorList();
|
|
//显示下拉界面
|
var form = new FloorRoomSelectPopupView();
|
form.ShowDeviceFunctionView(btnFloor, listAllFun, (selectId, listFun) =>
|
{
|
nowSelectId = selectId;
|
//重新刷新设备列表
|
this.LoadFunctionListRow(listFun);
|
}, nowSelectId);
|
};
|
|
|
#endregion
|
|
functionListView = new VerticalScrolViewLayout()
|
{
|
Y = showdFunctionTypeRow.Bottom,
|
Height = Application.GetRealHeight(530),
|
BackgroundColor = CSS_Color.BackgroundColor,
|
};
|
bodyView.AddChidren(functionListView);
|
|
|
|
LoadFunctionListRow(FunctionList.List.GetArmSensorList());
|
|
|
|
var bottomView = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(591),
|
Height = Application.GetRealHeight(100),
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
Radius = (uint)Application.GetRealWidth(22),
|
};
|
this.AddChidren(bottomView);
|
|
var btnConfrim = new Button()
|
{
|
X = Application.GetRealWidth(78),
|
Y = Application.GetRealHeight(12),
|
Width = Application.GetRealWidth(220),
|
Height = Application.GetRealWidth(44),
|
Radius = (uint)Application.GetRealWidth(22),
|
BackgroundColor = CSS_Color.MainColor,
|
TextID = StringId.Confirm,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
TextColor = CSS_Color.MainBackgroundColor,
|
TextAlignment = TextAlignment.Center,
|
};
|
bottomView.AddChidren(btnConfrim);
|
btnConfrim.MouseUpEventHandler = (sender, e) =>
|
{
|
securityAlarm.input = new List<SecurityInput>();
|
foreach (var input in inputList)
|
{
|
if (input.addCondition)
|
{
|
securityAlarm.input.Add(input);
|
}
|
}
|
this.RemoveFromParent();
|
refreshAction?.Invoke(securityAlarm);
|
};
|
|
|
|
}
|
|
|
// <summary>
|
/// 显示功能Row
|
/// </summary>
|
void LoadFunctionListRow(List<Function> functions)
|
{
|
functionListView.RemoveAll();
|
if (functions == null)
|
{
|
//初始值
|
functions = FunctionList.List.GetArmSensorList();
|
}
|
|
#if DEBUG
|
functions.AddRange(FunctionList.List.GetLightList());
|
#endif
|
|
foreach (var function in functions)
|
{
|
var input = securityAlarm.input.Find((obj) => obj.sid == function.sid);
|
if (input == null)
|
{
|
input = new SecurityInput();
|
input.sid = function.sid;
|
|
var inKey = "status";
|
var inValue = "true";
|
switch(function.spk)
|
{
|
case SPK.SensorWater:
|
inKey = "";
|
break;
|
case SPK.SensorPir:
|
inKey = "people_status";
|
break;
|
case SPK.SensorSmoke:
|
inKey = "alarm_status";
|
inValue = "alarm";
|
break;
|
case SPK.SensorGas:
|
inKey = "alarm_status";
|
inValue = "alarm";
|
break;
|
case SPK.SensorDoorWindow:
|
inKey = "contact_status";
|
inValue = "open";
|
break;
|
}
|
input.condition = new List<SecurityInputCondition>()
|
{
|
new SecurityInputCondition()
|
{
|
key = inKey,
|
value = inValue,
|
}
|
};
|
|
if (function.spk == SPK.LightSwitch || function.spk == SPK.LightRGB || function.spk == SPK.LightDimming)
|
{
|
input.condition = new List<SecurityInputCondition>()
|
{
|
new SecurityInputCondition()
|
{
|
key = FunctionAttributeKey.OnOff,
|
value = "off",
|
}
|
};
|
}
|
|
}
|
else
|
{
|
input.addCondition = true;
|
}
|
inputList.Add(input);
|
|
FrameLayout functionRow = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(65),
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
};
|
functionListView.AddChidren(functionRow);
|
|
var btnFunctionName = new Button()
|
{
|
X = Application.GetRealWidth(16),
|
Width = Application.GetRealWidth(200),
|
Height = Application.GetRealHeight(44),
|
Text = function.name,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.TextFontSize,
|
};
|
functionRow.AddChidren(btnFunctionName);
|
|
var btnFunctionFloorName = new Button()
|
{
|
X = Application.GetRealWidth(16),
|
Y = Application.GetRealHeight(24),
|
Width = Application.GetRealWidth(200),
|
Height = Application.GetRealHeight(41),
|
Text = function.GetRoomListName(),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = CSS_Color.PromptingColor1,
|
TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
|
};
|
functionRow.AddChidren(btnFunctionFloorName);
|
|
Button btnState = new Button()
|
{
|
Width = Application.GetRealWidth(317),
|
TextAlignment = TextAlignment.CenterRight,
|
TextSize = CSS_FontSize.TextFontSize,
|
TextColor = CSS_Color.PromptingColor1,
|
};
|
functionRow.AddChidren(btnState);
|
|
|
Button btnChooseIcon = new Button()
|
{
|
X = Application.GetRealWidth(333),
|
Gravity = Gravity.CenterVertical,
|
Width = Application.GetMinRealAverage(32),
|
Height = Application.GetMinRealAverage(32),
|
UnSelectedImagePath = "Public/ChooseIcon.png",
|
SelectedImagePath = "Public/ChooseOnIcon.png",
|
};
|
functionRow.AddChidren(btnChooseIcon);
|
|
btnChooseIcon.MouseUpEventHandler = (sender, e) => {
|
btnChooseIcon.IsSelected = !btnChooseIcon.IsSelected;
|
if(btnChooseIcon.IsSelected)
|
{
|
input.addCondition = true;
|
//if (input.condition.Count==0)
|
//{
|
// ShowStateDialog(input, btnState,btnChooseIcon,function.spk);
|
//}
|
}
|
else
|
{
|
input.addCondition = false;
|
}
|
};
|
btnState.MouseUpEventHandler = (sender, e) =>
|
{
|
//ShowStateDialog(input, btnState, btnChooseIcon, function.spk);
|
btnChooseIcon.IsSelected = !btnChooseIcon.IsSelected;
|
if (btnChooseIcon.IsSelected)
|
{
|
input.addCondition = true;
|
}
|
else
|
{
|
input.addCondition = false;
|
}
|
};
|
|
|
if (input.addCondition)
|
{
|
btnChooseIcon.IsSelected = true;
|
btnState.Text = input.StateText();
|
}
|
|
|
functionListView.AddChidren(new Button()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Width = Application.GetRealWidth(343),
|
Height = Application.GetRealWidth(1),
|
BackgroundColor = CSS_Color.DividingLineColor,
|
});
|
|
|
}
|
}
|
|
|
private void ShowStateDialog(SecurityInput input,Button btnState,Button btnChoose ,string spk)
|
{
|
Dialog dialog = new Dialog();
|
|
FrameLayout contentView = new FrameLayout();
|
dialog.AddChidren(contentView);
|
contentView.MouseUpEventHandler = (sender, e) =>
|
{
|
dialog.Close();
|
if (input.condition.Count == 0)
|
{
|
if (btnChoose != null)
|
{
|
btnChoose.IsSelected = false;
|
}
|
}
|
};
|
|
VerticalScrolViewLayout optinView = new VerticalScrolViewLayout()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight(515),
|
Width = Application.GetRealWidth(343),
|
Height = Application.GetRealHeight(88),
|
Radius = (uint)Application.GetRealHeight(13),
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
};
|
contentView.AddChidren(optinView);
|
|
Button btnOpen = new Button()
|
{
|
Height = Application.GetRealHeight(44),
|
TextAlignment = TextAlignment.Center,
|
TextColor = CSS_Color.MainColor,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
Text = input.GetStateText("true")
|
};
|
optinView.AddChidren(btnOpen);
|
|
optinView.AddChidren(new Button()
|
{
|
Height = 1,
|
BackgroundColor = CSS_Color.DividingLineColor
|
});
|
|
Button btnClose = new Button()
|
{
|
Height = Application.GetRealHeight(44),
|
TextAlignment = TextAlignment.Center,
|
TextColor = CSS_Color.PromptingColor1,
|
Text = input.GetStateText("false"),
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
};
|
optinView.AddChidren(btnClose);
|
|
|
Button btnCancel = new Button()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = optinView.Bottom + Application.GetRealHeight(8),
|
Width = Application.GetRealWidth(343),
|
Height = Application.GetRealHeight(44),
|
Radius = (uint)Application.GetRealHeight(13),
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
TextID = StringId.Cancel,
|
TextColor = CSS_Color.WarningColor,
|
IsBold = true,
|
};
|
contentView.AddChidren(btnCancel);
|
|
dialog.Show();
|
|
btnOpen.MouseUpEventHandler = (sender, e) => {
|
btnState.Text = btnOpen.Text;
|
input.condition = new List<SecurityInputCondition>()
|
{
|
new SecurityInputCondition()
|
{
|
key = "status",
|
value = "true",
|
}
|
};
|
|
if (spk == SPK.LightSwitch || spk == SPK.LightRGB || spk == SPK.LightDimming)
|
{
|
input.condition = new List<SecurityInputCondition>()
|
{
|
new SecurityInputCondition()
|
{
|
key = FunctionAttributeKey.OnOff,
|
value = "on",
|
}
|
};
|
}
|
|
|
|
input.addCondition = true;
|
if (btnChoose != null)
|
{
|
btnChoose.IsSelected = true;
|
}
|
dialog.Close();
|
};
|
|
btnClose.MouseUpEventHandler = (sender, e) =>
|
{
|
btnState.Text = btnClose.Text;
|
input.condition = new List<SecurityInputCondition>()
|
{
|
new SecurityInputCondition()
|
{
|
key = "status",
|
value = "false",
|
}
|
};
|
|
if (spk == SPK.LightSwitch || spk == SPK.LightRGB || spk == SPK.LightDimming)
|
{
|
input.condition = new List<SecurityInputCondition>()
|
{
|
new SecurityInputCondition()
|
{
|
key = FunctionAttributeKey.OnOff,
|
value = "off",
|
}
|
};
|
}
|
|
|
input.addCondition = true;
|
if (btnChoose != null)
|
{
|
btnChoose.IsSelected = true;
|
}
|
dialog.Close();
|
};
|
|
btnCancel.MouseUpEventHandler = (sender, e) =>
|
{
|
dialog.Close();
|
if (input.condition.Count == 0)
|
{
|
if (btnChoose != null)
|
{
|
btnChoose.IsSelected = false;
|
}
|
}
|
|
};
|
|
}
|
|
|
}
|
|
}
|