using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Shared;
|
using Shared.SimpleControl.R;
|
using System.Xml;
|
using Shared.SimpleControl.Phone;
|
using Shared.SimpleControl;
|
|
namespace SmartHome.UI.SimpleControl.Phone.Music
|
{
|
class A31UserLogin : FrameLayout
|
{
|
/// <summary>
|
/// 用户名
|
/// </summary>
|
EditText username;
|
/// <summary>
|
/// 密码
|
/// </summary>
|
EditText password;
|
A31MusicModel currentMusiceA31;
|
public void show (A31MusicModel a31, string TextUserName, string TextPasswrod)
|
{
|
currentMusiceA31 = a31;
|
AddChidren (new Button {
|
Height = Application.GetRealHeight (36),
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
});
|
|
var topFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (100),
|
Y = Application.GetRealHeight (36),
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
};
|
AddChidren (topFrameLayout);
|
|
var RadiolistName = new Button {
|
TextID = MyInternationalizationString.PANDORA,
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
topFrameLayout.AddChidren (RadiolistName);
|
|
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 frameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (Application.DesignHeight - 136),
|
Y = Application.GetRealHeight (136),
|
//BackgroundColor = 0xff2F2F2F,
|
BackgroundColor=SkinStyle.Current.MusicVerticalScrolViewLayout,
|
};
|
AddChidren (frameLayout);
|
|
var tologin = new Button {
|
Height = Application.GetRealHeight (100),
|
TextID = MyInternationalizationString.Tologin,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (25),
|
Y = Application.GetRealHeight (10),
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
frameLayout.AddChidren (tologin);
|
|
//用户名
|
username = new EditText {
|
Width = Application.GetRealWidth (590),
|
Height = Application.GetRealHeight (80),
|
X = Application.GetRealWidth (25),
|
Y = Application.GetRealHeight (130),
|
TextAlignment = TextAlignment.Center,
|
Text = TextUserName,
|
//Radius = (uint)Application.GetRealHeight(6),
|
BackgroundColor =SkinStyle.Current.MusicEditTextBackgroundColor,
|
PlaceholderText = Language.StringByID (MyInternationalizationString.Youremail),
|
PlaceholderTextColor =SkinStyle.Current.MusicEditTextPlaceholderTextColor,
|
TextColor = SkinStyle.Current.MusicTextColor,
|
Radius=2,
|
BorderWidth=2,
|
BorderColor=SkinStyle.Current.MusicEditBorderColor,
|
};
|
frameLayout.AddChidren (username);
|
|
//密码
|
password = new EditText {
|
Width = Application.GetRealWidth (590),
|
Height = Application.GetRealHeight (80),
|
X = Application.GetRealWidth (25),
|
Y = Application.GetRealHeight (230),
|
TextAlignment = TextAlignment.Center,
|
Text = TextPasswrod,
|
SecureTextEntry = true,
|
//Radius = (uint)Application.GetRealHeight(6),
|
BackgroundColor = SkinStyle.Current.MusicEditTextBackgroundColor,
|
PlaceholderText = Language.StringByID (MyInternationalizationString.yourpassword),
|
TextColor = SkinStyle.Current.MusicTextColor,
|
Radius = 2,
|
BorderWidth = 2,
|
BorderColor = SkinStyle.Current.MusicEditBorderColor,
|
};
|
frameLayout.AddChidren (password);
|
|
var notologin = new Button {
|
Height = Application.GetRealHeight (100),
|
TextID = MyInternationalizationString.Toregister,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (25),
|
Y = Application.GetRealHeight (350),
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
frameLayout.AddChidren (notologin);
|
|
//登录
|
var login = new Button {
|
Width = Application.GetRealWidth (590),
|
Height = Application.GetRealHeight (100),
|
TextID = MyInternationalizationString.login,
|
TextSize = 18,
|
X = Application.GetRealWidth (25),
|
Y = Application.GetRealHeight (450),
|
BackgroundColor = 0xff656565,
|
//Radius = (uint)Application.GetRealHeight(6),
|
};
|
frameLayout.AddChidren (login);
|
|
login.MouseUpEventHandler += (sender, e) => {
|
login.BackgroundColor = 0xff656565;
|
if (username.Text.Trim () == "" || password.Text.Trim () == "") {
|
new Alert (Language.StringByID (MyInternationalizationString.Tip),
|
Language.StringByID (MyInternationalizationString.TipPleaseEnterTheCorrectData),
|
Language.StringByID (MyInternationalizationString.Close)).Show ();
|
return;
|
}
|
MainPage.Loading.Start ("Loging...");
|
|
var tempusername = username.Text;
|
var temppassword = password.Text;
|
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
var dd = Login (tempusername, temppassword);
|
if (dd == null) {
|
return;
|
}
|
int number = 3;
|
System.DateTime dateTime = DateTime.Now;
|
while ((DateTime.Now - dateTime).TotalMilliseconds < 9 * 1000) {
|
System.Threading.Thread.Sleep (500);
|
var pandoraString = readList ();
|
if (pandoraString == null) {
|
continue;
|
}
|
pandoraString = pandoraString.Replace ("&", "&").Replace ("<", "<").Replace (">", ">").Replace (""", "\"").Replace ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "").Replace ("<", "").Replace (">", "").Replace ("&", "").Replace (""", "");
|
int startIndex5 = pandoraString.IndexOf ("<PlayList>");
|
int endIndex = pandoraString.IndexOf ("</PlayList>") + "</PlayList>".Length;
|
if (endIndex <= startIndex5) {
|
continue;
|
}
|
var ss = pandoraString.Substring (startIndex5, endIndex - startIndex5);
|
XmlDocument xml = new XmlDocument ();
|
xml.LoadXml (ss);
|
|
var playList = xml.SelectSingleNode ("PlayList");
|
|
var listNameP = playList.SelectSingleNode ("ListName").InnerText;
|
|
var listInfo = playList.SelectSingleNode ("ListInfo");
|
|
number = int.Parse (listInfo.SelectSingleNode ("MarkSearch").InnerText);
|
if (number == 1) {
|
break;
|
}
|
}
|
if (number == 1) {
|
var pandoraListString = PandoraList ();
|
if (pandoraListString == null) {
|
return;
|
}
|
|
pandoraListString = pandoraListString.Replace ("&", "&").Replace ("<", "<").Replace (">", ">").Replace (""", "\"").Replace ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "").Replace ("<", "").Replace (">", "").Replace ("&", "").Replace (""", "");
|
int startIndex1 = pandoraListString.IndexOf ("<PlayQueue>");
|
int endIndex1 = pandoraListString.IndexOf ("</PlayQueue>") + "</PlayQueue>".Length;
|
var aa = pandoraListString.Substring (startIndex1, endIndex1 - startIndex1);
|
if (endIndex1 <= startIndex1) {
|
return;
|
}
|
XmlDocument xml1 = new XmlDocument ();
|
xml1.LoadXml (aa);
|
var pandoraList = xml1.SelectSingleNode ("PlayQueue");
|
|
int number1 = int.Parse (pandoraList.SelectSingleNode ("TotalQueue").InnerText);
|
|
var playListInfo = pandoraList.SelectSingleNode ("PlayListInfo");
|
|
a31.PanRadioInfoList.Clear ();
|
for (int i = 1; i <= number1; i++) {
|
var list = playListInfo.SelectSingleNode ("List" + i);
|
|
MusicInfo musicInfo = new MusicInfo ();
|
musicInfo.Title = list.SelectSingleNode ("Name").InnerText;
|
var ListInfo = list.SelectSingleNode ("ListInfo");
|
|
foreach (XmlNode childNode in ListInfo.ChildNodes) {
|
switch (childNode.Name) {
|
case "SearchUrl":
|
musicInfo.URL = childNode.InnerText;
|
break;
|
case "StationID":
|
musicInfo.ID = childNode.InnerText;
|
break;
|
case "PicUrl":
|
#region 初始化网络图片路径
|
string path = "";
|
if (Shared.Application.IsPad) {
|
path = "Pad/" + "MusicImage/";
|
} else {
|
path = "Phone/" + "MusicImage/";
|
}
|
path = System.IO.Path.Combine (Shared.IO.FileUtils.RootPath, path + childNode.InnerText.Replace ('/', '_').Replace ('\\', '_').Replace (':', '_').Replace ('*', '_').Replace ('?', '_').Replace ('"', '_').Replace ('<', '_').Replace ('>', '_').Replace ('|', '_'));
|
musicInfo.Image = path;
|
#endregion
|
Shared.IO.FileUtils.DownLoadImage (musicInfo.Image, childNode.InnerText);
|
//musicInfo.Image = childNode.InnerText;
|
break;
|
}
|
}
|
if (musicInfo.ID == null) {
|
continue;
|
}
|
currentMusiceA31.PanRadioInfoList.Add (musicInfo);
|
}
|
|
var pandoraConfigBytes = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (new PandoraConfig { UserName = tempusername, Passwrod = temppassword }));
|
Shared.IO.FileUtils.WriteFileByBytes (PandoraConfig.FileName, pandoraConfigBytes);
|
|
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
MainPage.AddTip (Language.StringByID (MyInternationalizationString.successful), 1000);
|
this.Parent.RemoveAt (Parent.ChildrenCount - 2);
|
this.RemoveFromParent ();
|
A31PandoraList a31Pandoralist = new A31PandoraList ();
|
MainPage.MainFrameLayout.AddChidren (a31Pandoralist);
|
a31Pandoralist.show (a31, username.Text, password.Text);
|
});
|
} else if (number == 3) {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
new Alert (Language.StringByID (MyInternationalizationString.Tip),
|
Language.StringByID (MyInternationalizationString.Accountorpassworderro),
|
Language.StringByID (MyInternationalizationString.Close)).Show ();
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
new Alert (Language.StringByID (MyInternationalizationString.Tip),
|
Language.StringByID (MyInternationalizationString.networkerrors),
|
Language.StringByID (MyInternationalizationString.Close)).Show ();
|
});
|
}
|
} catch { }
|
});
|
};
|
login.MouseDownEventHandler += (sender, e) => {
|
login.BackgroundColor = 0xffFE5E00;
|
};
|
}
|
|
|
|
/// <summary>
|
/// 登录信息
|
/// </summary>
|
/// <param name="username">用户名</param>
|
/// <param name="password">密码</param>
|
/// <returns></returns>
|
string Login (string username, string password)
|
{
|
StringBuilder getPlayList = new StringBuilder ();
|
getPlayList.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
|
getPlayList.AppendLine ("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">");
|
getPlayList.AppendLine ("<s:Body>");
|
getPlayList.AppendLine ("<u:BackUpQueue xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">");
|
getPlayList.AppendLine ("<QueueContext>");
|
getPlayList.AppendLine ("<?xml version="1.0"?>");
|
getPlayList.AppendLine ("<PlayList>");
|
getPlayList.AppendLine ("<ListName>Pandora</ListName>");
|
getPlayList.AppendLine ("<ListInfo>");
|
getPlayList.AppendLine ("<TrackNumber>0</TrackNumber>");
|
getPlayList.AppendLine ("<SearchUrl>tuner.pandora.com</SearchUrl>");
|
getPlayList.AppendLine ("<Quality>0</Quality>");
|
getPlayList.AppendLine ("<UpdateTime>0</UpdateTime>");
|
getPlayList.AppendLine ("<Http_proxy></Http_proxy>");
|
getPlayList.AppendLine ("<Login_username>" + username + "</Login_username>");//2532767200@qq.com
|
getPlayList.AppendLine ("<Login_password>" + password + "</Login_password>");//85521566
|
getPlayList.AppendLine ("</ListInfo>");
|
getPlayList.AppendLine ("</PlayList>");
|
getPlayList.AppendLine ("</QueueContext>");
|
getPlayList.AppendLine ("</u:BackUpQueue>");
|
getPlayList.AppendLine ("</s:Body>");
|
getPlayList.AppendLine ("</s:Envelope>");
|
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
|
webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#BackUpQueue\"");
|
webClient.Headers.Add ("CONTENT-TYPE", "text/xml;charset=\"utf-8\"");
|
try {
|
byte [] recevieBytes = webClient.UploadData (new Uri ("http://" + currentMusiceA31.IPAddress + ":" + currentMusiceA31.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes (getPlayList.ToString ()));
|
return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
|
} catch (Exception e) {
|
return null;
|
}
|
}
|
/// <summary>
|
/// 登录成功
|
/// </summary>
|
/// <returns></returns>
|
string readList ()
|
{
|
StringBuilder ss = new StringBuilder ();
|
ss.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
|
ss.AppendLine ("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">");
|
ss.AppendLine ("<s:Body>");
|
ss.AppendLine ("<u:BrowseQueue xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">");
|
ss.AppendLine ("<QueueName>Pandora</QueueName>");
|
ss.AppendLine ("</u:BrowseQueue>");
|
ss.AppendLine ("</s:Body>");
|
ss.AppendLine ("</s:Envelope>");
|
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
|
webClient.Proxy = null;
|
webClient.Headers.Add ("CONTENT-TYPE", "text/xml;charset=\"utf-8\"");
|
webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#BrowseQueue\"");
|
try {
|
byte [] recevieBytes = webClient.UploadData (new Uri ("http://" + currentMusiceA31.IPAddress + ":" + currentMusiceA31.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes (ss.ToString ()));
|
return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
|
} catch (Exception e) {
|
return null;
|
}
|
}
|
/// <summary>
|
/// 获取电台列表信息
|
/// </summary>
|
/// <param name="listname">列表名</param>
|
/// <returns></returns>
|
string PandoraList ()
|
{
|
StringBuilder stringList = new StringBuilder ();
|
|
stringList.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
|
stringList.AppendLine ("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">");
|
stringList.AppendLine ("<s:Body>");
|
stringList.AppendLine ("<u:BrowseQueue xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">");
|
stringList.AppendLine ("<QueueName>TotalQueue</QueueName>");
|
stringList.AppendLine ("</u:BrowseQueue>");
|
stringList.AppendLine ("</s:Body>");
|
stringList.AppendLine ("</s:Envelope>");
|
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
|
webClient.Proxy = null;
|
webClient.Headers.Add ("CONTENT-TYPE", "text/xml;charset=\"utf-8\"");
|
webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#BrowseQueue\"");
|
try {
|
byte [] recevieBytes = webClient.UploadData (new Uri ("http://" + currentMusiceA31.IPAddress + ":" + currentMusiceA31.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes (stringList.ToString ()));
|
return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
|
} catch (Exception e) {
|
return null;
|
}
|
}
|
}
|
}
|