using System;
using System.Collections.Generic;
using System.Text;
using Shared;
using System.Xml;
using Shared.SimpleControl.R;
namespace Shared.SimpleControl.Phone.Music
{
///
/// 网络流媒体音乐界面
///
class A31StreamingMusic : FrameLayout
{
///
/// 流行
///
Button popular;
///
/// 民歌
///
Button ballad;
///
/// 摇滚
///
Button rock;
///
/// 古典
///
Button classical;
public void Show(A31MusicModel a31)
{
BackgroundColor = 0XFF2F2F2F;
AddChidren(new Button
{
Height = Application.GetRealHeight(30),
BackgroundColor = SkinStyle.Current.MainColor,
});
var topFrameLayout = new FrameLayout
{
Height = Application.GetRealHeight(100),
Y = Application.GetRealHeight(30),
BackgroundColor = SkinStyle.Current.MainColor,
};
AddChidren(topFrameLayout);
var btnTitle = new Button
{
TextID = MyInternationalizationString.streamingmusic,
};
topFrameLayout.AddChidren(btnTitle);
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 hdl = new Button
{
Width = Application.GetRealWidth(104),
Height = Application.GetRealHeight(32),
X = Application.GetRealWidth(530),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/HDL.png",
};
topFrameLayout.AddChidren(hdl);
var framelayout = new FrameLayout
{
Height = Application.GetRealHeight(100),
Y = topFrameLayout.Bottom,
BackgroundColor = 0XFF121212,
};
AddChidren(framelayout);
popular = new Button
{
Width = Application.GetRealWidth(640 / 4),
Height = Application.GetRealHeight(100),
TextID = MyInternationalizationString.Musicpopular,
};
framelayout.AddChidren(popular);
popular.MouseUpEventHandler += (sender, e) =>
{
popular.TextColor = 0xffFE5E00;
ballad.TextColor = 0xFFFFFFFF;
rock.TextColor = 0xFFFFFFFF;
classical.TextColor = 0xFFFFFFFF;
};
ballad = new Button
{
Width = Application.GetRealWidth(640 / 4),
Height = Application.GetRealHeight(100),
TextID = MyInternationalizationString.Musicballad,
X = popular.Right,
};
framelayout.AddChidren(ballad);
ballad.MouseUpEventHandler += (sender, e) =>
{
popular.TextColor = 0xFFFFFFFF;
ballad.TextColor = 0xffFE5E00;
rock.TextColor = 0xFFFFFFFF;
classical.TextColor = 0xFFFFFFFF;
};
rock = new Button
{
Width = Application.GetRealWidth(640 / 4),
Height = Application.GetRealHeight(100),
TextID = MyInternationalizationString.Musicrock,
X = ballad.Right,
};
framelayout.AddChidren(rock);
rock.MouseUpEventHandler += (sender, e) =>
{
popular.TextColor = 0xFFFFFFFF;
ballad.TextColor = 0xFFFFFFFF;
rock.TextColor = 0xffFE5E00;
classical.TextColor = 0xFFFFFFFF;
};
classical = new Button
{
Width = Application.GetRealWidth(640 / 4),
Height = Application.GetRealHeight(100),
TextID = MyInternationalizationString.Musicclassical,
X = rock.Right,
};
framelayout.AddChidren(classical);
classical.MouseUpEventHandler += (sender, e) =>
{
popular.TextColor = 0xFFFFFFFF;
ballad.TextColor = 0xFFFFFFFF;
rock.TextColor = 0xFFFFFFFF;
classical.TextColor = 0xffFE5E00;
};
var framelayout1 = new FrameLayout
{
Height = Application.GetRealHeight(130),
BackgroundColor = 0XFF2F2F2F,
Y = framelayout.Bottom,
};
AddChidren(framelayout1);
var etSongName = new EditText
{
Width = Application.GetRealWidth(400),
Height = Application.GetRealHeight(75),
Radius = (uint)Application.GetRealHeight(6),
Gravity = Gravity.CenterVertical,
X = 40,
BackgroundColor = 0xFF4D4D4D,
};
framelayout1.AddChidren(etSongName);
var btnSerach = new Button
{
Width = Application.GetRealWidth(120),
Height = Application.GetRealHeight(75),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/seekSelected.png",
X = Application.GetRealWidth(530),
};
framelayout1.AddChidren(btnSerach);
var btnLine = new Button
{
Height = Application.GetRealHeight(4),
Y = framelayout1.Bottom,
UnSelectedImagePath = "MusicIcon/MusicThread.png",
};
AddChidren(btnLine);
VerticalScrolViewLayout middle = new VerticalScrolViewLayout()
{
Y = btnLine.Bottom,
Height = Application.GetRealHeight (Application.DesignHeight - 230 - 130),
BackgroundColor = 0XFF2F2F2F,
};
AddChidren(middle);
btnSerach.MouseUpEventHandler += (sender, e) =>
{
//清空当前空间界面
middle.RemoveAll();
var songList = Newtonsoft.Json.JsonConvert.DeserializeObject(serarchSong(etSongName.Text));
int number = 0;
foreach (var musicInfo in songList.song)
{
number++;
var iErowL = new RowLayout
{
Height = Application.GetRealHeight(100),
};
middle.AddChidren(iErowL);
var iEtitle = new Button
{
Width = Application.GetRealWidth(80),
Height = Application.GetRealHeight(70),
X = Application.GetRealWidth(10),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayMusic.png",
};
iErowL.AddChidren(iEtitle);
var iEmusic = new Button
{
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight(100),
Text = musicInfo.artistname+"---"+musicInfo.songname,
TextAlignment = TextAlignment.CenterLeft,
X = Application.GetRealWidth(120),
Tag = number,
};
iErowL.AddChidren(iEmusic);
}
};
}
///
/// 读取歌曲信息
///
///
///
string serarchSong(string songName)
{
System.Net.WebClient webClient=new System.Net.WebClient();
try
{
byte[] recevieBytes = webClient.DownloadData(new Uri("http://tingapi.ting.baidu.com/v1/restserver/ting?format=json&calback=&from=webapp_music&method=baidu.ting.search.catalogSug&query=" + songName));
return System.Text.Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length);
}
catch
{
return "";
}
}
}
}