Update pager demos to match new v4 ViewPager API.

Change-Id: I3b0f3382d56b477868b5a5fbf5af22fa83c3e06a
diff --git a/samples/Support13Demos/_index.html b/samples/Support13Demos/_index.html
index d6168ab..5861f72 100644
--- a/samples/Support13Demos/_index.html
+++ b/samples/Support13Demos/_index.html
@@ -19,7 +19,7 @@
 "together. Current samples are only for the fragment and loader in the "+
 "application part of the support library:</p>"+
 
-"<ul><li><a href='src/com/example/android/supportv4/app/index.html'>App</a></li></ul>");
+"<ul><li><a href='src/com/example/android/supportv13/app/index.html'>App</a></li></ul>");
 
 }
 
diff --git a/samples/Support13Demos/res/layout/fragment_pager.xml b/samples/Support13Demos/res/layout/fragment_pager.xml
index cc07d84..46c8cbe 100644
--- a/samples/Support13Demos/res/layout/fragment_pager.xml
+++ b/samples/Support13Demos/res/layout/fragment_pager.xml
@@ -21,12 +21,12 @@
         android:gravity="center_horizontal"
         android:layout_width="match_parent" android:layout_height="match_parent">
 
-    <android.support.v13.view.ViewPager
+    <android.support.v4.view.ViewPager
             android:id="@+id/pager"
             android:layout_width="match_parent"
             android:layout_height="0px"
             android:layout_weight="1">
-    </android.support.v13.view.ViewPager>
+    </android.support.v4.view.ViewPager>
 
     <LinearLayout android:orientation="horizontal"
             android:gravity="center" android:measureWithLargestChild="true"
diff --git a/samples/Support13Demos/src/com/example/android/supportv13/app/FragmentPagerSupport.java b/samples/Support13Demos/src/com/example/android/supportv13/app/FragmentPagerSupport.java
index fcb41cd..ae2f481 100644
--- a/samples/Support13Demos/src/com/example/android/supportv13/app/FragmentPagerSupport.java
+++ b/samples/Support13Demos/src/com/example/android/supportv13/app/FragmentPagerSupport.java
@@ -20,7 +20,7 @@
 import com.example.android.supportv13.R;
 
 import android.support.v13.app.FragmentPagerAdapter;
-import android.support.v13.view.ViewPager;
+import android.support.v4.view.ViewPager;
 
 import android.os.Bundle;
 import android.app.Activity;
diff --git a/samples/Support13Demos/src/com/example/android/supportv13/app/FragmentStatePagerSupport.java b/samples/Support13Demos/src/com/example/android/supportv13/app/FragmentStatePagerSupport.java
index e19bdf6..4e6ebda 100644
--- a/samples/Support13Demos/src/com/example/android/supportv13/app/FragmentStatePagerSupport.java
+++ b/samples/Support13Demos/src/com/example/android/supportv13/app/FragmentStatePagerSupport.java
@@ -20,7 +20,7 @@
 import com.example.android.supportv13.R;
 
 import android.support.v13.app.FragmentStatePagerAdapter;
-import android.support.v13.view.ViewPager;
+import android.support.v4.view.ViewPager;
 
 import android.os.Bundle;
 import android.app.Activity;
diff --git a/samples/Support13Demos/src/com/example/android/supportv13/app/_index.html b/samples/Support13Demos/src/com/example/android/supportv13/app/_index.html
index b00985e..47673da 100644
--- a/samples/Support13Demos/src/com/example/android/supportv13/app/_index.html
+++ b/samples/Support13Demos/src/com/example/android/supportv13/app/_index.html
@@ -9,7 +9,12 @@
 <h3 id="Fragment">Fragment</h3>
 <dl>
   <dt><a href="FragmentPagerSupport.html">Fragment Pager Support</a></dt>
-  <dd>A support class for using the framework Fragment APIs to build
-   a user interface where the user can fling left or right to switch
-   between fragments.</dd>
+  <dd>Demonstrates the use of the v4 support class ViewPager with a
+  FragmentPagerAdapter to build a user interface where the user can fling
+  left or right to switch between fragments.</dd>
+  <dt><a href="FragmentStatePagerSupport.html">Fragment State Pager Support</a></dt>
+  <dd>Demonstrates the use of the v4 support class ViewPager with a
+  FragmentStatePagerAdapter to build a user interface where the user can fling
+  left or right to switch between fragments.  This versions of the adapter
+  doesn't keep around the fragment instances that ViewPager has destroyed.</dd>
 </dl>
diff --git a/samples/Support4Demos/AndroidManifest.xml b/samples/Support4Demos/AndroidManifest.xml
index 772eb54..db4dbd1 100644
--- a/samples/Support4Demos/AndroidManifest.xml
+++ b/samples/Support4Demos/AndroidManifest.xml
@@ -24,7 +24,7 @@
 
     <uses-permission android:name="android.permission.READ_CONTACTS" />
 
