using System;
using HDL_ON.Common;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock
{
public class UnlockSettingPage : FrameLayout
{
FrameLayout bodyView;
///
/// 二次开锁开关
///
Button btnSecondaryUnlockingUnlockkSwtichIcon;
///
/// 童锁开关
///
Button btnChildLockSwitchIcon;
///
/// 反锁开关
///
Button btnAntiLockSwitchIcon;
///
/// 布防开关
///
Button btnDefenceStatusSwitchIcon;
///
/// 按键两次开门
///
bool ezvizDoubleClickOpenDoorSwitchVO = false;
///
/// 童锁状态
///
bool ezvizChildLockSwitchVO = false;
///
/// 反锁状态
///
bool ezvizAntiLock = false;
///
/// 布防状态
///
bool ezvizDefenceStatus = false;
Function device;
public UnlockSettingPage(Function function)
{
bodyView = this;
device = function;
}
public void LoadPage()
{
new TopViewDiv(bodyView, Language.StringByID(StringId.UnlockSetting)).LoadTopView();
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
var contentView = new VerticalScrolViewLayout()
{
Y = Application.GetRealHeight(64),
Height = Application.GetRealHeight(600),
ScrollEnabled = false,
};
bodyView.AddChidren(contentView);
#region 人脸开锁设置
var faceUnlockSettingView = new FrameLayout()
{
Height = Application.GetRealHeight(50),
BackgroundColor = CSS.CSS_Color.MainBackgroundColor,
};
contentView.AddChidren(faceUnlockSettingView);
var btnFaceSettingRight = new Button()
{
X = Application.GetRealWidth(339),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(16),
Height = Application.GetMinRealAverage(16),
UnSelectedImagePath = "Public/Right.png",
};
faceUnlockSettingView.AddChidren(btnFaceSettingRight);
var btnFaceText = new Button()
{
X = Application.GetRealWidth(16),
TextSize = CSS_FontSize.SubheadingFontSize,
TextColor = CSS_Color.FirstLevelTitleColor,
TextAlignment = TextAlignment.CenterLeft,
TextID = StringId.FaceUnlockSetting,
};
faceUnlockSettingView.AddChidren(btnFaceText);
btnFaceText.MouseUpEventHandler = (sender, e) => {
var page = new UnlockSettingFacePage(device);
MainPage.BasePageView.AddChidren(page);
page.LoadPage();
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
};
#endregion
contentView.AddChidren(new Button() {
Height = Application.GetRealHeight(8),
BackgroundColor = CSS_Color.BackgroundColor,
});
#region 按键两次开锁
var secondaryUnlockingView = new FrameLayout()
{
Height = Application.GetRealHeight(74),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
contentView.AddChidren(secondaryUnlockingView);
var btnSecondaryUnlockingText = new Button()
{
X = Application.GetRealWidth(16),
Y = Application.GetRealHeight(7),
Height = Application.GetRealHeight(37),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.PressTheButtonToUnlockTwice
};
secondaryUnlockingView.AddChidren(btnSecondaryUnlockingText);
var btnSecondaryUnlockingTipText = new Button()
{
X = Application.GetRealWidth(16),
Y = btnSecondaryUnlockingText.Bottom,
Width = Application.GetRealWidth(339),
Height = Application.GetRealHeight(37),
TextAlignment = TextAlignment.TopLeft,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
IsMoreLines = true,
TextID = StringId.PressTheButtonToUnlockTwiceTip
};
secondaryUnlockingView.AddChidren(btnSecondaryUnlockingTipText);
btnSecondaryUnlockingUnlockkSwtichIcon = new Button()
{
X = Application.GetRealWidth(322),
Y = Application.GetRealHeight(8),
Width = Application.GetMinRealAverage(36),
Height = Application.GetMinRealAverage(36),
UnSelectedImagePath = "Public/Switch_2.png",
SelectedImagePath = "Public/SwitchOn_2.png",
IsSelected = ezvizDoubleClickOpenDoorSwitchVO,
};
secondaryUnlockingView.AddChidren(btnSecondaryUnlockingUnlockkSwtichIcon);
#endregion
#region 童锁模式
var childLockView = new FrameLayout()
{
Height = Application.GetRealHeight(74),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
contentView.AddChidren(childLockView);
childLockView.AddChidren(new Button()
{
Gravity = Gravity.CenterHorizontal,
Height = 1,
BackgroundColor = CSS_Color.DividingLineColor,
});
var btnEzvizChildLockText = new Button()
{
X = Application.GetRealWidth(16),
Y = Application.GetRealHeight(7),
Height = Application.GetRealHeight(37),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.ChildLockMode
};
childLockView.AddChidren(btnEzvizChildLockText);
var btnChildLockTipText = new Button()
{
X = Application.GetRealWidth(16),
Y = btnEzvizChildLockText.Bottom,
Width = Application.GetRealWidth(339),
Height = Application.GetRealHeight(37),
TextAlignment = TextAlignment.TopLeft,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
IsMoreLines = true,
TextID = StringId.ChildLockModeTip,
};
childLockView.AddChidren(btnChildLockTipText);
btnChildLockSwitchIcon = new Button()
{
X = Application.GetRealWidth(322),
Y = Application.GetRealHeight(8),
Width = Application.GetMinRealAverage(36),
Height = Application.GetMinRealAverage(36),
UnSelectedImagePath = "Public/Switch_2.png",
SelectedImagePath = "Public/SwitchOn_2.png",
IsSelected = ezvizChildLockSwitchVO,
};
childLockView.AddChidren(btnChildLockSwitchIcon);
#endregion
#region 反锁模式
var antiLockView = new FrameLayout()
{
Height = Application.GetRealHeight(94),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
contentView.AddChidren(antiLockView);
antiLockView.AddChidren(new Button()
{
Gravity = Gravity.CenterHorizontal,
Height = 1,
BackgroundColor = CSS_Color.DividingLineColor,
});
var btnAntiLockText = new Button()
{
X = Application.GetRealWidth(16),
Y = Application.GetRealHeight(7),
Height = Application.GetRealHeight(37),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.AntiLockMode
};
antiLockView.AddChidren(btnAntiLockText);
var btnAntilockTipText = new Button()
{
X = Application.GetRealWidth(16),
Y = btnAntiLockText.Bottom,
Width = Application.GetRealWidth(339),
Height = Application.GetRealHeight(37 + 15),
TextAlignment = TextAlignment.TopLeft,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
IsMoreLines = true,
TextID = StringId.AntiLockModeTip,
};
antiLockView.AddChidren(btnAntilockTipText);
btnAntiLockSwitchIcon = new Button()
{
X = Application.GetRealWidth(322),
Y = Application.GetRealHeight(8),
Width = Application.GetMinRealAverage(36),
Height = Application.GetMinRealAverage(36),
UnSelectedImagePath = "Public/Switch_2.png",
SelectedImagePath = "Public/SwitchOn_2.png",
IsSelected = ezvizAntiLock,
};
antiLockView.AddChidren(btnAntiLockSwitchIcon);
#endregion
#region 布防模式
var defenceView = new FrameLayout()
{
Height = Application.GetRealHeight(94),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
contentView.AddChidren(defenceView);
defenceView.AddChidren(new Button()
{
Gravity = Gravity.CenterHorizontal,
Height = 1,
BackgroundColor = CSS_Color.DividingLineColor,
});
var btnDefenceText = new Button()
{
X = Application.GetRealWidth(16),
Y = Application.GetRealHeight(7),
Height = Application.GetRealHeight(37),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.DefenceMode
};
defenceView.AddChidren(btnDefenceText);
var btnDefenceTipText = new Button()
{
X = Application.GetRealWidth(16),
Y = btnDefenceText.Bottom,
Width = Application.GetRealWidth(339),
Height = Application.GetRealHeight(37 + 15),
TextAlignment = TextAlignment.TopLeft,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
IsMoreLines = true,
TextID = StringId.DoorlockDefenceModeTip,
};
defenceView.AddChidren(btnDefenceTipText);
btnDefenceStatusSwitchIcon = new Button()
{
X = Application.GetRealWidth(322),
Y = Application.GetRealHeight(8),
Width = Application.GetMinRealAverage(36),
Height = Application.GetMinRealAverage(36),
UnSelectedImagePath = "Public/Switch_2.png",
SelectedImagePath = "Public/SwitchOn_2.png",
IsSelected = ezvizAntiLock,
};
defenceView.AddChidren(btnDefenceStatusSwitchIcon);
#endregion
var waitPage = new Loading();
bodyView.AddChidren(waitPage);
waitPage.Start("");
new System.Threading.Thread(() => {
try
{
var pack = ApiUtlis.Ins.HttpRequest.GetDoubleClickOpenDoorSwitch(device.deviceId);
if (pack != null && pack.Code == StateCode.SUCCESS)
{
Application.RunOnMainThread(() =>
{
//更新界面
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject(pack.Data.ToString());
btnSecondaryUnlockingUnlockkSwtichIcon.IsSelected = obj.enabled.ToString() == "0" ? false : true;
});
}
else
{
//失败提示
Application.RunOnMainThread(() =>
{
if (!string.IsNullOrEmpty(pack.message))
{
if (string.IsNullOrEmpty(pack.message))
{
pack.message = Language.StringByID(StringId.OperationFailed);
}
var tip = new Tip()
{
MaxWidth = Application.GetRealWidth(300),
Text = $"{pack.message}({pack.Code})",
CloseTime = 3,
Direction = AMPopTipDirection.None
};
tip.Show(MainPage.BaseView);
}
});
}
#region 查询童锁开关状态
pack = ApiUtlis.Ins.HttpRequest.GetChildLockSwitch(device.deviceId);
if (pack != null && pack.Code == StateCode.SUCCESS)
{
Application.RunOnMainThread(() =>
{
//更新界面
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject(pack.Data.ToString());
btnChildLockSwitchIcon.IsSelected = obj.enabled.ToString() == "0" ? false : true;
});
}
else
{
//失败提示
Application.RunOnMainThread(() =>
{
if (string.IsNullOrEmpty(pack.message))
{
pack.message = Language.StringByID(StringId.OperationFailed);
}
var tip = new Tip()
{
MaxWidth = Application.GetRealWidth(300),
Text = $"{pack.message}({pack.Code})",
CloseTime = 3,
Direction = AMPopTipDirection.None
};
tip.Show(MainPage.BaseView);
});
}
#endregion
#region 查询反锁开关状态
pack = ApiUtlis.Ins.HttpRequest.GetAntiLockCfg(device.deviceId);
if (pack != null && pack.Code == StateCode.SUCCESS)
{
Application.RunOnMainThread(() =>
{
try
{
//更新界面
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject(pack.Data.ToString());
btnAntiLockSwitchIcon.IsSelected = (bool)obj.enabled;
}catch(Exception ex)
{
MainPage.Log($"update btnAntiLockSwitchIcon.IsSelected error :{ex.Message}");
}
});
}
else
{
//失败提示
Application.RunOnMainThread(() =>
{
if (string.IsNullOrEmpty(pack.message))
{
pack.message = Language.StringByID(StringId.OperationFailed);
}
var tip = new Tip()
{
MaxWidth = Application.GetRealWidth(300),
Text = $"{pack.message}({pack.Code})",
CloseTime = 3,
Direction = AMPopTipDirection.None
};
tip.Show(MainPage.BaseView);
});
}
#endregion
#region 查询布防状态
pack = ApiUtlis.Ins.HttpRequest.GetDefenceStatus(device.deviceId);
if (pack != null && pack.Code == StateCode.SUCCESS)
{
Application.RunOnMainThread(() =>
{
//更新界面
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject(pack.Data.ToString());
btnDefenceStatusSwitchIcon.IsSelected = obj.armStatus == "disarmed" ? false : true;
});
}
else
{
//失败提示
Application.RunOnMainThread(() =>
{
if (string.IsNullOrEmpty(pack.message))
{
pack.message = Language.StringByID(StringId.OperationFailed);
}
{
var tip = new Tip()
{
MaxWidth = Application.GetRealWidth(300),
Text = $"{pack.message}({pack.Code})",
CloseTime = 3,
Direction = AMPopTipDirection.None
};
tip.Show(MainPage.BaseView);
}
});
}
#endregion
}
catch (Exception ex)
{
MainPage.Log($"UnlockSettingPage error : {ex.Message}");
}
finally
{
Application.RunOnMainThread(() =>
{
waitPage.Hide();
});
}
}) { IsBackground = true }.Start();
#region 配置事件
btnSecondaryUnlockingUnlockkSwtichIcon.MouseUpEventHandler = (sender, e) => {
waitPage.Start("");
int changeState = 0;
if (!btnSecondaryUnlockingUnlockkSwtichIcon.IsSelected)
{
btnSecondaryUnlockingUnlockkSwtichIcon.IsSelected = true;
changeState = 1;
}
new System.Threading.Thread(() => {
try
{
var pack = ApiUtlis.Ins.HttpRequest.SetDoubleClickOpenDoorSwitch(device.deviceId,changeState);
if (pack != null && pack.Code == StateCode.SUCCESS)
{
Application.RunOnMainThread(() =>
{
//更新界面
btnSecondaryUnlockingUnlockkSwtichIcon.IsSelected = changeState == 1;
});
}
else
{
//失败提示
Application.RunOnMainThread(() =>
{
if (string.IsNullOrEmpty(pack.message))
{
pack.message = Language.StringByID(StringId.OperationFailed);
}
{
var tip = new Tip()
{
MaxWidth = Application.GetRealWidth(300),
Text = $"{pack.message}({pack.Code})",
CloseTime = 3,
Direction = AMPopTipDirection.None
};
tip.Show(MainPage.BaseView);
}
});
}
}
catch (Exception ex)
{
MainPage.Log($"SetDoubleClickOpenDoorSwitch error : {ex.Message}");
}
finally
{
Application.RunOnMainThread(() =>
{
waitPage.Hide();
});
}
}) { IsBackground = true }.Start();
};
btnChildLockSwitchIcon.MouseUpEventHandler = (sender, e) => {
waitPage.Start("");
int changeState = 0;
if (!btnChildLockSwitchIcon.IsSelected)
{
btnChildLockSwitchIcon.IsSelected = true;
changeState = 1;
}
new System.Threading.Thread(() => {
try
{
var pack = ApiUtlis.Ins.HttpRequest.SetChildLockSwitch(device.deviceId, changeState);
if (pack != null && pack.Code == StateCode.SUCCESS)
{
Application.RunOnMainThread(() =>
{
//更新界面
btnChildLockSwitchIcon.IsSelected = changeState == 1;
});
}
else
{
//失败提示
Application.RunOnMainThread(() =>
{
if (string.IsNullOrEmpty(pack.message))
{
pack.message = Language.StringByID(StringId.OperationFailed);
}
{
var tip = new Tip()
{
MaxWidth = Application.GetRealWidth(300),
Text = $"{pack.message}({pack.Code})",
CloseTime = 3,
Direction = AMPopTipDirection.None
};
tip.Show(MainPage.BaseView);
}
});
}
}
catch (Exception ex)
{
MainPage.Log($"SetChildLockSwitch error : {ex.Message}");
}
finally
{
Application.RunOnMainThread(() =>
{
waitPage.Hide();
});
}
})
{ IsBackground = true }.Start();
};
btnAntiLockSwitchIcon.MouseUpEventHandler = (sender, e) => {
waitPage.Start("");
bool changeState = false;
if (!btnAntiLockSwitchIcon.IsSelected)
{
btnAntiLockSwitchIcon.IsSelected = true;
changeState = true;
}
new System.Threading.Thread(() => {
try
{
var pack = ApiUtlis.Ins.HttpRequest.SetAntiLockCfg(device.deviceId, changeState);
if (pack != null && pack.Code == StateCode.SUCCESS)
{
Application.RunOnMainThread(() =>
{
//更新界面
btnAntiLockSwitchIcon.IsSelected = changeState;
});
}
else
{
//失败提示
Application.RunOnMainThread(() =>
{
if (string.IsNullOrEmpty(pack.message))
{
pack.message = Language.StringByID(StringId.OperationFailed);
}
{
var tip = new Tip()
{
MaxWidth = Application.GetRealWidth(300),
Text = $"{pack.message}({pack.Code})",
CloseTime = 3,
Direction = AMPopTipDirection.None
};
tip.Show(MainPage.BaseView);
}
});
}
}
catch (Exception ex)
{
MainPage.Log($"SetAntiLockCfg error : {ex.Message}");
}
finally
{
Application.RunOnMainThread(() =>
{
waitPage.Hide();
});
}
})
{ IsBackground = true }.Start();
};
btnDefenceStatusSwitchIcon.MouseUpEventHandler = (sender, e) => {
waitPage.Start("");
bool changeState = false;
if (!btnDefenceStatusSwitchIcon.IsSelected)
{
btnDefenceStatusSwitchIcon.IsSelected = true;
changeState = true;
}
new System.Threading.Thread(() => {
try
{
var pack = ApiUtlis.Ins.HttpRequest.SetDefenceStatus(device.deviceId, changeState);
if (pack != null && pack.Code == StateCode.SUCCESS)
{
Application.RunOnMainThread(() =>
{
//更新界面
btnDefenceStatusSwitchIcon.IsSelected = changeState;
});
}
else
{
//失败提示
Application.RunOnMainThread(() =>
{
if (string.IsNullOrEmpty(pack.message))
{
pack.message = Language.StringByID(StringId.OperationFailed);
}
{
var tip = new Tip()
{
MaxWidth = Application.GetRealWidth(300),
Text = $"{pack.message}({pack.Code})",
CloseTime = 3,
Direction = AMPopTipDirection.None
};
tip.Show(MainPage.BaseView);
}
});
}
}
catch (Exception ex)
{
MainPage.Log($"SetDefenceStatus error : {ex.Message}");
}
finally
{
Application.RunOnMainThread(() =>
{
waitPage.Hide();
});
}
})
{ IsBackground = true }.Start();
};
#endregion
}
}
///
/// 门锁配置
///
public class StateObj
{
public object enabled;
}
public class DoorlockDefenceState
{
///
/// 布防状态 disarmed-撤防 armed-已布防
///
public string armStatus;
///
/// 布防模式 global-全局 atHome-在家 outDoor-外出 sleep-睡眠
///
public string defenceMode;
}
}