/*
 * Copyright (C) 2012 Gregory S. Meiste  <http://gregmeiste.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.meiste.greg.ptw;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
import android.support.v4.view.ViewPager;

import com.viewpagerindicator.PageIndicator;
import com.viewpagerindicator.TitlePageIndicator;
import com.viewpagerindicator.TitlePageIndicator.IndicatorStyle;

public class MainActivity extends FragmentActivity {
	TestFragmentAdapter mAdapter;
	ViewPager mPager;
	PageIndicator mIndicator;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Eula.show(this);
        
        setContentView(R.layout.main);
        
        mAdapter = new TestFragmentAdapter(getSupportFragmentManager());

		mPager = (ViewPager)findViewById(R.id.pager);
		mPager.setAdapter(mAdapter);

		TitlePageIndicator indicator = (TitlePageIndicator)findViewById(R.id.indicator);
		mIndicator = indicator;
		indicator.setViewPager(mPager);

		/** TODO: Move style to layout */
		final float density = getResources().getDisplayMetrics().density;
		indicator.setBackgroundColor(0x18FF0000);
		indicator.setFooterColor(0xFFAA2222);
		indicator.setFooterLineHeight(1 * density); //1dp
		indicator.setFooterIndicatorHeight(3 * density); //3dp
		indicator.setFooterIndicatorStyle(IndicatorStyle.Underline);
		indicator.setTextColor(0xAA000000);
		indicator.setSelectedColor(0xFF000000);
		indicator.setSelectedBold(true);
    }
    
    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case R.id.settings:
				/** TODO */
				return true;

			case R.id.legal:
				/** TODO */
				return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
@@ -654,16 +654,87 @@
 g.ptw;%0A%0A
+import android.app.Activity;%0Aimport android.content.SharedPreferences;%0A
 import a
@@ -923,53 +923,33 @@
 er;%0A
-%0A
 import 
-com.viewpagerindicator.PageIndicator;
+android.util.Log;%0A
 %0Aimp
@@ -1115,16 +1115,223 @@
 vity %7B%0A%09
+private final String TAG = %22PickTheWinner%22;%0A%09private final boolean DEBUG = true;%0A%09%0A%09public static final String PREFERENCES_STATE = %22state%22;%0A%09private final String PREFERENCE_LAST_TAB = %22tab.last%22;%0A%09%0A%09private 
 TestFrag
@@ -1353,16 +1353,24 @@
 apter;%0A%09
+private 
 ViewPage
@@ -1380,16 +1380,29 @@
 Pager;%0A%09
+private Title
 PageIndi
@@ -1661,32 +1661,155 @@
 main);%0A        %0A
+        final SharedPreferences prefs = getSharedPreferences(PREFERENCES_STATE,%0A        %09%09Activity.MODE_PRIVATE);%0A        %0A
         mAdapter
@@ -1952,28 +1952,10 @@
 %0A%0A%09%09
-TitlePageIndicator i
+mI
 ndic
@@ -2027,25 +2027,35 @@
 ator
- = indicator
+.setViewPager(mPager)
 ;%0A%09%09
-i
+mI
 ndic
@@ -2062,32 +2062,64 @@
 ator.set
-ViewPager(mPager
+CurrentItem(prefs.getInt(PREFERENCE_LAST_TAB, 0)
 );%0A%0A%09%09/*
@@ -2216,25 +2216,26 @@
 .density;%0A%09%09
-i
+mI
 ndicator.set
@@ -2257,33 +2257,34 @@
 (0x18FF0000);%0A%09%09
-i
+mI
 ndicator.setFoot
@@ -2302,25 +2302,26 @@
 FAA2222);%0A%09%09
-i
+mI
 ndicator.set
@@ -2355,25 +2355,26 @@
 y); //1dp%0A%09%09
-i
+mI
 ndicator.set
@@ -2417,17 +2417,18 @@
 //3dp%0A%09%09
-i
+mI
 ndicator
@@ -2477,25 +2477,26 @@
 derline);%0A%09%09
-i
+mI
 ndicator.set
@@ -2512,33 +2512,34 @@
 (0xAA000000);%0A%09%09
-i
+mI
 ndicator.setSele
@@ -2563,17 +2563,18 @@
 000);%0A%09%09
-i
+mI
 ndicator
@@ -2614,32 +2614,361 @@
  %0A    @Override%0A
+%09public void onPause() %7B%0A%09%09super.onPause();%0A%0A%09%09if (DEBUG) Log.d(TAG, %22Saving state: tab=%22 + mPager.getCurrentItem());%0A%09%09%0A%09%09final SharedPreferences prefs = getSharedPreferences(PREFERENCES_STATE,%0A        %09%09Activity.MODE_PRIVATE);%0A%09%09prefs.edit().putInt(PREFERENCE_LAST_TAB, mPager.getCurrentItem()).commit();%0A%09%7D%0A    %0A    @Override%0A
 %09public boolean 

Save state when application is closed