using System; using System.Collections.Generic; using HDL_ON.Entity; using HDL_ON.UI.UI2.Intelligence.Automation.LogicView; using Shared; namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice { public class Matching : FrameLayout { public Matching() { Tag = "PirView"; } public void Show(List brandList, List libraryList,string spk) { #region 界面布局 this.BackgroundColor = CSS.CSS_Color.viewMiddle; PirDevice.View.TopView topView = new View.TopView(); topView.topNameBtn.TextID = StringId.pipeiyaokongqi; this.AddChidren(topView.FLayoutView()); topView.clickBackBtn.MouseUpEventHandler += (sender, e) => { BrandList brandObj = new BrandList(); brandObj.Show(brandList, spk); this.RemoveFromParent(); }; FrameLayout fLayout = new FrameLayout { Y = topView.frameLayout.Bottom, Height = Application.GetRealHeight(667 - 64), Width = Application.GetRealWidth(375), }; this.AddChidren(fLayout); //请点击以下按钮 Button text1Btn = new Button { Y = Application.GetRealHeight(60), X = Application.GetRealWidth(16), Width = Application.GetRealWidth(375 - 32), Height = Application.GetRealHeight(20), TextID = StringId.dianjianniu, TextSize = TextSize.text14, TextColor = CSS.CSS_Color.textColor, TextAlignment = TextAlignment.Center, }; fLayout.AddChidren(text1Btn); //确认设备是否有响应 Button text2Btn = new Button { Y = Application.GetRealHeight(60 + 24), X = Application.GetRealWidth(16), Width = Application.GetRealWidth(375 - 32), Height = Application.GetRealHeight(20), TextID = StringId.shifouyouxiangying, TextSize = TextSize.text14, TextColor = CSS.CSS_Color.textColor, TextAlignment = TextAlignment.Center, }; fLayout.AddChidren(text2Btn); //左 var leftIconBtn = new Button { Y = Application.GetRealHeight(203), X = Application.GetRealWidth(16), Width = Application.GetRealWidth(36), Height = Application.GetRealWidth(36), UnSelectedImagePath = "PirIcon/left.png", }; fLayout.AddChidren(leftIconBtn); //右 var rightIconBtn = new Button { Y = Application.GetRealHeight(203), X = Application.GetRealWidth(323), Width = Application.GetRealWidth(36), Height = Application.GetRealWidth(36), UnSelectedImagePath = "PirIcon/right.png", }; fLayout.AddChidren(rightIconBtn); //测试功能 var testBtn = new Button { Y = Application.GetRealHeight(199), X = Application.GetRealWidth(136), Width = Application.GetRealWidth(104), Height = Application.GetRealHeight(44), TextID=StringId.dianyuan, TextSize = TextSize.text16, TextColor = CSS.CSS_Color.textColor, TextAlignment = TextAlignment.Center, Radius = (uint)Application.GetRealHeight(18), BorderWidth = 1, BorderColor = CSS.CSS_Color.textCancelColor, }; fLayout.AddChidren(testBtn); // 5/10 Button sumBtn = new Button { Y = Application.GetRealHeight(267), X = Application.GetRealWidth(136), Width = Application.GetRealWidth(104), Height = Application.GetRealHeight(17), Text = $"(1/{libraryList.Count})", TextSize = TextSize.text12, TextColor = CSS.CSS_Color.textCancelColor, }; fLayout.AddChidren(sumBtn); //控制失败 var failedBtn = new Button { Y = Application.GetRealHeight(521), X = Application.GetRealWidth(52), Width = Application.GetRealWidth(124), Height = Application.GetRealHeight(44), TextID = StringId.kongzhishibai, TextSize = TextSize.text16, TextColor = CSS.CSS_Color.textConfirmColor, TextAlignment = TextAlignment.Center, Radius = (uint)Application.GetRealHeight(22), BorderWidth = 1, BorderColor = CSS.CSS_Color.textConfirmColor, }; fLayout.AddChidren(failedBtn); //控制成功 var succeedBtn = new Button { Y = Application.GetRealHeight(521), X = Application.GetRealWidth(196), Width = Application.GetRealWidth(124), Height = Application.GetRealHeight(44), TextID = StringId.kongzhichenggong, TextSize = TextSize.text16, TextColor = CSS.CSS_Color.textWhiteColor, TextAlignment = TextAlignment.Center, Radius = (uint)Application.GetRealHeight(22), //BorderWidth = 1, //BorderColor = CSS.CSS_Color.textConfirmColor, BackgroundColor = CSS.CSS_Color.textConfirmColor, }; fLayout.AddChidren(succeedBtn); #endregion #region 点击事件 //表示库列表索引值(目前只20个库) int index = 1; //表示测试码索引值(目前只测试3个码) int code = 1; //表示测试最后一个码; bool if_bool = false; //左 leftIconBtn.MouseUpEventHandler += (sender, e) => { if (index>1) { index--; sumBtn.Text = $"({index.ToString()}/{libraryList.Count})"; } code = 1; GetBtnText(testBtn, code, spk); }; //右 rightIconBtn.MouseUpEventHandler += (sender, e) => { if (index < libraryList.Count) { index++; sumBtn.Text = $"({index.ToString()}/{libraryList.Count})"; } code = 1; GetBtnText(testBtn, code, spk); }; //测试Text testBtn.MouseUpEventHandler += (sender, e) => { // testBtn.BackgroundColor = CSS.CSS_Color.viewMiddle; var library = libraryList[index - 1]; var control = GetControl(spk, testBtn.TextID, library); //发送测试码命令 PirMethod.ThreadSend(control, (responsePackNew) => { }, "库码测试", "frame", this, null); if (code == 3) { //标记最后那个码 if_bool = true; } }; testBtn.MouseDownEventHandler += (sender, e) => { //testBtn.BackgroundColor = CSS.CSS_Color.textConfirmColor; }; //控制失败 failedBtn.MouseUpEventHandler += (sender, e) => { if (index < libraryList.Count) { //先加 index++; //更新文本 sumBtn.Text = $"({index.ToString()}/{libraryList.Count})"; } code = 1; //更新状态 GetBtnText(testBtn, code, spk); }; //控制成功 succeedBtn.MouseUpEventHandler += (sender, e) => { if (code < 3) { code++; } //更新状态 GetBtnText(testBtn, code, spk); if (if_bool) { var library = libraryList[index-1]; var control = GetControl(spk, testBtn.TextID, library); if (spk == SPK.TvIr) { //备注:伟南要求小米电视换掉spk=ir.tvxm(听说是临时解决方案) var brand = brandList.Find((c) => c.id == library.brandId); if (brand != null) { if (brand.brandName.Contains("小米") || brand.brandName.Contains("Xiaomi")) { //更换spk control.spk = "ir.tvxm"; } } } PirMethod method = new PirMethod(); //发送库添加遥控器命令 method.ThreadAddControl(control, this, (device) => { MainPage.BasePageView.RemoveViewByTag("PirView"); AddControlComplete addControlComplete = new AddControlComplete(); MainPage.BasePageView.AddChidren(addControlComplete); addControlComplete.Show(device, true); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }); } }; #endregion } /// /// 获取Control对象(存储发送数据的对象) /// /// /// /// /// private Control GetControl(string spk, int textInt, Library library) { string key = ""; string value = ""; switch (spk) { case SPK.AcIr: { switch (textInt) { case StringId.dianyuan: { key = "on_off"; value = "on"; } break; case StringId.moshizhileng: { key = "mode"; value = "cool"; } break; case StringId.fengsuzhongfeng: { key = "fan"; value = "medium"; } break; } } break; case SPK.TvIr: { switch (textInt) { case StringId.dianyuan: { key = "on_off"; value = "on"; } break; case StringId.yinliangjia: { key = "volume+"; value = "50"; } break; case StringId.jingyin: { key = "mute"; value = "0"; } break; } } break; case SPK.FanIr: { switch (textInt) { case StringId.dianyuan: { key = "on_off"; value = "on"; } break; case StringId.fengsuqiehuan: { key = "speed"; value = ""; } break; case StringId.yaotou: { key = "swing"; value = ""; } break; } } break; case SPK.PjtIr: { switch (textInt) { case StringId.dianyuan: { key = "on_off"; value = "on"; } break; case StringId.yinliangjia: { key = "volume+"; value = ""; } break; case StringId.yinliangjian: { key = "volume-"; value = ""; } break; } } break; case SPK.StbIr: { switch (textInt) { case StringId.dianyuan: { key = "on_off"; value = "on"; } break; case StringId.yinliangjia: { key = "volume+"; value = ""; } break; case StringId.yinliangjian: { key = "volume-"; value = ""; } break; } } break; case SPK.DvDIr: { } break; case SPK.PurifierIr: { switch (textInt) { case StringId.dianyuan: { key = "on_off"; value = "on"; } break; case StringId.zidong: { key = "auto"; value = ""; } break; case StringId.jingyin: { key = "mute"; value = "0"; } break; } } break; case SPK.HeaterIr: { switch (textInt) { case StringId.dianyuan: { key = "on_off"; value = "on"; } break; case StringId.wendujia: { key = "temp+"; value = ""; } break; case StringId.wendujian: { key = "temp-"; value = ""; } break; } } break; } AttributesStatus buttonObj = new AttributesStatus(); buttonObj.key = key; buttonObj.value = value; Control control = new Control(); control.spk = spk; control.name = spk; control.groupId = library.irIndex; control.type = "library"; control.status.Add(buttonObj); control.deviceId = Pir.currPir.deviceId; control.sid = ""; string[] strings = library.irCode.Split(','); for (int arrayStr = 0; arrayStr < strings.Length; arrayStr++) { //var intValue = Convert.ToInt32(strings[arrayStr],16); control.library.Add(strings[arrayStr].Replace("0x","")); } return control; } /// /// 显示测试文本 /// /// 显示控件 /// 测试码文本索引值 /// 云雀上定义spk private void GetBtnText(Button testBtn,int code,string spk) { int textValue = 0; switch (spk) { case SPK.AcIr: { switch (code) { case 1: { textValue = StringId.dianyuan; } break; case 2: { textValue = StringId.moshizhileng; } break; case 3: { textValue = StringId.fengsuzhongfeng; } break; } } break; case SPK.TvIr: { switch (code) { case 1: { textValue = StringId.dianyuan; } break; case 2: { textValue = StringId.yinliangjia; } break; case 3: { textValue = StringId.jingyin; } break; } } break; case SPK.FanIr: { switch (code) { case 1: { textValue = StringId.dianyuan; } break; case 2: { textValue = StringId.fengsuqiehuan; } break; case 3: { textValue = StringId.yaotou; } break; } } break; case SPK.PjtIr: { switch (code) { case 1: { textValue = StringId.dianyuan; } break; case 2: { textValue = StringId.yinliangjia; } break; case 3: { textValue = StringId.yinliangjian; } break; } } break; case SPK.StbIr: { switch (code) { case 1: { textValue = StringId.dianyuan; } break; case 2: { textValue = StringId.yinliangjia; } break; case 3: { textValue = StringId.yinliangjian; } break; } } break; case SPK.DvDIr: { } break; case SPK.PurifierIr: { switch (code) { case 1: { textValue = StringId.dianyuan; } break; case 2: { textValue = StringId.zidong; } break; case 3: { textValue = StringId.jingyin; } break; } } break; case SPK.HeaterIr: { switch (code) { case 1: { textValue = StringId.dianyuan; } break; case 2: { textValue = StringId.wendujia; } break; case 3: { textValue = StringId.wendujian; } break; } } break; } testBtn.TextID = textValue; } } }