mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-05-14 22:36:35 +03: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:id="@+id/download_control_layout"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
a:layout_weight="1"
|
a:layout_weight="1.2"
|
||||||
a:orientation="vertical">
|
a:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -1561,7 +1561,7 @@ public class DownloadServiceImpl extends Service implements DownloadService
|
|||||||
{
|
{
|
||||||
MusicDirectory.Entry currentSong = currentPlaying.getSong();
|
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 artist = currentSong.getArtist();
|
||||||
String album = currentSong.getAlbum();
|
String album = currentSong.getAlbum();
|
||||||
|
@ -169,7 +169,15 @@ public class FileUtil
|
|||||||
opt.inJustDecodeBounds = false;
|
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));
|
Log.i("getAlbumArtBitmap", String.valueOf(size));
|
||||||
|
|
||||||
if (bitmap != null)
|
if (bitmap != null)
|
||||||
|
@ -25,7 +25,6 @@ import android.graphics.drawable.BitmapDrawable;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.TransitionDrawable;
|
import android.graphics.drawable.TransitionDrawable;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.DisplayMetrics;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@ -79,9 +78,7 @@ public class ImageLoader implements Runnable
|
|||||||
imageSizeDefault = drawable.getIntrinsicHeight();
|
imageSizeDefault = drawable.getIntrinsicHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
imageSizeLarge = Util.getMaxDisplayMetric(context);
|
||||||
imageSizeLarge = Math.round(Math.min(metrics.widthPixels, metrics.heightPixels));
|
|
||||||
|
|
||||||
createLargeUnknownImage(context);
|
createLargeUnknownImage(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +192,7 @@ public class ImageLoader implements Runnable
|
|||||||
|
|
||||||
Bitmap bitmap = cache.get(getKey(coverArt, size));
|
Bitmap bitmap = cache.get(getKey(coverArt, size));
|
||||||
|
|
||||||
if (bitmap != null)
|
if (bitmap != null && !bitmap.isRecycled())
|
||||||
{
|
{
|
||||||
Bitmap.Config config = bitmap.getConfig();
|
Bitmap.Config config = bitmap.getConfig();
|
||||||
return bitmap.copy(config, false);
|
return bitmap.copy(config, false);
|
||||||
|
@ -1252,6 +1252,12 @@ public class Util extends DownloadActivity
|
|||||||
return Math.min(metrics.widthPixels, metrics.heightPixels);
|
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)
|
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
|
||||||
{
|
{
|
||||||
// Raw height and width of image
|
// Raw height and width of image
|
||||||
|
Loading…
x
Reference in New Issue
Block a user