package edu.psu.rcy5017.publicspeakingassistant;

import edu.psu.rcy501.publicspeakingassistant.R;
import edu.psu.rcy5017.publicspeakingassistant.adapter.TabsPagerAdapter;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends FragmentActivity implements
ActionBar.TabListener {
	
	private static final String TAG = "MainActivity";
	
	 private ViewPager viewPager;
	 private TabsPagerAdapter mAdapter;
	 private ActionBar actionBar;
	 // Tab titles
	 private String[] tabs = { "Note 1", "Note2", "Note3" };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        // Initilization
        viewPager = (ViewPager) findViewById(R.id.pager);
        actionBar = getActionBar();
        mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
 
        viewPager.setAdapter(mAdapter);
        actionBar.setHomeButtonEnabled(false);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);        
 
        // Adding Tabs
        for (String tab_name : tabs) {
            actionBar.addTab(actionBar.newTab().setText(tab_name)
                    .setTabListener(this));
        }
        
        /**
         * on swiping the viewpager make respective tab selected
         * */
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                // on changing the page
                // make respected tab selected
                actionBar.setSelectedNavigationItem(position);
            }
         
            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            	// Do nothing.
            }
         
            @Override
            public void onPageScrollStateChanged(int arg0) {
            	// Do nothing.
            }
        });
        
        Log.d(TAG, "Main activity started");
    }


    @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 boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
		// Do nothing.
	}

	 @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // show respected fragment view
        viewPager.setCurrentItem(tab.getPosition());
    }

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		// Do nothing.
	}
}

@@ -161,24 +161,154 @@
 gerAdapter;%0A
+import edu.psu.rcy5017.publicspeakingassistant.model.NoteCard;%0Aimport edu.psu.rcy5017.publicspeakingassistant.model.TestNoteList;%0A
 import andro
@@ -684,18 +684,16 @@
 tener %7B%0A
-%09%0A
 %09private
@@ -738,17 +738,16 @@
 ty%22;%0A%09%0A%09
- 
 private 
@@ -764,25 +764,24 @@
 viewPager;%0A%09
- 
 private Tabs
@@ -804,17 +804,16 @@
 apter;%0A%09
- 
 private 
@@ -836,82 +836,8 @@
 Bar;
-%0A%09 // Tab titles%0A%09 private String%5B%5D tabs = %7B %22Note 1%22, %22Note2%22, %22Note3%22 %7D;
 %0A%0A  
@@ -1012,16 +1012,17 @@
 // Initi
+a
 lization
@@ -1353,16 +1353,23 @@
       %0A 
+       
 %0A       
@@ -1376,55 +1376,294 @@
  // 
-Adding Tabs%0A        for (String tab_name : tabs
+Create a list of test notecards.%0A        final TestNoteList notecards = new TestNoteList();%0A        notecards.populateList();%0A        %0A        //DEBUG%0A        notecards.logNotes();%0A        %0A        // Create a tab for each note card.%0A        for (NoteCard noteCard : notecards.getList()
 ) %7B%0A
@@ -1722,16 +1722,27 @@
 ext(
-tab_name
+noteCard.getTitle()
 )%0A  
@@ -1814,11 +1814,8 @@
     
-/**
 %0A   
@@ -1823,12 +1823,12 @@
     
- * o
+// O
 n sw
@@ -1879,22 +1879,9 @@
 cted
-%0A         * */
+.
 %0A   
@@ -3599,9 +3599,8 @@
 ng.%0A%09%7D%0A%7D
-%0A

Use text note list for tab titles.