Visual improvements when loading images

This commit is contained in:
daniel oeh 2013-08-31 15:56:36 +02:00
parent 7df102daa3
commit dbdda5643c
2 changed files with 87 additions and 81 deletions

View File

@ -2,10 +2,14 @@ package de.danoeh.antennapod.asynctask;
import android.content.res.TypedArray;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.os.Handler;
import android.util.Log;
import android.widget.ImageView;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.asynctask.ImageLoader.ImageWorkerTaskResource;
import de.danoeh.antennapod.util.BitmapDecoder;
@ -13,8 +17,11 @@ import de.danoeh.antennapod.util.BitmapDecoder;
public class BitmapDecodeWorkerTask extends Thread {
protected int PREFERRED_LENGTH;
public static final int FADE_DURATION = 500;
/** Can be thumbnail or cover */
/**
* Can be thumbnail or cover
*/
protected int imageType;
private static final String TAG = "BitmapDecodeWorkerTask";
@ -35,10 +42,7 @@ public class BitmapDecodeWorkerTask extends Thread {
this.imageResource = imageResource;
this.PREFERRED_LENGTH = length;
this.imageType = imageType;
TypedArray res = target.getContext().obtainStyledAttributes(
new int[] { R.attr.default_cover });
this.defaultCoverResource = res.getResourceId(0, 0);
res.recycle();
this.defaultCoverResource = android.R.color.transparent;
}
/**
@ -53,7 +57,13 @@ public class BitmapDecodeWorkerTask extends Thread {
protected void onPostExecute() {
// check if imageview is still supposed to display this image
if (tagsMatching(target) && cBitmap.getBitmap() != null) {
target.setImageBitmap(cBitmap.getBitmap());
Drawable[] drawables = new Drawable[]{
PodcastApp.getInstance().getResources().getDrawable(android.R.color.transparent),
new BitmapDrawable(PodcastApp.getInstance().getResources(), cBitmap.getBitmap())
};
TransitionDrawable transitionDrawable = new TransitionDrawable(drawables);
target.setImageDrawable(transitionDrawable);
transitionDrawable.startTransition(FADE_DURATION);
} else {
if (AppConfig.DEBUG)
Log.d(TAG, "Not displaying image");

View File

@ -66,7 +66,7 @@ public class ImageLoader {
private ExecutorService createExecutor() {
return Executors.newFixedThreadPool(Runtime.getRuntime()
.availableProcessors() + 1, new ThreadFactory() {
.availableProcessors(), new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
@ -196,11 +196,7 @@ public class ImageLoader {
}
private int getDefaultCoverResource(Context context) {
TypedArray res = context
.obtainStyledAttributes(new int[] { R.attr.default_cover });
final int defaultCoverResource = res.getResourceId(0, 0);
res.recycle();
return defaultCoverResource;
return android.R.color.transparent;
}
/**