import java.util.ArrayList;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.FragmentTransaction;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;

public class Menu extends ActionBarActivity implements TabListener {

	protected static DatabaseHandler db;
	protected static ArrayList<SQLiteLocation> favoriteList;
	private ActionBar actionBar;
	private ViewPager viewPager;
	private int favChange;

	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.main);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		db = new DatabaseHandler(this);
		
		favoriteList = new ArrayList<SQLiteLocation>(); 
		favChange = favoriteList.size();
	/*	if(db.getLocationsCount() > 0){
			for(int i = 1; i <= db.getLocationsCount(); i++) {
				if(db.getLocation(i).isFavorite()){
					db.getLocation(i).setPos(favoriteList.size());
					favoriteList.add(db.getLocation(i));
				}
			}
		}
	 */
		viewPager = (ViewPager) findViewById(R.id.pager);
		viewPager.setAdapter(new MyAdapter(getSupportFragmentManager()));
		viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {
				actionBar.setSelectedNavigationItem(arg0);
			}
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
			}
			@Override
			public void onPageScrollStateChanged(int arg0) {
			}
		});
		actionBar = getActionBar();
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

		ActionBar.Tab favorite = actionBar.newTab();
		favorite.setText("Favorites");
		favorite.setTabListener(this);

		ActionBar.Tab custom = actionBar.newTab();
		custom.setText("New Location");
		custom.setTabListener(this);

		ActionBar.Tab history = actionBar.newTab();
		history.setText("History");
		history.setTabListener(this);

		actionBar.addTab(favorite);
		actionBar.addTab(custom, true);
		actionBar.addTab(history);
	}
	
	public static void saveFavorite(SQLiteLocation newFav){
		db.getLocation(newFav.getId()).setFavorite(true);
		db.getLocation(newFav.getId()).setPos(favoriteList.size());
		favoriteList.add(newFav);
	}
	
	public static void deleteFavorite(SQLiteLocation deleteFav){
		db.getLocation(deleteFav.getId()).setFavorite(false);
		favoriteList.remove(deleteFav.getPos());
	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		viewPager.setCurrentItem(tab.getPosition());
	}
	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
	}
	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
	}

	public void onPause() {
		super.onPause();
		favChange = favoriteList.size();
	}

	public void onResume() {
		super.onResume(); //hack-job update fix
		if(favoriteList.size() > favChange || viewPager.getCurrentItem() == 0){	//added favorite
			viewPager.setCurrentItem(2,false);
			viewPager.setCurrentItem(0,false);
		}
		else if(viewPager.getCurrentItem() == 1){
			viewPager.setCurrentItem(0,false);
			viewPager.setCurrentItem(2,false);
			viewPager.setCurrentItem(1,false);
		}
		else {
			viewPager.setCurrentItem(0,false);
			viewPager.setCurrentItem(2,false);
		}
	}

}

class MyAdapter extends FragmentPagerAdapter {

	public MyAdapter(FragmentManager fm) {
		super(fm);
	}

	@Override
	public Fragment getItem(int arg0) {
		Fragment fragment = null;
		if (arg0 == 0)
			fragment = new FavoriteMark();
		else if (arg0 == 1)
			fragment = new CustomMark();
		else
			fragment = new HistoryMark();
		return fragment;
	}
	
	@Override
	public int getCount() {
		return 3;
	}
}

@@ -882,16 +882,34 @@
 TRAIT);%0A
+%09%09if(db == null)%0A%09
 %09%09db = n
@@ -934,16 +934,16 @@
 (this);%0A
-
 %09%09%0A%09%09fav
@@ -1027,251 +1027,8 @@
 ();%0A
-%09/*%09if(db.getLocationsCount() %3E 0)%7B%0A%09%09%09for(int i = 1; i %3C= db.getLocationsCount(); i++) %7B%0A%09%09%09%09if(db.getLocation(i).isFavorite())%7B%0A%09%09%09%09%09db.getLocation(i).setPos(favoriteList.size());%0A%09%09%09%09%09favoriteList.add(db.getLocation(i));%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09 */
 %0A%09%09v
@@ -2012,378 +2012,8 @@
 ;%0A%09%7D
-%0A%09%0A%09public static void saveFavorite(SQLiteLocation newFav)%7B%0A%09%09db.getLocation(newFav.getId()).setFavorite(true);%0A%09%09db.getLocation(newFav.getId()).setPos(favoriteList.size());%0A%09%09favoriteList.add(newFav);%0A%09%7D%0A%09%0A%09public static void deleteFavorite(SQLiteLocation deleteFav)%7B%0A%09%09db.getLocation(deleteFav.getId()).setFavorite(false);%0A%09%09favoriteList.remove(deleteFav.getPos());%0A%09%7D
 %0A%0A%09@

Remove favoriteList functions from Menu.java