package com.androidbegin.buttonclicktutorial;


import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

public class repeat extends Activity
{
	
    PendingIntent pendingIntent;
    AlarmManager alarmManager;
    
    Button  button1, button2, button3, button20;
    ImageButton  imageButton1;
	
	Drawable back;
	int flag = 0;
	
	boolean isPressed = false;

	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
        setContentView(R.layout.repeat);

        alarm();
        
        
        button1 = (Button) findViewById(R.id.btn01);
		
        button1 = (Button) findViewById(R.id.btn01);
		
        
        imageButton1 = (ImageButton) findViewById(R.id.imageButton1);
        
        
        imageButton1.setOnTouchListener(new OnTouchListener() 
		{
		    public boolean onTouch(View v, MotionEvent event) 
		    {
		        if (event.getAction() == MotionEvent.ACTION_UP)
		            if ((boolean) v.getTag())
		            {
		                v.setPressed(false);
		                v.setTag(false);
		                return false;
		            } 
		            else 
		            {
		                v.setPressed(true);
		                v.setTag(true);
		                return true;
		            }
		        return false;
		    }
		});
		

        
        
        
		button1.setTag(false);
		button1.setOnTouchListener(new OnTouchListener() 
		{
		    public boolean onTouch(View v, MotionEvent event) 
		    {
		        if (event.getAction() == MotionEvent.ACTION_UP)
		            if ((boolean) v.getTag())
		            {
		                v.setPressed(false);
		                v.setTag(false);
		                return false;
		            } 
		            else 
		            {
		                v.setPressed(true);
		                v.setTag(true);
		                return true;
		            }
		        return false;
		    }
		});
		
		

		
	}
	
	private void repeat_option()
	{
		/*
		String interval = Utils.concat(	minsEdit.getText(), " ", 
										hoursEdit.getText(), " ", 
										daysEdit.getText(), " ", 
										monthsEdit.getText(), " ", 
										yearsEdit.getText() );
		*/
		
	}
	
	private  void alarm()
	{
		
		int i = 5;
		Intent intent = new Intent(this, receiver.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),	alarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIntent);
		Toast.makeText(this, "Starting alarm in " + i + " seconds",	Toast.LENGTH_LONG).show();
	
		
	//	alarmManager.INTERVAL_FIFTEEN_MINUTES;
		
		
	}
	
	@Override
	protected void onDestroy() 
	{
		alarmManager.cancel(pendingIntent);
		super.onDestroy();
	}

}
