package com.androidbegin.buttonclicktutorial;



import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;


// source Appli_alarm01 du 15 Décembre 2016

public class MainActivity extends Activity
{
	public static final String PREFERENCES_NAME = "MyPrefsFile";
	public static SharedPreferences sp;
	
	DB_alarm db;
	private SQLiteDatabase dataBase;

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
			super.onCreate(savedInstanceState);
			setContentView(R.layout.activity_custom_calendar);
	
			// preferences
			PreferenceManager.setDefaultValues(this, R.xml.settings, false);
			sp = PreferenceManager.getDefaultSharedPreferences(this);
			
			
			 db = new DB_alarm(getApplicationContext());
			 
             //creation_alarm();

			 
			
			//getSupportActionBar().setDisplayHomeAsUpEnabled(true);
			
			
			 ArrayList<ArrayList<Object>> dataArrays = new ArrayList<ArrayList<Object>>();
			 
			 ArrayList<Object> dataList = new ArrayList<Object>();
			 
			 dataList.add("toto");
             dataList.add(128);
             Calendar cal_start = Calendar.getInstance();
             cal_start.set(2017,0,7,15,54);
             Date event =  cal_start.getTime();
             dataList.add(event);
             dataArrays.add(dataList);
             
             dataList.clear();
             

			 dataList.add("alpha");
             dataList.add(512);
             cal_start = Calendar.getInstance();
             cal_start.set(2017,0,18,15,54);
             event =  cal_start.getTime();
             dataList.add(event);
             dataArrays.add(dataList);


             
             CalendarCustomView mView = (CalendarCustomView)findViewById(R.id.custom_calendar);

             
/*		    
			// Locate the button in activity_main.xml
			button = (Button) findViewById(R.id.MyButton);
	
			// Capture button clicks
			button.setOnClickListener(new OnClickListener()
			{
				public void onClick(View arg0) {
	
					// Start NewActivity.class
					Intent myIntent = new Intent(MainActivity.this,
							NewActivity.class);
					startActivity(myIntent);
				}
			});
*/			
			
	}
	
	
	private void creation_alarm()
	{
       
		String dateInString = "22-14-2017 22:00";
		long  time_millis = Tools.convertir_date_timestamp(dateInString);
	    long now = System.currentTimeMillis(); 
	    String NAME = "PIF";
	    String FROMDATE =  "un_a";
	    String TODATE =  "un_b";
	    long DATETIME =  time_millis;
	    String STATUS = "active";
	    long CREATEDTIME =  now ;
	    long MODIFIEDTIME =  now ;
	    db.insert_alarm(NAME, FROMDATE, TODATE, DATETIME, STATUS, CREATEDTIME, MODIFIEDTIME);
	}   
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
	      switch (item.getItemId())
	      {
	      
	      		case R.id.add_event:
	      			Toast.makeText(getApplicationContext(),"Add event",Toast.LENGTH_SHORT).show();
	      			Intent Intent02 = new Intent(MainActivity.this, agenda02.class);
	      			startActivity(Intent02);
	      			return true;
		     
	      		case R.id.menu_help:
	      			Toast.makeText(getApplicationContext(),"Clicked",Toast.LENGTH_SHORT).show();
	      			Intent Intent01 = new Intent(MainActivity.this, agenda02.class);
	      			startActivity(Intent01);
	      			return true;
		      
	      		case R.id.menu_settings:
		          // Comportement du bouton "Paramètres"
		          return true;
		      
	      		case R.id.menu_datepicker:
	      			Toast.makeText(getApplicationContext(),"Clicked",Toast.LENGTH_SHORT).show();
	      			Intent Intent03 = new Intent(MainActivity.this, datepicker.class);
	      			startActivity(Intent03);
	      			
			          return true;
		          
		          
	      		default:
		          return super.onOptionsItemSelected(item);
		 }
	}
	
	
}