Hopefully fixed OOM when bluring an image.
This commit is contained in:
parent
8ba3ed3b4b
commit
bfa800bce6
5 changed files with 34 additions and 19 deletions
|
|
@ -27,15 +27,19 @@ package com.kabouzeid.gramophone.helper.bitmapblur;
|
|||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
// class modified by Karim Abou Zeid (kabouzeid)
|
||||
|
||||
public class StackBlurManager {
|
||||
static final int EXECUTOR_THREADS = Runtime.getRuntime().availableProcessors();
|
||||
static final ExecutorService EXECUTOR = Executors.newFixedThreadPool(EXECUTOR_THREADS);
|
||||
|
||||
/**
|
||||
* Original image
|
||||
* Resized original image
|
||||
*/
|
||||
private final Bitmap _image;
|
||||
|
||||
|
|
@ -52,10 +56,10 @@ public class StackBlurManager {
|
|||
/**
|
||||
* Constructor method (basic initialization and construction of the pixel array)
|
||||
*
|
||||
* @param image The image that will be analyed
|
||||
* @param image The image that will be analysed
|
||||
*/
|
||||
public StackBlurManager(Bitmap image) {
|
||||
_image = image;
|
||||
_image = Util.getResizedBitmap(image, 500, 500, false);
|
||||
_blurProcess = new JavaBlurProcess();
|
||||
}
|
||||
|
||||
|
|
@ -77,13 +81,4 @@ public class StackBlurManager {
|
|||
public Bitmap returnBlurredImage() {
|
||||
return _result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the original image as a bitmap
|
||||
*
|
||||
* @return the original bitmap image
|
||||
*/
|
||||
public Bitmap getImage() {
|
||||
return this._image;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -213,11 +213,12 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
|||
.resetViewBeforeLoading(true)
|
||||
.build(),
|
||||
new SimpleImageLoadingListener() {
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
applyPalette(null);
|
||||
albumArtBackground.setImageBitmap(new StackBlurManager(BitmapFactory.decodeResource(getResources(), R.drawable.default_album_art)).process(10));
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inSampleSize = 2;
|
||||
albumArtBackground.setImageBitmap(new StackBlurManager(BitmapFactory.decodeResource(getResources(), R.drawable.default_album_art, options)).process(10));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
||||
startPostponedEnterTransition();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ import butterknife.InjectView;
|
|||
|
||||
/**
|
||||
* A lot of hackery is done in this activity. Changing things may will brake the whole activity.
|
||||
* <p>
|
||||
* <p/>
|
||||
* Should be kinda stable ONLY AS IT IS!!!
|
||||
*/
|
||||
public class ArtistDetailActivity extends AbsFabActivity implements PaletteColorHolder, CabHolder {
|
||||
|
|
@ -282,8 +282,9 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
|||
}
|
||||
|
||||
private void setUpArtistImageAndApplyPalette(final boolean forceDownload) {
|
||||
final StackBlurManager defaultArtistImageBlurManager = new StackBlurManager(BitmapFactory.decodeResource(getResources(), R.drawable.default_artist_image));
|
||||
artistImageBackground.setImageBitmap(defaultArtistImageBlurManager.process(10));
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inSampleSize = 2;
|
||||
final StackBlurManager defaultArtistImageBlurManager = new StackBlurManager(BitmapFactory.decodeResource(getResources(), R.drawable.default_artist_image, options));
|
||||
LastFMArtistImageUrlLoader.loadArtistImageUrl(this, artist.name, forceDownload, new LastFMArtistImageUrlLoader.ArtistImageUrlLoaderCallback() {
|
||||
@Override
|
||||
public void onArtistImageUrlLoaded(final String url) {
|
||||
|
|
@ -299,7 +300,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
|||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
applyPalette(null);
|
||||
artistImageBackground.setImageBitmap(defaultArtistImageBlurManager.returnBlurredImage());
|
||||
artistImageBackground.setImageBitmap(defaultArtistImageBlurManager.process(10));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -435,7 +435,9 @@ public class MusicControllerActivity extends AbsFabActivity {
|
|||
applyPalette(null);
|
||||
// to gain some performance cache the blurred bitmap
|
||||
if (defaultAlbumArtStackBlurManager == null) {
|
||||
defaultAlbumArtStackBlurManager = new StackBlurManager(BitmapFactory.decodeResource(getResources(), R.drawable.default_album_art));
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inSampleSize = 2;
|
||||
defaultAlbumArtStackBlurManager = new StackBlurManager(BitmapFactory.decodeResource(getResources(), R.drawable.default_album_art, options));
|
||||
defaultAlbumArtStackBlurManager.process(10);
|
||||
}
|
||||
albumArtBackground.setImageBitmap(defaultAlbumArtStackBlurManager.returnBlurredImage());
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ import android.content.Context;
|
|||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
|
@ -247,4 +249,18 @@ public class Util {
|
|||
return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth, boolean recycleOld) {
|
||||
int width = bm.getWidth();
|
||||
int height = bm.getHeight();
|
||||
float scaleWidth = ((float) newWidth) / width;
|
||||
float scaleHeight = ((float) newHeight) / height;
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postScale(scaleWidth, scaleHeight);
|
||||
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
|
||||
if (recycleOld && resizedBitmap != bm) {
|
||||
bm.recycle();
|
||||
}
|
||||
return resizedBitmap;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue