package com.androidbegin.buttonclicktutorial;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import android.os.Bundle;
import android.text.InputFilter;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Scroller;
import android.widget.TextView;
import android.app.Activity;
import android.app.ActionBar.LayoutParams;

public class infos_appointment extends Activity 
{

	
	TimeWidgetSlider start_timeSliderHour = null;
	TimeWidgetSlider start_timeSliderMinutes = null;
	TimeWidgetSlider end_timeSliderHour = null;
	TimeWidgetSlider end_timeSliderMinutes = null;
	
	private Button btnStartTime = null;
	private Calendar dateStart = null;
	
	private String date_event;
	
    
    LinearLayout layout1;
    private static int viewsCount = 0;
    private List<View> allViews = new ArrayList<View>();
    LinearLayout.LayoutParams params;
    
    
	//fields
		private static String sStrSelect = "Select time";
		private static String sStrSet = "set";
		private static String sStrNone = "none";
		
		//fields
		public static final int SELECT_TIME_REQUEST = 112;
		public static final int iSliderViewWidth = 276;
		private static final int iSmallButtonWidth = 100;	
		
		//fields
		private LinearLayout layContent = null;
		private LinearLayout layContent2 = null;
		
		
		private Button btnNone = null;
		private Button btnOK = null;
		
		//fields
		private boolean bNoneButton = true;
		private boolean b24HourMode = false;
		private int start_hour = -1;
		private int start_minutes = -1;
		private int end_hour = -1;
		private int end_minutes = -1;
		
