using System;
|
using System.Text.RegularExpressions;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class RemotelyUnlock : FrameLayout
|
{
|
|
DoorLock doorLock;
|
//UserInfo user_Info = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo> (System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (UserInfo.GlobalRegisterFile)));
|
|
public RemotelyUnlock (DoorLock DoorLock)
|
{
|
this.doorLock = DoorLock;
|
BackgroundColor = SkinStyle.Current.MainColor;
|
}
|
|
//string getPasword ()
|
//{
|
// var randomNum = Control.ControlBytesSendHasReturn (Command.CreatConnection, this.doorLock.SubnetID, this.doorLock.DeviceID, new byte [] { 1 });
|
// if (randomNum != null) {
|
// byte [] randomBytes = new byte [8];
|
// System.Array.Copy (randomNum, 1, randomBytes, 0, 8);
|
// byte [] inpuptBytes = { 0x1F, 0xE0, this.doorLock.LoopID };
|
// var encryptionBytes = Security.Encryption (randomBytes, inpuptBytes);
|
// //门锁远程控制密码读取命令
|
// var resultBytes = Control.ControlBytesSendHasReturn (Command.SendEncryptionAfterConnected, this.doorLock.SubnetID, this.doorLock.DeviceID, encryptionBytes);
|
// if (resultBytes != null) {
|
// var ddBytes = Security.Encryption (randomBytes, resultBytes);
|
// var password = "";
|
// for (int i = 3; i < 9; i++) {
|
// password += ddBytes [i];
|
// }
|
// return password;
|
// }
|
// }
|
// return null;
|
//}
|
|
public void ShowUserRemoteUnLock ()
|
{
|
#region 标题
|
var topView = new FrameLayout () {
|
Y = Application.GetRealHeight (36),
|
Height = Application.GetRealHeight (90),
|
};
|
AddChidren (topView);
|
|
var title = new Button () {
|
TextAlignment = TextAlignment.Center,
|
TextID = R.MyInternationalizationString.RemotelyUnlock,
|
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,
|
Gravity = Gravity.CenterVertical,
|
};
|
topView.AddChidren (logo);
|
var back = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
SelectedImagePath = "Item/BackSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
topView.AddChidren (back);
|
back.MouseUpEventHandler += (sender, e) => {
|
this.RemoveFromParent ();
|
};
|
#endregion
|
|
#region bodyScrolView
|
var bodyScrolView = new FrameLayout () {
|
Height = Application.GetRealHeight (1136 - 126),
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
Y = topView.Bottom,
|
};
|
AddChidren (bodyScrolView);
|
|
var passwordText = new EditText () {
|
Y = Application.GetRealHeight (70),
|
Width = Application.GetRealWidth (480),
|
Gravity = Gravity.CenterHorizontal,
|
PlaceholderText = Language.StringByID (R.MyInternationalizationString.InputSixPassword),
|
TextAlignment = TextAlignment.Center,
|
UnSelectedImagePath = "Register/Register_Password_kuang.png",
|
PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor,
|
Radius = (uint)Application.GetRealHeight (0),
|
TextColor = SkinStyle.Current.TextColor1,
|
SecureTextEntry = true,
|
TextSize = 15,
|
};
|
bodyScrolView.AddChidren (passwordText);
|
|
var btnTip = new Button () {
|
Height = Application.GetRealHeight (60),
|
Width = Application.GetRealWidth (60),
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight (200),
|
Enable = false,
|
Visible = false,
|
};
|
bodyScrolView.AddChidren (btnTip);
|
var btnLock = new Button () {
|
Height = Application.GetRealHeight (300),
|
Width = Application.GetRealWidth (301),
|
UnSelectedImagePath = "DoorLockPic/door_lock_close.png",
|
SelectedImagePath = "DoorLockPic/door_lock_open.png",
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight (370),
|
Enable = false,
|
};
|
bodyScrolView.AddChidren (btnLock);
|
|
DateTime delayTime = DateTime.Now.AddSeconds (-15);
|
passwordText.TextChangeEventHandler += (sender, e) => {
|
if (passwordText.Text.Length == 6) {
|
if (passwordText.Text == doorLock.GetDoorLockPassword ()) {
|
btnLock.Enable = true;
|
} else {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.PasswordIsError), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show ((View)sender);
|
passwordText.Text = "";
|
}
|
}
|
};
|
#endregion
|
|
DateTime dateTime = DateTime.Now.AddSeconds (-15);
|
btnLock.MouseDownEventHandler += (sender, e) => {
|
btnLock.IsSelected = true;
|
if (DateTime.Now <= dateTime) {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.AfterFifteenSeconds), Direction = AMPopTipDirection.Up, CloseTime = 4 }.Show (btnTip);
|
return;
|
}
|
|
var inputPassword = passwordText.Text.Trim ();
|
var password = doorLock.GetDoorLockPassword ();
|
if (password != inputPassword) {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.PasswordIsError), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show (btnTip);
|
return;
|
}
|
|
//开锁控制
|
//System.Threading.Tasks.Task.Run (() => {
|
//var password = getPasword ();
|
var randomNum = Control.ControlBytesSendHasReturn (Command.CreatConnection, doorLock.SubnetID, doorLock.DeviceID, new byte [] { 1 });
|
if (randomNum != null) {
|
var randomBytes = new byte [8];
|
System.Array.Copy (randomNum, 1, randomBytes, 0, 8);
|
|
var word = "123456";
|
var passwordArray = new byte [word.Length];
|
for (int index = 0; index < word.Length; index++) {
|
passwordArray [index] = byte.Parse (word [index].ToString ());
|
}
|
|
//备注20位
|
var deviceBytes = CommonPage.MyEncodingGB2312.GetBytes ("HDL ON");
|
|
var inpuptBytes = new byte [] { 0x1F, 0x56, doorLock.LoopID, 1 };
|
var allAddBytes = new byte [4 + 6 + 2 + 20];
|
System.Array.Copy (inpuptBytes, 0, allAddBytes, 0, 4);
|
System.Array.Copy (passwordArray, 0, allAddBytes, 4, 6);
|
System.Array.Copy (deviceBytes, 0, allAddBytes, 4 + 6 + 2, deviceBytes.Length);
|
//加密远程开锁输入
|
var encryptionBsytes = Security.Encryption (randomBytes, allAddBytes);
|
var resultBytes = Control.ControlBytesSendHasReturn (Command.SendEncryptionAfterConnected, doorLock.SubnetID, doorLock.DeviceID, encryptionBsytes);
|
if (resultBytes == null) {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.DoorLockControlUnsuccessfully), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show (btnTip);
|
btnLock.IsSelected = false;
|
btnLock.Enable = false;
|
});
|
return;
|
} else {
|
if (Security.Encryption (randomBytes, resultBytes) [2] == 0xF8) {
|
dateTime = DateTime.Now.AddSeconds (15);
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.VertifyIsSuccess), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show (btnTip);
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.OperationFailed), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show (btnTip);
|
btnLock.IsSelected = false;
|
btnLock.Enable = false;
|
});
|
return;
|
}
|
}
|
} else {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.MaybeDeviceOffline), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show (btnTip);
|
btnLock.IsSelected = false;
|
btnLock.Enable = false;
|
});
|
}
|
//});
|
};
|
|
btnLock.MouseUpEventHandler += (sender, e) => {
|
btnLock.IsSelected = false;
|
btnLock.Enable = false;
|
passwordText.Text = "";
|
};
|
|
#region bottomFrameLayout
|
var bottomFrameLayout = new FrameLayout () {
|
Y = Application.GetRealHeight (1136 - 100),
|
};
|
AddChidren (bottomFrameLayout);
|
|
var btnForgotPassword = new Button () {
|
Height = Application.GetRealHeight (100),
|
TextID = R.MyInternationalizationString.ForgotPassword,
|
TextAlignment = TextAlignment.Center,
|
TextSize = 18,
|
BackgroundColor = SkinStyle.Current.TitileView,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
bottomFrameLayout.AddChidren (btnForgotPassword);
|
|
btnForgotPassword.MouseDownEventHandler += (sender, e) => {
|
btnForgotPassword.IsSelected = true;
|
//if (user_Info == null) {
|
// //提示还没有登陆
|
// new Alert ("", Language.StringByID (R.MyInternationalizationString.PleaseLoginSystem),
|
// Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
// return;
|
//}
|
ForgetPassword ();
|
};
|
|
btnForgotPassword.MouseUpEventHandler += (sender, e) => {
|
btnForgotPassword.IsSelected = false;
|
};
|
#endregion
|
|
if (doorLock.GetDoorLockPassword () == null) {
|
passwordText.Height = Application.GetRealHeight (0);
|
passwordText.PlaceholderText = "";
|
bottomFrameLayout.Height = Application.GetRealHeight (0);
|
} else {
|
passwordText.Height = Application.GetRealHeight (80);
|
bottomFrameLayout.Height = Application.GetRealHeight (100);
|
}
|
}
|
|
//void FirstPassword ()
|
//{
|
// Dialog dialog = new Dialog ();
|
// var dialogBodyView = new FrameLayout () {
|
// Width = Application.GetRealWidth (400),
|
// Height = Application.GetRealHeight (300),
|
// //BackgroundColor = SkinStyle.Current.DialogColor,
|
// BackgroundColor = 0xff000000,
|
// Radius = 5,
|
// BorderColor = SkinStyle.Current.Transparent,
|
// BorderWidth = 0,
|
// Gravity = Gravity.Center
|
// };
|
// dialog.AddChidren (dialogBodyView);
|
// var btnTitle = new Button () {
|
// Height = Application.GetRealHeight (80),
|
// BackgroundColor = SkinStyle.Current.DialogTitle,
|
// TextAlignment = TextAlignment.Center,
|
// TextID = R.MyInternationalizationString.SetPassword,
|
// };
|
// dialogBodyView.AddChidren (btnTitle);
|
// var textButton = new EditText () {
|
// X = Application.GetRealWidth (30),
|
// Y = btnTitle.Bottom + Application.GetRealHeight (25),
|
// Height = Application.GetRealHeight (80),
|
// Width = Application.GetRealWidth (340),
|
// Gravity = Gravity.CenterHorizontal,
|
// PlaceholderText = Language.StringByID (R.MyInternationalizationString.InputSixPassword),
|
// TextAlignment = TextAlignment.Center,
|
// UnSelectedImagePath = "Register/Register_Password_kuang.png",
|
// PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor,
|
// Radius = (uint)Application.GetRealHeight (0),
|
// TextColor = 0xffffffff,
|
// TextSize = 15,
|
// };
|
// dialogBodyView.AddChidren (textButton);
|
// var bottomView = new FrameLayout () {
|
// Y = dialogBodyView.Height - Application.GetRealHeight (80),
|
// Height = Application.GetRealHeight (80),
|
// BackgroundColor = SkinStyle.Current.DialogTitle,
|
// };
|
// dialogBodyView.AddChidren (bottomView);
|
// var btnBack = new Button () {
|
// Width = Application.GetRealWidth (119),
|
// UnSelectedImagePath = "Item/PositioningDialogBack.png",
|
// SelectedImagePath = "Item/PositioningDialogBack.png",
|
// };
|
// bottomView.AddChidren (btnBack);
|
// btnBack.MouseUpEventHandler += (sender1, e1) => {
|
// dialog.Close ();
|
// };
|
// var btnLineH = new Button () {
|
// Width = 1,
|
// Height = LayoutParams.MatchParent,
|
// BackgroundColor = SkinStyle.Current.White20Transparent,
|
// X = btnBack.Right,
|
// };
|
// bottomView.AddChidren (btnLineH);
|
// Button btnSave = new Button () {
|
// Width = Application.GetRealWidth (280),
|
// X = btnLineH.Right,
|
// TextID = R.MyInternationalizationString.SAVE,
|
// TextAlignment = TextAlignment.Center,
|
// Radius = 1,
|
// };
|
// bottomView.AddChidren (btnSave);
|
// btnSave.MouseUpEventHandler += (sender, e) => {
|
// if (doorLock.GetDoorLockPassword () == null) {
|
// new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.NoPassword), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show ((View)sender);
|
// return;
|
// }
|
// if (string.IsNullOrEmpty (textButton.Text.Trim ())) {
|
// new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.InputSixPassword), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show ((View)sender);
|
// return;
|
// }
|
// //string SuID = textButton.Text;
|
// //Regex reg = new Regex ("^[0-9]+$"); //判断是不是数据,要不是就表示没有选择,则从隐藏域里读出来
|
// //Match ma = reg.Match (SuID);
|
// //if (ma.Success) {
|
// // //是数字时的操作
|
// //} else {
|
// // new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.PasswordNotFormedFromSixDigitalCodes), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
|
// // return;
|
// //}
|
// doorLock.AddDoorLockPassword (textButton.Text.Trim ());
|
// dialog.Close ();
|
// };
|
// dialog.Show ();
|
//}
|
|
void ForgetPassword ()
|
{
|
Dialog dialog = new Dialog ();
|
var dialogBodyView = new FrameLayout () {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (420),
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
BorderWidth = 0,
|
Gravity = Gravity.Center
|
};
|
dialog.AddChidren (dialogBodyView);
|
|
var btnTitle = new Button () {
|
Height = Application.GetRealHeight (80),
|
BackgroundColor = SkinStyle.Current.DialogTitle,
|
TextAlignment = TextAlignment.Center,
|
TextID = R.MyInternationalizationString.FindPassword,
|
};
|
dialogBodyView.AddChidren (btnTitle);
|
|
Button btnTipEntryOnPW = new Button () {
|
X = Application.GetRealWidth (30),
|
Y = btnTitle.Bottom + Application.GetRealHeight (25),
|
Height = Application.GetRealHeight (80),
|
Width = Application.GetRealWidth (340),
|
TextID = R.MyInternationalizationString.PasswordForHDLON,
|
TextColor = SkinStyle.Current.TextColor,
|
};
|
dialogBodyView.AddChidren (btnTipEntryOnPW);
|
|
var accountPassword = new EditText () {
|
X = Application.GetRealWidth (30),
|
Y = btnTipEntryOnPW.Bottom + Application.GetRealHeight (25),
|
Height = Application.GetRealHeight (80),
|
Width = Application.GetRealWidth (340),
|
Gravity = Gravity.CenterHorizontal,
|
TextAlignment = TextAlignment.Center,
|
BorderColor = SkinStyle.Current.BorderColor,
|
BorderWidth = 2,
|
Radius = 5,
|
SecureTextEntry = true,
|
TextColor = SkinStyle.Current.TextColor,
|
TextSize = 15,
|
};
|
dialogBodyView.AddChidren (accountPassword);
|
|
//var obtainPassword = new Button () {
|
// X = Application.GetRealWidth (30),
|
// Y = accountPassword.Bottom + Application.GetRealHeight (25),
|
// Height = Application.GetRealHeight (85),
|
// Width = Application.GetRealWidth (340),
|
// TextSize = 15,
|
// Text = Language.StringByID (R.MyInternationalizationString.OK),
|
// Gravity = Gravity.CenterHorizontal,
|
// BorderWidth = 1,
|
// Radius = 5,
|
// BorderColor = SkinStyle.Current.BorderColor,
|
// //BorderColor = 0xFFff0000,
|
// TextAlignment = TextAlignment.Center,
|
// TextColor = SkinStyle.Current.TextColor1,
|
//};
|
//dialogBodyView.AddChidren (obtainPassword);
|
|
var bottomView = new FrameLayout () {
|
Y = dialogBodyView.Height - Application.GetRealHeight (80),
|
Height = Application.GetRealHeight (80),
|
BackgroundColor = SkinStyle.Current.DialogTitle,
|
};
|
dialogBodyView.AddChidren (bottomView);
|
|
Button btnclose = new Button () {
|
Width = Application.GetRealWidth (199),
|
TextID = R.MyInternationalizationString.cancel,
|
TextAlignment = TextAlignment.Center,
|
};
|
bottomView.AddChidren (btnclose);
|
btnclose.MouseUpEventHandler += (sender, e) => {
|
dialog.Close ();
|
};
|
|
var btnLineH = new Button () {
|
Width = 1,
|
Height = LayoutParams.MatchParent,
|
BackgroundColor = SkinStyle.Current.White20Transparent,
|
X = btnclose.Right,
|
};
|
bottomView.AddChidren (btnLineH);
|
|
Button btnReset = new Button () {
|
Width = Application.GetRealWidth (199),
|
X = btnLineH.Right,
|
TextID = R.MyInternationalizationString.Reset,
|
TextAlignment = TextAlignment.Center,
|
};
|
bottomView.AddChidren (btnReset);
|
btnReset.MouseUpEventHandler += (sender, e) => {
|
if (string.IsNullOrEmpty( accountPassword.Text )) {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.AccountPasswordIsEmpty), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show ((View)sender);
|
return;
|
}
|
|
if (accountPassword.Text != MainPage.LoginUser.Password) {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.PasswordIsError), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show ((View)sender);
|
return;
|
} else {
|
//obtainPassword.Text = doorLock.GetDoorLockPassword ();
|
dialog.Close ();
|
//this.RemoveFromParent ();
|
RemoteUnlockPasswordSet unlockView = new RemoteUnlockPasswordSet (doorLock);
|
UserMiddle.DevicePageView.AddChidren (unlockView);
|
unlockView.ShowDoorLockRemoteSetPassword ();
|
UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1;
|
}
|
};
|
|
//btnReset.MouseUpEventHandler += (sender, e) => {
|
// if (accountPassword.Text == null) {
|
// new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.AccountPasswordIsEmpty), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show ((View)sender);
|
// return;
|
// }
|
// if (accountPassword.Text != user_Info.Password) {
|
// new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.AccountPasswordError), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show ((View)sender);
|
// return;
|
// }
|
// dialog.Close ();
|
// this.RemoveFromParent ();
|
// RemoteUnlockPasswordSet unlockView = new RemoteUnlockPasswordSet (doorLock);
|
// UserMiddle.DevicePageView.AddChidren (unlockView);
|
// unlockView.ShowDoorLockRemoteSetPassword ();
|
// UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1;
|
//};
|
dialog.Show ();
|
}
|
|
}
|
}
|