package com.androidbegin.buttonclicktutorial;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DialogFragment;
import android.app.ActionBar.LayoutParams;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.ScrollView;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import android.widget.CompoundButton;

public class infos_repeat02 extends Activity 
{
	
		TextView txt_id;
		private EditText txtjbt, txttelefon, txtemel;
		String sid, telno,email,name;

		private SimpleCursorAdapter dataAdapter;
		
		static int TAG_TITRE = 5250;
		static int TAG_TIME = 5251;
		static int TAG_SWITCH = 5252;
		static int TAG_RINGTONE = 5253;
		static int TAG_VIBRATE = 5254;
		
		
		
		static int TAG_RG_OPT = 1234;
		
		static int TAG_OPT1 = 5260;
		static int TAG_OPT2 = 5261;
		static int TAG_OPT3 = 5262;
		
		static int TAG_CHK1 = 5265;
		static int TAG_CHK2 = 5266;
		static int TAG_CHK3 = 5267;
		
		 CheckBox un, deux, trois;
		
		
		static int TAG_SPN1 = 5270;
		static int TAG_SPN2 = 5271;
		static int TAG_SP3 = 5272;
		
		static int TAG_BTN_DELETE = 1;
		static int TAG_BTN_EXIT = 2;
		
		
		long repeat_id; 
		String repeat_titre; 
		long repeat_time;
		String repeat_days;
		String repeat_interval;
		String repeat_active;
		String repeat_vibrate;
		String repeat_ringtone;
		long repeat_created_time;
		long repeat_modified_time;
		
		
		DB_alarm db;
	
		@Override
		public void onCreate(Bundle savedInstanceState) 
		{
				super.onCreate(savedInstanceState);
				//setContentView(R.layout.infos_repeat_layout);
	
				db = new DB_alarm(getApplicationContext());
				
				ActionBar actionBar = getActionBar();
		        getActionBar().setHomeButtonEnabled(true);
		        getActionBar().setDisplayHomeAsUpEnabled(true);
		        setTitle("Infos repeatxxxxx");
		        
		        int indice = getIntent().getExtras().getInt("indice");
		        indice = indice + 1;
		        
		        //txt_id =(TextView) findViewById(R.id.txt_id);
		        //txt_id.setText(Integer.toString(indice));
		        
		        loadDB(Integer.toString(indice));
		        
		        layout();
		        

		        
/*		        
		        Button btn_quitter = (Button) findViewById(R.id.btn_exit);
		        btn_quitter.setOnClickListener(new OnClickListener() 
		 	    {
		 				@Override
		 				public void onClick(View arg0) 
		 				{
		 					finish();
		 				}
		 	    });
		        
		        Button btn_delete = (Button) findViewById(R.id.btn_delete);
		        btn_delete.setOnClickListener(new OnClickListener() 
		 	    {
		 				@Override
		 				public void onClick(View arg0) 
		 				{
							Toast.makeText(infos_repeat.this, "Delete repeat...", Toast.LENGTH_LONG).show();
							// arrêter le service et suppression de la database
							repeat_delete();
		 				}
		 	    });
*/		        
		}
		
//		@Override
//		protected void onResume() 
//		{
//			displayData();
//			super.onResume();
//		}
		
		
		private void loadDB(String sid)
		{
			
			String requete ="SELECT * FROM " + DB_alarm.TABLE_REPEAT  +" WHERE _id ='"+sid+"';";
			Cursor mCursor = db.DB_query(requete);
			int val = mCursor.getCount();
		    Log.i("**************** => ", String.valueOf(val));
		    
		    
		    
		    if (mCursor.moveToFirst()) 
			{
				do {
						
						repeat_id = mCursor.getInt(mCursor.getColumnIndex(DB_alarm.COLUMN_REPEAT_ID));
						repeat_titre = mCursor.getString(mCursor.getColumnIndex(DB_alarm.COLUMN_REPEAT_NAME));
						repeat_time = mCursor.getLong(mCursor.getColumnIndex(DB_alarm.COLUMN_REPEAT_TIME));
						repeat_days = mCursor.getString(mCursor.getColumnIndex(DB_alarm.COLUMN_REPEAT_DAYS));
						repeat_interval = mCursor.getString(mCursor.getColumnIndex(DB_alarm.COLUMN_REPEAT_INTERVAL));
						repeat_active = mCursor.getString(mCursor.getColumnIndex(DB_alarm.COLUMN_REPEAT_ACTIVE));
						repeat_vibrate = mCursor.getString(mCursor.getColumnIndex(DB_alarm.COLUMN_REPEAT_VIBRATE));
						repeat_ringtone = mCursor.getString(mCursor.getColumnIndex(DB_alarm.COLUMN_REPEAT_RINGTONE));
						repeat_created_time = mCursor.getLong(mCursor.getColumnIndex(DB_alarm.COLUMN_REPEAT_CREATED_TIME));
						repeat_modified_time = mCursor.getLong(mCursor.getColumnIndex(DB_alarm.COLUMN_REPEAT_MODIFIED_TIME));
					
				} while (mCursor.moveToNext());
		    
				Toast.makeText(infos_repeat02.this, "Data loaded...", Toast.LENGTH_LONG).show();
		    
			}
			
			
		}
		

