using System;
|
using System.Collections.Generic;
|
using Shared.SimpleControl;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class UserTVFrameLayout : FrameLayout
|
{
|
InfraredMode infrared;
|
int PageIndex = 0;
|
|
public UserTVFrameLayout (InfraredMode common)
|
{
|
BackgroundColor = SkinStyle.Current.MainColor;
|
infrared = common;
|
if (infrared.infraredInherentFunctions.Count == 0) {
|
infrared.InitInherentFunction ();
|
}
|
if(infrared.infraredFuntionList.Count == 0) {
|
infrared.InitFunction ();
|
}
|
#if DEBUG
|
if (!infrared.IsUniversalSwitch) {
|
infrared.InitInherentFunction ();
|
infrared.InitFunction ();
|
}
|
#endif
|
}
|
|
public void ShowUserTV (Button tempSwtich = null)
|
{
|
RemoveAll ();
|
Random ran = new Random ();
|
|
#region 标题
|
var topView = new FrameLayout () {
|
Y = Application.GetRealHeight (36),
|
Height = Application.GetRealHeight (90),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
AddChidren (topView);
|
|
var title = new Button () {
|
TextAlignment = TextAlignment.Center,
|
Text = infrared.Name,
|
TextSize = 19,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
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 (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
SelectedImagePath = "Item/BackSelected.png",
|
};
|
topView.AddChidren (back);
|
back.MouseUpEventHandler += (sender, e) => {
|
this.RemoveFromParent ();
|
};
|
#endregion
|
|
#region middle
|
PageLayout BodyView = new PageLayout () {
|
Y = Application.GetRealHeight (126),
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (980),
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
AddChidren (BodyView);
|
|
#region FristBodyView
|
FrameLayout FristBodyView = new FrameLayout ();
|
BodyView.AddChidren (FristBodyView);
|
FrameLayout fristTopView = new FrameLayout () {
|
BackgroundImagePath = infrared.InfraredType == InfraredType.TV ? "TVIcon/tvBg.png" : "TVIcon/stbBg.png",
|
Height = Application.GetRealHeight (500),
|
};
|
FristBodyView.AddChidren (fristTopView);
|
if (infrared.InfraredType == InfraredType.TV) {
|
Button btnTVPower = new Button () {
|
X = Application.GetRealWidth (10),
|
Y = Application.GetRealHeight (20),
|
Width = Application.GetMinRealAverage (131),
|
Height = Application.GetMinRealAverage (131),
|
UnSelectedImagePath = "TVIcon/Power.png",
|
SelectedImagePath = "TVIcon/Power_On.png",
|
TextID = R.MyInternationalizationString.TV,
|
Padding = new Padding (Application.GetRealWidth (100), 0, 0, 0),
|
IsSelected = infrared.isOpen,
|
};
|
fristTopView.AddChidren (btnTVPower);
|
|
btnTVPower.MouseUpEventHandler += (sender, e) => {
|
infrared.isOpen = btnTVPower.IsSelected = !btnTVPower.IsSelected;
|
if (infrared.IsUniversalSwitch) {
|
byte powerState = btnTVPower.IsSelected ? (byte)255 : (byte)0;
|
var commandCode = infrared.InfraredType == InfraredType.TV ? (byte)InfraredCode_TV.Power : (byte)InfraredCode_STB.Standby;
|
var inf = infrared.infraredInherentFunctions.Find ((obj) => obj.functionCode.ToString () == commandCode.ToString ());
|
Control.ControlBytesSend (Command.SetCommonSwitch, infrared.SubnetID, infrared.DeviceID, new byte [] { inf.universalSwitchId, powerState });
|
} else {
|
int RandKey = ran.Next (0, 255);
|
Control.ControlBytesSend (Command.InfraredControl, infrared.SubnetID, infrared.DeviceID, new byte [] { Convert.ToByte (infrared.Port), infrared.LoopID, (byte)InfraredCode_TV.Power, 0, 0, (byte)RandKey });
|
IO.FileUtils.SaveEquipmentMessage (infrared, infrared.LoopID.ToString ());
|
}
|
if(tempSwtich != null)
|
{
|
tempSwtich.IsSelected = infrared.isOpen;
|
}
|
};
|
} else {
|
Button btnSTBPower = new Button () {
|
X = Application.GetRealWidth (640 - 141),
|
Y = Application.GetRealHeight (20),
|
Width = Application.GetMinRealAverage (131),
|
Height = Application.GetMinRealAverage (131),
|
UnSelectedImagePath = "TVIcon/Power.png",
|
SelectedImagePath = "TVIcon/Power_On.png",
|
Padding = new Padding (Application.GetRealHeight (100), 0, 0, 0),
|
TextID = R.MyInternationalizationString.STB,
|
IsSelected = infrared.isOpen
|
};
|
fristTopView.AddChidren (btnSTBPower);
|
btnSTBPower.MouseUpEventHandler += (sender, e) => {
|
infrared.isOpen = btnSTBPower.IsSelected = !btnSTBPower.IsSelected;
|
if (infrared.IsUniversalSwitch) {
|
byte powerState = btnSTBPower.IsSelected ? (byte)255 : (byte)0;
|
var commandCode = infrared.InfraredType == InfraredType.TV ? (byte)InfraredCode_TV.Power : (byte)InfraredCode_STB.Standby;
|
var inf = infrared.infraredInherentFunctions.Find ((obj) => obj.functionCode.ToString () == commandCode.ToString());
|
Control.ControlBytesSend (Command.SetCommonSwitch, infrared.SubnetID, infrared.DeviceID, new byte [] { inf.universalSwitchId, powerState });
|
} else {
|
int RandKey = ran.Next (0, 255);
|
Control.ControlBytesSend (Command.InfraredControl, infrared.SubnetID, infrared.DeviceID, new byte [] { Convert.ToByte (infrared.Port), infrared.LoopID, (byte)InfraredCode_STB.Standby, 0, 0, (byte)RandKey });
|
IO.FileUtils.SaveEquipmentMessage (infrared, infrared.LoopID.ToString ());
|
}
|
if (tempSwtich != null) {
|
tempSwtich.IsSelected = infrared.isOpen;
|
}
|
};
|
}
|
Button btnTVUp = new Button () {
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight (88),
|
Width = Application.GetMinRealAverage (127),
|
Height = Application.GetMinRealAverage (108),
|
SelectedImagePath = "TVIcon/Up_On.png",
|
UnSelectedImagePath = "TVIcon/Up.png",
|
};
|
fristTopView.AddChidren (btnTVUp);
|
btnTVUp.MouseUpEventHandler += (sender, e) => {
|
btnTVUp.IsSelected = true;
|
new System.Threading.Thread (() => {
|
System.Threading.Thread.Sleep (300);
|
Application.RunOnMainThread (() => {
|
btnTVUp.IsSelected = false;
|
});
|
}) { IsBackground = true }.Start ();
|
try {
|
|
var commandCode = infrared.InfraredType == InfraredType.TV ? (byte)InfraredCode_TV.Up : (byte)InfraredCode_STB.Up;
|
var inf = infrared.infraredInherentFunctions.Find ((obj) => obj.functionCode.ToString () == commandCode.ToString ());
|
if (infrared.IsUniversalSwitch) {
|
Control.ControlBytesSend (Command.SetCommonSwitch, infrared.SubnetID, infrared.DeviceID, new byte [] { inf.universalSwitchId, 255 });
|
} else {
|
int RandKey = ran.Next (0, 255);
|
Control.ControlBytesSend (Command.InfraredControl, infrared.SubnetID, infrared.DeviceID, new byte [] { Convert.ToByte (infrared.Port), infrared.LoopID, inf.functionCode, 0, 0, (byte)RandKey });
|
}
|
} catch { }
|
};
|
Button btnTVLeft = new Button () {
|
X = btnTVUp.X - Application.GetMinRealAverage (108),
|
Y = btnTVUp.Bottom,
|
Width = Application.GetMinRealAverage (108),
|
Height = Application.GetMinRealAverage (127),
|
UnSelectedImagePath = "TVIcon/Left.png",
|
SelectedImagePath = "TVIcon/Left_On.png",
|
};
|
fristTopView.AddChidren (btnTVLeft);
|
btnTVLeft.MouseUpEventHandler += (sender, e) => {
|
btnTVLeft.IsSelected = true;
|
new System.Threading.Thread (() => {
|
System.Threading.Thread.Sleep (300);
|
Application.RunOnMainThread (() => {
|
btnTVLeft.IsSelected = false;
|
});
|
}) { IsBackground = true }.Start ();
|
try {
|
var commandCode = infrared.InfraredType == InfraredType.TV ? (byte)InfraredCode_TV.Left : (byte)InfraredCode_STB.Left;
|
var inf = infrared.infraredInherentFunctions.Find ((obj) => obj.functionCode.ToString () == commandCode.ToString ());
|
if (infrared.IsUniversalSwitch) {
|
Control.ControlBytesSend (Command.SetCommonSwitch, infrared.SubnetID, infrared.DeviceID, new byte [] { inf.universalSwitchId, 255 });
|
} else {
|
int RandKey = ran.Next (0, 255);
|
Control.ControlBytesSend (Command.InfraredControl, infrared.SubnetID, infrared.DeviceID, new byte [] { Convert.ToByte (infrared.Port), infrared.LoopID, inf.functionCode, 0, 0, (byte)RandKey });
|
}
|
} catch { }
|
};
|
|
Button btnOK = new Button () {
|
X = btnTVLeft.Right,
|
Y = btnTVUp.Bottom,
|
Width = Application.GetMinRealAverage (127),
|
Height = Application.GetMinRealAverage (127),
|
UnSelectedImagePath = "TVIcon/Ok.png",
|
SelectedImagePath = "TVIcon/Ok_On.png",
|
};
|
fristTopView.AddChidren (btnOK);
|
|
btnOK.MouseUpEventHandler += (sender, e) => {
|
btnOK.IsSelected = true;
|
new System.Threading.Thread (() => {
|
System.Threading.Thread.Sleep (300);
|
Application.RunOnMainThread (() => {
|
btnOK.IsSelected = false;
|
});
|
}) { IsBackground = true }.Start ();
|
try {
|
var commandCode = infrared.InfraredType == InfraredType.TV ? (byte)InfraredCode_TV.Confrim : (byte)InfraredCode_STB.Confrim;
|
var inf = infrared.infraredInherentFunctions.Find ((obj) => obj.functionCode.ToString () == commandCode.ToString ());
|
if (infrared.IsUniversalSwitch) {
|
Control.ControlBytesSend (Command.SetCommonSwitch, infrared.SubnetID, infrared.DeviceID, new byte [] { inf.universalSwitchId, 255 });
|
} else {
|
int RandKey = ran.Next (0, 255);
|
Control.ControlBytesSend (Command.InfraredControl, infrared.SubnetID, infrared.DeviceID, new byte [] { Convert.ToByte (infrared.Port), infrared.LoopID, inf.functionCode, 0, 0, (byte)RandKey });
|
}
|
} catch { }
|
};
|
|
Button btnTVRight = new Button () {
|
X = btnOK.Right,
|
Y = btnTVUp.Bottom,
|
Width = Application.GetMinRealAverage (108),
|
Height = Application.GetMinRealAverage (127),
|
UnSelectedImagePath = "TVIcon/Right.png",
|
SelectedImagePath = "TVIcon/Right_On.png",
|
};
|
fristTopView.AddChidren (btnTVRight);
|
btnTVRight.MouseUpEventHandler += (sender, e) => {
|
btnTVRight.IsSelected = true;
|
new System.Threading.Thread (() => {
|
System.Threading.Thread.Sleep (300);
|
Application.RunOnMainThread (() => {
|
btnTVRight.IsSelected = false;
|
});
|
}) { IsBackground = true }.Start ();
|
try {
|
var commandCode = infrared.InfraredType == InfraredType.TV ? (byte)InfraredCode_TV.Right : (byte)InfraredCode_STB.Right;
|
var inf = infrared.infraredInherentFunctions.Find ((obj) => obj.functionCode.ToString () == commandCode.ToString ());
|
if (infrared.IsUniversalSwitch) {
|
Control.ControlBytesSend (Command.SetCommonSwitch, infrared.SubnetID, infrared.DeviceID, new byte [] { inf.universalSwitchId, 255 });
|
} else {
|
int RandKey = ran.Next (0, 255);
|
Control.ControlBytesSend (Command.InfraredControl, infrared.SubnetID, infrared.DeviceID, new byte [] { Convert.ToByte (infrared.Port), infrared.LoopID, inf.functionCode, 0, 0, (byte)RandKey });
|
}
|
} catch { }
|
};
|
|
Button btnTVDown = new Button () {
|
X = btnTVUp.X,
|
Y = btnOK.Bottom,
|
Width = Application.GetMinRealAverage (127),
|
Height = Application.GetMinRealAverage (108),
|
SelectedImagePath = "TVIcon/Down_On.png",
|
UnSelectedImagePath = "TVIcon/Down.png",
|
};
|
fristTopView.AddChidren (btnTVDown);
|
btnTVDown.MouseUpEventHandler += (sender, e) => {
|
btnTVDown.IsSelected = true;
|
new System.Threading.Thread (() => {
|
System.Threading.Thread.Sleep (300);
|
Application.RunOnMainThread (() => {
|
btnTVDown.IsSelected = false;
|
});
|
}) { IsBackground = true }.Start ();
|
try {
|
var commandCode = infrared.InfraredType == InfraredType.TV ? (byte)InfraredCode_TV.Down : (byte)InfraredCode_STB.Down;
|
var inf = infrared.infraredInherentFunctions.Find ((obj) => obj.functionCode.ToString () == commandCode.ToString ());
|
if (infrared.IsUniversalSwitch) {
|
Control.ControlBytesSend (Command.SetCommonSwitch, infrared.SubnetID, infrared.DeviceID, new byte [] { inf.universalSwitchId, 255 });
|
} else {
|
int RandKey = ran.Next (0, 255);
|
Control.ControlBytesSend (Command.InfraredControl, infrared.SubnetID, infrared.DeviceID, new byte [] { Convert.ToByte (infrared.Port), infrared.LoopID, inf.functionCode, 0, 0, (byte)RandKey });
|
}
|
} catch { }
|
};
|
|
#endregion
|
|
#region SecondBodyView
|
FrameLayout SecondBodyView = new FrameLayout () {
|
Y = fristTopView.Bottom,
|
Height = Application.GetRealHeight (410),
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
FristBodyView.AddChidren (SecondBodyView);
|
|
VerticalScrolViewLayout frist_VS_View = new VerticalScrolViewLayout ();
|
SecondBodyView.AddChidren (frist_VS_View);
|
|
HorizontalScrolViewLayout HS_View_3 = null;
|
|
foreach (var cusFunction in infrared.infraredFuntionList) {
|
int index = infrared.infraredFuntionList.IndexOf (cusFunction);
|
if (index % 4 == 0) {
|
Button btnHLine2 = new Button () {
|
Height = 1,
|
};
|
//frist_VS_View.AddChidren (btnHLine2);
|
|
HS_View_3 = new HorizontalScrolViewLayout () {
|
Height = Application.GetMinRealAverage (138),
|
ScrollEnabled = false,
|
};
|
frist_VS_View.AddChidren (HS_View_3);
|
}
|
Button btn = new Button () {
|
Width = Application.GetRealWidth (160),
|
Height = Application.GetMinRealAverage (138),
|
Padding = new Padding (Application.GetRealHeight (70), 0, 0, 0),
|
TextColor = SkinStyle.Current.TextColor1,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
Text = cusFunction.GetText(infrared.InfraredType),
|
UnSelectedImagePath = cusFunction.GetUnSelectedImagePath (infrared.InfraredType),
|
SelectedImagePath = cusFunction.GetSelectedImagePath (infrared.InfraredType),
|
Tag = cusFunction.functionCode,
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
};
|
HS_View_3.AddChidren (btn);
|
btn.MouseUpEventHandler += (sender, e) => {
|
btn.IsSelected = true;
|
new System.Threading.Thread (() => {
|
System.Threading.Thread.Sleep (300);
|
Application.RunOnMainThread (() => {
|
btn.IsSelected = false;
|
});
|
}) { IsBackground = true }.Start ();
|
try {
|
var inf = infrared.infraredFuntionList.Find ((obj) => obj.functionCode.ToString () == ((Button)sender).Tag.ToString());
|
if (infrared.IsUniversalSwitch) {
|
Control.ControlBytesSend (Command.SetCommonSwitch, infrared.SubnetID, infrared.DeviceID, new byte [] { inf.universalSwitchId, 255 });
|
} else {
|
int RandKey = ran.Next (0, 255);
|
Control.ControlBytesSend (Command.InfraredControl, infrared.SubnetID, infrared.DeviceID, new byte [] { Convert.ToByte (infrared.Port), infrared.LoopID, Convert.ToByte (((Button)sender).Tag), 0, 0, (byte)RandKey });
|
}
|
} catch { }
|
};
|
|
|
if (index % 4 != 3) {
|
Button btnLine31 = new Button () {
|
Width = 1
|
};
|
//HS_View_3.AddChidren (btnLine31);
|
}
|
}
|
#endregion
|
|
#endregion
|
|
#region bottom
|
FrameLayout bottom = new FrameLayout () {
|
Y = BodyView.Bottom,
|
Height = Application.GetRealHeight (100),
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
AddChidren (bottom);
|
#endregion
|
|
var tvNumberView = new UserTVNumberView ();
|
BodyView.AddChidren (tvNumberView);
|
tvNumberView.Show (infrared);
|
var tvCustomChannel = new UserTVCustomChannel ();
|
BodyView.AddChidren (tvCustomChannel);
|
tvCustomChannel.Show (infrared);
|
|
BodyView.PageIndex = PageIndex;
|
}
|
}
|
}
|