-    <uses-sdk android:minSdkVersion="4" />
+    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="13" />
 
     <!-- This app has not been optimized for large screens. -->
     <supports-screens android:requiresSmallestWidthDp="320"
@@ -155,6 +155,14 @@
             </intent-filter>
         </activity>
 
+        <activity android:name=".app.FragmentStatePagerSupport"
+                android:label="@string/fragment_state_pager_support">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="com.example.android.supportv4.SUPPORT4_SAMPLE_CODE" />
+            </intent-filter>
+        </activity>
+
         <activity android:name=".app.LoaderCursorSupport"
                 android:label="@string/loader_cursor_support">
             <intent-filter>
diff --git a/samples/Support4Demos/res/layout/fragment_pager.xml b/samples/Support4Demos/res/layout/fragment_pager.xml
index a082e2e..46c8cbe 100644
--- a/samples/Support4Demos/res/layout/fragment_pager.xml
+++ b/samples/Support4Demos/res/layout/fragment_pager.xml
@@ -21,12 +21,12 @@
         android:gravity="center_horizontal"
         android:layout_width="match_parent" android:layout_height="match_parent">
 
-    <android.support.v4.app.FragmentPager
+    <android.support.v4.view.ViewPager
             android:id="@+id/pager"
             android:layout_width="match_parent"
             android:layout_height="0px"
             android:layout_weight="1">
-    </android.support.v4.app.FragmentPager>
+    </android.support.v4.view.ViewPager>
 
     <LinearLayout android:orientation="horizontal"
             android:gravity="center" android:measureWithLargestChild="true"
diff --git a/samples/Support4Demos/res/values/strings.xml b/samples/Support4Demos/res/values/strings.xml
index ba7a341..477cd9b 100644
--- a/samples/Support4Demos/res/values/strings.xml
+++ b/samples/Support4Demos/res/values/strings.xml
@@ -81,6 +81,8 @@
     <string name="first">First</string>
     <string name="last">Last</string>
 
+    <string name="fragment_state_pager_support">Fragment/State Pager</string>
+
     <string name="loader_cursor_support">Loader/Cursor</string>
     
     <string name="loader_throttle_support">Loader/Throttle</string>
diff --git a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentPagerSupport.java b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentPagerSupport.java
index 3329597..c10890b 100644
--- a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentPagerSupport.java
+++ b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentPagerSupport.java
@@ -22,8 +22,10 @@
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentActivity;
-import android.support.v4.app.FragmentPager;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentPagerAdapter;
 import android.support.v4.app.ListFragment;
+import android.support.v4.view.ViewPager;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -34,19 +36,22 @@
 import android.widget.ListView;
 import android.widget.TextView;
 
-public class FragmentPagerSupport extends FragmentActivity
-        implements FragmentPager.Adapter {
+public class FragmentPagerSupport extends FragmentActivity {
     static final int NUM_ITEMS = 10;
 
-    FragmentPager mPager;
+    MyAdapter mAdapter;
+
+    ViewPager mPager;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.fragment_pager);
 
-        mPager = (FragmentPager)findViewById(R.id.pager);
-        mPager.setAdapter(this);
+        mAdapter = new MyAdapter(getSupportFragmentManager());
+
+        mPager = (ViewPager)findViewById(R.id.pager);
+        mPager.setAdapter(mAdapter);
 
         // Watch for button clicks.
         Button button = (Button)findViewById(R.id.goto_first);
@@ -63,14 +68,20 @@
         });
     }
 