		/*****************************************************************************/
		
		public void repeat_delete()
	    {
	    	
								AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);

								alertDialogBuilder.setTitle("Confirmation");
				
								alertDialogBuilder
								.setMessage("Click yes to delete !")
								.setCancelable(false)
								.setPositiveButton("Yes",new DialogInterface.OnClickListener()
								{
									public void onClick(DialogInterface dialog,int id)
									{
										// supprimer de la database
										db.delete_repeat(sid);
										Intent cancelThis = new Intent(infos_repeat02.this, RepeatService.class);
				 						long indice = Long.parseLong(sid);   
										cancelThis.putExtra("ALARMID", indice );
										cancelThis.setAction(RepeatService.CANCEL);
										startService(cancelThis);
										
										
										
//		    		                    SimpleCursorAdapter adapter = (SimpleCursorAdapter) getListAdapter();
//										adapter.getCursor().requery();
//										adapter.notifyDataSetChanged();

										
										
										
										// retour à l'activity précédente
										finish();
										
									}
								})
								
								.setNegativeButton("No",new DialogInterface.OnClickListener()
								{
									public void onClick(DialogInterface dialog,int id)
									{
										dialog.cancel();
									}
								});

								AlertDialog alertDialog = alertDialogBuilder.create();
								alertDialog.show();
								
