using System;
|
using System.Collections.Generic;
|
using System.Net;
|
using System.IO;
|
using System.Text;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class FingerprintAndProximityScene : Dialog
|
{
|
public Action Action;
|
DoorLock doorLock;
|
Button btn;
|
bool showMessageFormulaBar;
|
string NotificationContent;//发送到服务器的通知的具体内容
|
|
public FingerprintAndProximityScene (DoorLock doorLock)
|
{
|
BackgroundColor = SkinStyle.Current.MainColor;
|
this.doorLock = doorLock;
|
DoorLockSceneShow ();
|
}
|
|
public string SceneType;//场景类型
|
public int SceneID;//场景类型
|
public string SceneName = Language.StringByID (R.MyInternationalizationString.NotConfigured);//场景名称
|
Button btnEditedName;
|
|
void DoorLockSceneShow ()
|
{
|
#region 标题
|
var topView = new FrameLayout () {
|
Height = Application.GetRealHeight (130),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
|
AddChidren (topView);
|
|
var title = new Button () {
|
TextAlignment = TextAlignment.Center,
|
Text = doorLock.doorLockSceneRemark,
|
TextSize = 19,
|
TextColor = SkinStyle.Current.TextColor1,
|
Y = Application.GetRealHeight (10),
|
};
|
topView.AddChidren (title);
|
|
var back = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
SelectedImagePath = "Item/BackSelected.png",
|
Y = Application.GetRealHeight (30),
|
};
|
topView.AddChidren (back);
|
back.MouseUpEventHandler += (sender, e) => {
|
Close ();
|
Action ();
|
};
|
#endregion
|
|
#region ShowPushView
|
FrameLayout ShowPushView = new FrameLayout () {
|
Height = Application.GetRealHeight (90),
|
Y = topView.Bottom,
|
BackgroundColor = SkinStyle.Current.TitileView,
|
};
|
AddChidren (ShowPushView);
|
|
var btnShowPush = new Button () {
|
X = Application.GetRealWidth (20),
|
Height = Application.GetRealHeight (88),
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = Language.StringByID (R.MyInternationalizationString.SetPush),
|
TextColor = SkinStyle.Current.TextColor1,
|
SelectedTextColor = SkinStyle.Current.TextColor1
|
};
|
ShowPushView.AddChidren (btnShowPush);
|
|
var Switch = new Button () {
|
X = Application.GetRealWidth (525),
|
Gravity = Gravity.CenterVertical,
|
Width = Application.GetMinRealAverage (90),
|
Height = Application.GetMinRealAverage (53),
|
UnSelectedImagePath = "Item/SwitchClose.png",
|
SelectedImagePath = "Item/SwitchOpen.png",
|
IsSelected = false,
|
};
|
ShowPushView.AddChidren (Switch);
|
|
btn = new Button () {
|
Height = Application.GetRealHeight (2),
|
BackgroundColor = SkinStyle.Current.LineColor2,
|
Y = Application.GetRealHeight (88),
|
};
|
ShowPushView.AddChidren (btn);
|
|
var editMessageView = new FrameLayout () {
|
Y = ShowPushView.Bottom,
|
Height = Application.GetRealHeight (0),
|
BackgroundColor = SkinStyle.Current.LineColor2,
|
};
|
AddChidren (editMessageView);
|
|
var editbox = new EditText () {
|
Height = Application.GetRealHeight (180),
|
Width = Application.GetRealWidth (520),
|
PlaceholderText = Language.StringByID (R.MyInternationalizationString.EditPushContent),
|
TextAlignment = TextAlignment.Center,
|
Radius = (uint)Application.GetRealHeight (10),
|
TextColor = SkinStyle.Current.TextColor1,
|
BackgroundColor = SkinStyle.Current.LineColor2,
|
TextSize = 15,
|
PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor,
|
};
|
editMessageView.AddChidren (editbox);
|
|
var btnSend = new Button () {
|
Height = Application.GetRealHeight (180),
|
X = editbox.Right,
|
Width = Application.GetRealWidth (116),
|
TextID = R.MyInternationalizationString.OK,
|
BackgroundColor = SkinStyle.Current.ButtonColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
Radius = 10,
|
};
|
editMessageView.AddChidren (btnSend);
|
|
#endregion
|
|
#region btnEditScence
|
Button btnEditScence = new Button () {
|
Height = Application.GetRealHeight (90),
|
TextAlignment = TextAlignment.Center,
|
Y = Application.GetRealHeight (130 + 90) + editMessageView.Height,
|
BackgroundColor = SkinStyle.Current.TitileView,
|
TextID = R.MyInternationalizationString.SceneTriggering,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
AddChidren (btnEditScence);
|
|
var editedScrolViewLayout = new VerticalScrolViewLayout () {
|
Height = Application.GetRealHeight (90),
|
Y = Application.GetRealHeight (130 + 180) + editMessageView.Height,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
AddChidren (editedScrolViewLayout);
|
|
|
string saveSceneFilePath = null;
|
doorLock.DictionaryList.TryGetValue ("001_" + doorLock.doorLockSceneTargetsMethod.ToString ("000") + "_" + doorLock.doorLockSceneTargetsUserID.ToString ("000"), out saveSceneFilePath);
|
if (saveSceneFilePath == null) {
|
var frameLayout1 = new RowLayout () {
|
Height = Application.GetRealHeight (90),
|
};
|
editedScrolViewLayout.AddChidren (frameLayout1);
|
|
btnEditedName = new Button () {
|
Height = LayoutParams.MatchParent,
|
TextAlignment = TextAlignment.Center,
|
Text = SceneName,
|
};
|
frameLayout1.AddChidren (btnEditedName);
|
|
Button btnDel = new Button () {
|
TextID = R.MyInternationalizationString.Del,
|
BackgroundColor = SkinStyle.Current.DelColor,
|
};
|
frameLayout1.AddRightView (btnDel);
|
btnDel.MouseUpEventHandler += (sender, e) => {
|
var key = "001_" + doorLock.doorLockSceneTargetsMethod.ToString ("000") + "_" + doorLock.doorLockSceneTargetsUserID.ToString ("000");
|
doorLock.DictionaryList.Remove (key);
|
doorLock.HaveSceneTargets.Remove (key);
|
IO.FileUtils.SaveEquipmentMessage (doorLock, doorLock.PhysicsLoopID.ToString ());
|
Close ();
|
new FingerprintAndProximityScene (doorLock) { Action = Action }.Show ();
|
};
|
}
|
else {
|
var frameLayout = new RowLayout () {
|
Height = Application.GetRealHeight (90),
|
BackgroundColor = 0x7f7f7f,
|
};
|
editedScrolViewLayout.AddChidren (frameLayout);
|
|
var scene = Scene.GetSceneByFilePath (saveSceneFilePath);
|
btnEditedName = new Button () {
|
Height = LayoutParams.MatchParent,
|
TextAlignment = TextAlignment.Center,
|
Text = scene == null ? SceneName : scene.Name,
|
};
|
frameLayout.AddChidren (btnEditedName);
|
|
Button btnDel = new Button () {
|
TextID = R.MyInternationalizationString.Del,
|
BackgroundColor = SkinStyle.Current.DelColor,
|
};
|
frameLayout.AddRightView (btnDel);
|
btnDel.MouseUpEventHandler += (sender, e) => {
|
string key = "001_" + doorLock.doorLockSceneTargetsMethod.ToString ("000") + "_" + doorLock.doorLockSceneTargetsUserID.ToString ("000");
|
doorLock.DictionaryList.Remove (key);
|
doorLock.HaveSceneTargets.Remove (key);
|
IO.FileUtils.SaveEquipmentMessage (doorLock, doorLock.PhysicsLoopID.ToString ());
|
Close ();
|
new FingerprintAndProximityScene (doorLock) { Action = Action }.Show ();
|
};
|
}
|
#endregion
|
|
#region ShowUnEditView
|
var ShowUnEditView = new FrameLayout () {
|
Height = Application.GetRealHeight (90),
|
BackgroundColor = SkinStyle.Current.TitileView,
|
Y = Application.GetRealHeight (130 + 270) + editMessageView.Height,
|
};
|
AddChidren (ShowUnEditView);
|
|
Button btnUnEditedScene = new Button () {
|
X = Application.GetRealWidth (20),
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = Language.StringByID (R.MyInternationalizationString.AlternativeScenes),
|
TextColor = SkinStyle.Current.TextColor1,
|
SelectedTextColor = SkinStyle.Current.TextColor1
|
};
|
ShowUnEditView.AddChidren (btnUnEditedScene);
|
|
var btnDown = new Button () {
|
X = Application.GetRealWidth (560),
|
Gravity = Gravity.CenterVertical,
|
Width = Application.GetMinRealAverage (50),
|
Height = Application.GetMinRealAverage (55),
|
UnSelectedImagePath = "Item/Down.png",
|
SelectedImagePath = "Item/DownSelected.png",
|
IsSelected = true,
|
};
|
ShowUnEditView.AddChidren (btnDown);
|
|
var middleVerticalScrolViewLayout = new VerticalScrolViewLayout () {
|
Height = Application.GetRealHeight (Application.DesignHeight - 130 - 360) - editMessageView.Height,
|
Y = Application.GetRealHeight (130 + 360) + editMessageView.Height,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
AddChidren (middleVerticalScrolViewLayout);
|
#endregion
|
|
#region sceneList
|
//全部类型的场景列表
|
var allSceneFilePaths = new List<string> ();
|
//全局场景中所有的场景
|
var sceneFileList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (Scene.GlobalSceneFilePath)));
|
allSceneFilePaths.AddRange (sceneFileList);
|
//房间的所有场景
|
foreach (var room in Room.Lists) {
|
if (string.IsNullOrEmpty(room.Name)) {
|
continue;
|
}
|
allSceneFilePaths.AddRange (room.SceneFilePathList);
|
}
|
|
int i = 0;
|
foreach (var sceneFilePath in allSceneFilePaths) {
|
var scene = Scene.GetSceneByFilePath (sceneFilePath);
|
if (scene == null) {
|
continue;
|
}
|
|
var frameLayout = new RowLayout () {
|
Height = Application.GetRealHeight (115),
|
BackgroundImagePath = "DoorLockPic/door_lock_ scene.png"
|
};
|
middleVerticalScrolViewLayout.AddChidren (frameLayout);
|
if (saveSceneFilePath == sceneFilePath) {
|
frameLayout.BackgroundImagePath = "DoorLockPic/door_lock_ scene_on.png";
|
}
|
|
var btnRemarkName = new Button () {
|
Width = Application.GetRealWidth (420),
|
Height = LayoutParams.MatchParent,
|
Text = scene.Name,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (80),
|
};
|
frameLayout.AddChidren (btnRemarkName);
|
|
int currentIndex = i;
|
|
EventHandler<MouseEventArgs> hander = (sender, e) => {
|
Action action = () => {
|
var tempScene = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (sceneFilePath)));
|
|
if (tempScene.DeviceFilePathList.Count == 0) {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.EmptyTargetsLeadToControlFailure), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show ((View)sender);
|
return;
|
}
|
|
for (int j = 0; j < middleVerticalScrolViewLayout.ChildrenCount; j++) {
|
var rowView = middleVerticalScrolViewLayout.GetChildren (j);
|
if (rowView.GetType () == typeof (RowLayout)) {
|
if (currentIndex == j) {
|
((RowLayout)rowView).BackgroundImagePath = "DoorLockPic/door_lock_ scene_on.png";
|
} else {
|
((RowLayout)rowView).BackgroundImagePath = "DoorLockPic/door_lock_ scene.png";
|
}
|
}
|
}
|
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.TargetsConfiguring) + "...");
|
});
|
System.Threading.Tasks.Task.Run (() => {
|
bool result = false;
|
try {
|
int controlDeviceIndex = 1;
|
foreach (var deviceFilePath in tempScene.DeviceFilePathList) {
|
if (controlDeviceIndex > 19) {
|
controlDeviceIndex = 19;
|
break;
|
}
|
|
var sendBytes = new byte [12];
|
sendBytes [0] = doorLock.PhysicsLoopID;//开锁
|
sendBytes [1] = 1;//开锁
|
sendBytes [2] = (byte)doorLock.doorLockSceneTargetsMethod;//开锁类型 密码开锁
|
sendBytes [3] = (byte)doorLock.doorLockSceneTargetsUserID;//用户ID
|
sendBytes [4] = (byte)controlDeviceIndex;
|
|
var common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (deviceFilePath.Split ('_') [1] == DeviceType.LightDimming.ToString ()) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDimming> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device == null) {
|
continue;
|
}
|
sendBytes [5] = 0x59;
|
sendBytes [6] = device.SubnetID;
|
sendBytes [7] = device.DeviceID;
|
sendBytes [8] = device.LoopID;
|
sendBytes [9] = device.CurrentBrightness;
|
sendBytes [10] = device.DelayTimeHeight;
|
sendBytes [11] = device.DelayTimeLow;
|
if (sceneControl (doorLock, sendBytes, btnEditedName, btnRemarkName, sender, sceneFilePath)) {
|
result = true;
|
}
|
} else if (deviceFilePath.Split ('_') [1] == DeviceType.LightSwitch.ToString ()) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device == null) {
|
continue;
|
}
|
sendBytes [5] = 0x59;
|
sendBytes [6] = device.SubnetID;
|
sendBytes [7] = device.DeviceID;
|
sendBytes [8] = device.LoopID;
|
sendBytes [9] = device.CurrentBrightness;
|
sendBytes [10] = device.DelayTimeHeight;
|
sendBytes [11] = device.DelayTimeLow;
|
if (sceneControl (doorLock, sendBytes, btnEditedName, btnRemarkName, sender, sceneFilePath)) {
|
result = true;
|
}
|
} else if (deviceFilePath.Split ('_') [1] == DeviceType.CurtainModel.ToString ()) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainModel> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device == null) {
|
continue;
|
}
|
sendBytes [5] = 0x5C;
|
sendBytes [6] = device.SubnetID;
|
sendBytes [7] = device.DeviceID;
|
sendBytes [8] = device.LoopID;
|
sendBytes [9] = (byte)device.Status;
|
if (sceneControl (doorLock, sendBytes, btnEditedName, btnRemarkName, sender, sceneFilePath)) {
|
result = true;
|
}
|
} else if (deviceFilePath.Split ('_') [1] == DeviceType.CurtainRoller.ToString ()) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainRoller> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device == null) {
|
continue;
|
}
|
sendBytes [5] = 0x5C;
|
sendBytes [6] = device.SubnetID;
|
sendBytes [7] = device.DeviceID;
|
sendBytes [8] = device.LoopID;
|
sendBytes [9] = (byte)device.Status;
|
if (sceneControl (doorLock, sendBytes, btnEditedName, btnRemarkName, sender, sceneFilePath)) {
|
result = true;
|
}
|
} else if (deviceFilePath.Split ('_') [1] == DeviceType.CurtainTrietex.ToString ()) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainTrietex> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device == null) {
|
continue;
|
}
|
sendBytes [5] = 0x5C;
|
sendBytes [6] = device.SubnetID;
|
sendBytes [7] = device.DeviceID;
|
sendBytes [8] = 1;
|
sendBytes [9] = (byte)device.Status;
|
if (sceneControl (doorLock, sendBytes, btnEditedName, btnRemarkName, sender, sceneFilePath)) {
|
result = true;
|
}
|
} else if (deviceFilePath.Split ('_') [1] == DeviceType.FanModule.ToString ()) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device == null) {
|
continue;
|
}
|
sendBytes [5] = 0x59;
|
sendBytes [6] = device.SubnetID;
|
sendBytes [7] = device.DeviceID;
|
sendBytes [8] = device.LoopID;
|
sendBytes [9] = 1;
|
sendBytes [10] = (byte)device.WindSpeed;
|
if (sceneControl (doorLock, sendBytes, btnEditedName, btnRemarkName, sender, sceneFilePath)) {
|
result = true;
|
}
|
} else if (deviceFilePath.Split ('_') [1] == DeviceType.LogicModule.ToString ()) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LogicModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device == null) {
|
continue;
|
}
|
sendBytes [5] = 0x55;
|
sendBytes [6] = device.SubnetID;
|
sendBytes [7] = device.DeviceID;
|
sendBytes [8] = device.AreaID;
|
sendBytes [9] = device.AreaSceneID;
|
if (sceneControl (doorLock, sendBytes, btnEditedName, btnRemarkName, sender, sceneFilePath)) {
|
result = true;
|
}
|
}
|
else if (deviceFilePath.Split ('_') [1] == DeviceType.UniversalDevice.ToString ()) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<UniversalDevice> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device == null) {
|
continue;
|
}
|
if (device.UniversalType == 0xE01C) {
|
sendBytes [5] = 0x58;
|
sendBytes [6] = device.SubnetID;
|
sendBytes [7] = device.DeviceID;
|
sendBytes [8] = 0 < device.SendBytes.Count ? device.SendBytes [0] : (byte)0;
|
sendBytes [9] = 1 < device.SendBytes.Count ? device.SendBytes [1] : (byte)0;
|
if (sceneControl (doorLock, sendBytes, btnEditedName, btnRemarkName, sender, sceneFilePath)) {
|
result = true;
|
}
|
}
|
else {
|
continue;
|
}
|
}else {
|
continue;
|
}
|
controlDeviceIndex++;
|
}
|
|
//读回来是设备目标,但是当前设置没有那个设备,则设为无效
|
for (int k = controlDeviceIndex; k < 20; k++) {
|
var sceneTargetInfoBytes = Control.ControlBytesSendHasReturn (Command.ReadDoorLockSceneObj, doorLock.SubnetID, doorLock.DeviceID, new byte [] { doorLock.PhysicsLoopID, 1, (byte)doorLock.doorLockSceneTargetsMethod, (byte)doorLock.doorLockSceneTargetsUserID, (byte)k });
|
if (sceneTargetInfoBytes == null) {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show ((View)sender);
|
break;
|
} else {
|
if (sceneTargetInfoBytes [5] == 0 || sceneTargetInfoBytes [5] == 0xFF) {
|
break;
|
} else {
|
var sendBytes = new byte [12];
|
sendBytes [0] = doorLock.PhysicsLoopID;
|
sendBytes [1] = 1;//开锁
|
sendBytes [2] = (byte)doorLock.doorLockSceneTargetsMethod;//开锁类型 密码开锁
|
sendBytes [3] = (byte)doorLock.doorLockSceneTargetsUserID;//用户ID
|
sendBytes [4] = (byte)k;
|
sendBytes [5] = 0;
|
sendBytes [6] = 0;
|
sendBytes [7] = 0;
|
sendBytes [8] = 0;
|
sendBytes [9] = 0;
|
sendBytes [10] = 0;
|
sendBytes [11] = 0;
|
var r = Control.ControlBytesSendHasReturn (Command.SetDoorLockSceneObj, doorLock.SubnetID, doorLock.DeviceID, sendBytes);
|
if(r==null){
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show ((View)sender);
|
}
|
}
|
}
|
}
|
|
} catch { } finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
if (result == true) {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.TargetsControlSuccessfully), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show ((View)sender);
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.TargetsSetFail), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show ((View)sender);
|
});
|
}
|
}
|
});
|
};
|
|
string lastSceneFilePath = null;
|
doorLock.DictionaryList.TryGetValue ("001_" + doorLock.doorLockSceneTargetsMethod.ToString ("000") + "_" + doorLock.doorLockSceneTargetsUserID.ToString ("000"), out lastSceneFilePath);
|
var sceneEdit = Scene.GetSceneByFilePath (lastSceneFilePath);
|
if (sceneEdit != null) {
|
if (lastSceneFilePath != null) {
|
if (lastSceneFilePath == sceneFilePath) {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.ThisSceneHasBeenChoosen), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show ((View)sender);
|
return;
|
});
|
} else {
|
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.SureToReplaceExistedScene),
|
Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.Show ();
|
alert.ResultEventHandler += (sender2, e2) => {
|
if (e2) {
|
action ();
|
}
|
};
|
}
|
} else {
|
action ();
|
}
|
} else {
|
action ();
|
}
|
};
|
frameLayout.MouseUpEventHandler += hander;
|
btnRemarkName.MouseUpEventHandler += hander;
|
i++;
|
}
|
#endregion
|
|
Action actionOpen = () => {
|
editMessageView.Height = Application.GetRealHeight (180);
|
editbox.Height = Application.GetRealHeight (180);
|
btnEditScence.Y = Application.GetRealHeight (130 + 90) + editMessageView.Height;
|
editedScrolViewLayout.Y = Application.GetRealHeight (130 + 180) + editMessageView.Height;
|
ShowUnEditView.Y = Application.GetRealHeight (130 + 270) + editMessageView.Height;
|
middleVerticalScrolViewLayout.Y = Application.GetRealHeight (130 + 360) + editMessageView.Height;
|
if (UserConfig.Instance.ShowAlternativeScene == true) {
|
middleVerticalScrolViewLayout.Height = Application.GetRealHeight (Application.DesignHeight - 130 - 360 - 180);
|
} else {
|
middleVerticalScrolViewLayout.Height = Application.GetRealHeight (0);
|
}
|
};
|
|
Action actionClose = () => {
|
editMessageView.Height = Application.GetRealHeight (0);
|
editbox.Height = Application.GetRealHeight (0);
|
btnEditScence.Y = Application.GetRealHeight (130 + 90);
|
editedScrolViewLayout.Y = Application.GetRealHeight (130 + 180);
|
ShowUnEditView.Y = Application.GetRealHeight (130 + 270);
|
middleVerticalScrolViewLayout.Y = Application.GetRealHeight (130 + 360);
|
if (UserConfig.Instance.ShowAlternativeScene == true) {
|
middleVerticalScrolViewLayout.Height = Application.GetRealHeight (Application.DesignHeight - 130 - 360);
|
} else {
|
middleVerticalScrolViewLayout.Height = Application.GetRealHeight (0);
|
}
|
};
|
|
//读门锁信息
|
readStatus ((obj) => {
|
Application.RunOnMainThread (() => {
|
if (obj) {
|
Switch.IsSelected = true;
|
showMessageFormulaBar = Switch.IsSelected;
|
editMessageView.Height = Application.GetRealHeight (180);
|
editbox.Height = Application.GetRealHeight (180);
|
btnEditScence.Y = Application.GetRealHeight (130 + 90) + editMessageView.Height;
|
editedScrolViewLayout.Y = Application.GetRealHeight (130 + 180) + editMessageView.Height;
|
ShowUnEditView.Y = Application.GetRealHeight (130 + 270) + editMessageView.Height;
|
middleVerticalScrolViewLayout.Y = Application.GetRealHeight (130 + 360) + editMessageView.Height;
|
if (UserConfig.Instance.ShowAlternativeScene) {
|
btnDown.IsSelected = true;
|
middleVerticalScrolViewLayout.Height = Application.GetRealHeight (Application.DesignHeight - 130 - 360 - 180);
|
} else {
|
btnDown.IsSelected = false;
|
middleVerticalScrolViewLayout.Height = Application.GetRealHeight (0);
|
}
|
} else {
|
Switch.IsSelected = false;
|
showMessageFormulaBar = Switch.IsSelected;
|
editMessageView.Height = Application.GetRealHeight (0);
|
editbox.Height = Application.GetRealHeight (0);
|
btnEditScence.Y = Application.GetRealHeight (130 + 90);
|
editedScrolViewLayout.Y = Application.GetRealHeight (130 + 180);
|
ShowUnEditView.Y = Application.GetRealHeight (130 + 270);
|
middleVerticalScrolViewLayout.Y = Application.GetRealHeight (130 + 360);
|
if (UserConfig.Instance.ShowAlternativeScene) {
|
btnDown.IsSelected = true;
|
middleVerticalScrolViewLayout.Height = Application.GetRealHeight (Application.DesignHeight - 130 - 360);
|
} else {
|
btnDown.IsSelected = false;
|
middleVerticalScrolViewLayout.Height = Application.GetRealHeight (0);
|
}
|
}
|
});
|
});
|
|
Action pushContentAction = () => {
|
//读服务器消息
|
GetOnePushMsg (editbox);
|
|
};
|
|
//首次进来看一下消息的状态
|
pushContentAction ();
|
|
btnSend.MouseUpEventHandler += (sender, e) => {
|
if (string.IsNullOrEmpty (editbox.Text.Trim ())) {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.EditPushContent), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show ((View)sender);
|
return;
|
}
|
|
var alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.SureToSendNotification),
|
Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.Show ();
|
alert.ResultEventHandler += (sender1, e1) => {
|
if (e1) {
|
NoticePushServer (editbox.Text,pushContentAction);
|
}
|
};
|
};
|
|
Switch.MouseUpEventHandler += (sender, e) => {
|
Switch.IsSelected = !Switch.IsSelected;
|
showMessageFormulaBar = Switch.IsSelected;
|
NoticePushDoorLock (doorLock, Switch);
|
if (Switch.IsSelected) {
|
actionOpen ();
|
} else {
|
actionClose ();
|
}
|
};
|
|
btnDown.MouseUpEventHandler += (sender, e) => {
|
btnDown.IsSelected = !btnDown.IsSelected;
|
UserConfig.Instance.ShowAlternativeScene = btnDown.IsSelected;
|
UserConfig.Instance.SaveUserConfig ();
|
if (btnDown.IsSelected == true) {
|
if (showMessageFormulaBar == true) {
|
actionOpen ();
|
} else {
|
actionClose ();
|
}
|
} else {
|
middleVerticalScrolViewLayout.Height = Application.GetRealHeight (0);
|
}
|
};
|
}
|
|
/// <summary>
|
/// 服务器请求
|
/// </summary>
|
/// <returns>The web.</returns>
|
/// <param name="url">URL.</param>
|
/// <param name="data">Data.</param>
|
string requestWeb (string data,string url)
|
{
|
var webClient = new WebClient { };
|
webClient.Headers.Remove ("ContentType");
|
webClient.Headers.Add ("ContentType", "application/json");
|
var bytes = webClient.UploadData (url, "POST", Encoding.UTF8.GetBytes (data));
|
if (bytes == null) {
|
return null;
|
} else {
|
return Encoding.UTF8.GetString (bytes);
|
}
|
}
|
|
public static string messageJson (PushMessageEntity pushMessage)
|
{
|
if (pushMessage == null) {
|
return null;
|
}
|
return Newtonsoft.Json.JsonConvert.SerializeObject (pushMessage);
|
}
|
|
/// <summary>
|
/// 消息推送到服务器
|
/// </summary>
|
/// <param name="message">Message.</param>
|
public async void NoticePushServer (string message,Action pushContentAction)
|
{
|
string result = null;
|
await System.Threading.Tasks.Task.Run (() => {
|
//获取一端口交换机的mac
|
var gateWayString = CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (UserConfig.Instance.RemoteModeFile));
|
if (gateWayString == null || UserConfig.Instance.RemoteModeFile.Split ('_').Length < 2) {
|
result = Language.StringByID (R.MyInternationalizationString.NoGateway);
|
return;
|
}
|
var common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (gateWayString);
|
if (common == null) {
|
result = Language.StringByID (R.MyInternationalizationString.NoGateway);
|
return;
|
}
|
string mac = null;
|
if (common.Type == DeviceType.OnePortWirelessFR) {
|
var gateWay = Newtonsoft.Json.JsonConvert.DeserializeObject<OnePortWirelessFR> (gateWayString);
|
mac = gateWay.MAC.Replace (".", "");
|
} else if (common.Type == DeviceType.OnePortBus) {
|
var gateWay = Newtonsoft.Json.JsonConvert.DeserializeObject<OnePortBus> (gateWayString);
|
mac = gateWay.MAC.Replace (".", "");
|
} else {
|
result = Language.StringByID (R.MyInternationalizationString.NoGateway);
|
return;
|
}
|
|
var pushMessage = new PushMessageEntity ();
|
pushMessage.Mac = mac;
|
pushMessage.SubnetID = doorLock.SubnetID;
|
pushMessage.DeviceID = doorLock.DeviceID;
|
|
if (doorLock.doorLockSceneTargetsMethod == 0x01) {
|
pushMessage.SwitchNum = doorLock.doorLockSceneTargetsUserID + 10;//密码10以下,指纹ID+10,感应卡id+100
|
} else if (doorLock.doorLockSceneTargetsMethod == 0x03) {
|
pushMessage.SwitchNum = doorLock.doorLockSceneTargetsUserID + 110;//密码10以下,指纹ID+10,感应卡id+100
|
}
|
pushMessage.MessageMode = 0;
|
pushMessage.AlarmEmail = new byte [] { 2 };
|
pushMessage.DetailMessage = message;
|
|
var mess = messageJson (pushMessage);
|
try {
|
var recevieResult = requestWeb (mess,"https://developer.hdlcontrol.com/api/AddPushMessage");
|
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<PushMessageResult> (recevieResult);
|
if (obj.StateCode == "SUCCESS") {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.SendNotificationsSuccessfully), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show (btn);
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.SendNotificationsUnsuccessfully), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show (btn);
|
});
|
}
|
} catch (Exception ex) {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.SendNotificationsUnsuccessfully), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show (btn);
|
});
|
}
|
});
|
|
pushContentAction ();
|
|
if (result != null) {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = result, Direction = AMPopTipDirection.Down, CloseTime = 1 }.Show (btn);
|
});
|
}
|
}
|
|
/// <summary>
|
///从服务器上读数据
|
/// </summary>
|
public async void GetOnePushMsg (EditText editbox)
|
{
|
string result = null;
|
await System.Threading.Tasks.Task.Run (() => {
|
//获取一端口交换机的mac
|
var gateWayString = CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (UserConfig.Instance.RemoteModeFile));
|
if (gateWayString == null || UserConfig.Instance.RemoteModeFile.Split ('_').Length < 2) {
|
result = Language.StringByID (R.MyInternationalizationString.NoGateway);
|
return;
|
}
|
var common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (gateWayString);
|
if (common == null) {
|
result = Language.StringByID (R.MyInternationalizationString.NoGateway);
|
return;
|
}
|
string mac = null;
|
if (common.Type == DeviceType.OnePortWirelessFR) {
|
var gateWay = Newtonsoft.Json.JsonConvert.DeserializeObject<OnePortWirelessFR> (gateWayString);
|
mac = gateWay.MAC.Replace (".", "");
|
} else if (common.Type == DeviceType.OnePortBus) {
|
var gateWay = Newtonsoft.Json.JsonConvert.DeserializeObject<OnePortBus> (gateWayString);
|
mac = gateWay.MAC.Replace (".", "");
|
} else {
|
result = Language.StringByID (R.MyInternationalizationString.NoGateway);
|
return;
|
}
|
|
var message = new PushMessageEntity ();
|
message.Mac = mac;
|
message.SubnetID = doorLock.SubnetID;
|
message.DeviceID = doorLock.DeviceID;
|
if (doorLock.doorLockSceneTargetsMethod == 0x01) {
|
message.SwitchNum = doorLock.doorLockSceneTargetsUserID + 10;//密码10以下,指纹ID+10,感应卡id+100
|
} else if (doorLock.doorLockSceneTargetsMethod == 0x03) {
|
message.SwitchNum = doorLock.doorLockSceneTargetsUserID + 110;//密码10以下,指纹ID+10,感应卡id+100
|
}
|
|
var mess = Newtonsoft.Json.JsonConvert.SerializeObject (message);
|
try {
|
var recevieResult = requestWeb (mess, "https://developer.hdlcontrol.com/api/GetOnePushMsg");
|
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<PushMessageResult> (recevieResult);
|
if (obj.StateCode == "SUCCESS") {
|
var msgEntity = Newtonsoft.Json.JsonConvert.DeserializeObject<List<MessageInfoRes>> (obj.ResponseData.ToString ());
|
|
foreach (var msg in msgEntity) {
|
Application.RunOnMainThread (() => { editbox.Text = msg.DetailMessage; });
|
}
|
} else {
|
Application.RunOnMainThread (() => {
|
if (Language.CurrentLanguage == "Chinese") {
|
editbox.Text = obj.ErrorInfo_Zh;
|
} else {
|
editbox.Text = obj.ErrorInfo_Zh;
|
}
|
});
|
}
|
} catch (Exception ex) {
|
Application.RunOnMainThread (() => {
|
editbox.PlaceholderText = Language.StringByID (R.MyInternationalizationString.EditPushContent);
|
});
|
}
|
|
});
|
|
|
if (result != null) {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = result, Direction = AMPopTipDirection.Down, CloseTime = 1 }.Show (btn);
|
});
|
}
|
}
|
|
public void readStatus (Action<bool> action)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
var sceneTargetInfoBytes = Control.ControlBytesSendHasReturn (Command.ReadDoorLockSceneObj, doorLock.SubnetID, doorLock.DeviceID, new byte [] { doorLock.PhysicsLoopID, 1, (byte)doorLock.doorLockSceneTargetsMethod, (byte)doorLock.doorLockSceneTargetsUserID, 0 });
|
if (sceneTargetInfoBytes == null) {
|
action (false);
|
} else {
|
var sceneTargetsInfo = new DoorLockSceneTargets ();
|
sceneTargetsInfo.TargetSerialNum = sceneTargetInfoBytes [4];
|
sceneTargetsInfo.ControlType = sceneTargetInfoBytes [5];//通用开关0x58,无效0
|
sceneTargetsInfo.TargetSunbetID = sceneTargetInfoBytes [6];
|
sceneTargetsInfo.TargetDeviceID = sceneTargetInfoBytes [7];
|
sceneTargetsInfo.TargetLoopID = sceneTargetInfoBytes [8];
|
sceneTargetsInfo.Parameter1 = sceneTargetInfoBytes [9];
|
sceneTargetsInfo.Parameter2 = sceneTargetInfoBytes [10];
|
sceneTargetsInfo.Parameter3 = sceneTargetInfoBytes [11];
|
|
var command = sceneTargetInfoBytes [5];
|
if (sceneTargetsInfo.TargetSunbetID == doorLock.SubnetID &&
|
sceneTargetsInfo.TargetDeviceID == 0 &&
|
command == 0x58) {
|
action (true);
|
} else {
|
action (false);
|
}
|
}
|
});
|
}
|
|
//消息发送到门锁
|
void NoticePushDoorLock (DoorLock door_lock, Button Switch)
|
{
|
var sendBytes = new byte [12];
|
sendBytes [0] = doorLock.PhysicsLoopID;
|
sendBytes [1] = 1;//开锁
|
sendBytes [2] = (byte)doorLock.doorLockSceneTargetsMethod;
|
sendBytes [3] = (byte)doorLock.doorLockSceneTargetsUserID;//用户ID
|
|
sendBytes [4] = 0;//目标序号
|
if (Switch.IsSelected == true) {
|
sendBytes [5] = 0x58;//开关开发通用开关,关发无效
|
} else {
|
sendBytes [5] = 0;
|
}
|
sendBytes [6] = doorLock.SubnetID;
|
sendBytes [7] = 0;
|
if (doorLock.doorLockSceneTargetsMethod == 0x01) {
|
sendBytes [8] = (byte)(doorLock.doorLockSceneTargetsUserID + 10);//密码10以下,指纹ID+10,感应卡id+100
|
} else if (doorLock.doorLockSceneTargetsMethod == 0x03) {
|
sendBytes [8] = (byte)(doorLock.doorLockSceneTargetsUserID + 110);//密码10以下,指纹ID+10,感应卡id+100
|
}
|
sendBytes [9] = 0;
|
sendBytes [10] = 0;
|
sendBytes [11] = 0;
|
|
var result = Control.ControlBytesSendHasReturn (Command.SetDoorLockSceneObj, door_lock.SubnetID, door_lock.DeviceID, sendBytes);
|
if (result == null) {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show (Switch);
|
});
|
return;
|
} else {
|
var result1 = result [0];
|
if (result1 == 0xF8) {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.SetSuccessfully), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show (Switch);
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.ControlFailure), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show (Switch);
|
});
|
}
|
}
|
}
|
|
//场景控制
|
bool sceneControl (DoorLock door_lock, byte [] sendBytes, Button btnEditedName, Button btnRemarkName, object sender, string sceneFilePath)
|
{
|
var result = Control.ControlBytesSendHasReturn (Command.SetDoorLockSceneObj, door_lock.SubnetID, door_lock.DeviceID, sendBytes);
|
if (result == null) {
|
return false;
|
} else {
|
if (result [0] == 0xF8) {
|
Application.RunOnMainThread (() => {
|
btnEditedName.Text = btnRemarkName.Text;
|
var key = "001_" + door_lock.doorLockSceneTargetsMethod.ToString ("000") + "_" + door_lock.doorLockSceneTargetsUserID.ToString ("000");
|
door_lock.DictionaryList.Remove (key);
|
door_lock.DictionaryList.Add (key, sceneFilePath);
|
doorLock.HaveSceneTargets.Remove (key);
|
doorLock.HaveSceneTargets.Add (key, true);
|
IO.FileUtils.SaveEquipmentMessage (door_lock, door_lock.PhysicsLoopID.ToString ());
|
});
|
return true;
|
} else {
|
return false;
|
}
|
}
|
}
|
}
|
}
|