Update pager demos to match new v4 ViewPager API.
Change-Id: I3b0f3382d56b477868b5a5fbf5af22fa83c3e06a
This commit is contained in:
@@ -19,7 +19,7 @@ document.write(""+
|
||||
"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>");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.example.android.supportv13.Cheeses;
|
||||
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;
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.example.android.supportv13.Cheeses;
|
||||
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;
|
||||
|
||||
@@ -9,7 +9,12 @@ package features of the static support library fir API 13 or later.
|
||||
<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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -22,8 +22,10 @@ import com.example.android.supportv4.R;
|
||||
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.Button;
|
||||
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,6 +68,11 @@ public class FragmentPagerSupport extends FragmentActivity
|
||||
});
|
||||
}
|
||||
|
||||
public static class MyAdapter extends FragmentPagerAdapter {
|
||||
public MyAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return NUM_ITEMS;
|
||||
@@ -72,6 +82,7 @@ public class FragmentPagerSupport extends FragmentActivity
|
||||
public Fragment getItem(int position) {
|
||||
return ArrayListFragment.newInstance(position);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ArrayListFragment extends ListFragment {
|
||||
int mNum;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class LoaderThrottleSupport extends FragmentActivity {
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -45,9 +45,15 @@ and loaders.</p>
|
||||
<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
|
||||
|
||||
Reference in New Issue
Block a user