您的位置:首页 > 其它

ImageLoader 线程池 单例 使用模板

2015-06-30 00:25 302 查看
ImageLoader 线程池 单例 使用模板
package com.cggame.trillion;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import android.graphics.Bitmap;import android.widget.ImageView;public class ImageLoader {private static ImageLoader imageLoader;private ExecutorService pool = null;private static final int MAX_THREAD_COUNT = 5;private ImageLoader() {imageLoader = new ImageLoader();pool = Executors.newFixedThreadPool(MAX_THREAD_COUNT);}public static void loadImageAsync(final ImageView imageView, final String path) {if (imageLoader == null) {imageLoader = new ImageLoader();}imageLoader.pool.execute(new DownLoadThread(imageView, path));}private static void downloadImage(final ImageView imageView, String path) {final Bitmap bitmap = null;// 开始下载// bitmap = ...;// 下载完成imageView.post(new Runnable() {@Overridepublic void run() {imageView.setImageBitmap(bitmap);}});}private static class DownLoadThread extends Thread {private ImageView imageView;private String path;public DownLoadThread(ImageView imageView, String path) {this.imageView = imageView;this.path = path;}@Overridepublic void run() {super.run();downloadImage(imageView, path);}}}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: