/*
Copyright 2011 Dietmar Wieser, Norbert Lanzanasto, Margit Mutschlechner.
Distributed under the terms of the GNU Lesser General Public License (LGPL).
This file is part of Interactive Museum Guide.
Interactive Museum Guide is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Interactive Museum Guide is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Interactive Museum Guide. If not, see <http://www.gnu.org/licenses/>.
*/
package museum.android.screens;
import java.io.ByteArrayInputStream;
import java.util.Vector;
import museum.server.model.Statistic;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
/**
* Represents one entry in the statistic screen.
*
* @author Norbert Lanzanasto
*
*/
public class StatisticListAdapter extends BaseAdapter {
private LayoutInflater mInflater;
/** statistic items to be displayed **/
private Vector<Statistic> statItems;
/**
* Constructor
*
* @param context
* Context in which the Adapter got called
* @param statItems
* Statistic items to be displayed
*/
public StatisticListAdapter(Context context, Vector<Statistic> statItems) {
mInflater = LayoutInflater.from(context);
this.statItems = statItems;
}
public int getCount() {
return statItems.size();
}
public Statistic getStatisticItemAt(int i) {
return statItems.elementAt(i);
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
/**
* Method to arrange the displaying of one entry on the statistic screen.
*
* @param position
* Statistic item that should be arranged
* @param convertView
* The old view to reuse, if possible
* @param parent
* The parent that this view will eventually be attached to
* @return view A View corresponding to the data at the specified position.
*/
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.statistic_list_item, null);
holder = new ViewHolder();
holder.imgView = (ImageView) convertView.findViewById(R.id.imgIcon);
holder.objName = (TextView) convertView
.findViewById(R.id.txtObjectName);
holder.extraInfo = (TextView) convertView
.findViewById(R.id.txtExtraInfo);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (statItems.get(position).getIcon() == null)
holder.imgView.setImageResource(R.drawable.icon);
else
holder.imgView.setImageDrawable(Drawable
.createFromStream(new ByteArrayInputStream(statItems.get(
position).getIcon()), statItems.get(position)
.getObjectName()));
holder.objName.setText(statItems.get(position).getObjectName());
holder.extraInfo.setText(statItems.get(position).getExtraInfo());
return convertView;
}
static class ViewHolder {
ImageView imgView;
TextView objName;
TextView extraInfo;
}
}
|