using System;
|
using System.Collections.Generic;
|
namespace Shared.SimpleControl.Phone
|
{
|
public class UserTVAddCustomChannel : Dialog
|
{
|
public UserTVAddCustomChannel ()
|
{
|
BackgroundColor = SkinStyle.Current.ViewColor;
|
}
|
|
public void Show (InfraredMode infrared, Action<InfraredMode> BackAction)
|
{
|
#region 标题
|
var topView = new FrameLayout () {
|
Height = Application.GetRealHeight (126),
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
AddChidren (topView);
|
|
|
Button title = new Button () {
|
TextAlignment = TextAlignment.Center,
|
Text = Language.StringByID (R.MyInternationalizationString.TV),
|
TextSize = 19,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
topView.AddChidren (title);
|
|
Button logo = new Button () {
|
Width = Application.GetRealWidth (154),
|
Height = Application.GetRealHeight (90),
|
X = Application.GetRealWidth (486),
|
Y = Application.GetRealHeight (36),
|
UnSelectedImagePath = MainPage.LogoString,
|
};
|
topView.AddChidren (logo);
|
Button back = new Button () {
|
Y = Application.GetRealHeight (35),
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
SelectedImagePath = "Item/BackSelected.png",
|
};
|
topView.AddChidren (back);
|
back.MouseUpEventHandler += (sender, e) => {
|
Close ();
|
};
|
#endregion
|
|
#region
|
FrameLayout channelNameView = new FrameLayout () {
|
Y = Application.GetRealHeight (126),
|
Height = Application.GetRealHeight (105),
|
};
|
this.AddChidren (channelNameView);
|
|
Button btnChannelNamePoint = new Button () {
|
X = Application.GetRealWidth (25),
|
Gravity = Gravity.CenterVertical,
|
Width = Application.GetRealWidth (10),
|
Height = Application.GetRealHeight (10),
|
UnSelectedImagePath = "Item/Point.png",
|
SelectedImagePath = "Item/Point.png",
|
};
|
channelNameView.AddChidren (btnChannelNamePoint);
|
EditText etChannelName = new EditText () {
|
Width = Application.GetRealWidth (550),
|
X = Application.GetRealWidth (60),
|
PlaceholderText = Language.StringByID (R.MyInternationalizationString.ChannelName),
|
PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextSize = 15,
|
};
|
channelNameView.AddChidren (etChannelName);
|
|
Button btnChannelNameNull = new Button () {
|
Height = Application.GetRealHeight (3),
|
Y = channelNameView.Height - 1,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
channelNameView.AddChidren (btnChannelNameNull);
|
|
FrameLayout channelNumberView = new FrameLayout () {
|
Height = Application.GetRealHeight (105),
|
Y = channelNameView.Bottom,
|
};
|
this.AddChidren (channelNumberView);
|
|
Button btnChannelNumberPoint = new Button () {
|
Width = Application.GetRealWidth (10),
|
Height = Application.GetRealHeight (10),
|
X = Application.GetRealWidth (25),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/Point.png",
|
SelectedImagePath = "Item/Point.png",
|
};
|
channelNumberView.AddChidren (btnChannelNumberPoint);
|
|
EditText etChannelNumber = new EditText () {
|
X = Application.GetRealWidth (60),
|
Width = Application.GetRealWidth (550),
|
PlaceholderText = Language.StringByID (R.MyInternationalizationString.ChannelNumber),
|
PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextSize = 15,
|
};
|
channelNumberView.AddChidren (etChannelNumber);
|
etChannelNumber.TextChangeEventHandler += (sender, e) => {
|
if (e.Length > 6) {
|
etChannelNumber.Text = e.Remove (6);
|
}
|
};
|
|
var btnChannelNumberNull = new Button () {
|
Y = Application.GetRealHeight (105) - 1,
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
channelNumberView.AddChidren (btnChannelNumberNull);
|
#endregion
|
|
#region bodyMiddle
|
FrameLayout middleView = new FrameLayout () {
|
Y = channelNumberView.Bottom,
|
Height = Application.GetRealHeight (190),
|
};
|
AddChidren (middleView);
|
|
Button bodyMiddlePicture = new Button () {
|
X = Application.GetRealWidth (25),
|
Y = Application.GetRealHeight (15),
|
Width = Application.GetRealWidth (225),
|
Height = Application.GetRealHeight (165),
|
UnSelectedImagePath = "TV/TV3_1.png",
|
};
|
middleView.AddChidren (bodyMiddlePicture);
|
|
Button pictureRightLine = new Button () {
|
X = bodyMiddlePicture.Right + Application.GetRealWidth (20),
|
Width = 1,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
middleView.AddChidren (pictureRightLine);
|
#if wallon
|
bodyMiddlePicture.Gravity = Gravity.Center;
|
#else
|
Button btnTakePictrue = new Button () {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (90),
|
TextColor = SkinStyle.Current.TextColor1,
|
TextID = R.MyInternationalizationString.TakePhoto,
|
UnSelectedImagePath = "TV/TV3_photo.png",
|
SelectedImagePath = "TV/TV3_photo_on.png",
|
X = pictureRightLine.Right,
|
};
|
middleView.AddChidren (btnTakePictrue);
|
|
Button btnLineP = new Button () {
|
X = btnTakePictrue.X,
|
Y = btnTakePictrue.Bottom,
|
Width = btnTakePictrue.Width,
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
middleView.AddChidren (btnLineP);
|
|
Button btnSelectPictrue = new Button () {
|
X = btnTakePictrue.X,
|
Y = btnLineP.Bottom,
|
Width = btnTakePictrue.Width,
|
Height = btnTakePictrue.Height,
|
TextID = R.MyInternationalizationString.SelectPicture,
|
TextColor = SkinStyle.Current.TextColor1,
|
UnSelectedImagePath = "TV/TV3_photo.png",
|
SelectedImagePath = "TV/TV3_photo_on.png",
|
};
|
middleView.AddChidren (btnSelectPictrue);
|
|
var pid = Guid.NewGuid ();
|
btnTakePictrue.MouseUpEventHandler += (sender, e) => {
|
btnTakePictrue.IsSelected = true;
|
pid = Guid.NewGuid ();
|
btnSelectPictrue.IsSelected = false;
|
Camera.TakePicture ((obj) => {
|
if (obj != null) {
|
bodyMiddlePicture.UnSelectedImagePath = pid.ToString ();
|
}
|
}, pid.ToString (), false);
|
};
|
|
btnSelectPictrue.MouseUpEventHandler += (sender, e) => {
|
btnTakePictrue.IsSelected = false;
|
pid = Guid.NewGuid ();
|
btnSelectPictrue.IsSelected = true;
|
Camera.SelectPicture ((obj) => {
|
if (obj != null) {
|
bodyMiddlePicture.UnSelectedImagePath = pid.ToString ();
|
}
|
}, pid.ToString (), false);
|
};
|
#endif
|
Button btnPhotoViewBottomLine = new Button () {
|
Y = middleView.Height - 1,
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
middleView.AddChidren (btnPhotoViewBottomLine);
|
#endregion
|
|
#region TVIconView
|
VerticalScrolViewLayout TVIconView = new VerticalScrolViewLayout () {
|
Height = Application.GetRealHeight (500),
|
Y = middleView.Bottom + Application.GetRealHeight (15),
|
};
|
this.AddChidren (TVIconView);
|
|
int iconCount = 0;
|
while (true) {
|
HorizontalScrolViewLayout horizontalScrolView = new HorizontalScrolViewLayout () {
|
Height = Application.GetMinRealAverage (125),
|
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 (25),
|
};
|
horizontalScrolView.AddChidren (btnNull);
|
Button btnIcon = new Button () {
|
Width = Application.GetMinRealAverage (180),
|
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
|
var lineBottom = new Button () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (5),
|
Y = TVIconView.Bottom,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
this.AddChidren (lineBottom);
|
|
var btnSave = new Button () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (75),
|
Y = lineBottom.Bottom + Application.GetRealHeight (18),
|
TextID = R.MyInternationalizationString.SAVE,
|
TextSize = 15,
|
TextAlignment = TextAlignment.Center,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
this.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)) {
|
foreach (var c in infrared.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;
|
}
|
}
|
InfraredCustomChannel icc = new InfraredCustomChannel ();
|
icc.ChannelName = etChannelName.Text.Trim ();
|
icc.ChannelNumber = etChannelNumber.Text.Trim ();
|
icc.loopID = infrared.LoopID;
|
icc.port = Convert.ToByte (infrared.Port);
|
|
|
/// <summary>
|
/// 自定义频道图标保存路径
|
/// </summary>
|
var imagePath = "Image_" + infrared.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;
|
infrared.InfraredCustomChannel.Add (icc);
|
IO.FileUtils.SaveEquipmentMessage (infrared, infrared.LoopID.ToString ());
|
BackAction (infrared);
|
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
|
}
|
}
|
}
|