using System.Text; using Shared; using Shared.SimpleControl.Phone; using Shared.SimpleControl; using Shared.SimpleControl.R; using System.Xml; using SmartHome.UI.SimpleControl.Phone; using System.Security; using SmartHome; using System.Net; using System.Security.Cryptography; using System; using System.Collections.Generic; using Newtonsoft.Json.Linq; namespace Shared.SimpleControl.Phone { public class SonosLocal:FrameLayout { public void Show (SonosMusic sonosMusic) { AddChidren (new Button { Height = Application.GetRealHeight (36), BackgroundColor = SkinStyle.Current.MusicTopFrameLayout, }); var topFrameLayout = new FrameLayout { Height = Application.GetRealHeight (90), Y = Application.GetRealHeight (36), BackgroundColor = SkinStyle.Current.MusicTopFrameLayout, }; AddChidren (topFrameLayout); 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) => { this.RemoveFromParent (); }; var musiclist = new Button { Width = Application.GetRealWidth (200), Height = Application.GetRealHeight (150), TextID = MyInternationalizationString.Musicmusic, X = Application.GetRealWidth (200), Gravity = Gravity.CenterVertical, }; topFrameLayout.AddChidren (musiclist); var locallistview = new VerticalScrolViewLayout { Height = Application.GetRealHeight (Application.DesignHeight - 126), Y = topFrameLayout.Bottom, BackgroundColor = 0xff2F2F2F, }; this.AddChidren (locallistview); //if (sonosMusic.SonosLovePlayList.Count == 0) { sonosMusic.SonosLocalList.Clear (); MainPage.Loading.Start (); System.Threading.Tasks.Task.Run (() => { try { var tempsonosList = SuperGateWay.Control.getsonosLocalList (); if (tempsonosList == null) { return; } if (tempsonosList != null) { foreach (var str in tempsonosList) { try { var result = SuperGateWay.Control.getsonosLocalSongs(str.Replace (".json", "")); if (result != null) { var obj = JObject.Parse (result); var songitems = obj ["tones"]?.ToString (); var songlist = Newtonsoft.Json.JsonConvert.DeserializeObject> (songitems); foreach (var songinof in songlist) { local songs = new local (); songs.id = songinof.id; songs.name = songinof.name; sonosMusic.SonosLocalList.Add (songs); } } } catch { } } } } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); localSongView (locallistview, sonosMusic); }); } }); //} else { // likeView (likelistview, sonosMusic); //} } void localSongView (VerticalScrolViewLayout localview, SonosMusic sonosMusic) { for (int i = 0; i < sonosMusic.SonosLocalList.Count; i++) { var music = sonosMusic.SonosLocalList [i]; var rowlocal = new RowLayout { Height = Application.GetRealHeight (100), }; localview.AddChidren (rowlocal); var titleMusic = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (61), X = Application.GetRealWidth (20), Gravity = Gravity.CenterVertical, Radius = (uint)Application.GetRealHeight (4), UnSelectedImagePath = "MusicIcon/musicplay1.png", }; rowlocal.AddChidren (titleMusic); //string patn = "SonosMusicImage_"; //if (Shared.IO.FileUtils.Exists (patn + music.songname)) { // titleMusic.UnSelectedImagePath = patn + music.songname; //} else { // titleMusic.UnSelectedImagePath = "MusicIcon/musicplay1.png"; // System.Threading.Tasks.Task.Run (() => { // var filePath = SonosMusic.SonosMusicImage (music.imageUrl, music.songname); // if (filePath != null) { // Application.RunOnMainThread (() => { // titleMusic.UnSelectedImagePath = filePath; // }); // } // }); //} var songmker = new Button { Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (50), TextAlignment = TextAlignment.BottomLeft, X = Application.GetRealWidth (100), Text = music.name, TextColor = SkinStyle.Current.MusicTextColor, }; rowlocal.AddChidren (songmker); var artists = new Button { Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (40), TextAlignment = TextAlignment.TopLeft, X = Application.GetRealWidth (100), Y = songmker.Bottom, //TextColor = 0x75ffffff, Text ="unkown", TextColor = SkinStyle.Current.MusicArtistTextColor, }; rowlocal.AddChidren (artists); EventHandler clicklocalsong = (sender, e) => { rowlocal.BackgroundColor = 0xffFE5E00; System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { //先移除当前控件的前面那个控件 this.Parent.RemoveAt (this.Parent.ChildrenCount - 3); this.Parent.RemoveAt (this.Parent.ChildrenCount - 2); //当前控件界面 this.RemoveFromParent (); var sonosPlay = new SonosPlay { }; MainPage.MainFrameLayout.AddChidren (sonosPlay); sonosPlay.Show (sonosMusic); System.Threading.Tasks.Task.Run (() => { sonosMusic.eventsend (sonosMusic, 25, int.Parse (music.id)); }); }); }); }; rowlocal.MouseUpEventHandler += clicklocalsong; titleMusic.MouseUpEventHandler += clicklocalsong; songmker.MouseUpEventHandler += clicklocalsong; artists.MouseUpEventHandler += clicklocalsong; new System.Threading.Thread (() => { while (this.Parent != null) { System.Threading.Thread.Sleep (1000); Shared.Application.RunOnMainThread (() => { try { for (int j = 0; j < rowlocal.ChildrenCount; j++) { RowLayout view = (RowLayout)rowlocal.GetChildren (j); var songName = (Button)view.GetChildren (1); if (sonosMusic.sonosPlayStatus.songName == songName.Text) { songName.TextColor = 0xffFE5E00; } else { songName.TextColor = SkinStyle.Current.MusicTextColor; } } } catch { } }); } }){IsBackground=true}.Start(); } } } }