mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-16 19:50:35 +01:00
Try to be better with memory when reading bitmaps
This commit is contained in:
parent
ad7ea3cc9e
commit
6362b5d266
@ -44,7 +44,7 @@
|
||||
a:id="@+id/download_control_layout"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="fill_parent"
|
||||
a:layout_weight="1"
|
||||
a:layout_weight="1.2"
|
||||
a:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
|
@ -1561,7 +1561,7 @@ public class DownloadServiceImpl extends Service implements DownloadService
|
||||
{
|
||||
MusicDirectory.Entry currentSong = currentPlaying.getSong();
|
||||
|
||||
Bitmap lockScreenBitmap = FileUtil.getAlbumArtBitmap(this, currentSong, 0, true);
|
||||
Bitmap lockScreenBitmap = FileUtil.getAlbumArtBitmap(this, currentSong, Util.getMinDisplayMetric(this), true);
|
||||
|
||||
String artist = currentSong.getArtist();
|
||||
String album = currentSong.getAlbum();
|
||||
|
@ -169,7 +169,15 @@ public class FileUtil
|
||||
opt.inJustDecodeBounds = false;
|
||||
}
|
||||
|
||||
bitmap = BitmapFactory.decodeFile(albumArtFile.getPath(), opt);
|
||||
try
|
||||
{
|
||||
bitmap = BitmapFactory.decodeFile(albumArtFile.getPath(), opt);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.e(TAG, "Exception in BitmapFactory.decodeFile()", ex);
|
||||
}
|
||||
|
||||
Log.i("getAlbumArtBitmap", String.valueOf(size));
|
||||
|
||||
if (bitmap != null)
|
||||
|
@ -25,7 +25,6 @@ import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.TransitionDrawable;
|
||||
import android.os.Handler;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@ -79,9 +78,7 @@ public class ImageLoader implements Runnable
|
||||
imageSizeDefault = drawable.getIntrinsicHeight();
|
||||
}
|
||||
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
imageSizeLarge = Math.round(Math.min(metrics.widthPixels, metrics.heightPixels));
|
||||
|
||||
imageSizeLarge = Util.getMaxDisplayMetric(context);
|
||||
createLargeUnknownImage(context);
|
||||
}
|
||||
|
||||
@ -195,7 +192,7 @@ public class ImageLoader implements Runnable
|
||||
|
||||
Bitmap bitmap = cache.get(getKey(coverArt, size));
|
||||
|
||||
if (bitmap != null)
|
||||
if (bitmap != null && !bitmap.isRecycled())
|
||||
{
|
||||
Bitmap.Config config = bitmap.getConfig();
|
||||
return bitmap.copy(config, false);
|
||||
|
@ -1252,6 +1252,12 @@ public class Util extends DownloadActivity
|
||||
return Math.min(metrics.widthPixels, metrics.heightPixels);
|
||||
}
|
||||
|
||||
public static int getMaxDisplayMetric(Context context)
|
||||
{
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
return Math.max(metrics.widthPixels, metrics.heightPixels);
|
||||
}
|
||||
|
||||
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
|
||||
{
|
||||
// Raw height and width of image
|
||||
|
Loading…
x
Reference in New Issue
Block a user