ResourceAdapter.java 2.02 KB
package com.upc.pbe.upcnews;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

//Modificacio de l'Adapter d'Adnroid, creat al nostre gust per donar estil als elements de la ListView de directoris i arxius
public class ResourceAdapter extends ArrayAdapter<String> {

    Context context; 
    int layoutResourceId;    
    String[] entries = null;
    
    public ResourceAdapter(Context context, int layoutResourceId, String[] data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        entries = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    	 TextView row;
    	 ImageView rowImage;
    	 RelativeLayout container;
    	 
         if (convertView == null) 
         {
        	 LayoutInflater inflater = ((Activity)context).getLayoutInflater();
             container = (RelativeLayout) inflater.inflate(R.layout.rowlayout, parent, false);
         } 
         else 
         {
             container = (RelativeLayout) convertView;
         }
         final String text = entries[position];
         row = (TextView) container.findViewById(R.id.rowTextView);
         rowImage = (ImageView) container.findViewById(R.id.rowImageView);
         row.setText(text);
         //Si es un m3u8, posem el text en verd i l'icono de video
	     if(text.endsWith(".m3u8")) {
	       	row.setTextColor(Color.parseColor("#5FB404"));
	       	rowImage.setImageResource(R.drawable.movie);
	     }
	     //Si no, posem el text en blau i l'icono de directori
	     else{
	    	 row.setTextColor(((Activity)context).getResources().getColor(R.color.BlueAndroid));
	    	 rowImage.setImageResource(R.drawable.folder);
	     }
        return container;
    }
}