using System; using System.Collections.Generic; using Shared.Common; using Shared.Phone.UserCenter; using ZigBee.Device; namespace Shared.Phone.MainPage.ControlForm { /// /// 新风类型的深度卡片界面 /// public class DeviceFreshAirDetailCardForm : DeviceDetailCardCommonForm { #region ■ 变量声明___________________________ /// /// 界面上可以操作的控件 /// private List listControl = new List(); /// /// 控件 /// private FreshAir freshAirDev = null; /// /// 状态控件 /// private NormalViewControl btnStatu = null; /// /// 当前的文本 /// private string CurrentText = string.Empty; /// /// 设备名称控件 /// private NormalViewControl btnDeviceName = null; #endregion #region ■ 初始化_____________________________ public override void InitMiddleFrameAfter(FrameLayout frameWhiteBack) { //左滑不能 this.ScrollEnabled = true; this.freshAirDev = (FreshAir)this.device; //先清空 this.listControl = new List(); InitFreshAirControl(frameWhiteBack); UpdateStatus(); } /// /// 初始化新风控件 /// /// private void InitFreshAirControl(FrameLayout frameWhiteBack) { //新风控件的容器 var frameAcBack = new FrameLayout(); frameAcBack.Y = Application.GetRealHeight(262); frameAcBack.Width = Application.GetMinRealAverage(444); frameAcBack.Height = Application.GetMinRealAverage(444); frameAcBack.Gravity = Gravity.CenterHorizontal; frameAcBack.BackgroundImagePath = "FreshAir/FreshAirPic.png"; frameWhiteBack.AddChidren(frameAcBack); //新风自动Layout【为了扩大点击范围】 var autoFrameLayout = new NormalViewControl(213 + 40, 63 + 80, true); autoFrameLayout.X = Application.GetRealWidth(275 - 20); autoFrameLayout.Y = Application.GetRealHeight(821 - 20); frameWhiteBack.AddChidren(autoFrameLayout); autoFrameLayout.ButtonClickEvent += HandlerAuto; // 自动(第1个,listControl【0】) var btnAuto = new NormalViewControl(213, 63, true); btnAuto.X = Application.GetRealWidth(275); btnAuto.Y = Application.GetRealHeight(821); btnAuto.TextID = R.MyInternationalizationString.Mode_Auto; btnAuto.TextColor = ZigbeeColor.Current.XMGray3; btnAuto.IsBold = false; btnAuto.TextAlignment = TextAlignment.Center; frameWhiteBack.AddChidren(btnAuto); this.listControl.Add(btnAuto); btnAuto.ButtonClickEvent += HandlerAuto; //自动下划线(第2个,listControl【1】) var btnAutoLine = new NormalViewControl(72, 12, true); btnAutoLine.X = Application.GetRealWidth(346); btnAutoLine.Y = Application.GetRealHeight(896); btnAutoLine.BackgroundColor = ZigbeeColor.Current.XMOrange; btnAutoLine.Visible = false; frameWhiteBack.AddChidren(btnAutoLine); this.listControl.Add(btnAutoLine); btnAutoLine.ButtonClickEvent += HandlerAuto; //新风手动Layout【为了扩大点击范围】 var manualFrameLayout = new NormalViewControl(213 + 40, 63 + 80, true); manualFrameLayout.X = Application.GetRealWidth(488 - 20); manualFrameLayout.Y = Application.GetRealHeight(821 - 20); frameWhiteBack.AddChidren(manualFrameLayout); manualFrameLayout.ButtonClickEvent += HandlerManual; //手动(第3个,listControl【2】) var btnManual = new NormalViewControl(213, 63, true); btnManual.X = Application.GetRealWidth(488); btnManual.Y = btnAuto.Y; btnManual.TextID = R.MyInternationalizationString.Manual; btnManual.TextColor = ZigbeeColor.Current.XMGray3; btnManual.IsBold = false; btnManual.TextAlignment = TextAlignment.Center; frameWhiteBack.AddChidren(btnManual); this.listControl.Add(btnManual); btnManual.ButtonClickEvent += HandlerManual; //手动下划线(第4个,listControl【3】) var btnManualLine = new NormalViewControl(72, 12, true); btnManualLine.X = Application.GetRealWidth(560); btnManualLine.BackgroundColor = ZigbeeColor.Current.XMOrange; btnManualLine.Y = btnAutoLine.Y; btnManualLine.Visible = false; frameWhiteBack.AddChidren(btnManualLine); this.listControl.Add(btnManualLine); btnManualLine.ButtonClickEvent += HandlerManual; //高风(第5个,listControl【4】) var btnHighSpeed = new IconViewControl(81); btnHighSpeed.X = Application.GetRealWidth(207); btnHighSpeed.Y = Application.GetRealHeight(999); btnHighSpeed.UnSelectedImagePath = "AC/Fan_Height.png"; btnHighSpeed.SelectedImagePath = "AC/Fan_HeightSelected.png"; frameWhiteBack.AddChidren(btnHighSpeed); this.listControl.Add(btnHighSpeed); btnHighSpeed.ButtonClickEvent += (sender, e) => { if (freshAirDev.currentFanStatus == 0) { return; } if (freshAirDev.currentFanMode == 5) { var msgContr = new ShowMsgControl(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.AutoModeForbiddenOperate)); msgContr.Show(); return; } if (!btnHighSpeed.IsSelected) { this.listControl[4].Enable = false; this.SetFanComand(3); } }; //开关(第6个,listControl【5】) var btnSwitch = new IconViewControl(81); btnSwitch.X = Application.GetRealWidth(444); btnSwitch.Y = btnHighSpeed.Y; btnSwitch.UnSelectedImagePath = "AC/OpenOrClose.png"; btnSwitch.SelectedImagePath = "AC/OpenOrCloseSelected.png"; frameWhiteBack.AddChidren(btnSwitch); this.listControl.Add(btnSwitch); btnSwitch.ButtonClickEvent += (sender, e) => { btnSwitch.IsSelected = !btnSwitch.IsSelected; if (btnSwitch.IsSelected) { this.listControl[5].Enable = false; this.SetFanComand(4); } else { this.listControl[5].Enable = false; this.SetFanComand(0); } }; //低风(第7个,listControl【6】) var btnLowSpeed = new IconViewControl(81); btnLowSpeed.X = Application.GetRealWidth(677); btnLowSpeed.Y = btnHighSpeed.Y; btnLowSpeed.UnSelectedImagePath = "AC/Fan_Low.png"; btnLowSpeed.SelectedImagePath = "AC/Fan_LowSelected.png"; frameWhiteBack.AddChidren(btnLowSpeed); this.listControl.Add(btnLowSpeed); btnLowSpeed.ButtonClickEvent += (sender, e) => { if (freshAirDev.currentFanStatus == 0) { return; } if (freshAirDev.currentFanMode == 5) { var msgContr = new ShowMsgControl(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.AutoModeForbiddenOperate)); msgContr.Show(); return; } if (!btnLowSpeed.IsSelected) { this.listControl[6].Enable = false; this.SetFanComand(1); } }; } /// /// 自动事件 /// /// /// private void HandlerAuto(object sender, MouseEventArgs e) { if (freshAirDev.currentFanStatus == 0) { return; } if (freshAirDev.currentFanMode == 5) { return; } if (!listControl[0].IsSelected) { this.listControl[0].Enable = false; this.SetFanComand(5); } } /// /// 手动事件 /// /// /// private void HandlerManual(object sender, MouseEventArgs e) { if (freshAirDev.currentFanStatus == 0) { return; } if (freshAirDev.currentFanMode == 15) { return; } if (!this.listControl[2].IsSelected) { this.listControl[2].Enable = false; this.SetFanComand(15); } } #endregion #region ■ 是否获取网关反馈的结果_____________ /// /// 检测网关的反馈结果(属性上报的对象:device.DeviceStatusReport) /// /// 命令区分 /// 上报数据 /// public override bool CheckResponeResultStatu(ReceiveComandDiv comandDiv, CommonDevice report) { if (comandDiv == ReceiveComandDiv.A设备属性上报) { if (report.DeviceStatusReport.CluterID == 514) { var attriButeList = report.DeviceStatusReport.AttriBute; foreach (var attList in attriButeList) { if (attList.AttributeId == 0) { //风速 HdlThreadLogic.Current.RunMain(() => { UpdateStatus(); }); //已经接收到网关的反馈 return true; } } } } this.listControl[0].Enable = true; this.listControl[2].Enable = true; this.listControl[4].Enable = true; this.listControl[5].Enable = true; this.listControl[6].Enable = true; return false; } #endregion #region ■ 设置方法 /// ///命令 ///0:Off ///1:Low ///3:High ///4:On ///5:Auto /// 15:Manual /// private void SetFanComand(int command) { //检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息 this.StartCheckResponeResult(this.listControl, (result) => { //接收到网关回复 if (result == true) { } }); switch (command) { case 0: freshAirDev.Close(); break; case 1: freshAirDev.SetLowSpeed(); break; case 3: freshAirDev.SetHighSpeed(); break; case 4: freshAirDev.Open(); break; case 5: freshAirDev.SetAuto(); break; case 15: freshAirDev.SetManual(); break; } } #endregion #region ■ 刷新状态_____________ /// /// 刷新状态 /// private void UpdateStatus() { //设置状态文字 if (freshAirDev.currentFanStatus == 4) { this.listControl[5].Enable = true; //打开 this.listControl[5].IsSelected = true; //设置状态文字 this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uOpen1)); } if (freshAirDev.currentFanStatus == 0) { //关闭 this.listControl[0].TextColor = ZigbeeColor.Current.XMGray3; this.listControl[0].IsBold = false; this.listControl[1].Visible = false; this.listControl[2].TextColor = ZigbeeColor.Current.XMGray3; this.listControl[2].IsBold = false; this.listControl[3].Visible = false; this.listControl[4].IsSelected = false; this.listControl[5].IsSelected = false; this.listControl[6].IsSelected = false; this.listControl[5].Enable = true; //设置状态文字 this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close)); return; } //设置模式 if (freshAirDev.currentFanMode == 5) { this.listControl[0].TextColor = ZigbeeColor.Current.XMGray1; this.listControl[0].IsBold = true; this.listControl[1].Visible = true; this.listControl[2].TextColor = ZigbeeColor.Current.XMGray3; this.listControl[2].IsBold = false; this.listControl[3].Visible = false; this.listControl[0].Enable = true; } else if (freshAirDev.currentFanMode == 15) { this.listControl[0].TextColor = ZigbeeColor.Current.XMGray3; this.listControl[0].IsBold = false; this.listControl[1].Visible = false; this.listControl[2].TextColor = ZigbeeColor.Current.XMGray1; this.listControl[2].IsBold = true; this.listControl[3].Visible = true; this.listControl[2].Enable = true; } //设置风速 if (freshAirDev.currentFanSpeed == 1) { this.listControl[4].IsSelected = false; this.listControl[6].IsSelected = true; this.listControl[6].Enable = true; } else if (freshAirDev.currentFanSpeed == 3) { this.listControl[4].IsSelected = true; this.listControl[6].IsSelected = false; this.listControl[4].Enable = true; } } #endregion } }