From f3e65daca7978b21b5888f49b1bf35e1a6e5d4fd Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 13 七月 2020 12:33:31 +0800 Subject: [PATCH] 新版本 --- ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceMiniLightDetailCardForm.cs | 513 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 513 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..a4001f1 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceMiniLightDetailCardForm.cs @@ -0,0 +1,513 @@ +锘縰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> + /// MaxLevel + /// </summary> + private const int MaxLevel = 254; + /// <summary> + /// 浜害杩涘害鍊兼槸鍚﹀湪鏀瑰彉涓� + /// </summary> + private bool isLightProgressing = false; + /// <summary> + /// 鑹叉俯杩涘害鍊兼槸鍚﹀湪鏀瑰彉涓� + /// </summary> + private bool isColorProgressing = false; + /// <summary> + /// 鑳藉惁鍙戦�佽繘搴﹀�� + /// </summary> + private bool canSetProgressValue = true; + /// <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 = (int)(((ColorTemperatureLight)this.device).Level * 1.0 / MaxLevel * 100); + 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(58); + seekBarColor.X = Application.GetRealWidth(266 - 60); + seekBarColor.Height = Application.GetRealHeight(144); + seekBarColor.SeekBarViewHeight = Application.GetRealHeight(20); + seekBarColor.SeekBarPadding = Application.GetRealWidth(60); + seekBarColor.IsProgressTextShow = true; + seekBarColor.ProgressBarColor = UserCenterColor.Current.Transparent; + seekBarColor.SeekBarBackgroundColor = UserCenterColor.Current.Transparent; + seekBarColor.ProgressTextSize = 14; + seekBarColor.ProgressTextColor = UserCenterColor.Current.TextGrayColor2; + seekBarColor.Gravity = Gravity.Frame; + seekBarColor.ProgressBarUnitSring = "K"; + seekBarColor.MinValue = 30; + seekBarColor.MaxValue = 60; + frameWhiteBack.AddChidren(seekBarColor); + //璁剧疆鍒濆鍊� + int colorValue = ((ColorTemperatureLight)this.device).ColorTemperature; + if (colorValue == 0) { colorValue = 3000; } + seekBarColor.Progress = colorValue / 100; + + //铚傞福鍣ㄥ紑鍏筹細 + 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"; + 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; + this.canSetProgressValue = btnMiniSwitch.IsSelected; + + //浜害寮�濮嬫粦鍔ㄧ殑浜嬩欢 + 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) + { + if (this.canSetProgressValue == true) + { + //鑳藉鍙戦�佽繘搴﹀�肩殑鏃跺��,鎵嶈褰� + nowLightValue = value; + } + } + else + { + //濡傛灉浣忓畢涓鸿櫄鎷熶綇瀹�,鐩存帴鏀圭紦瀛� + ((ColorTemperatureLight)this.device).Level = value * MaxLevel / 100; + //浜害 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) => + { + if (Common.Config.Instance.Home.IsVirtually == false) + { + if (this.canSetProgressValue == true) + { + //鑳藉鍙戦�佽繘搴﹀�肩殑鏃跺��,鎵嶈褰� + nowColorValue = value; + } + } + else + { + //濡傛灉浣忓畢涓鸿櫄鎷熶綇瀹�,鐩存帴鏀圭紦瀛� + ((ColorTemperatureLight)this.device).ColorTemperature = value * 100; + } + }; + + //寮�涓�涓嚎绋�,鐩戣鏄惁婊戝姩鐨勬粦鍔ㄦ潯,姣忕妫�娴嬩竴娆� + HdlThreadLogic.Current.RunThread(() => + { + while (this.Parent != null) + { + System.Threading.Thread.Sleep(1000); + //鍙戦�佷寒搴﹀�� + if (nowLightValue != oldLightValue) + { + oldLightValue = nowLightValue; + ((ColorTemperatureLight)this.device).SetLevel((int)(oldLightValue * MaxLevel / 100.0)); + } + //鍙戦�佽壊娓╁�� + if (nowColorValue != oldColorValue) + { + oldColorValue = nowColorValue; + int value = 1000000 / (oldColorValue * 100); + ((ColorTemperatureLight)this.device).SetColorTemperature(value); + } + } + if (this.canSetProgressValue == true) + { + //鐣岄潰鍏抽棴鏃� + if (nowLightValue != oldLightValue) + { + //鍙戦�佷寒搴﹀�� + ((ColorTemperatureLight)this.device).SetLevel((int)(nowLightValue * MaxLevel / 100.0)); + } + 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) + { + //濡傛灉浣忓畢鏄櫄鎷熶綇瀹� + if (Common.Config.Instance.Home.IsVirtually == true) + { + ((LightBase)this.device).OnOffStatus = isOpen == true ? 1 : 0; + //鍒锋柊寮�鍏崇姸鎬� + this.RefreshSwitchStatu(isOpen); + return; + } + + //褰撴寜涓嬪紑鍏虫寜閽椂,涓嶈兘鍐嶅彂閫佽繘搴﹀�� + this.canSetProgressValue = false; + + //妫�娴嬫槸鍚﹁幏鍙栫綉鍏冲弽棣堢殑缁撴灉,濡傛灉缃戝叧娌℃湁鍥炲,鍒欎細寮瑰嚭娑堟伅 + 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); + if (statu == true) + { + //褰撴槸鎵撳紑鐘舵�佹椂,缃戝叧璇村畠浼氶粯璁ゆ妸浜害鍙樻垚100% + //浠ラ槻涓囦竴,杩欓噷鍐嶆璇诲彇涓�涓� + ((ColorTemperatureLight)device).ReadLevel(); + } + } + }); + }); + + this.sendDiv = 1; + if (isOpen == true) + { + //鎵撳紑 + 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) + { + //((LightBase)this.device).OnOffStatus = isOpen == true ? 1 : 0; + ////鍒锋柊寮�鍏崇姸鎬� + //this.RefreshSwitchStatu(isOpen); + return; + } + + //妫�娴嬫槸鍚﹁幏鍙栫綉鍏冲弽棣堢殑缁撴灉,濡傛灉缃戝叧娌℃湁鍥炲,鍒欎細寮瑰嚭娑堟伅 + this.StartCheckResponeResult(new List<ButtonBase> { this.btnBuzzerSwitch.btnIcon }, (result) => + { + HdlThreadLogic.Current.RunMain(() => + { + //鎺ユ敹鍒扮綉鍏冲洖澶� + if (result == true) + { + this.btnBuzzerSwitch.IsSelected = isOpen; + //bool statu = ((LightBase)this.device).OnOffStatus == 1; + ////鍒锋柊寮�鍏崇姸鎬� + //this.RefreshSwitchStatu(statu); + } + }); + }); + //鍙戦�佸懡浠� + 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) + { + if (this.isColorProgressing == true) + { + //濡傛灉鏄壊娓╂粦鍔ㄧ殑璇�,涓嶉渶瑕佸埛鏂扮晫闈� + return; + } + if (isOpen == true) + { + //浜害鏄繀椤昏鍒锋柊鐨� 浜害 XX + this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + " " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device)); + if (this.isLightProgressing == false) + { + //褰撹繘搴﹀�煎湪鎵嬪姩鍙樻洿涓椂,涓嶆帴鏀舵帹閫� + seekBarLight.Progress = (int)(((ColorTemperatureLight)this.device).Level * 1.0 / MaxLevel * 100); + } + if (this.isColorProgressing == false) + { + //褰撹繘搴﹀�煎湪鎵嬪姩鍙樻洿涓椂,涓嶆帴鏀舵帹閫� + seekBarColor.Progress = (int)(((ColorTemperatureLight)this.device).ColorTemperature / 100); + } + this.btnMiniSwitch.IsSelected = true; + } + else + { + //鍙樻洿瀛楁牱:鍏抽棴 + this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close)); + this.btnMiniSwitch.IsSelected = false; + } + + //鍥炲鐨勭粨鏋滆,澶勪簬鎵撳紑鐘舵�佹墠鑳藉彂閫� + this.canSetProgressValue = isOpen; + } + + #endregion + + #region 鈻� 鐣岄潰鍏抽棴___________________________ + + /// <summary> + /// 鐣岄潰鍏抽棴 + /// </summary> + public override void CloseFormBefore() + { + base.CloseFormBefore(); + HdlGatewayReceiveLogic.Current.RemoveEvent("DeviceBuzzerDetailCardACK"); + } + + #endregion + } +} -- Gitblit v1.8.0