using System; using System.Collections.Generic; namespace Shared.SimpleControl.Phone { public class DoorLockEditedScence : Dialog { public static DoorLockEditedScence curView; VerticalScrolViewLayout bodyFrameLayout; List deviceFileList;//本地设备信息 List targetList = new List ();//按键配置的目标列 Button currentBtn;// 当前选择的按键 public DoorLockEditedScence (DoorLock door_lock) { curView = this; BackgroundColor = 0xFF3b3d3c; //找出当前的设备目标 deviceFileList = IO.FileUtils.ReadFiles ().FindAll ((obj) => { string [] str = obj.Split ('_'); return obj.StartsWith ("Equipment_") && str.Length == 5 && (str [1] == DeviceType.LightSwitch.ToString () || str [1] == DeviceType.LightDimming.ToString () || str [1] == DeviceType.CurtainModel.ToString () || str [1] == DeviceType.CurtainRoller.ToString () || str [1] == DeviceType.CurtainTrietex.ToString () || str [1] == DeviceType.LogicModule.ToString () ); }); showUserEditeScene (door_lock); readStatus (door_lock); } /// /// 读门锁所有历史记录信息 /// /// Door lock. void readStatus (DoorLock door_lock) { System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load)); }); try{ for (int i = 0, lostLink = 0; i < 19; i++) { door_lock.doorLockSceneTargetsList.Add (new DoorLockSceneTargets ()); byte [] sceneTargetInfoBytes = Control.ControlBytesSendHasReturn (Command.ReadDoorLockSceneObj, door_lock.SubnetID, door_lock.DeviceID, new byte [] { door_lock.PhysicsLoopID, 1, (byte)door_lock.doorLockSceneTargetsMethod, (byte)door_lock.doorLockSceneTargetsUserID, 1 }); if (sceneTargetInfoBytes == null) { lostLink++; } else { lostLink = 0; var sceneTargetsInfo = door_lock.doorLockSceneTargetsList [i]; sceneTargetsInfo.LoopID = sceneTargetInfoBytes [0]; sceneTargetsInfo.Type = sceneTargetInfoBytes [1]; sceneTargetsInfo.SceneMethod = sceneTargetInfoBytes [2]; sceneTargetsInfo.UserID = sceneTargetInfoBytes [3]; sceneTargetsInfo.TargetSerialNum = sceneTargetInfoBytes [4]; sceneTargetsInfo.ControlType = sceneTargetInfoBytes [5]; sceneTargetsInfo.TargetSunbetID = sceneTargetInfoBytes [6]; sceneTargetsInfo.TargetDeviceID = sceneTargetInfoBytes [7]; sceneTargetsInfo.TargetLoopID = sceneTargetInfoBytes [8]; sceneTargetsInfo.Parameter3 = sceneTargetInfoBytes [9]; sceneTargetsInfo.Parameter3 = sceneTargetInfoBytes [10]; sceneTargetsInfo.Parameter3 = sceneTargetInfoBytes [11]; } if (2 <= lostLink) { break; } } IO.FileUtils.SaveEquipmentMessage (door_lock, door_lock.PhysicsLoopID.ToString ()); } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); } void showUserEditeScene (DoorLock door_lock) { currentBtn = null; #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), BackgroundColor =0xff1e1f20, }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, TextID = R.MyInternationalizationString.EditScence, TextSize = 19, }; 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) => { Close (); curView = null; }; var btnl = new Button () { Height = 1, BackgroundColor = 0xFF000000, Y = topView.Height - 1 }; topView.AddChidren (btnl); #endregion var topFrameLayout = new FrameLayout () { Height = Application.GetRealHeight (80), BackgroundColor = 0xff000000, Y = topView.Bottom, }; AddChidren (topFrameLayout); var btnUnEditedScence = new Button () { Height = Application.GetRealHeight (80), Width = Application.GetRealWidth (310), X = Application.GetRealWidth (8), TextAlignment = TextAlignment.Center, BackgroundColor = 0xFFAAAAAA, SelectedBackgroundColor = 0xFFEB642C, Text = Language.StringByID (R.MyInternationalizationString.UnEditedScene), Padding = new Padding (0, 20, 0, 0), Radius = 5, }; topFrameLayout.AddChidren (btnUnEditedScence); Button btnTopLine = new Button () { Width = 8, X = btnUnEditedScence.Right , }; topFrameLayout.AddChidren (btnTopLine); var btnEditedDevice = new Button () { Width = Application.GetRealWidth (310), Height = Application.GetRealHeight (80), TextAlignment = TextAlignment.Center, BackgroundColor = 0xFFAAAAAA, SelectedBackgroundColor = 0xFFEB642C, Text = Language.StringByID (R.MyInternationalizationString.EditScence), Radius = 5, X = btnTopLine.Right , }; topFrameLayout.AddChidren (btnEditedDevice); bodyFrameLayout = new VerticalScrolViewLayout () { Height = Application.GetRealHeight (Application.DesignHeight - 126 - 80), Y = topFrameLayout.Bottom, }; AddChidren (bodyFrameLayout); showEquipments (door_lock, false); EventHandler UnEdithander = (sender1, e1) => { bodyFrameLayout.RemoveAll (); btnUnEditedScence.IsSelected = true; btnEditedDevice.IsSelected = false; showEquipments (door_lock, false); }; btnUnEditedScence.MouseUpEventHandler += UnEdithander; EventHandler Editedhander = (sender1, e1) => { bodyFrameLayout.RemoveAll (); btnUnEditedScence.IsSelected = false; btnEditedDevice.IsSelected = true; showEquipments (door_lock, true); }; btnEditedDevice.MouseUpEventHandler += Editedhander; UnEdithander (btnEditedDevice, null); #region bottomFrameLayout var bottomFrameLayout = new FrameLayout () { Height = Application.GetRealHeight (98), Y = Application.GetRealHeight (Application.DesignHeight - 97), }; AddChidren (bottomFrameLayout); var bottomLine = new Button () { Height = Application.GetRealHeight (1), BackgroundColor = 0xFFffffff, }; bottomFrameLayout.AddChidren (bottomLine); var btnSave = new Button () { Y = bottomLine.Bottom, Height = Application.GetRealHeight (97), TextID = R.MyInternationalizationString.SAVE, TextSize = 15, BackgroundColor = 0xFF121212, SelectedBackgroundColor = 0xFFFC5806, }; bottomFrameLayout.AddChidren (btnSave); btnSave.MouseUpEventHandler += (sender, e) => { for (int targetNum = 0; targetNum < targetList.Count; targetNum++) { Control.ControlBytesSend (Command.SetDoorLockSceneObj, door_lock.SubnetID, door_lock.DeviceID, new byte [] { door_lock.PhysicsLoopID, 1, (byte)door_lock.doorLockSceneTargetsMethod, (byte)door_lock.doorLockSceneTargetsUserID, (byte)targetNum, (byte)door_lock.doorLockSceneTargetsControlType, (byte)door_lock.doorLockSceneTargetSunbetID, (byte)door_lock.doorLockSceneTargetDeviceID, (byte)door_lock.doorLockSceneTargetLoopID, (byte)door_lock.doorLockSceneTargetsParameter1, (byte)door_lock.doorLockSceneTargetParameter2, (byte)door_lock.doorLockSceneParameter3, } ); } }; #endregion } /// /// 显示所有支持的设备 /// void showEquipments (DoorLock door_lock, bool onlyShowSelected = false) { bodyFrameLayout.RemoveAll (); int btnLimmingNum = 0; currentBtn = null; List willBeShowDeviceFilePath = new List (); if (onlyShowSelected) { foreach (var bytes in targetList) { foreach (var deviceFilePath in deviceFileList) { // if (deviceFilePath.EndsWith (bytes [3] + "_" + bytes [4] + "_" + bytes [5]) || deviceFilePath.EndsWith (bytes [3] + "_" + bytes [4] + "_0" + bytes [5])) { willBeShowDeviceFilePath.Add (deviceFilePath); break; // } } } } else { willBeShowDeviceFilePath = deviceFileList; } foreach (string deviceFilePath in willBeShowDeviceFilePath)//显示在本地找到的所有设备 { var frameLayout = new RowLayout () { Height = Application.GetRealHeight (93), }; bodyFrameLayout.AddChidren (frameLayout); var btnDelFile = new Button () { TextID = R.MyInternationalizationString.Del, BackgroundColor = 0xffff0000 }; frameLayout.AddRightView (btnDelFile); btnDelFile.MouseUpEventHandler += (sender, e) => { }; Common common = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); if (common == null) { continue; } var btnIcon = new Button () { Width = Application.GetRealHeight (13), Height = Application.GetRealHeight (13), X = Application.GetRealWidth (40), UnSelectedImagePath = "Item/Point.png", SelectedImagePath = "Item/PointSelected.png", Gravity = Gravity.CenterVertical, }; frameLayout.AddChidren (btnIcon); Button btnDevice = new Button () { Width = Application.GetRealWidth (300), Height = Application.GetRealHeight (80), TextAlignment = TextAlignment.CenterLeft, Text = common.Name, Tag = false, X = btnIcon.Right + Application.GetRealWidth (20), }; frameLayout.AddChidren (btnDevice); var btnRight = new Button () { Width = Application.GetRealWidth (28), Height = Application.GetRealHeight (40), X = btnDevice.Right + Application.GetRealWidth (200), UnSelectedImagePath = "Item/Right.png", SelectedImagePath = "Item/CheckSelected.png", Gravity = Gravity.CenterVertical, }; frameLayout.AddChidren (btnRight); btnRight.MouseUpEventHandler += (sender, e) => { //如果之前的按键点击了,也不是配置过的目标 if (currentBtn != null) { if ((bool)currentBtn.Tag) { btnRight.IsSelected = true; } else { btnRight.IsSelected = false; } } currentBtn = btnRight; btnRight.BackgroundColor = 0xff990088; }; string [] str = deviceFilePath.Split ('_');//str的格式为,前缀_设备类型_子网号_设备号_回路号 //当保存在本地的设备信息回路号小于10的时候,前面会加了个0,在这里去掉 //如果包括了当前设备,就显示为选中状态 if (null != targetList.Find ((bytes) => { if (common.Type == DeviceType.CurtainRoller || common.Type == DeviceType.CurtainTrietex) { return bytes [3] + "_" + bytes [4] == str [2] + "_" + str [3]; } else { return bytes [3] + "_" + bytes [4] + "_" + bytes [5] == str [2] + "_" + str [3] + "_" + str [4].TrimStart ('0'); } })) { btnRight.BackgroundColor = 0x99123456; btnRight.Tag = true; } btnRight.AddTag ("DeviceFilePath", deviceFilePath); btnRight.MouseUpEventHandler += (sender, e) => { TargetDeviceConfigure (sender, e, common, currentBtn, door_lock); }; } } /// /// 目标设备配置 /// /// Sender. /// E. /// Common. /// Button right. /// Door lock. public void TargetDeviceConfigure (Object sender, System.EventArgs e, Common common, Button currentBtn, DoorLock door_lock) { Common commonObj = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (currentBtn.GetTagByKey ("DeviceFilePath").ToString ()))); if (commonObj == null) { return; } byte [] sendBytes = new byte [12]; byte [] data = null; if (commonObj.Type == DeviceType.CurtainRoller || commonObj.Type == DeviceType.CurtainTrietex) { data = targetList.Find ((obj) => { return obj [3] + "_" + obj [4] == commonObj.SubnetID + "_" + commonObj.DeviceID; }); } else { data = targetList.Find ((obj) => { return obj [3] + "_" + obj [4] + "_" + obj [5] == commonObj.SubnetID + "_" + commonObj.DeviceID + "_" + commonObj.LoopID; }); } if (data == null) { sendBytes [0] = door_lock.PhysicsLoopID;//开锁 sendBytes [1] = 1;//开锁 sendBytes [2] = (byte)door_lock.doorLockSceneTargetsMethod;//开锁类型 密码开锁 sendBytes [3] = (byte)door_lock.doorLockSceneTargetsUserID;//用户ID sendBytes [6] = common.SubnetID; sendBytes [7] = common.DeviceID; sendBytes [8] = common.LoopID; } else { sendBytes = data; } string deviceType = commonObj.Type.ToString (); #region setingDialog Dialog dialog = new Dialog () { BackgroundColor = 0xFF111111, Width = Application.GetRealWidth (480), Height = Application.GetRealHeight (560), }; Button btnEquipmentTitle = new Button () { X = Application.GetRealWidth (35), Y = Application.GetRealHeight (15), Width = Application.GetRealWidth (250), Height = Application.GetRealHeight (50), TextAlignment = TextAlignment.CenterLeft, TextID = R.MyInternationalizationString.Device }; dialog.AddChidren (btnEquipmentTitle); Button btnLine1 = new Button () { Width = LayoutParams.MatchParent, Height = 1, BackgroundColor = 0xF0202020, Y = dialog.Height - Application.GetRealHeight (87), }; dialog.AddChidren (btnLine1); Button btnBack = new Button () { UnSelectedImagePath = "Item/PositioningDialogBack.png", Width = Application.GetRealWidth (123), Height = Application.GetRealHeight (87), Y = btnLine1.Bottom, }; dialog.AddChidren (btnBack); btnBack.MouseUpEventHandler += (senderB, eB) => { dialog.Close (); }; Button btnLine2 = new Button () { Width = 1, Height = Application.GetRealHeight (87), BackgroundColor = 0xF0202020, X = btnBack.Right, Y = btnLine1.Bottom }; dialog.AddChidren (btnLine2); Button btnSave1 = new Button () { Width = dialog.Width - Application.GetRealWidth (124), Height = Application.GetRealHeight (85), X = btnBack.Width + Application.GetRealWidth (2), Y = btnBack.Y, TextID = R.MyInternationalizationString.SAVE, UnSelectedImagePath = "Item/DialogSave2.png", SelectedImagePath = "Item/DialogSave2.png", }; dialog.AddChidren (btnSave1); btnEquipmentTitle.Text = commonObj.Name; if (deviceType == DeviceType.LightDimming.ToString () || deviceType == DeviceType.LightSwitch.ToString ()) { if (deviceType == DeviceType.LightSwitch.ToString () || deviceType == DeviceType.LightSwitchSocket.ToString ()) { var lblChangeName = new Button () { X = Application.GetRealWidth (20), Y = btnEquipmentTitle.Bottom + Application.GetRealHeight (20), Width = Application.GetRealWidth (200), Height = Application.GetRealHeight (60), TextID = R.MyInternationalizationString.DelayTime, TextAlignment = TextAlignment.CenterLeft, }; dialog.AddChidren (lblChangeName); var etDelayTime = new EditText () { X = lblChangeName.Right + Application.GetRealWidth (10), Y = btnEquipmentTitle.Bottom + Application.GetRealHeight (20), Width = lblChangeName.Width, Height = lblChangeName.Height, TextAlignment = TextAlignment.CenterLeft, Text = " " + (sendBytes [10] * 256 + sendBytes [11]).ToString (), UnSelectedImagePath = "Item/DialogTextBox.png", }; dialog.AddChidren (etDelayTime); var btnTest = new Button () { X = btnEquipmentTitle.X, Y = etDelayTime.Bottom + Application.GetRealHeight (30), Width = Application.GetRealWidth (200), Height = Application.GetRealHeight (60), BackgroundColor = 0xFF454545, SelectedBackgroundColor = 0xFFEB642C, BorderWidth = 1, Radius = 5, BorderColor = 0x00FFFFFF, TextID = R.MyInternationalizationString.ON, }; dialog.AddChidren (btnTest); if (sendBytes [9] == 100) { btnTest.IsSelected = true; } else { btnTest.IsSelected = false; } btnTest.MouseUpEventHandler += (sender3, e3) => { btnTest.IsSelected = !btnTest.IsSelected; if (btnTest.IsSelected) { sendBytes [9] = 100; btnTest.TextID = R.MyInternationalizationString.ON; } else { sendBytes [9] = 0; btnTest.TextID = R.MyInternationalizationString.OFF; } Control.ControlBytesSend (Command.SetSingleLight, sendBytes [6], sendBytes [7], new byte [] { sendBytes [8], sendBytes [9], sendBytes [10], sendBytes [11] }); }; btnSave1.MouseUpEventHandler += (sender2, e2) => { sendBytes [5] = 0x59; int dtime; if (int.TryParse (etDelayTime.Text.Trim ().ToString (), out dtime)) { if (dtime > 3600 || dtime < 0) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterTheNumberTwo), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } } else { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterTheNumberTwo), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } sendBytes [10] = (byte)(Convert.ToInt32 (etDelayTime.Text.Trim ()) / 256); sendBytes [11] = (byte)(Convert.ToInt32 (etDelayTime.Text.Trim ()) % 256); //if (hasNotInLocalDevice) { // foreach (var bytesend in targetList) { // Control.ControlBytesSend (Command.WriteWirelessPanelButtonKey, deviceLoop.SubnetID, deviceLoop.DeviceID, bytesend); // } //} if (!targetList.Contains (sendBytes)) { targetList.Add (sendBytes); } //Control.ControlBytesSend (Command.SetDoorLockSceneObj, door_lock.SubnetID, door_lock.DeviceID, sendBytes); dialog.Close (); currentBtn.IsSelected = true; AddBytesInfo (door_lock, sendBytes); }; } else if (deviceType == DeviceType.LightDimming.ToString ()) { //btnEquipmentTitle.TextID = R.MyInternationalizationString.DimmingLights; var lblChangeName = new Button () { X = Application.GetRealWidth (10), Y = btnEquipmentTitle.Bottom + Application.GetRealHeight (20), Width = Application.GetRealWidth (200), Height = Application.GetRealHeight (60), TextID = R.MyInternationalizationString.DelayTime, TextAlignment = TextAlignment.CenterLeft, }; dialog.AddChidren (lblChangeName); var etDelayTime = new EditText () { X = lblChangeName.Right + Application.GetRealWidth (10), Y = btnEquipmentTitle.Bottom + Application.GetRealHeight (20), Width = lblChangeName.Width, Height = lblChangeName.Height, TextAlignment = TextAlignment.CenterLeft, Text = " " + (sendBytes [10] * 256 + sendBytes [11]).ToString (), UnSelectedImagePath = "Item/DialogTextBox.png", }; dialog.AddChidren (etDelayTime); #region 进度条 bool unEnableDimmingLight = true; if (UserConfig.Instance.UnEnableDimmingLight.Contains (sendBytes [6] + "_" + sendBytes [7] + "_" + sendBytes [9])) { unEnableDimmingLight = false; } var btnMinBrightness = new Button () { Width = Application.GetRealWidth (50), Height = Application.GetRealHeight (80), X = Application.GetRealWidth (10), Y = lblChangeName.Bottom + Application.GetRealHeight (30), Text = "0%", TextColor = 0xFF555555, TextAlignment = TextAlignment.Center, }; if (unEnableDimmingLight) dialog.AddChidren (btnMinBrightness); var f = new FrameLayout () { Width = Application.GetRealWidth (540 - 210), Height = Application.GetRealHeight (80), X = btnMinBrightness.Right, Y = btnMinBrightness.Y, BackgroundImagePath = "Item/SeekBarBackground.png" }; if (unEnableDimmingLight) dialog.AddChidren (f); HorizontalSeekBar horizontalSeekBar = new HorizontalSeekBar () { Gravity = Gravity.CenterVertical, Progress = sendBytes [9], }; f.AddChidren (horizontalSeekBar); var btnMaxBrightness = new Button () { Width = Application.GetRealWidth (100), Height = Application.GetRealHeight (80), X = f.Right, Y = btnMinBrightness.Y, Text = sendBytes [10] * 256 + sendBytes [11] + "%", TextColor = 0xFF555555, }; if (unEnableDimmingLight) dialog.AddChidren (btnMaxBrightness); horizontalSeekBar.ProgressChanged += (s, ee) => { sendBytes [9] = (byte)ee; btnMaxBrightness.Text = sendBytes [9].ToString () + "%"; Control.ControlBytesSend (Command.SetSingleLight, sendBytes [6], sendBytes [7], new byte [] { sendBytes [8], sendBytes [9], 0, 0 }); }; #endregion var btnTest = new Button () { X = btnEquipmentTitle.X, Y = f.Bottom + Application.GetRealHeight (30), Width = Application.GetRealWidth (200), Height = Application.GetRealHeight (60), BackgroundColor = 0xFF454545, SelectedBackgroundColor = 0xFFEB642C, BorderWidth = 1, Radius = 5, BorderColor = 0x00FFFFFF, TextID = R.MyInternationalizationString.ON, Gravity = Gravity.CenterHorizontal, }; dialog.AddChidren (btnTest); btnTest.MouseUpEventHandler += (sender3, e3) => { btnTest.IsSelected = !btnTest.IsSelected; if (btnTest.IsSelected) { sendBytes [9] = 100; btnTest.TextID = R.MyInternationalizationString.ON; horizontalSeekBar.Progress = 100; btnMaxBrightness.Text = "100%"; } else { sendBytes [9] = 0; btnTest.TextID = R.MyInternationalizationString.OFF; horizontalSeekBar.Progress = 0; btnMaxBrightness.Text = "0%"; } Control.ControlBytesSend (Command.SetSingleLight, sendBytes [6], sendBytes [7], new byte [] { sendBytes [8], sendBytes [9], 0, 0 }); }; if (sendBytes [9] == 0) { btnTest.IsSelected = false; } else { btnTest.IsSelected = true; } btnSave1.MouseUpEventHandler += (sender2, e2) => { sendBytes [5] = 0x59; int dtime; if (int.TryParse (etDelayTime.Text.Trim ().ToString (), out dtime)) { if (dtime > 3600 || dtime < 0) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterTheNumberTwo), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } } else { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterTheNumberTwo), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } sendBytes [10] = (byte)(Convert.ToInt32 (etDelayTime.Text.Trim ()) / 256); sendBytes [11] = (byte)(Convert.ToInt32 (etDelayTime.Text.Trim ()) % 256); //if (hasNotInLocalDevice) { // foreach (var bytesend in targetList) { // Control.ControlBytesSend (Command.WriteWirelessPanelButtonKey, deviceLoop.SubnetID, deviceLoop.DeviceID, bytesend); // } //} if (!targetList.Contains (sendBytes)) { targetList.Add (sendBytes); } Control.ControlBytesSend (Command.SetDoorLockSceneObj, door_lock.SubnetID, door_lock.DeviceID, sendBytes); dialog.Close (); AddBytesInfo (door_lock, sendBytes); currentBtn.IsSelected = true; }; } } else if (deviceType == DeviceType.CurtainModel.ToString () || deviceType == DeviceType.CurtainTrietex.ToString () || deviceType == DeviceType.CurtainRoller.ToString ()) { if (deviceType == DeviceType.CurtainModel.ToString ()) { var btnOpenCurtain = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (125), UnSelectedImagePath = "Curtain/CurtainOpen.png", SelectedImagePath = "Curtain/CurtainOpenSelected.png", X = btnEquipmentTitle.X, Y = Application.GetRealHeight (255), }; dialog.AddChidren (btnOpenCurtain); var btnOpenLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnOpenCurtain.X, Y = btnOpenCurtain.Bottom + Application.GetRealHeight (5), TextID = R.MyInternationalizationString.Open, TextColor = 0xFFFFFFFF, }; dialog.AddChidren (btnOpenLbl); var btnStopCurtain = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (125), X = Application.GetRealWidth ((480 - 124) / 2), Y = btnOpenCurtain.Y, SelectedImagePath = "Curtain/CurtainTimeOutSelected.png", UnSelectedImagePath = "Curtain/CurtainTimeOut.png", }; dialog.AddChidren (btnStopCurtain); var btnStopLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnStopCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Stop, TextColor = 0xFFFFFFFF, }; dialog.AddChidren (btnStopLbl); var btnCloseCurtain = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (125), X = Application.GetRealWidth (480 - 124 - 35), Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainClose.png", SelectedImagePath = "Curtain/CurtainCloseSelected.png", }; if (sendBytes [9] == 2) { btnCloseCurtain.IsSelected = true; btnStopCurtain.IsSelected = false; btnOpenCurtain.IsSelected = false; } else if (sendBytes [9] == 0) { btnCloseCurtain.IsSelected = false; btnStopCurtain.IsSelected = true; btnOpenCurtain.IsSelected = false; } else if (sendBytes [9] == 1) { btnCloseCurtain.IsSelected = false; btnStopCurtain.IsSelected = false; btnOpenCurtain.IsSelected = true; } btnCloseCurtain.MouseUpEventHandler += (sender3, e3) => { btnCloseCurtain.IsSelected = true; btnOpenCurtain.IsSelected = false; btnStopCurtain.IsSelected = false; sendBytes [9] = 2; }; btnOpenCurtain.MouseUpEventHandler += (sender3, e3) => { btnCloseCurtain.IsSelected = false; btnOpenCurtain.IsSelected = true; btnStopCurtain.IsSelected = false; sendBytes [9] = 1; }; btnStopCurtain.MouseUpEventHandler += (sender3, e3) => { btnCloseCurtain.IsSelected = false; btnOpenCurtain.IsSelected = false; btnStopCurtain.IsSelected = true; sendBytes [9] = 0; }; dialog.AddChidren (btnCloseCurtain); btnStopCurtain.IsSelected = true; var btnCloseLbl = new Button () { Width = Application.GetRealWidth (94), Height = Application.GetRealHeight (30), X = btnCloseCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Close, TextColor = 0xFFFFFFFF, }; dialog.AddChidren (btnCloseLbl); btnSave1.MouseUpEventHandler += (sender2, e2) => { //if (hasNotInLocalDevice) { // foreach (var bytesend in targetList) { // Control.ControlBytesSend (Command.WriteWirelessPanelButtonKey, deviceLoop.SubnetID, deviceLoop.DeviceID, bytesend); // } //} if (!targetList.Contains (sendBytes)) { targetList.Add (sendBytes); } sendBytes [5] = 0x5C; Control.ControlBytesSend (Command.SetDoorLockSceneObj, door_lock.SubnetID, door_lock.DeviceID, sendBytes); dialog.Close (); AddBytesInfo (door_lock, sendBytes); currentBtn.IsSelected = true; }; } else if (deviceType == DeviceType.CurtainTrietex.ToString () || deviceType == DeviceType.CurtainRoller.ToString ()) { var horizontalScrolViewMain = new HorizontalScrolViewLayout () { Height = Application.GetRealHeight (78), Y = Application.GetRealHeight (75), }; dialog.AddChidren (horizontalScrolViewMain); var middleLayout = new FrameLayout { Height = Application.GetRealHeight (292), Y = horizontalScrolViewMain.Bottom, }; dialog.AddChidren (middleLayout); var curtainState = new Button { Width = Application.GetRealWidth (240), Height = LayoutParams.MatchParent, UnSelectedImagePath = "Item/Menu.png", SelectedImagePath = "Item/MenuSelected.png", TextID = R.MyInternationalizationString.CurtainState, TextAlignment = TextAlignment.Center, IsSelected = true, }; horizontalScrolViewMain.AddChidren (curtainState); var curtainProgress = new Button { Width = Application.GetRealWidth (240), Height = LayoutParams.MatchParent, UnSelectedImagePath = "Item/Menu.png", SelectedImagePath = "Item/MenuSelected.png", TextID = R.MyInternationalizationString.CurtainProgress, TextAlignment = TextAlignment.Center, }; horizontalScrolViewMain.AddChidren (curtainProgress); EventHandler handler = (sender1, e1) => { middleLayout.RemoveAll (); curtainState.IsSelected = true; curtainProgress.IsSelected = false; #region curtain status var btnOpenCurtain = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (125), UnSelectedImagePath = "Curtain/CurtainOpen.png", SelectedImagePath = "Curtain/CurtainOpenSelected.png", X = btnEquipmentTitle.X, Y = Application.GetRealHeight (85), }; middleLayout.AddChidren (btnOpenCurtain); if (sendBytes [8] == 1) { if (sendBytes [9] == 1) { btnOpenCurtain.IsSelected = true; } } var btnOpenLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnOpenCurtain.X, Y = btnOpenCurtain.Bottom + Application.GetRealHeight (5), TextID = R.MyInternationalizationString.Open, TextColor = 0xFFFFFFFF, }; middleLayout.AddChidren (btnOpenLbl); var btnStopCurtain = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (125), X = Application.GetRealWidth ((480 - 124) / 2), Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainTimeOut.png", SelectedImagePath = "Curtain/CurtainTimeOutSelected.png", }; middleLayout.AddChidren (btnStopCurtain); if (sendBytes [8] == 1) { if (sendBytes [9] == 0) { btnStopCurtain.IsSelected = true; } } var btnStopLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnStopCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Stop, TextColor = 0xFFFFFFFF, }; middleLayout.AddChidren (btnStopLbl); var btnCloseCurtain = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (125), X = Application.GetRealWidth (480 - 124 - 35), Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainClose.png", SelectedImagePath = "Curtain/CurtainCloseSelected.png", }; middleLayout.AddChidren (btnCloseCurtain); if (sendBytes [8] == 1) { if (sendBytes [9] == 2) { btnCloseCurtain.IsSelected = true; } } var btnCloseLbl = new Button () { Width = Application.GetRealWidth (94), Height = Application.GetRealHeight (30), X = btnCloseCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Close, TextColor = 0xFFFFFFFF, }; middleLayout.AddChidren (btnCloseLbl); btnCloseCurtain.MouseUpEventHandler += (sender3, e3) => { btnCloseCurtain.IsSelected = true; btnOpenCurtain.IsSelected = false; btnStopCurtain.IsSelected = false; sendBytes [8] = 1; sendBytes [9] = 2; UpdataStatus (sendBytes); }; btnOpenCurtain.MouseUpEventHandler += (sender3, e3) => { btnCloseCurtain.IsSelected = false; btnOpenCurtain.IsSelected = true; btnStopCurtain.IsSelected = false; sendBytes [8] = 1; sendBytes [9] = 1; UpdataStatus (sendBytes); }; btnStopCurtain.MouseUpEventHandler += (sender3, e3) => { btnCloseCurtain.IsSelected = false; btnOpenCurtain.IsSelected = false; btnStopCurtain.IsSelected = true; sendBytes [8] = 1; sendBytes [9] = 0; UpdataStatus (sendBytes); }; #endregion }; curtainState.MouseUpEventHandler += handler; EventHandler progressHandler = (sender1, e1) => { middleLayout.RemoveAll (); curtainProgress.IsSelected = true; curtainState.IsSelected = false; #region 进度条 var btnLine = new Button () { Width = Application.GetRealWidth (640), Height = 1, BackgroundColor = 0xF0000000, }; middleLayout.AddChidren (btnLine); var curtainbtnCurrentStatus = new Button () { Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (50), X = Application.GetRealWidth (20), Y = Application.GetRealHeight (80), TextAlignment = TextAlignment.CenterLeft, Text = Language.StringByID (R.MyInternationalizationString.CurrentStatusProgress) + ":" + sendBytes [6].ToString () + "%", }; middleLayout.AddChidren (curtainbtnCurrentStatus); var btnMinBrightness = new Button () { Width = Application.GetRealWidth (50), Height = Application.GetRealHeight (40), X = Application.GetRealWidth (2), Y = curtainbtnCurrentStatus.Bottom + Application.GetRealHeight (30), Text = "0%", TextColor = 0xFF555555, TextAlignment = TextAlignment.Center, }; middleLayout.AddChidren (btnMinBrightness); var f = new FrameLayout () { Width = Application.GetRealWidth (540 - 192), Height = Application.GetRealHeight (80), X = btnMinBrightness.Right, Y = btnMinBrightness.Y, BackgroundImagePath = "Item/SeekBarBackground.png" }; middleLayout.AddChidren (f); var curtainhorizontalSeekBar = new HorizontalSeekBar () { Width = Application.GetRealWidth (540 - 193), Height = LayoutParams.MatchParent, Gravity = Gravity.CenterVertical, Progress = sendBytes [9], }; f.AddChidren (curtainhorizontalSeekBar); if (sendBytes [8] == 1) { if (sendBytes [9] == 1) { sendBytes [9] = 100; curtainbtnCurrentStatus.Text = Language.StringByID (R.MyInternationalizationString.CurrentStatusProgress) + ":" + 100 + "%"; curtainhorizontalSeekBar.Progress = 100; } else if (sendBytes [9] == 2) { sendBytes [9] = 0; curtainhorizontalSeekBar.Progress = 0; curtainbtnCurrentStatus.Text = Language.StringByID (R.MyInternationalizationString.CurrentStatusProgress) + ":" + 0 + "%"; } else { curtainhorizontalSeekBar.Progress = sendBytes [9]; curtainbtnCurrentStatus.Text = Language.StringByID (R.MyInternationalizationString.CurrentStatusProgress) + ":" + sendBytes [6].ToString () + "%"; } } var btnMaxBrightness = new Button () { Width = Application.GetRealWidth (100), Height = Application.GetRealHeight (40), X = f.Right, Y = btnMinBrightness.Y, Text = "100%", TextColor = 0xFF555555, }; middleLayout.AddChidren (btnMaxBrightness); curtainhorizontalSeekBar.ProgressChanged += (s, ee) => { sendBytes [8] = 17; sendBytes [9] = (byte)ee; curtainhorizontalSeekBar.Progress = sendBytes [9]; curtainbtnCurrentStatus.Text = Language.StringByID (R.MyInternationalizationString.CurrentStatusProgress) + ":" + sendBytes [9].ToString () + "%"; }; #endregion }; curtainProgress.MouseUpEventHandler += progressHandler; if (sendBytes [8] == 1) { handler (curtainState, null); } else { progressHandler (curtainProgress, null); } btnSave1.MouseUpEventHandler += (sender2, e2) => { //if (hasNotInLocalDevice) { // foreach (var bytesend in targetList) { // Control.ControlBytesSend (Command.WriteWirelessPanelButtonKey, deviceLoop.SubnetID, deviceLoop.DeviceID, bytesend); // } //} if (!targetList.Contains (sendBytes)) { targetList.Add (sendBytes); } sendBytes [5] = 0x5C; Control.ControlBytesSend (Command.SetDoorLockSceneObj, door_lock.SubnetID, door_lock.DeviceID, sendBytes); dialog.Close (); AddBytesInfo (door_lock, sendBytes); currentBtn.IsSelected = false; }; } } else if (deviceType == DeviceType.LogicModule.ToString ()) { Button btnTest = new Button () { Width = Application.GetRealWidth (170), Height = Application.GetRealHeight (70), TextID = R.MyInternationalizationString.Test, Gravity = Gravity.Center, SelectedBackgroundColor = 0xF0EF5800, BackgroundColor = 0xF06A6A6A, }; dialog.AddChidren (btnTest); btnTest.MouseUpEventHandler += (sender2, e2) => { btnTest.IsSelected = false; }; LogicModule device = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (currentBtn.GetTagByKey ("DeviceFilePath").ToString ()))); btnTest.MouseDownEventHandler += (sender2, e2) => { btnTest.IsSelected = true; Control.ControlBytesSendHasReturn (Command.SetScene, device.SubnetID, device.DeviceID, new byte [] { device.AreaID,device.AreaSceneID}); }; btnSave1.MouseUpEventHandler += (sender2, e2) => { //if (hasNotInLocalDevice) { // foreach (var bytesend in targetList) { // Control.ControlBytesSend (Command.WriteWirelessPanelButtonKey, deviceLoop.SubnetID, deviceLoop.DeviceID, bytesend); // } //} if (!targetList.Contains (sendBytes)) { targetList.Add (sendBytes); } sendBytes [5] = 0x55; sendBytes [9] = device.AreaSceneID; Control.ControlBytesSend (Command.SetDoorLockSceneObj, door_lock.SubnetID, door_lock.DeviceID, sendBytes); dialog.Close (); currentBtn.IsSelected = true; AddBytesInfo (door_lock, sendBytes); }; } dialog.Show (); #endregion } /// /// 窗帘状态更新 /// /// Send bytes. void UpdataStatus (byte [] sendBytes) { Common common = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (currentBtn.GetTagByKey ("DeviceFilePath").ToString ()))); if (common == null) { return; } sendBytes [6] = common.SubnetID; sendBytes [7] = common.DeviceID; sendBytes [8] = common.LoopID; if (Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, sendBytes [6], sendBytes [7], new byte [] { sendBytes [8], 1 }) == null) { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); } else { } } /// /// 目标设备被发送时的附加数据的保存方法 /// /// Door lock. /// Send bytes. void AddBytesInfo (DoorLock door_lock, byte [] sendBytes) { door_lock.doorLockSceneTargetsControlType = sendBytes [5]; door_lock.doorLockSceneTargetSunbetID = sendBytes [6]; door_lock.doorLockSceneTargetDeviceID = sendBytes [7]; door_lock.doorLockSceneTargetLoopID = sendBytes [8]; door_lock.doorLockSceneTargetsParameter1 = sendBytes [9]; door_lock.doorLockSceneTargetParameter2 = sendBytes [10]; door_lock.doorLockSceneParameter3 = sendBytes [11]; IO.FileUtils.SaveEquipmentMessage (door_lock, door_lock.PhysicsLoopID.ToString ()); } } }