summaryrefslogtreecommitdiff
path: root/src/de/danoeh
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/danoeh')
-rw-r--r--src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java4
-rw-r--r--src/de/danoeh/antennapod/asynctask/FeedImageLoader.java105
-rw-r--r--src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java33
-rw-r--r--src/de/danoeh/antennapod/util/BitmapDecoder.java8
4 files changed, 23 insertions, 127 deletions
diff --git a/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java b/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java
index 586e20deb..0174e0471 100644
--- a/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java
+++ b/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java
@@ -23,7 +23,7 @@ public abstract class BitmapDecodeWorkerTask extends Thread {
private static final String TAG = "BitmapDecodeWorkerTask";
private ImageView target;
- private Bitmap bitmap;
+ protected Bitmap bitmap;
private Bitmap decodedBitmap;
protected int baseLength;
@@ -50,7 +50,7 @@ public abstract class BitmapDecodeWorkerTask extends Thread {
protected void onPostExecute() {
// check if imageview is still supposed to display this image
- if (tagsMatching(target)) {
+ if (tagsMatching(target) && bitmap != null) {
target.setImageBitmap(bitmap);
} else {
if (AppConfig.DEBUG)
diff --git a/src/de/danoeh/antennapod/asynctask/FeedImageLoader.java b/src/de/danoeh/antennapod/asynctask/FeedImageLoader.java
index 628d62d9b..39013cdac 100644
--- a/src/de/danoeh/antennapod/asynctask/FeedImageLoader.java
+++ b/src/de/danoeh/antennapod/asynctask/FeedImageLoader.java
@@ -1,6 +1,5 @@
package de.danoeh.antennapod.asynctask;
-import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
@@ -8,17 +7,11 @@ import java.util.concurrent.ThreadFactory;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.content.Context;
-import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.os.Handler;
import android.support.v4.util.LruCache;
import android.util.Log;
import android.widget.ImageView;
-
-import com.jakewharton.DiskLruCache;
-import com.jakewharton.DiskLruCache.Snapshot;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R;
@@ -93,7 +86,7 @@ public class FeedImageLoader {
private ExecutorService createExecutor() {
return Executors.newFixedThreadPool(Runtime.getRuntime()
.availableProcessors(), new ThreadFactory() {
-
+
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
@@ -102,7 +95,7 @@ public class FeedImageLoader {
}
});
}
-
+
public static FeedImageLoader getInstance() {
if (singleton == null) {
singleton = new FeedImageLoader();
@@ -110,22 +103,6 @@ public class FeedImageLoader {
return singleton;
}
- public static DiskLruCache openThubmnailDiskCache() throws IOException {
-
- Context appContext = PodcastApp.getInstance();
- DiskLruCache cache = null;
- try {
- cache = DiskLruCache.open(
- appContext.getExternalFilesDir(CACHE_DIR),
- appContext.getPackageManager().getPackageInfo(
- appContext.getPackageName(), 0).versionCode,
- VALUE_SIZE, CACHE_SIZE);
- } catch (NameNotFoundException e) {
- e.printStackTrace();
- }
- return cache;
- }
-
public void loadCoverBitmap(FeedImage image, ImageView target) {
if (image.getFile_url() != null) {
Bitmap bitmap = getBitmapFromCoverCache(image.getFile_url());
@@ -163,25 +140,12 @@ public class FeedImageLoader {
Bitmap bitmap = getBitmapFromThumbnailCache(channel
.getThumbnailUrl());
if (bitmap == null) {
- boolean isInDiskCache = false;
- /*
- try {
- isInDiskCache = isInThumbnailDiskCache(channel
- .getThumbnailUrl());
- } catch (IOException e) {
- e.printStackTrace();
- Log.e(TAG, "Error when trying to read disk cache");
- }
- */
- if (isInDiskCache) {
- executor.submit(new MiroGuideDiskCacheLoader(handler,
- target, channel, LENGTH_BASE_THUMBNAIL));
- } else {
- if (AppConfig.DEBUG) Log.d(TAG, "Starting new thumbnail download");
-
- executor.submit(new MiroGuideThumbnailDownloader(handler,
- target, channel, LENGTH_BASE_THUMBNAIL));
- }
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Starting new thumbnail download");
+ target.setImageResource(R.drawable.default_cover);
+
+ executor.submit(new MiroGuideThumbnailDownloader(handler,
+ target, channel, LENGTH_BASE_THUMBNAIL));
} else {
target.setImageBitmap(bitmap);
}
@@ -189,12 +153,13 @@ public class FeedImageLoader {
target.setImageResource(R.drawable.default_cover);
}
}
-
+
public void clearExecutorQueue() {
executor.shutdownNow();
- if (AppConfig.DEBUG) Log.d(TAG, "Executor was shut down.");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Executor was shut down.");
executor = createExecutor();
-
+
}
public void wipeImageCache() {
@@ -226,11 +191,6 @@ public class FeedImageLoader {
coverCache.put(key, bitmap);
}
- public boolean isInThumbnailDiskCache(String key) throws IOException {
- DiskLruCache cache = openThubmnailDiskCache();
- return cache.get(key) != null;
- }
-
class FeedImageDecodeWorkerTask extends BitmapDecodeWorkerTask {
private static final String TAG = "FeedImageDecodeWorkerTask";
@@ -262,45 +222,4 @@ public class FeedImageLoader {
}
- class MiroGuideDiskCacheLoader extends BitmapDecodeWorkerTask {
- private static final String TAG = "MiroGuideDiskCacheLoader";
- private Exception exception;
-
- private MiroChannel channel;
-
- public MiroGuideDiskCacheLoader(Handler handler, ImageView target,
- MiroChannel channel, int length) {
- super(handler, target, channel.getThumbnailUrl(), length);
- this.channel = channel;
- }
-
- public void run() {
- try {
- DiskLruCache cache = openThubmnailDiskCache();
- Snapshot snapshot = cache.get(fileUrl);
- storeBitmapInCache(BitmapFactory.decodeStream(snapshot
- .getInputStream(0)));
- } catch (IOException e) {
- e.printStackTrace();
- exception = e;
- }
- endBackgroundTask();
- }
-
- @Override
- protected void onPostExecute() {
- if (exception != null) {
- super.onPostExecute();
- } else {
- Log.e(TAG, "Failed to load bitmap from disk cache");
- }
- }
-
- @Override
- protected boolean tagsMatching(ImageView target) {
- return target.getTag() == null || target.getTag() == channel;
- }
-
- }
-
}
diff --git a/src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java b/src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java
index 557aac623..febe309ed 100644
--- a/src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java
+++ b/src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java
@@ -1,31 +1,21 @@
package de.danoeh.antennapod.asynctask;
import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
-import com.jakewharton.DiskLruCache;
-import com.jakewharton.DiskLruCache.Editor;
-
+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.miroguide.model.MiroChannel;
import de.danoeh.antennapod.util.BitmapDecoder;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.os.Handler;
-import android.util.Log;
-import android.widget.ImageView;
-
/** Downlods thumbnails from the MiroGuide and stores them in a DiskLruCache */
public class MiroGuideThumbnailDownloader extends BitmapDecodeWorkerTask {
private static final String TAG = "MiroGuideThumbnailDownloader";
@@ -61,12 +51,8 @@ public class MiroGuideThumbnailDownloader extends BitmapDecodeWorkerTask {
File destination = new File(PodcastApp.getInstance().getCacheDir(),
Integer.toString(fileUrl.hashCode()));
try {
- /*
- * DiskLruCache diskCache =
- * FeedImageLoader.openThubmnailDiskCache(); Editor editor =
- * diskCache.edit(fileUrl);
- */
- if (AppConfig.DEBUG) Log.d(TAG, "Downloading " + fileUrl);
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Downloading " + fileUrl);
URLConnection connection = url.openConnection();
connection.connect();
byte inputBuffer[] = new byte[1024];
@@ -77,8 +63,6 @@ public class MiroGuideThumbnailDownloader extends BitmapDecodeWorkerTask {
int count = 0;
while ((count = input.read(inputBuffer)) != -1) {
output.write(inputBuffer, 0, count);
- if (AppConfig.DEBUG)
- Log.d(TAG, "" + count);
}
output.close();
if (AppConfig.DEBUG)
@@ -86,12 +70,9 @@ public class MiroGuideThumbnailDownloader extends BitmapDecodeWorkerTask {
// Get a smaller version of the bitmap and store it inside the
// LRU
// Cache
- Bitmap bitmap = BitmapDecoder.decodeBitmap(PREFERRED_LENGTH,
+ bitmap = BitmapDecoder.decodeBitmap(PREFERRED_LENGTH,
destination.getPath());
if (bitmap != null) {
- // OutputStream imageOut = editor.newOutputStream(0);
- // bitmap.compress(Bitmap.CompressFormat.PNG, 80, imageOut);
- // editor.commit();
storeBitmapInCache(bitmap);
}
@@ -109,6 +90,6 @@ public class MiroGuideThumbnailDownloader extends BitmapDecodeWorkerTask {
@Override
protected boolean tagsMatching(ImageView target) {
- return target.getTag() == null || target.getTag() == miroChannel;
+ return target.getTag() == miroChannel;
}
}
diff --git a/src/de/danoeh/antennapod/util/BitmapDecoder.java b/src/de/danoeh/antennapod/util/BitmapDecoder.java
index f4b902c6f..d9975a0bb 100644
--- a/src/de/danoeh/antennapod/util/BitmapDecoder.java
+++ b/src/de/danoeh/antennapod/util/BitmapDecoder.java
@@ -41,8 +41,6 @@ public class BitmapDecoder {
options.inJustDecodeBounds = false;
options.inSampleSize = sampleSize;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- options.inDither = false;
- options.inScaled = false;
Bitmap decodedBitmap = BitmapFactory.decodeFile(fileUrl, options);
if (decodedBitmap == null) {
@@ -52,12 +50,10 @@ public class BitmapDecoder {
decodedBitmap = BitmapFactory.decodeFile(fileUrl);
}
if (decodedBitmap != null) {
- if (preferredLength > srcWidth || preferredLength > srcHeight) {
- return decodedBitmap;
- } else {
+
return Bitmap.createScaledBitmap(decodedBitmap,
preferredLength, preferredLength, false);
- }
+
} else {
return null;
}