package it.unipr.mobdev;

import android.os.Bundle;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.view.Menu;


public class MainActivity extends Activity implements ActionBar.TabListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		//Retrieve the ActionBar
		final ActionBar actionBar = getActionBar();
		
		//Set the Navigation mode to support tabs with the ActionBar
	    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

	    // for each of the sections in the app, add a tab to the action bar.
	    actionBar.addTab(actionBar.newTab().setText("Section 1").setTabListener(this));
	    actionBar.addTab(actionBar.newTab().setText("Section 2").setTabListener(this));
	    actionBar.addTab(actionBar.newTab().setText("Section 3").setTabListener(this));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onTabReselected(Tab tab, FragmentTransaction fragmentTransaction) {
	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction fragmentTransaction) {
		    // When the given tab is selected, show the tab contents in the container view.
		    Fragment fragment = new DemoSectionFragment();
		    Bundle args = new Bundle();
		    args.putInt(DemoSectionFragment.ARG_SECTION_NUMBER,tab.getPosition() + 1);
		    fragment.setArguments(args);
		    getFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
	}

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction fragmentTransaction) {
	}

}
