package com.example.listviewcustom05;


import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

public class debug extends ListActivity
{
	
	Bundle extras;
	
	protected TextView employeeNameText;
	protected TextView titleText;
		
	protected List<contact_action> actions;
    protected EmployeeActionAdapter adapter;
	
	
	public void onCreate(Bundle savedInstanceState) 
	{
		
			super.onCreate(savedInstanceState);
			setContentView(R.layout.details);
			extras = getIntent().getExtras();
			
			String nom = extras.getString("nom");
			String prenom = extras.getString("prenom");
	//		String adresse = extras.getString("adresse");
	//		String email = extras.getString("email");
	//		String portable = extras.getString("portable");
	//		String fixe = extras.getString("fixe");
					   
			
			employeeNameText = (TextView) findViewById(R.id.employeeName);
		    employeeNameText.setText(nom.toUpperCase());
		
		 
		    String firstLetter = prenom.substring(0,1).toUpperCase();
		    String restLetters = prenom.substring(1).toLowerCase();
		     String complete =  firstLetter + restLetters;
		    
		    titleText = (TextView) findViewById(R.id.title);
		    titleText.setText(complete);
  	        
		    actions = new ArrayList<contact_action>();
		       
		        actions.add(new contact_action("Call office", "fixe", contact_action.ACTION_CALL));
		        actions.add(new contact_action("Call mobile", "portable", contact_action.ACTION_CALL));
		        actions.add(new contact_action("SMS", "email", contact_action.ACTION_SMS));
		        actions.add(new contact_action("Email", "email", contact_action.ACTION_EMAIL));
			
		        adapter = new EmployeeActionAdapter();
		        setListAdapter(adapter);

		
			
			
	}
	
	
	 public void onListItemClick(ListView parent, View view, int position, long id) 
	 {
	    	
		 contact_action action = actions.get(position);

		    Intent intent;
		    switch (action.getType()) {

		    	case contact_action.ACTION_CALL:  
		        	Uri callUri = Uri.parse("tel:" + action.getData());  
		        	intent = new Intent(Intent.ACTION_CALL, callUri); 
		    	    startActivity(intent);
		        	break;

		    	case contact_action.ACTION_EMAIL:  
	                intent = new Intent(Intent.ACTION_SEND);
	                intent.setType("plain/text");
	                intent.putExtra(Intent.EXTRA_EMAIL, new String[]{action.getData()});
	                startActivity(intent);
	                break;
	                
		    	case contact_action.ACTION_SMS:  
		        	Uri smsUri = Uri.parse("sms:" + action.getData());  
		        	intent = new Intent(Intent.ACTION_VIEW, smsUri); 
		    	    startActivity(intent);
		        	break;

		    	
		    }
	    }    


	class EmployeeActionAdapter extends ArrayAdapter<contact_action> 
	  {

	    	EmployeeActionAdapter() {
				super(debug.this, R.layout.action_list_item, actions);
			}
	    	
	    	@Override
	    	public View getView(int position, View convertView, ViewGroup parent)
	    	{
	    		contact_action action = actions.get(position);
	    		LayoutInflater inflater = getLayoutInflater();
	    		View view = inflater.inflate(R.layout.action_list_item, parent, false);
	    		TextView label = (TextView) view.findViewById(R.id.label);
	    		label.setText(action.getLabel());
	    		TextView data = (TextView) view.findViewById(R.id.data);
	    		data.setText(action.getData());
	    		return view;
	    	}
	    	
	    }
	
	   
}