Universal Image Loader for Android
This project aims to provide a reusable instrument for asynchronous image loading, caching and displaying.Downloads
- universal-image-loader-1.8.4.jar (library; contains *.class files)
- universal-image-loader-1.8.4-sources.jar (sources; contains *.java files)
- universal-image-loader-1.8.4-javadoc.jar (Java docs; contains *.html files)
-
universal-image-loader-1.8.4-with-sources.jar (library with sources inside; contains *.class and *.java files)
Prefer to use this JAR so you can see Java docs in Eclipse tooltips. - universal-image-loader-sample-1.8.4.apk (sample application)
Quick Setup
1. Include library
Manual:- Download JAR
- Put the JAR in the libs sub folder of your Android project
2. Android Manifest
<manifest> <uses-permission android:name="android.permission.INTERNET" /> <!-- Include next permission if you want to allow UIL to cache images on SD card --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> ... <application android:name="MyApplication"> ... </application> </manifest>
3. Application class
public class MyApplication extends Application { @SuppressWarnings("unused") @Override public void onCreate() { if (Config.DEVELOPER_MODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectAll().penaltyDialog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectAll().penaltyDeath().build()); } super.onCreate(); initImageLoader(getApplicationContext()); } public static 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() .discCacheFileNameGenerator(new Md5FileNameGenerator()) .tasksProcessingOrder(QueueProcessingType.LIFO).enableLogging() // Not // necessary // in // common .build(); // Initialize ImageLoader with configuration. ImageLoader.getInstance().init(config); } static class Config { public static final boolean DEVELOPER_MODE = false; } }
4 Common Interface
public interface Common {
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.ic_stub)
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error).cacheInMemory().cacheOnDisc()
.build();
// Image Loader
ImageLoader imageLoader = ImageLoader.getInstance();
AnimateFirstDisplayListener animationListener = new AnimateFirstDisplayListener();
static class AnimateFirstDisplayListener extends SimpleImageLoadingListener {
static final List<String> displayedImages = Collections
.synchronizedList(new LinkedList<String>());
@Override
public void onLoadingComplete(String imageUri, View view,
Bitmap loadedImage) {
if (loadedImage != null) {
ImageView imageView = (ImageView) view;
boolean firstDisplay = !displayedImages.contains(imageUri);
if (firstDisplay) {
FadeInBitmapDisplayer.animate(imageView, 500);
displayedImages.add(imageUri);
}
}
}
}
5 Image Display Class
public class MonthCalendarAdapter extends BaseAdapter implements Common {
private LayoutInflater mInflater;
private ArrayList<MonthCalendarModel> ListData;
public Context con;
public MonthCalendarAdapter(Context con, ArrayList<MonthCalendarModel> data) {
// TODO Auto-generated constructor stub
mInflater = LayoutInflater.from(con);
ListData = data;
this.con = con;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return ListData.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return ListData.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.activity_month_calendar,
null);
holder = new ViewHolder();
holder.name = (TextView) convertView
.findViewById(R.id.FestivalName);
holder.content = (TextView) convertView
.findViewById(R.id.FestivalContent);
holder.date = (TextView) convertView
.findViewById(R.id.FestivalplaceName);
holder.icon = (ImageView) convertView
.findViewById(R.id.profile_image);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.name.setText(ListData.get(position).getName().toString());
Log.w("Content", ListData.get(position).getInfo().toString());
holder.content.setText("dsfsdf nsafn ");
holder.date.setText(ListData.get(position).getPlace().toString());
imageLoader.displayImage(ListData.get(position).getHimg(), holder.icon,
options, animationListener);
return convertView;
}
static class ViewHolder {
TextView name;
TextView content;
TextView date;
ImageView icon;
}
}
No comments:
Post a Comment