package com.example.url04;


import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ProgressBar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Toast;
import android.widget.ArrayAdapter;
import android.widget.ListView;


//http://www.viralandroid.com/2015/11/android-seekbar-example.html

public class essai extends Activity {

 private TextView switchStatus;
 private Switch mySwitch;
 private Spinner spinner1, spinner2;
 private Button btnSubmit;
 
 String[] prenoms = new String[]{
         "Antoine", "Benoit", "Cyril", "David", "Eloise", "Florent",
         "Gerard", "Hugo", "Ingrid", "Jonathan", "Kevin", "Logan",
         "Mathieu", "Noemie", "Olivia", "Philippe", "Quentin", "Romain",
         "Sophie", "Tristan", "Ulric", "Vincent", "Willy", "Xavier",
         "Yann", "Zoé"
    };
 
 SeekBar seekBar;
 TextView textView;
 ListView mListView;

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

  switchStatus = (TextView) findViewById(R.id.switchStatus);
  mySwitch = (Switch) findViewById(R.id.mySwitch);
  
  addItemsOnSpinner2();
	addListenerOnButton();
	addListenerOnSpinnerItemSelection();
	
	
	 mListView = (ListView) findViewById(R.id.list);
	 
	 ArrayAdapter<String> adapter = new ArrayAdapter<String>(essai.this,
		        android.R.layout.simple_list_item_1, prenoms);
		        mListView.setAdapter(adapter);
	

  /************ SeekBar **************/
  
  seekBar = (SeekBar) findViewById(R.id.seekBar);
  textView = (TextView) findViewById(R.id.count);

  seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() 
  {
      int seekBarProgress = 0;

      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
          seekBarProgress = progress;
          Toast.makeText(getApplicationContext(),"SeekBar Progress Change",Toast.LENGTH_SHORT).show();
      }

      public void onStartTrackingTouch(SeekBar seekBar) {
          Toast.makeText(getApplicationContext(),"SeekBar Touch Started",Toast.LENGTH_SHORT).show();
      }

      public void onStopTrackingTouch(SeekBar seekBar) {
          textView.setText("Progress: " + seekBarProgress + " / " + seekBar.getMax());
                  Toast.makeText(getApplicationContext(), "SeekBar Touch Stop ", Toast.LENGTH_SHORT).show();
      }

  });
  
  /********** switch ****************/
    
  //set the switch to ON 
  mySwitch.setChecked(true);
  //attach a listener to check for changes in state
  mySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

   @Override
   public void onCheckedChanged(CompoundButton buttonView,
     boolean isChecked) {

    if(isChecked){
     switchStatus.setText("Switch is currently ON");
    }else{
     switchStatus.setText("Switch is currently OFF");
    }

   }
  });
  
  //check the current state before we display the screen
  if(mySwitch.isChecked()){
   switchStatus.setText("Switch is currently ON");
  }
  else {
   switchStatus.setText("Switch is currently OFF");
  }
 }

 /**************** checkbox  *****************/
 
 public void androidCheckBoxClicked(View view) {
     // action for checkbox click
     switch (view.getId()) {
         case R.id.checkBox:
             //DO something when user check the box
        	 Toast.makeText(getApplicationContext(), "SeekBar Touch Stop ", Toast.LENGTH_SHORT).show();
             break;
         case R.id.checkBox2:
             //DO something when user check the box
             break;
         case R.id.checkBox3:
             //DO something when user check the box
             break;
         case R.id.checkBox4:
             //DO something when user check the box
             break;
         case R.id.checkBox5:
             //DO something when user check the box
             break;
         case R.id.checkBox6:
             //DO something when user check the box
             break;
         case R.id.checkBox7:
             //DO something when user check the box
             break;
         case R.id.checkBox8:
             //DO something when user check the box
             break;
         case R.id.checkBox9:
             //DO something when user check the box
             break;
     }
 }

 
 /****************radio *****************/
 public void radioButtonClicked(View view) {
     boolean checked = ((RadioButton) view).isChecked();
     // This check which radio button was clicked
     switch (view.getId()) {
         case R.id.radioButton1:
             if (checked)
                 //Do something when radio button is clicked
                 Toast.makeText(getApplicationContext(), "It seems like you feeal RelativeLayout easy", Toast.LENGTH_SHORT).show();
             break;

         case R.id.radioButton2:
             //Do something when radio button is clicked
             Toast.makeText(getApplicationContext(), "It seems like you feel LinearLayout easy", Toast.LENGTH_SHORT).show();
             break;

         case R.id.radioButton3:
             //Do something when radio button is clicked
             Toast.makeText(getApplicationContext(), "It seems like you feel FrameLayout easy", Toast.LENGTH_SHORT).show();
             break;

         case R.id.radioButton4:
             //Do something when radio button is clicked
             Toast.makeText(getApplicationContext(), "It seems like you feel TablleLayout easy", Toast.LENGTH_SHORT).show();
             break;

         case R.id.radioButton5:
             //Do something when radio button is clicked
             Toast.makeText(getApplicationContext(), "It seems like you feel GridLayout easy", Toast.LENGTH_SHORT).show();
             break;
     }
 }
 
 /*********************************/
 
 public void addItemsOnSpinner2() {

	spinner2 = (Spinner) findViewById(R.id.spinner2);
	List<String> list = new ArrayList<String>();
	list.add("list 1");
	list.add("list 2");
	list.add("list 3");
	ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
		android.R.layout.simple_spinner_item, list);
	dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	spinner2.setAdapter(dataAdapter);
 }

 public void addListenerOnSpinnerItemSelection() {
	spinner1 = (Spinner) findViewById(R.id.spinner1);
	spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener());
 }

 // get the selected dropdown list value
 public void addListenerOnButton() {

	spinner1 = (Spinner) findViewById(R.id.spinner1);
	spinner2 = (Spinner) findViewById(R.id.spinner2);
	btnSubmit = (Button) findViewById(R.id.btnSubmit);

	/*btnSubmit.setOnClickListener(new OnClickListener() {

	  @Override
	  public void onClick(View v) {

	    Toast.makeText(essai.this,
		"OnClickListener : " + 
               "\nSpinner 1 : "+ String.valueOf(spinner1.getSelectedItem()) + 
               "\nSpinner 2 : "+ String.valueOf(spinner2.getSelectedItem()),
			Toast.LENGTH_SHORT).show();
	  }

	});*/
 }
 
 /**********************************/
 

}



class CustomOnItemSelectedListener implements OnItemSelectedListener {

	  public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
		Toast.makeText(parent.getContext(), 
			"OnItemSelectedListener : " + parent.getItemAtPosition(pos).toString(),
			Toast.LENGTH_SHORT).show();
	  }

	  @Override
	  public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub
	  }

	}