-    @Override
-    public int getCount() {
-        return NUM_ITEMS;
-    }
+    public static class MyAdapter extends FragmentPagerAdapter {
+        public MyAdapter(FragmentManager fm) {
+            super(fm);
+        }
 
-    @Override
-    public Fragment getItem(int position) {
-        return ArrayListFragment.newInstance(position);
+        @Override
+        public int getCount() {
+            return NUM_ITEMS;
+        }
+
+        @Override
+        public Fragment getItem(int position) {
+            return ArrayListFragment.newInstance(position);
+        }
     }
 
     public static class ArrayListFragment extends ListFragment {
diff --git a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStatePagerSupport.java b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStatePagerSupport.java
new file mode 100644
index 0000000..8a52896
--- /dev/null
+++ b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStatePagerSupport.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * 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.example.android.supportv4.app;
+
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentActivity;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentStatePagerAdapter;
+import android.support.v4.app.ListFragment;
+import android.support.v4.view.ViewPager;
+
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ListView;
+import android.widget.TextView;
+
+import com.example.android.supportv4.Cheeses;
+import com.example.android.supportv4.R;
+
+public class FragmentStatePagerSupport extends FragmentActivity {
+    static final int NUM_ITEMS = 10;
+
+    MyAdapter mAdapter;
+
+    ViewPager mPager;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.fragment_pager);
+
+        mAdapter = new MyAdapter(getSupportFragmentManager());
+
+        mPager = (ViewPager)findViewById(R.id.pager);
+        mPager.setAdapter(mAdapter);
+
+        // Watch for button clicks.
+        Button button = (Button)findViewById(R.id.goto_first);
+        button.setOnClickListener(new OnClickListener() {
+            public void onClick(View v) {
+                mPager.setCurrentItem(0);
+            }
+        });
+        button = (Button)findViewById(R.id.goto_last);
+        button.setOnClickListener(new OnClickListener() {
+            public void onClick(View v) {
+                mPager.setCurrentItem(NUM_ITEMS-1);
+            }
+        });
+    }
+
+    public static class MyAdapter extends FragmentStatePagerAdapter {
+        public MyAdapter(FragmentManager fm) {
+            super(fm);
+        }
+
+        @Override
+        public int getCount() {
+            return NUM_ITEMS;
+        }
+
+        @Override
+        public Fragment getItem(int position) {
+            return ArrayListFragment.newInstance(position);
+        }
+    }
+
+    public static class ArrayListFragment extends ListFragment {
+        int mNum;
+
+        /**
+         * Create a new instance of CountingFragment, providing "num"
+         * as an argument.
+         */
+        static ArrayListFragment newInstance(int num) {
+            ArrayListFragment f = new ArrayListFragment();
+
+            // Supply num input as an argument.
+            Bundle args = new Bundle();
+            args.putInt("num", num);
+            f.setArguments(args);
+
+            return f;
+        }
+
+        /**
+         * When creating, retrieve this instance's number from its arguments.
+         */
+        @Override
+        public void onCreate(Bundle savedInstanceState) {
+            super.onCreate(savedInstanceState);
+            mNum = getArguments() != null ? getArguments().getInt("num") : 1;
+        }
+
+        /**
+         * The Fragment's UI is just a simple text view showing its
+         * instance number.
+         */
+        @Override
+        public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                Bundle savedInstanceState) {
+            View v = inflater.inflate(R.layout.fragment_pager_list, container, false);
+            View tv = v.findViewById(R.id.text);
+            ((TextView)tv).setText("Fragment #" + mNum);
+            return v;
+        }
+
+        @Override
+        public void onActivityCreated(Bundle savedInstanceState) {
+            super.onActivityCreated(savedInstanceState);
+            setListAdapter(new ArrayAdapter<String>(getActivity(),
+                    android.R.layout.simple_list_item_1, Cheeses.sCheeseStrings));
+        }
+
+        @Override
+        public void onListItemClick(ListView l, View v, int position, long id) {
+            Log.i("FragmentList", "Item clicked: " + id);
+        }
+    }
+}
diff --git a/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderThrottleSupport.java b/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderThrottleSupport.java
index 6693008..d16797b 100644
--- a/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderThrottleSupport.java
+++ b/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderThrottleSupport.java
@@ -63,7 +63,7 @@
     /**
      * The authority we use to get to our sample provider.
      */
-    public static final String AUTHORITY = "com.example.android.apis.support.app.LoaderThrottle";
+    public static final String AUTHORITY = "com.example.android.apis.supportv4.app.LoaderThrottle";
 
     /**
      * Definition of the contract for the main table of our provider.
diff --git a/samples/Support4Demos/src/com/example/android/supportv4/app/_index.html b/samples/Support4Demos/src/com/example/android/supportv4/app/_index.html
index 592ccc1..286d4a0 100644
--- a/samples/Support4Demos/src/com/example/android/supportv4/app/_index.html
+++ b/samples/Support4Demos/src/com/example/android/supportv4/app/_index.html
@@ -45,9 +45,15 @@
   <dd>Demonstrates populating custom menu items from a Fragment.</dd>
   
   <dt><a href="FragmentPagerSupport.html">Fragment Pager Support</a></dt>
-  <dd>A support class for using the Fragment APIs to build
-   a user interface where the user can fling left or right to switch
-   between fragments.</dd>
+  <dd>Demonstrates the use of the support class ViewPager with a
+  FragmentPagerAdapter to build a user interface where the user can fling
+  left or right to switch between fragments.</dd>
+
+  <dt><a href="FragmentStatePagerSupport.html">Fragment State Pager Support</a></dt>
+  <dd>Demonstrates the use of the support class ViewPager with a
+  FragmentStatePagerAdapter to build a user interface where the user can fling
+  left or right to switch between fragments.  This versions of the adapter
+  doesn't keep around the fragment instances that ViewPager has destroyed.</dd>
 
   <dt><a href="FragmentReceiveResultSupport.html">Fragment Receive Result</a></dt>
   <dd>Demonstrates starting a new Activity from a Fragment, and receiving