From e0b2c6bb8bb45a2e054ebbf46da99b6e6aa79c74 Mon Sep 17 00:00:00 2001 From: ycastonguay Date: Wed, 24 Jul 2013 01:57:44 -0400 Subject: [PATCH] Android: Adjusted bitmap cache sizes depending on screen size, layout bug fixes in MobileLibraryBrowser, and now using SquareImageView when displaying album art throughout the application. Related to issue #406. --- .../Classes/Activities/MainActivity.cs | 15 ++++++--- .../Classes/Activities/PlayerActivity.cs | 14 +++++--- .../MobileLibraryBrowserGridAdapter.cs | 12 +++---- .../Fragments/MobileLibraryBrowserFragment.cs | 13 +++++--- MPfm/MPfm.Android/Resources/Layout/Main.axml | 3 +- .../Layout/MobileLibraryBrowser.axml | 32 +++++++++++-------- .../MPfm.Android/Resources/Layout/Player.axml | 4 +-- 7 files changed, 57 insertions(+), 36 deletions(-) diff --git a/MPfm/MPfm.Android/Classes/Activities/MainActivity.cs b/MPfm/MPfm.Android/Classes/Activities/MainActivity.cs index 390371ee..9f22f4fe 100644 --- a/MPfm/MPfm.Android/Classes/Activities/MainActivity.cs +++ b/MPfm/MPfm.Android/Classes/Activities/MainActivity.cs @@ -22,6 +22,7 @@ using Android.App; using Android.Content; using Android.Content.PM; +using Android.Graphics; using Android.Support.V4.App; using Android.Support.V4.View; using Android.Views; @@ -39,6 +40,7 @@ using MPfm.MVP.Views; using MPfm.Sound.AudioFiles; using TinyMessenger; +using org.sessionsapp.android; using DialogFragment = Android.App.DialogFragment; using Fragment = Android.App.Fragment; @@ -57,7 +59,7 @@ public class MainActivity : BaseActivity, IMobileOptionsMenuView, View.IOnTouchL private TextView _lblArtistName; private TextView _lblAlbumTitle; private TextView _lblSongTitle; - private ImageView _imageAlbum; + private SquareImageView _imageAlbum; private ImageButton _btnPrevious; private ImageButton _btnPlayPause; private ImageButton _btnNext; @@ -88,7 +90,7 @@ protected override void OnCreate(Bundle bundle) _btnPrevious = FindViewById(Resource.Id.main_miniplayer_btnPrevious); _btnPlayPause = FindViewById(Resource.Id.main_miniplayer_btnPlayPause); _btnNext = FindViewById(Resource.Id.main_miniplayer_btnNext); - _imageAlbum = FindViewById(Resource.Id.main_miniplayer_imageAlbum); + _imageAlbum = FindViewById(Resource.Id.main_miniplayer_imageAlbum); _miniPlayer.Visibility = ViewStates.Gone; _miniPlayer.Click += (sender, args) => { Console.WriteLine("MainActivity - Mini player click - Showing player view..."); @@ -101,11 +103,14 @@ protected override void OnCreate(Bundle bundle) _btnPlayPause.Click += BtnPlayPauseOnClick; _btnNext.Click += BtnNextOnClick; + // Get screen size + Point size = new Point(); + WindowManager.DefaultDisplay.GetSize(size); + // Create bitmap cache int maxMemory = (int)(Runtime.GetRuntime().MaxMemory() / 1024); - int cacheSize = maxMemory / 8; - //int cacheSize = 4*1024*1024; - BitmapCache = new BitmapCache(this, cacheSize, 800, 800); + int cacheSize = maxMemory / 16; + BitmapCache = new BitmapCache(this, cacheSize, size.X / 6, size.X / 6); // Listen to player changes to show/hide the mini player _messengerHub = Bootstrapper.GetContainer().Resolve(); diff --git a/MPfm/MPfm.Android/Classes/Activities/PlayerActivity.cs b/MPfm/MPfm.Android/Classes/Activities/PlayerActivity.cs index 39fc4f9d..fae90eae 100644 --- a/MPfm/MPfm.Android/Classes/Activities/PlayerActivity.cs +++ b/MPfm/MPfm.Android/Classes/Activities/PlayerActivity.cs @@ -21,6 +21,7 @@ using Android.App; using Android.Content; using Android.Content.PM; +using Android.Graphics; using Android.Support.V4.View; using Android.Views; using Android.OS; @@ -38,6 +39,7 @@ using MPfm.Player.Objects; using MPfm.Sound.AudioFiles; using TinyMessenger; +using org.sessionsapp.android; using Exception = System.Exception; namespace MPfm.Android @@ -47,7 +49,7 @@ public class PlayerActivity : BaseActivity, IPlayerView, View.IOnTouchListener { private ITinyMessengerHub _messengerHub; private BitmapCache _bitmapCache; - private ImageView _imageViewAlbumArt; + private SquareImageView _imageViewAlbumArt; private TextView _lblPosition; private TextView _lblLength; private ImageButton _btnPlayPause; @@ -82,7 +84,7 @@ protected override void OnCreate(Bundle bundle) _viewPager.Adapter = _tabPagerAdapter; _viewPager.SetOnPageChangeListener(_tabPagerAdapter); - _imageViewAlbumArt = FindViewById(Resource.Id.player_imageViewAlbumArt); + _imageViewAlbumArt = FindViewById(Resource.Id.player_imageViewAlbumArt); _lblPosition = FindViewById(Resource.Id.player_lblPosition); _lblLength = FindViewById(Resource.Id.player_lblLength); _btnPlayPause = FindViewById(Resource.Id.player_btnPlayPause); @@ -108,10 +110,14 @@ protected override void OnCreate(Bundle bundle) _seekBar.StopTrackingTouch += SeekBarOnStopTrackingTouch; _seekBar.ProgressChanged += SeekBarOnProgressChanged; + // Get screen size + Point size = new Point(); + WindowManager.DefaultDisplay.GetSize(size); + // Create bitmap cache int maxMemory = (int)(Runtime.GetRuntime().MaxMemory() / 1024); - int cacheSize = maxMemory / 8; - _bitmapCache = new BitmapCache(this, cacheSize, 800, 800); + int cacheSize = maxMemory / 12; + _bitmapCache = new BitmapCache(this, cacheSize, size.X, size.X); // The album art takes the whole screen width // Match height with width (cannot do that in xml) //_imageViewAlbumArt.LayoutParameters = new ViewGroup.LayoutParams(_imageViewAlbumArt.Width, _imageViewAlbumArt.Width); diff --git a/MPfm/MPfm.Android/Classes/Adapters/MobileLibraryBrowserGridAdapter.cs b/MPfm/MPfm.Android/Classes/Adapters/MobileLibraryBrowserGridAdapter.cs index 5ffc089a..04a6cb95 100644 --- a/MPfm/MPfm.Android/Classes/Adapters/MobileLibraryBrowserGridAdapter.cs +++ b/MPfm/MPfm.Android/Classes/Adapters/MobileLibraryBrowserGridAdapter.cs @@ -122,18 +122,18 @@ public override View GetView(int position, View convertView, ViewGroup parent) if(_fragment.BitmapCache.KeyExists(bitmapKey)) { //Console.WriteLine(">>>>>>>>> MobileLibraryBrowserGridAdapter - Getting album art from cache - position: {0} artistName: {1} albumTitle: {2}", position, _items[position].Query.ArtistName, _items[position].Query.AlbumTitle); - Task.Factory.StartNew(() => { + //Task.Factory.StartNew(() => { imageView.Tag = bitmapKey; //imageView.SetImageBitmap(mainActivity.BitmapCache.GetBitmapFromMemoryCache(bitmapKey)); imageView.SetImageBitmap(_fragment.BitmapCache.GetBitmapFromMemoryCache(bitmapKey)); - }); + //}); } else { - Task.Factory.StartNew(() => { + //Task.Factory.StartNew(() => { //Console.WriteLine(">>>>>>>>> MobileLibraryBrowserGridAdapter - Requesting album art from presenter - position: {0} artistName: {1} albumTitle: {2}", position, _items[position].Query.ArtistName, _items[position].Query.AlbumTitle); _fragment.OnRequestAlbumArt(item.Query.ArtistName, item.Query.AlbumTitle); - }); + //}); } return view; @@ -154,13 +154,13 @@ public void RefreshAlbumArtCell(string artistName, string albumTitle, byte[] alb //Console.WriteLine(">>>>>>>>>MobileLibraryBrowserGridAdapter - *RECEIVED* album art for {0}/{1} - index: {2} visibleCellIndex: {3} firstVisiblePosition: {4}", artistName, albumTitle, index, visibleCellIndex, _gridView.FirstVisiblePosition); if (view != null) { - Task.Factory.StartNew(() => { + //Task.Factory.StartNew(() => { //Console.WriteLine(">>>>>>>>>MobileLibraryBrowserGridAdapter - *LOADING BITMAP* from byte array for {0}/{1} - Index found: {2}", artistName, albumTitle, index); var image = view.FindViewById(Resource.Id.albumCell_image); image.Tag = artistName + "_" + albumTitle; //mainActivity.BitmapCache.LoadBitmapFromByteArray(albumArtData, artistName + "_" + albumTitle, image); _fragment.BitmapCache.LoadBitmapFromByteArray(albumArtData, artistName + "_" + albumTitle, image); - }); + //}); } else { diff --git a/MPfm/MPfm.Android/Classes/Fragments/MobileLibraryBrowserFragment.cs b/MPfm/MPfm.Android/Classes/Fragments/MobileLibraryBrowserFragment.cs index 17d46a1f..afb98641 100644 --- a/MPfm/MPfm.Android/Classes/Fragments/MobileLibraryBrowserFragment.cs +++ b/MPfm/MPfm.Android/Classes/Fragments/MobileLibraryBrowserFragment.cs @@ -20,6 +20,7 @@ using System.Linq; using System.Threading.Tasks; using Android.App; +using Android.Graphics; using Android.OS; using Android.Views; using Android.Views.Animations; @@ -32,6 +33,7 @@ using MPfm.MVP.Models; using MPfm.MVP.Views; using MPfm.Sound.AudioFiles; +using org.sessionsapp.android; using Exception = System.Exception; namespace MPfm.Android.Classes.Fragments @@ -45,7 +47,7 @@ public class MobileLibraryBrowserFragment : BaseFragment, IMobileLibraryBrowserV private MobileLibraryBrowserGridAdapter _gridAdapter; private List _entities = new List(); - ImageView _imageAlbum; + SquareImageView _imageAlbum; LinearLayout _layoutAlbum; TextView _lblArtistName; TextView _lblAlbumTitle; @@ -70,13 +72,16 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Console.WriteLine("MLBFragment - OnCreateView"); _view = inflater.Inflate(Resource.Layout.MobileLibraryBrowser, container, false); + // Get screen size + Point size = new Point(); + Activity.WindowManager.DefaultDisplay.GetSize(size); + // Create bitmap cache int maxMemory = (int)(Runtime.GetRuntime().MaxMemory() / 1024); - //int cacheSize = 4 * 1024 * 1024; int cacheSize = maxMemory / 8; - BitmapCache = new BitmapCache(Activity, cacheSize, 800, 800); + BitmapCache = new BitmapCache(Activity, cacheSize, size.X / 2, size.X / 2); // Max size = half the screen (grid has 2 columns) - _imageAlbum = _view.FindViewById(Resource.Id.mobileLibraryBrowser_imageAlbum); + _imageAlbum = _view.FindViewById(Resource.Id.mobileLibraryBrowser_imageAlbum); _layoutAlbum = _view.FindViewById(Resource.Id.mobileLibraryBrowser_layoutAlbum); _lblArtistName = _view.FindViewById(Resource.Id.mobileLibraryBrowser_lblArtistName); _lblAlbumTitle = _view.FindViewById(Resource.Id.mobileLibraryBrowser_lblAlbumTitle); diff --git a/MPfm/MPfm.Android/Resources/Layout/Main.axml b/MPfm/MPfm.Android/Resources/Layout/Main.axml index b7b1069e..69328bf1 100644 --- a/MPfm/MPfm.Android/Resources/Layout/Main.axml +++ b/MPfm/MPfm.Android/Resources/Layout/Main.axml @@ -13,10 +13,11 @@ android:background="#36454F" android:gravity="center_vertical" android:layout_alignParentBottom="true"> - - + android:textSize="16dp" /> + android:textSize="15dp" /> -