using System.IO; using System;//ConfigIRCode using System.Collections.Generic; namespace Shared.SimpleControl.Phone { public class ConfigIRCode : Dialog { private static byte TestByteIndex = 12; Common common; int pageIndex = 1; int pageCount = 1; /// /// 当前的品牌数据 /// object btnBrandData_Tag; /// /// 设备类型编号 /// string modulTypeNumber; VerticalScrolViewLayout brandView; FrameLayout brandFlipView; byte textByte = 6; int textTime = 5; /// /// 品牌名字:按钮 /// Button btnBrandName; /// /// 品牌列表 /// List brandDataList = new List (); /// /// 红外码列表 /// string [] infraredDataList; int infraredDataIndex = 0; byte [] updateInfraredBytes = new byte [27]; FrameLayout bodyView; string port = "1"; public void ShowSystemInfrared (Common c, bool isACInfrared = false) { common = c; if (isACInfrared) { if (common.LoopID < 4) { port = common.LoopID.ToString (); } } bodyView = new FrameLayout () { BackgroundColor = SkinStyle.Current.ViewColor }; AddChidren (bodyView); var btntopss =new Button () { Height = Application.GetRealHeight (36), BackgroundColor = SkinStyle.Current.MainColor }; bodyView.AddChidren (btntopss); #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (640), BackgroundColor = SkinStyle.Current.MainColor }; bodyView.AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = common.Name, TextColor = SkinStyle.Current.TextColor1, TextSize = 19, }; topView.AddChidren (title); var logo = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), UnSelectedImagePath = MainPage.LogoString, }; topView.AddChidren (logo); var back = new Button () { Height = Application.GetRealHeight (100), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { this.Close (); }; #endregion var rl = new RowLayout () { Y = topView.Bottom, Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (110), }; bodyView.AddChidren (rl); var btnEquipmentIcon = new Button () { Width = Application.GetRealHeight (63), Height = Application.GetRealHeight (63), X = Application.GetRealWidth (60), Gravity = Gravity.CenterVertical, }; rl.AddChidren (btnEquipmentIcon); if (isACInfrared) { btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredAC.png"; } else { btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredTV.png"; } btnBrandName = new Button () { Width = Application.GetRealHeight (343), X = btnEquipmentIcon.Right + Application.GetRealWidth (5), TextAlignment = TextAlignment.CenterLeft, Text = "Select Brand", TextColor = SkinStyle.Current.TextColor1 }; rl.AddChidren (btnBrandName); var btnDropDownIcon = new Button () { X = rl.Width - Application.GetRealWidth (100), Height = Application.GetRealHeight (46), Width = Application.GetRealWidth (47), UnSelectedImagePath = "Item/Down.png", SelectedImagePath = "Item/DownSelected.png", Gravity = Gravity.CenterVertical, }; rl.AddChidren (btnDropDownIcon); #region EventHandler dropTypehandler = ( sender, e) =>{ FindBrand (); }; btnDropDownIcon.MouseUpEventHandler += dropTypehandler; rl.MouseUpEventHandler += dropTypehandler; btnEquipmentIcon.MouseUpEventHandler += dropTypehandler; #endregion brandView = new VerticalScrolViewLayout () { Gravity = Gravity.CenterHorizontal, Y = rl.Bottom, Height = bodyView.Height - rl.Bottom - Application.GetRealHeight (90), }; bodyView.AddChidren (brandView); brandFlipView = new FrameLayout () { X = brandView.X, Y = brandView.Bottom, Width = brandView.Width, Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.MainColor, Visible = false }; bodyView.AddChidren (brandFlipView); Button btnAutoTestLeft = new Button () { Width = Application.GetRealWidth (158), UnSelectedImagePath = @"AC/ACDialogRegresses.png", SelectedImagePath = @"AC/ACDialogRegressesOn.png", }; brandFlipView.AddChidren (btnAutoTestLeft); btnAutoTestLeft.MouseDownEventHandler += (sender, e) => { btnAutoTestLeft.IsSelected = true; }; Button btnAutoTest = new Button () { X = btnAutoTestLeft.Right, Width = Application.GetRealWidth (640 - 158 - 158), TextColor = SkinStyle.Current.TextColor1, Text = pageIndex.ToString () }; brandFlipView.AddChidren (btnAutoTest); Button btnAutoTestRight = new Button () { Width = Application.GetRealWidth (158), X = btnAutoTest.Right, UnSelectedImagePath = @"AC/ACDialogForward.png", SelectedImagePath = @"AC/ACDialogForwardOn.png", }; brandFlipView.AddChidren (btnAutoTestRight); btnAutoTestRight.MouseDownEventHandler += (sender, e) => { btnAutoTestRight.IsSelected = true; }; btnAutoTestLeft.MouseUpEventHandler += (sender, e) => { btnAutoTestLeft.IsSelected = false; if (pageIndex > 1) { MainPage.Loading.Start (); System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { try { pageIndex--; btnAutoTest.Text = pageIndex.ToString (); InitInfraredView (); } catch { } finally { MainPage.Loading.Hide (); } }); }); } }; btnAutoTestRight.MouseUpEventHandler += (sender, e) => { btnAutoTestRight.IsSelected = false; if (pageIndex < pageCount) { MainPage.Loading.Start (); System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { try { pageIndex++; btnAutoTest.Text = pageIndex.ToString (); InitInfraredView (); } catch { } finally { MainPage.Loading.Hide (); } }); }); } }; Button b2 = new Button () { Width = LayoutParams.MatchParent, Height = 1, BackgroundColor = 0xFFDBDDDF, }; brandFlipView.AddChidren (b2); #region type if (isACInfrared) { modulTypeString = "6_AC__0_0_0_0_0"; updateInfraredBytes [26] = 1;//后面修改了指令多了一个byte用来区分是否是红外空调 } else { modulTypeString = "5_TV__0_0_0_0_0"; updateInfraredBytes [26] = 0; } #endregion } string modulTypeString = ""; /// /// 查找设备品牌 /// void FindBrand () { var dialog = new Dialog () { BackgroundColor = SkinStyle.Current.DialogColor, Width = Application.GetRealWidth (540), Height = Application.GetRealHeight (744 + 80), }; var btnTitle = new Button () { Width = dialog.Width, Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.TitileView, TextAlignment = TextAlignment.Center, Text = "Select Brand", TextColor = SkinStyle.Current.TextColor1, Enable = false }; dialog.AddChidren (btnTitle); var verticalScrolView = new VerticalScrolViewLayout () { Height = Application.GetRealHeight (520), Width = Application.GetRealWidth (480), Gravity = Gravity.CenterHorizontal, Y = btnTitle.Height + Application.GetRealHeight (20), BackgroundColor = SkinStyle.Current.ViewColor }; dialog.AddChidren (verticalScrolView); var FlipView = new FrameLayout () { X = verticalScrolView.X, Y = verticalScrolView.Bottom + Application.GetRealHeight(10), Width = verticalScrolView.Width, Height = Application.GetRealHeight (80), BackgroundColor = SkinStyle.Current.ViewColor }; dialog.AddChidren (FlipView); var btnAutoTestLeft = new Button () { Width = Application.GetRealWidth (158), UnSelectedImagePath = @"AC/ACDialogRegresses.png", SelectedImagePath = @"AC/ACDialogRegressesOn.png", }; FlipView.AddChidren (btnAutoTestLeft); btnAutoTestLeft.MouseDownEventHandler += (sender, e) => { btnAutoTestLeft.IsSelected = true; }; var btnPageText = new Button () { X = btnAutoTestLeft.Right, Width = Application.GetRealWidth (480 - 158 - 158), Text = pageIndex.ToString (), TextColor = SkinStyle.Current.TextColor1 }; FlipView.AddChidren (btnPageText); var btnAutoTestRight = new Button () { Width = Application.GetRealWidth (158), X = btnPageText.Right, UnSelectedImagePath = @"AC/ACDialogForward.png", SelectedImagePath = @"AC/ACDialogForwardOn.png", }; FlipView.AddChidren (btnAutoTestRight); btnAutoTestRight.MouseDownEventHandler += (sender, e) => { btnAutoTestRight.IsSelected = true; }; btnAutoTestLeft.MouseUpEventHandler += (sender, e) => { btnAutoTestLeft.IsSelected = false; if (pageIndex > 1) { MainPage.Loading.Start (); System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { try { pageIndex--; btnPageText.Text = pageIndex.ToString (); InitBrandView (verticalScrolView, dialog); } catch { } finally { MainPage.Loading.Hide (); } }); }); } }; btnAutoTestRight.MouseUpEventHandler += (sender, e) => { btnAutoTestRight.IsSelected = false; if (pageIndex < pageCount) { MainPage.Loading.Start (); System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { try { pageIndex++; btnPageText.Text = pageIndex.ToString (); InitBrandView (verticalScrolView, dialog); } catch { } finally { MainPage.Loading.Hide (); } }); }); } }; var b2 = new Button () { Width = LayoutParams.MatchParent, Height = 1, BackgroundColor = 0xFFDBDDDF, }; FlipView.AddChidren (b2); Button btnBack = new Button () { Y = dialog.Height - Application.GetRealHeight (90), Height = Application.GetRealHeight (90), TextID = R.MyInternationalizationString.cancel, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, BackgroundColor = SkinStyle.Current.MainColor, }; dialog.AddChidren (btnBack); btnBack.MouseUpEventHandler += (sender, e) => { dialog.Close (); }; dialog.Show (); verticalScrolView.RemoveAll (); brandView.RemoveAll (); MainPage.Loading.Start (); try { modulTypeNumber = modulTypeString.Split ('_') [0]; string path = "InfraredType/" + modulTypeNumber + ".txt"; if (System.IO.File.Exists (System.IO.Path.Combine (IO.FileUtils.RootPath, path))) { path = System.IO.Path.Combine (IO.FileUtils.RootPath, path); } StreamReader sr = new StreamReader (path, CommonPage.MyEncodingUTF8); string line = ""; brandDataList = new List (); while ((line += sr.ReadLine ()) != null && line != "") { if (!line.Contains ("_0_0_0_0_0")) continue; brandDataList.Add (line); line = ""; } sr.Close (); pageIndex = 1; pageCount = brandDataList.Count / 50; if ((brandDataList.Count % 50) > 0) pageCount++; InitBrandView (verticalScrolView, dialog); } catch (Exception ex) { Console.WriteLine (ex.ToString ()); } finally { MainPage.Loading.Hide (); } } void InitBrandView (VerticalScrolViewLayout verticalScrolView, Dialog dialog) { verticalScrolView.RemoveAll (); for (int i = (pageIndex - 1) * 50; i < pageIndex * 50; i++) { if (i >= brandDataList.Count) break; string brandData = brandDataList [i]; string brandName = brandData.Split ('_') [6]; RowLayout rlBrandName = new RowLayout () { Height = Application.GetRealHeight (90), }; verticalScrolView.AddChidren (rlBrandName); Button btnBrandName_InDialog = new Button () { Text = brandName.Trim (), TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, Tag = brandData }; rlBrandName.AddChidren (btnBrandName_InDialog); btnBrandName_InDialog.MouseUpEventHandler += (sender2, e2) => { dialog.Close (); btnBrandName.Text = btnBrandName_InDialog.Tag.ToString ().Split ('_') [6]; btnBrandData_Tag = btnBrandName_InDialog.Tag; FindInrared (); }; } } /// /// 查找红外 /// void FindInrared ( ) { MainPage.Loading.Start (); System.Threading.Tasks.Task.Run (() => { string [] listStrInfrared = btnBrandData_Tag.ToString ().Split ('_');//红外库数据 List listInfrared = new List (listStrInfrared [5].Replace ("}", "").Replace ("\r\n", "").Replace (" ", "").Split (',')); listInfrared.RemoveAt (0); infraredDataList = new string [listInfrared.Count]; string tempStr = null; string typeStr = listStrInfrared [0]; string path = "InfraredCode/" + typeStr + ".txt"; if (System.IO.File.Exists (System.IO.Path.Combine (IO.FileUtils.RootPath, path))) { path = System.IO.Path.Combine (IO.FileUtils.RootPath, path); } StreamReader sr = new StreamReader (path, CommonPage.MyEncodingUTF8); string line = ""; Application.RunOnMainThread (() => { try { while ((line += sr.ReadLine ()) != null && line != "") { if (!line.Contains ("}")) continue; tempStr = line; if (tempStr.Split ('_') [0] == listStrInfrared [0]) { string infraredNumber = tempStr.Split ('_') [1].Trim (); if (listInfrared.Contains (infraredNumber)) { infraredDataList [listInfrared.IndexOf (infraredNumber)] = tempStr; } } line = ""; } pageIndex = 1; pageCount = infraredDataList.Length / 50; if ((infraredDataList.Length % 50) > 0) pageCount++; InitInfraredView (); } catch (Exception ex) { Console.WriteLine ("dbnew3 error :" + ex.ToString ()); } finally { MainPage.Loading.Hide (); } }); }); } public void InitInfraredView () { brandFlipView.Visible = true; brandView.RemoveAll (); for (int i = (pageIndex - 1) * 50; i < pageIndex * 50; i++) { if (i >= infraredDataList.Length) break; if (infraredDataList [i] == null) continue; var flEquipmentView = new RowLayout () { Height = Application.GetRealHeight (90) }; brandView.AddChidren (flEquipmentView); string infraredName = btnBrandData_Tag.ToString ().Split ('_') [6] + " " + (i + 1).ToString (); string modelData = btnBrandData_Tag.ToString (); if (modelData.Split (',') [i + 1].Contains ("%")) { infraredName = modelData.Split (',') [i + 1].Replace ('%', ';').Trim (); } var btnInfraredCode = new Button () { Width = Application.GetRealWidth (400), X = Application.GetRealWidth (50), TextAlignment = TextAlignment.CenterLeft, Text = infraredName, Tag = i,//红外码 TextColor = SkinStyle.Current.TextColor1 }; flEquipmentView.AddChidren (btnInfraredCode); btnInfraredCode.MouseUpEventHandler += (sender, e) => { if (btnInfraredCode.Text.Length > 10) { new Alert ("", infraredName, Language.StringByID (R.MyInternationalizationString.Close)).Show (); } }; Button btnText = new Button () { Width = Application.GetRealWidth (140), Height = Application.GetRealHeight (60), TextID = R.MyInternationalizationString.Test, X = btnInfraredCode.Right + Application.GetRealWidth (10), Gravity = Gravity.CenterVertical, BackgroundColor = SkinStyle.Current.ButtonColor, Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, TextColor = SkinStyle.Current.TextColor1, }; flEquipmentView.AddChidren (btnText); //测试按钮 btnText.MouseUpEventHandler += (sender3, e3) => { Application.RunOnMainThread (() => { MainPage.Loading.Start (); }); System.Threading.Tasks.Task.Run (() => { infraredDataIndex = Convert.ToInt32 (btnInfraredCode.Tag); string infraredString = infraredDataList [infraredDataIndex]; string iCode = infraredString.Split ('_') [2]; //红外码 string [] byteICode = iCode.Substring (0, iCode.IndexOf ("}")).Replace ("{", "").Trim ().Split (','); byte hByte = Convert.ToByte (Convert.ToInt32 (infraredString.Split ('_') [1].Trim ()) / 256); byte lByte = Convert.ToByte (Convert.ToInt32 (infraredString.Split ('_') [1].Trim ()) % 256); byte InfraredTypeCode = Convert.ToByte (infraredString.Split ('_') [0]); updateInfraredBytes [0] = TestByteIndex;//测试的红外码存放区域 updateInfraredBytes [1] = 0; updateInfraredBytes [2] = Convert.ToByte ((int)InfraredTypeCode - 1);//设备码 updateInfraredBytes [3] = hByte;//组码 updateInfraredBytes [4] = lByte;//组码 updateInfraredBytes [5] = Convert.ToByte (byteICode.Length);//红外数据总长度 (1byte) var resule = UpdataInfrared (updateInfraredBytes, byteICode); Application.RunOnMainThread (() => { btnBrandName.Text = btnInfraredCode.Text; MainPage.Loading.Hide (); if (!resule) { new Alert ("", Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } Dialog dialog = new Dialog () { Width = Application.GetRealWidth (520), Height = Application.GetRealHeight (870 ), }; FrameLayout dialogBodyView = new FrameLayout () { BackgroundColor = SkinStyle.Current.ViewColor, }; dialog.AddChidren (dialogBodyView); #region top View FrameLayout topView = new FrameLayout () { Height = Application.GetRealHeight (100), BackgroundColor = SkinStyle.Current.MainColor }; dialogBodyView.AddChidren (topView); var btnInfraredName_Dialog = new Button () { Text = infraredName, TextColor = SkinStyle.Current.TextColor1, Enable = false, TextAlignment = TextAlignment.Center, }; topView.AddChidren (btnInfraredName_Dialog); #endregion if (InfraredTypeCode == 3 || InfraredTypeCode == 5) { Random ran = new Random (); Button btnSwitch = new Button () { Width = Application.GetRealWidth (150), Height = Application.GetRealHeight (55), X = Application.GetRealWidth (25), Y = topView.Bottom + Application.GetRealHeight (20), Radius = 5, BackgroundColor = SkinStyle.Current.ViewColor, BorderWidth=1, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextColor = SkinStyle.Current.TextColor1, TextID = R.MyInternationalizationString.Power }; dialog.AddChidren (btnSwitch); btnSwitch.MouseDownEventHandler += (sender, e) => { btnSwitch.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btnSwitch.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btnChannelUp = new Button () { Width = Application.GetRealWidth (150), Height = Application.GetRealHeight (55), X = btnSwitch.Right + Application.GetRealWidth (10), TextColor = SkinStyle.Current.TextColor1, Y = btnSwitch.Y, BorderWidth = 1, Radius = 5, BackgroundColor = SkinStyle.Current.ViewColor, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.ChannelUp }; dialog.AddChidren (btnChannelUp); btnChannelUp.MouseDownEventHandler += (sender, e) => { btnChannelUp.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btnChannelUp.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btnChannelDown = new Button () { Width = Application.GetRealWidth (150), Height = Application.GetRealHeight (55), X = btnChannelUp.Right + Application.GetRealWidth (10), Y = btnChannelUp.Y, TextColor = SkinStyle.Current.TextColor1, BorderWidth = 1, Radius = 5, BackgroundColor = SkinStyle.Current.ViewColor, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.ChannelDown }; dialog.AddChidren (btnChannelDown); btnChannelDown.MouseDownEventHandler += (sender, e) => { btnChannelDown.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btnChannelDown.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btnMute = new Button { Width = Application.GetRealWidth (150), Height = Application.GetRealHeight (55), X = Application.GetRealWidth (25), Y = btnSwitch.Bottom + Application.GetRealHeight (20), TextColor = SkinStyle.Current.TextColor1, BorderWidth = 1, Radius = 5, BackgroundColor = SkinStyle.Current.ViewColor, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.Menu }; dialog.AddChidren (btnMute); btnMute.MouseDownEventHandler += (sender, e) => { btnMute.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btnMute.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btnVolumeUp = new Button () { Width = Application.GetRealWidth (150), Height = Application.GetRealHeight (55), X = btnMute.Right + Application.GetRealWidth (10), Y = btnSwitch.Bottom + Application.GetRealHeight (20), TextColor = SkinStyle.Current.TextColor1, BorderWidth = 1, Radius = 5, BackgroundColor = SkinStyle.Current.ViewColor, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.VolumeUp, }; dialog.AddChidren (btnVolumeUp); btnVolumeUp.MouseDownEventHandler += (sender, e) => { btnVolumeUp.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btnVolumeUp.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btnVolumeDown = new Button () { Width = Application.GetRealWidth (150), Height = Application.GetRealHeight (55), X = btnVolumeUp.Right + Application.GetRealWidth (10), Y = btnVolumeUp.Y, TextColor = SkinStyle.Current.TextColor1, BorderWidth = 1, Radius = 5, BackgroundColor = SkinStyle.Current.ViewColor, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.VolumeDown, }; dialog.AddChidren (btnVolumeDown); btnVolumeDown.MouseDownEventHandler += (sender, e) => { btnVolumeDown.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btnVolumeDown.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btn1 = new Button () { X = Application.GetRealWidth (30), Y = btnMute.Bottom + Application.GetRealHeight (30), Width = Application.GetRealWidth (104), Height = Application.GetRealHeight (90), UnSelectedImagePath = "TV/TV2_1.png", SelectedImagePath = "TV/TV2_1_on.png", }; dialog.AddChidren (btn1); btn1.MouseDownEventHandler += (sender, e) => { btn1.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btn1.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btn2 = new Button () { X = btn1.Right + Application.GetRealWidth (15), Y = btn1.Y, Width = Application.GetRealWidth (104), Height = Application.GetRealHeight (90), UnSelectedImagePath = "TV/TV2_2.png", SelectedImagePath = "TV/TV2_2_on.png", }; dialog.AddChidren (btn2); btn2.MouseDownEventHandler += (sender, e) => { btn2.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btn2.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btn3 = new Button () { X = btn2.Right + Application.GetRealWidth (15), Y = btn2.Y, Width = Application.GetRealWidth (104), Height = Application.GetRealHeight (90), UnSelectedImagePath = "TV/TV2_3.png", SelectedImagePath = "TV/TV2_3_on.png", }; dialog.AddChidren (btn3); btn3.MouseDownEventHandler += (sender, e) => { btn3.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btn3.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btn4 = new Button () { X = btn3.Right + Application.GetRealWidth (15), Y = btn3.Y, Width = Application.GetRealWidth (104), Height = Application.GetRealHeight (90), UnSelectedImagePath = "TV/TV2_4.png", SelectedImagePath = "TV/TV2_4_on.png", }; dialog.AddChidren (btn4); btn4.MouseDownEventHandler += (sender, e) => { btn4.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btn4.IsSelected = false; }); }) { IsBackground = true }.Start (); ; }; Button btn5 = new Button () { X = btn1.X, Y = btn1.Bottom + Application.GetRealHeight (20), Width = Application.GetRealWidth (104), Height = Application.GetRealHeight (90), UnSelectedImagePath = "TV/TV2_5.png", SelectedImagePath = "TV/TV2_5_on.png", }; dialog.AddChidren (btn5); btn5.MouseDownEventHandler += (sender, e) => { btn5.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btn5.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btn6 = new Button () { X = btn5.Right + Application.GetRealWidth (15), Y = btn5.Y, Width = Application.GetRealWidth (104), Height = Application.GetRealHeight (90), UnSelectedImagePath = "TV/TV2_6.png", SelectedImagePath = "TV/TV2_6_on.png", }; dialog.AddChidren (btn6); btn6.MouseDownEventHandler += (sender, e) => { btn6.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btn6.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btn7 = new Button () { X = btn6.Right + Application.GetRealWidth (15), Y = btn6.Y, Width = Application.GetRealWidth (104), Height = Application.GetRealHeight (90), UnSelectedImagePath = "TV/TV2_7.png", SelectedImagePath = "TV/TV2_7_on.png", }; dialog.AddChidren (btn7); btn7.MouseDownEventHandler += (sender, e) => { btn7.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btn7.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btn8 = new Button () { X = btn7.Right + Application.GetRealWidth (15), Y = btn7.Y, Width = Application.GetRealWidth (104), Height = Application.GetRealHeight (90), UnSelectedImagePath = "TV/TV2_8.png", SelectedImagePath = "TV/TV2_8_on.png", }; dialog.AddChidren (btn8); btn8.MouseDownEventHandler += (sender, e) => { btn8.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btn8.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btn9 = new Button () { X = btn1.X, Y = btn5.Bottom + Application.GetRealHeight (20), Width = Application.GetRealWidth (104), Height = Application.GetRealHeight (90), UnSelectedImagePath = "TV/TV2_9.png", SelectedImagePath = "TV/TV2_9_on.png", }; dialog.AddChidren (btn9); btn9.MouseDownEventHandler += (sender, e) => { btn9.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btn9.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btn0 = new Button () { X = btn9.Right + Application.GetRealWidth (15), Y = btn9.Y, Width = Application.GetRealWidth (100), Height = Application.GetRealHeight (90), UnSelectedImagePath = "TV/TVNum0.png", SelectedImagePath = "TV/TVNum0_on.png", }; dialog.AddChidren (btn0); btn0.MouseDownEventHandler += (sender, e) => { btn0.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btn0.IsSelected = false; }); }) { IsBackground = true }.Start (); }; Button btnOK = new Button () { X = btn0.Right + Application.GetRealWidth (35), Y = btn0.Y, Width = Application.GetRealWidth (190), Height = Application.GetRealHeight (90), UnSelectedImagePath = "TV/TV2_OK.png", SelectedImagePath = "TV/TV2_OK_on.png", }; dialog.AddChidren (btnOK); btnOK.MouseDownEventHandler += (sender, e) => { btnOK.IsSelected = true; new System.Threading.Thread (() => { System.Threading.Thread.Sleep (1000); Application.RunOnMainThread (() => { btnOK.IsSelected = false; }); }) { IsBackground = true }.Start (); }; if (InfraredTypeCode == 5) //电视 { btnSwitch.MouseUpEventHandler += (sender4, e4) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.Power; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btnMute.TextID = R.MyInternationalizationString.Mute; btnMute.MouseUpEventHandler += (sender4, e4) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.Mute; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btnChannelUp.MouseUpEventHandler += (sender4, e4) => { int RandKey = ran.Next (0, 255); Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, (byte)InfraredCode_TV.ChannelUp, 0, 0, Convert.ToByte (RandKey) }); }; btnChannelDown.MouseUpEventHandler += (sender4, e4) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.ChannelDown; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btnVolumeUp.MouseUpEventHandler += (sender4, e4) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.VolUp; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btnVolumeDown.MouseUpEventHandler += (sender4, e4) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.VolDown; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; #region ---数字--- btn1.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.One; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btn2.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.Two; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btn3.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.Three; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btn4.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.Four; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btn5.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.Five; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btn6.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.Six; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btn7.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.Seven; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btn8.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.Eight; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btn9.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.Nine; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btn0.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.Zero; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; btnOK.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); textByte = (byte)InfraredCode_TV.Confrim; Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) }); }; #endregion } } if (InfraredTypeCode == 6)//空调 { ///129回路号,193A 指令回路号在1-128之间,这里是测试所以用129 ///1:表示开,0关(之前的0是无用字节) index[8] ///模式0制冷 1制热,2通风 3自动 4抽湿 index[9] ///风速0自动 1高峰 2中风 3低风 i ///扫风开关 0关 1开 index[12] byte [] acHostBytes = new byte [] { 129, 0, 0, 16, 16, 16, 16, 16, 0, 0, 0, 16, 0 }; byte temperature = 16; Button btnSwitch = new Button () { Width = Application.GetRealWidth (80), Height = Application.GetRealHeight (80), X = Application.GetRealWidth (520 - 80 - 55), Y = topView.Bottom + Application.GetRealHeight (10), UnSelectedImagePath = "AC/ACDialogSwitch.png", SelectedImagePath = "AC/ACDialogSwitchOn.png", }; dialogBodyView.AddChidren (btnSwitch); btnSwitch.MouseUpEventHandler += (sender, e) => { if (acHostBytes [8] == 0) { acHostBytes [8] = 1; btnSwitch.IsSelected = true; } else { acHostBytes [8] = 0; btnSwitch.IsSelected = false; } System.Threading.Tasks.Task.Run (() => { Control.ControlBytesSend (Command.SetACMode, common.SubnetID, common.DeviceID, acHostBytes); }); }; #region ---temperatureView--- FrameLayout temperatureView = new FrameLayout () { Height = Application.GetRealHeight (135), Y = btnSwitch.Bottom, }; dialogBodyView.AddChidren (temperatureView); Button btnReduceTemperature = new Button () { Width = Application.GetMinRealAverage (129), Height = Application.GetMinRealAverage (129), X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "AC/ACDialog-.png", SelectedImagePath = "AC/ACDialog-On.png", }; temperatureView.AddChidren (btnReduceTemperature); Button btnSetTemperature = new Button () { Width = Application.GetRealWidth (194), Gravity = Gravity.CenterHorizontal, TextColor = SkinStyle.Current.TextColor1, Y = btnReduceTemperature.Y, Text = "16°C", TextSize = 24, TextAlignment = TextAlignment.Center, Enable = false, }; temperatureView.AddChidren (btnSetTemperature); Button btnAddTemperature = new Button () { Width = Application.GetMinRealAverage (129), Height = Application.GetMinRealAverage (129), X = Application.GetRealWidth (520 - 129 - 30), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "AC/ACDialog+.png", SelectedImagePath = "AC/ACDialog+On.png", }; temperatureView.AddChidren (btnAddTemperature); btnReduceTemperature.MouseDownEventHandler += (sender, e) => { btnReduceTemperature.IsSelected = true; }; btnReduceTemperature.MouseUpEventHandler += (sender, e) => { btnReduceTemperature.IsSelected = false; if (temperature > 16) { temperature--; btnSetTemperature.Text = temperature.ToString () + "°C"; acHostBytes [11] = temperature; Control.ControlBytesSend (Command.SetACMode, common.SubnetID, common.DeviceID, acHostBytes); } }; btnAddTemperature.MouseDownEventHandler += (sender, e) => { btnAddTemperature.IsSelected = true; }; btnAddTemperature.MouseUpEventHandler += (sender, e) => { btnAddTemperature.IsSelected = false; btnReduceTemperature.IsSelected = false; if (temperature < 30) { temperature++; btnSetTemperature.Text = temperature.ToString () + "°C"; acHostBytes [11] = temperature; Control.ControlBytesSend (Command.SetACMode, common.SubnetID, common.DeviceID, acHostBytes); } }; #endregion List ModelList = new List (); List WindModelList = new List (); ModelList.Add ("Cool"); ModelList.Add ("Hot"); ModelList.Add ("Ventilae"); ModelList.Add ("Auto"); ModelList.Add ("Dehumidify"); WindModelList.Add ("Auto"); WindModelList.Add ("High"); WindModelList.Add ("Medium"); WindModelList.Add ("Low"); #region 模式 var acModeView = new FrameLayout () { Height = Application.GetRealHeight (140), Width = LayoutParams.MatchParent, Y = temperatureView.Bottom, }; dialogBodyView.AddChidren (acModeView); Button btnACModeLeft = new Button () { Width = Application.GetMinRealAverage (129), Height = Application.GetMinRealAverage (129), X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "AC/ACLeft.png", SelectedImagePath = "AC/ACLeft.png", }; acModeView.AddChidren (btnACModeLeft); //var btnModeName = new Button () { // Width = Application.GetRealWidth (200), // Height = Application.GetRealHeight (30), // Gravity = Gravity.CenterHorizontal, // Y = Application.GetRealHeight (15), // TextID = R.MyInternationalizationString.UserACMode, // TextColor = SkinStyle.Current.ViewColor, //}; //acModeView.AddChidren (btnModeName); Button btnModeIcon = new Button () { Width = Application.GetMinRealAverage (130), Height = Application.GetMinRealAverage (135), Gravity = Gravity.Center, Y = Application.GetRealHeight (20), UnSelectedImagePath = "AC/ACRefrigeration.png", }; acModeView.AddChidren (btnModeIcon); //Button btnModeText = new Button () { // Width = Application.GetRealWidth (200), // Height = Application.GetRealHeight (50), // Text = ModelList [0], // Gravity = Gravity.CenterHorizontal, // TextAlignment = TextAlignment.TopCenter, // Y = btnModeIcon.Bottom - Application.GetRealHeight (15), //}; //acModeView.AddChidren (btnModeText); Button btnACModeRight = new Button () { Width = Application.GetMinRealAverage (129), Height = Application.GetMinRealAverage (129), X = Application.GetRealWidth (520 - 129 - 30), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "AC/ACRight.png", SelectedImagePath = "AC/ACRightSelected.png", }; acModeView.AddChidren (btnACModeRight); btnACModeRight.MouseDownEventHandler += (sender, e) => { btnACModeRight.IsSelected = true; }; btnACModeRight.MouseUpEventHandler += (sender, e) => { btnACModeRight.IsSelected = false; //模式0制冷 1制热,2通风 3自动 4抽湿 index[9] if (acHostBytes [9] < 5 && acHostBytes [9] >=0) acHostBytes [9]++; else acHostBytes[9] = 0; UpdataACHostModeIcon (acHostBytes [9], btnModeIcon, ModelList); Control.ControlBytesSend (Command.SetACMode, common.SubnetID, common.DeviceID, acHostBytes); }; btnACModeLeft.MouseDownEventHandler += (sender, e) => { btnACModeLeft.IsSelected = true; }; btnACModeLeft.MouseUpEventHandler += (sender, e) => { btnACModeLeft.IsSelected = false; if (acHostBytes [9] == 0 || acHostBytes [9] > 4) acHostBytes [9] = 4; else acHostBytes [9]--; UpdataACHostModeIcon (acHostBytes [9], btnModeIcon, ModelList); Control.ControlBytesSend (Command.SetACMode, common.SubnetID, common.DeviceID, acHostBytes); }; #endregion #region 风速 var acWindView = new FrameLayout () { Height = Application.GetRealHeight (140), Width = LayoutParams.MatchParent, Y = acModeView.Bottom, }; dialogBodyView.AddChidren (acWindView); Button btnACWindLeft = new Button () { Width = Application.GetMinRealAverage (129), Height = Application.GetMinRealAverage (129), X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "AC/ACLeft.png", SelectedImagePath = "AC/ACLeft.png", }; acWindView.AddChidren (btnACWindLeft); //var btnWindName = new Button () { // Width = Application.GetRealWidth (200), // Height = Application.GetRealHeight (30), // Gravity = Gravity.CenterHorizontal, // Y = Application.GetRealHeight (15), // TextID = R.MyInternationalizationString.Speed, // TextColor = SkinStyle.Current.ViewColor, //}; //acWindView.AddChidren (btnWindName); Button btnWindIcon = new Button () { Width = Application.GetMinRealAverage (130), Height = Application.GetMinRealAverage (135), Gravity = Gravity.Center, Y = Application.GetRealHeight (20), UnSelectedImagePath = "AC/ACAuto.png", }; acWindView.AddChidren (btnWindIcon); //Button btnWindModeText = new Button () { // Width = Application.GetRealWidth (200), // Height = Application.GetRealHeight (50), // Text = WindModelList [0], // Gravity = Gravity.CenterHorizontal, // Y = btnWindIcon.Bottom - Application.GetRealHeight (15), //}; //acWindView.AddChidren (btnWindModeText); Button btnACWindRight = new Button () { Width = Application.GetMinRealAverage (129), Height = Application.GetMinRealAverage (129), X = btnACModeRight.X, Gravity = Gravity.CenterVertical, UnSelectedImagePath = "AC/ACRight.png", SelectedImagePath = "AC/ACRightSelected.png", }; btnACWindLeft.MouseDownEventHandler += (sender, e) => { btnACWindLeft.IsSelected = true; }; btnACWindLeft.MouseDownEventHandler += (sender, e) => { btnACWindLeft.IsSelected = true; }; btnACWindLeft.MouseUpEventHandler += (sender, e) => { btnACWindLeft.IsSelected = false; if (acHostBytes [10] == 0 || acHostBytes [10] > 3) acHostBytes [10] = 3; else acHostBytes [10]--; UpdataACHostWindIcon (acHostBytes [10], btnWindIcon, WindModelList); Control.ControlBytesSend (Command.SetACMode, common.SubnetID, common.DeviceID, acHostBytes); }; acWindView.AddChidren (btnACWindRight); btnACWindRight.MouseDownEventHandler += (sender, e) => { btnACWindRight.IsSelected = true; }; btnACWindRight.MouseUpEventHandler += (sender, e) => { btnACWindRight.IsSelected = false; if (acHostBytes [10] == 0 || acHostBytes [10] > 3) acHostBytes [10] = 0; else acHostBytes[10]++; UpdataACHostWindIcon (acHostBytes [10], btnWindIcon, WindModelList); Control.ControlBytesSend (Command.SetACMode, common.SubnetID, common.DeviceID, acHostBytes); }; #endregion } #region ---testTime--- var rowLine = new RowLayout () { Y = Application.GetRealHeight (870 - 90 - 90 - 90), Height = 1 }; dialogBodyView.AddChidren (rowLine); RowLayout autoTestTimeView = new RowLayout () { Height = Application.GetRealHeight (90), Y = rowLine.Bottom }; dialogBodyView.AddChidren (autoTestTimeView); Button btnAutoTestTimeLeft = new Button () { Width = Application.GetRealWidth (158), UnSelectedImagePath = @"AC/DialogTime-.png", SelectedImagePath = @"AC/DialogTime-On.png", }; autoTestTimeView.AddChidren (btnAutoTestTimeLeft); Button btnAutoTestTime = new Button () { X = btnAutoTestTimeLeft.Right, Width = Application.GetRealWidth (520 - 158 - 158), TextColor = SkinStyle.Current.TextColor1, BorderWidth = 2, BorderColor = SkinStyle.Current.Transparent, Radius = 5, Text = Language.StringByID (R.MyInternationalizationString.IntervalTime).Replace ("--", textTime.ToString ()) }; autoTestTimeView.AddChidren (btnAutoTestTime); Button btnAutoTestTimeRight = new Button () { Width = Application.GetRealWidth (158), X = btnAutoTestTime.Right, UnSelectedImagePath = @"AC/DialogTime+.png", SelectedImagePath = @"AC/DialogTime+On.png", }; autoTestTimeView.AddChidren (btnAutoTestTimeRight); btnAutoTestTimeLeft.MouseDownEventHandler += (sender, e) => { btnAutoTestTimeLeft.IsSelected = true; }; btnAutoTestTimeLeft.MouseUpEventHandler += (sender, e) => { btnAutoTestTimeLeft.IsSelected = false; if (textTime > 1) { textTime--; btnAutoTestTime.Text = Language.StringByID (R.MyInternationalizationString.IntervalTime).Replace ("--", textTime.ToString ()); } }; btnAutoTestTimeRight.MouseDownEventHandler += (sender, e) => { btnAutoTestTimeRight.IsSelected = true; }; btnAutoTestTimeRight.MouseUpEventHandler += (sender, e) => { btnAutoTestTimeRight.IsSelected = false; if (textTime < 10) { textTime++; btnAutoTestTime.Text = Language.StringByID (R.MyInternationalizationString.IntervalTime).Replace ("--", textTime.ToString ()); } }; #endregion #region ---autoTest--- RowLayout autoTestView = new RowLayout () { Height = Application.GetRealHeight (90) , Y = Application.GetRealHeight (870 -90- 90) , }; dialogBodyView.AddChidren (autoTestView); Button btnAutoTestLeft = new Button () { Width = Application.GetRealWidth (158), UnSelectedImagePath = @"AC/ACDialogRegresses.png", SelectedImagePath = @"AC/ACDialogRegressesOn.png", }; autoTestView.AddChidren (btnAutoTestLeft); Button btnAutoTest = new Button () { X = btnAutoTestLeft.Right, Width = Application.GetRealWidth (520 - 158 - 158), TextColor = SkinStyle.Current.TextColor1, BorderWidth = 2, BorderColor = SkinStyle.Current.Transparent, Radius = 5, TextID = R.MyInternationalizationString.AutoTest }; autoTestView.AddChidren (btnAutoTest); Button btnAutoTestRight = new Button () { Width = Application.GetRealWidth (158), X = btnAutoTest.Right, UnSelectedImagePath = @"AC/ACDialogForward.png", SelectedImagePath = @"AC/ACDialogForwardOn.png", }; autoTestView.AddChidren (btnAutoTestRight); btnAutoTestLeft.MouseDownEventHandler += (sender, e) => { btnAutoTestLeft.IsSelected = true; }; btnAutoTestRight.MouseDownEventHandler += (sender, e) => { btnAutoTestRight.IsSelected = true; }; btnAutoTestLeft.MouseUpEventHandler += (sender, e) => { btnAutoTestLeft.IsSelected = false; if (infraredDataIndex < 1) return; System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { MainPage.Loading.Start (); }); infraredDataIndex--; infraredString = infraredDataList [infraredDataIndex]; iCode = infraredString.Split ('_') [2]; byteICode = iCode.Substring (0, iCode.IndexOf ("}")).Replace ("{", "").Trim ().Split (','); Console.WriteLine (iCode); hByte = Convert.ToByte (Convert.ToInt32 (infraredString.Split ('_') [1].Trim ()) / 256); lByte = Convert.ToByte (Convert.ToInt32 (infraredString.Split ('_') [1].Trim ()) % 256); InfraredTypeCode = Convert.ToByte (infraredString.Split ('_') [0]); updateInfraredBytes [0] = TestByteIndex;//测试的红外码存放区域 updateInfraredBytes [1] = 0; updateInfraredBytes [2] = Convert.ToByte ((int)InfraredTypeCode - 1);//设备码 updateInfraredBytes [3] = hByte;//组码 updateInfraredBytes [4] = lByte;//组码 updateInfraredBytes [5] = Convert.ToByte (byteICode.Length);//红外数据总长度 (1byte) UpdataInfrared (updateInfraredBytes, byteICode); if (InfraredTypeCode == 6) Control.ControlBytesSendHasReturn (Command.SetACMode, common.SubnetID, common.DeviceID, new byte [] { 129, 0, 0, 16, 16, 16, 16, 16, 1, 0, 0, 16, 0 }); else { Random ran = new Random (); int RandKey = ran.Next (0, 255); Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) }); } Application.RunOnMainThread (() => { btnBrandName.Text = btnInfraredCode.Text; infraredName = btnBrandData_Tag.ToString ().Split ('_') [6] + " " + (infraredDataIndex + 1).ToString (); modelData = btnBrandData_Tag.ToString (); if (modelData.Split (',') [i + 1].Contains ("%")) { infraredName = modelData.Split (',') [i + 1].Replace ('%', ';').Trim (); } btnInfraredName_Dialog.Text = infraredName; MainPage.Loading.Hide (); }); }); }; btnAutoTestRight.MouseUpEventHandler += (sender, e) => { btnAutoTestRight.IsSelected = false; if (infraredDataIndex >= infraredDataList.Length) return; System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { MainPage.Loading.Start (); }); infraredDataIndex++; infraredString = infraredDataList [infraredDataIndex]; iCode = infraredString.Split ('_') [2]; byteICode = iCode.Substring (0, iCode.IndexOf ("}")).Replace ("{", "").Trim ().Split (','); Console.WriteLine (iCode); hByte = Convert.ToByte (Convert.ToInt32 (infraredString.Split ('_') [1].Trim ()) / 256); lByte = Convert.ToByte (Convert.ToInt32 (infraredString.Split ('_') [1].Trim ()) % 256); InfraredTypeCode = Convert.ToByte (infraredString.Split ('_') [0]); updateInfraredBytes [0] = TestByteIndex;//测试的红外码存放区域 updateInfraredBytes [1] = 0; updateInfraredBytes [2] = Convert.ToByte ((int)InfraredTypeCode - 1);//设备码 updateInfraredBytes [3] = hByte;//组码 updateInfraredBytes [4] = lByte;//组码 updateInfraredBytes [5] = Convert.ToByte (byteICode.Length);//红外数据总长度 (1byte) UpdataInfrared (updateInfraredBytes, byteICode); if (InfraredTypeCode == 6) Control.ControlBytesSendHasReturn (Command.SetACMode, common.SubnetID, common.DeviceID, new byte [] { 129, 0, 0, 16, 16, 16, 16, 16, 1, 0, 0, 16, 0 }); else { Random ran = new Random (); int RandKey = ran.Next (0, 255); Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) }); } Application.RunOnMainThread (() => { btnBrandName.Text = btnInfraredCode.Text; infraredName = btnBrandData_Tag.ToString ().Split ('_') [6] + " " + (infraredDataIndex + 1).ToString (); modelData = btnBrandData_Tag.ToString (); if (modelData.Split (',') [i + 1].Contains ("%")) { infraredName = modelData.Split (',') [i + 1].Replace ('%', ';').Trim (); } btnInfraredName_Dialog.Text = infraredName; MainPage.Loading.Hide (); }); }); }; btnAutoTest.MouseUpEventHandler += (sender, e) => { if (!btnAutoTest.IsSelected) { btnAutoTest.IsSelected = true; btnAutoTest.TextColor = SkinStyle.Current.SelectedColor; btnAutoTest.BorderColor = SkinStyle.Current.SelectedColor; System.Threading.Tasks.Task.Run (() => { while (btnAutoTest.IsSelected) { Application.RunOnMainThread (() => { MainPage.Loading.Start (); }); infraredDataIndex++; if (infraredDataIndex >= infraredDataList.Length) { Application.RunOnMainThread (() => { btnAutoTest.IsSelected = false; MainPage.Loading.Hide (); return; }); } infraredString = infraredDataList [infraredDataIndex]; iCode = infraredString.Split ('_') [2]; byteICode = iCode.Substring (0, iCode.IndexOf ("}")).Replace ("{", "").Trim ().Split (','); Console.WriteLine (iCode); hByte = Convert.ToByte (Convert.ToInt32 (infraredString.Split ('_') [1].Trim ()) / 256); lByte = Convert.ToByte (Convert.ToInt32 (infraredString.Split ('_') [1].Trim ()) % 256); InfraredTypeCode = Convert.ToByte (infraredString.Split ('_') [0]); updateInfraredBytes [0] = TestByteIndex;//测试的红外码存放区域 updateInfraredBytes [1] = 0; updateInfraredBytes [2] = Convert.ToByte ((int)InfraredTypeCode - 1);//设备码 updateInfraredBytes [3] = hByte;//组码 updateInfraredBytes [4] = lByte;//组码 updateInfraredBytes [5] = Convert.ToByte (byteICode.Length);//红外数据总长度 (1byte) UpdataInfrared (updateInfraredBytes, byteICode); if (InfraredTypeCode == 6) Control.ControlBytesSendHasReturn (Command.SetACMode, common.SubnetID, common.DeviceID, new byte [] { 129, 0, 0, 16, 16, 16, 16, 16, 1, 0, 0, 16, 0 }); else { Random ran = new Random (); int RandKey = ran.Next (0, 255); Control.ControlBytesSend (Command.InfraredControl, common.SubnetID, common.DeviceID, new byte [] { Convert.ToByte (port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) }); } Application.RunOnMainThread (() => { btnBrandName.Text = btnInfraredCode.Text; infraredName = btnBrandData_Tag.ToString ().Split ('_') [6] + " " + (infraredDataIndex + 1).ToString (); modelData = btnBrandData_Tag.ToString (); if (modelData.Split (',') [i + 1].Contains ("%")) { infraredName = modelData.Split (',') [i + 1].Replace ('%', ';').Trim (); } btnInfraredName_Dialog.Text = infraredName; MainPage.Loading.Hide (); }); System.Threading.Thread.Sleep (textTime * 1000); } }); } else { btnAutoTest.IsSelected = false; btnAutoTest.TextColor = SkinStyle.Current.TextColor1; btnAutoTest.BorderColor = SkinStyle.Current.Transparent; } }; #endregion #region --- bottom --- FrameLayout bottomView = new FrameLayout () { Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.MainColor, Y = Application.GetRealHeight (870-90), }; dialogBodyView.AddChidren (bottomView); Button btnBack = new Button () { Width = Application.GetRealWidth (258), TextID = R.MyInternationalizationString.Close, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1 }; bottomView.AddChidren (btnBack); btnBack.MouseUpEventHandler += (sender01, e01) => { btnAutoTest.IsSelected = false; dialog.Close (); }; Button btnLineH12 = new Button () { Width = Application.GetRealWidth (4), BackgroundColor = SkinStyle.Current.White20Transparent, X = btnBack.Right, Y = btnBack.Y, }; bottomView.AddChidren (btnLineH12); Button btnSave = new Button () { Width = Application.GetRealWidth (258), X = btnLineH12.Right, TextID = R.MyInternationalizationString.SAVE, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, }; bottomView.AddChidren (btnSave); btnSave.MouseUpEventHandler += (sender, e) => { MainPage.Loading.Start (); new System.Threading.Thread (() => { updateInfraredBytes [0] = common.LoopID; btnAutoTest.IsSelected = false; var result = UpdataInfrared (updateInfraredBytes, byteICode); if (result) { IO.FileUtils.SaveEquipmentMessage (common, common.LoopID.ToString ()); Application.RunOnMainThread (() => { dialog.Close (); this.Close (); }); } else { Application.RunOnMainThread (() => { new Alert ("", "The device did not respond. Please confirm the status of the device and try again.", "OK").Show (); }); } }) { IsBackground = true }.Start (); }; #endregion dialog.Show (); }); }); }; } } /// /// 上传红外码 /// bool UpdataInfrared (byte [] sendBytes, string [] byteICode) { bool resulte = true; //System.Threading.Tasks.Task.Run (() => { try { Application.RunOnMainThread (() => { MainPage.Loading.Start (); }); var fristUpLoadBytes = Control.ControlBytesSendHasReturn (Command.UpLoadInfrared, common.SubnetID, common.DeviceID, sendBytes); if (fristUpLoadBytes == null) resulte = false; byte [] upLoadbyte; if (byteICode.Length > 64) { upLoadbyte = new byte [66]; upLoadbyte [0] = 25; for (int c = 1; c <= byteICode.Length / 64; c++) { upLoadbyte [1] = (byte)c; for (int i = 2; i < byteICode.Length - 1; i++) { upLoadbyte [i] = Convert.ToByte (byteICode [i - 2]); if ((i * c + 64) == byteICode.Length - 2 || i == 64) { Control.ControlBytesSendHasReturn (Command.UpLoadInfrared, common.SubnetID, common.DeviceID, upLoadbyte); } } } } else { upLoadbyte = new byte [2 + byteICode.Length]; upLoadbyte [0] = sendBytes [0]; upLoadbyte [1] = 1; for (int i = 0; i < byteICode.Length; i++) { upLoadbyte [i + 2] = Convert.ToByte (byteICode [i], 16); } Control.ControlBytesSendHasReturn (Command.UpLoadInfrared, common.SubnetID, common.DeviceID, upLoadbyte); } } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } return resulte; //}); } void UpdataACHostModeIcon (byte modeByte, Button btn, List modeList) { ///模式0制冷 1制热,2通风 3自动 4抽湿 index[9] switch (modeByte) { case 0: btn.UnSelectedImagePath = "AC/ACRefrigeration.png"; break; case 1: btn.UnSelectedImagePath = "AC/ACDehumidification.png"; break; case 2: btn.UnSelectedImagePath = "AC/ ACAuto.png"; break; case 3: btn.UnSelectedImagePath = "AC/ACAuto.png"; break; case 4: btn.UnSelectedImagePath = "AC/ACDehumidification.png"; break; } } void UpdataACHostWindIcon (byte windByte, Button btn, List windModelList) { switch (windByte) { case 0: btn.UnSelectedImagePath = "AC/ACAuto.png"; break; case 3: btn.UnSelectedImagePath = "AC/ACLowWind.png"; break; case 2: btn.UnSelectedImagePath = "AC/ACStroke.png"; break; case 1: btn.UnSelectedImagePath = "AC/ACHighWind.png"; break; } } } }