万能imageLoader加载图片的包装,直接用

ImageLoader 是android一款牛逼的开源项目,为了大家能更方便的使用,我在这里分别对

1:加载网络图片

2:加载drwable目录图片

3:加载assert目录的图片

4:加载相册图片

等模块进行了封装:

import android.widget.ImageView;


import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;


/**
 * @ClassName ImageLoaderUtils.java
 * @Description universalimageloader
 *              封装加载网络和本地的图片(相册,assert目录,drawable目录,不包括.9.png图片) 
 *              String imageUri= "http://site.com/image.png"; // from Web 
 *              String imageUri ="file:///mnt/sdcard/image.png"; // from SD card 
 *              String imageUri= "content://media/external/audio/albumart/13"; // from content provider
 *              String imageUri = "assets://image.png"; // from assets
 *              String imageUri = "drawable://" + R.drawable.image; // from drawables (only images, non-9patch)
 * @author youxuan E-mail:[email protected]
 * @date 创建时间:2015-4-1 上午11:45:07
 * @version 3.7.2
 */
public class ImageLoaderUtils {


	private ImageLoaderUtils() {
	}


	public static void displayImage(FilePrefix prefix, String uri, ImageView iv) {
		ImageLoader.getInstance()
				.displayImage(prefix.getPathPrefix() + uri, iv);
	}
	public static void displayImage(FilePrefix prefix, String uri, ImageView iv,DisplayImageOptions options) {
		ImageLoader.getInstance().displayImage(prefix.getPathPrefix(), iv, options);
	}
	
	public static void displayImage(FilePrefix prefix, String uri, ImageView iv,ImageLoadingListener listener) {
		ImageLoader.getInstance().displayImage(prefix.getPathPrefix(), iv,listener);
	}
	
	public static void displayImage(FilePrefix prefix, String uri, ImageView iv,DisplayImageOptions options,ImageLoadingListener listener) {
		ImageLoader.getInstance().displayImage(prefix.getPathPrefix(), iv,options,listener);
	}
	
	
	


	public enum FilePrefix {
		HTTP {
			@Override
			public String getPathPrefix() {
				//return "http://";
				return "";
			}
		},
		FILE {
			@Override
			public String getPathPrefix() {
				return "file:///";
			}
		},
		CONTENT {
			@Override
			public String getPathPrefix() {
				return "content://";
			}
		},
		ASSETS {
			@Override
			public String getPathPrefix() {
				return "assets://";
			}
		},
		DRAWABLE {
			@Override
			public String getPathPrefix() {
				return "drawable://";
			};
		};
		public abstract String getPathPrefix();
	}


}


加载相册图片: ImageLoaderUtils.displayImage(ImageLoaderUtils.FilePrefix.FILE, mPhotoPath, iv_head_img);

加载Asset目录图片: ImageLoaderUtils.displayImage(FilePrefix.ASSETS, "ic_pulish_channel.png", ivLoadingFlash,ishouApplication.loadingOptionsPublishChinal);

加载drawable图片:ImageLoaderUtils.displayImage(FilePrefix.DRAWABLE, ""+R.drawable.ic_launch, ivLoadingFlash,ishouApplication.loadingOptions);

你可能感兴趣的:(万能imageLoader加载图片的包装,直接用)