android-openrat

Unnamed repository; edit this file 'description' to name the repository.
git clone http://git.code.weiherhei.de/android-openrat.git
Log | Files | Refs

FolderContentAdapter.java (2261B)


      1 /**
      2  * 
      3  */
      4 package de.openrat.android.client.adapter;
      5 
      6 import java.util.ArrayList;
      7 import java.util.List;
      8 
      9 import android.content.Context;
     10 import android.view.LayoutInflater;
     11 import android.view.View;
     12 import android.view.ViewGroup;
     13 import android.widget.BaseAdapter;
     14 import android.widget.ImageView;
     15 import android.widget.TextView;
     16 import de.openrat.android.client.FolderEntry;
     17 import de.openrat.android.client.R;
     18 
     19 /**
     20  * @author dankert
     21  * 
     22  */
     23 public class FolderContentAdapter extends BaseAdapter
     24 {
     25 
     26 	/** Remember our context so we can use it when constructing views. */
     27 	private Context mContext;
     28 
     29 	/**
     30 	 * Hold onto a copy of the entire Contact List.
     31 	 */
     32 	private List<FolderEntry> data = new ArrayList<FolderEntry>();
     33 
     34 	private LayoutInflater inflator;
     35 
     36 	public FolderContentAdapter(Context context, List<FolderEntry> data2)
     37 	{
     38 		mContext = context;
     39 		inflator = (LayoutInflater) context
     40 				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     41 		data = data2;
     42 	}
     43 
     44 	public int getCount()
     45 	{
     46 		return data.size();
     47 	}
     48 
     49 	public Object getItem(int position)
     50 	{
     51 		return data.get(position);
     52 	}
     53 
     54 	/** Use the array index as a unique id. */
     55 	public long getItemId(int position)
     56 	{
     57 		return position;
     58 
     59 	}
     60 
     61 	/**
     62 	 * @param convertView
     63 	 *            The old view to overwrite, if one is passed
     64 	 * @returns a ContactEntryView that holds wraps around an ContactEntry
     65 	 */
     66 	public View getView(int position, View convertView, ViewGroup parent)
     67 	{
     68 
     69 		FolderEntry e = data.get(position);
     70 
     71 		final View view = inflator.inflate(R.layout.listing_entry, null);
     72 
     73 		ImageView image = (ImageView) view.findViewById(R.id.listentry_image);
     74 		switch (e.type)
     75 		{
     76 		case FOLDER:
     77 			image.setImageResource(R.drawable.icon_folder);
     78 			break;
     79 		case FILE:
     80 			image.setImageResource(R.drawable.icon_file);
     81 			break;
     82 		case PAGE:
     83 			image.setImageResource(R.drawable.icon_page);
     84 			break;
     85 		case LINK:
     86 			image.setImageResource(R.drawable.icon_link);
     87 			break;
     88 		case PROJECT:
     89 			image.setImageResource(R.drawable.icon_project);
     90 			break;
     91 		default:
     92 		}
     93 
     94 		TextView name = (TextView) view.findViewById(R.id.listentry_name);
     95 		name.setText(e.name);
     96 
     97 		TextView desc = (TextView) view
     98 				.findViewById(R.id.listentry_description);
     99 		desc.setText(e.description);
    100 
    101 		return view;
    102 	}
    103 
    104 }