using 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 { /// /// 晾衣架界面 /// public class ClothesHangerPage : DeviceFunctionCardCommonForm { #region ■ 变量声明___________________________ /// /// 图标 /// private Button btnIcon = null; /// /// 上升 /// Button btnUp; /// /// 停止 /// Button btnStop; /// /// 下降 /// Button btnDown; /// /// 烘干控件 /// ClothesHangerControl hotDryView; /// /// 风干控件 /// ClothesHangerControl windDryView; /// /// 消毒控件 /// ClothesHangerControl disinfectView; /// /// 照明控件 /// ClothesHangerControl lightingView; #endregion #region ■ 初始化_____________________________ /// /// 初始化白色区域的内容 /// public override void InitFrameWhiteContent() { base.ShowColltionButton = false; base.SetTitleText(Language.StringByID(StringId.Electric)); //初始化第一个索引页的内容 this.InitFrameWhiteContent1(); //刷新当前设备的状态缓存 this.RefreshNowDeviceStatuMemory(this.device); //刷新界面状态 this.RefreshFormStatu(); //读取状态 new System.Threading.Thread(() => { Control.Ins.SendReadCommand(device); }) { IsBackground = true }.Start(); } /// /// 初始化第一个索引页的内容 /// 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); #endregion #region 菜单 var menu = new List() { FunctionAttributeKey.HotDry, FunctionAttributeKey.WindDry, FunctionAttributeKey.Disinfect, FunctionAttributeKey.OnOff }; int index = 0; List 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 eventHandler = (sender, e) => { device.SetAttrState(FunctionAttributeKey.HotDry, "true"); Dictionary d = new Dictionary(); d.Add(FunctionAttributeKey.HotDry, "true"); 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 eventHandler = (sender, e) => { device.SetAttrState(FunctionAttributeKey.WindDry, "true"); Dictionary d = new Dictionary(); d.Add(FunctionAttributeKey.WindDry, "true"); 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 eventHandler = (sender, e) => { device.SetAttrState(FunctionAttributeKey.Disinfect, "true"); Dictionary d = new Dictionary(); d.Add(FunctionAttributeKey.Disinfect, "true"); 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 eventHandler = (sender, e) => { string onoff = lightingView.Lighting ? "off" : "on"; device.SetAttrState(FunctionAttributeKey.OnOff, onoff); Dictionary d = new Dictionary(); d.Add(FunctionAttributeKey.OnOff, onoff); Control.Ins.SendWriteCommand(device, d); }; lightingView.SetThouchEvent(eventHandler); index++; } #endregion } #endregion #region ■ 设备状态反馈_______________________ /// /// 设备状态反馈 /// /// public override void DeviceStatuPush(Function i_LocalDevice) { //不是同一个东西 if (this.device.sid != i_LocalDevice.sid) { return; } //刷新当前设备的状态缓存 this.RefreshNowDeviceStatuMemory(i_LocalDevice); //刷新界面状态 this.RefreshFormStatu(); } #endregion #region ■ 发送各种命令_______________________ #endregion #region ■ 刷新界面状态_______________________ /// /// 刷新界面状态 /// private void RefreshFormStatu() { Application.RunOnMainThread(() => { btnIcon.IsSelected = true; #region 点亮文本 var hotDryTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.HotDry); if (hotDryTemp != null) { hotDryView.SetViewStatus(hotDryTemp.value == "true"); } var windDryTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.WindDry); if (windDryTemp != null) { windDryView.SetViewStatus(windDryTemp.value == "true"); } var disinfectTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.Disinfect); if (disinfectTemp != null) { disinfectView.SetViewStatus(disinfectTemp.value == "true"); } var lightTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.OnOff); if (lightTemp != null) { lightingView.SetViewStatus(lightTemp.value == "on"); } #endregion #region 修改时间 var hotDryTimeLeftTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.HotDryTimeLeft); if (hotDryTimeLeftTemp != null) { hotDryView.ChangeTime(hotDryTimeLeftTemp.value); } var windDryTimeLeftTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.WindDryTimeLeft); if (windDryTimeLeftTemp != null) { windDryView.ChangeTime(windDryTimeLeftTemp.value); } var disinfectTimeLeftTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.DisinfectTimeLeft); if (disinfectTimeLeftTemp != null) { disinfectView.ChangeTime(disinfectTimeLeftTemp.value); } #endregion }); } #endregion #region ■ 一般方法___________________________ /// /// 刷新当前设备的状态缓存 /// private void RefreshNowDeviceStatuMemory(Function i_LocalDevice) { foreach (var data in i_LocalDevice.status) { //开关 //if (data.key == "on_off") { this.weepRobotData.Cleaning = data.value.ToLower() == "on"; } } } #endregion } public class ClothesHangerControl : FrameLayout { private Button btnIcon; private Button btnTitle; private Button btnTime; /// /// 控件是否点亮 /// 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 = btnTitle.Bottom, Height = Application.GetRealHeight(32), Text = time, TextColor = 0x00000000, SelectedTextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel, }; this.AddChidren(btnTime); } /// /// 修改显示时间 /// /// public void ChangeTime (string newTime) { if(newTime == "0") { newTime = ""; } int time = 0; int.TryParse(newTime, out time); time = time * 60; if (countdownThread == null) { countdownThread = new System.Threading.Thread(() => { while(true) { if(time>1) { Application.RunOnMainThread(() => { btnTime.Text = new TimeSpan(0, 0, time).ToString(); }); System.Threading.Thread.Sleep(1000); time--; }else { Application.RunOnMainThread(() => { btnTime.Text = ""; }); } } }) { IsBackground = true }; countdownThread.Start(); } } public void SetViewStatus(bool state) { btnIcon.IsSelected = btnTitle.IsSelected = btnTime.IsSelected = Lighting = state; } public bool GetViewState() { return Lighting; } /// /// 设置点击事件 /// public void SetThouchEvent(EventHandler eventHandler) { btnIcon.MouseUpEventHandler = eventHandler; btnTime.MouseUpEventHandler = eventHandler; btnTitle.MouseUpEventHandler = eventHandler; } /// /// 倒计时线程 /// System.Threading.Thread countdownThread; } }