package com.example.appli_calendar05;


import android.app.ActionBar.LayoutParams;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
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.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class AddEvent extends Activity 
{
	
	private EditText txt_id, txt_name, txt_from_date, txt_to_date, txt_datetime, txt_status, txt_created_time, txt_modified_time, txt_rule, txt_interval, txt_sound, txt_created_at;
	private EditText txt_info;
	
	private CheckBox chk1,chk2;
	private Button btn_update_alarm;  
	
	DB_calendar db;
	
	final String EXTRA_POSITION = "extra_position";
	final String EXTRA_ID = "extra_id";
	
	String id_alarm = "";
		
	Button  button1, button2, button3, button20;
	
	Drawable back;
	int flag = 0;
	
	boolean isPressed = false;

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

	}
	
	void test()
	{
			
			button3 = (Button) findViewById(R.id.btn3);
			button2 = (Button) findViewById(R.id.btn2);

			
		    //createCalender();
		    //dynamique();
			
//			setContentView(R.layout.add_event_view);

			
			/***********  OK  *********/
			
		    back = button2 .getBackground();
			button2.setOnClickListener(new OnClickListener()
			{

	            @SuppressLint("NewApi")
				@Override
	            public void onClick(View v) {   
	                if(flag==0){
	                	button2.setBackgroundResource(R.drawable.ic_launcher);
	                    flag=1;
	                    }
	                else{
	                    flag=0;
	                    button2.setBackground(back);
	                }
	            }
	        });		
			
			
			/*********************OK ********************/
			button3.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
		                        button3.setPressed(isPressed);
			                }

			                return true;
			            }
			});
			

			
		
			/*************** OK ***************************/
			
		
			button1 = (Button) findViewById(R.id.btn1);
			
			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;
			    }
			});
			
			
			button20 = (Button) findViewById(R.id.btn20);
			
			button20.setTag(false);
			button20.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.setOnClickListener(new OnClickListener() {

			    @Override
			    public void onClick(View v)
			    {
			         //v.setBackgroundColor(Color.RED );
					button1.setPressed(true);
					  v.setSelected(true);
					  

			    }
			});
	        */
			
	/*		
			button1 = (Button) findViewById(R.id.button1);
			button1.setOnTouchListener(new OnTouchListener() {
				@Override
				public boolean onTouch(View v, MotionEvent event) {
					// TODO Auto-generated method stub
					button1.setPressed(true);

					return false;
				}
	        });
	*/	
	}
	

public void createCalenderXXXX()
{
    RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams
    (
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT
    );  
    LinearLayout layoutVertical = (LinearLayout) findViewById(R.id.liVLayout);
    LinearLayout rowLayout=null;
    Button[][] buttons = new Button[6][7]; 
    int count=43;
    for (int i = 0; i<6; i++) 
    {
        if(count%7==1)
        {
            rowLayout = new LinearLayout(this);
            layoutVertical.addView(rowLayout,p);
            count=count-7;
        }
        for(int j=0;j<7;j++)
        {
            buttons[i][j]=new Button(this);
            //buttons[i][j].setBackgroundResource(R.drawable.icon); 
            rowLayout.addView(buttons[i][j], p);
        }
    }
	
}
	 		

public void createCalender()
{  
    LinearLayout layoutVertical = (LinearLayout) findViewById(R.id.liVLayout);
    LinearLayout rowLayout=null;
    Button[][] buttons = new Button[6][7]; 
    int count=43;
    
    
   // LayoutParams param = new LinearLayout.LayoutParams(
   //         LayoutParams.FILL_PARENT,
   //         LayoutParams.FILL_PARENT,1);
    
    android.widget.LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT,1);

    for (int i = 0; i<6; i++) 
    {
        if(count%7==1)
        {
            rowLayout = new LinearLayout(this);
            rowLayout.setWeightSum(7);
            layoutVertical.addView(rowLayout,param);
            count=count-7;
        }
        for(int j=0;j<7;j++)
        {
            buttons[i][j]=new Button(this);
            //buttons[i][j].setBackgroundResource(R.drawable.icon);
            rowLayout.addView(buttons[i][j],param);
        }
    }
}

		public void dynamique()
		{

			LinearLayout lm = (LinearLayout) findViewById(R.id.liVLayout);

			// create the layout params that will be used to define how your
			// button will be displayed
			LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
 
			for(int j=0;j<=4;j++) 
			{   
				// Create LinearLayout
				LinearLayout ll = new LinearLayout(this);
				ll.setOrientation(LinearLayout.HORIZONTAL);
     
				// Create TextView
				TextView product = new TextView(this);
				product.setText(" Product"+j+"    ");
				ll.addView(product);
     
				// Create TextView
				TextView price = new TextView(this);
				price.setText("  $"+j+"     ");
				ll.addView(price);
     
				// Create Button
				Button btn = new Button(this);
				// Give button an ID
				btn.setId(j+1);
				btn.setText("Add To Cart");
				// set the layoutParams on the button
				btn.setLayoutParams(params);
         
				final int index = j;
				// Set click listener for button
				btn.setOnClickListener(new OnClickListener() 
				{
					public void onClick(View v)
					{
                       Log.i("TAG", "index :" + index);
                       Toast.makeText(getApplicationContext(), "Clicked Button Index :" + index, Toast.LENGTH_LONG).show();
					}
				});
         
				//Add button to LinearLayout
				ll.addView(btn);
				//	Add button to LinearLayout defined in XML
				lm.addView(ll);  
}
}

}
