From ed2604abbc7949ebc78e3659fc9f03b2f814a14b Mon Sep 17 00:00:00 2001 From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local> Date: 星期二, 29 十月 2019 14:20:27 +0800 Subject: [PATCH] 2019.10.29-1 --- ZigbeeApp/Shared/Phone/UserCenter/Device/Curtain/RollerShadeDirectionLimitSettingForm.cs | 1020 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 1,020 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Curtain/RollerShadeDirectionLimitSettingForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Curtain/RollerShadeDirectionLimitSettingForm.cs new file mode 100755 index 0000000..9dbff4c --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Curtain/RollerShadeDirectionLimitSettingForm.cs @@ -0,0 +1,1020 @@ +锘縰sing System; +using System.Collections.Generic; +using Shared.Common; +using Shared.Phone.UserView; +using ZigBee.Device; +namespace Shared.Phone.UserCenter.DeviceCurtain +{ + /// <summary> + /// 鍗峰笜璁剧疆鍙嶅悜涓庨檺浣� + /// </summary> + public class RollerShadeDirectionLimitSettingForm: EditorCommonForm,ZigBee.Common.IStatus + { + #region 鈼� 璁惧鎺ュ彛__________________________ + /// <summary> + /// Changed the specified common. + /// </summary> + /// <param name="common">Common.</param> + public void Changed(CommonDevice common) + { + //throw new NotImplementedException(); + } + /// <summary> + /// 璁惧鐘舵�佹洿鏂版帴鍙� + /// <para>type锛氬鏋滀负 DeviceInComingRespon:璁惧鏂颁笂鎶�</para> + /// <para>type锛氬鏋滀负 IASInfoReport:RemoveDeviceRespon</para> + /// <para>type锛氬鏋滀负 DeviceStatusReport:璁惧涓婃姤</para> + /// <para>type锛氬鏋滀负 IASInfoReport:IAS瀹夐槻淇℃伅涓婃姤</para> + /// <para>type锛氬鏋滀负 OnlineStatusChange: 璁惧鍦ㄧ嚎鐘舵�佹洿鏂�</para> + /// </summary> + /// <param name="common">Common.</param> + /// <param name="typeTag">Type tag.</param> + public void DeviceInfoChange(CommonDevice common, string typeTag) + { + if (typeTag == "DeviceStatusReport") + { + Application.RunOnMainThread(() => + { + try + { + var device = listRollershade[0]; + + //鏄惁涓哄綋鍓嶈澶� + if (device.DeviceEpoint != common.DeviceEpoint || device.DeviceAddr != common.DeviceAddr) + { + return; + } + if ((common as Rollershade).DeviceStatusReport == null || (common as Rollershade).DeviceStatusReport.CluterID != 258) + { + return; + } + var attriButeList = (common as Rollershade).DeviceStatusReport.AttriBute; + if(attriButeList==null || attriButeList.Count==0) + { + return; + } + switch (attriButeList[0].AttributeId) + { + case 0: + //绫诲瀷 + rollershade.DeviceStatusReport = (common as Rollershade).DeviceStatusReport; + rollershade.WcdType = attriButeList[0].AttriButeData; + rollershade.LastDateTime = DateTime.Now; + break; + case 1: + //鎬婚暱 + rollershade.DeviceStatusReport = (common as Rollershade).DeviceStatusReport; + rollershade.WcdCurrentLength = attriButeList[0].AttriButeData; + windowCurrentLength = rollershade.WcdCurrentLength; + rollershade.LastDateTime = DateTime.Now; + break; + case 23: + //鏂瑰悜 + rollershade.DeviceStatusReport = (common as Rollershade).DeviceStatusReport; + if (0 < (attriButeList[0].AttriButeData & 0x01)) + { + //鐢垫満鍙嶅悜 + rollershade.WcdCurrentDirection = true; + directionBtn.TextID = R.MyInternationalizationString.ReverseDirection; + } + else + { + //鐢垫満姝e悜 + rollershade.WcdCurrentDirection = false; + directionBtn.TextID = R.MyInternationalizationString.ForwardDirection; + } + rollershade.LastDateTime = DateTime.Now; + break; + case 16: + //涓婇檺浣� + rollershade.DeviceStatusReport = (common as Rollershade).DeviceStatusReport; + if (windowCurrentLength != 0) + { + rollershade.WcdCurrentWcdInstalOpenLimit = attriButeList[0].AttriButeData; + startSeekBar.Progress = (int)(rollershade.WcdCurrentWcdInstalOpenLimit / (windowCurrentLength * 1.0) * 100); + startBtn.Text = $"{Language.StringByID(R.MyInternationalizationString.SetStartLimit)} : {startSeekBar.Progress}%"; + rollershade.LastDateTime = DateTime.Now; + } + break; + case 17: + //涓嬮檺浣� + rollershade.DeviceStatusReport = (common as Rollershade).DeviceStatusReport; + if (windowCurrentLength != 0) + { + rollershade.WcdCurrentInstalCloseLimit = attriButeList[0].AttriButeData; + endSeekBar.Progress = (int)(rollershade.WcdCurrentInstalCloseLimit / (windowCurrentLength * 1.0) * 100); + endBtn.Text = $"{Language.StringByID(R.MyInternationalizationString.SetEndLimit)} : {endSeekBar.Progress}%"; + rollershade.LastDateTime = DateTime.Now; + } + break; + case 8: + //绐楀笜鐧惧垎姣� + //鍙戦�佽缃笂闄愪綅 + //鍙戦�佽缃笅闄愪綅 + rollershade.DeviceStatusReport = (common as Rollershade).DeviceStatusReport; + rollershade.LastDateTime = DateTime.Now; + rollershade.WcdCurrentPositionLiftPercentage= attriButeList[0].AttriButeData; + System.Console.WriteLine($"鏀跺埌浜嗗洖澶嶏細{rollershade.WcdCurrentPositionLiftPercentage} {startSeekBar.Progress} {endSeekBar.Progress}"); + if (canSetStartLimit && System.Math.Abs(rollershade.WcdCurrentPositionLiftPercentage - startSeekBar.Progress) < 5) + { + hadReceivedStartEndLimitCode = true; + CommonPage.Loading.Hide(); + var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.SettingStartLimit), Language.StringByID(R.MyInternationalizationString.Cancel), Language.StringByID(R.MyInternationalizationString.Confrim)); + alert.Show(); + alert.ResultEventHandler += async (sender2, e2) => + { + if (e2) + { + try + { + CommonPage.Loading.Start(); + var status = await SetLimitAsync(Rollershade.CurtainPrivateInstalledLimi.UpLimit, rollershade); + if (status == 0) + { + System.Console.WriteLine("涓婅绋嬭缃垚鍔�"); + this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.Success)); + } + else if (status == -1) + { + CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ConnectGWFail); + } + else + { + CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FAIL); + } + } + catch (Exception ex) + { + System.Console.WriteLine($"璁剧疆涓婇檺浣嶅け璐ex.Message}"); + } + finally + { + CommonPage.Loading.Hide(); + } + } + }; + } + if (canSetEndLimit && System.Math.Abs(rollershade.WcdCurrentPositionLiftPercentage - endSeekBar.Progress) < 5) + { + hadReceivedStartEndLimitCode = true; + CommonPage.Loading.Hide(); + var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.SettingEndLimit), Language.StringByID(R.MyInternationalizationString.Cancel), Language.StringByID(R.MyInternationalizationString.Confrim)); + alert.Show(); + alert.ResultEventHandler += async (sender2, e2) => + { + if (e2) + { + try + { + CommonPage.Loading.Start(); + var status = await SetLimitAsync(Rollershade.CurtainPrivateInstalledLimi.DownLimit, rollershade); + if (status == 0) + { + System.Console.WriteLine("涓嬭绋嬭缃垚鍔�"); + this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.Success)); + } + else if (status == -1) + { + CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ConnectGWFail); + } + else + { + CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FAIL); + } + } + catch (Exception ex) + { + System.Console.WriteLine($"璁剧疆涓嬮檺浣嶅け璐ex.Message}"); + } + finally + { + CommonPage.Loading.Hide(); + } + } + }; + } + break; + } + } + catch (Exception ex) + { + System.Console.WriteLine($"Error:{ex.Message}"); + } + }); + } + } + /// <summary> + /// Changeds the IL ogic status. + /// </summary> + /// <param name="logic">Logic.</param> + public void ChangedILogicStatus(ZigBee.Device.Logic logic) + { + //throw new NotImplementedException(); + } + /// <summary> + /// Changeds the IS cene status. + /// </summary> + /// <param name="scene">Scene.</param> + public void ChangedISceneStatus(Scene scene) + { + //throw new NotImplementedException(); + } + #endregion + + #region 鈼� 鍙橀噺_____________________________ + /// <summary> + /// 璁剧疆鏂瑰悜涓庨檺浣嶇殑璁惧--绐楀笜 + /// </summary> + private List<CommonDevice> listRollershade = null; + /// <summary> + /// The rollershade. + /// </summary> + private Rollershade rollershade = null; + /// <summary> + /// 璧峰鏂瑰悜btn + /// </summary> + private NormalViewControl directionBtn = null; + /// <summary> + /// 璁剧疆寮�濮嬬殑闄愪綅鐨勬粦鏉� + /// </summary> + private HorizontalSeekBar startSeekBar = null; + /// <summary> + /// 璁剧疆闄愪綅鐨勫紑濮嬬櫨鍒嗘瘮鎸夐挳 + /// </summary> + private Button startBtn = null; + /// <summary> + /// 璁剧疆缁撴潫闄愪綅鐨勬粦鏉� + /// </summary> + private HorizontalSeekBar endSeekBar = null; + /// <summary> + /// 璁剧疆闄愪綅鐨勭粨鏉熺櫨鍒嗘瘮鎸夐挳 + /// </summary> + private Button endBtn = null; + //寤舵椂 300姣 + private readonly double sleepSpan = 0.3; + /// <summary> + /// 鏄惁鍙互鍙戦�佽缃笂闄愪綅鍛戒护浜� + /// </summary> + private bool canSetStartLimit = false; + /// <summary> + /// 鎺ュ彛涓槸鍚︽敹鍒颁簡璁剧疆寮�濮媆缁撴潫闄愪綅鐨勫杞ㄧЩ鍔ㄧ殑鐧惧垎姣� + /// </summary> + private bool hadReceivedStartEndLimitCode = false; + /// <summary> + /// 鏄惁鍙互鍙戦�佽缃粨鏉熼檺浣嶅懡浠や簡 + /// </summary> + /// + private bool canSetEndLimit = false; + /// <summary> + /// 绐楀笜鎬婚暱 + /// </summary> + private int windowCurrentLength = 0; + /// <summary> + /// 璁剧疆闄愪綅鐨勭嚎绋嬪垪琛� + /// </summary> + static List<System.Threading.Thread> threads = new List<System.Threading.Thread> { }; + #endregion + + #region 鈼� 鏋勯�犳柟娉昣_________________________ + /// <summary> + /// 鏋勯�犳柟娉� + /// </summary> + public RollerShadeDirectionLimitSettingForm() + { + UserView.HomePage.Instance.ScrollEnabled = false; + ZigBee.Device.ZbGateway.StatusList.Add(this); + } + + #endregion + + #region 鈼� 鍏抽棴鐣岄潰__________________________ + /// <summary> + /// 鐢婚潰鍏抽棴 + /// </summary> + public override void CloseForm() + { + UserView.HomePage.Instance.ScrollEnabled = true; + ZigBee.Device.ZbGateway.StatusList.Remove(this); + base.CloseForm(); + } + + #endregion + + #region 鈼� 鏄剧ず鐣岄潰__________________________ + + /// <summary> + /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) + /// </summary> + /// <param name="i_listdevice">璁惧</param> + public void ShowForm(List<CommonDevice> i_listdevice) + { + if(i_listdevice==null || i_listdevice.Count==0) + { + return; + } + this.listRollershade = i_listdevice; + this.rollershade = listRollershade[0] as Rollershade; + + //璁剧疆鏍囬淇℃伅 + base.SetTitleText(Language.StringByID(R.MyInternationalizationString.DirectionLimit)); + + //鍒濆鍖栦腑閮ㄦ帶浠� + this.InitMiddleFrame(); + } + + #endregion + + #region 鈼� 鍒濆鍖栦腑閮ㄦ帶浠禵____________________ + /// <summary> + /// 鍒濆鍖栦腑閮ㄦ帶浠� + /// </summary> + private void InitMiddleFrame() + { + bodyFrameLayout.RemoveAll(); + + var listview = new VerticalScrolViewLayout(); + listview.ScrollEnabled = false; + bodyFrameLayout.AddChidren(listview); + //璇诲彇鐘舵�� + InitReadStatu(); + //璧峰鏂瑰悜 + AddinitialDirectionRow(listview); + //闄愪綅 + AddDirectionLimitRow(listview); + //鎭㈠琛岀▼璁剧疆 + AddRestoreTravelSettingsRow(listview); + } + #endregion + + #region 鈼� 璇诲彇鐘舵�乢_________________________ + /// <summary> + /// 璇诲彇鐘舵�� + /// </summary> + private void InitReadStatu() + { + //涓嶄笂闈炶繙绋� + if (rollershade.Gateway == null) + { + return; + } + UserHomeView.ReadStatus(rollershade, () => + { + rollershade.ReadWcdType(); + rollershade.ReadWcdLength(); + rollershade.ReadCurtainDirectionAndMode(); + rollershade.ReadWcdInstalOpenLimit(); + rollershade.ReadWcdInstalCloseLimit(); + }, 1); + } + + #endregion + + #region 鈼� 娣诲姞 銆愯捣濮嬫柟鍚戙�戣_________________ + + /// <summary> + /// 娣诲姞 銆愯捣濮嬫柟鍚戙�戣 + /// </summary> + /// <param name="listview">Lisrview.</param> + private void AddinitialDirectionRow(VerticalScrolViewLayout listview) + { + var initialDirectionRow = new RowLayoutControl(); + listview.AddChidren(initialDirectionRow); + + var initialDirectionBtn = initialDirectionRow.frameTable.AddLeftCaption("", 900); + initialDirectionBtn.TextID = R.MyInternationalizationString.InitialDirection; + + initialDirectionRow.frameTable.AddRightArrow(); + + directionBtn = initialDirectionRow.frameTable.AddMostRightView("", 300); + directionBtn.TextID = rollershade.WcdCurrentDirection == false ? R.MyInternationalizationString.ForwardDirection : R.MyInternationalizationString.ReverseDirection; + directionBtn.TextColor = UserCenterColor.Current.TextGrayColor; + + initialDirectionRow.frameTable.ButtonClickEvent += (sender, e) => + { + try + { + CommonPage.Loading.Start(); + System.Console.WriteLine("鏂瑰悜"); + var list = new List<string> { }; + list.Add(Language.StringByID(R.MyInternationalizationString.ForwardDirection)); + list.Add(Language.StringByID(R.MyInternationalizationString.ReverseDirection)); + PickerView.Show(list, async (obj) => + { + directionBtn.Text = list[obj]; + bool direction = directionBtn.Text.Trim() == Language.StringByID(R.MyInternationalizationString.ReverseDirection); + var setWritableValueResponAllData = await rollershade.SetCurtainDirectionAsync(direction); + if (setWritableValueResponAllData == null || setWritableValueResponAllData.setWritableValueResponData == null) + { + CommonPage.Loading.Hide(); + Shared.Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ConnectGWFail); + return; + } + var status = setWritableValueResponAllData.setWritableValueResponData.Status; + //浠ュ悗琛ュ厖鎻愮ず + //0锛氶厤缃垚鍔燂紙鑻ラ厤缃垚鍔燂紝涓嬮潰鐨凙ttributeId瀛楁涓嶅瓨鍦級 + //34锛氫笉鏀寔璇ュ睘鎬� + //135锛氭棤鏁堢殑灞炴�у�� + //141锛氭棤鏁堢殑鏁版嵁绫诲瀷 + if (status == 0) + { + System.Console.WriteLine("璁剧疆鏂瑰悜鎴愬姛"); + rollershade.WcdCurrentDirection = direction; + } + else + { + CommonPage.Loading.Hide(); + Shared.Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FAIL); + } + }, 0, "", Language.StringByID(R.MyInternationalizationString.Confrim)); + } + catch(Exception ex) + { + System.Console.WriteLine($"璁剧疆鏂瑰悜琛岄敊璇細{ex.Message}"); + } + finally + { + CommonPage.Loading.Hide(); + } + + }; + + } + + #endregion + + #region 鈼� 娣诲姞 銆愰檺浣嶃�戣____________________ + /// <summary> + /// 娣诲姞 銆愰檺浣嶃�戣 + /// </summary> + /// <param name="listview">Lisrview.</param> + private void AddDirectionLimitRow(VerticalScrolViewLayout listview) + { + if(rollershade.WcdType==0) + { + AddDirectionLimitRowJL(listview); + } + else if(rollershade.WcdType==4) + { + AddDirectionLimitRowKHL(listview); + } + + } + + /// <summary> + /// 娣诲姞 鍗峰笜銆愰檺浣嶃�戣 + /// </summary> + /// <param name="listview">Lisrview.</param> + private void AddDirectionLimitRowJL(VerticalScrolViewLayout listview) + { + var directionLimitRow = new RowLayoutControl(); + directionLimitRow.Height = ControlCommonResourse.ListViewRowHeight; + directionLimitRow.LineColor = ZigbeeColor.Current.GXCLineColor; + listview.AddChidren(directionLimitRow); + + var directionLimitBtn = directionLimitRow.frameTable.AddLeftCaption("", 900); + directionLimitBtn.TextID = R.MyInternationalizationString.Limit; + directionLimitRow.AddChidren(directionLimitBtn); + //鏂瑰悜涓庨檺浣嶈缃悜鍙崇殑鍥炬爣 + //鍚戝彸鐨勫浘鏍� + var btnDirectionRight = new Button() + { + X = directionLimitRow.Width - Application.GetRealWidth(150), + Height = Application.GetMinRealAverage(110), + Width = Application.GetMinRealAverage(110), + UnSelectedImagePath = "Item/Next.png", + SelectedImagePath = "Item/DownSelected.png", + Gravity = Gravity.CenterVertical + }; + //btnDirectionRight.UnSelectedImagePath = "Item/Next.png"; + //btnDirectionRight.SelectedImagePath = "Item/Down.png"; + directionLimitRow.AddChidren(btnDirectionRight); + + var startLimitRowView = new FrameLayout() + { + Y = ControlCommonResourse.ListViewRowHeight, + Height = ControlCommonResourse.ListViewRowHeight * 2, + BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, + Tag = "startEndLimitRowView" + }; + directionLimitRow.AddChidren(startLimitRowView); + + var startLine = new Button() + { + Height = 1, + BackgroundColor = ZigbeeColor.Current.GXCLineColor + }; + startLimitRowView.AddChidren(startLine); + + startBtn = new Button() + { + Height = Application.GetRealHeight(80), + X = Application.GetRealWidth(CommonPage.XLeft), + Width = Application.GetRealWidth(500), + TextColor = ZigbeeColor.Current.GXCTextBlueColor, + TextAlignment = TextAlignment.CenterLeft, + TextID = R.MyInternationalizationString.SetStartLimit, + Gravity=Gravity.CenterVertical + }; + startLimitRowView.AddChidren(startBtn); + startBtn.MouseUpEventHandler += (sender, e) => + { + rollershade.WcdGoToLiftValue(0); + }; + + var setStart = new Button() + { + Height = Application.GetRealHeight(80), + X = Application.GetRealWidth(CommonPage.AppRealWidth-200-100), + Width = Application.GetRealWidth(200), + TextColor = ZigbeeColor.Current.GXCTextBlueColor, + TextAlignment = TextAlignment.CenterRight, + TextID = R.MyInternationalizationString.Confrim, + Gravity = Gravity.CenterVertical + }; + startLimitRowView.AddChidren(setStart); + setStart.MouseUpEventHandler += async (sender, e) => + { + var status = await SetLimitAsync(Rollershade.CurtainPrivateInstalledLimi.UpLimit, rollershade); + if (status == 0) + { + System.Console.WriteLine("涓嬭绋嬭缃垚鍔�"); + this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.Success)); + } + else if (status == -1) + { + CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ConnectGWFail); + } + else + { + CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FAIL); + } + }; + + var endLimitRowView = new FrameLayout() + { + Y = startLimitRowView.Bottom, + Height = ControlCommonResourse.ListViewRowHeight * 2, + BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, + Tag = "startEndLimitRowView" + }; + directionLimitRow.AddChidren(endLimitRowView); + + var endLine = new Button() + { + Height = 1, + BackgroundColor = ZigbeeColor.Current.GXCLineColor + }; + endLimitRowView.AddChidren(endLine); + + endBtn = new Button() + { + Height = Application.GetRealHeight(80), + X = Application.GetRealWidth(CommonPage.XLeft), + Width = Application.GetRealWidth(500), + TextColor = ZigbeeColor.Current.GXCTextBlueColor, + TextAlignment = TextAlignment.CenterLeft, + TextID = R.MyInternationalizationString.SetEndLimit, + Gravity = Gravity.CenterVertical + }; + endLimitRowView.AddChidren(endBtn); + endBtn.MouseUpEventHandler+=(sender, e) => + { + rollershade.WcdGoToLiftValue(100); + }; + + var setEnd = new Button() + { + Height = Application.GetRealHeight(80), + X = Application.GetRealWidth(CommonPage.AppRealWidth - 200 - 100), + Width = Application.GetRealWidth(200), + TextColor = ZigbeeColor.Current.GXCTextBlueColor, + TextAlignment = TextAlignment.CenterRight, + TextID = R.MyInternationalizationString.Confrim, + Gravity = Gravity.CenterVertical + }; + endLimitRowView.AddChidren(setEnd); + setEnd.MouseUpEventHandler += async (sender, e) => + { + var status = await SetLimitAsync(Rollershade.CurtainPrivateInstalledLimi.DownLimit, rollershade); + if (status == 0) + { + System.Console.WriteLine("涓嬭绋嬭缃垚鍔�"); + this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.Success)); + } + else if (status == -1) + { + CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ConnectGWFail); + } + else + { + CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FAIL); + } + }; + + void limit_MouseUpEvnet(object sender, MouseEventArgs mouseEventArgs) + { + btnDirectionRight.IsSelected = !btnDirectionRight.IsSelected; + if (btnDirectionRight.IsSelected) + { + directionLimitRow.Height = ControlCommonResourse.ListViewRowHeight * 5; + } + else + { + directionLimitRow.Height = ControlCommonResourse.ListViewRowHeight; + } + } + btnDirectionRight.MouseUpEventHandler += limit_MouseUpEvnet; + directionLimitBtn.MouseUpEventHandler += limit_MouseUpEvnet; + directionLimitRow.MouseUpEventHandler += limit_MouseUpEvnet; + } + + /// <summary> + /// 娣诲姞 寮�鍚堝笜銆愰檺浣嶃�戣 + /// </summary> + /// <param name="listview">Lisrview.</param> + private void AddDirectionLimitRowKHL(VerticalScrolViewLayout listview) + { + var directionLimitRow = new RowLayoutControl(); + directionLimitRow.Height = ControlCommonResourse.ListViewRowHeight; + directionLimitRow.LineColor = ZigbeeColor.Current.GXCLineColor; + listview.AddChidren(directionLimitRow); + + var directionLimitBtn = directionLimitRow.frameTable.AddLeftCaption("", 900); + directionLimitBtn.TextID = R.MyInternationalizationString.Limit; + directionLimitRow.AddChidren(directionLimitBtn); + //鏂瑰悜涓庨檺浣嶈缃悜鍙崇殑鍥炬爣 + //鍚戝彸鐨勫浘鏍� + var btnDirectionRight = new Button() + { + X = directionLimitRow.Width - Application.GetRealWidth(150), + Height = Application.GetMinRealAverage(110), + Width = Application.GetMinRealAverage(110), + UnSelectedImagePath = "Item/Next.png", + SelectedImagePath = "Item/DownSelected.png", + Gravity = Gravity.CenterVertical + }; + //btnDirectionRight.UnSelectedImagePath = "Item/Next.png"; + //btnDirectionRight.SelectedImagePath = "Item/Down.png"; + directionLimitRow.AddChidren(btnDirectionRight); + + var startLimitRowView = new FrameLayout() + { + Y = ControlCommonResourse.ListViewRowHeight, + Height = ControlCommonResourse.ListViewRowHeight * 2, + BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, + Tag = "startEndLimitRowView" + }; + directionLimitRow.AddChidren(startLimitRowView); + + var startLine = new Button() + { + Height = 1, + BackgroundColor = ZigbeeColor.Current.GXCLineColor + }; + startLimitRowView.AddChidren(startLine); + + startSeekBar = new HorizontalSeekBar() + { + Height = Application.GetRealHeight(80), + Width = Application.GetRealWidth(750), + Gravity = Gravity.Center, + ThumbColor = ZigbeeColor.Current.GXCButtonBlueColor, + BackgroundColor = ZigbeeColor.Current.GXCSliderUnSelectedColor, + ProgressColor = ZigbeeColor.Current.GXCButtonBlueColor, + Max = 100, + Progress = 0 + }; + startLimitRowView.AddChidren(startSeekBar); + + startBtn = new Button() + { + Y = Application.GetRealHeight(30), + Height = Application.GetRealHeight(80), + X = Application.GetRealWidth(CommonPage.XLeft), + Width = Application.GetRealWidth(500), + TextColor = ZigbeeColor.Current.GXCTextBlackColor, + TextAlignment = TextAlignment.CenterLeft, + Text = $"{Language.StringByID(R.MyInternationalizationString.SetStartLimit)} : {startSeekBar.Progress}%" + }; + startLimitRowView.AddChidren(startBtn); + + var endLimitRowView = new FrameLayout() + { + Y = startLimitRowView.Bottom, + Height = ControlCommonResourse.ListViewRowHeight * 2, + BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, + Tag = "startEndLimitRowView" + }; + directionLimitRow.AddChidren(endLimitRowView); + + var endLine = new Button() + { + Height = 1, + BackgroundColor = ZigbeeColor.Current.GXCLineColor + }; + endLimitRowView.AddChidren(endLine); + + endSeekBar = new HorizontalSeekBar() + { + Y = endLine.Bottom, + Height = Application.GetRealHeight(80), + BackgroundColor = ZigbeeColor.Current.GXCSliderUnSelectedColor, + Width = Application.GetRealWidth(750), + Gravity = Gravity.Center, + ThumbColor = ZigbeeColor.Current.GXCButtonBlueColor, + ProgressColor = ZigbeeColor.Current.GXCButtonBlueColor, + Max = 100, + Progress = 100 + }; + endLimitRowView.AddChidren(endSeekBar); + endBtn = new Button() + { + Y = Application.GetRealHeight(30), + Height = Application.GetRealHeight(80), + X = Application.GetRealWidth(CommonPage.XLeft), + Width = Application.GetRealWidth(500), + TextColor = ZigbeeColor.Current.GXCTextBlackColor, + TextAlignment = TextAlignment.CenterLeft, + Text = $"{Language.StringByID(R.MyInternationalizationString.SetEndLimit)} : {endSeekBar.Progress}%" + }; + endLimitRowView.AddChidren(endBtn); + + bool isStartSendDelayFrist = false; + bool isEndSendDelayFrist = false; + + DateTime lastStartSendDelayTime = DateTime.Now; + DateTime lastEndSendDelayTime = DateTime.Now; + + startSeekBar.ProgressChanged += async (sender1, e1) => + { + canSetStartLimit = false; + startBtn.Text = $"{Language.StringByID(R.MyInternationalizationString.SetStartLimit)} : {startSeekBar.Progress}%"; + if (isStartSendDelayFrist == false) + { + isStartSendDelayFrist = true; + //鍏堝彂閫佸垹闄ら檺浣嶇偣鍛戒护 + var t = await DeleteUpLimitAsync(rollershade); + endBtn.Text = $"{Language.StringByID(R.MyInternationalizationString.SetEndLimit)} : {endSeekBar.Progress}%"; + rollershade.WcdGoToTiltValue(startSeekBar.Progress); + lastStartSendDelayTime = DateTime.Now; + } + else + { + if ((DateTime.Now - lastStartSendDelayTime).TotalSeconds > sleepSpan) + { + rollershade.WcdGoToTiltValue(startSeekBar.Progress); + lastStartSendDelayTime = DateTime.Now; + } + } + }; + startSeekBar.MouseUpEventHandler += (sender1, e1) => + { + isStartSendDelayFrist = false; + canSetStartLimit = true; + hadReceivedStartEndLimitCode = false; + rollershade.WcdGoToTiltValue(startSeekBar.Progress); + lastStartSendDelayTime = DateTime.Now; + CommonPage.Loading.Start(Language.StringByID(R.MyInternationalizationString.PleaseWaitWhileTheGuidewayIsMoving)); + DeviceDelayAction(rollershade, (hadReceived) => + { + Application.RunOnMainThread(() => + { + if (hadReceived == false) + { + this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.FailedPleaseTryAgain)); + } + else + { + //var tip = new TipViewControl(Language.StringByID(R.MyInternationalizationString.Success)); + //tip.ShowView(); + } + CommonPage.Loading.Hide(); + }); + }, 5); + }; + + endSeekBar.ProgressChanged += async (sender1, e1) => + { + canSetEndLimit = false; + endBtn.Text = $"{Language.StringByID(R.MyInternationalizationString.SetEndLimit)} : {endSeekBar.Progress}%"; + if (isEndSendDelayFrist == false) + { + isEndSendDelayFrist = true; + //鍏堝彂閫佸垹闄ら檺浣嶇偣鍛戒护 + await DeleteDownLimintAsync(rollershade); + rollershade.WcdGoToTiltValue(endSeekBar.Progress); + lastEndSendDelayTime = DateTime.Now; + } + else + { + if ((DateTime.Now - lastEndSendDelayTime).TotalSeconds > sleepSpan) + { + rollershade.WcdGoToTiltValue(endSeekBar.Progress); + lastEndSendDelayTime = DateTime.Now; + } + } + }; + endSeekBar.MouseUpEventHandler += (sender1, e1) => + { + isEndSendDelayFrist = false; + hadReceivedStartEndLimitCode = false; + canSetEndLimit = true; + rollershade.WcdGoToTiltValue(endSeekBar.Progress); + lastEndSendDelayTime = DateTime.Now; + CommonPage.Loading.Start(Language.StringByID(R.MyInternationalizationString.PleaseWaitWhileTheGuidewayIsMoving)); + DeviceDelayAction(rollershade, (hadReceived) => + { + Application.RunOnMainThread(() => + { + if (hadReceived == false) + { + this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.FailedPleaseTryAgain)); + } + else + { + //var tip = new TipViewControl(Language.StringByID(R.MyInternationalizationString.Success)); + //tip.ShowView(); + } + CommonPage.Loading.Hide(); + }); + }, 5); + + }; + + void limit_MouseUpEvnet(object sender, MouseEventArgs mouseEventArgs) + { + btnDirectionRight.IsSelected = !btnDirectionRight.IsSelected; + if (btnDirectionRight.IsSelected) + { + directionLimitRow.Height = ControlCommonResourse.ListViewRowHeight * 5; + } + else + { + directionLimitRow.Height = ControlCommonResourse.ListViewRowHeight; + } + } + btnDirectionRight.MouseUpEventHandler += limit_MouseUpEvnet; + directionLimitBtn.MouseUpEventHandler += limit_MouseUpEvnet; + directionLimitRow.MouseUpEventHandler += limit_MouseUpEvnet; + } + + #endregion + + #region 鈼� 娣诲姞 銆愭仮澶嶈绋嬭缃�戣______________ + /// <summary> + /// 娣诲姞 銆愭仮澶嶈绋嬭缃�戣 + /// </summary> + /// <param name="listview">Lisrview.</param> + private void AddRestoreTravelSettingsRow(VerticalScrolViewLayout listview) + { + var RestoreTravelSettingsRow = new RowLayoutControl(); + listview.AddChidren(RestoreTravelSettingsRow); + + var RestoreTravelSettingsRowBtn = RestoreTravelSettingsRow.frameTable.AddLeftCaption("", 900); + RestoreTravelSettingsRowBtn.TextID = R.MyInternationalizationString.RestoreTravelSettings; + RestoreTravelSettingsRow.AddChidren(RestoreTravelSettingsRowBtn); + RestoreTravelSettingsRow.frameTable.ButtonClickEvent += (sender, e) => + { + try + { + CommonPage.Loading.Start(); + System.Console.WriteLine("鎭㈠闄愪綅"); + var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.IsCancelRestoreTravelSettings), Language.StringByID(R.MyInternationalizationString.Cancel), Language.StringByID(R.MyInternationalizationString.Confrim)); + alert.Show(); + alert.ResultEventHandler += async (alertSender, alertE) => + { + if (alertE) + { + var setWritableValueResponAllData = await rollershade.RestoreCurtainLimitAsync(); + if(setWritableValueResponAllData==null || setWritableValueResponAllData.setWritableValueResponData==null) + { + CommonPage.Loading.Hide(); + CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FAIL); + return; + } + var status = setWritableValueResponAllData.setWritableValueResponData.Status; + //浠ュ悗琛ュ厖鎻愮ず + //0锛氶厤缃垚鍔燂紙鑻ラ厤缃垚鍔燂紝涓嬮潰鐨凙ttributeId瀛楁涓嶅瓨鍦級 + //34锛氫笉鏀寔璇ュ睘鎬� + //135锛氭棤鏁堢殑灞炴�у�� + //141锛氭棤鏁堢殑鏁版嵁绫诲瀷 + if (status == 0) + { + //鎭㈠琛岀▼鎴愬姛鍚庢墜鍔ㄥ幓璇诲彇鐘舵�� + InitReadStatu(); + System.Console.WriteLine("鎭㈠琛岀▼璁剧疆鎴愬姛"); + this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.Success)); + + } + else + { + CommonPage.Loading.Hide(); + CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FAIL); + } + } + }; + } + catch(Exception ex) + { + System.Console.WriteLine($"鎭㈠琛岀▼璁剧疆澶辫触{ex.Message}"); + } + finally + { + CommonPage.Loading.Hide(); + } + }; + } + + #endregion + + #region 鈼� 璁惧寤舵椂鍥炶皟_______________________ + /// <summary> + /// 璁惧寤舵椂鍥炶皟 + /// </summary> + /// <param name="commonDevice">Common device.</param> + /// <param name="action">Action.</param> + /// <param name="delayTime">寤舵椂鎵ц鏃堕棿锛岄粯璁�10绉�</param> + public void DeviceDelayAction(CommonDevice commonDevice,Action<bool> action,int delayTime=10) + { + var threadName = commonDevice.GetHashCode().ToString(); + var tt = threads.Find((obj) => obj.Name == threadName); + if (threads.Find((obj) => obj.Name==threadName)==null) + { + var thread = new System.Threading.Thread(() => + { + var dateTime = DateTime.Now; + while ((DateTime.Now - dateTime).TotalSeconds < delayTime) + { + System.Threading.Thread.Sleep(100); + } + lock (threads) + { + threads.RemoveAll((obj) => obj.Name == threadName); + } + action?.Invoke(hadReceivedStartEndLimitCode); + }) + { IsBackground = true, Name = threadName }; + lock (threads) + { + threads.Add(thread); + } + thread.Start(); + } + else + { + System.Console.WriteLine("dddd"); + } + } + + #endregion + + #region 鈼� 璁剧疆涓娿�佷笅闄愪綅______________________ + /// <summary> + /// 璁剧疆涓娿�佷笅闄愪綅 + /// <para>0 锛氭垚鍔�</para> + /// <para>-1 锛氬け璐�(缃戝叧涓嶅湪绾�)</para> + /// <para>34锛氫笉鏀寔璇ュ睘鎬�</para> + /// <para>135锛氭棤鏁堢殑灞炴�у��</para> + /// <para>141锛氭棤鏁堢殑鏁版嵁绫诲瀷</para> + /// </summary> + /// <returns>The limit async.</returns> + /// <param name="upOrDownLimit">涓婃垨鑰呬笅闄愪綅</param> + /// <param name="r">绐楀笜.</param> + private async System.Threading.Tasks.Task<int> SetLimitAsync(Rollershade.CurtainPrivateInstalledLimi upOrDownLimit, Rollershade r) + { + var setWritableValueResponAllData = await r.SetCurtainInstalledLimitAsync(upOrDownLimit); + if (setWritableValueResponAllData == null || setWritableValueResponAllData.setWritableValueResponData == null) + { + return -1; + } + return setWritableValueResponAllData.setWritableValueResponData.Status; + } + + #endregion + + #region 鈼� 鍒犻櫎闄愪綅鐐筥________________________ + /// <summary> + /// 鍒犻櫎涓婇檺浣嶇偣 + /// </summary> + /// <returns>The up limits async.</returns> + /// <param name="r">The red component.</param> + private async System.Threading.Tasks.Task<CommonDevice.SetWritableValueResponAllData> DeleteUpLimitAsync(Rollershade r) + { + return await r.DeleteCurtainLimitsAsync(Rollershade.LimiType.UpLimit); + } + + /// <summary> + /// 鍒犻櫎涓嬮檺浣嶇偣 + /// </summary> + /// <returns>The down limint async.</returns> + /// <param name="r">The red component.</param> + private async System.Threading.Tasks.Task<CommonDevice.SetWritableValueResponAllData> DeleteDownLimintAsync(Rollershade r) + { + return await r.DeleteCurtainLimitsAsync(Rollershade.LimiType.DownLimit); + } + + #endregion + + + } +} -- Gitblit v1.8.0