								//displayData();
	    }

		
		
		/*****************************************************************************/
		
		private LinearLayout createLayout(int iOrientation)
		{
					LinearLayout lay = new LinearLayout(this);		
					lay.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
					lay.setOrientation(iOrientation);
					return lay;
		}
		    
		    
		private void layout()
		{
		    	LinearLayout layMain = createLayout(LinearLayout.VERTICAL);  	
		 		layMain.setPadding(8, 8, 8, 8);
		 		
		 		ScrollView scrollView= new ScrollView(this);
		        LinearLayout mainLayout = new LinearLayout(this);
		        mainLayout.setOrientation(LinearLayout.VERTICAL);               
		        
		        /******************** Image *************************/    

		        LinearLayout ll = new LinearLayout(this);
		        ll.setOrientation(LinearLayout.VERTICAL);
		 		ImageView imageView = new ImageView(this);
		 		imageView.setImageResource(R.drawable.clock);
		 		LayoutParams layoutParams=new LayoutParams(75, 75);
		 	    layoutParams.setMargins(10,10,0,0);
		 	    imageView.setLayoutParams(layoutParams);
		 	    ll.addView(imageView);
		        mainLayout.addView(ll);
		        
		        /******************** Titre *************************/    
		        
		        ll = new LinearLayout(this);
		        ll.setOrientation(LinearLayout.HORIZONTAL);
		        ll.setTag(1); 
		        TextView tv_titre = new TextView(this);
		        tv_titre.setText("Evenement");
		        tv_titre.setPadding(10, 10, 0, 0);
		 	    ll.addView(tv_titre);
		        mainLayout.addView(ll);
		        
		 		ll = new LinearLayout(this);
		        ll.setOrientation(LinearLayout.VERTICAL);
		        final EditText editText = new EditText(this);
		        editText.setEnabled(false);
		        editText.setId(150);
		        editText.setText(repeat_titre);
		        layoutParams=new LayoutParams(450, 75);
		        editText.setLayoutParams(layoutParams);
		        editText.setSingleLine(true);
		        editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(20) });
		 	    ll.addView(editText);
		        mainLayout.addView(ll);
		        
		        /******************** Time *************************/    
		        
		    	ll = new LinearLayout(this);
		        ll.setOrientation(LinearLayout.VERTICAL);
		        TextView tv_time = new TextView(this);
		        tv_time.setId(TAG_TIME); 
		        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		        //SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
		        Date netDate = (new Date(repeat_time));
		        String stime =  sdf.format(netDate);
		        String tmp = "Time : " +  stime;     //"-- : --";
		        tv_time.setText(tmp);
		        tv_time.setPadding(10, 30, 0, 30);
		 	    ll.addView(tv_time);
		        mainLayout.addView(ll);

		        /******************** ACTIVE repeat *************************/    
		        
		        ll = new LinearLayout(this);
		        ll.setOrientation(LinearLayout.HORIZONTAL);
		        Switch sw_active = new Switch(this);
		        sw_active.setId(TAG_SWITCH);
		        sw_active.setPadding(10, 10, 0, 0);
		        sw_active.setEnabled(false);
		        sw_active.setText("Active:");
		        sw_active.setTextOn("On"); 
		        sw_active.setTextOff("Off");
		        ll.addView(sw_active);
		        mainLayout.addView(ll);
		        
		        
		        if(repeat_active.equals("active") )
		        {
		        	sw_active.setChecked(true);
		        }
		        else
		        {
		        	sw_active.setChecked(false);
		        }
		        
		        //simpleSwitch2.isChecked()
		        
		        /******************** Radiogroup des options *************************/ 
		        
		        //http://www.android-examples.com/set-checkbox-align-right-side-of-textview-in-android/
		        
		        RadioGroup rg_opt = new RadioGroup(getApplicationContext());
		        rg_opt.setOrientation(RadioGroup.VERTICAL);
		        rg_opt.setPadding(10, 20, 0, 0);
		        rg_opt.setId(TAG_RG_OPT);
		        
		        RadioButton rb_opt1 = new RadioButton(getApplicationContext());
		        rb_opt1.setId(TAG_OPT1);
		        rb_opt1.setText("OPT1");
		        rb_opt1.setTextColor(Color.BLACK);
		        rb_opt1.setChecked(true); 		       // selection par défaut 
		        //rb_opt1.setEnabled(false);
		        rg_opt.addView(rb_opt1);
		        
		        RadioButton rb_opt2 = new RadioButton(getApplicationContext());
		        rb_opt2.setId(TAG_OPT2);
		        rb_opt2.setText("OPT2");
		        rb_opt2.setTextColor(Color.BLACK);
		        //rb_opt2.setEnabled(false);
		        rg_opt.addView(rb_opt2);
		        
		        RadioButton rb_opt3 = new RadioButton(getApplicationContext());
		        rb_opt3.setId(TAG_OPT3);
		        rb_opt3.setText("OPT3");
		        rb_opt3.setTextColor(Color.BLACK);
		        //rb_opt2.setEnabled(false);
		        rg_opt.addView(rb_opt3);
		        
		        mainLayout.addView(rg_opt);
		        
		        /********************************************************************************************************************/
		        
		  
		        ll = new LinearLayout(this);
		        ll.setOrientation(LinearLayout.HORIZONTAL);
		      
		 	   	final TextView tv_interval_opt1 = new TextView(this);
		 	    tv_interval_opt1.setText("Interval1 : ");
		 	    tv_interval_opt1.setVisibility(View.VISIBLE); 
		 	    tv_interval_opt1.setPadding(10, 30, 0, 30);
			   	ll.addView(tv_interval_opt1);
		 	    
		 	    final Spinner Spinner_opt1 = new Spinner(this);  
		 	    Spinner_opt1.setId(TAG_SPN1);
		 	    Spinner_opt1.setPadding(30, 10, 0, 10);
		        layoutParams=new LayoutParams(125, 75);
		        layoutParams.width += 50;  //
		        Spinner_opt1.setLayoutParams(layoutParams);
		        
		        List<String> ArraySpinner_opt1 = new ArrayList<String>();
		        ArraySpinner_opt1.add("A");
		        ArraySpinner_opt1.add("B");
		        ArraySpinner_opt1.add("C");     
		        ArraySpinner_opt1.add("D");
		        
		        final ArrayAdapter<String> spinnerArrayAdapter_opt1 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ArraySpinner_opt1);
		        spinnerArrayAdapter_opt1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
		        Spinner_opt1.setAdapter(spinnerArrayAdapter_opt1);
		        Spinner_opt1.setVisibility(View.VISIBLE); 
		        ll.addView(Spinner_opt1);
		        mainLayout.addView(ll);
		        
		        
		        
		        List<String> ArraySpinner_opt2 = new ArrayList<String>();
		        ArraySpinner_opt2.add("xxxx");
		        ArraySpinner_opt2.add("YYYY");
		        ArraySpinner_opt2.add("0000");     
		        ArraySpinner_opt2.add("FFFF");
		        
		        final ArrayAdapter<String> spinnerArrayAdapter_opt2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ArraySpinner_opt2);
		        spinnerArrayAdapter_opt2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 


		        // https://openclassrooms.com/courses/creez-des-applications-pour-android/des-widgets-plus-avances-et-des-boites-de-dialogue
		        
		        List<String> ArraySpinner_opt3 = new ArrayList<String>();
		        ArraySpinner_opt3.add("TOP");
		        ArraySpinner_opt3.add("coco");
		        ArraySpinner_opt3.add("pipo");     
		        ArraySpinner_opt3.add("zorro");
		        
		        //final ListView listView = getListView();
		        //ArraySpinner_opt3.setChoiceMode(CHOICE_MODE_MULTIPLE);
		        
		        
		        final ArrayAdapter<String> spinnerArrayAdapter_opt3 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ArraySpinner_opt3);
		        spinnerArrayAdapter_opt3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
		        
		        
		        // http://navinsandroidtutorial.blogspot.fr/2012/09/spinner-view.html
		        //ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice,bond_films);  
		        
		        //https://trinitytuts.com/tips/multiselect-spinner-item-in-android/
		        //https://www.mkyong.com/android/android-spinner-drop-down-list-example/
		        
		        // http://simplyadvanced.net/blog/android-how-to-multiple-spinners-drop-down-list-view-to-app/
		        // https://www.javatpoint.com/android-spinner-example
		        // https://www.learn2crack.com/2013/12/android-spinner-dropdown-example.html
		        
		        // http://stackoverflow.com/questions/5015686/android-spinner-with-multiple-choice
		        // https://github.com/GunaseelanArumaikkannu/MultiSpinner
		        
		        //http://www.compiletimerror.com/2013/09/android-spinnersdropdownlist-tutorial.html
		        
		        // http://theopentutorials.com/tutorials/android/listview/android-multiple-selection-listview/

		        
		        //  https://trinitytuts.com/tips/multiselect-spinner-item-in-android/ Spinners Dropdownlist mutli select
		        
		        //https://github.com/wongk/MultiSelectSpinner
		        
	
		        /*******************************************************************************************************************/
		        
		        
		        // http://android-er.blogspot.fr/2013/11/example-of-viewswitcher.html
		        // http://www.techirsh.com/2012/12/how-to-use-viewswitcher-in-android-eclipse.html 

		        
		        // source https://github.com/wongk/MultiSelectSpinner
		        
		        //https://examples.javacodegeeks.com/android/core/app/fragment/android-fragments-example/
		        
		        ll = new LinearLayout(this);
		       	ll.setOrientation(LinearLayout.VERTICAL);
		        String[] strings = { "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche" };
		        final multiselectspinner01 mySpin = new multiselectspinner01(this);  
		        mySpin.setItems(strings);
		        mySpin.setPadding(30, 10, 0, 10);
		        layoutParams=new LayoutParams(125, 75);
		        layoutParams.width += 50;  //
		        mySpin.setLayoutParams(layoutParams);
		        mySpin.setVisibility(View.INVISIBLE); 
		        ll.addView(mySpin);
		        mainLayout.addView(ll);
		        
		        /*****************************************************/
		        
		        //http://stackoverflow.com/questions/14216762/selecting-one-checkbox-out-of-multiple-checkboxes-getting-user-selected-checkb
		        
		        ll = new LinearLayout(this);
		       	ll.setOrientation(LinearLayout.HORIZONTAL);
		        CheckBox checkBox1 = new CheckBox(this); 
		        checkBox1.setId(TAG_CHK1);
		        checkBox1.setChecked(true); 		       // selection par défaut 
		        checkBox1.setPadding(30, 10, 0, 0);
		    	ll.addView(checkBox1);
		    	//TextView tv_one = new TextView(this);
		    	//tv_one.setPadding(70, 10, 0, 0);
		    	//tv_one.setText("Interval1 : ");
		    	//ll.addView(tv_one);
		    	final Spinner Spinner_opt4 = new Spinner(this);  
		 	    Spinner_opt4.setId(10000);
		 	    Spinner_opt4.setPadding(30, 10, 0, 10);
		        layoutParams=new LayoutParams(125, 75);
		        layoutParams.width += 50;  //
		        Spinner_opt4.setLayoutParams(layoutParams);
		        List<String> ArraySpinner_opt4 = new ArrayList<String>();
		        ArraySpinner_opt4.add("A");
		        ArraySpinner_opt4.add("B");
		        ArraySpinner_opt4.add("C");     
		        ArraySpinner_opt4.add("D");
		        final ArrayAdapter<String> spinnerArrayAdapter_opt4 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ArraySpinner_opt4);
		        spinnerArrayAdapter_opt4.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
		        Spinner_opt4.setAdapter(spinnerArrayAdapter_opt4);
		        Spinner_opt4.setVisibility(View.VISIBLE); 
		        ll.addView(Spinner_opt4);
		        mainLayout.addView(ll);
		    	
		    	
		        ////https://android--examples.blogspot.fr/2015/04/checkbox-in-android.html  +++++++
		        //// http://stackoverflow.com/questions/3795439/one-onclickhandler-for-multiple-buttons   ++++++
		        //// http://treeptik.fr/language/fr/un-onclicklistener-pour-les-gouverner-tous/    ++++++++
		        
		        ll = new LinearLayout(this);
		       	ll.setOrientation(LinearLayout.HORIZONTAL);
		        CheckBox checkBox2 = new CheckBox(this); 
		        checkBox2.setId(TAG_CHK2);
		        checkBox2.setPadding(30, 10, 0, 0);
		    	ll.addView(checkBox2);
		    	//TextView tv_two = new TextView(this);
		    	//tv_two.setPadding(70, 10, 0, 0);
		    	//tv_two.setText("Interval1 : ");
		    	//ll.addView(tv_two);
		    	final Spinner Spinner_opt5 = new Spinner(this);  
		 	    Spinner_opt5.setId(10100);
		 	    Spinner_opt5.setPadding(30, 10, 0, 10);
		        layoutParams=new LayoutParams(125, 75);
		        layoutParams.width += 50;  //
		        Spinner_opt5.setLayoutParams(layoutParams);
		        List<String> ArraySpinner_opt5 = new ArrayList<String>();
		        ArraySpinner_opt5.add("xxxA");
		        ArraySpinner_opt5.add("6+5B");
		        ArraySpinner_opt5.add("aqssdC");     
		        ArraySpinner_opt5.add("99888D");
		        final ArrayAdapter<String> spinnerArrayAdapter_opt5 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ArraySpinner_opt5);
		        spinnerArrayAdapter_opt5.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
		        Spinner_opt5.setAdapter(spinnerArrayAdapter_opt5);
		        Spinner_opt5.setVisibility(View.INVISIBLE); 
		        ll.addView(Spinner_opt5);
		        mainLayout.addView(ll);

		    	
		      
		        ll = new LinearLayout(this);
		       	ll.setOrientation(LinearLayout.HORIZONTAL);
		        CheckBox checkBox3 = new CheckBox(this); 
		        checkBox3.setId(TAG_CHK3);
		        checkBox3.setPadding(30, 10, 0, 0);
		    	ll.addView(checkBox3);
		    	//TextView tv_tree = new TextView(this);
		    	//tv_tree.setPadding(70, 10, 0, 0);
		    	//tv_tree.setText("Interval1 : ");
		    	//ll.addView(tv_tree);
		        String[] string_day = { "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche" };
		        final multiselectspinner01 mySpin02 = new multiselectspinner01(this);  
		        mySpin02.setItems(string_day);
		        mySpin02.setPadding(30, 10, 0, 10);
		        layoutParams=new LayoutParams(125, 75);
		        layoutParams.width += 50;  //
		        mySpin02.setLayoutParams(layoutParams);
		        mySpin02.setVisibility(View.INVISIBLE); 
		        ll.addView(mySpin02);
		        mainLayout.addView(ll);
		        
		    	
		    	
		    	/*
		    	final Spinner Spinner_opt6 = new Spinner(this);  
		 	    Spinner_opt6.setId(10200);
		 	    Spinner_opt6.setPadding(30, 10, 0, 10);
		        layoutParams=new LayoutParams(125, 75);
		        layoutParams.width += 50;  //
		        Spinner_opt6.setLayoutParams(layoutParams);
		        List<String> ArraySpinner_opt6 = new ArrayList<String>();
		        ArraySpinner_opt6.add("A");
		        ArraySpinner_opt6.add("B");
		        ArraySpinner_opt6.add("C");     
		        ArraySpinner_opt6.add("D");
		        final ArrayAdapter<String> spinnerArrayAdapter_opt6 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ArraySpinner_opt6);
		        spinnerArrayAdapter_opt6.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
		        Spinner_opt6.setAdapter(spinnerArrayAdapter_opt6);
		        Spinner_opt6.setVisibility(View.INVISIBLE); 
		        ll.addView(Spinner_opt6);
		        mainLayout.addView(ll);
		        */
		        
		        
		        /******************** Bouton *************************/        
		        
		        ll = new LinearLayout(this);
		       	ll.setOrientation(LinearLayout.VERTICAL);
		        /**/
		       	final View childView = getLayoutInflater().inflate(R.layout.weeks_button_layout, null);
		       	childView.setVisibility(View.GONE);
		        /**/
		        ll.addView(childView);
		        mainLayout.addView(ll);

		        
		        /******************** option alarme *************************/        
		 	    
		        final RadioGroup rg = new RadioGroup(getApplicationContext());
		        rg.setOrientation(RadioGroup.HORIZONTAL);
		        rg.setPadding(10, 20, 0, 0);
		        rg.setId(1234);
		        RadioButton rb_ringtone = new RadioButton(getApplicationContext());
		        rb_ringtone.setId(TAG_RINGTONE);
		        rb_ringtone.setText("Ringtone");
		        rb_ringtone.setTextColor(Color.BLACK);
		        rb_ringtone.setEnabled(false);
		        rg.addView(rb_ringtone);
		        RadioButton rb_vibrate = new RadioButton(getApplicationContext());
		        rb_vibrate.setId(TAG_VIBRATE);
		        rb_vibrate.setText("Vibrate");
		        rb_vibrate.setTextColor(Color.BLACK);
		        rb_vibrate.setEnabled(false);
		        rg.addView(rb_vibrate);
		        mainLayout.addView(rg);
		        
		        
		        if(repeat_ringtone.equals("ringtone"))
				{
					rb_ringtone.setChecked(true);
					rb_vibrate.setChecked(false);
				}
				if(repeat_ringtone.equals("noringtone"))
				{
					rb_ringtone.setChecked(false);
					rb_vibrate.setChecked(true);
				}
			
				if(repeat_vibrate.equals("vibrate"))
				{
			        rb_vibrate.setChecked(true);
					rb_ringtone.setChecked(false);
				}
				if(repeat_vibrate.equals("novibrate"))
				{
			        rb_vibrate.setChecked(false);
					rb_ringtone.setChecked(true);
				}

				
				/******************************************************/
				
				ll = new LinearLayout(this);
			    ll.setOrientation(LinearLayout.HORIZONTAL);
			    ll.setPadding(0, 30, 0, 0);
			    ll.setGravity(Gravity.CENTER);
			       
		        Button b1_test = new Button(this);
		        b1_test.setId(95);
		        b1_test.setText("Delete");
		        ll.addView(b1_test);
			        
		        Button b2_test = new Button(this);
		        b2_test.setId(96);
		        b2_test.setText("Exit");
			    ll.addView(b2_test);

			        mainLayout.addView(ll);
			        
				
		        
		        /******************** Bouton *************************/        
		        
		        ll = new LinearLayout(this);
		        ll.setOrientation(LinearLayout.HORIZONTAL);
		        ll.setPadding(0, 30, 0, 0);
		        ll.setGravity(Gravity.CENTER);
		       
		        Button b1 = new Button(this);
		        b1.setId(TAG_BTN_DELETE);
		        b1.setText("Delete");
		        ll.addView(b1);
		        
		        Button b2 = new Button(this);
		        b2.setId(TAG_BTN_EXIT);
		        b2.setText("Exit");
		        ll.addView(b2);

		        mainLayout.addView(ll);
		        
		        /******************** Appliquer le code dans la vue *************************/        
		        scrollView.addView(mainLayout);
		        layMain.addView(scrollView);
		        setContentView(layMain);

		        
		        //http://blog.cubeactive.com/onclicklistener-android-tutorial/
		        //https://anujarosha.wordpress.com/2011/11/13/how-to-implements-onclicklistener-for-a-view-item-in-android/
		        
		      
		      
		        
		        /******************** Listner *************************/      
		       		      
				Button btn_delete = (Button) findViewById(TAG_BTN_DELETE);
			    btn_delete.setOnClickListener(new OnClickListener() 
			 	{
			 				@Override
			 				public void onClick(View arg0) 
			 				{
								Toast.makeText(infos_repeat02.this, "Delete repeat...", Toast.LENGTH_LONG).show();
								// arrêter le service et suppression de la database
								//repeat_delete();
			 				}
			 	});
				
		        Button btn_quitter = (Button) findViewById(TAG_BTN_EXIT);
		        btn_quitter.setOnClickListener(new OnClickListener() 
		 	    {
		 				@Override
		 				public void onClick(View arg0) 
		 				{
		 					Toast.makeText(infos_repeat02.this, "Finish .......", Toast.LENGTH_LONG).show();
		 					List<String> selected = mySpin.getSelectedStrings();
		 					//finish();
		 				}
		 	    });
		        
		       
