package com.example.geo_api16;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class TrajetDisplay extends Activity 
{

	ArrayList<String> Trajet_Steps_List;

	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.trajet_listview_layout);
		
		ListView ListSteps = (ListView)findViewById(R.id.listView);
       
        Trajet_Steps_List = new ArrayList<String>();
        getSteps();
        // Create The Adapter with passing ArrayList as 3rd parameter
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, Trajet_Steps_List);
        // Set The Adapter
        ListSteps.setAdapter(arrayAdapter);
        
        // register onClickListener to handle click events on each item
        ListSteps.setOnItemClickListener(new OnItemClickListener()
        {
                     // argument position gives the index of item which is clicked
                    public void onItemClick(AdapterView<?> arg0, View v,int position, long arg3)
                    {
                       
                            String str = Trajet_Steps_List.get(position);
                            Toast.makeText(getApplicationContext(), "Selection --> : "+str,   Toast.LENGTH_LONG).show();
                    }
         });
		
	}
	
	void getSteps()
    {
        
        
        String filenamex = "infos_filename.txt";
		File filex = new File(Environment.getExternalStorageDirectory(), filenamex);
	    FileInputStream fis;
	    
	    String [] codes = new String[200];
	    int i = 0;
	    
		try 
		{
			fis = new FileInputStream(filex);
    		BufferedReader br = new BufferedReader(new InputStreamReader(fis));
    	 
    		String line = null;
    		
    		
    		while ((line = br.readLine()) != null)
    		{
    			codes[i] = line;
    			i++;
    			System.out.println(line);
    			Trajet_Steps_List.add(line);
    		}
    	 
    		br.close();
			
		} 
		catch (FileNotFoundException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
       
		/*
		Trajet_Steps_List.add("DOG");
        Trajet_Steps_List.add("CAT");
        Trajet_Steps_List.add("HORSE");
        Trajet_Steps_List.add("ELEPHANT");
        Trajet_Steps_List.add("LION");
        Trajet_Steps_List.add("COW");
        Trajet_Steps_List.add("MONKEY");
        Trajet_Steps_List.add("DEER");
        Trajet_Steps_List.add("RABBIT");
        Trajet_Steps_List.add("BEER");
        Trajet_Steps_List.add("DONKEY");
        Trajet_Steps_List.add("LAMB");
        Trajet_Steps_List.add("GOAT");
       */
    }

	
}