From d72ca686a3e262693f8a6e45e747e8e8da43335b Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期二, 06 七月 2021 09:39:03 +0800 Subject: [PATCH] 2021-07-06 1.更新 --- HDL_ON/UI/UI2/FuntionControlView/Electrical/ClothesHangerPage.cs | 552 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 546 insertions(+), 6 deletions(-) diff --git a/HDL_ON/UI/UI2/FuntionControlView/Electrical/ClothesHangerPage.cs b/HDL_ON/UI/UI2/FuntionControlView/Electrical/ClothesHangerPage.cs index 96b2b0f..0a3c074 100644 --- a/HDL_ON/UI/UI2/FuntionControlView/Electrical/ClothesHangerPage.cs +++ b/HDL_ON/UI/UI2/FuntionControlView/Electrical/ClothesHangerPage.cs @@ -1,21 +1,561 @@ -锘縰sing System; -using Shared; +锘縰sing Shared; +using HDL_ON.Stan; using HDL_ON.UI.CSS; +using HDL_ON.Entity; +using System.Collections.Generic; +using System; +using HDL_ON.DriverLayer; namespace HDL_ON.UI { /// <summary> /// 鏅捐。鏋剁晫闈� /// </summary> - public class ClothesHangerPage : FrameLayout + public class ClothesHangerPage : DeviceFunctionCardCommonForm { - public ClothesHangerPage() + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 鍥炬爣 + /// </summary> + private Button btnIcon = null; + /// <summary> + /// 涓婂崌 + /// </summary> + Button btnUp; + /// <summary> + /// 鍋滄 + /// </summary> + Button btnStop; + /// <summary> + /// 涓嬮檷 + /// </summary> + Button btnDown; + /// <summary> + /// 鐑樺共鎺т欢 + /// </summary> + ClothesHangerControl hotDryView; + /// <summary> + /// 椋庡共鎺т欢 + /// </summary> + ClothesHangerControl windDryView; + /// <summary> + /// 娑堟瘨鎺т欢 + /// </summary> + ClothesHangerControl disinfectView; + /// <summary> + /// 鐓ф槑鎺т欢 + /// </summary> + ClothesHangerControl lightingView; + + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <summary> + /// 鍒濆鍖栫櫧鑹插尯鍩熺殑鍐呭 + /// </summary> + public override void InitFrameWhiteContent() { + base.ShowColltionButton = false; + base.SetTitleText(Language.StringByID(StringId.Electric)); + + //鍒濆鍖栫涓�涓储寮曢〉鐨勫唴瀹� + this.InitFrameWhiteContent1(); + + //鍒锋柊鐣岄潰鐘舵�� + this.RefreshFormStatu(); + //璇诲彇鐘舵�� + new System.Threading.Thread(() => + { + Control.Ins.SendReadCommand(device); + }) + { IsBackground = true }.Start(); } - public void LoadPage() + /// <summary> + /// 鍒濆鍖栫涓�涓储寮曢〉鐨勫唴瀹� + /// </summary> + private void InitFrameWhiteContent1() { + btnIcon = new Button() + { + Gravity = Gravity.CenterHorizontal, + Y = Application.GetRealHeight(85), + Width = Application.GetRealWidth(195), + Height = Application.GetRealHeight(121), + UnSelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerBgIcon.png", + SelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerBgIconOn.png", + }; + FrameWhiteCentet1.AddChidren(btnIcon); + #region 涓婂崌 鍋滄 涓嬮檷 + btnUp = new Button() + { + X = Application.GetRealWidth(42), + Y = Application.GetRealHeight(236), + Width = Application.GetRealWidth(28), + Height = Application.GetRealWidth(28), + UnSelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerUpIcon.png", + SelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerUpIconOn.png", + }; + FrameWhiteCentet1.AddChidren(btnUp); + + btnStop = new Button() + { + Gravity = Gravity.CenterHorizontal, + Y = Application.GetRealHeight(236), + Width = Application.GetRealWidth(28), + Height = Application.GetRealWidth(28), + UnSelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerStopIcon.png", + SelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerStopIconOn.png", + }; + FrameWhiteCentet1.AddChidren(btnStop); + + btnDown = new Button() + { + X = Application.GetRealWidth(257), + Y = Application.GetRealHeight(236), + Width = Application.GetRealWidth(28), + Height = Application.GetRealWidth(28), + UnSelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerDownIcon.png", + SelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerDownIconOn.png", + }; + FrameWhiteCentet1.AddChidren(btnDown); + + #region 鎺у埗 + btnUp.MouseDownEventHandler = (sender, e) => { + btnUp.IsSelected = true; + }; + btnUp.MouseUpEventHandler = (sender, e) => { + new System.Threading.Thread(() => + { + System.Threading.Thread.Sleep(2000); + Application.RunOnMainThread(() => + { + btnUp.IsSelected = false; + }); + }) + { IsBackground = true }.Start(); + Dictionary<string, string> d = new Dictionary<string, string>(); + d.Add(FunctionAttributeKey.Position, "up"); + Control.Ins.SendWriteCommand(device, d); + }; + //---- + btnStop.MouseDownEventHandler = (sender, e) => { + btnStop.IsSelected = true; + }; + btnStop.MouseUpEventHandler = (sender, e) => { + new System.Threading.Thread(() => + { + System.Threading.Thread.Sleep(2000); + Application.RunOnMainThread(() => + { + btnStop.IsSelected = false; + }); + }) + { IsBackground = true }.Start(); + Dictionary<string, string> d = new Dictionary<string, string>(); + d.Add(FunctionAttributeKey.Position, "stop"); + Control.Ins.SendWriteCommand(device, d); + }; + //----- + btnDown.MouseDownEventHandler = (sender, e) => { + btnDown.IsSelected = true; + }; + btnDown.MouseUpEventHandler = (sender, e) => { + new System.Threading.Thread(() => + { + System.Threading.Thread.Sleep(2000); + Application.RunOnMainThread(() => + { + btnDown.IsSelected = false; + }); + }) + { IsBackground = true }.Start(); + Dictionary<string, string> d = new Dictionary<string, string>(); + d.Add(FunctionAttributeKey.Position, "down"); + Control.Ins.SendWriteCommand(device, d); + }; + #endregion + + #endregion + + #region 鑿滃崟 + var menu = new List<string>() { + FunctionAttributeKey.HotDry, + FunctionAttributeKey.WindDry, + FunctionAttributeKey.Disinfect, + FunctionAttributeKey.OnOff + }; + + int index = 0; + List<string> attrs = device.GetAttributes(); + + hotDryView = new ClothesHangerControl( + "FunctionIcon/Electrical/ClothesHanger/ClothesHangerHotDryIcon.png", + "FunctionIcon/Electrical/ClothesHanger/ClothesHangerHotDryIconOn.png", + Language.StringByID(StringId.HotDry), + device.GetAttrState(FunctionAttributeKey.HotDryTimeLeft)); + hotDryView.X = 0; + hotDryView.Y = Application.GetRealHeight(304); + hotDryView.Width = Application.GetRealWidth(96); + hotDryView.Height = Application.GetRealHeight(74);//28 29 14 3 + if (attrs.Contains(menu[0])) + { + FrameWhiteCentet1.AddChidren(hotDryView); + + EventHandler<MouseEventArgs> eventHandler = (sender, e) => + { + string onoff = hotDryView.Lighting ? "false" : "true"; + device.SetAttrState(FunctionAttributeKey.HotDry, onoff); + Dictionary<string, string> d = new Dictionary<string, string>(); + d.Add(FunctionAttributeKey.HotDry, onoff); + Control.Ins.SendWriteCommand(device, d); + }; + hotDryView.SetThouchEvent(eventHandler); + + index++; + } + + windDryView = new ClothesHangerControl( + "FunctionIcon/Electrical/ClothesHanger/ClothesHangerWindDryIcon.png", + "FunctionIcon/Electrical/ClothesHanger/ClothesHangerWindDryIconOn.png", + Language.StringByID(StringId.WindDry), + device.GetAttrState(FunctionAttributeKey.WindDryTimeLeft)); + windDryView.Y = Application.GetRealHeight(304); + windDryView.Width = Application.GetRealWidth(96); + windDryView.Height = Application.GetRealHeight(74); + if (attrs.Contains(menu[1])) + { + if (index == 1) + { + windDryView.Gravity = Gravity.CenterHorizontal; + } + FrameWhiteCentet1.AddChidren(windDryView); + + EventHandler<MouseEventArgs> eventHandler = (sender, e) => + { + string onoff = windDryView.Lighting ? "false" : "true"; + device.SetAttrState(FunctionAttributeKey.WindDry, onoff); + Dictionary<string, string> d = new Dictionary<string, string>(); + d.Add(FunctionAttributeKey.WindDry, onoff); + Control.Ins.SendWriteCommand(device, d); + }; + windDryView.SetThouchEvent(eventHandler); + + index++; + } + + + + disinfectView = new ClothesHangerControl( + "FunctionIcon/Electrical/ClothesHanger/ClothesHangerDisinfectIcon.png", + "FunctionIcon/Electrical/ClothesHanger/ClothesHangerDisinfectIconOn.png", + Language.StringByID(StringId.Disinfect), + device.GetAttrState(FunctionAttributeKey.DisinfectTimeLeft)); + disinfectView.Y = Application.GetRealHeight(304); + disinfectView.Width = Application.GetRealWidth(96); + disinfectView.Height = Application.GetRealHeight(74); + if (attrs.Contains(menu[2])) + { + if (index == 1) + { + disinfectView.Gravity = Gravity.CenterHorizontal; + } + else if (index == 2) + { + disinfectView.X = Application.GetRealWidth(266 - 33); + } + FrameWhiteCentet1.AddChidren(disinfectView); + + EventHandler<MouseEventArgs> eventHandler = (sender, e) => + { + string onoff = disinfectView.Lighting ? "false" : "true"; + device.SetAttrState(FunctionAttributeKey.Disinfect, onoff); + Dictionary<string, string> d = new Dictionary<string, string>(); + d.Add(FunctionAttributeKey.Disinfect, onoff); + Control.Ins.SendWriteCommand(device, d); + }; + disinfectView.SetThouchEvent(eventHandler); + + index++; + } + + lightingView = new ClothesHangerControl( + "FunctionIcon/Electrical/ClothesHanger/ClothesHangerLightIcon.png", + "FunctionIcon/Electrical/ClothesHanger/ClothesHangerLightIconOn.png", + Language.StringByID(StringId.Lighting), + ""); + lightingView.Width = Application.GetRealWidth(96); + lightingView.Height = Application.GetRealHeight(74); + if (attrs.Contains(menu[3])) + { + if (index > 2) + { + lightingView.Y = Application.GetRealHeight(409); + } + else + { + lightingView.Y = Application.GetRealHeight(304); + if (index == 1) + { + lightingView.Gravity = Gravity.CenterHorizontal; + } + else if (index == 2) + { + lightingView.X = Application.GetRealWidth(266 - 33); + } + } + FrameWhiteCentet1.AddChidren(lightingView); + + EventHandler<MouseEventArgs> eventHandler = (sender, e) => + { + string onoff = lightingView.Lighting ? "off" : "on"; + device.SetAttrState(FunctionAttributeKey.OnOff, onoff); + Dictionary<string, string> d = new Dictionary<string, string>(); + d.Add(FunctionAttributeKey.OnOff, onoff); + Control.Ins.SendWriteCommand(device, d); + }; + lightingView.SetThouchEvent(eventHandler); + + index++; + } + + #endregion + + + #region 鏃堕棿璁剧疆 + var timeSetView = new ClothesHangerControl( + "FunctionIcon/Electrical/ClothesHanger/ClothesHangerTimeIcon.png", + "FunctionIcon/Electrical/ClothesHanger/ClothesHangerTimeIconOn.png", + Language.StringByID(StringId.Time), + ""); + timeSetView.Width = Application.GetRealWidth(96); + timeSetView.Height = Application.GetRealHeight(74); + timeSetView.Y = Application.GetRealHeight(409); + timeSetView.X = Application.GetRealWidth(266 - 33); + + + EventHandler<MouseEventArgs> eventHandler_timeSetView = (sender, e) => + { + var setTimePage = new ClothesHangerSetTimePage(device); + MainPage.BasePageView.AddChidren(setTimePage); + setTimePage.LoadPage(); + MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; + }; + timeSetView.SetThouchEvent(eventHandler_timeSetView); + + FrameWhiteCentet1.AddChidren(timeSetView); + + #endregion } + #endregion + + #region 鈻� 璁惧鐘舵�佸弽棣坃______________________ + + /// <summary> + /// 璁惧鐘舵�佸弽棣� + /// </summary> + /// <param name="i_LocalDevice"></param> + public override void DeviceStatuPush(Function i_LocalDevice) + { + //涓嶆槸鍚屼竴涓笢瑗� + if (this.device.sid != i_LocalDevice.sid) { return; } + + //鍒锋柊鐣岄潰鐘舵�� + this.RefreshFormStatu(); + } + + #endregion + + #region 鈻� 鍙戦�佸悇绉嶅懡浠______________________ + + #endregion + + #region 鈻� 鍒锋柊鐣岄潰鐘舵�乢______________________ + + /// <summary> + /// 鍒锋柊鐣岄潰鐘舵�� + /// </summary> + private void RefreshFormStatu() + { + Application.RunOnMainThread(() => + { + btnIcon.IsSelected = true; + #region 鐐逛寒鏂囨湰 + var hotDryTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.HotDry); + if (hotDryTemp != null) + { + hotDryView.SetViewStatus(hotDryTemp.state == "true"); + } + var windDryTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.WindDry); + if (windDryTemp != null) + { + windDryView.SetViewStatus(windDryTemp.state == "true"); + } + var disinfectTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.Disinfect); + if (disinfectTemp != null) + { + disinfectView.SetViewStatus(disinfectTemp.state == "true"); + } + var lightTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.OnOff); + if (lightTemp != null) + { + lightingView.SetViewStatus(lightTemp.state == "on"); + } + MainPage.Log($"鏃堕棿鎴筹細{device.time_stamp} 鏃堕棿锛歿device.GeteTime()} 鐑樺共:{hotDryTemp.state} 椋庡共:{windDryTemp.state} 娑堟瘨:{disinfectTemp.state} 鐏厜鐘舵�侊細{lightTemp.state}"); + #endregion + + #region 淇敼鏃堕棿 + var hotDryTimeLeftTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.HotDryTimeLeft); + if (hotDryTimeLeftTemp != null) + { + hotDryView.ChangeTime(hotDryTimeLeftTemp.state); + } + var windDryTimeLeftTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.WindDryTimeLeft); + if (windDryTimeLeftTemp != null) + { + windDryView.ChangeTime(windDryTimeLeftTemp.state); + } + var disinfectTimeLeftTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.DisinfectTimeLeft); + if (disinfectTimeLeftTemp != null) + { + disinfectView.ChangeTime(disinfectTimeLeftTemp.state); + } + #endregion + + + }); + } + + #endregion + + #region 鈻� 涓�鑸柟娉昣__________________________ + + #endregion } -} + + public class ClothesHangerControl : FrameLayout + { + private Button btnIcon; + private Button btnTitle; + private Button btnTime; + /// <summary> + /// 鍊掕鏃舵椂闂� + /// </summary> + private int leftTime = 0; + /// <summary> + /// 鎺т欢鏄惁鐐逛寒 + /// </summary> + public bool Lighting = false; + + public ClothesHangerControl(string iconPath1, string iconPath2, string title, string time) + { + btnIcon = new Button() + { + Gravity = Gravity.CenterHorizontal, + Width = Application.GetRealWidth(28), + Height = Application.GetRealWidth(28), + UnSelectedImagePath = iconPath1, + SelectedImagePath = iconPath2, + }; + this.AddChidren(btnIcon); + + btnTitle = new Button() + { + Gravity = Gravity.Center, + Text = title, + Height = Application.GetRealHeight(42), + TextColor = CSS_Color.TextualColor, + SelectedTextColor = CSS_Color.MainColor, + TextSize = CSS_FontSize.PromptFontSize_FirstLevel, + }; + this.AddChidren(btnTitle); + + btnTime = new Button() + { + Gravity = Gravity.CenterHorizontal, + Y = Application.GetRealHeight(74-32), + Height = Application.GetRealHeight(32), + Text = time, + TextColor = 0x00000000, + SelectedTextColor = CSS_Color.MainColor, + TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel, + }; + this.AddChidren(btnTime); + } + /// <summary> + /// 淇敼鏄剧ず鏃堕棿 + /// </summary> + /// <param name="newTime"></param> + public void ChangeTime(string newTime) + { + int.TryParse(newTime, out leftTime); + if (leftTime > 0) + { + Application.RunOnMainThread(() => + { + btnTime.Text = new TimeSpan(0, leftTime, 0).ToString().Remove(5, 3); + }); + leftTime--; + } + else if (leftTime == 0) + { + Application.RunOnMainThread(() => + { + btnTime.Text = ""; + }); + } + if (countdownThread == null) + { + countdownThread = new System.Threading.Thread(() => + { + + while (true) + { + if (leftTime > 0) + { + Application.RunOnMainThread(() => + { + btnTime.Text = new TimeSpan(0, leftTime, 0).ToString().Remove(5,3) ; + }); + leftTime--; + } + else if(leftTime == 0) + { + Application.RunOnMainThread(() => + { + btnTime.Text = ""; + }); + } + System.Threading.Thread.Sleep(60000); + } + }) + { IsBackground = true }; + countdownThread.Start(); + } + } + + public void SetViewStatus(bool state) + { + btnIcon.IsSelected = btnTitle.IsSelected = btnTime.IsSelected = Lighting = state; + } + + /// <summary> + /// 璁剧疆鐐瑰嚮浜嬩欢 + /// </summary> + public void SetThouchEvent(EventHandler<MouseEventArgs> eventHandler) + { + btnIcon.MouseUpEventHandler = eventHandler; + btnTime.MouseUpEventHandler = eventHandler; + btnTitle.MouseUpEventHandler = eventHandler; + } + + /// <summary> + /// 鍊掕鏃剁嚎绋� + /// </summary> + System.Threading.Thread countdownThread; + } +} \ No newline at end of file -- Gitblit v1.8.0