package com.example.reminder_proj01;


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


import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleCursorAdapter;
import android.widget.SimpleCursorAdapter.ViewBinder;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends ListActivity 
{
	
	private TextView headingText;
	private TextView rangeText;
	private String[] monthArr;
	
	public final Calendar cal = Calendar.getInstance();
	public final Date date_info = new Date();
	
	private SQLiteDatabase db;
	

	private Alarm alarm = new Alarm();
	private AlarmMsg alarmMsg = new AlarmMsg();
	
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);

        
        db = RemindMe.db;
        
        headingText = (TextView) findViewById(R.id.heading_tv);
		rangeText = (TextView) findViewById(R.id.range_tv);
		
		monthArr = getResources().getStringArray(R.array.spinner3_arr);
    }    
    
	
    
   	public void onClick(View v)
   	{
   		switch (v.getId()) 
   		{
	   		case R.id.imageButton1:
	   			Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_LONG).show();
	   			//startActivity(new Intent(this, SettingsActivity.class));
	   			break;		
	   		case R.id.imageButton2:
	   			//Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_LONG).show();
	   			startActivity(new Intent(this, AddAlarm.class));
	   			break;
	   		case R.id.imageButton3:
	   			Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_LONG).show();
	   			move(-1);
	   			rangeText.setText(getRangeStr());
	   			//((SimpleCursorAdapter)getListAdapter()).changeCursor(createCursor());
	   			break;
	   		case R.id.imageButton4:
	   			Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_LONG).show();
	   			move(+1);
	   			rangeText.setText(getRangeStr());
	   			//((SimpleCursorAdapter)getListAdapter()).changeCursor(createCursor());
	   			break;			
   		}
   	}
   	
    @Override
   	protected void onResume()
    {
   		super.onResume();
   		//rangeText.setText("toto");
   		rangeText.setText(getRangeStr());
   	}
    
    private String getRangeStr() 
    {
    	
		int date = cal.get(Calendar.DATE);
		int month = cal.get(Calendar.MONTH);
		int year = cal.get(Calendar.YEAR);
		date_info.setTime(System.currentTimeMillis());
		
		int tmp  = 0;
		
		switch(tmp) // RemindMe.getDateRange()
		{
			case 0: // Daily
				if (date == date_info.getDate() && month == date_info.getMonth() && year == date_info.getYear()+1900) 
				{	return "Today";
				}
				else 
				{
					return date+" "+ monthArr[month+1];
				}
				
			case 1: // Weekly
				return date+" "+monthArr[month+1] + move(+1) + " - " + cal.get(Calendar.DATE)+" "+monthArr[cal.get(Calendar.MONTH)+1] + move(-1);
				//Toast.makeText(getApplicationContext(), "Pipo", Toast.LENGTH_LONG).show();
				
			case 2: // Monthly
				return monthArr[month+1]+" "+year;
				//Toast.makeText(getApplicationContext(), "Pipo", Toast.LENGTH_LONG).show();
				
			case 3: // Yearly
				return year+"";
				//Toast.makeText(getApplicationContext(), "Pipo", Toast.LENGTH_LONG).show();

		}
		
		return null;
	}
    
    private String move(int step)
    {
    	int tmp  = 0;
		switch(tmp) // RemindMe.getDateRange()
		{
			case 0:
				cal.add(Calendar.DATE, 1*step);
				break;		
			case 1:
				cal.add(Calendar.DATE, 7*step);
				break;
			case 2:
				cal.add(Calendar.MONTH, 1*step);
				break;
			case 3:
				cal.add(Calendar.YEAR, 1*step);
				break;			
		}
		return "";
	}    
    


	
	
	
    

    

	
	
}