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 A31CommonLogin : FrameLayout { /// /// 密码 /// EditText password; /// /// 用户名 /// EditText userName; A31MusicModel currentMusiceA31; public void show (A31MusicModel a31, string url, string topname) { currentMusiceA31 = a31; AddChidren (new Button { Height = Application.GetRealHeight (36), BackgroundColor = SkinStyle.Current.MainColor, }); var topFrameLayout = new FrameLayout { Height = Application.GetRealHeight (90), Y = Application.GetRealHeight (30), BackgroundColor = SkinStyle.Current.MainColor, }; AddChidren (topFrameLayout); var LocallistName = new Button { TextID = MyInternationalizationString.login, }; topFrameLayout.AddChidren (LocallistName); var hdl = new Button { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), Gravity = Gravity.CenterVertical, UnSelectedImagePath = MainPage.LogoString, }; topFrameLayout.AddChidren (hdl); var back = new Button { Width = Application.GetRealWidth (82), Height = Application.GetRealHeight (89), X = Application.GetRealWidth (10), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/HomepageBack.png", }; topFrameLayout.AddChidren (back); back.MouseDownEventHandler += (sender, e) => { RemoveFromParent (); }; var middle = new FrameLayout (); middle.Y = topFrameLayout.Bottom; middle.Height = Application.GetRealHeight (Application.DesignHeight - 126); middle.BackgroundColor = 0xff2F2F2F; AddChidren (middle); userName = new EditText { Width = Application.GetRealWidth (580), Height = Application.GetRealHeight (80), X = Application.GetRealWidth (30), Y = Application.GetRealHeight (180), TextAlignment = TextAlignment.CenterLeft, BackgroundColor = 0xFF4D4D4D, PlaceholderText = Language.StringByID (MyInternationalizationString.Youremail), PlaceholderTextColor = 0x80ffffff, }; middle.AddChidren (userName); password = new EditText { Width = Application.GetRealWidth (580), Height = Application.GetRealHeight (80), X = Application.GetRealWidth (30), Y = Application.GetRealHeight (300), TextAlignment = TextAlignment.CenterLeft, BackgroundColor = 0xFF4D4D4D, SecureTextEntry = true, PlaceholderText = Language.StringByID (MyInternationalizationString.Yourpassword), PlaceholderTextColor = 0x80ffffff, }; middle.AddChidren (password); Button login = new Button { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (100), X = Application.GetRealWidth (70), Y = Application.GetRealHeight (460), BackgroundColor = 0xff009999, TextID = MyInternationalizationString.login, TextSize = 18, Radius = (uint)Application.GetRealHeight (16), }; login.MouseUpEventHandler += (sender, e) => { login.BackgroundColor = 0xff009999; MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); var tempUserName = userName.Text; var tempPassword = password.Text; System.Threading.Tasks.Task.Run (() => { Airable airable = null; try { airable = ReadRadiohome (tempUserName, tempPassword, url); if (airable == null) { airable = ReadRadiohome (tempUserName, tempPassword, url); } } catch (Exception ee) { var dd = ee.Message; } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); if (airable == null) { new Tip () { Text = Language.StringByID (MyInternationalizationString.Accountorpassworderro), Direction = AMPopTipDirection.Down }.Show (login); return; } else { var RadioConfigBytes = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (new RadioConfig { UserName = userName.Text, Passwrod = password.Text })); Shared.IO.FileUtils.WriteFileByBytes (RadioConfig.FileName, RadioConfigBytes); } A31RadioList a31RadioList = new A31RadioList (); MainPage.MainFrameLayout.AddChidren (a31RadioList); a31RadioList.show (a31, airable, topname); }); } }); }; login.MouseDownEventHandler += (sender, e) => { login.BackgroundColor = 0xffFE5E00; }; var radioConfig = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (RadioConfig.FileName))); if (radioConfig != null) { userName.Text = radioConfig.UserName; password.Text = radioConfig.Passwrod; MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { Airable airable = null; try { airable = ReadRadiohome (radioConfig.UserName, radioConfig.Passwrod, url); if (airable == null) { airable = ReadRadiohome (radioConfig.UserName, radioConfig.Passwrod, url); } } catch (Exception ee) { var dd = ee.Message; } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); if (airable == null) { new Tip () { Text = Language.StringByID (MyInternationalizationString.Accountorpassworderro), Direction = AMPopTipDirection.Down }.Show (login); return; } else { var RadioConfigBytes = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (new RadioConfig { UserName = userName.Text, Passwrod = password.Text })); Shared.IO.FileUtils.WriteFileByBytes (RadioConfig.FileName, RadioConfigBytes); } A31RadioList a31RadioList = new A31RadioList(); MainPage.MainFrameLayout.AddChidren (a31RadioList); a31RadioList.show (a31, airable, topname); }); } }); } middle.AddChidren (login); } public static Airable ReadRadiohome (string userName, string password, string url) { System.IO.StringReader sr = null; Airable airable = null; try { Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (); 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 (url)); //var ddd = Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length); 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 ("", ""); } if (line.Contains ("description")) { //line = line.Remove(); } else { stringBuilder.AppendLine (@line); } } } } } catch (Exception e) { } finally { if (sr != null) sr.Close (); } return airable; } } }