using System; using System.Collections.Generic; using System.Xml; using Shared; namespace HDL_ON.UI.Music { public class A31Radio : FrameLayout { public A31Radio() { Tag = "Music"; } VerticalRefreshLayout middViewLayout; /// /// 先加载界面出来 /// public void Show(string date) { InitList(date); #region 界面布局------ this.BackgroundColor = MusicColor.ViewColor; var topView = new TopView(); this.AddChidren(topView.TopFLayoutView()); topView.topNameBtn.TextID = StringId.radio; topView.clickBackBtn.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); }; middViewLayout = new VerticalRefreshLayout { BackgroundColor = MusicColor.WhiteColor, Y = topView.fLayout.Bottom, Height = Application.GetRealHeight(H_W.H - H_W.T_Height), }; this.AddChidren(middViewLayout); middViewLayout.BeginHeaderRefreshingAction += () => { middViewLayout.EndHeaderRefreshing(); }; #endregion RadioListView(); } /// /// 加载数据的方法 /// public void RadioListView() { middViewLayout.RemoveAll(); for (int i = 0; i < A31MusicModel.Current.CnRadioInfoList.Count; i++) { var radioInfo = A31MusicModel.Current.CnRadioInfoList[i]; RowLayout addFlieRow = new RowLayout { Height = Application.GetRealHeight(78), LineColor = MusicColor.WhiteColor, SubViewWidth = Application.GetRealWidth(90),//改变编辑控件宽度多少; }; middViewLayout.AddChidren(addFlieRow); //文件图标 Button fileIconBtn = new Button { X = Application.GetRealWidth(16), Y = Application.GetRealHeight(8), Width = Application.GetRealWidth(62), Height = Application.GetRealWidth(62), UnSelectedImagePath = "MusicIcon/file.png", }; addFlieRow.AddChidren(fileIconBtn); //文件名控件 Button fileNameBtn = new Button { X = fileIconBtn.Right + Application.GetRealWidth(16), Y = Application.GetRealHeight(29), Width = Application.GetRealWidth(220), Height = Application.GetRealHeight(20), TextColor = MusicColor.TextColor, TextSize = TextSize.Text14, TextAlignment = TextAlignment.CenterLeft, Text = radioInfo.Title, }; addFlieRow.AddChidren(fileNameBtn); Button clickBtn = new Button { X = fileIconBtn.Right + Application.GetRealWidth(16), Width = Application.GetRealWidth(375 - 94), Height = Application.GetRealHeight(78), Tag = radioInfo.URL, }; addFlieRow.AddChidren(clickBtn); clickBtn.MouseUpEventHandler += (sender, e) => { Loading loading = new Loading(); this.AddChidren(loading); loading.Start(); System.Threading.Tasks.Task.Run(() => { try { var dataString = SendMethod.ReadRadioList(clickBtn.Tag.ToString()); if (dataString == null) { return; } int startIndex1=dataString.IndexOf(""); int endIndex1 = dataString.IndexOf("") + "".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; } A31MusicModel.Current.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; A31MusicModel.Current.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; A31MusicModel.Current.CnRadioInfoList.Add(musicInfoCN); } } } } catch { } finally { Application.RunOnMainThread(() => { loading.Hide(); A31RadioList a31RadioList = new A31RadioList(); MainPage.BasePageView.AddChidren(a31RadioList); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; a31RadioList.Show(fileNameBtn.Text); }); } }); }; } } void InitList(string data) { try { var readString = data; if (readString == null) { return; } int startIndex1 = readString.IndexOf(""); int endIndex = readString.IndexOf("") + "".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; } A31MusicModel.Current.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; A31MusicModel.Current.CnRadioInfoList.Add(musicInfo); break; } } } catch { } } } }