using Shared.SimpleControl.Phone; using System; using System.Collections.Generic; using Shared.SimpleControl; namespace Shared.SimpleControl.Pad { public class UserTVFrameLayout : FrameLayout { //InfraredMode infraredTV; InfraredMode linkSTB; Button btn; List TVList = new List (); List STBList = new List (); Button btnAddTVKey; Button btnAddSTBKey; public UserTVFrameLayout (InfraredMode common) { if (Language.CurrentLanguage == "Chinese") { TVList.Add ("音量-"); TVList.Add ("频道+"); TVList.Add ("菜单"); TVList.Add ("频道-"); TVList.Add ("音量+"); TVList.Add ("电源"); TVList.Add ("静音"); TVList.Add ("1"); 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 ("返回"); TVList.Add ("确认"); TVList.Add ("上"); TVList.Add ("左"); TVList.Add ("右"); TVList.Add ("下"); STBList.Add ("待机"); STBList.Add ("1"); STBList.Add ("2"); STBList.Add ("3"); STBList.Add ("4"); STBList.Add ("5"); STBList.Add ("6"); STBList.Add ("7"); STBList.Add ("8"); STBList.Add ("9"); STBList.Add ("主页"); STBList.Add ("0"); STBList.Add ("返回");//12 STBList.Add ("上"); STBList.Add ("左"); STBList.Add ("确认"); STBList.Add ("右"); STBList.Add ("下"); STBList.Add ("音量+"); STBList.Add ("音量-"); STBList.Add ("频道+"); STBList.Add ("频道-"); STBList.Add ("菜单"); } else { TVList.Add ("VolDown"); TVList.Add ("ChannelUp"); TVList.Add ("Menu"); TVList.Add ("ChannelDown"); TVList.Add ("VolUp"); TVList.Add ("Power"); TVList.Add ("Mute"); TVList.Add ("1"); 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"); STBList.Add ("Standby"); STBList.Add ("1"); STBList.Add ("2"); STBList.Add ("3"); STBList.Add ("4"); STBList.Add ("5"); STBList.Add ("6"); STBList.Add ("7"); STBList.Add ("8"); STBList.Add ("9"); STBList.Add ("HomePage"); STBList.Add ("0"); STBList.Add ("Back"); STBList.Add ("Up"); STBList.Add ("Left"); STBList.Add ("Confrim"); STBList.Add ("Right"); STBList.Add ("Down"); STBList.Add ("VolUp"); STBList.Add ("VolDown"); STBList.Add ("ChannelUp"); STBList.Add ("ChannelDown"); STBList.Add ("Menu"); } } public void ShowUserTV (InfraredMode infraredTV) { RemoveAll (); if (!string.IsNullOrEmpty (infraredTV.LinkInfraredMode)) { linkSTB = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (infraredTV.LinkInfraredMode))); } else linkSTB = null; Random ran = new Random (); #region middle FrameLayout BodyView = new FrameLayout () { BackgroundColor = SkinStyle.Current.MainColor }; AddChidren (BodyView); #region FristBodyView FrameLayout FristBodyView = new FrameLayout (); BodyView.AddChidren (FristBodyView); FrameLayout fristTopView = new FrameLayout () { X = Application.GetRealWidth (10), Y = Application.GetRealHeight (10), Height = Application.GetRealHeight (520), }; FristBodyView.AddChidren (fristTopView); Button btnTVUp = new Button () { Y = Application.GetRealHeight (55), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth (82), Height = Application.GetRealHeight (62), SelectedImagePath = "Item/TV_UpSelected.png", UnSelectedImagePath = "Item/TV_Up.png", }; fristTopView.AddChidren (btnTVUp); btnTVUp.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); if (infraredTV.isControlTV) Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, (byte)InfraredCode_TV.Up, 0, 0, (byte)RandKey }); else Control.ControlBytesSend (Command.InfraredControl, linkSTB.SubnetID, linkSTB.DeviceID, new byte [] { Convert.ToByte (linkSTB.Port), linkSTB.LoopID, (byte)InfraredCode_STB.Up, 0, 0, (byte)RandKey }); }; Button btnTVLeft = new Button () { X = Application.GetRealWidth (60), 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.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); if (infraredTV.isControlTV) Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, (byte)InfraredCode_TV.Left, 0, 0, (byte)RandKey }); else Control.ControlBytesSend (Command.InfraredControl, linkSTB.SubnetID, linkSTB.DeviceID, new byte [] { Convert.ToByte (linkSTB.Port), linkSTB.LoopID, (byte)InfraredCode_STB.Left, 0, 0, (byte)RandKey }); }; Button btnOK = new Button () { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight (190), Width = Application.GetMinRealAverage (127), Height = Application.GetMinRealAverage (126), SelectedImagePath = "Item/TV_OK.png", UnSelectedImagePath = "Item/TV_OkSelected.png", }; fristTopView.AddChidren (btnOK); btnOK.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); if (infraredTV.isControlTV) Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, (byte)InfraredCode_TV.Confrim, 0, 0, (byte)RandKey }); else Control.ControlBytesSend (Command.InfraredControl, linkSTB.SubnetID, linkSTB.DeviceID, new byte [] { Convert.ToByte (linkSTB.Port), linkSTB.LoopID, (byte)InfraredCode_STB.Confrim, 0, 0, (byte)RandKey }); }; Button btnTVRight = new Button () { X = Application.GetRealWidth (420), 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.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); if (infraredTV.isControlTV) Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, (byte)InfraredCode_TV.Right, 0, 0, (byte)RandKey }); else Control.ControlBytesSend (Command.InfraredControl, linkSTB.SubnetID, linkSTB.DeviceID, new byte [] { Convert.ToByte (linkSTB.Port), linkSTB.LoopID, (byte)InfraredCode_STB.Right, 0, 0, (byte)RandKey }); }; Button btnTVDown = new Button () { Gravity = Gravity.CenterHorizontal, 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.MouseUpEventHandler += (sender, e) => { int RandKey = ran.Next (0, 255); if (infraredTV.isControlTV) Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, (byte)InfraredCode_TV.Down, 0, 0, (byte)RandKey }); else Control.ControlBytesSend (Command.InfraredControl, linkSTB.SubnetID, linkSTB.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), linkSTB.LoopID, (byte)InfraredCode_STB.Down, 0, 0, (byte)RandKey }); }; Button btnChangeTopControl = new Button () { X = Application.GetRealWidth (380), Y = Application.GetRealHeight (350), Width = Application.GetMinRealAverage (131), Height = Application.GetMinRealAverage (131), SelectedImagePath = "TV/ChangeTV.png", UnSelectedImagePath = "TV/ChangeSTB.png", IsSelected = infraredTV.isControlTV }; if (linkSTB != null) fristTopView.AddChidren (btnChangeTopControl); btnChangeTopControl.MouseUpEventHandler += (sender, e) => { Application.RunOnMainThread (() => { infraredTV.isControlTV = !infraredTV.isControlTV; btnChangeTopControl.IsSelected = infraredTV.isControlTV; IO.FileUtils.SaveEquipmentMessage (infraredTV, infraredTV.LoopID.ToString ()); }); }; #endregion #region SecondBodyView FrameLayout SecondBodyView = new FrameLayout () { Y = fristTopView.Bottom, Height = Application.GetRealHeight (860), }; 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 < 8) { initCount = 8; } else { initCount = infraredTV.TV_CustomFuntion.Count + (2 + infraredTV.TV_CustomFuntion.Count % 2); } for (int index = 0; index < initCount; index++) { if (index % 2 == 0) { Button btnHLine2 = new Button () { Height = Application.GetRealHeight (8), }; frist_VS_View.AddChidren (btnHLine2); HS_View_3 = new HorizontalScrolViewLayout () { Height = Application.GetRealHeight (200), Enable = false, ScrollEnabled = false }; frist_VS_View.AddChidren (HS_View_3); } btn = new Button () { Width = Application.GetRealWidth (260), Height = Application.GetRealHeight (200), Padding = new Padding (Application.GetRealHeight (70), 0, 0, 0), BackgroundColor = SkinStyle.Current.MainColor, TextColor = SkinStyle.Current.TextColor1, }; 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; 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 }); }; } else { btn.Text = STBList [infraredTV.TV_CustomFuntion [index].TextID]; btn.SelectedImagePath = 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; if (linkSTB == null) return; int RandKey = ran.Next (0, 255); Control.ControlBytesSend (Command.InfraredControl, linkSTB.SubnetID, linkSTB.DeviceID, new byte [] { Convert.ToByte (linkSTB.Port), linkSTB.LoopID, Convert.ToByte(((Button)sender).Tag), 0, 0, (byte)RandKey }); }; } } #endregion #region Edit if (index == initCount - 1) { btn.UnSelectedImagePath = "TV/TV_Edit.png"; btn.MouseUpEventHandler += (sender, e) => { Dialog AddButtonDialog = new Dialog () { Width = Application.GetRealWidth (641), Height = Application.GetRealHeight (751), }; FrameLayout DialogBodyView = new FrameLayout () { BorderWidth = 1, Radius = 5 }; AddButtonDialog.AddChidren (DialogBodyView); var horizontalScrolView = new FrameLayout () { Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.TextColor1, }; DialogBodyView.AddChidren (horizontalScrolView); var DialogBody = new FrameLayout () { BackgroundColor = SkinStyle.Current.TextColor1, Height = Application.GetRealHeight (570), Y = horizontalScrolView.Bottom, }; DialogBodyView.AddChidren (DialogBody); Button btnClose = new Button () { Height = Application.GetRealHeight (90), Y = DialogBody.Bottom + Application.GetRealHeight (1), BackgroundColor = 0xFFDBDDDF, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.Close }; DialogBodyView.AddChidren (btnClose); btnAddTVKey = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (320), BackgroundColor = 0xFFDBDDDF, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.TV }; horizontalScrolView.AddChidren (btnAddTVKey); Button btnTopLine = new Button () { Width = 1, X = btnAddTVKey.Right }; horizontalScrolView.AddChidren (btnTopLine); btnAddSTBKey = new Button () { X = btnTopLine.Right, Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (318), BackgroundColor = 0xFFDBDDDF, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.STB }; horizontalScrolView.AddChidren (btnAddSTBKey); EventHandler hander = (sender1, e1) => { DialogBody.RemoveAll (); btnAddTVKey.IsSelected = true; btnAddSTBKey.IsSelected = false; VerticalScrolViewLayout dialogVericalView = new VerticalScrolViewLayout (); DialogBody.AddChidren (dialogVericalView); HorizontalScrolViewLayout dialogHorizontalView = null; for (int j = 0; j < 25; j++) { if (j % 4 == 0) { Button btnHLineH = new Button () { Height = 1 }; dialogVericalView.AddChidren (btnHLineH); dialogHorizontalView = new HorizontalScrolViewLayout () { Height = Application.GetRealHeight (138), Enable = false, }; dialogVericalView.AddChidren (dialogHorizontalView); } Button btnLine5 = new Button () { Width = 1, }; dialogHorizontalView.AddChidren (btnLine5); 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), }; 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", 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); } }; btnAddTVKey.MouseUpEventHandler += hander; EventHandler STBhander = (sender1, e1) => { DialogBody.RemoveAll (); btnAddTVKey.IsSelected = false; btnAddSTBKey.IsSelected = true; if (string.IsNullOrEmpty (infraredTV.LinkInfraredMode)) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseBindTheSTB), Language.StringByID (R.MyInternationalizationString.Close)).Show (); AddButtonDialog.Close (); } VerticalScrolViewLayout dialogVericalView = new VerticalScrolViewLayout () { }; DialogBody.AddChidren (dialogVericalView); HorizontalScrolViewLayout dialogHorizontalView = null; for (int j = 0; j < STBList.Count; j++) { if (j % 4 == 0) { Button btnHLineH = new Button () { Height = 1 }; dialogVericalView.AddChidren (btnHLineH); dialogHorizontalView = new HorizontalScrolViewLayout () { Height = Application.GetRealHeight (138), Enable = false, }; dialogVericalView.AddChidren (dialogHorizontalView); } Button btnLine7 = new Button () { Width = 1, }; dialogHorizontalView.AddChidren (btnLine7); Button btnSTBAdd = new Button () { Width = Application.GetRealWidth (158), Height = Application.GetRealHeight (138), SelectedImagePath = "TV/STB_ON.png", UnSelectedImagePath = "TV/STBIcon.png", Padding = new Padding (Application.GetRealHeight (70), 0, 0, 0), Text = STBList [j], Tag = (InfraredCode_STB)Convert.ToByte (j + 1), }; var stbCustomFunction = infraredTV.TV_CustomFuntion.Find ((obj) => obj.FunctionCode == (j + 1) && !obj.IsTV); if (null != stbCustomFunction) { btnSTBAdd.IsSelected = true; btnSTBAdd.MouseUpEventHandler += (sender3, e3) => { if (btnSTBAdd.IsSelected == true) { btnSTBAdd.IsSelected = false; infraredTV.TV_CustomFuntion.Remove (stbCustomFunction); IO.FileUtils.SaveEquipmentMessage (infraredTV, infraredTV.LoopID.ToString ()); } else { btnSTBAdd.IsSelected = true; stbCustomFunction = new InfraredCustomFunction () { FunctionCode = (int)btnSTBAdd.Tag, DeviceFilePath = infraredTV.deviceFilePath, UnSelectedImagePath = "TV/STBIcon.png", SelectedImagePath = "TV/STB_ON.png", TextID = STBList.IndexOf (btnSTBAdd.Text), IsTV = false, }; infraredTV.TV_CustomFuntion.Add (stbCustomFunction); IO.FileUtils.SaveEquipmentMessage (infraredTV, infraredTV.LoopID.ToString ()); } }; } else { btnSTBAdd.IsSelected = false; btnSTBAdd.MouseUpEventHandler += (sender3, e3) => { if (btnSTBAdd.IsSelected == false) { btnSTBAdd.IsSelected = true; stbCustomFunction = new InfraredCustomFunction () { FunctionCode = (int)btnSTBAdd.Tag, DeviceFilePath = infraredTV.deviceFilePath, UnSelectedImagePath = "TV/STBIcon.png", TextID = STBList.IndexOf (btnSTBAdd.Text), IsTV = false, }; infraredTV.TV_CustomFuntion.Add (stbCustomFunction); IO.FileUtils.SaveEquipmentMessage (infraredTV, infraredTV.LoopID.ToString ()); } else { btnSTBAdd.IsSelected = false; infraredTV.TV_CustomFuntion.Remove (stbCustomFunction); IO.FileUtils.SaveEquipmentMessage (infraredTV, infraredTV.LoopID.ToString ()); } }; } //} dialogHorizontalView.AddChidren (btnSTBAdd); } }; btnAddSTBKey.MouseUpEventHandler += STBhander; hander (btnAddTVKey, null); btnClose.MouseDownEventHandler += (senderClose, eClose) => { btnClose.IsSelected = true; }; btnClose.MouseUpEventHandler += (senderClose, eClose) => { btnClose.IsSelected = false; AddButtonDialog.Close (); this.ShowUserTV (infraredTV); }; AddButtonDialog.Show (); }; } //if (index % 2 != 0) { Button btnLine31 = new Button () { Width = Application.GetRealWidth (10), }; HS_View_3.AddChidren (btnLine31); //} #endregion } #endregion } } }