package com.androidbegin.buttonclicktutorial;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Color;
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.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

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

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

   
		button1 = (Button) findViewById(R.id.btn01);
	    back = button1 .getBackground();
		button1.setOnClickListener(new OnClickListener()
		{

            @SuppressLint("NewApi")
			@Override
            public void onClick(View v) {   
                if(flag==0){
                	button1.setBackgroundColor(Color.YELLOW);
                    flag=1;
                    }
                else{
                    flag=0;
                    button1.setBackground(back);
                }
            }
        });		

	
		
		
		/*******  OK **************/
		
		button2 = (Button) findViewById(R.id.btn02);

		
		button2.setOnTouchListener(new OnTouchListener()
		{
		            @Override
		            public boolean onTouch(View v, MotionEvent event)
		            {
		                if(event.getAction() == MotionEvent.ACTION_UP)
		                {
		                	if(!isPressed)
		                	{
		                		isPressed = true;
		                	}
		                	else
		                	{
		                		isPressed = false;
		                	}  
		                	// appliquer l'état
	                        button2.setPressed(isPressed);
		                }

		                return true;
		            }
		});

      
     
		button3 = (Button) findViewById(R.id.btn3);
		
		button3.setTag(false);
		button3.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;
		    }
		});
	
		
		button4 = (Button) findViewById(R.id.btn4);

		
		button4.setOnTouchListener(new OnTouchListener()
		{
		            @Override
		            public boolean onTouch(View v, MotionEvent event)
		            {
		                if(event.getAction() == MotionEvent.ACTION_UP)
		                {
		                	if(!isPressed)
		                	{
		                		isPressed = true;
		                	}
		                	else
		                	{
		                		isPressed = false;
		                	}  
		                	// appliquer l'état
	                        button4.setPressed(isPressed);
		                }

		                return true;
		            }
		});

		
		
		 final ImageView login;
		 login = (ImageView) findViewById(R.id.imageView1);
		 login.setOnClickListener(new OnClickListener()
		 {
/*
		     public void onClick(View v) 
		     {
		         //TODO: your code here

			     Toast.makeText(getApplicationContext(), 
                               "Button is clicked", Toast.LENGTH_LONG).show();
		     }
	*/	     
		     
		     
	            @SuppressLint("NewApi")
				@Override
	            public void onClick(View v) {   
	                if(flag==0){
	                	login.setImageResource(R.drawable.ic_recurrence_bubble_fill);
	                    flag=1;
	                    }
	                else{
	                    flag=0;
	                	login.setImageResource(R.drawable.ic_recurrence_bubble_outline);
	                }
	            }

		     
		 });
	
		// https://android--code.blogspot.fr/2015/01/android-round-button.html
		
		//http://www.thecrazyprogrammer.com/2016/10/android-round-button-example.html
			// http://angrytools.com/android/button/
		
		// https://www.google.fr/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&ved=0ahUKEwi1laPU2O3SAhWqD8AKHWJGDpQQjxwIAw&url=http%3A%2F%2Fwww.viralandroid.com%2F2016%2F01%2Fcircular-button-with-icon-and-text-in-android.html&psig=AFQjCNFLsxrqCrDEP1hsG30J3y5AXBMr8Q&ust=1490395128310101&cad=rjt

        
        
     // http://trickyandroid.com/simple-ripple-reveal-elevation-tutorial/
		

		
		 //https://assist-software.net/snippets/android-button-place-image-center-and-text-bottom
		 
		 //http://www.androidhub4you.com/2014/10/android-custom-shape-imageview-rounded.html
		 
		 //https://android--examples.blogspot.fr/2015/05/how-to-use-framelayout-in-android.html
		 
		 //http://www.android-examples.com/create-round-oval-shape-button-in-android-xml/
		 
		 
//		 http://stackoverflow.com/questions/21178193/android-draw-circle-with-text-inside
		 
		 //http://stackoverflow.com/questions/16867815/android-official-alarm-clock-week-style
		 
		 // http://trickyandroid.com/simple-ripple-reveal-elevation-tutorial/
		 
		 
		 
		 
			 
	}
	
	
	
	
	

}
