From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期二, 30 八月 2022 09:37:38 +0800 Subject: [PATCH] 合并了IOS的代码 --- ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceMiniLightDetailCardForm.cs | 522 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 522 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceMiniLightDetailCardForm.cs b/ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceMiniLightDetailCardForm.cs new file mode 100755 index 0000000..4c219f0 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceMiniLightDetailCardForm.cs @@ -0,0 +1,522 @@ +锘縰sing Shared.Common; +using Shared.Phone.UserCenter; +using System; +using System.Collections.Generic; +using System.Text; +using ZigBee.Device; + +namespace Shared.Phone.MainPage.ControlForm +{ + /// <summary> + /// mini澶滅伅鐨勬繁搴﹀崱鐗囩晫闈� + /// </summary> + public class DeviceMiniLightDetailCardForm : DeviceDetailCardCommonForm + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 铚傞福鍣ㄧ殑寮�鍏虫帶浠� + /// </summary> + private IconBigViewControl btnBuzzerSwitch = null; + /// <summary> + /// mini澶滅伅鐨勫紑鍏虫帶浠� + /// </summary> + private IconBigViewControl btnMiniSwitch = null; + /// <summary> + /// 浜害鐨勮繘搴︽潯鎺т欢 + /// </summary> + private SeekBarControl seekBarLight = null; + /// <summary> + /// 鑹叉俯鐨勮繘搴︽潯鎺т欢 + /// </summary> + private SeekBarControl seekBarColor = null; + /// <summary> + /// 浜害杩涘害鍊兼槸鍚﹀湪鏀瑰彉涓� + /// </summary> + private bool isLightProgressing = false; + /// <summary> + /// 鑹叉俯杩涘害鍊兼槸鍚﹀湪鏀瑰彉涓� + /// </summary> + private bool isColorProgressing = false; + /// <summary> + /// 1:鍙戦�佺殑鏄皬澶滅伅 2:鍙戦�佺殑鏄渹楦e櫒 + /// </summary> + private int sendDiv = 0; + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <summary> + /// 搴曞眰鍒濆鍖栦腑閮ㄦ帶浠跺畬鎴愪箣鍚� + /// </summary> + /// <param name="frameWhiteBack"></param> + public override void InitMiddleFrameAfter(FrameLayout frameWhiteBack) + { + //娣诲姞鎺ユ敹铚傞福鍣ˋck涓婚 + this.AddReceiveBuzzerAckEvent(); + + //宸︽粦涓嶈兘 + this.ScrollEnabled = false; + //璁剧疆鐘舵�佹枃瀛� + if (((LightBase)this.device).OnOffStatus == 1) + { + //浜害 XX + this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + " " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device)); + } + else + { + //鍏抽棴 + this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close)); + } + + //浜害 + var btnLightView = new NormalViewControl(300, 60, true); + btnLightView.Text = Language.StringByID(R.MyInternationalizationString.uBrightness) + ":"; + btnLightView.X = Application.GetRealWidth(43); + btnLightView.Y = Application.GetRealHeight(320); + frameWhiteBack.AddChidren(btnLightView); + //搴曠嚎 + var btnLightLine = new NormalViewControl(Application.GetRealWidth(841), ControlCommonResourse.BottomLineHeight, false); + btnLightLine.BackgroundColor = UserCenterColor.Current.ButtomLine; + btnLightLine.X = btnLightView.X; + btnLightLine.Y = btnLightView.Bottom + Application.GetRealHeight(37); + frameWhiteBack.AddChidren(btnLightLine); + //杩涘害鏉�(+60鐨勫亸绉婚噺) + this.seekBarLight = new SeekBarControl(611 + 120); + seekBarLight.Y = Application.GetRealHeight(280); + seekBarLight.X = Application.GetRealWidth(266 - 60); + seekBarLight.Height = Application.GetRealHeight(144); + seekBarLight.SeekBarViewHeight = Application.GetRealHeight(20); + seekBarLight.SeekBarPadding = Application.GetRealWidth(60); + seekBarLight.IsProgressTextShow = true; + seekBarLight.ProgressBarColor = 0xffff6c2c; + seekBarLight.ProgressTextSize = 14; + seekBarLight.ProgressTextColor = UserCenterColor.Current.TextGrayColor2; + seekBarLight.Gravity = Gravity.Frame; + seekBarLight.Progress = HdlDeviceCommonLogic.Current.CalculateLightLevelPersent(((ColorTemperatureLight)this.device).Level); + frameWhiteBack.AddChidren(seekBarLight); + + //鑹叉俯 + var btnColorView = new NormalViewControl(300, 60, true); + btnColorView.Text = Language.StringByID(R.MyInternationalizationString.uColorTemperature) + ":"; + btnColorView.X = Application.GetRealWidth(43); + btnColorView.Y = btnLightLine.Y + Application.GetRealHeight(107); + frameWhiteBack.AddChidren(btnColorView); + //搴曠嚎 + var btnColorLine = new NormalViewControl(Application.GetRealWidth(841), ControlCommonResourse.BottomLineHeight, false); + btnColorLine.BackgroundColor = UserCenterColor.Current.ButtomLine; + btnColorLine.X = btnColorView.X; + btnColorLine.Y = btnColorView.Bottom + Application.GetRealHeight(37); + frameWhiteBack.AddChidren(btnColorLine); + //鑹叉俯鐨勬笎鍙樿壊鑳屾櫙 + var btnColorBack = new PicViewControl(611, 20); + btnColorBack.UnSelectedImagePath = "Item/ColorTemperatureBar.png"; + btnColorBack.X = Application.GetRealWidth(266); + btnColorBack.Y = btnColorView.Y + btnColorView.Height / 2 - HdlControlLogic.Current.GetPictrueRealSize(20) / 2; + frameWhiteBack.AddChidren(btnColorBack); + //杩涘害鏉�(+60鐨勫亸绉婚噺,鑹叉俯鐨勮寖鍥存槸 3000~6000) + this.seekBarColor = new SeekBarControl(611 + 120); + seekBarColor.Y = btnLightLine.Bottom + Application.GetRealHeight(88); + seekBarColor.X = Application.GetRealWidth(266 - 60); + seekBarColor.SeekBarViewHeight = Application.GetRealHeight(20); + seekBarColor.SeekBarPadding = Application.GetRealWidth(60); + seekBarColor.ProgressBarColor = UserCenterColor.Current.Transparent; + seekBarColor.ProgressBarUnEnableColor = UserCenterColor.Current.Transparent; + seekBarColor.SeekBarBackgroundColor = UserCenterColor.Current.Transparent; + seekBarColor.ProgressTextSize = 14; + seekBarColor.ProgressTextColor = UserCenterColor.Current.TextGrayColor2; + seekBarColor.Gravity = Gravity.Frame; + seekBarColor.MinValue = 30; + seekBarColor.MaxValue = 60; + seekBarColor.ProgressChangeDelayTime = 0; + frameWhiteBack.AddChidren(seekBarColor); + //鏄剧ず鑷畾涔夋枃鏈� + seekBarColor.ShowCustomTextView(Application.GetRealWidth(200), 15, UserCenterColor.Current.TextGrayColor3); + //璁剧疆鍒濆鍊� + int colorValue = ((ColorTemperatureLight)this.device).ColorTemperature; + if (colorValue == 0) { colorValue = 3000; } + seekBarColor.Progress = colorValue / 100; + seekBarColor.SetCustomText(seekBarColor.Progress * 100 + "K"); + + //铚傞福鍣ㄥ紑鍏筹細 + var btnBuzzerView = new NormalViewControl(300, 60, true); + btnBuzzerView.Text = Language.StringByID(R.MyInternationalizationString.uBuzzerSwitch) + ":"; + btnBuzzerView.X = Application.GetRealWidth(43); + btnBuzzerView.Y = btnColorLine.Y + Application.GetRealHeight(107); + frameWhiteBack.AddChidren(btnBuzzerView); + //搴曠嚎 + var btnBuzzerLine = new NormalViewControl(Application.GetRealWidth(841), ControlCommonResourse.BottomLineHeight, false); + btnBuzzerLine.BackgroundColor = UserCenterColor.Current.ButtomLine; + btnBuzzerLine.X = btnBuzzerView.X; + btnBuzzerLine.Y = btnBuzzerView.Bottom + Application.GetRealHeight(37); + frameWhiteBack.AddChidren(btnBuzzerLine); + //寮�鍏� + this.btnBuzzerSwitch = new IconBigViewControl(81, 81); + btnBuzzerSwitch.UnSelectedImagePath = "Item/Switch.png"; + btnBuzzerSwitch.SelectedImagePath = "Item/SwitchSelected.png"; + btnBuzzerSwitch.IsSelected = ((ColorTemperatureLight)this.device).IsBuzzerRing; + frameWhiteBack.AddChidren(btnBuzzerSwitch); + btnBuzzerSwitch.InitControl(); + btnBuzzerSwitch.UseClickStatu = false; + btnBuzzerSwitch.X = Application.GetRealWidth(795) - btnBuzzerSwitch.XOffset; + btnBuzzerSwitch.Y = btnColorLine.Y + Application.GetRealHeight(98) - btnBuzzerSwitch.YOffset; + btnBuzzerSwitch.ButtonClickEvent += (sender, e) => + { + //鍙戦�佸紑鍏冲懡浠� + this.SetBuzzerSwitchCommand(!btnBuzzerSwitch.IsSelected); + }; + + //灏忓鐏紑鍏筹細 + var btnMiniView = new NormalViewControl(300, 60, true); + btnMiniView.Text = Language.StringByID(R.MyInternationalizationString.uMiniLightSwitch) + ":"; + btnMiniView.X = Application.GetRealWidth(43); + btnMiniView.Y = btnBuzzerLine.Y + Application.GetRealHeight(107); + frameWhiteBack.AddChidren(btnMiniView); + //搴曠嚎 + var btnMiniLine = new NormalViewControl(Application.GetRealWidth(841), ControlCommonResourse.BottomLineHeight, false); + btnMiniLine.BackgroundColor = UserCenterColor.Current.ButtomLine; + btnMiniLine.X = btnMiniView.X; + btnMiniLine.Y = btnMiniView.Bottom + Application.GetRealHeight(37); + frameWhiteBack.AddChidren(btnMiniLine); + //寮�鍏� + this.btnMiniSwitch = new IconBigViewControl(81, 81); + btnMiniSwitch.UnSelectedImagePath = "Item/Switch.png"; + btnMiniSwitch.SelectedImagePath = "Item/SwitchSelected.png"; + frameWhiteBack.AddChidren(btnMiniSwitch); + btnMiniSwitch.InitControl(); + btnMiniSwitch.UseClickStatu = false; + btnMiniSwitch.X = Application.GetRealWidth(795) - btnMiniSwitch.XOffset; + btnMiniSwitch.Y = btnBuzzerLine.Y + Application.GetRealHeight(98) - btnMiniSwitch.YOffset; + btnMiniSwitch.ButtonClickEvent += (sender, e) => + { + //鍙戦�佸紑鍏冲懡浠� + this.SetLightSwitchCommand(!btnMiniSwitch.IsSelected); + }; + btnMiniSwitch.IsSelected = ((LightBase)this.device).OnOffStatus == 1; + + //浜害寮�濮嬫粦鍔ㄧ殑浜嬩欢 + seekBarLight.OnStartTrackingTouchEvent += (sender, e) => + { + //杩涘害鍊煎紑濮嬪彉鏇� + this.isLightProgressing = true; + }; + + //浜害缁撴潫婊戝姩鐨勪簨浠� + seekBarLight.OnStopTrackingTouchEvent += (sender, e) => + { + //杩涘害鍊煎紑濮嬬粨鏉� + this.isLightProgressing = false; + }; + + //浜害婊戝姩杩囩▼涓� + int oldLightValue = seekBarLight.Progress;//涔嬪墠鐨勫�� + int nowLightValue = oldLightValue;//鍙樻洿鐨勫�� + seekBarLight.OnProgressChangedEvent += (sender, value) => + { + if (Common.Config.Instance.Home.IsVirtually == false) + { + //鑳藉鍙戦�佽繘搴﹀�肩殑鏃跺��,鎵嶈褰� + nowLightValue = value; + } + else + { + //濡傛灉浣忓畢涓鸿櫄鎷熶綇瀹�,鐩存帴鏀圭紦瀛� + ((ColorTemperatureLight)this.device).Level = HdlDeviceCommonLogic.Current.CalculateLightLevel(value); + //浜害 XX + this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + " " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device)); + } + }; + + + //鑹叉俯寮�濮嬫粦鍔ㄧ殑浜嬩欢 + seekBarColor.OnStartTrackingTouchEvent += (sender, e) => + { + //杩涘害鍊煎紑濮嬪彉鏇� + this.isColorProgressing = true; + }; + + //鑹叉俯缁撴潫婊戝姩鐨勪簨浠� + seekBarColor.OnStopTrackingTouchEvent += (sender, e) => + { + //杩涘害鍊煎紑濮嬬粨鏉� + this.isColorProgressing = false; + }; + + //鑹叉俯婊戝姩杩囩▼涓� + int oldColorValue = seekBarColor.Progress;//涔嬪墠鐨勫�� + int nowColorValue = oldColorValue;//鍙樻洿鐨勫�� + seekBarColor.OnProgressChangedEvent += (sender, value) => + { + //璁剧疆鑷畾涔夌殑鏂囨湰 + seekBarColor.SetCustomText(value * 100 + "K"); + if (Common.Config.Instance.Home.IsVirtually == false) + { + //鑳藉鍙戦�佽繘搴﹀�肩殑鏃跺��,鎵嶈褰� + nowColorValue = value; + } + else + { + //濡傛灉浣忓畢涓鸿櫄鎷熶綇瀹�,鐩存帴鏀圭紦瀛� + ((ColorTemperatureLight)this.device).ColorTemperature = value * 100; + } + }; + if (Config.Instance.Home.IsVirtually == true) + { + //铏氭嫙浣忓畢 + return; + } + + //寮�涓�涓嚎绋�,鐩戣鏄惁婊戝姩鐨勬粦鍔ㄦ潯,姣忕妫�娴嬩竴娆� + HdlThreadLogic.Current.RunThread(() => + { + while (this.Parent != null) + { + System.Threading.Thread.Sleep(1000); + //鍙戦�佷寒搴﹀�� + if (nowLightValue != oldLightValue) + { + oldLightValue = nowLightValue; + ((ColorTemperatureLight)this.device).SetLevel(HdlDeviceCommonLogic.Current.CalculateLightLevel(oldLightValue)); + } + //鍙戦�佽壊娓╁�� + if (nowColorValue != oldColorValue) + { + oldColorValue = nowColorValue; + int value = 1000000 / (oldColorValue * 100); + ((ColorTemperatureLight)this.device).SetColorTemperature(value); + } + } + //鐣岄潰鍏抽棴鏃� + if (nowLightValue != oldLightValue) + { + //鍙戦�佷寒搴﹀�� + ((ColorTemperatureLight)this.device).SetLevel(HdlDeviceCommonLogic.Current.CalculateLightLevel(nowLightValue)); + } + if (nowColorValue != oldColorValue) + { + //鍙戦�佽壊娓╁�� + int value = 1000000 / (nowColorValue * 100); + ((ColorTemperatureLight)this.device).SetColorTemperature(value); + } + }); + } + + #endregion + + #region 鈻� 鍙戦�佸鐏紑鍏冲懡浠__________________ + + /// <summary> + /// 鍙戦�佸鐏紑鍏冲懡浠� + /// </summary> + /// <param name="isOpen"></param> + private void SetLightSwitchCommand(bool isOpen) + { + //鑾峰彇褰撳墠浜害 + int level = Convert.ToInt32(this.device.GetType().InvokeMember("Level", System.Reflection.BindingFlags.GetField, null, this.device, null)); + //濡傛灉浣忓畢鏄櫄鎷熶綇瀹� + if (Common.Config.Instance.Home.IsVirtually == true) + { + ((LightBase)this.device).OnOffStatus = isOpen == true ? 1 : 0; + if (((LightBase)this.device).OnOffStatus == 1 && level == 0) + { + //濡傛灉褰撳墠鏄墦寮�鐘舵��,骞朵笖浜害涓�0鐨勮瘽,鍒欓渶瑕佸彉鎴�100%浜害 + this.device.GetType().InvokeMember("Level", System.Reflection.BindingFlags.SetField, null, this.device, new object[] { 100 }); + } + //鍒锋柊寮�鍏崇姸鎬� + this.RefreshSwitchStatu(isOpen); + return; + } + + //妫�娴嬫槸鍚﹁幏鍙栫綉鍏冲弽棣堢殑缁撴灉,濡傛灉缃戝叧娌℃湁鍥炲,鍒欎細寮瑰嚭娑堟伅 + this.StartCheckResponeResult(new List<ButtonBase> { this.btnMiniSwitch.btnIcon }, (result) => + { + HdlThreadLogic.Current.RunMain(() => + { + //鎺ユ敹鍒扮綉鍏冲洖澶� + if (result == true) + { + bool statu = ((LightBase)this.device).OnOffStatus == 1; + //鍒锋柊寮�鍏崇姸鎬� + this.RefreshSwitchStatu(statu); + } + }); + }); + + this.sendDiv = 1; + if (isOpen == true) + { + //鎵撳紑 + if (level == 0) + { + //濡傛灉褰撳墠鏄墦寮�鐘舵��,骞朵笖浜害涓�0鐨勮瘽,鍒欓渶瑕佸彉鎴�100%浜害 + this.device.GetType().InvokeMember("SetLevel", System.Reflection.BindingFlags.InvokeMethod, null, this.device, new object[] { 255 }); + } + else + { + this.device.SwitchControl(1); + } + } + else + { + //鍏抽棴 + this.device.SwitchControl(0); + } + } + + #endregion + + #region 鈻� 鍙戦�佽渹楦e櫒寮�鍏冲懡浠________________ + + /// <summary> + /// 鍙戦�佽渹楦e櫒寮�鍏冲懡浠� + /// </summary> + /// <param name="isOpen"></param> + private void SetBuzzerSwitchCommand(bool isOpen) + { + //濡傛灉浣忓畢鏄櫄鎷熶綇瀹� + if (Common.Config.Instance.Home.IsVirtually == true) + { + ((ColorTemperatureLight)this.device).IsBuzzerRing = isOpen; + //鍒锋柊寮�鍏崇姸鎬� + this.RefreshSwitchStatu(isOpen); + return; + } + + //妫�娴嬫槸鍚﹁幏鍙栫綉鍏冲弽棣堢殑缁撴灉,濡傛灉缃戝叧娌℃湁鍥炲,鍒欎細寮瑰嚭娑堟伅 + this.btnBuzzerSwitch.CanClick = false; + this.StartCheckResponeResult(new List<ButtonBase>(), (result) => + { + HdlThreadLogic.Current.RunMain(() => + { + //鎺ユ敹鍒扮綉鍏冲洖澶� + this.btnBuzzerSwitch.CanClick = true; + if (result == true) + { + this.btnBuzzerSwitch.IsSelected = isOpen; + } + }); + }); + //鍙戦�佸懡浠� + this.sendDiv = 2; + ((ColorTemperatureLight)this.device).SendBuzzerSwitchControl(isOpen); + } + + /// <summary> + /// 娣诲姞鎺ユ敹铚傞福鍣ˋck涓婚 + /// </summary> + private void AddReceiveBuzzerAckEvent() + { + //Ack涓婚涓婃姤 + string mainKeys = LocalDevice.Current.GetDeviceMainKeys(this.device); + HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceBuzzerDetailCardACK", ReceiveComandDiv.A鑺傜偣鎺у埗鍙嶉, (report) => + { + string mainKey2 = LocalDevice.Current.GetDeviceMainKeys(report); + if (mainKeys != mainKey2) + { + //涓嶆槸鍚屼竴涓笢瑗� + return; + } + //杩欓噷鍙鐞嗚渹楦e櫒鐨� + if (this.sendDiv == 2) + { + //缁撴灉宸茬粡鎺ユ敹鍒� + this.ResponeResult = 1; + } + }); + } + + #endregion + + #region 鈻� 鏄惁鑾峰彇缃戝叧鍙嶉鐨勭粨鏋淿____________ + + /// <summary> + /// 妫�娴嬬綉鍏崇殑鍙嶉缁撴灉(灞炴�т笂鎶ョ殑瀵硅薄锛歞evice.DeviceStatusReport) + /// </summary> + /// <param name="comandDiv">鍛戒护鍖哄垎</param> + /// <param name="report">涓婃姤鏁版嵁</param> + /// <returns></returns> + public override bool CheckResponeResultStatu(ReceiveComandDiv comandDiv, CommonDevice report) + { + if (comandDiv == ReceiveComandDiv.A璁惧灞炴�т笂鎶�) + { + HdlThreadLogic.Current.RunMain(() => + { + //鍒锋柊寮�鍏崇姸鎬� + this.RefreshSwitchStatu(((LightBase)this.device).OnOffStatus == 1); + }); + return true; + } + return false; + } + + #endregion + + #region 鈻� 鍒锋柊寮�鍏崇姸鎬乢______________________ + + /// <summary> + /// 鍒锋柊寮�鍏崇姸鎬� + /// </summary> + /// <param name="isOpen">鎵撳紑鐘舵��</param> + private void RefreshSwitchStatu(bool isOpen) + { + //鍒锋柊铚傞福鍣ㄥ紑鍏崇姸鎬� + bool isBuzzerRing = ((ColorTemperatureLight)this.device).IsBuzzerRing; + if (this.btnBuzzerSwitch.IsSelected != isBuzzerRing) + { + this.btnBuzzerSwitch.IsSelected = isBuzzerRing; + } + + if (isOpen == true) + { + //浜害鏄繀椤昏鍒锋柊鐨� 浜害 XX + this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + " " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device)); + if (this.btnMiniSwitch.IsSelected == false) + { + this.btnMiniSwitch.IsSelected = true; + } + } + else + { + if (this.btnMiniSwitch.IsSelected == true) + { + this.btnMiniSwitch.IsSelected = false; + //鍙樻洿瀛楁牱:鍏抽棴 + this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close)); + } + } + + if (this.isLightProgressing == false) + { + //褰撹繘搴﹀�煎湪鎵嬪姩鍙樻洿涓椂,涓嶆帴鏀舵帹閫� + int progress = HdlDeviceCommonLogic.Current.CalculateLightLevelPersent(((ColorTemperatureLight)this.device).Level); + if (seekBarLight.Progress != progress) + { + seekBarLight.Progress = progress; + } + } + if (this.isColorProgressing == false) + { + //褰撹繘搴﹀�煎湪鎵嬪姩鍙樻洿涓椂,涓嶆帴鏀舵帹閫� + seekBarColor.Progress = (int)(((ColorTemperatureLight)this.device).ColorTemperature / 100); + //璁剧疆鑷畾涔夌殑鏂囨湰 + seekBarColor.SetCustomText(seekBarColor.Progress * 100 + "K"); + } + } + + #endregion + + #region 鈻� 鐣岄潰鍏抽棴___________________________ + + /// <summary> + /// 鐣岄潰鍏抽棴 + /// </summary> + public override void CloseFormBefore() + { + base.CloseFormBefore(); + HdlGatewayReceiveLogic.Current.RemoveEvent("DeviceBuzzerDetailCardACK"); + } + + #endregion + } +} -- Gitblit v1.8.0