Permalink
Browse files

Made ImageManager use a variable number of threads to download images…

… so now they load faster\!

git-svn-id: file:///var/ifixit/CodeRepos/Apps/Android/Guidebook@13679 3574e4b1-9a2c-0410-9c1c-83071a6f58f1
  • Loading branch information...
1 parent cdf8589 commit 621f8960dbc3973b8fd2231f13f57558b1b7b442 @marczych marczych committed Sep 18, 2011
Showing with 10 additions and 7 deletions.
  1. +10 −7 src/com/ifixit/guidebook/ImageManager.java
@@ -22,20 +22,26 @@
public class ImageManager {
private static final int IMAGE_THREAD_PRIORITY = Thread.NORM_PRIORITY - 1;
private static final int MAX_STORED_IMAGES = 20;
+ private static final int NUM_THREADS = 5;
private HashMap<String, Bitmap> mImageMap;
private LinkedList<String> mRecentBitmaps;
private File mCacheDir;
private ImageQueue mImageQueue;
- private Thread mImageLoaderThread;
+ private Thread[] mThreads;
public ImageManager(Context context) {
mImageMap = new HashMap<String, Bitmap>();
mRecentBitmaps = new LinkedList<String>();
mImageQueue = new ImageQueue();
- mImageLoaderThread = new Thread(new ImageQueueManager());
+ mThreads = new Thread[NUM_THREADS];
+
+ for (int i = 0; i < NUM_THREADS; i++) {
+ mThreads[i] = new Thread(new ImageQueueManager());
+ mThreads[i].setPriority(IMAGE_THREAD_PRIORITY);
+ mThreads[i].start();
+ }
- mImageLoaderThread.setPriority(IMAGE_THREAD_PRIORITY);
mCacheDir = context.getCacheDir();
if (!mCacheDir.exists()) {
@@ -60,11 +66,8 @@ private void queueImage(String url, Activity activity, LoaderImage imageView) {
synchronized(mImageQueue.imageRefs) {
mImageQueue.imageRefs.push(imageRef);
- mImageQueue.imageRefs.notifyAll();
+ mImageQueue.imageRefs.notify();
}
-
- if (mImageLoaderThread.getState() == Thread.State.NEW)
- mImageLoaderThread.start();
}
private Bitmap getBitmap(String url) {

0 comments on commit 621f896

Please sign in to comment.