package com.easemob.easeui.oss; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.widget.ImageView; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.WeakHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class AsyncImageLoader { private MemoryCache mMemoryCache; private FileCache mFileCache; private ExecutorService mExecutorService; private Context context; private Map mImageViews = Collections .synchronizedMap(new WeakHashMap()); private List mTaskQueue = new ArrayList(); public AsyncImageLoader(Context context, MemoryCache memoryCache, FileCache fileCache) { this.context = context; mMemoryCache = memoryCache; mFileCache = fileCache; mExecutorService = Executors.newFixedThreadPool(5); } public Bitmap loadBitmap(ImageView imageView, String url) { mImageViews.put(imageView, url); Bitmap bitmap = mMemoryCache.get(url); if(bitmap == null) { enquequeLoadPhoto(url, imageView); } return bitmap; } private void enquequeLoadPhoto(String url, ImageView imageView) { if(isTaskExisted(url)) return; LoadPhotoTask task = new LoadPhotoTask(url, imageView); synchronized (mTaskQueue) { mTaskQueue.add(task); } mExecutorService.execute(task); } private boolean isTaskExisted(String url) { if(url == null) return false; synchronized (mTaskQueue) { int size = mTaskQueue.size(); for(int i=0; i