using System;
namespace Shared.SimpleControl.Phone
{
public class UserSecurityAreaPage : FrameLayout
{
static UserSecurityAreaPage curView;
FrameLayout BodyView;
SecurityModul sm;
Button btnDay;
Button btnAtNight;
Button btnGoAway;
Button btnVacation;
Button btnReception;
Button btnDisarm;
///
/// 构造函数
///
public UserSecurityAreaPage (SecurityModul fh)
{
this.sm = fh;
curView = this;
BackgroundColor = SkinStyle.Current.MainColor;
}
public static void UnSelectedStatus ()
{
curView.btnDay.IsSelected = false;
curView.btnDisarm.IsSelected = false;
curView.btnGoAway.IsSelected = false;
curView.btnAtNight.IsSelected = false;
curView.btnVacation.IsSelected = false;
curView.btnReception.IsSelected = false;
}
public static void UpdateStatus (SecurityModul updataSM)
{
if (curView == null) {
return;
}
if (curView.sm.SubnetID != updataSM.SubnetID && curView.sm.DeviceID != updataSM.DeviceID && curView.sm.LoopID != updataSM.LoopID) {
return;
}
Application.RunOnMainThread (() => {
for (int i = 0; i < curView.BodyView.ChildrenCount; i++) {
try {
UnSelectedStatus ();
/// VacationArm = 1,//假期
/// AwayArm = 2,//离开
/// NightArm = 3,//晚上
/// NightWithGuestArm = 4,//夜
/// DayArm = 5,//白天
/// Disarm = 6,// 解除安防
switch (updataSM.AreaType) {
case 1:
curView.btnVacation.IsSelected = true;
break;
case 2:
curView.btnGoAway.IsSelected = true;
break;
case 3:
curView.btnAtNight.IsSelected = true;
break;
case 4:
curView.btnReception.IsSelected = true;
break;
case 5:
curView.btnDay.IsSelected = true;
break;
default:
curView.btnDisarm.IsSelected = true;
break;
}
} catch (Exception ex) {
Console.WriteLine ("UserACPage " + ex.ToString ());
}
}
});
}
///
/// 显示出当前房间所有的地热
///
public void ShowSecurityArea ()
{
#region 标题
var topView = new FrameLayout () {
Y = Application.GetRealHeight (36),
Height = Application.GetRealHeight (90),
};
AddChidren (topView);
var title = new Button () {
TextAlignment = TextAlignment.Center,
Text = sm.Name,
TextSize = 19,
TextColor = SkinStyle.Current.TextColor1
};
topView.AddChidren (title);
var logo = new Button () {
Width = Application.GetRealWidth (154),
Height = Application.GetRealHeight (90),
X = Application.GetRealWidth (486),
UnSelectedImagePath = MainPage.LogoString,
};
topView.AddChidren (logo);
var back = new Button () {
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (85),
UnSelectedImagePath = "Item/Back.png",
SelectedImagePath = "Item/BackSelected.png",
};
topView.AddChidren (back);
back.MouseUpEventHandler += (sender, e) => {
(Parent as PageLayout).PageIndex -= 1;
curView = null;
};
#endregion
BodyView = new FrameLayout {
Height = Application.GetRealHeight (Application.DesignHeight - 126),
Y = Application.GetRealHeight (126),
};
AddChidren (BodyView);
FrameLayout roomBackgroundImageView = new FrameLayout () {
Height = Application.GetRealHeight (360),
BackgroundImagePath = "Security/SecurityBackgoround.png"
};
BodyView.AddChidren (roomBackgroundImageView);
FrameLayout subtitleView = new FrameLayout () {
Height = Application.GetRealHeight (100),
Y = roomBackgroundImageView.Bottom,
BackgroundColor = SkinStyle.Current.ViewColor
};
BodyView.AddChidren (subtitleView);
FrameLayout contentView = new FrameLayout () {
Height = Application.GetRealHeight (Application.DesignHeight - 126 - 360 - 100),
Y = subtitleView.Bottom,
BackgroundColor = SkinStyle.Current.ViewColor
};
BodyView.AddChidren (contentView);
Button btnArm = new Button () {
Width = Application.GetRealWidth (320),
BackgroundColor = SkinStyle.Current.SubtitleView,
TextID = R.MyInternationalizationString.SecurityState,
TextAlignment = TextAlignment.Center,
};
subtitleView.AddChidren (btnArm);
btnArm.MouseUpEventHandler += (sender, e) => {
initArmView (contentView);
};
Button btnDryContact = new Button () {
X = btnArm.Right + Application.GetRealWidth (4),
Width = Application.GetRealWidth (320),
TextID = R.MyInternationalizationString.SensorState,
TextAlignment = TextAlignment.Center,
BackgroundColor = SkinStyle.Current.SubtitleView,
};
subtitleView.AddChidren (btnDryContact);
btnDryContact.MouseUpEventHandler += (sender, e) => {
showDrycontactList (contentView);
};
initArmView (contentView);
}
void showDrycontactList (FrameLayout cView)
{
cView.RemoveAll ();
VerticalScrolViewLayout contentView = new VerticalScrolViewLayout () {
BackgroundColor = SkinStyle.Current.ViewColor,
};
cView.AddChidren (contentView);
System.Threading.Tasks.Task.Run (() => {
try {
Application.RunOnMainThread (() => {
MainPage.Loading.Start ("");
});
int loseCount = 0;
foreach (var dr in sm.SensorList) {
string btnTipString = "";
if (loseCount < 3) {
var drBytes = Control.ControlBytesSendHasReturn (Command.ReadSecurityStatus, sm.SubnetID, sm.DeviceID, new byte [] { dr.AreaNumber, dr.IndexOfScurity, 0 });
if (drBytes != null) {
loseCount = 0;
dr.Status = drBytes [2];
dr.ByPass = drBytes [3];
if (drBytes [3] == 1) {
btnTipString = "Bypass";
}
} else {
loseCount++;
btnTipString = Language.StringByID (R.MyInternationalizationString.NotOnline);
}
}
Application.RunOnMainThread (() => {
FrameLayout drRowView = new FrameLayout () {
Height = Application.GetRealHeight (100),
BackgroundColor = SkinStyle.Current.ViewColor,
};
contentView.AddChidren (drRowView);
//Button btnTip = new Button () {
// X = Application.GetRealWidth(120),
// Width = Application.GetRealWidth(400),
// TextAlignment = TextAlignment.TopLeft,
// Text = btnTipString,
// TextSize = 12,
//};
//drRowView.AddChidren (btnTip);
Button btnIcon = new Button () {
X = Application.GetRealWidth (10),
Y = Application.GetRealHeight (5),
Width = Application.GetRealWidth (95),
Height = Application.GetRealHeight (90),
};
drRowView.AddChidren (btnIcon);
switch (dr.SensorType) {
case 0:
btnIcon.UnSelectedImagePath = "Security/IconWindow.png";
btnIcon.SelectedImagePath = "Security/IconWindowOn.png";
break;
case 1:
btnIcon.UnSelectedImagePath = "Security/IconDoor.png";
btnIcon.SelectedImagePath = "Security/IconDoorOn.png";
break;
default:
btnIcon.UnSelectedImagePath = "Security/IconInduction.png";
btnIcon.SelectedImagePath = "Security/IconInductionOn.png";
break;
}
Button btnName = new Button () {
X = btnIcon.Right + Application.GetRealWidth (5),
Width = Application.GetRealWidth (360),
TextAlignment = TextAlignment.CenterLeft,
TextColor = SkinStyle.Current.TextColor1,
Text = dr.Name,
};
drRowView.AddChidren (btnName);
Button btnStatus = new Button () {
X = btnName.Right + Application.GetRealWidth (5),
Width = Application.GetRealWidth (140),
TextAlignment = TextAlignment.Center,
TextColor = SkinStyle.Current.TextColor1,
};
drRowView.AddChidren (btnStatus);
btnStatus.MouseLongEventHandler += (sender, e) => {
if (dr.Status == 2) {
return;
}
MainPage.Loading.Start ("");
byte [] byResult = null;
System.Threading.Tasks.Task.Run (() => {
try {
if (dr.ByPass == 1) {
dr.ByPass = 0;
byResult = Control.ControlBytesSendHasReturn (Command.SetSecurityByPass, sm.SubnetID, sm.DeviceID, new byte [] { dr.AreaNumber, dr.IndexOfScurity, dr.ByPass });
} else {
dr.ByPass = 1;
byResult = Control.ControlBytesSendHasReturn (Command.SetSecurityByPass, sm.SubnetID, sm.DeviceID, new byte [] { dr.AreaNumber, dr.IndexOfScurity, dr.ByPass });
}
} catch (Exception ex) {
Console.WriteLine ("Bypass " + ex.ToString ());
} finally {
Application.RunOnMainThread (() => {
if (byResult == null) {
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.OperationFailed),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
} else {
if (dr.ByPass == 1) {
btnStatus.Text = "Bypass";
} else {
if (dr.Status == 0) {
btnStatus.TextID = R.MyInternationalizationString.Close;
} else {
btnStatus.TextID = R.MyInternationalizationString.Open;
}
}
}
MainPage.Loading.Hide ();
});
}
});
};
if (btnTipString == "") {
if (dr.Status == 0) {
btnStatus.TextID = R.MyInternationalizationString.Close;
} else {
btnStatus.TextID = R.MyInternationalizationString.Open;
}
} else {
btnStatus.Text = btnTipString;
}
Button btnNullLine = new Button () {
Y = Application.GetRealHeight (97),
Height = Application.GetRealHeight (3),
BackgroundColor = SkinStyle.Current.White20Transparent,
};
drRowView.AddChidren (btnNullLine);
});
}
} catch (Exception ex) {
Console.WriteLine ("ShowDry" + ex.ToString ());
} finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
});
}
});
}
void initArmView(FrameLayout contentView){
contentView.RemoveAll ();
var btnPadding = Application.DeviceType == Device.Ios ? new Padding (Application.GetRealHeight (120), 0, 0, 0) : new Padding (Application.GetRealHeight (110), 0, 0, 0);
btnDay = new Button () {
X = Application.GetRealWidth (30),
Y = Application.GetRealHeight (60),
Width = Application.GetRealWidth (140),
Height = Application.GetRealHeight (140),
UnSelectedImagePath = "Security/Day.png",
SelectedImagePath = "Security/DayOn.png",
TextID = R.MyInternationalizationString.Day,
Padding = btnPadding,
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
};
contentView.AddChidren (btnDay);
btnDay.MouseUpEventHandler += (sender, e) => {
ControlArm (btnDay, 5);
};
btnAtNight = new Button () {
Gravity = Gravity.CenterHorizontal,
Y = btnDay.Y,
Width = Application.GetRealWidth (140),
Height = Application.GetRealHeight (140),
UnSelectedImagePath = "Security/Night.png",
SelectedImagePath = "Security/NightOn.png",
TextID = R.MyInternationalizationString.AtNight,
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
Padding = btnPadding,
};
contentView.AddChidren (btnAtNight);
btnAtNight.MouseUpEventHandler += (sender, e) => {
ControlArm (btnAtNight, 3);
};
btnGoAway = new Button () {
X = Application.GetRealWidth (640 - 140 - 30),
Y = btnDay.Y,
Width = Application.GetRealWidth (140),
Height = Application.GetRealHeight (140),
UnSelectedImagePath = "Security/Away.png",
SelectedImagePath = "Security/AwayOn.png",
TextID = R.MyInternationalizationString.GoAway,
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
Padding = btnPadding
};
contentView.AddChidren (btnGoAway);
btnGoAway.MouseUpEventHandler += (sender, e) => {
ControlArm (btnGoAway, 2);
};
btnVacation = new Button () {
X = Application.GetRealWidth (30),
Y = btnDay.Bottom + Application.GetRealHeight (50),
Width = Application.GetRealWidth (140),
Height = Application.GetRealHeight (140),
UnSelectedImagePath = "Security/Vacation.png",
SelectedImagePath = "Security/VacationOn.png",
TextID = R.MyInternationalizationString.Vacation,
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
Padding = btnPadding,
};
contentView.AddChidren (btnVacation);
btnVacation.MouseUpEventHandler += (sender, e) => {
ControlArm (btnVacation, 1);
};
btnReception = new Button () {
Gravity = Gravity.CenterHorizontal,
Y = btnVacation.Y,
Width = Application.GetRealWidth (140),
Height = Application.GetRealHeight (140),
UnSelectedImagePath = "Security/Reception.png",
SelectedImagePath = "Security/ReceptionOn.png",
TextID = R.MyInternationalizationString.Reception,
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
Padding = btnPadding
};
contentView.AddChidren (btnReception);
btnReception.MouseUpEventHandler += (sender, e) => {
ControlArm (btnReception, 4);
};
btnDisarm = new Button () {
X = Application.GetRealWidth (640 - 140 - 30),
Y = btnVacation.Y,
Width = Application.GetRealWidth (140),
Height = Application.GetRealHeight (140),
UnSelectedImagePath = "Security/Disarm.png",
SelectedImagePath = "Security/DisarmOn.png",
TextID = R.MyInternationalizationString.Disarm,
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
Padding = btnPadding
};
contentView.AddChidren (btnDisarm);
btnDisarm.MouseUpEventHandler += (sender, e) => {
Disarm (contentView);
};
System.Threading.Tasks.Task.Run (() => {
try {
var armBytes = Control.ControlBytesSendHasReturn (Command.ReadArm, sm.SubnetID, sm.DeviceID, new byte [] { sm.LoopID });
Application.RunOnMainThread (() => {
if (armBytes == null) {
} else {
sm.AreaType = armBytes [1];
UpdateStatus (sm);
}
});
} catch (Exception ex) {
Console.WriteLine ("arm : " + ex.ToString ());
} finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
});
}
});
}
void ControlArm (Button btn, byte armType)
{
if (!btn.IsSelected) {
MainPage.Loading.Start ("");
System.Threading.Tasks.Task.Run (() => {
try {
var armBytes = Control.ControlBytesSendHasReturn (Command.SetArm, sm.SubnetID, sm.DeviceID, new byte [] { sm.LoopID, armType });
Application.RunOnMainThread (() => {
if (armBytes == null) {
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
} else {
if (armType == 6) {
if (armBytes [1] == armType) {
UnSelectedStatus ();
btn.IsSelected = true;
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipDisarmSuccess),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
} else{
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipDisarmFail),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
}
} else {
if (armBytes [1] == armType) {
UnSelectedStatus ();
btn.IsSelected = true;
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipArmSuccess),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
}else {
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipArmFail),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
}
}
}
});
} catch (Exception ex) {
Console.WriteLine ("arm : " + ex.ToString ());
} finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
});
}
});
}
}
void Disarm (FrameLayout securityTypeView)
{
FrameLayout contentView = new FrameLayout () {
BackgroundColor = SkinStyle.Current.ViewColor,
};
securityTypeView.AddChidren (contentView);
Button btnTipButton = new Button () {
X = Application.GetRealWidth (40),
Y = Application.GetRealHeight(20),
Width = Application.GetRealWidth (600),
Height = Application.GetRealHeight (80),
TextID = R.MyInternationalizationString.PleaseEnterPassword,
TextAlignment = TextAlignment.CenterLeft
};
contentView.AddChidren (btnTipButton);
string pwString = "";
Button btnPW = new Button () {
Y = btnTipButton.Bottom,
Height = Application.GetRealHeight (70),
TextAlignment = TextAlignment.Center,
TextColor = SkinStyle.Current.TextColor1,
TextSize = 34,
Text = "- - - - - - - -"
};
contentView.AddChidren (btnPW);
FrameLayout numberView = new FrameLayout () {
X = Application.GetRealWidth (25),
Y = btnPW.Bottom ,
Height = Application.GetRealHeight (240),
};
contentView.AddChidren (numberView);
int pNumber = 1;
FrameLayout bottomView = new FrameLayout () {
Y = numberView.Bottom + Application.GetRealHeight (20),
Height = Application.GetRealHeight (140),
};
contentView.AddChidren (bottomView);
Button btnClear = new Button () {
X = Application.GetRealWidth (40),
Y = Application.GetRealHeight (20),
Width = Application.GetRealWidth (250),
Height = Application.GetRealHeight (80),
TextAlignment = TextAlignment.Center,
TextID = R.MyInternationalizationString.cancel,
BackgroundColor = SkinStyle.Current.ButtonColor1,
SelectedBackgroundColor = SkinStyle.Current.ButtonColor1,
BorderColor = SkinStyle.Current.Transparent,
TextColor = SkinStyle.Current.DialogTextColor,
BorderWidth = 0,
Radius = 5,
};
bottomView.AddChidren (btnClear);
Button btnSave = new Button () {
X = btnClear.Right + Application.GetRealWidth (70),
Y = Application.GetRealHeight (20),
Width = Application.GetRealWidth (250),
Height = Application.GetRealHeight (80),
TextAlignment = TextAlignment.Center,
TextID = R.MyInternationalizationString.confirm,
BackgroundColor = SkinStyle.Current.ButtonColor1,
SelectedBackgroundColor = SkinStyle.Current.ButtonColor1,
BorderColor = SkinStyle.Current.Transparent,
TextColor = SkinStyle.Current.DialogTextColor,
BorderWidth = 0,
Radius = 5,
};
bottomView.AddChidren (btnSave);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 5; j++) {
string unP = "TV/TV2_" + pNumber.ToString ();
string uSP = "TV/TV2_" + pNumber.ToString () + "_on";
Button btn = new Button () {
X = Application.GetRealWidth (120 * j),
Y = Application.GetRealHeight (120 * i),
Width = Application.GetRealWidth (120),
Height = Application.GetRealHeight (120),
UnSelectedImagePath = unP + ".png",
SelectedImagePath = uSP + ".png",
Tag = pNumber
};
numberView.AddChidren (btn);
btn.MouseDownEventHandler += (sende2r, e2) => {
btn.IsSelected = true;
};
btn.MouseUpEventHandler += (sender2, e2) => {
btn.IsSelected = false;
btnClear.TextID = R.MyInternationalizationString.Clear;
if (pwString.Length == 8)
return;
string NumString = ((Button)(sender2)).Tag.ToString ();
if (NumString == "10")
NumString = "0";
pwString += NumString;
string btnpws = "";
for (int c = 0; c < 8; c++) {
if (c < pwString.Length) {
btnpws += "* ";
} else {
btnpws += "- ";
}
}
btnPW.Text = btnpws;
if (pwString.Length == 8) {
btnSave.IsSelected = btnSave.Enable = true;
}
};
pNumber++;
}
}
btnClear.MouseUpEventHandler += (sender2, e2) => {
if (btnClear.TextID == R.MyInternationalizationString.Clear) {
pwString = "";
btnPW.Text = "- - - - - - - -";
btnSave.IsSelected = btnSave.Enable = false;
btnClear.TextID = R.MyInternationalizationString.cancel;
} else {
contentView.RemoveFromParent ();
}
};
btnSave.MouseUpEventHandler += (sender2, e2) => {
if (pwString.Length == 8) {
if (pwString == UserConfig.Instance.ArmPW) {
pwString = "";
btnPW.Text = "- - - - - - - -";
contentView.RemoveFromParent ();
ControlArm (btnDisarm, 6);
} else {
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PasswordIsError),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
pwString = "";
btnPW.Text = "- - - - - - - -";
}
}
};
}
}
}