using Shared.Common; using Shared.Phone.UserCenter; using System; using System.Collections.Generic; using System.Text; using ZigBee.Device; namespace Shared.Phone.MainPage.ControlForm { /// /// 晾衣架类型的深度卡片界面 /// public class DeviceAirerDetailCardForm : DeviceDetailCardCommonForm { #region ■ 变量声明___________________________ /// /// 当前晾衣架 /// Airer airer = null; /// /// 打开控件 /// private IconBigViewControl btnOpen = null; /// /// 停止控件 /// private IconBigViewControl btnStop = null; /// /// 关闭控件 /// private IconBigViewControl btnClose = null; /// /// 照明 /// private IconViewControl btnLight = null; /// /// 消毒 /// private IconViewControl btnDisinfect = null; /// /// 风干 /// private IconViewControl btnWind = null; /// /// 烘干 /// private IconViewControl btnDry = null; /// /// 开合帘控件 /// private CurtainSeekBar SeekBarOpenCurtain = null; /// /// 进度值是否在改变中 /// private bool isProgressing = false; /// /// 是否已经初始化了控件(因为底层有可能会刷新整个界面) /// private bool hadInitControl = false; /// /// 烘干时间 /// Button btnDryTimeText; /// /// 风干时间 /// Button btnWindTimeText; /// /// 消毒时间 /// Button btnDisinfectTimeText; /// /// 烘干文本时间处理 /// public Action actionDry = null; /// /// 风干文本时间处理 /// public Action actionWind = null; /// /// 消毒文本时间处理 /// public Action actionDisinfect = null; #endregion #region ■ 初始化_____________________________ /// /// 底层初始化中部控件完成之后 /// /// public override void InitMiddleFrameAfter(FrameLayout frameWhiteBack) { airer = this.device as Airer; //左滑不能 this.ScrollEnabled = false; //设置状态文字 this.SetStatuText(HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device)); var btnDoorLockPic = new Button() { Width = Application.GetMinReal(432), Height = Application.GetMinReal(302), Y = Application.GetRealHeight(228), UnSelectedImagePath = "Airer/DetailAirerPic.png", Gravity = Gravity.CenterHorizontal, }; frameWhiteBack.AddChidren(btnDoorLockPic); //打开控件 this.btnOpen = new IconBigViewControl(81, 81); btnOpen.btnIcon.UseClickStatu = true; frameWhiteBack.AddChidren(btnOpen); btnOpen.InitControl(); btnOpen.UnSelectedImagePath = "Airer/UpOffline.png"; btnOpen.SelectedImagePath = "Airer/Up.png"; btnOpen.X = Application.GetRealWidth(132) - btnOpen.XOffset; btnOpen.Y = Application.GetRealHeight(671); //停止控件 this.btnStop = new IconBigViewControl(81, 81); btnStop.btnIcon.UseClickStatu = true; btnStop.UnSelectedImagePath = "Airer/StopOffline.png"; btnStop.SelectedImagePath = "Airer/Stop.png"; frameWhiteBack.AddChidren(btnStop); btnStop.InitControl(); btnStop.X = Application.GetRealWidth(444) - btnStop.XOffset; btnStop.Y = btnOpen.Y; //关闭 this.btnClose = new IconBigViewControl(81, 81); btnClose.btnIcon.UseClickStatu = true; frameWhiteBack.AddChidren(btnClose); btnClose.InitControl(); btnClose.UnSelectedImagePath = "Airer/DownOffline.png"; btnClose.SelectedImagePath = "Airer/Down.png"; btnClose.X = Application.GetRealWidth(752) - btnClose.XOffset; btnClose.Y = btnOpen.Y; //烘干 btnDry = new IconViewControl(81); btnDry.UnSelectedImagePath = "Airer/DryOffline.png"; btnDry.SelectedImagePath = "Airer/Dry.png"; btnDry.X = Application.GetRealWidth(98); btnDry.Y = Application.GetRealHeight(913); btnDry.IsSelected = ((Airer)this.device).DryOnOffStatus == 1 ? true : false; frameWhiteBack.AddChidren(btnDry); //风干 btnWind = new IconViewControl(81); frameWhiteBack.AddChidren(btnWind); btnWind.UnSelectedImagePath = "Airer/WindOffline.png"; btnWind.SelectedImagePath = "Airer/Wind.png"; btnWind.X = Application.GetRealWidth(328); btnWind.IsSelected = ((Airer)this.device).WindOnOffStatus == 1 ? true : false; btnWind.Y = btnDry.Y; //消毒 btnDisinfect = new IconViewControl(81); frameWhiteBack.AddChidren(btnDisinfect); btnDisinfect.UnSelectedImagePath = "Airer/DisinfectOffline.png"; btnDisinfect.SelectedImagePath = "Airer/DisinfectSelected.png"; btnDisinfect.IsSelected = ((Airer)this.device).DisinfectOnOffStatus == 1 ? true : false; btnDisinfect.X = Application.GetRealWidth(556); btnDisinfect.Y = btnDry.Y; //照明 btnLight = new IconViewControl(81); frameWhiteBack.AddChidren(btnLight); btnLight.UnSelectedImagePath = "Airer/LightOffline.png"; btnLight.SelectedImagePath = "Airer/LightSelected.png"; btnLight.IsSelected = ((Airer)this.device).OnOffStatus == 1 ? true : false; btnLight.X = Application.GetRealWidth(786); btnLight.Y = btnDry.Y; string[] stringText = { Language.StringByID(R.MyInternationalizationString.AirerUp), Language.StringByID(R.MyInternationalizationString.AirerStop), Language.StringByID(R.MyInternationalizationString.AirerDown), Language.StringByID(R.MyInternationalizationString.AirerDry), Language.StringByID(R.MyInternationalizationString.AirerWind), Language.StringByID(R.MyInternationalizationString.AirerDisinfect), Language.StringByID(R.MyInternationalizationString.AirerLight) }; for (int i = 0; i < stringText.Length; i++) { var btnText = new Button() { Width = Application.GetRealWidth(69 + 20), Height = Application.GetRealHeight(46), TextColor = ZigbeeColor.Current.XMGray2, TextSize = 12, Text = stringText[i], }; frameWhiteBack.AddChidren(btnText); switch (i) { case 0: btnText.X = Application.GetRealWidth(128); btnText.Y = Application.GetRealHeight(780); break; case 1: btnText.X = Application.GetRealWidth(439); btnText.Y = Application.GetRealHeight(780); break; case 2: btnText.X = Application.GetRealWidth(747); btnText.Y = Application.GetRealHeight(780); break; case 3: btnText.X = Application.GetRealWidth(94); btnText.Y = Application.GetRealHeight(1022); btnText.BackgroundColor = 0xff00ff; break; case 4: btnText.X = Application.GetRealWidth(324); btnText.Y = Application.GetRealHeight(1022); btnText.BackgroundColor = 0xff00ff; break; case 5: btnText.X = Application.GetRealWidth(552); btnText.Y = Application.GetRealHeight(1022); break; case 6: btnText.X = Application.GetRealWidth(782); btnText.BackgroundColor = 0xff00ff; btnText.Y = Application.GetRealHeight(1022); break; } } //右箭头 {烘干、风干和消毒的设置默认时间暂时取去掉,且倒计时也去掉,因为第三方设备不支持」 //TimeShow(frameWhiteBack); ClickEventHander(); } #endregion #region ■ 时间显示_______________________ /// /// 发送窗帘命令 /// /// private void TimeShow(FrameLayout frameWhiteBack) { //烘干时间 btnDryTimeText = new Button() { Width = Application.GetRealWidth(109 + 10), Height = Application.GetRealHeight(40), X = Application.GetRealWidth(81), Y = Application.GetRealHeight(1092), TextColor = ZigbeeColor.Current.XMOrange, TextSize = 10, Text = GetTimeString(airer.DryRemainTime), }; frameWhiteBack.AddChidren(btnDryTimeText); //风干时间 btnWindTimeText = new Button() { Width = Application.GetRealWidth(109 + 10), Height = Application.GetRealHeight(40), TextColor = ZigbeeColor.Current.XMOrange, TextSize = 10, X = Application.GetRealWidth(311), Y = btnDryTimeText.Y, Text = GetTimeString(airer.WindRemainTime), }; frameWhiteBack.AddChidren(btnWindTimeText); //消毒时间 btnDisinfectTimeText = new Button() { Width = Application.GetRealWidth(109 + 10), Height = Application.GetRealHeight(40), TextColor = ZigbeeColor.Current.XMOrange, TextSize = 10, Text = GetTimeString(airer.DisinfectRemainTime), X = Application.GetRealWidth(539), Y = btnDryTimeText.Y, }; frameWhiteBack.AddChidren(btnDisinfectTimeText); var rowAirer = new AiererTimeControl(0); rowAirer.DetailCardActionTimeEvent += (timeCur, typeCur) => { switch (typeCur) { case 1: btnDryTimeText.Text = GetTimeString(timeCur); break; case 2: btnWindTimeText.Text = GetTimeString(timeCur); break; case 3: btnDisinfectTimeText.Text = GetTimeString(timeCur); break; } }; actionDry = (textTime) => { btnDryTimeText.Text = textTime; TimerHandler(airer); }; actionWind = (textTime) => { btnWindTimeText.Text = textTime; TimerHandler(airer); }; actionDisinfect = (textTime) => { btnDisinfectTimeText.Text = textTime; TimerHandler(airer); }; TimerHandler(airer); } #endregion #region ■ 点击事件处理_______________________ /// /// 点击事件处理 /// void ClickEventHander() { btnOpen.ButtonClickEvent += (sender, e) => { //发送窗帘命令 this.SetCurtainCommand(0); }; btnStop.ButtonClickEvent += (sender, e) => { //如果住宅为虚拟住宅,则此功能无效 if (Common.Config.Instance.Home.IsVirtually == true) { return; } //发送窗帘命令 this.SetCurtainCommand(2); }; btnClose.ButtonClickEvent += (sender, e) => { //发送窗帘命令 this.SetCurtainCommand(1); }; btnDry.ButtonClickEvent += (sender, e) => { //发送开关命令 this.SetSwitchCommand(!btnDry.IsSelected, 4); }; btnWind.ButtonClickEvent += (sender, e) => { //发送开关命令 this.SetSwitchCommand(!btnWind.IsSelected, 3); }; btnDisinfect.ButtonClickEvent += (sender, e) => { //发送开关命令 this.SetSwitchCommand(!btnDisinfect.IsSelected, 5); }; btnLight.ButtonClickEvent += (sender, e) => { //发送开关命令 this.SetSwitchCommand(!btnLight.IsSelected, 2); }; } #endregion #region ■ 发送开关命令_______________________ /// /// 发送开关命令 ///注意,衣架中不同端点代表不同功能 ///回路1:窗帘控制 ///回路2:照明控制 ///回路3:风干控制 ///回路4:烘干控制 ///回路5:消毒控制 /// /// 发送状态 /// 发送类型:2:照明;3:风干;4:烘干;5消毒 private void SetSwitchCommand(bool isOpen, int type) { //如果住宅为虚拟住宅 if (Common.Config.Instance.Home.IsVirtually == true) { switch (type) { case 2: ((Airer)this.device).OnOffStatus = isOpen == true ? 1 : 0; //变更卡片状态 this.RefreshSwitchStatu(((Airer)this.device).OnOffStatus == 1, 2); break; case 3: ((Airer)this.device).WindOnOffStatus = isOpen == true ? 1 : 0; if (isOpen) { airer.WindRemainTime = airer.WindTime; } //变更卡片状态 this.RefreshSwitchStatu(((Airer)this.device).WindOnOffStatus == 1, 3); break; case 4: ((Airer)this.device).DryOnOffStatus = isOpen == true ? 1 : 0; if (isOpen) { airer.DryRemainTime = airer.DryTime; } //变更卡片状态 this.RefreshSwitchStatu(((Airer)this.device).DryOnOffStatus == 1, 4); break; case 5: ((Airer)this.device).DisinfectOnOffStatus = isOpen == true ? 1 : 0; if (isOpen) { airer.DisinfectRemainTime = airer.DisinfectTime; } //变更卡片状态 this.RefreshSwitchStatu(((Airer)this.device).DisinfectOnOffStatus == 1, 5); break; } return; } //检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息 var listControl = new List(); listControl.Add(btnDry); listControl.Add(btnWind); listControl.Add(btnDisinfect); listControl.Add(btnLight); this.StartCheckResponeResult(listControl, (result) => { //接收到网关回复 if (result == true) { HdlThreadLogic.Current.RunMain(() => { //变更卡片状态 switch (type) { case 2: bool statu = ((Airer)this.device).OnOffStatus == 1; this.RefreshSwitchStatu(statu, type); break; case 3: bool statu5 = ((Airer)this.device).WindOnOffStatus == 1; this.RefreshSwitchStatu(statu5, type); break; case 4: bool statu4 = ((Airer)this.device).DryOnOffStatus == 1; this.RefreshSwitchStatu(statu4, type); break; case 5: bool statu3 = ((Airer)this.device).DisinfectOnOffStatus == 1; this.RefreshSwitchStatu(statu3, type); break; } }); } }); //打开 //switch (type) //{ // case 3: //发送默认时间 //if (airer.WindTime == 0) //{ // airer.WindTime = 180; //} //airer.SetAirerFunTimeDevice(airer.WindTime, 3); // break; //case 4: //发送默认时间 //if (airer.DryTime == 0) //{ // airer.DryTime = 180; //} //airer.SetAirerFunTimeDevice(airer.DryTime, 4); // break; //case 5: //发送默认时间 //if (airer.DisinfectTime == 0) //{ // airer.DisinfectTime = 30; //} //airer.SetAirerFunTimeDevice(airer.DisinfectTime, 5); // break; //} if (isOpen == true) { airer.SwitchControl(1, type); } else { airer.SwitchControl(0, type); } } #endregion #region ■ 发送窗帘命令_______________________ /// /// 发送窗帘命令 ///注意,衣架中不同端点代表不同功能 ///回路1:窗帘控制 ///回路2:照明控制 ///回路3:风干控制 ///回路4:烘干控制 ///回路5:消毒控制 /// /// private void SetCurtainCommand(int comand) { // this.device.DeviceEpoint = 1; //发送命令 ((Airer)device).AirerUpDownStopControl(comand); } #endregion #region ■ 刷新开关状态_______________________ /// /// 刷新开关状态 /// /// 打开状态 /// 发送类型:2:照明;3:风干;4:烘干;5消毒 private void RefreshSwitchStatu(bool isOpen, int type) { switch (type) { case 2: btnLight.IsSelected = isOpen; break; case 3: btnWind.IsSelected = isOpen; //btnWindTimeText.Text = GetTimeString(airer.WindRemainTime); //if (!isOpen) //{ // airer.WindRemainTime = 0; //} break; case 4: btnDry.IsSelected = isOpen; //btnDryTimeText.Text = GetTimeString(airer.DryRemainTime); //if (!isOpen) //{ // airer.DryRemainTime = 0; //} break; case 5: btnDisinfect.IsSelected = isOpen; //btnDisinfectTimeText.Text = GetTimeString(airer.DisinfectRemainTime); //if (!isOpen) //{ // airer.DisinfectRemainTime = 0; //} break; } //设置状态文字 this.SetStatuText(HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device)); } #endregion #region ■ 是否获取网关反馈的结果_____________ /// /// 检测网关的反馈结果(属性上报的对象:device.DeviceStatusReport) /// /// 命令区分 /// 上报数据 /// public override bool CheckResponeResultStatu(ReceiveComandDiv comandDiv, CommonDevice report) { if (comandDiv == ReceiveComandDiv.A设备属性上报) { HdlThreadLogic.Current.RunMain(() => { //变更卡片状态 switch (report.DeviceEpoint) { case 2: this.RefreshSwitchStatu(((Airer)this.device).OnOffStatus == 1, 2); break; case 3: this.RefreshSwitchStatu(((Airer)this.device).WindOnOffStatus == 1, 3); break; case 4: this.RefreshSwitchStatu(((Airer)this.device).DryOnOffStatus == 1, 4); break; case 5: this.RefreshSwitchStatu(((Airer)this.device).DisinfectOnOffStatus == 1, 5); break; } }); return true; } return false; } #endregion /// /// 时间倒计时设置 /// 晾衣架时间 :1烘干,2:风干;3消毒 /// /// public async void TimerHandler(Airer airer) { if (airer.DryOnOffStatus == 1 && airer.DryRemainTime != 0) { new System.Threading.Thread(async () => { while (airer.DryRemainTime > 0 && this.Parent != null) { System.Threading.Thread.Sleep(1000); HdlThreadLogic.Current.RunMain(() => { actionDry?.Invoke(GetTimeString(airer.DryRemainTime)); }, ShowErrorMode.NO); airer.DryRemainTime--; } HdlThreadLogic.Current.RunMain(() => { if (this.Parent != null) { //直接开启Loading特效 actionDry?.Invoke(""); } }, ShowErrorMode.NO); }) { IsBackground = true }.Start(); } if (airer.WindOnOffStatus == 1 && airer.WindRemainTime != 0) { //开启风干时间 new System.Threading.Thread(async () => { while (airer.WindRemainTime > 0 && this.Parent != null) { System.Threading.Thread.Sleep(1000); HdlThreadLogic.Current.RunMain(() => { actionWind?.Invoke(GetTimeString(airer.WindRemainTime)); }, ShowErrorMode.NO); airer.WindRemainTime--; } HdlThreadLogic.Current.RunMain(() => { if (this.Parent != null) { //直接开启Loading特效 actionWind?.Invoke(""); } }, ShowErrorMode.NO); }) { IsBackground = true }.Start(); } if (airer.DisinfectOnOffStatus == 1 && airer.DisinfectRemainTime != 0) { //开启消毒时间 new System.Threading.Thread(async () => { while (airer.DisinfectRemainTime > 0 && this.Parent != null) { System.Threading.Thread.Sleep(1000); HdlThreadLogic.Current.RunMain(() => { actionDisinfect?.Invoke(GetTimeString(airer.DisinfectRemainTime)); }, ShowErrorMode.NO); airer.DisinfectRemainTime--; } HdlThreadLogic.Current.RunMain(() => { if (this.Parent != null) { //直接开启Loading特效 actionDisinfect?.Invoke(""); } }, ShowErrorMode.NO); }) { IsBackground = true }.Start(); } } /// /// 获取场景延时字符串 /// /// /// public static string GetTimeString(int second) { if (second == 0) { return null; } string timeStr = string.Empty; int hour = second / 3600; int minu = second % 3600 / 60; int sec = second % 60; string h = string.Empty; string m = string.Empty; string s = string.Empty; if (hour > 0) { if (hour < 10) { h = "0" + hour; } else { h = hour.ToString(); } timeStr += $"{h}:"; if (minu >= 0) { if (minu < 10) { m = "0" + minu; } else { m = minu.ToString(); } timeStr += $"{m}:"; } if (sec >= 0) { if (sec < 10) { s = "0" + sec; } else { s = minu.ToString(); } timeStr += $"{s}"; } return timeStr; } else { if (minu > 0) { timeStr = "00:"; if (minu < 10) { m = "0" + minu; } else { m = minu.ToString(); } timeStr += $"{m}:"; if (sec >= 0) { if (sec < 10) { s = "0" + sec; } else { s = sec.ToString(); } timeStr += $"{s}"; } return timeStr; } else { if (sec > 0) { timeStr = "00:00:"; if (sec < 10) { s = "0" + sec; } else { s = sec.ToString(); } timeStr += $"{s}"; return timeStr; } else { return ""; } } } } } }