using System; using System.Collections.Generic; using System.Text; using Shared; using Shared.SimpleControl.R; using Shared.SimpleControl.Phone.Music; using Shared.SimpleControl.Phone; using Shared.SimpleControl; namespace SmartHome.UI.SimpleControl.Phone.Music { class A31Search : FrameLayout { /// /// 输入文本 /// EditText devicename; public void Show(A31MusicModel a31) { BackgroundColor = 0xffcccccc; Dialog window = new Dialog(); window.Show(); var frameLayout = new FrameLayout { Height = Application.GetRealHeight(250), Y = Application.GetRealHeight(300), BackgroundColor = 0xffffffff, }; window.AddChidren(frameLayout); var name = new Button { //TextID = MyInternationalizationString.cancel, Text = "输入关键字:", TextColor = 0xff000000, TextSize = 18, X = Application.GetRealWidth(10), Y = Application.GetRealHeight(20), Height = Application.GetRealHeight(75), Width = Application.GetRealWidth(200), TextAlignment = TextAlignment.CenterLeft, }; frameLayout.AddChidren(name); devicename = new EditText { Width = Application.GetRealWidth(620), Height = Application.GetRealHeight(80), Y = Application.GetRealHeight(80), X = Application.GetRealWidth(10), Gravity = Gravity.CenterVertical, BackgroundColor = 0xffcccccc, TextColor = 0xff000000, }; frameLayout.AddChidren(devicename); var searchname = new Button { //TextID = MyInternationalizationString.cancel, Text = "搜索", TextColor = 0xff000000, TextSize = 18, Width = Application.GetRealHeight(120), Height = Application.GetRealHeight(80), X = Application.GetRealWidth(350), Y = Application.GetRealHeight(170), }; frameLayout.AddChidren(searchname); searchname.MouseUpEventHandler += (sender, e) => { searchname.TextColor = 0xff000000; MainPage.Loading.Start(Language.StringByID(MyInternationalizationString.load) + "..."); System.Threading.Tasks.Task.Run(() => { var airablelist = serarchSong(devicename.Text); if (airablelist == null) { return; } Application.RunOnMainThread(() => { MainPage.Loading.Hide(); RemoveFromParent(); window.Close(); A31RadioList a31RadioList = new A31RadioList(); MainPage.MainFrameLayout.AddChidren(a31RadioList); a31RadioList.show(a31, airablelist, ""); }); }); }; searchname.MouseDownEventHandler += (sender, e) => { searchname.TextColor = 0xffFE5E00; }; var cancel = new Button { //TextID = MyInternationalizationString.cancel, Text = "取消", TextColor = 0xff333333, TextSize = 18, Width = Application.GetRealHeight(120), Height = Application.GetRealHeight(80), X = Application.GetRealWidth(500), Y = Application.GetRealHeight(170), }; frameLayout.AddChidren(cancel); cancel.MouseUpEventHandler += (sender1, e1) => { window.Close(); RemoveFromParent(); }; } static string userName = "ieast"; static string password = "60b25158ee94"; public static Airable serarchSong(string songName) { System.IO.StringReader sr = null; Airable airable = null; Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient(); try { webClient.Headers.Add("CONTENT-TYPE", "text/xml;charset=\"utf-8\""); webClient.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(userName + ":" + password))); byte[] recevieBytes = webClient.DownloadData(new Uri("http://meta.airable.io/view/airable/radios/search?q=" + songName)); sr = new System.IO.StringReader(Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length)); string line = null; StringBuilder stringBuilder = null; while ((line = sr.ReadLine()) != null) { line = line.Trim(); if (stringBuilder == null) { if (line.EndsWith("
") && sr.ReadLine().Trim() == "{") { stringBuilder = new StringBuilder(); stringBuilder.AppendLine("{"); } } else { if (line.EndsWith("")) { stringBuilder.AppendLine("}"); string s = @stringBuilder.ToString().Replace(",}", "}").Replace("\"content\": []", "\"content\": \"\""); airable = Newtonsoft.Json.JsonConvert.DeserializeObject(@s); break; } else { if (line.Contains("")) { line = line.Remove(line.IndexOf("") - line.IndexOf("", ""); } stringBuilder.AppendLine(@line); } } } } catch { } finally { if (sr != null) sr.Close(); } return airable; } } }