package ru.akd.renult;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap.CompressFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
public class ModelAdapter extends ArrayAdapter<Models> {
private final Activity activity;
private final ArrayList<Models> entries;
public ModelAdapter(final Activity a, final int textViewer, final ArrayList<Models> entries ){
super(a, textViewer, entries);
this.entries = entries;
activity = a;
}
@Override
public View getView(int position, View convertview, ViewGroup parent){
View v = convertview;
ViewHolder holder;
if(v == null){
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.list, parent, false);
holder = new ViewHolder();
holder.textView = (TextView) v.findViewById(R.id.title);
holder.id = (TextView) v.findViewById(R.id.desc);
holder.imageView = (ImageView) v.findViewById(R.id.image);
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
Models models = entries.get(position);
if(models != null){
holder.textView.setText(models.getModel());
holder.id.setText(models.getModelId());
ImageLoader imageLoader = ImageLoader.getInstance();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getContext())
.memoryCacheExtraOptions(480, 800) // width, height
.threadPoolSize(5)
.threadPriority(Thread.MIN_PRIORITY + 2)
.denyCacheImageMultipleSizesInMemory()
.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // 2 Mb
.defaultDisplayImageOptions(DisplayImageOptions.createSimple())
.build();
imageLoader.init(config);
imageLoader.displayImage(models.getImg(), holder.imageView);
}
return v;
}
private static class ViewHolder {
public TextView textView;
public ImageView imageView;
public TextView id;
}
}