/**
 *   Copyright 2010 Guenther Hoelzl, Shawn Brown
 *
 *   This file is part of MINDdroid.
 *
 *   MINDdroid is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   MINDdroid is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with MINDdroid.  If not, see <http://www.gnu.org/licenses/>.
**/

package com.lego.minddroid;

import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.Toast;

public class Options {

	private Dialog mDialog;
	String mSelectionMessage;
	SplashMenu splashMenu;

	public Options(Activity myActivity) {
		this.splashMenu=(SplashMenu) myActivity;
		mDialog = new Dialog(myActivity);
		mDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		mDialog.setContentView(R.layout.options);

		mSelectionMessage = myActivity.getString(R.string.model_type_selected);

		final RadioButton robot_type_1 = (RadioButton) mDialog.findViewById(R.id.robot_type_1);
		final RadioButton robot_type_2 = (RadioButton) mDialog.findViewById(R.id.robot_type_2);
		final RadioButton robot_type_3 = (RadioButton) mDialog.findViewById(R.id.robot_type_3);
		final RadioButton robot_type_4 = (RadioButton) mDialog.findViewById(R.id.robot_type_4);
		final RadioButton robot_type_5 = (RadioButton) mDialog.findViewById(R.id.robot_type_5);
		
		switch (splashMenu.getRobotType()) {

			case R.id.robot_type_2:
				robot_type_2.setChecked(true);
				break;

			case R.id.robot_type_3:
				robot_type_3.setChecked(true);
				break;

			case R.id.robot_type_4:
				robot_type_4.setChecked(true);
				break;

			case R.id.robot_type_5:
				robot_type_5.setChecked(true);
		        Toast toast = Toast.makeText(myActivity, "version 91", Toast.LENGTH_SHORT);
		        toast.show();				
				break;

			default:
				robot_type_1.setChecked(true);
				break;
		}

		robot_type_1.setOnClickListener(radio_listener);
		robot_type_2.setOnClickListener(radio_listener);
		robot_type_3.setOnClickListener(radio_listener);
		robot_type_4.setOnClickListener(radio_listener);
		robot_type_5.setOnClickListener(radio_listener);
	}
	
	public void show() {
		mDialog.show();
	}

	private OnClickListener radio_listener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			// Perform action on clicks
			RadioButton rb = (RadioButton) v;
			rb.setChecked(true);
			splashMenu.setRobotType(rb.getId());
			Toast.makeText(mDialog.getContext(), mSelectionMessage + " " + rb.getText(), Toast.LENGTH_SHORT).show();
			mDialog.dismiss();
		}
	};	
}
