From d6fb0646531172f23648441c224cdcccd721b894 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期一, 14 十二月 2020 09:59:01 +0800 Subject: [PATCH] 请合并代码,完成晾衣架最终功能。 --- ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceColorTemperatureLightDetailCardForm.cs | 367 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 367 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceColorTemperatureLightDetailCardForm.cs b/ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceColorTemperatureLightDetailCardForm.cs new file mode 100755 index 0000000..f233a45 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceColorTemperatureLightDetailCardForm.cs @@ -0,0 +1,367 @@ +锘縰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> + /// 鑹叉俯鐏被鍨嬬殑娣卞害鍗$墖鐣岄潰 + /// </summary> + public class DeviceColorTemperatureLightDetailCardForm : DeviceDetailCardCommonForm + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 鐣岄潰涓婂彲浠ユ搷浣滅殑鎺т欢 + /// </summary> + private List<ButtonBase> listControl = new List<ButtonBase>(); + /// <summary> + /// MaxLevel + /// </summary> + private const int MaxLevel = 254; + /// <summary> + /// 褰╃伅鎺т欢 + /// </summary> + private WaveSeekBar waveSeekBar = null; + /// <summary> + /// 杩涘害鍊兼槸鍚﹀湪鏀瑰彉涓� + /// </summary> + private bool isProgressing = false; + /// <summary> + /// 鑳藉惁鍙戦�佽繘搴﹀�� + /// </summary> + private bool canSetProgressValue = true; + /// <summary> + /// 褰╃伅鏄惁鏄墦寮�鐘舵��(涓嶈兘鐢ㄦ帶浠剁殑Select鏉ュ垽鏂�,澶潙) + /// </summary> + private bool IsLightOpen = false; + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <summary> + /// 搴曞眰鍒濆鍖栦腑閮ㄦ帶浠跺畬鎴愪箣鍚� + /// </summary> + /// <param name="frameWhiteBack"></param> + public override void InitMiddleFrameAfter(FrameLayout frameWhiteBack) + { + //宸︽粦涓嶈兘 + this.ScrollEnabled = false; + //鍏堟竻绌� + this.listControl = new List<ButtonBase>(); + //璁剧疆鐘舵�佹枃瀛� + 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)); + } + + //褰╃伅鎺т欢 + this.waveSeekBar = new WaveSeekBar(); + waveSeekBar.Y = Application.GetRealHeight(233); + waveSeekBar.Width = this.GetPictrueRealSize(253); + waveSeekBar.Height = this.GetPictrueRealSize(516); + waveSeekBar.Gravity = Gravity.CenterHorizontal; + waveSeekBar.WavePadding = Application.GetRealWidth(8); + waveSeekBar.MaxValue = 100; + waveSeekBar.Progress = (int)(((ColorTemperatureLight)this.device).Level * 1.0 / MaxLevel * 100); + waveSeekBar.CornerRadius = Application.GetRealHeight(58); + waveSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarColor_Start, ZigbeeColor.Current.GXCWaveSeekBarColor_End); + frameWhiteBack.AddChidren(waveSeekBar); + + //寮�鍏� + var btnSwitch = new IconViewControl(81); + btnSwitch.UnSelectedImagePath = "Item/Switch.png"; + btnSwitch.SelectedImagePath = "Item/SwitchSelected.png"; + btnSwitch.Y = waveSeekBar.Bottom + Application.GetRealHeight(418); + btnSwitch.Gravity = Gravity.CenterHorizontal; + frameWhiteBack.AddChidren(btnSwitch); + listControl.Add(btnSwitch); + btnSwitch.ButtonClickEvent += (sender, e) => + { + //鍙戦�佸紑鍏冲懡浠� + this.SetSwitchCommand(!btnSwitch.IsSelected); + }; + + //璁剧疆鍒濆鐘舵�� + this.IsLightOpen = ((LightBase)this.device).OnOffStatus == 1; + this.canSetProgressValue = this.IsLightOpen; + if (IsLightOpen == true) + { + btnSwitch.IsSelected = true; + } + + //褰╃伅鎺т欢閲岄潰鐨勯偅涓樉绀虹櫨鍒嗘瘮鐨勬帶浠� + int progressY = waveSeekBar.Y - Application.GetMinReal(154); + var btnProgress = new NormalViewControl(Application.GetMinReal(135), Application.GetMinReal(104), false); + btnProgress.Y = progressY; + btnProgress.UnSelectedImagePath = "Item/ProgressBubbles.png"; + btnProgress.IsBold = true; + btnProgress.TextColor = UserCenterColor.Current.White; + btnProgress.Gravity = Gravity.CenterHorizontal; + btnProgress.TextAlignment = TextAlignment.Center; + frameWhiteBack.AddChidren(btnProgress); + btnProgress.Visible = false; + + //寮�濮嬫粦鍔ㄧ殑浜嬩欢 + waveSeekBar.OnStartTrackingTouchEvent += (sender, e) => + { + //杩涘害鍊煎紑濮嬪彉鏇� + this.isProgressing = true; + //鍙樻洿杩涘害鐧惧垎姣旂殑鏄剧ず + btnProgress.Y = progressY + waveSeekBar.NowProgressY; + btnProgress.Text = waveSeekBar.Progress + "%"; + waveSeekBar.IsProgressTextShow = false; + if (btnProgress.Visible == false) + { + btnProgress.Visible = true; + } + }; + + //缁撴潫婊戝姩鐨勪簨浠� + waveSeekBar.OnStopTrackingTouchEvent += (sender, e) => + { + //杩涘害鍊煎紑濮嬬粨鏉� + this.isProgressing = false; + btnProgress.Visible = false; + waveSeekBar.IsProgressTextShow = true; + }; + + //婊戝姩杩囩▼涓� + int oldProgressValue = waveSeekBar.Progress;//涔嬪墠鐨勫�� + int nowProgressValue = oldProgressValue;//鍙樻洿鐨勫�� + waveSeekBar.OnProgressChangedEvent += (sender, value) => + { + //鍙樻洿杩涘害鐧惧垎姣旂殑鏄剧ず + btnProgress.Y = progressY + waveSeekBar.NowProgressY; + btnProgress.Text = value + "%"; + if (Common.Config.Instance.Home.IsVirtually == false) + { + nowProgressValue = value; + } + else + { + //濡傛灉浣忓畢涓鸿櫄鎷熶綇瀹�,鐩存帴鏀圭紦瀛� + ((ColorTemperatureLight)this.device).Level = value * MaxLevel / 100; + //浜害 XX + this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + " " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device)); + } + }; + + //鑹叉俯 + var btnColor = new NormalViewControl(300, 50, true); + btnColor.X = Application.GetRealWidth(132); + btnColor.Y = Application.GetRealHeight(829); + btnColor.TextSize = 12; + btnColor.Text = Language.StringByID(R.MyInternationalizationString.uColorTemperature) + "锛�"; + btnColor.TextColor = UserCenterColor.Current.TextGrayColor3; + frameWhiteBack.AddChidren(btnColor); + //涓婇儴鏄剧ず鏂囨湰 + var btnColorView = new NormalViewControl(150, 60, true); + btnColorView.Y = btnColor.Bottom; + btnColorView.TextAlignment = TextAlignment.Center; + btnColorView.TextSize = 15; + btnColorView.Gravity = Gravity.CenterHorizontal; + btnColorView.TextColor = UserCenterColor.Current.TextGrayColor3; + frameWhiteBack.AddChidren(btnColorView); + //杩涘害鏉�(鑹叉俯鐨勮寖鍥存槸 3400~6000) + var seekBar1 = new SeekBarControl(683); + seekBar1.Y = btnColorView.Bottom; + seekBar1.MinValue = 34; + seekBar1.MaxValue = 60; + seekBar1.ProgressBarColor = 0xff707070; + seekBar1.SeekBarViewHeight = Application.GetRealHeight(19); + frameWhiteBack.AddChidren(seekBar1); + + int oldColorValue = 0; + int nowColorValue = 0; + seekBar1.ProgressChangedEvent += (div, value) => + { + //鏁版嵁鍙樻洿 + btnColorView.Text = value * 100 + "K"; + if (Common.Config.Instance.Home.IsVirtually == false) + { + nowColorValue = value; + } + }; + //璁剧疆鍒濆鍊� + int colorValue = ((ColorTemperatureLight)this.device).ColorTemperature; + if (colorValue == 0) { colorValue = 3400; } + seekBar1.Progress = colorValue / 100; + btnColorView.Text = colorValue + "K"; + + //寮�涓�涓嚎绋�,鐩戣鏄惁婊戝姩鐨勬粦鍔ㄦ潯,姣忕妫�娴嬩竴娆� + HdlThreadLogic.Current.RunThread(() => + { + while (this.Parent != null) + { + System.Threading.Thread.Sleep(1000); + //鑳藉鍙戦�� + if (this.canSetProgressValue == true) + { + //鍙戦�佷寒搴﹀�� + if (nowProgressValue != oldProgressValue) + { + oldProgressValue = nowProgressValue; + ((ColorTemperatureLight)this.device).SetLevel((int)(oldProgressValue * MaxLevel / 100.0)); + } + //鍙戦�佽壊娓╁�� + if (nowColorValue != oldColorValue) + { + oldColorValue = nowColorValue; + ((ColorTemperatureLight)this.device).SetColorTemperature(oldColorValue * 100); + } + } + } + //鐣岄潰鍏抽棴鏃� + if (nowProgressValue != oldProgressValue) + { + //鍙戦�佷寒搴﹀�� + ((ColorTemperatureLight)this.device).SetLevel((int)(nowProgressValue * MaxLevel / 100.0)); + } + if (nowColorValue != oldColorValue) + { + //鍙戦�佽壊娓╁�� + ((ColorTemperatureLight)this.device).SetColorTemperature(nowColorValue * 100); + } + }); + } + + #endregion + + #region 鈻� 鍙戦�佸紑鍏冲懡浠______________________ + + /// <summary> + /// 鍙戦�佸紑鍏冲懡浠� + /// </summary> + /// <param name="isOpen"></param> + private void SetSwitchCommand(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.canSetProgressValue = false; + + //妫�娴嬫槸鍚﹁幏鍙栫綉鍏冲弽棣堢殑缁撴灉,濡傛灉缃戝叧娌℃湁鍥炲,鍒欎細寮瑰嚭娑堟伅 + this.StartCheckResponeResult(this.listControl, (result) => + { + HdlThreadLogic.Current.RunMain(() => + { + bool statu = ((LightBase)this.device).OnOffStatus == 1; + //鎺ユ敹鍒扮綉鍏冲洖澶� + if (result == true) + { + //鍒锋柊寮�鍏崇姸鎬� + this.RefreshSwitchStatu(statu); + //鐘舵�佸彇鍙� + listControl[0].IsSelected = statu; + } + }); + }); + if (isOpen == true) + { + //鎵撳紑 + if (level == 0) + { + //濡傛灉褰撳墠鏄墦寮�鐘舵��,骞朵笖浜害涓�0鐨勮瘽,鍒欓渶瑕佸彉鎴�100%浜害 + this.device.GetType().InvokeMember("SetLevel", System.Reflection.BindingFlags.InvokeMethod, null, this.device, new object[] { 254 }); + } + else + { + this.device.SwitchControl(1); + } + } + else + { + //鍏抽棴 + this.device.SwitchControl(0); + } + } + + #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 (isOpen == true) + { + //浜害鏄繀椤昏鍒锋柊鐨� 浜害 XX + this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + " " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device)); + } + if (isOpen == false && this.IsLightOpen == true) + { + //鐘舵�佷笉涓�鏍�,鎵嶅彉鏇村瓧鏍�:鍏抽棴 + this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close)); + } + if (listControl[0].IsSelected != isOpen) + { + //寮�鍏崇姸鎬佸彉鏇� + listControl[0].IsSelected = isOpen; + } + if (this.isProgressing == false) + { + //褰撹繘搴﹀�煎湪鎵嬪姩鍙樻洿涓椂,涓嶆帴鏀舵帹閫� + waveSeekBar.Progress = (int)(((ColorTemperatureLight)this.device).Level * 1.0 / MaxLevel * 100); + } + + this.IsLightOpen = isOpen; + //鍥炲鐨勭粨鏋滆,澶勪簬鎵撳紑鐘舵�佹墠鑳藉彂閫� + this.canSetProgressValue = this.IsLightOpen; + } + + #endregion + } +} -- Gitblit v1.8.0