From 6fa9d69da922c8049f5acfcbb9ce9fd26811024c Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期四, 16 四月 2020 17:10:57 +0800 Subject: [PATCH] 请合并代码 --- ZigbeeApp/Shared/Phone/MainPage/Controls/SceneCardControl.cs | 390 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 390 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/MainPage/Controls/SceneCardControl.cs b/ZigbeeApp/Shared/Phone/MainPage/Controls/SceneCardControl.cs new file mode 100755 index 0000000..fbb0cd2 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/MainPage/Controls/SceneCardControl.cs @@ -0,0 +1,390 @@ +锘縰sing Shared.Phone.UserCenter; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shared.Phone.MainPage.Controls +{ + /// <summary> + /// 鍦烘櫙鍗$墖鎺т欢 + /// </summary> + public class SceneCardControl : FrameLayoutControl + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 鍗$墖闇�瑕佽绉婚櫎鐨勪簨浠� + /// </summary> + public Action CardNeedRemoveEvent = null; + /// <summary> + /// 鍦烘櫙鍥剧墖鎺т欢 + /// </summary> + private ImageView btnScenePic = null; + /// <summary> + /// 鍦烘櫙鑳屾櫙鍥炬帶浠� + /// </summary> + private PicViewControl btnSceneBackGroud = null; + /// <summary> + /// 鏃堕棿鍥炬爣鎺т欢 + /// </summary> + private IconViewControl btnTimeIcon = null; + /// <summary> + /// 寤舵椂鏃堕棿鏄剧ず鎺т欢 + /// </summary> + private NormalViewControl btnTimeView = null; + /// <summary> + /// 鍦烘櫙鍚嶅瓧鎺т欢 + /// </summary> + private NormalViewControl btnSceneName = null; + /// <summary> + /// 鍦烘櫙ID + /// </summary> + private int SceneId = 0; + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <summary> + /// 鍦烘櫙鍗$墖鎺т欢(瀹藉害:458 + 14 * 2 楂樺害:305 + 43) + /// </summary> + public SceneCardControl() + { + //鍥剧墖鐪熷疄瀹藉害+鍥剧墖鑷韩宸﹀彸绌虹櫧 + this.Width = HdlControlLogic.Current.GetPictrueRealSize(458 + 14 * 2); + //鍥剧墖楂樺害+闃村奖 + this.Height = HdlControlLogic.Current.GetPictrueRealSize(305 + 43); + //鍙栨秷鐐瑰嚮鐗规晥 + this.UseClickStatu = false; + + this.ButtonClickEvent += (sender, e) => + { + //璋冪敤鍦烘櫙 + this.SetSceneAction(); + }; + } + + /// <summary> + /// 鍒濆鍖栨帶浠� + /// </summary> + /// <param name="i_scene">鍦烘櫙瀵硅薄</param> + public void InitControl(Common.SceneUI i_scene) + { + this.SceneId = i_scene.Id; + string hourText = Language.StringByID(R.MyInternationalizationString.Hour); + string minuText = Language.StringByID(R.MyInternationalizationString.Minute); + string secondText = Language.StringByID(R.MyInternationalizationString.Second); + + //鍦烘櫙鍥剧墖鎺т欢 + this.btnScenePic = new ImageView(); + btnScenePic.X = HdlControlLogic.Current.GetPictrueRealSize(14); + btnScenePic.Width = HdlControlLogic.Current.GetPictrueRealSize(458); + btnScenePic.Height = HdlControlLogic.Current.GetPictrueRealSize(305); + btnScenePic.Radius = (uint)Application.GetRealHeight(17); + this.AddChidren(btnScenePic, ChidrenBindMode.NotBind); + + //鍦烘櫙鑳屾櫙鍥炬帶浠� + this.btnSceneBackGroud = new PicViewControl(this.Width, this.Height, false); + btnSceneBackGroud.UnSelectedImagePath = "Scene/Background.png"; + this.AddChidren(btnSceneBackGroud, ChidrenBindMode.BindEventOnly); + + //寤舵椂鏃堕棿鏄剧ず鎺т欢 + this.btnTimeView = new NormalViewControl(HdlControlLogic.Current.GetPictrueRealSize(280), HdlControlLogic.Current.GetPictrueRealSize(63), false); + btnTimeView.X = HdlControlLogic.Current.GetPictrueRealSize(37); + btnTimeView.Y = HdlControlLogic.Current.GetPictrueRealSize(10); + btnTimeView.TextColor = 0xffffb400; + btnTimeView.IsBold = true; + if (i_scene.SceneDelayTime > 0) + { + btnTimeView.Text= this.GetTimeString(i_scene.SceneDelayTime, hourText, minuText, secondText); + } + this.AddChidren(btnTimeView, ChidrenBindMode.BindEventOnly); + + //鏃堕棿鍥炬爣鎺т欢 + this.btnTimeIcon = new IconViewControl(63); + btnTimeIcon.X = HdlControlLogic.Current.GetPictrueRealSize(37); + btnTimeIcon.Y = HdlControlLogic.Current.GetPictrueRealSize(20); + btnTimeIcon.UnSelectedImagePath = "Item/Time.png"; + this.AddChidren(btnTimeIcon, ChidrenBindMode.NotBind); + if (i_scene.SceneDelayTime > 0) + { + btnTimeIcon.Visible = false; + } + btnTimeIcon.ButtonClickEvent += (sender, e) => + { + if (i_scene.RemainTime > 0) + { + //璇ュ満鏅鍦ㄥ欢鏃讹紝璇风◢鍚� + var msgContr = new ShowMsgControl(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.TheSceneIsDelaying)); + msgContr.Show(); + return; + } + var timeSelect = new Device.CommonForm.SelectTime(); + Common.CommonPage.Instance.AddChidren(timeSelect); + timeSelect.TempTime = i_scene.SceneDelayTime; + timeSelect.Init(); + timeSelect.TimeAction = (time) => + { + i_scene.SceneDelayTime = time; + + //鏃堕棿鍥炬爣涓嶆樉绀� + this.btnTimeIcon.Visible = false; + //鏄剧ず鍓╀綑鐨勬椂闂� + this.btnTimeView.Text = this.GetTimeString(time, hourText, minuText, secondText); + }; + }; + + //鏀惰棌鎺т欢 + var btnCollect = new IconViewControl(107); + btnCollect.X = HdlControlLogic.Current.GetPictrueRealSize(350); + btnCollect.Y = HdlControlLogic.Current.GetPictrueRealSize(12); + btnCollect.UnSelectedImagePath = "Item/Collection1.png"; + btnCollect.SelectedImagePath = "Item/CollectionSelected1.png"; + this.AddChidren(btnCollect, ChidrenBindMode.NotBind); + btnCollect.IsSelected = HdlRoomLogic.Current.IsCollectInRoom(i_scene); + btnCollect.ButtonClickEvent += (sender, e) => + { + //鐘舵�佸彇鍙� + btnCollect.IsSelected = !btnCollect.IsSelected; + if (btnCollect.IsSelected == false) + { + //鍙栨秷鏀惰棌 + HdlSceneLogic.Current.DeleteLoveScene(i_scene); + if (HdlRoomLogic.Current.CurrentRoom.IsLove == true) + { + //濡傛灉褰撳墠鎴块棿鏄垜鐨勫枩鐖辩殑璇�,鍥炶皟鍗$墖琚垹闄ょ殑浜嬩欢 + this.CardNeedRemoveEvent?.Invoke(); + } + } + else + { + //娣诲姞鏀惰棌 + HdlSceneLogic.Current.AddLoveScene(i_scene); + } + }; + + //鍦烘櫙鍚嶇О鎺т欢 + this.btnSceneName = new NormalViewControl(HdlControlLogic.Current.GetPictrueRealSize(280), HdlControlLogic.Current.GetPictrueRealSize(63), false); + btnSceneName.X = HdlControlLogic.Current.GetPictrueRealSize(37); + btnSceneName.Y = HdlControlLogic.Current.GetPictrueRealSize(236); + btnSceneName.IsBold = true; + btnSceneName.TextColor = UserCenterColor.Current.White; + this.AddChidren(btnSceneName, ChidrenBindMode.BindEventOnly); + + //鍒锋柊鎺т欢鐘舵�� + this.RefreshControlInfo(i_scene); + } + + #endregion + + #region 鈻� 璋冪敤鍦烘櫙___________________________ + + /// <summary> + /// 璋冪敤鍦烘櫙 + /// </summary> + private async void SetSceneAction() + { + //杩欎釜鍦烘櫙涓嶈鐨勬儏鍐靛簲璇ヤ笉鍙兘 + var scene = HdlSceneLogic.Current.GetSceneUIBySceneId(this.SceneId); + if (scene.SceneDelayTime <= 0 && scene.RemainTime <= 0) + { + //濡傛灉娌℃湁寤惰繜鐨勮瘽,鐩存帴寮�鍚疞oading鐗规晥 + this.StartLoadingApreal(); + } + //鎵ц璋冪敤鍦烘櫙 + var result = await HdlSceneLogic.Current.ControlScene(scene); + if (result == false) + { + return; + } + //淇敼鏃堕棿 + scene.RemainTime = scene.SceneDelayTime; + scene.SceneDelayTime = 0; + //寮�鍚欢鏃跺�掕鏃剁壒鏁� + this.StartRemainTimeApreal(scene); + } + + #endregion + + #region 鈻� 鍒锋柊鎺т欢鐘舵�乢______________________ + + /// <summary> + /// 鍒锋柊鎺т欢鐘舵�� + /// </summary> + /// <param name="i_scene">鍦烘櫙瀵硅薄</param> + public void RefreshControlInfo(Common.SceneUI i_scene) + { + //鍦烘櫙鍚嶇О蹇呴』鍒锋柊 + this.btnSceneName.Text = i_scene.Name; + //鍒锋柊鍥剧墖 + if (i_scene.IconPathType == 0) + { + //涓婚〉鐨勫満鏅崱鐗囩敤鐨勬槸鍙﹀鐨勫浘 + string newPath = i_scene.IconPath.Replace("SceneIcon", "SceneCardIcon"); + if (this.btnScenePic.ImagePath != newPath) + { + this.btnScenePic.ImagePath = newPath; + } + } + else + { + string fullPath = System.IO.Path.Combine(Common.Config.Instance.FullPath, i_scene.IconPath); + if (this.btnScenePic.ImagePath != fullPath) + { + this.btnScenePic.ImagePath = fullPath; + } + } + + //寮�鍚欢鏃跺�掕鏃剁壒鏁� + this.StartRemainTimeApreal(i_scene); + } + + #endregion + + #region 鈻� 寤舵椂鍊掕鏃剁壒鏁坃____________________ + + /// <summary> + /// 寮�鍚欢鏃跺�掕鏃剁壒鏁� + /// </summary> + /// <param name="i_scene"></param> + private void StartRemainTimeApreal(Common.SceneUI i_scene) + { + if (i_scene.RemainTime <= 0) + { + return; + } + int remainTine = i_scene.RemainTime; + string hourText = Language.StringByID(R.MyInternationalizationString.Hour); + string minuText = Language.StringByID(R.MyInternationalizationString.Minute); + string secondText = Language.StringByID(R.MyInternationalizationString.Second); + + //鏃堕棿鍥炬爣涓嶆樉绀� + this.btnTimeIcon.Visible = false; + //鏄剧ず鍓╀綑鐨勬椂闂� + this.btnTimeView.Text = this.GetTimeString(i_scene.RemainTime, hourText, minuText, secondText); + + //寮�鍚唴閮ㄥ欢鏃舵椂闂寸嚎绋�(鏃ㄥ湪鍏ㄩ儴鍦版柟鐨勫悓涓�鍦烘櫙鏃堕棿鍚屾) + HdlSceneLogic.Current.StartDelayTimeThread(i_scene); + + new System.Threading.Thread(() => + { + while (remainTine > 0 && this.Parent != null) + { + System.Threading.Thread.Sleep(1000); + Application.RunOnMainThread(() => + { + this.btnTimeView.Text = this.GetTimeString(remainTine, hourText, minuText, secondText); + }); + remainTine--; + } + Application.RunOnMainThread(() => + { + //鍊掕鏃剁粨鏉熸椂锛屾椂闂村浘鏍囨樉绀� + this.btnTimeIcon.Visible = true; + this.btnTimeView.Text = string.Empty; + //鐩存帴寮�鍚疞oading鐗规晥 + this.StartLoadingApreal(); + }); + }) + { IsBackground = true }.Start(); + } + + #endregion + + #region 鈻� Loading鐗规晥________________________ + + /// <summary> + /// 寮�鍚疞oading鐗规晥 + /// </summary> + private void StartLoadingApreal() + { + //寮勪釜閬僵閬綇 + var frameBack = new FrameLayout(); + frameBack.BackgroundImagePath = "Scene/SceneActionGroud.png"; + this.AddChidren(frameBack); + //鍐嶅姞涓浆鍦堢殑 + var loadContr = new MyProgressLoading(); + loadContr.LoadingBackgroundColor = UserCenterColor.Current.Transparent; + frameBack.AddChidren(loadContr); + loadContr.StartLoading(1000); + loadContr.DisponeEvent += () => + { + frameBack.RemoveFromParent(); + }; + } + + #endregion + + #region 鈻� 鎺т欢鎽ф瘉___________________________ + + /// <summary> + /// 鎺т欢鎽ф瘉 + /// </summary> + public override void RemoveFromParent() + { + this.CardNeedRemoveEvent = null; + + base.RemoveFromParent(); + } + + #endregion + + #region 鈻� 涓�鑸柟娉昣__________________________ + + /// <summary> + /// 鑾峰彇鏃堕棿鐨勭炕璇戞枃鏈� + /// </summary> + /// <param name="second"></param> + /// <param name="hourText">灏忔椂鐨勬枃鏈�</param> + /// <param name="minuText">鍒嗙殑鏂囨湰</param> + /// <param name="secondText">绉掔殑鏂囨湰</param> + /// <returns></returns> + private string GetTimeString(int second, string hourText, string minuText, string secondText) + { + string timeStr = string.Empty; + int hour = second / 3600; + int minu = second % 3600 / 60; + int sec = second % 60; + if (hour > 0) + { + timeStr += hour + hourText; + } + if (minu > 0) + { + timeStr += minu + minuText; + } + if (sec > 0) + { + timeStr += sec + secondText; + } + return timeStr; + } + + #endregion + + #region 鈻� 鑷畾涔夋帶浠禵________________________ + + /// <summary> + /// 鑷畾涔夋帶浠�(闇�瑕佺殑瀹冪Щ闄や簨浠�) + /// </summary> + private class MyProgressLoading : ProgressLoading + { + /// <summary> + /// 鎺т欢閿�姣佺殑浜嬩欢 + /// </summary> + public Action DisponeEvent = null; + /// <summary> + /// 鎺т欢閿�姣� + /// </summary> + public override void RemoveFromParent() + { + base.RemoveFromParent(); + + this.DisponeEvent?.Invoke(); + this.DisponeEvent = null; + } + } + + #endregion + } +} -- Gitblit v1.8.0