package com.camera.simplemjpeg;

import java.io.File;
import java.util.ArrayList;

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class listing_fichiers extends Activity {

	 
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listing_fichiers);

		/*** Read Text File SD Card ***/
		try {

			String sdcard = Environment.getExternalStorageDirectory()
					.toString(); // /mnt/sdcard/
			String path = sdcard + "/mydata/";
			path = "/sdcard/";
			// or path = "/mnt/sdcard/mydata/";
			File file = new File(path);

			ArrayList<String> myArr = new ArrayList<String>();
			
			// List File
			File[] files = file.listFiles();
			for (File sfil : files) {
				if(sfil.isFile())
				{
					String fileName = sfil.toString().substring( sfil.toString().lastIndexOf('/')+1, sfil.toString().length());
					// myArr.add(sfil.toString()); // full path
					myArr.add(fileName);
				}
			}
			
			// List Directory
			/*
			File[] files = file.listFiles();
			for (File sfil : files) {
				if(sfil.isDirectory())
				{
					myArr.add(sfil.toString());
				}
			}
			*/
			   

			file = null;

			// listView1
			final ListView lisView1 = (ListView) findViewById(R.id.listView1);

			// ArrayList to Array
			String[] myData = {};
			myData = myArr.toArray(new String[myArr.size()]);

			ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
					android.R.layout.simple_list_item_1, myData);

			lisView1.setAdapter(adapter);
			

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
		}

	}
    
   
	
}