package com.hilton.vulcan;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class TabsFragment extends Fragment {
    protected static final String TAG = TabsFragment.class.getName();
    private Tab[] mTabs = new Tab[] {
	    new Tab("Tab 1"),
	    new Tab("Tab 2"),
	    new Tab("Tab 3"),
	    new Tab("Tab 4"),
	    new Tab("Tab 5")
    };
    
    private TabHost mTabHost;
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
	    Bundle savedInstanceState) {
	View root = inflater.inflate(R.layout.tabs, container, false);
	mTabHost = (TabHost) root.findViewById(android.R.id.tabhost);
	setupTabs(mTabHost);
	return root;
    }
    
    private void setupTabs(final TabHost tabHost) {
	tabHost.setup();
	for (final Tab tab : mTabs) {
	    TabSpec spec = tabHost.newTabSpec(tab.mTag);
	    spec.setIndicator(tab.mTag);
	    spec.setContent(new TabContentFactory() {
		@Override
		public View createTabContent(String tag) {
		    TextView tv =  new TextView(getActivity());
		    tv.setText(tab.mTag);
		    return tv;
		}
		
	    });
	    tabHost.addTab(spec);
	}
	tabHost.setOnTabChangedListener(new OnTabChangeListener() {
	    @Override
	    public void onTabChanged(String tabId) {
		Log.e(TAG, "which is showing ? tab id " + tabId);
	    }
	});
    }
    
    private class Tab {
	public String mTag;
	
	public Tab(final String tag) {
	    mTag = tag;
	}
	
	@Override
	public String toString() {
	    return "[tag " + mTag + "]";
	}
    }
}
@@ -21,16 +21,139 @@
 ulcan;%0A%0A
+import android.content.Context;%0Aimport android.content.SharedPreferences;%0Aimport android.content.SharedPreferences.Editor;%0A
 import a
@@ -170,16 +170,16 @@
 Bundle;%0A
-
 import a
@@ -646,16 +646,134 @@
 Name();%0A
+    private static final String PREFS = %22default_prefs%22;%0A    private static final String CURRENT_TAB = %22current_tab%22;%0A
     priv
@@ -959,24 +959,335 @@
 bHost;%0A    %0A
+    @Override%0A    public void onDestroy() %7B%0A%09super.onDestroy();%0A%09saveCurrentTab();%0A    %7D%0A%0A    private void saveCurrentTab() %7B%0A%09SharedPreferences sp = getActivity().getSharedPreferences(PREFS, Context.MODE_PRIVATE);%0A%09Editor ed = sp.edit();%0A%09ed.putInt(CURRENT_TAB, mTabHost.getCurrentTab());%0A%09ed.commit();%0A    %7D%0A%0A
     @Overrid
@@ -1553,17 +1553,256 @@
 %0A%09re
-turn root
+storeCurrentTab();%0A%09return root;%0A    %7D%0A%0A    private void restoreCurrentTab() %7B%0A%09SharedPreferences sp = getActivity().getSharedPreferences(PREFS, Context.MODE_PRIVATE);%0A%09final int current = sp.getInt(CURRENT_TAB, 0);%0A%09mTabHost.setCurrentTab(current)
 ;%0A  

Save and restore current tab between sessions.