using System;
using System.Collections.Generic;
namespace Shared.SimpleControl.Phone
{
public class UserDeviceToDoorLock : FrameLayout
{
VerticalScrolViewLayout bodyScrolView;
VerticalScrolViewLayout equipmentListScrolView;
///
///构造函数
///
public UserDeviceToDoorLock ()
{
BackgroundColor = SkinStyle.Current.MainColor;
}
public override void RemoveFromParent ()
{
base.RemoveFromParent ();
}
///
/// 添加的所有门锁列表
///
public void ShowAllRoomDoorLock (List doorLockList)
{
#region 标题
var topView = new FrameLayout () {
Y = Application.GetRealHeight (36),
Height = Application.GetRealHeight (90),
BackgroundColor = SkinStyle.Current.MainColor,
};
AddChidren (topView);
var title = new Button () {
TextAlignment = TextAlignment.Center,
Text = Language.StringByID (R.MyInternationalizationString.DoorLock),
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",
Gravity = Gravity.CenterVertical,
};
topView.AddChidren (back);
back.MouseUpEventHandler += (sender, e) => {
this.RemoveFromParent ();
};
#endregion
FrameLayout powerView = new FrameLayout () {
Height = Application.GetRealHeight (110),
BackgroundColor = SkinStyle.Current.TitileView,
Y = topView.Bottom
};
AddChidren (powerView);
Button showAllDoorLock = new Button () {
Height = Application.GetRealHeight (108),
TextAlignment = TextAlignment.CenterLeft,
TextColor = SkinStyle.Current.TextColor1,
TextID = R.MyInternationalizationString.DoorLockList,
X = Application.GetRealHeight (20),
};
powerView.AddChidren (showAllDoorLock);
#region bodyScrolView
bodyScrolView = new VerticalScrolViewLayout () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (1136 - 126 - 110),
Y = powerView.Bottom,
BackgroundColor = SkinStyle.Current.ViewColor
};
AddChidren (bodyScrolView);
equipmentListScrolView = new VerticalScrolViewLayout () {
Height = bodyScrolView.Height - Application.GetRealHeight (110),
};
bodyScrolView.AddChidren (equipmentListScrolView);
equipmentListScrolView.RemoveAll ();
foreach (var doorLockFile in doorLockList) {
DoorLock doorLock = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (doorLockFile)));
FrameLayout doorLockView = new FrameLayout () {
Height = Application.GetRealHeight (110),
Tag = doorLock.ToString () + doorLock.DeviceID.ToString () + doorLock.LoopID.ToString ()
};
equipmentListScrolView.AddChidren (doorLockView);
var btnPoint = new Button () {
Width = Application.GetRealWidth (10),
Height = Application.GetRealHeight (10),
X = Application.GetRealWidth (40),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Item/Point.png",
SelectedImagePath = "Item/Point.png",
};
doorLockView.AddChidren (btnPoint);
var tempDeviceName = new Button () {
Width = Application.GetRealWidth (340),
X = btnPoint.Right + Application.GetRealWidth (20),
TextAlignment = TextAlignment.CenterLeft,
TextColor = SkinStyle.Current.TextColor1,
Text = doorLock.Name,
Tag = doorLock,
};
doorLockView.AddChidren (tempDeviceName);
var editor = new Button () {
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (70),
UnSelectedImagePath = "Item/Editor.png",
SelectedImagePath = "Item/EditorSelected.png",
Gravity = Gravity.CenterVertical,
X = tempDeviceName.Right + Application.GetRealHeight (20),
};
doorLockView.AddChidren (editor);
editor.MouseUpEventHandler += (sender, e) => {
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.ChangeInformation
};
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),
Text = tempDeviceName.Text,
Gravity = Gravity.CenterVertical,
TextAlignment = TextAlignment.Center,
Tag = doorLock,
TextColor = SkinStyle.Current.TextColor,
BorderWidth = 1,
Radius = 5,
BorderColor = SkinStyle.Current.BorderColor,
};
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,
TextColor = SkinStyle.Current.DialogTextColor,
};
bottomView.AddChidren (btnSave);
btnSave.MouseUpEventHandler += (sender1, e1) => {
tempDeviceName.Text = textButton.Text.Trim ();
doorLock.Name = textButton.Text.Trim ();
CommonPage.UpdateRemark (doorLock.SubnetID, doorLock.DeviceID, textButton.Text.Trim ());
IO.FileUtils.SaveEquipmentMessage (doorLock);
dialog.Close ();
};
dialog.Show ();
};
//var btnLightIcon = new Button () {
// Width = Application.GetRealWidth (80),
// Height = Application.GetRealHeight (80),
// Gravity = Gravity.CenterVertical,
// UnSelectedImagePath = "DoorLockPic/door_lock_device.png",
// SelectedImagePath = "DoorLockPic/door_lock_device_on.png",
// X = Application.GetRealWidth (5) + editor.Right,
//};
//doorLockView.AddChidren (btnLightIcon);
//DateTime dateTime = DateTime.Now.AddSeconds (-15);
//btnLightIcon.MouseDownEventHandler += (sender, e) => {
// btnLightIcon.IsSelected = true;
// if (doorLock.remoteDoorLockPassword == null) {
// FirstRemoteUnlock unlockView = new FirstRemoteUnlock (doorLock);
// UserMiddle.DevicePageView.AddChidren (unlockView);
// unlockView.ShowDoorLockRoom ();
// UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1;
// } else {
// 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.PasswordUnlock,
// };
// 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 btnOK = new Button () {
// Width = Application.GetRealWidth (280),
// X = btnLineH.Right,
// TextID = R.MyInternationalizationString.OK,
// TextAlignment = TextAlignment.Center,
// Radius = 1,
// };
// bottomView.AddChidren (btnOK);
// btnOK.MouseUpEventHandler += (sender1, e1) => {
// if (DateTime.Now <= dateTime) {
// new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.AfterFifteenSeconds), Direction = AMPopTipDirection.Up, CloseTime = 4 }.Show ((View)sender);
// return;
// }
// if (string.IsNullOrEmpty (textButton.Text.Trim ())) {
// new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.PasswordIsEmpty), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
// return;
// }
// if (doorLock.remoteDoorLockPassword !=textButton.Text) {
// new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.PasswordIsError), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
// return;
// }
// //开锁控制
// System.Threading.Tasks.Task.Run (() => {
// 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) {
// new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.MaybeDeviceOffline), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
// 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 ((View)sender);
// });
// } else {
// Application.RunOnMainThread (() => {
// new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.OperationFailed), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show ((View)sender);
// });
// }
// }
// } else {
// Application.RunOnMainThread (() => {
// new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.MaybeDeviceOffline), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
// });
// return;
// }
// });
// dialog.Close ();
// };
// dialog.Show ();
// }
// };
//btnLightIcon.MouseDownEventHandler += (sender, e) => {
// btnLightIcon.IsSelected = false;
//};
var btnRight = new Button () {
Width = Application.GetRealWidth (28),
Height = Application.GetRealHeight (40),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Item/Right.png",
SelectedImagePath = "Item/RightSelected.png",
X = Application.GetRealWidth (580),
};
doorLockView.AddChidren (btnRight);
EventHandler openDoorLockControlPageEvent = (button, mouseEventArgs) => {
UserDoorLock toDoorLockView = new UserDoorLock ();
UserMiddle.DevicePageView.AddChidren (toDoorLockView);
toDoorLockView.ShowDoorLockRoom (doorLock);
UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1;
};
doorLockView.MouseUpEventHandler += openDoorLockControlPageEvent;
tempDeviceName.MouseUpEventHandler += openDoorLockControlPageEvent;
btnRight.MouseUpEventHandler += openDoorLockControlPageEvent;
Button btnRowNull = new Button () {
Y = Application.GetRealHeight (107),
Height = Application.GetRealHeight (3),
BackgroundColor = SkinStyle.Current.TitileView
};
doorLockView.AddChidren (btnRowNull);
}
#endregion
}
///
/// 读取设备状态
///
public static void readAllStatus ()
{
System.Threading.Tasks.Task.Run (() => {
System.Collections.Generic.List readList = new System.Collections.Generic.List ();
foreach (Room room in Room.Lists) {
var list = room.DeviceList.FindAll ((obj) => {
return obj.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now && (obj.Type == DeviceType.HVAC || obj.Type == DeviceType.ACPanel || obj.Type == DeviceType.ACInfrared);
});
foreach (Common common in list) {
var s = common.Type + "_" + common.SubnetID + "_" + common.DeviceID + "_" + common.LoopID;
//已经读取过当前设备就不再读取
if (readList.Contains (s)) {
continue;
}
readList.Add (s);
Control.ControlBytesSendHasReturn (Command.ReadACMode, common.SubnetID, common.DeviceID, new byte [] { common.LoopID });
}
}
});
}
}
}