한글로 된 블로그 내용이 별로 없어서 몇자 끄적여 봅니다.
코드 하이라이트가 좀 이상하군요.. 그래서 뺐습니다.
주소 : https://github.com/nostra13/Android-Universal-Image-Loader
퍼미션
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
어플리케이션 객체
ImageLoaderConfiguration 은 사이트에 있는 영어로 된 내용을 보고 추가 삭제 가능합니다.
아래 ImageLoaderConfiguration 소스는 샘플 소스에 있는 거 그대로 사용했습니다.
참고로 ImageLoaderConfiguration 이나 DisplayImageOptions 은 사이트에 있는 내용을 꼼꼼히 읽어보세요.
<application
android:name=".MyApplication"
public class MyApplication extends Application
{
private DisplayImageOptions options = null;
@Override
public void onCreate()
{
super.onCreate();
this.initImageLoader(getApplicationContext());
}
private void initImageLoader(Context context)
{
// This configuration tuning is custom. You can tune every option, you may tune some of them,
// or you can create default configuration by
// ImageLoaderConfiguration.createDefault(this);
// method.
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.diskCacheFileNameGenerator(new Md5FileNameGenerator())
.diskCacheSize(50 * 1024 * 1024) // 50 Mb
.tasksProcessingOrder(QueueProcessingType.LIFO)
// .writeDebugLogs() // Remove for release app
.build();
ImageLoader.getInstance().init(config);
}
public DisplayImageOptions getDisplayImageOptions()
{
if(this.options == null)
{
this.options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_stub)
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
// .resetViewBeforeLoading(false)
// .delayBeforeLoading(1000)
// .preProcessor(...)
// .postProcessor(...)
// .extraForDownloader(...)
// .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
// .bitmapConfig(Bitmap.Config.ARGB_8888)
// .decodingOptions(...)
// .displayer(new SimpleBitmapDisplayer())
// .handler(new Handler())
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.build();
}
return this.options;
}
public void removeFromCache(String imageUri)
{
DiskCacheUtils.removeFromCache(imageUri, ImageLoader.getInstance().getDiskCache());
MemoryCacheUtils.removeFromCache(imageUri, ImageLoader.getInstance().getMemoryCache());
}
}
사용방법
ImageLoader.getInstance().displayImage(Uri.fromFile(new File(profileRealPath)).toString(), imageview);
또는
ImageLoader.getInstance().displayImage(imageUrl, imageview,
((MyApplication)this.getActivity().getApplicationContext()).getDisplayImageOptions());
다양한 사용방법이 사이트에 있습니다.