package com.javacodegeeks.android.androidtimerexample;


import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class Repeat01 extends Activity
{
	
    PendingIntent pendingIntent;
    AlarmManager alarmManager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.repeat01);
	}

	

	public void startAlert(View view)
	{
		
//		EditText text = (EditText) findViewById(R.id.time);
//		int i = Integer.parseInt(text.getText().toString());
//		Intent intent = new Intent(this, MyBroadcastReceiver.class);
//		PendingIntent pendingIntent = PendingIntent.getBroadcast(
//				this.getApplicationContext(), 234324243, intent, 0);
//		AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
		/*alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
				+ (i * 1000), (i * 1000), pendingIntent);*/
//		alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
//				+ (i * 1000), 8000, pendingIntent);
//		Toast.makeText(this, "Starting alarm in " + i + " seconds",
//				Toast.LENGTH_LONG).show();
		
		
		
		EditText text = (EditText) findViewById(R.id.time);
		int i = Integer.parseInt(text.getText().toString());
		Intent intent = new Intent(this, Receiver01.class);
		pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent, 0);
		alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
		/*alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()	+ (i * 1000), (i * 1000), pendingIntent);*/
		alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (i * 1000), 8000, pendingIntent);
		Toast.makeText(this, "Starting alarm in " + i + " seconds",	Toast.LENGTH_LONG).show();
	}
	
	@Override

	protected void onDestroy() 
	{
		alarmManager.cancel(pendingIntent);
		//unregisterReceiver(br);
		super.onDestroy();
	}

}
