package it.unimi.di.laren.smartwash.View;

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

import it.unimi.di.laren.smartwash.R;
import it.unimi.di.laren.smartwash.Controller.Play_Controller;
import it.unimi.di.laren.smartwash.Model.SpinnerItem;
import it.unimi.di.laren.smartwash.Model.SpinnerItemAdapter;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;


public class PlayActivity extends Activity {
	
	public Spinner spinner;
	public Spinner spinner1;
	public Spinner spinner2;
	public Spinner spinner3;
	public Button random;
	public Button go;
	public int[] selezione = new int[4];
	public List<SpinnerItem> items;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_play);
		random = (Button)findViewById(R.id.RandBtn);
		go = (Button)findViewById(R.id.GoBtn);
		selezione[0] = 0;
		selezione[1] = 0;
		selezione[2] = 0;
		selezione[3] = 0;
		for(int i = 0; i<selezione.length; i++){
			Log.i("Selex item",": "+selezione[i]);
		}
		Log.i("Selex",": "+selezione);
				//dati spinner
				items = new ArrayList<SpinnerItem>();
				items.add(new SpinnerItem(getString(R.string.tipo_vestito), R.drawable.clothes));
				items.add(new SpinnerItem(getString(R.string.cotone), R.drawable.cotton));
				items.add(new SpinnerItem(getString(R.string.lana), R.drawable.wool));
				items.add(new SpinnerItem(getString(R.string.sintetico), R.drawable.synthetic));
				
				spinner = (Spinner) findViewById(R.id.spinner);
				spinner.setAdapter(new SpinnerItemAdapter(this,items));
				spinner.setOnItemSelectedListener(new OnItemSelectedListener() 
				{
					public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id)
					{
						selezione[0] = position;
	  			  	//Toast.makeText(adapterView.getContext(), "selezione: " + selezione.get(0).toString() + ", " + selezione.get(1).toString() + ", " + selezione.get(2).toString() + ", " + selezione.get(3).toString(), Toast.LENGTH_SHORT).show();
						for(int i = 0; i<selezione.length; i++){
							Log.i("Selex item",": "+selezione[i]);
						}
					}

					public void onNothingSelected(AdapterView<?> adapterView)
					{
						//nothing				
					}
				});
				
				
				//dati spinner 1
				List<SpinnerItem> items1 = new ArrayList<SpinnerItem>();
				items1.add(new SpinnerItem(getString(R.string.tipo_colore), R.drawable.color));
				items1.add(new SpinnerItem(getString(R.string.bianco), R.drawable.tshirt));
				items1.add(new SpinnerItem(getString(R.string.pococolore), R.drawable.littlecolor));
				items1.add(new SpinnerItem(getString(R.string.colorati), R.drawable.fullcolor));
				
				spinner1 = (Spinner) findViewById(R.id.spinner1);
				spinner1.setAdapter(new SpinnerItemAdapter(this,items1));
				spinner1.setOnItemSelectedListener(new OnItemSelectedListener() 
				{
					public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id)
					{
						selezione[1] = position;
						//Toast.makeText(adapterView.getContext(), "selezione: " + selezione.get(0).toString() + ", " + selezione.get(1).toString() + ", " + selezione.get(2).toString() + ", " + selezione.get(3).toString(), Toast.LENGTH_SHORT).show();
						for(int i = 0; i<selezione.length; i++){
							Log.i("Selex item",": "+selezione[i]);
						}
					}

					public void onNothingSelected(AdapterView<?> adapterView)
					{
						//nothing				
					}
				});
				
				//dati spinner 2
				List<SpinnerItem> items2 = new ArrayList<SpinnerItem>();
				items2.add(new SpinnerItem(getString(R.string.tipo_sporco), R.drawable.dirty));
				items2.add(new SpinnerItem(getString(R.string.poco_sporco), R.drawable.littledirty));
				items2.add(new SpinnerItem(getString(R.string.medio_sporco), R.drawable.mediumdirty));
				items2.add(new SpinnerItem(getString(R.string.tanto_sporco), R.drawable.fulldirty));
				
				spinner2 = (Spinner) findViewById(R.id.spinner2);
				spinner2.setAdapter(new SpinnerItemAdapter(this,items2));
				spinner2.setOnItemSelectedListener(new OnItemSelectedListener() 
				{
					public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id)
					{
						selezione[2] = position;
						//Toast.makeText(adapterView.getContext(), "selezione: " + selezione.get(0).toString() + ", " + selezione.get(1).toString() + ", " + selezione.get(2).toString() + ", " + selezione.get(3).toString(), Toast.LENGTH_SHORT).show();
						for(int i = 0; i<selezione.length; i++){
							Log.i("Selex item",": "+selezione[i]);
						}
					}

					public void onNothingSelected(AdapterView<?> adapterView)
					{
						//nothing				
					}
				});
				//dati spinner 3
				List<SpinnerItem> items3 = new ArrayList<SpinnerItem>();
				items3.add(new SpinnerItem(getString(R.string.tipo_peso), R.drawable.weight));
				items3.add(new SpinnerItem(getString(R.string.tre), R.drawable.trekg));
				items3.add(new SpinnerItem(getString(R.string.quattro), R.drawable.quattrokg));
				items3.add(new SpinnerItem(getString(R.string.cinque), R.drawable.cinquekg));
				
				spinner3 = (Spinner) findViewById(R.id.spinner3);
				spinner3.setAdapter(new SpinnerItemAdapter(this,items3));
				spinner3.setOnItemSelectedListener(new OnItemSelectedListener() 
				{
					public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id)
					{
						selezione[3] = position;
						//Toast.makeText(adapterView.getContext(), "selezione: " + selezione.get(0).toString() + ", " + selezione.get(1).toString() + ", " + selezione.get(2).toString() + ", " + selezione.get(3).toString(), Toast.LENGTH_SHORT).show();
						for(int i = 0; i<selezione.length; i++){
							Log.i("Selex item",": "+selezione[i]);
						}
					}

					public void onNothingSelected(AdapterView<?> adapterView)
					{
						//nothing				
					}
				});
				
				Play_Controller controller = new Play_Controller(this);
				go.setOnClickListener(controller);
				random.setOnClickListener(controller);
	}

	
//	@Override
//	public boolean onKeyDown(int keyCode, KeyEvent event) {
//	    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
//	        // start new Activity here
//	    	Intent showMain = new Intent(this,
//					MainActivity.class);
//			this.startActivity(showMain);
//	    }
//	    return super.onKeyDown(keyCode, event);
//	}
	


}
