using System; using System.Collections.Generic; using Shared.SimpleControl; namespace Shared.SimpleControl.Phone { public class UserTVFrameLayout : FrameLayout { InfraredMode infraredTV; int PageIndex = 0; List TVList = new List (); Button btnAddTVKey; public UserTVFrameLayout (InfraredMode common) { BackgroundColor = SkinStyle.Current.MainColor; infraredTV = common; TVList.Add ("VolDown"); TVList.Add ("Chan.Up"); TVList.Add ("Menu"); TVList.Add ("Chan.Down"); TVList.Add ("VolUp"); TVList.Add ("Power"); TVList.Add ("Mute"); TVList.Add ("1");//7 TVList.Add ("2"); TVList.Add ("3"); TVList.Add ("4"); TVList.Add ("5"); TVList.Add ("6"); TVList.Add ("7"); TVList.Add ("8"); TVList.Add ("9"); TVList.Add (@"-/--"); TVList.Add ("0"); TVList.Add (@"AV/TV"); TVList.Add ("Back"); TVList.Add ("Confrim"); TVList.Add ("Up"); TVList.Add ("Left"); TVList.Add ("Down"); TVList.Add ("Right"); } 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 = infraredTV.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 = "Item/TV_TopBackground.png", Height = Application.GetRealHeight (500), }; FristBodyView.AddChidren (fristTopView); Button btnTVPower = new Button () { X = Application.GetRealWidth (10), Y = Application.GetRealHeight (20), Width = Application.GetMinRealAverage (131), Height = Application.GetMinRealAverage (131), UnSelectedImagePath = "Item/TV_Power.png", SelectedImagePath = "Item/TV_PowerSelected.png", IsSelected = infraredTV.isOpen, }; fristTopView.AddChidren (btnTVPower); btnTVPower.MouseUpEventHandler += (sender, e) => { infraredTV.isOpen = btnTVPower.IsSelected = !btnTVPower.IsSelected; int RandKey = ran.Next (0, 255); Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, (byte)InfraredCode_TV.Power, 0, 0, (byte)RandKey }); IO.FileUtils.SaveEquipmentMessage (infraredTV, infraredTV.LoopID.ToString ()); if(tempSwtich != null) { tempSwtich.IsSelected = infraredTV.isOpen; } }; Button btnTVUp = new Button () { X = Application.GetRealWidth (320 - 41), Y = Application.GetRealHeight (55), Width = Application.GetRealWidth (82), Height = Application.GetRealHeight (62), SelectedImagePath = "Item/TV_UpSelected.png", UnSelectedImagePath = "Item/TV_Up.png", }; fristTopView.AddChidren (btnTVUp); btnTVUp.MouseDownEventHandler += (sender, e) => { btnTVUp.IsSelected = true; }; btnTVUp.MouseUpEventHandler += (sender, e) => { btnTVUp.IsSelected = false; int RandKey = ran.Next (0, 255); Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, (byte)InfraredCode_TV.Up, 0, 0, (byte)RandKey }); }; Button btnDownIRCode = new Button () { X = Application.GetRealWidth (640 - 141), Y = Application.GetRealHeight (20), Width = Application.GetMinRealAverage (131), Height = Application.GetMinRealAverage (131), UnSelectedImagePath = "TV/DownIRCodeIcon.png", SelectedImagePath = "TV/DownIRCodeIcon.png", }; fristTopView.AddChidren (btnDownIRCode); btnDownIRCode.MouseUpEventHandler += (sender, e) => { var downIRCodeDialog = new ConfigIRCode (); downIRCodeDialog.Show (); downIRCodeDialog.ShowSystemInfrared (infraredTV); }; Button btnTVLeft = new Button () { X = Application.GetRealWidth (105), Y = Application.GetRealHeight (210), Width = Application.GetRealWidth (62), Height = Application.GetRealHeight (80), UnSelectedImagePath = "Item/TV_Left.png", SelectedImagePath = "Item/TV_LeftSelected.png", }; fristTopView.AddChidren (btnTVLeft); btnTVLeft.MouseDownEventHandler += (sender, e) => { btnTVLeft.IsSelected = true; }; btnTVLeft.MouseUpEventHandler += (sender, e) => { btnTVLeft.IsSelected = false; int RandKey = ran.Next (0, 255); Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, (byte)InfraredCode_TV.Left, 0, 0, (byte)RandKey }); }; Button btnOK = new Button () { X = Application.GetRealWidth (255), Y = Application.GetRealHeight (190), Width = Application.GetMinRealAverage (127), Height = Application.GetMinRealAverage (126), UnSelectedImagePath = "Item/TV_Ok.png", SelectedImagePath = "Item/TV_OkSelected.png", }; fristTopView.AddChidren (btnOK); btnOK.MouseDownEventHandler += (sender, e) => { btnOK.IsSelected = true; }; btnOK.MouseUpEventHandler += (sender, e) => { btnOK.IsSelected = false; int RandKey = ran.Next (0, 255); Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, (byte)InfraredCode_TV.Confrim, 0, 0, (byte)RandKey }); }; Button btnTVRight = new Button () { X = Application.GetRealWidth (640 - 167), Y = Application.GetRealHeight (210), Width = Application.GetRealWidth (62), Height = Application.GetRealHeight (80), UnSelectedImagePath = "Item/TV_Right.png", SelectedImagePath = "Item/TV_RightSelected.png", }; fristTopView.AddChidren (btnTVRight); btnTVRight.MouseDownEventHandler += (sender, e) => { btnTVRight.IsSelected = true; }; btnTVRight.MouseUpEventHandler += (sender, e) => { btnTVRight.IsSelected = false; int RandKey = ran.Next (0, 255); Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, (byte)InfraredCode_TV.Right, 0, 0, (byte)RandKey }); }; Button btnTVDown = new Button () { X = Application.GetRealWidth (320 - 41), Y = Application.GetRealHeight (382), Width = Application.GetRealWidth (82), Height = Application.GetRealHeight (62), SelectedImagePath = "Item/TV_DownSelected.png", UnSelectedImagePath = "Item/TV_Down.png", }; fristTopView.AddChidren (btnTVDown); btnTVDown.MouseDownEventHandler += (sender, e) => { btnTVDown.IsSelected = true; }; btnTVDown.MouseUpEventHandler += (sender, e) => { btnTVDown.IsSelected = false; int RandKey = ran.Next (0, 255); Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, (byte)InfraredCode_TV.Down, 0, 0, (byte)RandKey }); }; #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; int initCount = 0; if (infraredTV.TV_CustomFuntion.Count == 0) infraredTV.InitTVFunction (); if (infraredTV.TV_CustomFuntion.Count < 12) { initCount = 12; } else { initCount = infraredTV.TV_CustomFuntion.Count + (4 - infraredTV.TV_CustomFuntion.Count % 4); } for (int index = 0; index < initCount; index++) { if (index % 4 == 0) { Button btnHLine2 = new Button () { Height = 1, }; frist_VS_View.AddChidren (btnHLine2); HS_View_3 = new HorizontalScrolViewLayout () { Height = Application.GetRealHeight (138), ScrollEnabled = false, }; frist_VS_View.AddChidren (HS_View_3); } Button btn = new Button () { Width = Application.GetRealWidth (158), Height = Application.GetRealHeight (138), Padding = new Padding (Application.GetRealHeight (70), 0, 0, 0), TextColor = SkinStyle.Current.TextColor1, SelectedImagePath = "TV/TV_ON.png", BackgroundColor = SkinStyle.Current.ViewColor }; HS_View_3.AddChidren (btn); if (index > infraredTV.TV_CustomFuntion.Count - 1) { } else { btn.MouseDownEventHandler += (sender, e) => { ((Button)sender).IsSelected = true; }; if (infraredTV.TV_CustomFuntion [index].IsTV) { btn.Text = TVList [infraredTV.TV_CustomFuntion [index].TextID]; btn.SelectedImagePath = infraredTV.TV_CustomFuntion [index].SelectedImagePath == null ? "TV/TV_ON.png" :infraredTV.TV_CustomFuntion [index].SelectedImagePath ; btn.UnSelectedImagePath = infraredTV.TV_CustomFuntion [index].UnSelectedImagePath; btn.Tag = infraredTV.TV_CustomFuntion [index].FunctionCode; btn.MouseUpEventHandler += (sender, e) => { ((Button)sender).IsSelected = false; int RandKey = ran.Next (0, 255); Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, Convert.ToByte(((Button)sender).Tag), 0, 0, (byte)RandKey }); }; } } #region Edit if (index == initCount - 1) { btn.UnSelectedImagePath = "TV/TV_Edit.png"; btn.MouseUpEventHandler += (sender, e) => { Dialog dialog = new Dialog () ; FrameLayout dialogBodyView = new FrameLayout () { Width = Application.GetRealWidth (480)+1, Height = Application.GetRealHeight (740), BackgroundColor = SkinStyle.Current.DialogColor, Gravity = Gravity.Center, Radius = 5, BorderWidth = 0, BorderColor = SkinStyle.Current.Transparent }; dialog.AddChidren (dialogBodyView); FrameLayout dialogTopView = new FrameLayout () { Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.DialogTitle, }; dialogBodyView.AddChidren (dialogTopView); FrameLayout DialogBody = new FrameLayout () { Height = Application.GetRealHeight (570), Y = dialogTopView.Bottom, }; dialogBodyView.AddChidren (DialogBody); Button btnClose = new Button () { Height = Application.GetRealHeight (90), Y = DialogBody.Bottom, BackgroundColor = SkinStyle.Current.DialogTitle, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.Close, TextColor= SkinStyle.Current.TextColor1 }; dialogBodyView.AddChidren (btnClose); btnAddTVKey = new Button () { BackgroundColor = SkinStyle.Current.DialogTitle, SelectedBackgroundColor = SkinStyle.Current.DialogTitle, TextID = R.MyInternationalizationString.TV, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor =SkinStyle.Current.TextColor1, }; dialogTopView.AddChidren (btnAddTVKey); EventHandler hander = (sender1, e1) => { DialogBody.RemoveAll (); VerticalScrolViewLayout dialogVericalView = new VerticalScrolViewLayout () { X = 1, }; DialogBody.AddChidren (dialogVericalView); HorizontalScrolViewLayout dialogHorizontalView = null; for (int j = 0; j < 25; j++) { if (j % 3 == 0) { Button btnHLineH = new Button () { Height = 1 }; dialogVericalView.AddChidren (btnHLineH); dialogHorizontalView = new HorizontalScrolViewLayout () { Height = Application.GetRealHeight (138), Enable = false, ScrollEnabled = false, }; dialogVericalView.AddChidren (dialogHorizontalView); } Button btnTVAdd = new Button () { Width = Application.GetRealWidth (158), Height = Application.GetRealHeight (138), SelectedImagePath = "TV/TV_ON.png", UnSelectedImagePath = "TV/TVIcon.png", Padding = new Padding (Application.GetRealHeight (70), 0, 0, 0), Text = TVList [j], Tag = (InfraredCode_TV)Convert.ToByte (j + 1), TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.SelectedColor }; var tvCustomFuntion = infraredTV.TV_CustomFuntion.Find ((obj) => obj.FunctionCode == (j + 1) && obj.IsTV); if (null != tvCustomFuntion) { btnTVAdd.IsSelected = true; btnTVAdd.MouseUpEventHandler += (sender3, e3) => { if (btnTVAdd.IsSelected == true) { btnTVAdd.IsSelected = false; infraredTV.TV_CustomFuntion.Remove (tvCustomFuntion); IO.FileUtils.SaveEquipmentMessage (infraredTV, infraredTV.LoopID.ToString ()); } else { btnTVAdd.IsSelected = true; tvCustomFuntion = new InfraredCustomFunction () { FunctionCode = (int)((Button)sender3).Tag, DeviceFilePath = infraredTV.deviceFilePath, SelectedImagePath = "TV/TV_ON.png", UnSelectedImagePath = "TV/TVIcon.png", TextID = TVList.IndexOf (btnTVAdd.Text), }; infraredTV.TV_CustomFuntion.Add (tvCustomFuntion); IO.FileUtils.SaveEquipmentMessage (infraredTV, infraredTV.LoopID.ToString ()); } }; } else { btnTVAdd.IsSelected = false; btnTVAdd.MouseUpEventHandler += (sender3, e3) => { if (btnTVAdd.IsSelected == false) { btnTVAdd.IsSelected = true; tvCustomFuntion = new InfraredCustomFunction () { FunctionCode = (int)((Button)sender3).Tag, DeviceFilePath = infraredTV.deviceFilePath, UnSelectedImagePath = "TV/TVIcon.png", SelectedImagePath = "TV/TV_ON.png", TextID = TVList.IndexOf (btnTVAdd.Text), }; infraredTV.TV_CustomFuntion.Add (tvCustomFuntion); IO.FileUtils.SaveEquipmentMessage (infraredTV, infraredTV.LoopID.ToString ()); } else { btnTVAdd.IsSelected = false; infraredTV.TV_CustomFuntion.Remove (tvCustomFuntion); IO.FileUtils.SaveEquipmentMessage (infraredTV, infraredTV.LoopID.ToString ()); } }; } dialogHorizontalView.AddChidren (btnTVAdd); if (j % 3 != 2) { Button btnLine31 = new Button () { Width = 1 }; dialogHorizontalView.AddChidren (btnLine31); } } }; btnAddTVKey.MouseUpEventHandler += hander; hander (btnAddTVKey, null); btnClose.MouseDownEventHandler += (senderClose, eClose) => { btnClose.IsSelected = true; }; btnClose.MouseUpEventHandler += (senderClose, eClose) => { btnClose.IsSelected = false; dialog.Close (); ShowUserTV (); }; dialog.Show (); }; } if (index % 4 != 3) { Button btnLine31 = new Button () { Width = 1 }; HS_View_3.AddChidren (btnLine31); } } #endregion #endregion #endregion #region bottom FrameLayout bottom = new FrameLayout () { Y = BodyView.Bottom, Height = Application.GetRealHeight (100), BackgroundColor = SkinStyle.Current.MainColor }; AddChidren (bottom); #endregion UserTVNumberView tvNumberView = new UserTVNumberView (); BodyView.AddChidren (tvNumberView); tvNumberView.Show (infraredTV); UserTVCustomChannel tvCustomChannel = new UserTVCustomChannel (); BodyView.AddChidren (tvCustomChannel); tvCustomChannel.Show (infraredTV); BodyView.PageIndex = PageIndex; } } }