/*		        
		        RadioGroup radGrp = (RadioGroup) findViewById(TAG_RG_OPT);
		        int checkedRadioButtonID = radGrp.getCheckedRadioButtonId();
		        radGrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
		        {
				          public void onCheckedChanged(RadioGroup arg0, int id)
				          {
				        	  
				        	  Toast.makeText(infos_repeat.this, "xxxxxxx...", Toast.LENGTH_LONG).show();
				        	  
				        	  switch (id)
				        	  {*/
						           /* case TAG_OPT1:
						             
						              Toast.makeText(infos_repeat.this, "Delete repeat...", Toast.LENGTH_LONG).show();
						              break;
						            case TAG_OPT2:
						            	Toast.makeText(infos_repeat.this, "Delete repeat...", Toast.LENGTH_LONG).show();
						              break;
						            case TAG_OPT3:
						            	Toast.makeText(infos_repeat.this, "Delete repeat...", Toast.LENGTH_LONG).show();
						              break;*/
/*						           
				        	  }
				          }
		        });
		        
*/		        
		        
		        RadioGroup radioGroup = (RadioGroup) findViewById(TAG_RG_OPT);
		         
		        radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() 
		        {
		            @Override
		            public void onCheckedChanged(RadioGroup group, int checkedId) 
		            {
			                if(checkedId == TAG_OPT1)
			                {
			    		 	    tv_interval_opt1.setText("Interval1 : ");
			    		 	    Spinner_opt1.setAdapter(spinnerArrayAdapter_opt1);
			    		 	    childView.setVisibility(View.GONE);
			    		        mySpin.setVisibility(View.INVISIBLE); 
			                	tv_interval_opt1.setVisibility(View.VISIBLE);
			                	Spinner_opt1.setVisibility(View.VISIBLE); 
//			                	tv_interval_opt2.setVisibility(View.INVISIBLE);
//			                	Spinner_opt2.setVisibility(View.INVISIBLE); 
			                } 
			               if(checkedId == TAG_OPT2) 
			                {
			    		 	    tv_interval_opt1.setText("Interval2 : ");
			    		        Spinner_opt1.setAdapter(spinnerArrayAdapter_opt2);
			    		    	childView.setVisibility(View.GONE);
			    		        mySpin.setVisibility(View.INVISIBLE); 
			                	tv_interval_opt1.setVisibility(View.VISIBLE);
			                	Spinner_opt1.setVisibility(View.VISIBLE); 
//			                	tv_interval_opt2.setVisibility(View.VISIBLE);
//			                	Spinner_opt2.setVisibility(View.VISIBLE); 
			                } 
			               if(checkedId == TAG_OPT3) 
			                {
			    		 	    //tv_interval_opt1.setText("Interval3 : ");
			    		 	    //Spinner_opt1.setAdapter(spinnerArrayAdapter_opt3);
			    		 	    
			    		 	  	//childView.setVisibility(View.VISIBLE);
			    		        mySpin.setVisibility(View.VISIBLE); 

			    		 	    
			                	tv_interval_opt1.setVisibility(View.INVISIBLE);
			                	Spinner_opt1.setVisibility(View.INVISIBLE); 
			                	//tv_interval_opt2.setVisibility(View.INVISIBLE);
			                	//Spinner_opt2.setVisibility(View.INVISIBLE); 
			                }
		            }
		        });
		        
		        //https://suvendugiri.wordpress.com/2012/02/09/android-using-checkbox-with-example/
		        
		        //http://www.technotalkative.com/android-checkbox-example/
		        //http://pulse7.net/android/android-check-box-example/
		        //https://android--examples.blogspot.fr/2015/04/checkbox-in-android.html
		        // http://stackoverflow.com/questions/10673628/implementing-onclicklistener-for-dynamically-created-buttons-in-android
		        
		        // http://androidexample.com/Dynamically_Create_View_Elements__-_Android_Example/index.php?view=article_discription&aid=115
		        
		        // http://www.androidhub4you.com/2013/09/android-dynamic-check-box-example-check.html
		        
		        un =(CheckBox)findViewById(TAG_CHK1);
		        deux =(CheckBox)findViewById(TAG_CHK2);
		        trois =(CheckBox)findViewById(TAG_CHK3);

		        
		        un.setOnClickListener(new OnClickListener()
		        {
		             public void onClick(View v)
		             {
		            	 if(un.isChecked())
		            	 {
		            		  Spinner_opt4.setVisibility(View.VISIBLE); 
		            		  Spinner_opt5.setVisibility(View.INVISIBLE); 
		            		  mySpin02.setVisibility(View.INVISIBLE); 
		            		  deux.setChecked(false);
		            		  trois.setChecked(false);
		            	 }
		             }
		        });
		       
		        
		        deux.setOnClickListener(new OnClickListener()
		        {
		             public void onClick(View v)
		             {
		            	 if(deux.isChecked())
		            	 {
		            		  Spinner_opt4.setVisibility(View.INVISIBLE); 
		            		  Spinner_opt5.setVisibility(View.VISIBLE); 
		            		  mySpin02.setVisibility(View.INVISIBLE); 
		            		  un.setChecked(false);
		            		  trois.setChecked(false);
		            	 }
		             }
		        });
		        
		        trois.setOnClickListener(new OnClickListener()
		        {
		             public void onClick(View v)
		             {
		            	 if(trois.isChecked())
		            	 {
		            		  Spinner_opt4.setVisibility(View.INVISIBLE); 
		            		  Spinner_opt5.setVisibility(View.INVISIBLE); 
		            		  mySpin02.setVisibility(View.VISIBLE); 
		            		  un.setChecked(false);
		            		  deux.setChecked(false);
		            	 }
		             }
		        });
		        
		    
			       
		        
		       
		      
		       
		    	
		}
		
		
		
		
	   
				
		/*****************************************************************************/
		
		@Override
		public boolean onOptionsItemSelected(MenuItem item)
		{
		      switch (item.getItemId())
		      {
	
		      		case android.R.id.home:
			      			this.finish();
			      			return true;
				    
		      		default:
			          return super.onOptionsItemSelected(item);
			 }
		}

	
}
