Improved blurring
This commit is contained in:
parent
66e5c4fdf1
commit
4f7566ddfc
@ -61,21 +61,25 @@ public class UpdateManager {
|
||||
|
||||
private static void onUpgrade(final int oldVersionCode, final int newVersionCode) {
|
||||
if(oldVersionCode < 1030000) {
|
||||
List<Feed> feeds = DBReader.getFeedList(context);
|
||||
for(Feed podcast: feeds) {
|
||||
List<FeedItem> episodes = DBReader.getFeedItemList(context, podcast);
|
||||
for(FeedItem episode : episodes) {
|
||||
FeedImage image = episode.getImage();
|
||||
if(image != null && image.isDownloaded() && image.getFile_url() != null) {
|
||||
File imageFile = new File(image.getFile_url());
|
||||
if(imageFile.exists()) {
|
||||
imageFile.delete();
|
||||
new Thread() {
|
||||
public void run() {
|
||||
List<Feed> feeds = DBReader.getFeedList(context);
|
||||
for (Feed podcast : feeds) {
|
||||
List<FeedItem> episodes = DBReader.getFeedItemList(context, podcast);
|
||||
for (FeedItem episode : episodes) {
|
||||
FeedImage image = episode.getImage();
|
||||
if (image != null && image.isDownloaded() && image.getFile_url() != null) {
|
||||
File imageFile = new File(image.getFile_url());
|
||||
if (imageFile.exists()) {
|
||||
imageFile.delete();
|
||||
}
|
||||
image.setFile_url(null); // calls setDownloaded(false)
|
||||
DBWriter.setFeedImage(context, image);
|
||||
}
|
||||
}
|
||||
image.setFile_url(null); // calls setDownloaded(false)
|
||||
DBWriter.setFeedImage(context, image);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.LightingColorFilter;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@ -506,6 +507,10 @@ public class ItemlistFragment extends ListFragment {
|
||||
txtvTitle.setText(feed.getTitle());
|
||||
txtvAuthor.setText(feed.getAuthor());
|
||||
|
||||
|
||||
// https://github.com/bumptech/glide/issues/529
|
||||
imgvBackground.setColorFilter(new LightingColorFilter(0xff828282, 0x000000));
|
||||
|
||||
Glide.with(getActivity())
|
||||
.load(feed.getImageUri())
|
||||
.placeholder(R.color.image_readability_tint)
|
||||
@ -515,9 +520,6 @@ public class ItemlistFragment extends ListFragment {
|
||||
.dontAnimate()
|
||||
.into(imgvBackground);
|
||||
|
||||
// https://github.com/bumptech/glide/issues/529
|
||||
imgvBackground.setColorFilter(R.color.image_readability_tint);
|
||||
|
||||
Glide.with(getActivity())
|
||||
.load(feed.getImageUri())
|
||||
.placeholder(R.color.light_gray)
|
||||
|
@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.glide;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.media.ThumbnailUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
@ -9,33 +10,35 @@ import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
|
||||
|
||||
public class FastBlurTransformation extends BitmapTransformation {
|
||||
|
||||
private static final String TAG = "BlurTransformation";
|
||||
private static final String TAG = FastBlurTransformation.class.getSimpleName();
|
||||
|
||||
private static final int RADIUS = 1;
|
||||
private static final int IMAGE_SIZE = 192;
|
||||
private static final int STACK_BLUR_RADIUS = 1;
|
||||
private static final int BLUR_IMAGE_WIDTH = 150;
|
||||
|
||||
public FastBlurTransformation(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap transform(BitmapPool pool, Bitmap toTransform,
|
||||
protected Bitmap transform(BitmapPool pool, Bitmap source,
|
||||
int outWidth, int outHeight) {
|
||||
Bitmap resizedBitmap = Bitmap.createScaledBitmap(toTransform, IMAGE_SIZE, IMAGE_SIZE, true);
|
||||
Bitmap transformed = fastBlur(resizedBitmap, RADIUS);
|
||||
if (transformed == null) {
|
||||
Log.w(TAG, "transformed was null");
|
||||
return toTransform;
|
||||
int targetWidth = BLUR_IMAGE_WIDTH;
|
||||
int targetHeight = (int) (1.0 * outHeight * targetWidth / outWidth);
|
||||
Bitmap resized = ThumbnailUtils.extractThumbnail(source, targetWidth, targetHeight);
|
||||
Bitmap result = fastBlur(resized, STACK_BLUR_RADIUS);
|
||||
if (result == null) {
|
||||
Log.w(TAG, "result was null");
|
||||
return source;
|
||||
}
|
||||
return transformed;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "FastBlurTransformation-" + IMAGE_SIZE + "x" + IMAGE_SIZE + "-" + RADIUS;
|
||||
return "FastBlurTransformation[width=" + BLUR_IMAGE_WIDTH + "px,radius=" + STACK_BLUR_RADIUS +"]";
|
||||
}
|
||||
|
||||
private static Bitmap fastBlur(Bitmap original, int radius) {
|
||||
private static Bitmap fastBlur(Bitmap bitmap, int radius) {
|
||||
|
||||
// Stack Blur v1.0 from
|
||||
// http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
|
||||
@ -65,15 +68,6 @@ public class FastBlurTransformation extends BitmapTransformation {
|
||||
//
|
||||
// Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com>
|
||||
|
||||
Bitmap.Config config = original.getConfig();
|
||||
if (config == null) {
|
||||
// Sometimes the config can be null, in those cases
|
||||
// we don't do a transform.
|
||||
return null;
|
||||
}
|
||||
|
||||
Bitmap bitmap = original.copy(config, true);
|
||||
|
||||
if (radius < 1) {
|
||||
return null;
|
||||
}
|
||||
@ -82,7 +76,6 @@ public class FastBlurTransformation extends BitmapTransformation {
|
||||
int h = bitmap.getHeight();
|
||||
|
||||
int[] pix = new int[w * h];
|
||||
Log.e("pix", w + " " + h + " " + pix.length);
|
||||
bitmap.getPixels(pix, 0, w, 0, 0, w, h);
|
||||
|
||||
int wm = w - 1;
|
||||
@ -267,10 +260,7 @@ public class FastBlurTransformation extends BitmapTransformation {
|
||||
yi += w;
|
||||
}
|
||||
}
|
||||
|
||||
Log.e("pix", w + " " + h + " " + pix.length);
|
||||
bitmap.setPixels(pix, 0, w, 0, 0, w, h);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
@ -465,7 +465,6 @@
|
||||
|
||||
<!-- Progress information -->
|
||||
<string name="progress_upgrading_database">Upgrading the database</string>
|
||||
<string name="progress_clearing_image_cache">Clearing old image cache</string>
|
||||
|
||||
<!-- AntennaPodSP -->
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user