using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Shared.SimpleControl.Phone
{
public class SystemInfrared : FrameLayout
{
private static InfraredMode infraredBase;
private static byte TestByteIndex = 12;
int nameNum;
int pageIndex = 1;
int pageCount = 1;
///
/// 当前的品牌数据
///
object btnBrandData_Tag;
bool isFindBrand = true;
///
/// 设备类型列表
///
List modulTypeList;
///
/// 设备类型编号
///
string modulTypeNumber;
Button btnTypeName;
Button btnEquipmentIcon;
VerticalScrolViewLayout brandView;
FrameLayout brandFlipView;
Button btnTextButton;
byte textByte = 6;
int textTime = 5;
///
/// 品牌名字:按钮
///
Button btnBrandName;
///
/// 品牌列表
///
List brandDataList = new List ();
///
/// 红外码列表
///
string [] infraredDataList;
int infraredDataIndex = 0;
byte [] updateInfraredBytes = new byte [27];
public SystemInfrared ()
{
}
public void ShowSystemInfrared (InfraredMode infrared, Common common, bool isACInfrared = false)
{
//SystemMiddle.hideBottom ();
string infraredType = "";
string [] infraredTypeList;
infraredBase = infrared;
RemoveAll ();
#region top
RowLayout topTitleView = new RowLayout () {
Height = Application.GetRealHeight (98),
Width = LayoutParams.MatchParent,
BackgroundColor = SkinStyle.Current.MainColor
};
AddChidren (topTitleView);
Button backButton = new Button () {
X = Application.GetRealWidth (0),
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (85),
UnSelectedImagePath = "Item/Back.png",
SelectedImagePath = "Item/BackSelected.png",
Gravity = Gravity.CenterVertical,
};
backButton.MouseUpEventHandler += (sender, e) => {
(Parent as PageLayout).PageIndex -= 1;
//SystemEquipmentBase.RefreshView (common);
};
topTitleView.AddChidren (backButton);
EditText textButton = new EditText () {
X = Application.GetRealWidth (30) + backButton.Right,
Height = Application.GetRealHeight (41),
Width = Application.GetRealWidth (400),
Text = infrared.Name,
Gravity = Gravity.CenterVertical,
TextAlignment = TextAlignment.CenterLeft,
BackgroundColor = SkinStyle.Current.Transparent,
SelectedBackgroundColor = 0xFF000000,
Enable = false,
TextSize = 15,
TextColor = SkinStyle.Current.TextColor1
};
topTitleView.AddChidren (textButton);
Button editor = new Button () {
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (70),
UnSelectedImagePath = "Item/Editor.png",
SelectedImagePath = "Item/EditorSelected.png",
Gravity = Gravity.CenterVertical,
};
editor.X = topTitleView.Width - editor.Width - Application.GetRealWidth (30);
topTitleView.AddChidren (editor);
editor.MouseUpEventHandler += (sender, e) => {
if (editor.IsSelected) {
textButton.IsSelected = false;
MainPage.Loading.Start ();
byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (textButton.Text.Trim ());
textButton.IsSelected = editor.IsSelected = textButton.Enable = false;
System.Threading.Tasks.Task.Run (() => {
byte [] updateBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, infrared.SubnetID, infrared.DeviceID, new byte [] {
infrared.BigClass,infrared.MinClass,infrared.LoopID
});
if (updateBytes == null) {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
});
return;
}
byte [] uBytes = new byte [20];
Array.Copy (remakeBytes, 0, uBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20);
Array.Copy (uBytes, 0, updateBytes, 3, 20 < uBytes.Length ? 20 : uBytes.Length);
var reBytes = Control.ControlBytesSendHasReturn (Command.SetDeviceLoopInfo, infrared.SubnetID, infrared.DeviceID, updateBytes);
if (reBytes != null) {
Application.RunOnMainThread (() => {
infrared.Name = textButton.Text.Trim ();
IO.FileUtils.SaveEquipmentMessage (infrared, infrared.LoopID.ToString ());
MainPage.Loading.Hide ();
});
} else {
Application.RunOnMainThread (() => {
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
MainPage.Loading.Hide ();
});
}
});
} else {
textButton.IsSelected = textButton.Enable = textButton.IsSelected = editor.IsSelected = true;
}
};
#endregion
#region type
modulTypeList = new List ();
if (isACInfrared) {
if (Language.CurrentLanguage == "English") {
modulTypeList.Add ("6_AC__0_0_0_0_0");
} else
modulTypeList.Add ("6_空调__0_0_0_0_0");
updateInfraredBytes [26] = 1;//后面修改了指令多了一个byte用来区分是否是红外空调
} else {
if (Language.CurrentLanguage == "English") {
//typeList.Add ("1_Projector__0_0_0_0_0");
//typeList.Add ("2_风扇__0_0_0_0_0");
modulTypeList.Add ("3_STB__0_0_0_0_0");
//typeList.Add ("4_影碟机 (DVD, EVD, VCD)__0_0_0_0_0");
modulTypeList.Add ("5_TV__0_0_0_0_0");
//typeList.Add ("6_空调__0_0_0_0_0");
//typeList.Add ("7_IPTV__0_0_0_0_0");
} else {
//typeList.Add ("1_投影仪__0_0_0_0_0");
//typeList.Add ("2_风扇__0_0_0_0_0");
modulTypeList.Add ("3_机顶盒__0_0_0_0_0");
//typeList.Add ("4_影碟机 (DVD, EVD, VCD)__0_0_0_0_0");
modulTypeList.Add ("5_电视机__0_0_0_0_0");
//typeList.Add ("6_空调__0_0_0_0_0");
//typeList.Add ("7_IPTV__0_0_0_0_0");
}
updateInfraredBytes [26] = 0;
}
#region 设备类型
RowLayout rl = new RowLayout () {
Y = Application.GetRealHeight (98),
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (93),
};
AddChidren (rl);
btnEquipmentIcon = new Button () {
Width = Application.GetRealHeight (63),
Height = Application.GetRealHeight (63),
X = Application.GetRealWidth (60),
Gravity = Gravity.CenterVertical,
};
rl.AddChidren (btnEquipmentIcon);
btnTypeName = new Button () {
Width = Application.GetRealHeight (343),
Height = Application.GetRealHeight (83),
X = btnEquipmentIcon.Right + Application.GetRealWidth (5),
TextAlignment = TextAlignment.CenterLeft,
Text = Language.StringByID (R.MyInternationalizationString.ChooseType),
TextColor = SkinStyle.Current.TextColor1
};
rl.AddChidren (btnTypeName);
Button 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);
RowLayout rowl2 = new RowLayout () {
Y = rl.Bottom,
Height = Application.GetRealHeight (93),
};
AddChidren (rowl2);
btnBrandName = new Button () {
TextAlignment = TextAlignment.Center,
TextID = R.MyInternationalizationString.ChooseType,
TextColor = SkinStyle.Current.TextColor1
};
rowl2.AddChidren (btnBrandName);
brandView = new VerticalScrolViewLayout () {
Gravity = Gravity.CenterHorizontal,
Y = rowl2.Bottom,
Height = Application.GetRealHeight (650 - 90)
};
AddChidren (brandView);
brandFlipView = new FrameLayout () {
X = brandView.X,
Y = brandView.Bottom,
Width = brandView.Width,
Height = Application.GetRealHeight (90),
BackgroundColor = 0xFF2f2f2f,
Visible = false
};
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),
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);
#endregion
EventHandler dropTypehandler = new EventHandler (delegate (object sender, MouseEventArgs e) {
#region DIALOG
Dialog dialog = new Dialog () {
BackgroundColor = SkinStyle.Current.DialogColor,
Width = Application.GetRealWidth (480),
Height = Application.GetRealHeight (600),
};
Button btnTitle = new Button () {
Width = dialog.Width,
Height = Application.GetRealHeight (105),
UnSelectedImagePath = "Item/Menu.png",
TextAlignment = TextAlignment.Center,
TextID = R.MyInternationalizationString.ChooseType,
TextColor = SkinStyle.Current.TextColor1
};
btnTitle.Enable = false;
dialog.AddChidren (btnTitle);
//存放设备的view
VerticalScrolViewLayout verticalScrolView = new VerticalScrolViewLayout () {
Width = Application.GetRealWidth (440),
Height = Application.GetRealHeight (350),
Gravity = Gravity.CenterHorizontal,
Y = btnTitle.Height + Application.GetRealHeight (20),
BackgroundColor = SkinStyle.Current.ViewColor
};
dialog.AddChidren (verticalScrolView);
FrameLayout BottomView = new FrameLayout () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (90),
BackgroundColor = SkinStyle.Current.ViewColor,
Y = dialog.Height - Application.GetRealHeight (90),
};
dialog.AddChidren (BottomView);
Button btnBack = new Button () {
Height = LayoutParams.MatchParent,
TextID = R.MyInternationalizationString.cancel,
TextAlignment = TextAlignment.Center,
TextColor = 0xFFFFFFFF
};
BottomView.AddChidren (btnBack);
btnBack.MouseUpEventHandler += (sender1, e1) => {
dialog.Close ();
};
#region ---显示设备类型---
for (int i = 0; i < modulTypeList.Count; i++) {
string modulName = modulTypeList [i].Split ('_') [1];
Button btnModulName = new Button () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (78),
Text = modulName,
TextAlignment = TextAlignment.Center,
TextColor = SkinStyle.Current.TextColor1,
Tag = i
};
verticalScrolView.AddChidren (btnModulName);
Button b1 = new Button () {
Width = LayoutParams.MatchParent,
Height = 1,
BackgroundColor = 0xFFDBDDDF
};
verticalScrolView.AddChidren (b1);
btnModulName.MouseUpEventHandler += (sender1, e1) => {
dialog.Close ();
FindBrand (brandView, btnModulName);
};
}
#endregion
#endregion
dialog.Show ();
});
btnDropDownIcon.MouseUpEventHandler += dropTypehandler;
rl.MouseUpEventHandler += dropTypehandler;
btnEquipmentIcon.MouseUpEventHandler += dropTypehandler;
#endregion
System.Threading.Tasks.Task.Run (() => {
//读取回路信息
byte [] infraredLoopBytes = Control.ControlBytesSendHasReturn (Command.DownloadInfrared, infrared.SubnetID, infrared.DeviceID,
new byte [] { infrared.LoopID, 0, infrared.LoopID });
if (infraredLoopBytes != null) {
infraredType = CommonPage.MyEncodingGB2312.GetString (infraredLoopBytes, 7, 20).Trim ('\0');
infraredTypeList = infraredType.Split ('-');
Application.RunOnMainThread (() => {
btnBrandName.Text = infraredTypeList [0];
try {
foreach (var t in modulTypeList) {
if (t.Contains (infraredTypeList [1])) {
switch (Convert.ToInt32 (t.Split ('_') [0])) {
case 1:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredProjector.png";
break;
case 2:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredFan.png";
break;
case 3:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredSTB.png";
break;
case 4:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredDVD.png";
break;
case 5:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredTV.png";
break;
case 6:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredAC.png";
break;
case 7:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredIPTV.png";
break;
}
}
}
} catch { }
});
}
});
//SystemMiddle.hideBottom ();
}
///
/// 查找设备品牌
///
void FindBrand (VerticalScrolViewLayout brandView, Button btnModulName)
{
MainPage.Loading.Start ();
isFindBrand = true;
System.Threading.Tasks.Task.Run (() => {
Application.RunOnMainThread (() => {
Dialog dialog = new Dialog () {
BackgroundColor = SkinStyle.Current.DialogColor,
Width = Application.GetRealWidth (540),
Height = Application.GetRealHeight (744 + 80),
};
Button btnTitle = new Button () {
Width = dialog.Width,
Height = Application.GetRealHeight (90),
BackgroundColor = SkinStyle.Current.ViewColor,
TextAlignment = TextAlignment.Center,
TextID = R.MyInternationalizationString.ChooseType,
TextColor = SkinStyle.Current.TextColor1,
Enable = false
};
dialog.AddChidren (btnTitle);
//存放设备的view
VerticalScrolViewLayout 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);
FrameLayout FlipView = new FrameLayout () {
X = verticalScrolView.X,
Y = verticalScrolView.Bottom,
Width = verticalScrolView.Width,
Height = Application.GetRealHeight (80),
BackgroundColor = SkinStyle.Current.ViewColor
};
dialog.AddChidren (FlipView);
Button 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;
};
Button btnPageText = new Button () {
X = btnAutoTestLeft.Right,
Width = Application.GetRealWidth (480 - 158 - 158),
Text = pageIndex.ToString (),
TextColor = SkinStyle.Current.TextColor1
};
FlipView.AddChidren (btnPageText);
Button 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, btnModulName, 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 ();
if (isFindBrand)
InitBrandView (verticalScrolView, btnModulName, dialog);
} catch { } finally {
MainPage.Loading.Hide ();
}
});
});
}
};
Button b2 = new Button () {
Width = LayoutParams.MatchParent,
Height = 1,
BackgroundColor = 0xFFDBDDDF,
};
FlipView.AddChidren (b2);
FrameLayout BottomView = new FrameLayout () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (90),
BackgroundColor = SkinStyle.Current.ViewColor,
Y = dialog.Height - Application.GetRealHeight (90),
};
dialog.AddChidren (BottomView);
Button btnBack = new Button () {
Height = LayoutParams.MatchParent,
TextID = R.MyInternationalizationString.cancel,
TextAlignment = TextAlignment.Center,
TextColor = SkinStyle.Current.TextColor1
};
BottomView.AddChidren (btnBack);
btnBack.MouseUpEventHandler += (sender, e) => {
dialog.Close ();
};
Button btnLineH = new Button () {
Width = 1,
Height = LayoutParams.MatchParent,
BackgroundColor = SkinStyle.Current.MainColor,
X = btnBack.Right,
};
BottomView.AddChidren (btnLineH);
dialog.Show ();
verticalScrolView.RemoveAll ();
brandView.RemoveAll ();
MainPage.Loading.Start ();
btnTitle.TextID = R.MyInternationalizationString.ChooseBrand;
nameNum = 2;
if (Language.CurrentLanguage == "English") {
nameNum = 6;
}
try {
modulTypeNumber = modulTypeList [(int)btnModulName.Tag].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 / 100;
if ((brandDataList.Count % 100) > 0)
pageCount++;
InitBrandView (verticalScrolView, btnModulName, dialog);
} catch (Exception ex) {
Console.WriteLine (ex.ToString ());
} finally {
MainPage.Loading.Hide ();
}
});
});
}
public void InitBrandView (VerticalScrolViewLayout verticalScrolView, Button btnModulName, Dialog dialog)
{
verticalScrolView.RemoveAll ();
for (int i = (pageIndex - 1) * 100; i < pageIndex * 100; i++) {
if (i >= brandDataList.Count)
break;
string brandData = brandDataList [i];
string brandName = brandData.Split ('_') [nameNum];
RowLayout rlBrandName = new RowLayout () {
Height = Application.GetRealHeight (78),
};
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) => {
#region 设备类型文本与图标
btnTypeName.Text = modulTypeList [(int)btnModulName.Tag].ToString ().Split ('_') [1];
switch (Convert.ToInt32 (modulTypeNumber)) {
case 1:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredProjector.png";
break;
case 2:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredFan.png";
break;
case 3:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredSTB.png";
break;
case 4:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredDVD.png";
break;
case 5:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredTV.png";
break;
case 6:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredAC.png";
break;
case 7:
btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredIPTV.png";
break;
}
#endregion
dialog.Close ();
try {
//verticalScrolView.RemoveAll ();
for (int i1 = 0; i1 < verticalScrolView.ChildrenCount; i1++) {
verticalScrolView.GetChildren (i1).RemoveFromParent ();
}
}catch(Exception ex) {
Console.WriteLine (ex.Message);
}
Console.WriteLine ("设备类型文本与图标");
btnBrandName.Text = btnBrandName_InDialog.Tag.ToString ().Split ('_') [nameNum];
btnBrandData_Tag = btnBrandName_InDialog.Tag;
FindInrared (verticalScrolView);
};
}
}
///
/// 查找红外
///
void FindInrared (VerticalScrolViewLayout verticalScrolView_Dialog)
{
try {
//verticalScrolView_Dialog.RemoveAll ();
for (int i1 = 0; i1 < verticalScrolView_Dialog.ChildrenCount; i1++) {
verticalScrolView_Dialog.GetChildren (i1).RemoveFromParent ();
}
} catch (Exception ex) {
Console.WriteLine (ex.Message);
}
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 / 100;
if ((infraredDataList.Length % 100) > 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) * 100; i < pageIndex * 100; i++) {
if (i >= infraredDataList.Length)
break;
if (infraredDataList [i] == null)
continue;
RowLayout flEquipmentView = new RowLayout () {
Height = Application.GetRealHeight (90)
};
brandView.AddChidren (flEquipmentView);
string infraredName = btnBrandData_Tag.ToString ().Split ('_') [nameNum] + " " + (i + 1).ToString ();
string modelData = btnBrandData_Tag.ToString ();
if (modelData.Split (',') [i + 1].Contains ("%")) {
infraredName = modelData.Split (',') [i + 1].Replace ('%', ';').Trim ();
}
Button btnInfraredCode = new Button () {
Width = Application.GetRealWidth (400),
X = Application.GetRealWidth (50),
TextAlignment = TextAlignment.CenterLeft,
Text = infraredName,
Tag = i,//红外码
TextColor = SkinStyle.Current.TextColor1
//Tag = infraredDataList [i],//红外码
};
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 (80),
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.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
return;
}
Dialog dialog = new Dialog () {
Width = Application.GetRealWidth (520),
Height = Application.GetRealHeight (850 + 90),
};
FrameLayout dialogBodyView = new FrameLayout () {
BackgroundColor = SkinStyle.Current.MainColor,
};
dialog.AddChidren (dialogBodyView);
#region top View
FrameLayout topView = new FrameLayout () {
Height = Application.GetRealHeight (80),
BackgroundColor = SkinStyle.Current.ViewColor
};
dialogBodyView.AddChidren (topView);
Button btnInfraredName_Dialog = new Button () {
Text = infraredName,
Enable = false,
TextAlignment = TextAlignment.Center,
};
topView.AddChidren (btnInfraredName_Dialog);
#endregion
#region ---channelView---
FrameLayout channelView = new FrameLayout () {
Height = Application.GetRealHeight (90),
Y = topView.Bottom,
};
dialogBodyView.AddChidren (channelView);
Button btnChannelText = new Button () {
X = Application.GetRealWidth (50),
Width = Application.GetRealWidth (130),
TextColor = SkinStyle.Current.TextColor1,
TextID = R.MyInternationalizationString.Port
};
channelView.AddChidren (btnChannelText);
EditText etPort = new EditText () {
X = btnChannelText.Right,
Y = Application.GetRealHeight (20),
Width = Application.GetRealWidth (210),
Height = Application.GetRealHeight (50),
Text = infraredBase.Port,
TextAlignment = TextAlignment.CenterLeft,
Enable = false,
TextColor = SkinStyle.Current.TextColor1
};
channelView.AddChidren (etPort);
Button btnSavePort = new Button () {
X = etPort.Right,
Y = etPort.Y - Application.GetRealHeight (20),
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (70),
UnSelectedImagePath = "Item/Editor.png",
SelectedImagePath = "Item/EditorSelected.png",
};
if (InfraredTypeCode != 6)
channelView.AddChidren (btnSavePort);
else {
etPort.Text = infraredBase.LoopID.ToString ();
}
btnSavePort.MouseUpEventHandler += (sender, e) => {
try {
if (etPort.IsSelected) {
btnSavePort.IsSelected = false;
etPort.Enable = false;
etPort.IsSelected = false;
etPort.BackgroundColor = SkinStyle.Current.Transparent;
var portss = 1;
if (int.TryParse (etPort.Text, out portss)) {
infraredBase.Port = etPort.Text.Trim ();
IO.FileUtils.SaveEquipmentMessage (infraredBase, infraredBase.LoopID.ToString ());
} else
throw new Exception ();
} else {
btnSavePort.IsSelected = true;
etPort.Enable = true;
etPort.IsSelected = true;
etPort.BackgroundColor = SkinStyle.Current.ViewColor;
}
} catch {
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterTheCorrectData),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
return;
}
};
#endregion
if (InfraredTypeCode == 1)//投影仪
{
}
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 = channelView.Bottom + Application.GetRealHeight (20),
Radius = 5,
BackgroundColor = SkinStyle.Current.ViewColor,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
TextID = R.MyInternationalizationString.Power
};
dialog.AddChidren (btnSwitch);
btnSwitch.MouseDownEventHandler += (sender, e) => {
btnSwitch.IsSelected = true;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
Button btnChannelUp = new Button () {
Width = Application.GetRealWidth (150),
Height = Application.GetRealHeight (55),
X = btnSwitch.Right + Application.GetRealWidth (10),
Y = btnSwitch.Y,
Radius = 5,
BackgroundColor = SkinStyle.Current.ViewColor,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
TextID = R.MyInternationalizationString.ChannelUp
};
dialog.AddChidren (btnChannelUp);
btnChannelUp.MouseDownEventHandler += (sender, e) => {
btnChannelUp.IsSelected = true;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
Button btnChannelDown = new Button () {
Width = Application.GetRealWidth (150),
Height = Application.GetRealHeight (55),
X = btnChannelUp.Right + Application.GetRealWidth (10),
Y = btnChannelUp.Y,
Radius = 5,
BackgroundColor = SkinStyle.Current.ViewColor,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
TextID = R.MyInternationalizationString.ChannelDown
};
dialog.AddChidren (btnChannelDown);
btnChannelDown.MouseDownEventHandler += (sender, e) => {
btnChannelDown.IsSelected = true;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
Button btnMute = new Button {
Width = Application.GetRealWidth (150),
Height = Application.GetRealHeight (55),
X = Application.GetRealWidth (25),
Y = btnSwitch.Bottom + Application.GetRealHeight (20),
Radius = 5,
BackgroundColor = SkinStyle.Current.ViewColor,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
TextID = R.MyInternationalizationString.Menu
};
dialog.AddChidren (btnMute);
btnMute.MouseDownEventHandler += (sender, e) => {
btnMute.IsSelected = true;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
Button btnVolumeUp = new Button () {
Width = Application.GetRealWidth (150),
Height = Application.GetRealHeight (55),
X = btnMute.Right + Application.GetRealWidth (10),
Y = btnSwitch.Bottom + Application.GetRealHeight (20),
Radius = 5,
BackgroundColor = SkinStyle.Current.ViewColor,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
TextID = R.MyInternationalizationString.VolumeUp,
};
dialog.AddChidren (btnVolumeUp);
btnVolumeUp.MouseDownEventHandler += (sender, e) => {
btnVolumeUp.IsSelected = true;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
Button btnVolumeDown = new Button () {
Width = Application.GetRealWidth (150),
Height = Application.GetRealHeight (55),
X = btnVolumeUp.Right + Application.GetRealWidth (10),
Y = btnVolumeUp.Y,
Radius = 5,
BackgroundColor = SkinStyle.Current.ViewColor,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
TextID = R.MyInternationalizationString.VolumeDown,
};
dialog.AddChidren (btnVolumeDown);
btnVolumeDown.MouseDownEventHandler += (sender, e) => {
btnVolumeDown.IsSelected = true;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
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;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
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;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
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;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
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;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
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;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
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;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
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;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
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;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
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;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
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;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
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;
if (btnTextButton != null)
btnTextButton.IsSelected = false;
btnTextButton = ((Button)sender);
};
dialogBodyView.AddChidren (new Button () { Height = 1, BackgroundColor = 0xFF2f2f2f, Y = Application.GetRealHeight (850 - 90 - 90) - 1 });
if (InfraredTypeCode == 3) //机顶盒
{
infraredBase.InfraredType = InfraredType.STB;
btnSwitch.MouseUpEventHandler += (sender4, e4) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.Standby;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, (byte)RandKey });//, 0, Convert.ToByte (RandKey) });
};
btnChannelUp.MouseUpEventHandler += (sender4, e4) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.ChannelUp;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btnChannelDown.MouseUpEventHandler += (sender4, e4) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.ChannelDown;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btnMute.MouseUpEventHandler += (sender4, e4) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.Menu;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btnVolumeUp.MouseUpEventHandler += (sender4, e4) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.VolUp;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btnVolumeDown.MouseUpEventHandler += (sender4, e4) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.VolDown;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
#region ---数字---
btn1.MouseUpEventHandler += (sender, e) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.One;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btn2.MouseUpEventHandler += (sender, e) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.Two;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btn3.MouseUpEventHandler += (sender, e) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.Three;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btn4.MouseUpEventHandler += (sender, e) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.Four;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btn5.MouseUpEventHandler += (sender, e) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.Five;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btn6.MouseUpEventHandler += (sender, e) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.Six;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btn7.MouseUpEventHandler += (sender, e) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.Seven;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btn8.MouseUpEventHandler += (sender, e) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.Eight;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btn9.MouseUpEventHandler += (sender, e) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.Nine;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btn0.MouseUpEventHandler += (sender, e) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.Zero;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
btnOK.MouseUpEventHandler += (sender, e) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_STB.Confrim;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID,
new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
};
#endregion
}
if (InfraredTypeCode == 5) //电视
{
infraredBase.InfraredType = InfraredType.TV;
btnSwitch.MouseUpEventHandler += (sender4, e4) => {
int RandKey = ran.Next (0, 255);
textByte = (byte)InfraredCode_TV.Power;
Control.ControlBytesSend (Command.InfraredControl, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.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 (61),
Height = Application.GetRealHeight (64),
X = Application.GetRealWidth (440),
Y = Application.GetRealHeight (5),
UnSelectedImagePath = "AC/ACDialogSwitch.png",
SelectedImagePath = "AC/ACDialogSwitchOn.png",
};
topView.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, infraredBase.SubnetID, infraredBase.DeviceID, acHostBytes);
});
};
#region ---temperatureView---
FrameLayout temperatureView = new FrameLayout () {
Height = Application.GetRealHeight (135),
Y = channelView.Bottom,
};
dialogBodyView.AddChidren (temperatureView);
Button btnMin1 = new Button () {
Height = 1,
Y = 1,
BackgroundColor = 0xFF2f2f2f,
};
temperatureView.AddChidren (btnMin1);
Button btnMin2 = new Button () {
Height = 1,
Y = temperatureView.Height - 1,
BackgroundColor = 0xFF2f2f2f,
};
temperatureView.AddChidren (btnMin2);
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),
Height = Application.GetRealHeight (94),
Gravity = Gravity.CenterHorizontal,
Y = btnReduceTemperature.Y,
Text = "16°",
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 () + "°";
acHostBytes [11] = temperature;
Control.ControlBytesSend (Command.SetACMode, infraredBase.SubnetID, infraredBase.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 () + "°";
acHostBytes [11] = temperature;
Control.ControlBytesSend (Command.SetACMode, infraredBase.SubnetID, infraredBase.DeviceID, acHostBytes);
}
};
#endregion
List ModelList = new List ();
List WindModelList = new List ();
if (Language.CurrentLanguage == "Chinese") {
ModelList.Add ("制冷");
ModelList.Add ("制热");
ModelList.Add ("通风");
ModelList.Add ("自动");
ModelList.Add ("除湿");
WindModelList.Add ("自动");
WindModelList.Add ("高风");
WindModelList.Add ("中风");
WindModelList.Add ("低风");
} else {
ModelList.Add ("Cool");
ModelList.Add ("Hot");
ModelList.Add ("Ventilae");
ModelList.Add ("Auto");
ModelList.Add ("Dehumidify");
WindModelList.Add ("Auto");
WindModelList.Add ("High");
WindModelList.Add ("Stroke");
WindModelList.Add ("Low");
}
#region 模式
var acModeView = new FrameLayout () {
Height = Application.GetRealHeight (180),
Width = LayoutParams.MatchParent,
Y = temperatureView.Bottom,
};
dialogBodyView.AddChidren (acModeView);
var btnLine12 = new Button () {
Height = 1,
BackgroundColor = SkinStyle.Current.MainColor,
Y = acModeView.Height - 1
};
acModeView.AddChidren (btnLine12);
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 (110),
Height = Application.GetMinRealAverage (112),
Gravity = Gravity.Center,
Y = btnModeName.Bottom + Application.GetRealHeight (10),
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] > 4)
acHostBytes [9] = 0;
UpdataACHostModeIcon (acHostBytes [9], btnModeIcon, btnModeText, ModelList);
Control.ControlBytesSend (Command.SetACMode, infraredBase.SubnetID, infraredBase.DeviceID, acHostBytes);
};
btnACModeLeft.MouseDownEventHandler += (sender, e) => {
btnACModeLeft.IsSelected = true;
};
btnACModeLeft.MouseUpEventHandler += (sender, e) => {
btnACModeLeft.IsSelected = false;
if (acHostBytes [9] == 0)
acHostBytes [9] = 4;
else
acHostBytes [9]--;
//if (acHostBytes [9] < 0 || acHostBytes [9] > 4)
//acHostBytes [9] = 4;
UpdataACHostModeIcon (acHostBytes [9], btnModeIcon, btnModeText, ModelList);
Control.ControlBytesSend (Command.SetACMode, infraredBase.SubnetID, infraredBase.DeviceID, acHostBytes);
};
#endregion
#region 风速
var acWindView = new FrameLayout () {
Height = Application.GetRealHeight (180),
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 (110),
Height = Application.GetMinRealAverage (112),
Gravity = Gravity.Center,
Y = btnWindName.Bottom + Application.GetRealHeight (10),
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;
else
acHostBytes [10]--;
//if (acHostBytes [10] < 0 || acHostBytes [10] > 3)
//acHostBytes [10] = 3;
UpdataACHostWindIcon (acHostBytes [10], btnWindIcon, btnWindModeText, WindModelList);
Control.ControlBytesSend (Command.SetACMode, infraredBase.SubnetID, infraredBase.DeviceID, acHostBytes);
};
acWindView.AddChidren (btnACWindRight);
btnACWindRight.MouseDownEventHandler += (sender, e) => {
btnACWindRight.IsSelected = true;
};
btnACWindRight.MouseUpEventHandler += (sender, e) => {
btnACWindRight.IsSelected = false;
if (++acHostBytes [10] > 3)
acHostBytes [10] = 0;
UpdataACHostWindIcon (acHostBytes [10], btnWindIcon, btnWindModeText, WindModelList);
Control.ControlBytesSend (Command.SetACMode, infraredBase.SubnetID, infraredBase.DeviceID, acHostBytes);
};
acWindView.AddChidren (new Button () { Height = 1, BackgroundColor = 0xFF2f2f2f, Y = acWindView.Height - 1 });
#endregion
}
#region ---testTime---
RowLayout autoTestTimeView = new RowLayout () {
Height = Application.GetRealHeight (90),
Y = Application.GetRealHeight (850 - 90 - 90),
};
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) - 1,
Y = Application.GetRealHeight (850 - 90) + 1,
};
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,
Tag = i,
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 (() => {
try {
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, infraredBase.SubnetID, infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
}
Application.RunOnMainThread (() => {
btnBrandName.Text = btnInfraredCode.Text;
infraredName = btnBrandData_Tag.ToString ().Split ('_') [nameNum] + " " + (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 ();
});
} catch (Exception ex) {
Console.WriteLine (ex.Message);
} finally {
Application.RunOnMainThread (() => {
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, infraredBase.SubnetID, infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
}
Application.RunOnMainThread (() => {
btnBrandName.Text = btnInfraredCode.Text;
infraredName = btnBrandData_Tag.ToString ().Split ('_') [nameNum] + " " + (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, infraredBase.SubnetID, infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, new byte [] { Convert.ToByte (infraredBase.Port), TestByteIndex, textByte, 0, 0, Convert.ToByte (RandKey) });
}
Application.RunOnMainThread (() => {
btnBrandName.Text = btnInfraredCode.Text;
infraredName = btnBrandData_Tag.ToString ().Split ('_') [nameNum] + " " + (infraredDataIndex).ToString ();
modelData = btnBrandData_Tag.ToString ();
if (modelData.Split (',') [infraredDataIndex].Contains ("%")) {
infraredName = modelData.Split (',') [infraredDataIndex].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.ViewColor,
Y = Application.GetRealHeight (850),
};
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,
BackgroundColor = SkinStyle.Current.ViewColor,
};
bottomView.AddChidren (btnSave);
btnSave.MouseUpEventHandler += (sender, e) => {
if (InfraredTypeCode == 5) {
infraredBase.DeviceTextID = R.MyInternationalizationString.TV;
infraredBase.InfraredType = InfraredType.TV;
}
if (InfraredTypeCode == 3) {
infraredBase.DeviceTextID = R.MyInternationalizationString.STB;
infraredBase.InfraredType = InfraredType.STB;
}
updateInfraredBytes [0] = infraredBase.LoopID;
btnAutoTest.IsSelected = false;
UpdataInfrared (updateInfraredBytes, byteICode);
IO.FileUtils.SaveEquipmentMessage (infraredBase, infraredBase.LoopID.ToString ());
dialog.Close ();
};
#endregion
dialog.Show ();
});
});
};
}
}
///
/// 上传红外码
///
static 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, infraredBase.SubnetID, infraredBase.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, infraredBase.SubnetID, infraredBase.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, infraredBase.SubnetID, infraredBase.DeviceID, upLoadbyte);
}
} catch { } finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
});
}
return resulte;
//});
}
void UpdataACHostModeIcon (byte modeByte, Button btn,Button btn2,List modeList)
{
///模式0制冷 1制热,2通风 3自动 4抽湿 index[9]
switch (modeByte) {
case 0:
btn.UnSelectedImagePath = "AC/ACRefrigeration.png";
btn2.Text = modeList [0];
break;
case 1:
btn.UnSelectedImagePath = "AC/ACDehumidification.png";
btn2.Text = modeList [1];
break;
case 2:
btn.UnSelectedImagePath = "AC/ ACAuto.png";
btn2.Text = modeList [2];
break;
case 3:
btn.UnSelectedImagePath = "AC/ACAuto.png";
btn2.Text = modeList [3];
break;
case 4:
btn.UnSelectedImagePath = "AC/ACDehumidification.png";
btn2.Text = modeList [4];
break;
}
}
void UpdataACHostWindIcon (byte windByte, Button btn,Button btn2,List windModelList)
{
switch (windByte) {
case 0:
btn.UnSelectedImagePath = "AC/ACAuto.png";
btn2.Text = windModelList [0];
break;
case 3:
btn.UnSelectedImagePath = "AC/ACLowWind.png";
btn2.Text = windModelList [3];
break;
case 2:
btn.UnSelectedImagePath = "AC/ACStroke.png";
btn2.Text = windModelList [2];
break;
case 1:
btn.UnSelectedImagePath = "AC/ACHighWind.png";
btn2.Text = windModelList [1];
break;
}
}
}
}