package com.androidbegin.buttonclicktutorial;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class ringtone extends Activity
{
	
	 Ringtone ringtone;
	 private Button btn_stop;
	 TextView tv_titre;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ringtone_layout);
		
		Bundle extras = getIntent().getExtras();
		String titre = extras.getString("titre");
		long delai = extras.getLong("delai", -1);
		long time = extras.getLong("time", -1);
		
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        Date netDate = (new Date(time));
        String str_date=  sdf.format(netDate);

		
		tv_titre = (TextView) findViewById(R.id.tv_titre);
        btn_stop = (Button) findViewById(R.id.btn_stop);
        
        String str_delai = "";

        // informations
        long min = delai / 60000;
        
        if(min == 15)
        {
        	str_delai = " dans 15min";
        }
        if(min == 30 )
        {
        	str_delai = " dans 30min";
        }
        
        if(min == 60 )
        {
        	str_delai = " dans1H";
        }

        
        String concat = titre + str_delai + " " + str_date; 
        tv_titre.setText(concat);
        
   
        
        
        Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        if (alarmUri == null)
        {
            alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        }
        
        ringtone = RingtoneManager.getRingtone(ringtone.this, alarmUri);
        ringtone.play();
        
        btn_stop.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v) 
            {
               // Ringtone ringtone = RingtoneManager.getRingtone(datepicker.this, alarmUri);
            	ringtone.stop();
            	finish();
            }
        });
		
		
		
		
	}	


}
