package com.androidbegin.buttonclicktutorial;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.widget.Toast;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

//http://programmerguru.com/android-tutorial/android-audio-manager-tutorial/

//http://code4reference.com/2012/07/android-jelly-bean-notification/

public class AlarmReceiver extends BroadcastReceiver 
{

	/*
	@Override
	public void onReceive(Context arg0, Intent arg1) 
	{
		Toast.makeText(arg0, "Alarm received!", Toast.LENGTH_LONG).show();

	}
	*/
	@Override
	public void onReceive(Context context, Intent intent) 
	{
	
			//long alarmId = intent.getLongExtra("index", -1);
			
		
			String titre = intent.getStringExtra("titre");
			int keycode = intent.getIntExtra("keycode", -1);

			/*
			AlarmMsg alarmMsg = new AlarmMsg(alarmMsgId);
			alarmMsg.setStatus(AlarmMsg.EXPIRED);
			alarmMsg.persist(RemindMe.db);
	
			Alarm alarm = new Alarm(alarmId);
			alarm.load(RemindMe.db);
	/*
	 */
			Notification n = new Notification(R.drawable.ic_launcher, titre, System.currentTimeMillis());
			//PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(), 0);
			PendingIntent pi = PendingIntent.getActivity(context, keycode, new Intent(), 0); 
			
	
			n.setLatestEventInfo(context, "Remind Me", titre, pi);		
			
			/*
			if (RemindMe.isVibrate()) 
			{
				n.defaults |= Notification.DEFAULT_VIBRATE;
			}
			
			*/
			
			boolean sound = false;
			
			if( sound == true)
			{
				String url = android.provider.Settings.System.DEFAULT_NOTIFICATION_URI.toString();
				n.sound = Uri.parse(url);
				//		n.defaults |= Notification.DEFAULT_SOUND;
			}		
			
			n.flags |= Notification.FLAG_AUTO_CANCEL;		
			NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
			nm.notify((int)keycode, n);
			
			
			Intent myIntent=new Intent(context, ringtone.class);   
			myIntent.putExtra("titre", titre);
			myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
			context.startActivity(myIntent); 
			
			
	}
}

	
	
	
	
	
	

