From: <kro...@us...> - 2011-01-17 21:09:41
|
Revision: 4072 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=4072&view=rev Author: kroko_koenig Date: 2011-01-17 21:09:34 +0000 (Mon, 17 Jan 2011) Log Message: ----------- some tweaks still slow on pictures (100% cpu on slow system) Modified Paths: -------------- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/main.java trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures/Pictures.java trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures/Picturesfullscreen.java trunk/plugins/AndroidRemote/Server/AndroidRemote/AndroidServer.cs trunk/plugins/AndroidRemote/Server/AndroidRemote/Content/MusicHandler.cs trunk/plugins/AndroidRemote/Server/AndroidRemote/Content/PictureHandler.cs trunk/plugins/AndroidRemote/Server/AndroidRemote.suo Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/main.java =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/main.java 2011-01-17 14:33:48 UTC (rev 4071) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/main.java 2011-01-17 21:09:34 UTC (rev 4072) @@ -247,6 +247,8 @@ } TextView txtHtpc = (TextView) findViewById(R.id.txtInstance); txtHtpc.setText(AppSettings.getName()); + + Pictures.actualDir = ""; } }); Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures/Pictures.java =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures/Pictures.java 2011-01-17 14:33:48 UTC (rev 4071) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures/Pictures.java 2011-01-17 21:09:34 UTC (rev 4072) @@ -56,8 +56,10 @@ public static ArrayList<ReceiveDirectoryXmlHandler.DirItems> pictureList; public static int selectedPicture; + private static int picNo; - final CharSequence[] itemsLong = { "Slideshow", "Random Slideshow", "Cancel" }; + final CharSequence[] itemsLong = { "Slideshow", "Random Slideshow", + "Cancel" }; @Override public void onCreate(Bundle savedInstanceState) { @@ -141,7 +143,7 @@ } Log.d("MediaPortal", "pictures read folder finished"); - + if (pictureList == null) { Toast.makeText(Pictures.this, "TIME OUT SERVER", Toast.LENGTH_SHORT).show(); @@ -152,11 +154,60 @@ } else { GridView gridview = (GridView) findViewById(R.id.GridView01); gridview.setAdapter(new ImageAdapter2(Pictures.this)); + + picNo = 0; + mFetchTask.run(); } } } } + private Runnable mFetchTask = new Runnable() { + public void run() { + new fetchPictures().execute(); + } + }; + + private class fetchPictures extends AsyncTask<String, Void, Void> { + + // can use UI thread here + protected void onPreExecute() { + + } + + // automatically done on worker thread (separate from UI thread) + protected Void doInBackground(final String... args) { + + HttpHandler http = new HttpHandler(); + String server = AppSettings.getWebServer() + "/pictures/"; + + while(picNo < pictureList.size()) { + + DirItems item = pictureList.get(picNo); + if (!item.isFolder) { + if (item.Picture == null) { + String file = server + actualDir + item.File + ".thb"; + item.Picture = http.DownloadImage(file); + pictureList.set(picNo, item); + break; + } + } + picNo++; + } + return null; + } + + // can use UI thread here + protected void onPostExecute(final Void unused) { + + GridView gridview = (GridView) findViewById(R.id.GridView01); + gridview.setAdapter(new ImageAdapter2(Pictures.this)); + + if (picNo < pictureList.size()) + mFetchTask.run(); + } + } + public class ImageAdapter2 extends BaseAdapter { private Context mContext; public static final int ACTIVITY_CREATE = 10; @@ -214,17 +265,20 @@ iv.setTag(pic); } else { - HttpHandler http = new HttpHandler(); + /* + * HttpHandler http = new HttpHandler(); + * + * String file = AppSettings.getWebServer() + "/pictures/"; + * file += actualDir + item.File + ".thb"; item.Picture = + * http.DownloadImage(file); + * iv.setImageBitmap(item.Picture); + */ - String file = AppSettings.getWebServer() + "/pictures/"; - file += actualDir + item.File + ".thb"; - item.Picture = http.DownloadImage(file); - iv.setImageBitmap(item.Picture); - if (item.Picture == null) iv.setImageResource(R.drawable.picture); - // else - // iv.setImageBitmap(item.Picture); + else + iv.setImageBitmap(item.Picture); + picItem pic = new picItem(); pic.title = txtName; pic.typ = "item"; Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures/Picturesfullscreen.java =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures/Picturesfullscreen.java 2011-01-17 14:33:48 UTC (rev 4071) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures/Picturesfullscreen.java 2011-01-17 21:09:34 UTC (rev 4072) @@ -69,7 +69,8 @@ public static boolean SlideshowPaused = false; private static long SlideInterval = 5000; - private Bitmap picture; + private static Bitmap picture; + private static String title; /** Called when the activity is first created. */ @Override @@ -77,12 +78,22 @@ super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.picturesfullscreen); gestureScanner = new GestureDetector(Picturesfullscreen.this); - new setPicture().execute(); + + if (savedInstanceState == null) + new setPicture().execute(); + else + { + ImageView imagev = (ImageView) findViewById(R.id.ImageView01); + imagev.setImageBitmap(picture); + TextView txt = (TextView) findViewById(R.id.full_text); + txt.setText(title); + } } private class setPicture extends AsyncTask<String, Void, Void> { @@ -116,7 +127,10 @@ // can use UI thread here protected void onPostExecute(final Void unused) { if (this.dialog.isShowing()) { - this.dialog.dismiss(); + try { + this.dialog.dismiss(); + } catch (Exception ex) { + } } if (item.isFolder != true) { @@ -126,9 +140,15 @@ TextView txt = (TextView) findViewById(R.id.full_text); if (!slideShow) + { txt.setText(item.File); + title = item.File; + } else + { txt.setText("Slide show"); + title = "Slide show"; + } } } } @@ -147,7 +167,7 @@ // // keep screen on in slideshow // - + if ((slideShow) || (randomShow)) { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock( @@ -293,8 +313,8 @@ try { outStream.close(); - //Toast.makeText(Picturesfullscreen.this, "File saved.", - // Toast.LENGTH_SHORT).show(); + // Toast.makeText(Picturesfullscreen.this, "File saved.", + // Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Log.e("Debug", "SavetoSDCard " + e.getMessage().toString() Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote/AndroidServer.cs =================================================================== --- trunk/plugins/AndroidRemote/Server/AndroidRemote/AndroidServer.cs 2011-01-17 14:33:48 UTC (rev 4071) +++ trunk/plugins/AndroidRemote/Server/AndroidRemote/AndroidServer.cs 2011-01-17 21:09:34 UTC (rev 4072) @@ -49,6 +49,7 @@ private Thread listen; private Thread grabPictures; + private Thread cacheDB; public static VideoLan.VlcControl vlc; @@ -69,9 +70,14 @@ grabPictures.Start(); logInfo("Caching music DB"); - Content.MusicHandler.CacheDB(); + cacheDB = new Thread(Content.MusicHandler.CacheDB); + cacheDB.IsBackground = true; + cacheDB.Priority = ThreadPriority.Lowest; + cacheDB.Start(); } + + public void Stop() { logInfo("Stop server"); @@ -121,9 +127,10 @@ // work on request Request req = new Request(clientSocket); + Thread thread = new Thread(new ThreadStart(req.DoWork)); thread.IsBackground = true; - thread.Priority = ThreadPriority.Normal; + thread.Priority = ThreadPriority.BelowNormal; thread.Start(); } catch (Exception ex) Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote/Content/MusicHandler.cs =================================================================== --- trunk/plugins/AndroidRemote/Server/AndroidRemote/Content/MusicHandler.cs 2011-01-17 14:33:48 UTC (rev 4071) +++ trunk/plugins/AndroidRemote/Server/AndroidRemote/Content/MusicHandler.cs 2011-01-17 21:09:34 UTC (rev 4072) @@ -50,6 +50,7 @@ MediaPortal.Music.Database.MusicDatabase db = MediaPortal.Music.Database.MusicDatabase.Instance; string msg = string.Empty; + int cnt = 0; #region artist @@ -64,11 +65,16 @@ ArrayList list = new ArrayList(); db.GetAllArtists(ref list); + AndroidServer.logInfo("Caching music artist found :" + list.Count); + cnt = 0; foreach (string artist in list) { if (artist != string.Empty) { + cnt++; + if (cnt > 1000) break; + msg += "<Item>\r\n"; msg += "<Artist>" + SomeUtils.EncodeString(artist) + "</Artist>\r\n"; msg += "</Item>\r\n"; @@ -78,6 +84,8 @@ replyAllArtist = msg; #endregion + AndroidServer.logInfo("Caching music artist finished"); + #region album msg = string.Empty; @@ -92,6 +100,7 @@ List<MediaPortal.Music.Database.AlbumInfo> list1 = new List<MediaPortal.Music.Database.AlbumInfo>(); db.GetAllAlbums(ref list1); + AndroidServer.logInfo("Caching music albums found :" + list1.Count); foreach (MediaPortal.Music.Database.AlbumInfo album in list1) { @@ -99,9 +108,14 @@ } list1.Sort(new AlbumComparer()); + AndroidServer.logInfo("Caching music album sorted"); + cnt = 0; foreach (MediaPortal.Music.Database.AlbumInfo album in list1) { + cnt++; + if (cnt > 1000) break; + string name = album.Album.Replace("|", "").Trim(); if (name != string.Empty) { @@ -121,6 +135,8 @@ #endregion + AndroidServer.logInfo("Caching music album finished"); + #region songs msg = string.Empty; @@ -137,11 +153,18 @@ List<MediaPortal.Music.Database.Song> list2 = new List<MediaPortal.Music.Database.Song>(); db.GetSongsByArtist("%", ref list2); + AndroidServer.logInfo("Caching music songs found :" + list2.Count) ; list2.Sort(new SongComparer()); + AndroidServer.logInfo("Caching music songs sorted"); + + cnt = 0; foreach (MediaPortal.Music.Database.Song song in list2) { + cnt++; + if (cnt > 1000) break; + msg += "<Item>\r\n"; msg += "<ID>" + HttpUtility.HtmlEncode(song.Id.ToString()) + "</ID>\r\n"; @@ -160,6 +183,9 @@ replyAllSong = msg; #endregion + + AndroidServer.logInfo("Caching music songs finished"); + } public static void ReplyMusicDir(Socket Socket, string Request) Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote/Content/PictureHandler.cs =================================================================== --- trunk/plugins/AndroidRemote/Server/AndroidRemote/Content/PictureHandler.cs 2011-01-17 14:33:48 UTC (rev 4071) +++ trunk/plugins/AndroidRemote/Server/AndroidRemote/Content/PictureHandler.cs 2011-01-17 21:09:34 UTC (rev 4072) @@ -154,10 +154,10 @@ Bitmap bit = (Bitmap)Bitmap.FromFile(dir); byte[] b; - if ((bit.Width > 1600) || (bit.Height > 1600)) + if ((bit.Width > 600) || (bit.Height > 600)) { Bitmap thumb = (Bitmap)bit.Clone(); - thumb = MediaPortal.Util.BitmapResize.Resize(ref thumb, 1600, 1600, false, true); + thumb = MediaPortal.Util.BitmapResize.Resize(ref thumb, 600, 600, false, true); b = SomeUtils.ImageToByteArray((Image)thumb); } @@ -277,10 +277,10 @@ Bitmap bit = (Bitmap)Bitmap.FromFile(PictureHandler.AllPicturesList[x]); byte[] b; - if ((bit.Width > 1600) || (bit.Height > 1600)) + if ((bit.Width > 600) || (bit.Height > 600)) { Bitmap thumb = (Bitmap)bit.Clone(); - thumb = MediaPortal.Util.BitmapResize.Resize(ref thumb, 1600, 1600, false, true); + thumb = MediaPortal.Util.BitmapResize.Resize(ref thumb, 600, 600, false, true); b = SomeUtils.ImageToByteArray((Image)thumb); } @@ -307,12 +307,12 @@ } else { - handler.SendServerError(sock,PictureHandler.AllPicturesList[x], "ReplyRandomPictureFile"); + handler.SendServerError(sock, PictureHandler.AllPicturesList[x], "ReplyRandomPictureFile"); } } else { - handler.SendErrorFile(sock,"ReplyRandomPictureFile"); + handler.SendErrorFile(sock, "ReplyRandomPictureFile"); } } @@ -478,10 +478,10 @@ Bitmap bit = (Bitmap)Bitmap.FromFile(filePath); byte[] b; - if ((bit.Width > 1600) || (bit.Height > 1600)) + if ((bit.Width > 600) || (bit.Height > 600)) { Bitmap thumb = (Bitmap)bit.Clone(); - thumb = MediaPortal.Util.BitmapResize.Resize(ref thumb, 1600, 1600, false, true); + thumb = MediaPortal.Util.BitmapResize.Resize(ref thumb, 600, 600, false, true); b = SomeUtils.ImageToByteArray((Image)thumb); } Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote.suo =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |