package com.example.imageload.load;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.util.LruCache;
import android.widget.ImageView;


/**
 * ͼƬ
 * @author Administrator
 *
 */

public class ImageLoader {
	//ͼƬ
	ImageCache mImageCache = new ImageCache();
	//̳߳أ߳ΪCPU
	ExecutorService mExecutorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
	
	
	//ͼƬ
	public void displayImage(final String url, final ImageView imageView){
		imageView.setTag(url);
		mExecutorService.submit(new Runnable() {
			@Override
			public void run() {
				Bitmap bitmap = downLoadImage(url);
				if (bitmap == null){
					return;
				}
				if (imageView.getTag().equals(url)){
					imageView.setImageBitmap(bitmap);
				}
				mImageCache.put(url, bitmap);
			}
		});
	}

	protected Bitmap downLoadImage(String imageUrl) {
		Bitmap bitmap = null;
		try {
			URL url = new URL(imageUrl);
			final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			bitmap = BitmapFactory.decodeStream(conn.getInputStream());
			conn.disconnect();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return bitmap;
	}
}

@@ -709,16 +709,131 @@
 eView)%7B%0A
+%09%09Bitmap bitmap = mImageCache.get(url);%0A%09%09if (bitmap != null)%7B%0A%09%09%09imageView.setImageBitmap(bitmap);%0A%09%09%09return;%0A%09%09%7D%0A
 %09%09imageV

修正加载图片，添加从缓存中加载