using System;
|
using System.Collections.Generic;
|
namespace Shared.SimpleControl.Pad
|
{
|
public class UserTVAddCustomChannel :Dialog
|
{
|
public UserTVAddCustomChannel () {
|
}
|
|
public void Show (InfraredMode infraredTV, Action<InfraredMode> BackAction)
|
{
|
FrameLayout BodyView = new FrameLayout () {
|
BorderColor = SkinStyle.Current.Transparent,
|
BorderWidth = 1,
|
Radius = 5,
|
};
|
AddChidren (BodyView);
|
|
#region Top
|
FrameLayout ChannelNameView = new FrameLayout () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (110),
|
};
|
BodyView.AddChidren (ChannelNameView);
|
|
Button btnChannelName = new Button () {
|
X = Application.GetRealWidth(20),
|
Y = Application.GetRealHeight(30),
|
Width = Application.GetRealHeight(250),
|
Height = Application.GetRealHeight(80),
|
TextSize =13,
|
TextID = R.MyInternationalizationString.ChannelNameText
|
};
|
ChannelNameView.AddChidren (btnChannelName);
|
|
EditText etChannelName = new EditText () {
|
Width = Application.GetRealWidth (500),
|
Height = Application.GetRealHeight (80),
|
X =btnChannelName.Right,
|
Y = Application.GetRealHeight(30),
|
TextSize =13,
|
TextAlignment = TextAlignment.BottomLeft,
|
};
|
ChannelNameView.AddChidren (etChannelName);
|
Button btnCNLine = new Button () {
|
X = etChannelName.X,
|
Y = etChannelName.Bottom - Application.GetRealHeight(15),
|
Width = etChannelName.Width,
|
Height = Application.GetRealHeight(5),
|
BackgroundColor = 0xFF333333
|
};
|
ChannelNameView.AddChidren (btnCNLine);
|
|
|
FrameLayout ChannelNumberView = new FrameLayout () {
|
Y = ChannelNameView.Bottom,
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (80),
|
};
|
BodyView.AddChidren (ChannelNumberView);
|
|
Button btnChannelNumber = new Button () {
|
X = Application.GetRealWidth (20),
|
Width = Application.GetRealHeight (250),
|
Height = Application.GetRealHeight (80),
|
TextSize = 13,
|
TextID = R.MyInternationalizationString.ChannelNumberText,
|
};
|
ChannelNumberView.AddChidren (btnChannelNumber);
|
|
EditText etChannelNumber = new EditText () {
|
Width = Application.GetRealWidth (500),
|
Height = Application.GetRealHeight (80),
|
X =btnChannelName.Right,
|
TextSize =13,
|
TextAlignment = TextAlignment.BottomLeft,
|
};
|
ChannelNumberView.AddChidren (etChannelNumber);
|
etChannelNumber.TextChangeEventHandler += (sender, e) => {
|
if (e.Length > 6) {
|
etChannelNumber.Text=e.Remove (6);
|
}
|
};
|
Button btnCNLine2 = new Button () {
|
X = etChannelNumber.X,
|
Y = etChannelNumber.Bottom - Application.GetRealHeight (15),
|
Width = etChannelNumber.Width,
|
Height = Application.GetRealHeight (5),
|
BackgroundColor = 0xFF333333
|
};
|
ChannelNumberView.AddChidren (btnCNLine2);
|
#endregion
|
|
#region bodyMiddle
|
FrameLayout PictureIconView = new FrameLayout () {
|
Y =ChannelNumberView.Bottom + Application.GetRealHeight(20),
|
Height = Application.GetRealHeight(250),
|
};
|
BodyView.AddChidren (PictureIconView);
|
|
Button bodyMiddlePicture = new Button () {
|
X = Application.GetRealWidth (25),
|
Width = Application .GetRealWidth (320),
|
Height = Application.GetRealHeight (240),
|
UnSelectedImagePath ="TV/TV3_1.png",
|
};
|
PictureIconView.AddChidren (bodyMiddlePicture);
|
|
Button lineBottom1 = new Button () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (5),
|
Y = bodyMiddlePicture.Bottom,
|
BackgroundColor = 0xFF000000,
|
};
|
PictureIconView.AddChidren (lineBottom1);
|
|
Button btnTakePictrue = new Button () {
|
X = bodyMiddlePicture.Right,
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (122),
|
TextColor = SkinStyle.Current.TextColor1,
|
TextID = R.MyInternationalizationString.TakePhoto,
|
};
|
PictureIconView.AddChidren (btnTakePictrue);
|
|
Button btnLineP = new Button () {
|
Width = btnTakePictrue.Width,
|
Height = 1,
|
BackgroundColor = 0xFF000000,
|
X = bodyMiddlePicture.Right,
|
Y = btnTakePictrue.Bottom,
|
};
|
PictureIconView.AddChidren (btnLineP);
|
|
Button btnSelectPictrue = new Button () {
|
Width = btnTakePictrue.Width,
|
Height = btnTakePictrue.Height,
|
TextID = R.MyInternationalizationString.SelectPicture,
|
TextColor = SkinStyle.Current.TextColor1,
|
X = bodyMiddlePicture.Right,
|
Y = btnLineP.Bottom,
|
};
|
PictureIconView.AddChidren (btnSelectPictrue);
|
|
btnTakePictrue.MouseUpEventHandler += (sender, e) => {
|
btnTakePictrue.IsSelected = true;
|
btnSelectPictrue.IsSelected = false;
|
Camera.TakePicture ((obj) => {
|
if (obj != null) {
|
bodyMiddlePicture.UnSelectedImagePath = "GlobalTVPicture";
|
}
|
}, "GlobalTVPicture");
|
};
|
|
btnSelectPictrue.MouseUpEventHandler += (sender, e) => {
|
btnTakePictrue.IsSelected = false ;
|
btnSelectPictrue.IsSelected = true;
|
Camera.SelectPicture ((obj) => {
|
if (obj != null) {
|
bodyMiddlePicture.UnSelectedImagePath = "GlobalTVPicture";
|
}
|
}, "GlobalTVPicture");
|
};
|
#endregion
|
|
#region TVIconView
|
VerticalScrolViewLayout TVIconView = new VerticalScrolViewLayout () {
|
X = Application.GetRealWidth(30),
|
Y = PictureIconView.Bottom + Application.GetRealHeight (15),
|
Width = Application.GetRealWidth(760),
|
Height = Application.GetRealHeight (900 - 400),
|
};
|
BodyView.AddChidren (TVIconView);
|
|
int iconCount = 0;
|
while(true){
|
//for ( iconCount < 44;) {
|
HorizontalScrolViewLayout horizontalScrolView = new HorizontalScrolViewLayout () {
|
Height = Application.GetMinRealAverage (170),
|
ScrollEnabled = false,
|
};
|
TVIconView.AddChidren (horizontalScrolView);
|
for (int i = 0; i < 3; i++) {
|
if (iconCount >= 44)
|
break;
|
iconCount++;
|
string imagePath = @"TV/TV3_" + iconCount.ToString () + @".png";
|
Button btnNull = new Button () {
|
Width = Application.GetRealWidth (20),
|
};
|
horizontalScrolView.AddChidren (btnNull);
|
Button btnIcon = new Button () {
|
Width = Application.GetMinRealAverage (240),
|
UnSelectedImagePath = imagePath
|
};
|
horizontalScrolView.AddChidren (btnIcon);
|
btnIcon.MouseUpEventHandler += (sender, e) => {
|
bodyMiddlePicture.UnSelectedImagePath = btnIcon.UnSelectedImagePath;
|
};
|
}
|
Button btnHor = new Button () {
|
Height = Application.GetRealHeight(20),
|
};
|
TVIconView.AddChidren (btnHor);
|
if (iconCount >= 44)
|
break;
|
}
|
|
#endregion
|
|
#region Save
|
FrameLayout bottomView = new FrameLayout () {
|
Y = BodyView.Height - Application.GetRealHeight(120),
|
Height = Application.GetRealHeight(120),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
BodyView.AddChidren (bottomView);
|
|
Button btnClose = new Button () {
|
Width = Application.GetRealWidth (419),
|
TextID = R.MyInternationalizationString.Close,
|
TextSize = 15,
|
TextAlignment = TextAlignment.Center,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
bottomView.AddChidren (btnClose);
|
btnClose.MouseUpEventHandler += (sender, e) => {
|
this.Close ();
|
};
|
Button btnBottomLine = new Button () {
|
X = btnClose.Right,
|
Width = Application.GetRealWidth(2),
|
BackgroundColor = 0xFF333333,
|
};
|
bottomView.AddChidren (btnBottomLine);
|
Button btnSave = new Button () {
|
X = btnBottomLine.Right,
|
Width = Application.GetRealWidth (419),
|
TextID = R.MyInternationalizationString.SAVE,
|
TextSize = 15,
|
TextAlignment = TextAlignment.Center,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
bottomView.AddChidren (btnSave);
|
|
btnSave.MouseUpEventHandler += (sender, e) => {
|
try {
|
int channelNumber = 0;
|
string channelStr = etChannelNumber.Text.Trim ();
|
|
if (string.IsNullOrEmpty (etChannelName.Text.Trim ())||string.IsNullOrEmpty (etChannelNumber.Text.Trim ())) {
|
throw new Exception ();
|
}
|
|
if (int.TryParse (channelStr, out channelNumber)) {
|
InfraredCustomChannel icc = new InfraredCustomChannel ();
|
icc.ChannelName = etChannelName.Text.Trim ();
|
icc.ChannelNumber = etChannelNumber.Text.Trim ();
|
if (!string.IsNullOrEmpty (infraredTV.LinkInfraredMode)) {
|
InfraredMode stb = Newtonsoft.Json.JsonConvert.DeserializeObject<InfraredMode> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (infraredTV.LinkInfraredMode)));
|
icc.isTV = false;
|
icc.subnetID = stb.SubnetID;
|
icc.deviceID = stb.DeviceID;
|
icc.loopID = stb.LoopID;
|
icc.port = Convert.ToByte (stb.Port);
|
} else {
|
icc.isTV = true;
|
icc.subnetID = infraredTV.SubnetID;
|
icc.deviceID = infraredTV.DeviceID;
|
icc.loopID = infraredTV.LoopID;
|
icc.port = Convert.ToByte (infraredTV.Port);
|
}
|
|
foreach (var c in infraredTV.InfraredCustomChannel) {
|
if (c.ChannelName == etChannelName.Text.Trim ()) {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
}
|
}
|
|
/// <summary>
|
/// 自定义频道图标保存路径
|
/// </summary>
|
var imagePath = "Image_" + infraredTV.Name + etChannelName.Text + etChannelNumber.Text;
|
|
/// <summary>
|
/// 从相册中选择或者从照相机中拍摄图标时将图标另外存放,当选择资源文件时不做单独保存
|
/// </summary>
|
if (bodyMiddlePicture.UnSelectedImagePath == "GlobalTVPicture") {
|
IO.FileUtils.ReNameFile (bodyMiddlePicture.UnSelectedImagePath, imagePath);
|
bodyMiddlePicture.UnSelectedImagePath = imagePath;
|
} else
|
{
|
IO.FileUtils.DeleteFile (imagePath);
|
}
|
|
icc.ChannelIconPath = bodyMiddlePicture.UnSelectedImagePath;
|
infraredTV.InfraredCustomChannel.Add (icc);
|
IO.FileUtils.SaveEquipmentMessage (infraredTV, infraredTV.LoopID.ToString ());
|
BackAction (infraredTV);
|
Close ();
|
}
|
else
|
throw new Exception ();
|
} catch {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterTheCorrectData),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
}
|
};
|
#endregion
|
}
|
}
|
}
|