package com.ramos.munoz.tesis;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class Tutorial extends Activity {

    private static final int MAX_VIEWS = 3;

    ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

	super.onCreate(savedInstanceState);
	setContentView(R.layout.tutorial);
	mViewPager = (ViewPager) findViewById(R.id.view_pager);
	WalkthroughPagerAdapter adaptador = new WalkthroughPagerAdapter();
	mViewPager.setAdapter(adaptador);
	mViewPager.setOnPageChangeListener(new WalkthroughPageChangeListener());
    }

    class WalkthroughPagerAdapter extends PagerAdapter {

	@Override
	public int getCount() {
	    return MAX_VIEWS;
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
	    return view == (View) object;
	}

	@Override
	public Object instantiateItem(View container, int position) {
	    Log.e("walkthrough", "instantiateItem(" + position + ");");
	    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    View imageViewContainer = inflater.inflate(R.layout.tutorial_imgview, null);
	    ImageView imageView = (ImageView) imageViewContainer.findViewById(R.id.image_view);

	    switch (position) {
		case 0:
		    imageView.setImageResource(R.drawable.menu_principal);
		    break;

		case 1:
		    imageView.setImageResource(R.drawable.radio_busqueda);
		    break;

		case 2:
		    imageView.setImageResource(R.drawable.calcular_ruta);
		    break;

	    }

	    ((ViewPager) container).addView(imageViewContainer, 0);
	    return imageViewContainer;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
	    ((ViewPager) container).removeView((View) object);
	}
    }

    class WalkthroughPageChangeListener implements ViewPager.OnPageChangeListener {

	@Override
	public void onPageScrollStateChanged(int arg0) {

	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {

	}

	@Override
	public void onPageSelected(int position) {
	    // Here is where you should show change the view of page indicator
	    switch (position) {

		case MAX_VIEWS - 1:
		    break;

		default:

	    }

	}

    }
}