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
|
{
|
/// <summary>
|
/// 电台界面
|
/// </summary>
|
class A31CNRadio : FrameLayout
|
{
|
public void show (A31MusicModel a31, string data)
|
{
|
initList (a31, data);
|
|
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.cnRadio,
|
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 middle = new VerticalScrolViewLayout () {
|
Y = topFrameLayout.Bottom,
|
Height = Application.GetRealHeight (Application.DesignHeight - 136),
|
//BackgroundColor = 0xff2F2F2F
|
BackgroundColor=SkinStyle.Current.MusicVerticalScrolViewLayout,
|
};
|
AddChidren (middle);
|
|
for (int i = 0; i < a31.CnRadioInfoList.Count; i++) {
|
var cnrow = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
LineColor = SkinStyle.Current.MusicRowLayoutLineColor,
|
};
|
middle.AddChidren (cnrow);
|
|
var title = new Button {
|
Width = Application.GetRealWidth (61),
|
Height = Application.GetRealHeight (81),
|
X = Application.GetRealWidth (30),
|
Gravity = Gravity.CenterVertical,
|
};
|
cnrow.AddChidren (title);
|
|
var cntext = new Button {
|
Gravity = Gravity.CenterVertical,
|
Text = a31.CnRadioInfoList [i].Cnkey,
|
X = Application.GetRealWidth (130),
|
Tag = a31.CnRadioInfoList [i].URL,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
cnrow.AddChidren (cntext);
|
|
var next = new Button {
|
Width = Application.GetRealWidth (87),
|
Height = Application.GetRealHeight (100),
|
UnSelectedImagePath = "MusicIcon/Next.png",
|
SelectedImagePath = "MusicIcon/NextSelecte.png",
|
X = Application.GetRealWidth (550),
|
};
|
cnrow.AddChidren (next);
|
|
EventHandler<MouseEventArgs> CNresources = (sender, e) => {
|
MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load));
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
var dataString = readRadioList (cntext.Tag.ToString ());
|
if (dataString == null) {
|
return;
|
}
|
int startIndex1 = dataString.IndexOf ("<body>");
|
int endIndex1 = dataString.IndexOf ("</body>") + "</body>".Length;
|
if (endIndex1 <= startIndex1) {
|
return;
|
}
|
|
XmlDocument xml1 = new XmlDocument ();
|
xml1.LoadXml (dataString.Substring (startIndex1, endIndex1 - startIndex1));
|
var dataList = xml1.SelectSingleNode ("body");
|
if (dataList == null) {
|
return;
|
}
|
a31.CnRadioInfoList.Clear ();
|
foreach (XmlNode childNodes in dataList.ChildNodes) {
|
if (childNodes.Name == "outline" && childNodes.Attributes ["URL"] != null) {
|
MusicInfo musicInfoCN = new MusicInfo ();
|
musicInfoCN.URL = childNodes.Attributes ["URL"] == null ? "" : childNodes.Attributes ["URL"].Value;
|
musicInfoCN.Title = childNodes.Attributes ["text"] == null ? "" : childNodes.Attributes ["text"].Value;
|
musicInfoCN.Image = childNodes.Attributes ["image"] == null ? "" : childNodes.Attributes ["image"].Value;
|
|
if (childNodes.Attributes ["image"] != null) {
|
string path = "";
|
if (Shared.Application.IsPad) {
|
path = "";
|
} else {
|
path = "Phone/" + "MusicImage/";
|
}
|
}
|
|
musicInfoCN.Cntype = childNodes.Attributes ["type"] == null ? "" : childNodes.Attributes ["type"].Value;
|
a31.CnRadioInfoList.Add (musicInfoCN);
|
|
|
|
}
|
foreach (XmlNode a in childNodes.ChildNodes) {
|
if (a.Name == "outline") {
|
MusicInfo musicInfoCN = new MusicInfo ();
|
musicInfoCN.URL = a.Attributes ["URL"] == null ? "" : a.Attributes ["URL"].Value;
|
musicInfoCN.Title = a.Attributes ["text"] == null ? "" : a.Attributes ["text"].Value;
|
|
if (a.Attributes ["image"] != null) {
|
#region 初始化网络图片路径
|
string path = "";
|
if (Shared.Application.IsPad) {
|
path = "Pad/" + "MusicImage/";
|
} else {
|
path = "Phone/" + "MusicImage/";
|
}
|
path = System.IO.Path.Combine (Shared.IO.FileUtils.RootPath, path + a.Attributes ["image"].Value.Replace ('/', '_').Replace ('\\', '_').Replace (':', '_').Replace ('*', '_').Replace ('?', '_').Replace ('"', '_').Replace ('<', '_').Replace ('>', '_').Replace ('|', '_'));
|
musicInfoCN.Image = path;
|
#endregion
|
Shared.IO.FileUtils.DownLoadImage (musicInfoCN.Image, a.Attributes ["image"].Value);
|
}
|
musicInfoCN.Cntype = a.Attributes ["type"] == null ? "" : a.Attributes ["type"].Value;
|
a31.CnRadioInfoList.Add (musicInfoCN);
|
|
}
|
}
|
}
|
} catch { } finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
A31CnList a31CnList = new A31CnList ();
|
MainPage.MainFrameLayout.AddChidren (a31CnList);
|
a31CnList.Show (a31, cntext.Text);
|
});
|
}
|
});
|
};
|
title.MouseUpEventHandler += CNresources;
|
next.MouseUpEventHandler += CNresources;
|
cntext.MouseUpEventHandler += CNresources;
|
|
|
|
switch (cntext.Text) {
|
case "local":
|
title.UnSelectedImagePath = "MusicIcon/ocalradio.png";
|
break;
|
case "recent":
|
title.UnSelectedImagePath = "MusicIcon/Lately.png";
|
break;
|
case "trending":
|
title.UnSelectedImagePath = "MusicIcon/popular.png";
|
break;
|
case "music":
|
title.UnSelectedImagePath = "MusicIcon/musiccn.png";
|
break;
|
case "talk":
|
title.UnSelectedImagePath = "MusicIcon/Talk.png";
|
break;
|
case "sports":
|
title.UnSelectedImagePath = "MusicIcon/sports.png";
|
break;
|
case "language":
|
title.UnSelectedImagePath = "MusicIcon/language.png";
|
break;
|
case "location":
|
title.UnSelectedImagePath = "MusicIcon/place.png";
|
break;
|
case "news":
|
title.UnSelectedImagePath = "MusicIcon/news.png";
|
break;
|
case "podcast":
|
title.UnSelectedImagePath = "MusicIcon/podcast.png";
|
break;
|
default:
|
title.UnSelectedImagePath = "MusicIcon/podcast.png";
|
break;
|
}
|
cntext.Text = a31.CnRadioInfoList [i].Title;
|
}
|
|
|
}
|
|
void initList (A31MusicModel a31, string data)
|
{
|
try {
|
var readString = data;
|
if (readString == null) {
|
return;
|
}
|
int startIndex1 = readString.IndexOf ("<body>");
|
int endIndex = readString.IndexOf ("</body>") + "</body>".Length;
|
if (endIndex <= startIndex1) {
|
return;
|
}
|
var aa = readString.Substring (startIndex1, endIndex - startIndex1);
|
XmlDocument xml = new XmlDocument ();
|
xml.LoadXml (aa);
|
var CNList = xml.SelectSingleNode ("body");
|
if (CNList == null) {
|
return;
|
}
|
a31.CnRadioInfoList.Clear ();
|
foreach (XmlNode v in CNList.ChildNodes) {
|
switch (v.Name) {
|
case "outline":
|
MusicInfo musicInfo = new MusicInfo ();
|
musicInfo.Title = v.Attributes ["text"].Value;
|
musicInfo.URL = v.Attributes ["URL"].Value;
|
musicInfo.Cnkey = v.Attributes ["key"].Value;
|
|
a31.CnRadioInfoList.Add (musicInfo);
|
break;
|
}
|
}
|
} catch { }
|
}
|
|
/// <summary>
|
/// 读取电台列表
|
/// </summary>
|
/// <returns>读取到的电台组列表信息,读取不到反馈为null</returns>
|
string readRadioList (string url)
|
{
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (10000);
|
webClient.Proxy = null;
|
webClient.Headers.Add ("Content-type", "plain/text; charset=UTF-8");
|
if (Language.CurrentLanguage == "Chinese") {
|
webClient.Headers.Add ("Accept-Language", "zh-cn");
|
} else {
|
webClient.Headers.Add ("Accept-Language", "en-us");
|
}
|
try {
|
byte [] recevieBytes = webClient.DownloadData (new Uri (url));
|
return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
|
} catch (Exception e) {
|
return null;
|
}
|
}
|
}
|
}
|