package com.example.date_time_picker01;




import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

//http://www.android-examples.com/change-datepickerdialog-theme-in-android-using-dialogfragment/

public class MainActivity extends Activity
{

	
	 DatabaseHelper db;
	  ListView mListView;
	  
	  String[] prenoms = new String[]{
	            "Antoine", "Benoit", "Cyril", "David", "Eloise", "Florent",
	            "Gerard", "Hugo", "Ingrid", "Jonathan", "Kevin", "Logan",
	            "Mathieu", "Noemie", "Olivia", "Philippe", "Quentin", "Romain",
	            "Sophie", "Tristan", "Ulric", "Vincent", "Willy", "Xavier",
	            "Yann", "Zoé"
	       };
	 
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		// db = new DatabaseHelper(getApplicationContext());
		 
		  // creation OK
	        //db.addAlarm01();
	        //db.addAlarm02();
	        
	        
	       // db.addAlarm03();
	        
	        mListView = (ListView) findViewById(R.id.listView);
	        
	     /*   ArrayList<String> tab = new ArrayList<String>();
	        
	        List<Alarm> all = db.getAll();
	        for (Alarm todo : all)
	        {
	            Log.d("ToDo", todo.get_nom());
	            
	            tab.add(todo.get_nom());
	            
	        }*/
	        
	        afficherListeNoms();
	        //afficherListeAlarms(all);
		 
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	
	public void onClick(View v) 
	{
		switch (v.getId())
		{
			case R.id.imageButton1:
				startActivity(new Intent(this, Settings.class));
				break;		
			case R.id.imageButton2:
				startActivity(new Intent(this, AddAlarm.class));
				break;
			/*case R.id.imageButton3:
				move(-1);
				rangeText.setText(getRangeStr());
				((SimpleCursorAdapter)getListAdapter()).changeCursor(createCursor());
				break;
			case R.id.imageButton4:
				move(+1);
				rangeText.setText(getRangeStr());
				((SimpleCursorAdapter)getListAdapter()).changeCursor(createCursor());
				break;	
				*/		
		}
	}
	
	
	/*******************************************************************/
	
	 private void afficherListeNoms()
	    {
	        //android.R.layout.simple_list_item_1 est une vue disponible de base dans le SDK android,
	        //Contenant une TextView avec comme identifiant "@android:id/text1"

	        ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, prenoms);
	        mListView.setAdapter(adapter);
	    }
	    

	    private List<Alarm> genererAlarms()
	    {
	    	//Alarm(String nom, String etat, long time_milliseconds
	        List<Alarm> obj = new ArrayList<Alarm>();
	        obj.add(new Alarm("aqwzsx" , "actif" , 123456   ));
	        obj.add(new Alarm("dickou" , "plouf" , 007   ));
	        obj.add(new Alarm("alpha" , "nada" , 543   ));
	        
	        //tweets.add(new Alarm(Color.BLUE, "Kevin", "C'est ici que ça se passe !"   ));
	        //tweets.add(new Alarm(Color.GREEN, "Logan", "Que c'est beau..."   ));
	        //tweets.add(new Alarm(Color.RED, "Mathieu", "Il est quelle heure ??"  ));
	        //tweets.add(new Alarm(Color.GRAY, "Willy", "On y est presque"  ));
	        return obj;
	    }

	    private void afficherListeAlarms(List<Alarm> all)
	    {
	    	// OK
	    	//List<Alarm> obj = genererAlarms();
	    	//AlarmAdapter adapter = new AlarmAdapter(MainActivity.this, obj);
	        //mListView.setAdapter(adapter);
	    	
	    	// ou bien ceci
	        AlarmAdapter adapter = new AlarmAdapter(MainActivity.this, all);
	        mListView.setAdapter(adapter);
	}
	
}
