using System;
|
using System.Collections.Generic;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class DoorLockAlarmSceneTargets : FrameLayout
|
{
|
DoorLock doorLock;
|
int sceneType;//当前场景类型
|
public string SceneName = Language.StringByID (R.MyInternationalizationString.NotConfigured);//场景名称
|
Button btnEditedName;
|
|
public DoorLockAlarmSceneTargets (DoorLock door_Lock, int currentTypeIndex)
|
{
|
BackgroundColor = SkinStyle.Current.MainColor;
|
this.doorLock = door_Lock;
|
|
if (currentTypeIndex == 0) {
|
sceneType = 0x01;
|
} else if (currentTypeIndex == 1) {
|
sceneType = 0x02;
|
} else if (currentTypeIndex == 2) {
|
sceneType = 0x03;
|
} else if (currentTypeIndex == 3) {
|
sceneType = 0x04;
|
} else if (currentTypeIndex == 4) {
|
sceneType = 0x05;
|
} else if (currentTypeIndex == 5) {
|
sceneType = 0x06;
|
}
|
|
|
}
|
|
public void DoorLockAlarmSceneShow (int currentTypeIndex)
|
{
|
#region 标题
|
var topView = new FrameLayout () {
|
Height = Application.GetRealHeight (130),
|
BackgroundColor = 0xff1e1f20,
|
};
|
AddChidren (topView);
|
|
var title = new Button () {
|
TextAlignment = TextAlignment.Center,
|
TextSize = 19,
|
Y = Application.GetRealHeight (10),
|
};
|
topView.AddChidren (title);
|
if (currentTypeIndex == 0) {
|
title.TextID = R.MyInternationalizationString.HijackAlarm;
|
} else if (currentTypeIndex == 1) {
|
title.TextID = R.MyInternationalizationString.DoorUncloseAlarm;
|
} else if (currentTypeIndex == 2) {
|
title.TextID = R.MyInternationalizationString.LowVoltageAlarm;
|
} else if (currentTypeIndex == 3) {
|
title.TextID = R.MyInternationalizationString.ErrorAlarm;
|
} else if (currentTypeIndex == 4) {
|
title.TextID = R.MyInternationalizationString.KeyUnlockAlarm;
|
} else if (currentTypeIndex == 5) {
|
title.TextID = R.MyInternationalizationString.TamperResistantAlarm;
|
}
|
|
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) => {
|
this.RemoveFromParent ();
|
};
|
#endregion
|
|
Button btnEditScence = new Button () {
|
Height = Application.GetRealHeight (80),
|
TextAlignment = TextAlignment.CenterLeft,
|
Y = topView.Bottom,
|
BackgroundColor = SkinStyle.Current.TitileView,
|
TextID = R.MyInternationalizationString.SceneTriggering
|
};
|
AddChidren (btnEditScence);
|
|
var middleVerticalScrolViewLayoutEdited = new VerticalScrolViewLayout () {
|
Height = Application.GetRealHeight (80),
|
Y = btnEditScence.Bottom,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
AddChidren (middleVerticalScrolViewLayoutEdited);
|
|
string saveSceneFilePath = null;
|
doorLock.DictionaryList.TryGetValue ("002_" + sceneType.ToString ("000"), out saveSceneFilePath);
|
if (saveSceneFilePath == null) {
|
var frameLayout1 = new FrameLayout () {
|
Height = Application.GetRealHeight (80),
|
};
|
middleVerticalScrolViewLayoutEdited.AddChidren (frameLayout1);
|
|
btnEditedName = new Button () {
|
Height = LayoutParams.MatchParent,
|
TextAlignment = TextAlignment.Center,
|
Text = SceneName,
|
};
|
frameLayout1.AddChidren (btnEditedName);
|
} else {
|
var frameLayout = new RowLayout () {
|
Height = Application.GetRealHeight (80),
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
middleVerticalScrolViewLayoutEdited.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);
|
}
|
|
btnEditScence.MouseUpEventHandler += (sender, e) => {
|
// if (btnEditScence.IsSelected) {
|
middleVerticalScrolViewLayoutEdited.Height = Application.GetRealHeight (80);
|
//btnEditScence.IsSelected = false;
|
//} else {
|
// middleVerticalScrolViewLayoutEdited.Height = Application.GetRealHeight (0);
|
// btnEditScence.IsSelected = true;
|
//}
|
};
|
|
Button btnUnEditedScene = new Button () {
|
Height = Application.GetRealHeight (80),
|
TextAlignment = TextAlignment.CenterLeft,
|
BackgroundColor = SkinStyle.Current.TitileView,
|
Text = Language.StringByID (R.MyInternationalizationString.AlternativeScenes),
|
Y = middleVerticalScrolViewLayoutEdited.Bottom,
|
};
|
AddChidren (btnUnEditedScene);
|
|
var middleVerticalScrolViewLayout = new VerticalScrolViewLayout () {
|
Height = Application.GetRealHeight (Application.DesignHeight - 126 - 160) - middleVerticalScrolViewLayoutEdited.Height,
|
Y = btnUnEditedScene.Bottom,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
AddChidren (middleVerticalScrolViewLayout);
|
|
btnUnEditedScene.MouseUpEventHandler += (sender, e) => {
|
// if (btnUnEditedScene.IsSelected) {
|
// btnUnEditedScene.IsSelected = false;
|
middleVerticalScrolViewLayout.Height = Application.GetRealHeight (Application.DesignHeight - 126 - 160) - middleVerticalScrolViewLayoutEdited.Height;
|
//} else {
|
// btnUnEditedScene.IsSelected = true;
|
// middleVerticalScrolViewLayout.Height = Application.GetRealHeight (0);
|
};
|
|
#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 currentSceneIndex = 0;
|
foreach (var sceneFilePath in allSceneFilePaths) {
|
var scene = Scene.GetSceneByFilePath (sceneFilePath);
|
if (scene == null) {
|
continue;
|
}
|
|
var scemeAlarmFrameLayout = new RowLayout () {
|
Height = Application.GetRealHeight (115),
|
BackgroundImagePath = "DoorLockPic/door_lock_ scene.png"
|
};
|
middleVerticalScrolViewLayout.AddChidren (scemeAlarmFrameLayout);
|
if (saveSceneFilePath == sceneFilePath) {
|
scemeAlarmFrameLayout.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),
|
};
|
scemeAlarmFrameLayout.AddChidren (btnRemarkName);
|
|
int currentSceneClickIndex = currentSceneIndex;
|
EventHandler<MouseEventArgs> hander = (sender, e) => {
|
Scene 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 = 4 }.Show ((View)sender);
|
return;
|
}
|
|
int logicModuleNum = 0;
|
foreach (var deviceFilePath in tempScene.DeviceFilePathList) {
|
if (deviceFilePath.Split ('_') [1] == DeviceType.LogicModule.ToString ()) {
|
logicModuleNum++;
|
}
|
}
|
|
if (logicModuleNum == 0) {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.PleaseAddLogicModule), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
|
});
|
return;
|
} else {
|
for (int j = 0; j < middleVerticalScrolViewLayout.ChildrenCount; j++) {
|
var rowView = middleVerticalScrolViewLayout.GetChildren (j);
|
if (rowView.GetType () == typeof (RowLayout)) {
|
if (currentSceneClickIndex == j) {
|
btnEditedName.Text = btnRemarkName.Text;
|
((RowLayout)rowView).BackgroundImagePath = "DoorLockPic/door_lock_ scene_on.png";
|
} else {
|
((RowLayout)rowView).BackgroundImagePath = "DoorLockPic/door_lock_ scene.png";
|
}
|
}
|
}
|
}
|
|
bool showTip = true;
|
System.Threading.Tasks.Task.Run (() => {
|
int controlDeviceIndex = 0;
|
var sendBytes = new byte [12];
|
|
foreach (var deviceFilePath in tempScene.DeviceFilePathList) {
|
if (controlDeviceIndex > 19) {
|
controlDeviceIndex = 19;
|
}
|
|
sendBytes [0] = doorLock.PhysicsLoopID;//开锁
|
sendBytes [1] = 2;//报警
|
sendBytes [2] = (byte)sceneType;
|
sendBytes [3] = 0;//用户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;
|
// sceneControl (doorLock, sendBytes, btnRemarkName, sender, sceneFilePath);
|
|
} else if (deviceFilePath.Split ('_') [1] == DeviceType.LightRGB.ToString ()) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device != null) {
|
}
|
|
} 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;
|
//sceneControl (doorLock, sendBytes, btnRemarkName, sender, sceneFilePath);
|
} 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;
|
// sceneControl (doorLock, sendBytes, btnRemarkName, sender, sceneFilePath);
|
} 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;
|
//sceneControl (doorLock, sendBytes, btnRemarkName, sender, sceneFilePath);
|
} 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;
|
// sceneControl (doorLock, sendBytes, btnRemarkName, sender, sceneFilePath);
|
} else if (deviceFilePath.Split ('_') [1] == DeviceType.HVAC.ToString ()
|
|| deviceFilePath.Split ('_') [1] == DeviceType.ACInfrared.ToString ()) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<HVAC> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device == null) {
|
continue;
|
}
|
|
} else if (deviceFilePath.Split ('_') [1] == DeviceType.FoolHeat.ToString ()) {
|
|
} 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;
|
}
|
} 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;
|
sceneControl (doorLock, sendBytes, btnRemarkName, sender, sceneFilePath);
|
}
|
controlDeviceIndex++;
|
}
|
});
|
};
|
|
scemeAlarmFrameLayout.MouseUpEventHandler += hander;
|
btnRemarkName.MouseUpEventHandler += hander;
|
currentSceneIndex++;
|
}
|
#endregion
|
}
|
|
//报警场景控制,只对逻辑模块有用,所以其他地方都注释掉这个方法
|
void sceneControl (DoorLock door_lock, byte [] sendBytes, Button btnRemarkName, object sender, string sceneFilePath)
|
{
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.TargetsConfiguring) + "...");
|
});
|
var result = Control.ControlBytesSendHasReturn (Command.SetDoorLockSceneObj, door_lock.SubnetID, door_lock.DeviceID, sendBytes);
|
if (result == null) {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
return;
|
} else {
|
var result1 = result [0];
|
if (result1 == 0xF8) {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.TargetsControlSuccessfully), Direction = AMPopTipDirection.Down, CloseTime = 2 }.Show ((View)sender);
|
});
|
string key = "002_" + sceneType.ToString ("000");
|
door_lock.DictionaryList.Remove (key);
|
door_lock.DictionaryList.Add (key, sceneFilePath);
|
IO.FileUtils.SaveEquipmentMessage (door_lock, door_lock.PhysicsLoopID.ToString ());
|
} else {
|
Application.RunOnMainThread (() => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.FuquencyLyVertify), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
|
});
|
}
|
}
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
|
}
|
}
|