		 private RelativeLayout mLayout;
	
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.infos_appointment);
		//setContentView(R.layout.form02);
		
		//mLayout = (RelativeLayout)findViewById(R.id.left_event_column);
		
		//EditText et = (EditText) findViewById(R.id.Edit_Notes);
		
		//et.setScroller(new Scroller(getApplicationContext()));
        //et.setVerticalScrollBarEnabled(true);
		
		  
		Bundle extras = getIntent().getExtras();
		int index = extras.getInt("index");
		
		appointment class_id = new appointment();
		class_id = agenda02.appointment_liste.get(index);
		
		class_id.getTitre();
		
		
	   setContentView(widget());
	    
	 //  LinearLayout mLinear = (LinearLayout) findViewById(R.id.child_linear);
	 //  View childView = getLayoutInflater().inflate(R.layout.form04, null);
     //   mLinear.addView(childView); 
		   
		 
		   
		   // inflate
		   
		
	/*	
	 	 TextView tv=(TextView)findViewById(R.id.et_nom);
     	 tv.setOnFocusChangeListener( new View.OnFocusChangeListener()
     	 {
     		 
     		 public void onFocusChange( View view, boolean hasfocus){
   				      if(hasfocus)
   				      {
   					
   					         view.setBackgroundResource( R.drawable.focus_border_style);
   				         }
   				      else{
   					         view.setBackgroundResource( R.drawable.lost_focus_style);
   				         }
   			      }
     	 });
     */	 
      
		
		/*
		et_nom = (EditText) findViewById(R.id.et_nom);
		et_nom.setText(extras.getString("nom"));
			
		et_prenom = (EditText) findViewById(R.id.et_prenom);
		et_prenom.setText(extras.getString("prenom"));
			
		et_adresse = (EditText) findViewById(R.id.et_adresse);
		et_adresse.setText(extras.getString("adresse"));
			
		et_email = (EditText) findViewById(R.id.et_email);
		et_email.setText(extras.getString("email"));
			
		et_portable = (EditText) findViewById(R.id.et_portable);
		et_portable.setText(extras.getString("portable"));		
			
		et_fixe = (EditText) findViewById(R.id.et_fixe);
		et_fixe.setText(extras.getString("fixe"));
		*/	
			
			
	}
	
	private void display()
    {
		
		 RelativeLayout.LayoutParams lParam = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
	     lParam.addRule(RelativeLayout.ALIGN_PARENT_TOP);
	     lParam.topMargin = 50;
	     lParam.leftMargin = 24;
	    
	     start_timeSliderHour = new TimeWidgetSlider(this, true, TimeWidgetSlider.STYPE_HOURS, iSliderViewWidth); // 24 heures 
		 start_timeSliderMinutes = new TimeWidgetSlider(this, b24HourMode, TimeWidgetSlider.STYPE_MINUTES, iSliderViewWidth);

		 end_timeSliderHour = new TimeWidgetSlider(this, true, TimeWidgetSlider.STYPE_HOURS, iSliderViewWidth); // 24 heures 
		 end_timeSliderMinutes = new TimeWidgetSlider(this, b24HourMode, TimeWidgetSlider.STYPE_MINUTES, iSliderViewWidth);

			
		 mLayout.addView(start_timeSliderHour);
		 //mLayout.addView(start_timeSliderMinutes);
		 //mLayout.setPadding(100, 0, 0, 60);
	        //layMain.addView(layContent);
    }
    
	
	public LinearLayout createLayout(int Orientation)
	  {
			LinearLayout lay = new LinearLayout(this);		
			lay.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
			lay.setOrientation(Orientation);
			return lay;
	  }
	
	public View widget()
	{
		
	 		LinearLayout layMain = createLayout(LinearLayout.VERTICAL);  	
	 		layMain.setPadding(8, 8, 8, 8);

	 		LinearLayout layMargin = createLayout(LinearLayout.HORIZONTAL);
	 		LinearLayout layMargin2 = createLayout(LinearLayout.HORIZONTAL);
	 		
	 		layContent = createLayout(LinearLayout.VERTICAL);
	 		layContent2 = createLayout(LinearLayout.VERTICAL);

	 		layMargin.getLayoutParams().height = 18;
	 		layMargin2.getLayoutParams().height = 18;
			
	 		
	 	/*	RelativeLayout.LayoutParams imageViewParam = new RelativeLayout.LayoutParams(
	                RelativeLayout.LayoutParams.WRAP_CONTENT,
	                RelativeLayout.LayoutParams.WRAP_CONTENT);
	 	*/	
	 		ImageView imageView = new ImageView(this);
	 		imageView.setImageResource(R.drawable.appointment);
	 		//imageView.setGravity( Gravity.CENTER);  
	 		//imageView.setLeft(left);  
	 		//imageView.setX(10);
	 		//imageViewParam.addRule(RelativeLayout.ALIGN_LEFT);
	 		//imageView.setPadding(20,20,20,20);


	 		imageView.setX(20);
	 		imageView.setY(175);


	 		
	 		
	 		layMain.addView(imageView);
	 		
	        TextView tv = new TextView(this);
	        tv.setText("Edfqffdvenement");
	        tv.setPadding(10, 0, 0, 0);
	        layMain.addView(tv);
	        
	        final EditText editText = new EditText(this);
	        editText.setHint("XXXXT85itre");
	        editText.setSingleLine(true);
	        layMain.addView(editText);
	        
	        tv = new TextView(this);
	        String tmp = "Date : " + date_event;
	        tv.setText(tmp);
	        tv.setPadding(10, 30, 0, 30);
	        layMain.addView(tv);
			
	        tv = new TextView(this);
	        tv.setText("Start Time");
	        tv.setPadding(10, 10, 0, 30);
	        layMain.addView(tv);
	        
	        
			start_timeSliderHour = new TimeWidgetSlider(this, true, TimeWidgetSlider.STYPE_HOURS, iSliderViewWidth); // 24 heures 
			start_timeSliderMinutes = new TimeWidgetSlider(this, b24HourMode, TimeWidgetSlider.STYPE_MINUTES, iSliderViewWidth);

			end_timeSliderHour = new TimeWidgetSlider(this, true, TimeWidgetSlider.STYPE_HOURS, iSliderViewWidth); // 24 heures 
			end_timeSliderMinutes = new TimeWidgetSlider(this, b24HourMode, TimeWidgetSlider.STYPE_MINUTES, iSliderViewWidth);

			
			layContent.addView(start_timeSliderHour);
			layContent.addView(layMargin);
			layContent.addView(start_timeSliderMinutes);
	        layContent.setPadding(100, 0, 0, 60);
	        layMain.addView(layContent);
	        
	        tv = new TextView(this);
	        tv.setText("End Time");
	        tv.setPadding(10, 10, 0, 30);
	        layMain.addView(tv);
	        
	        
	        layContent2.addView(end_timeSliderHour);
		 	layContent2.addView(layMargin2);
			layContent2.addView(end_timeSliderMinutes);
	        layContent2.setPadding(100, 0, 0, 60);
	        layMain.addView(layContent2);
		        
         
	        Button btn = new Button(this);
	        btn.setText("Ajouter");
	        layMain.addView(btn);
	        
	       
	      	btn.setOnClickListener(new Button.OnClickListener()
		  	{
					public void onClick(View arg0)
					{
						start_hour = start_timeSliderHour.getValue();
					  	start_minutes = start_timeSliderMinutes.getValue();
					  	end_hour = end_timeSliderHour.getValue();
					  	end_minutes = end_timeSliderMinutes.getValue();
					  	
					  	// creation des dates
					  	
					  	String[] items = date_event.split(" ");
					  	// jour mois annee
					  	int jour = Integer.parseInt(items[0]);
					  	int mois = Integer.parseInt(items[1]);
					  	int annee = Integer.parseInt(items[2]);
					  	mois = mois - 1;
					  	
						Calendar cal_date = Calendar.getInstance();
						cal_date.set(Calendar.YEAR, annee);
						cal_date.set(Calendar.DAY_OF_MONTH, jour);
						cal_date.set(Calendar.MONTH, mois);
						cal_date.set(Calendar.HOUR_OF_DAY, 0);
						cal_date.set(Calendar.MINUTE, 0);
						cal_date.set(Calendar.SECOND, 0);
						cal_date.set(Calendar.MILLISECOND, 0);
				        Date Date_date =  cal_date.getTime();
				        long date = cal_date.getTimeInMillis();
					  			
					  	Calendar cal_start = Calendar.getInstance();
				        cal_start.set(annee,mois,jour,start_hour, start_minutes);
				        cal_start.set(Calendar.SECOND, 0);
				        cal_start.set(Calendar.MILLISECOND, 0);
				        Date Date_start =  cal_start.getTime();
				        long startTime = cal_start.getTimeInMillis();
				        
				    	Calendar cal_end = Calendar.getInstance();
				        cal_end.set(annee,mois,jour, end_hour, end_minutes);
				        cal_end.set(Calendar.SECOND, 0);
				        cal_end.set(Calendar.MILLISECOND, 0);
				        Date Date_end =  cal_end.getTime();
				        long endTime = cal_end.getTimeInMillis();
				        
				        String titre = editText.getText().toString();
				        
					  	
						
			}});
		  	
	  	

	  	return layMain;
		
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}