package com.qiyou.mb.android.utils.image;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.qiyou.mb.android.QiYouConstant;
import com.qiyou.mb.android.R;
 
public class ImageGridAdapter extends BaseAdapter {
	private String[] files;

	private LayoutInflater mLayoutInflater;

	public ImageGridAdapter(String[] files, Context context) {
		this.files = files;
		mLayoutInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return files == null ? 0 : files.length;
	}

	@Override
	public String getItem(int position) {
		return files[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		MyGridViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new MyGridViewHolder();
			convertView = mLayoutInflater.inflate(R.layout.gridview_item,
					parent, false);
			viewHolder.imageView = (QimageView) convertView
					.findViewById(R.id.album_image);
		
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (MyGridViewHolder) convertView.getTag();
		}
		String url = getItem(position);
		viewHolder.imageView.getLayoutParams().height= (int) (QiYouConstant.PV_INT_SCREEN_WIDTH/4.5);
		viewHolder.imageView.getLayoutParams().width=(int) (QiYouConstant.PV_INT_SCREEN_WIDTH/4.5);
//		QLog.getLogger().d(dTAG, "imageloader to display url is:"+url);
		ImageLoader.getInstance().displayImage(url, viewHolder.imageView); 
//		IL.DisplayImage(url, viewHolder.imageView); 
		return convertView;
	}

	private static class MyGridViewHolder {
		QimageView imageView;
	}
}
