• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

development


Commit MetaInfo

Révision7ffb7d4b2face7d2ce5cee82c92ec36fd0ba2932 (tree)
l'heure2011-06-07 07:01:45
AuteurDianne Hackborn <hackbod@goog...>
CommiterDianne Hackborn

Message de Log

Update pager demos to match new v4 ViewPager API.

Change-Id: I3b0f3382d56b477868b5a5fbf5af22fa83c3e06a

Change Summary

Modification

--- a/samples/Support13Demos/_index.html
+++ b/samples/Support13Demos/_index.html
@@ -19,7 +19,7 @@ document.write(""+
1919 "together. Current samples are only for the fragment and loader in the "+
2020 "application part of the support library:</p>"+
2121
22-"<ul><li><a href='src/com/example/android/supportv4/app/index.html'>App</a></li></ul>");
22+"<ul><li><a href='src/com/example/android/supportv13/app/index.html'>App</a></li></ul>");
2323
2424 }
2525
--- a/samples/Support13Demos/res/layout/fragment_pager.xml
+++ b/samples/Support13Demos/res/layout/fragment_pager.xml
@@ -21,12 +21,12 @@
2121 android:gravity="center_horizontal"
2222 android:layout_width="match_parent" android:layout_height="match_parent">
2323
24- <android.support.v13.view.ViewPager
24+ <android.support.v4.view.ViewPager
2525 android:id="@+id/pager"
2626 android:layout_width="match_parent"
2727 android:layout_height="0px"
2828 android:layout_weight="1">
29- </android.support.v13.view.ViewPager>
29+ </android.support.v4.view.ViewPager>
3030
3131 <LinearLayout android:orientation="horizontal"
3232 android:gravity="center" android:measureWithLargestChild="true"
--- 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.Cheeses;
2020 import com.example.android.supportv13.R;
2121
2222 import android.support.v13.app.FragmentPagerAdapter;
23-import android.support.v13.view.ViewPager;
23+import android.support.v4.view.ViewPager;
2424
2525 import android.os.Bundle;
2626 import android.app.Activity;
--- 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.Cheeses;
2020 import com.example.android.supportv13.R;
2121
2222 import android.support.v13.app.FragmentStatePagerAdapter;
23-import android.support.v13.view.ViewPager;
23+import android.support.v4.view.ViewPager;
2424
2525 import android.os.Bundle;
2626 import android.app.Activity;
--- 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 @@ package features of the static support library fir API 13 or later.
99 <h3 id="Fragment">Fragment</h3>
1010 <dl>
1111 <dt><a href="FragmentPagerSupport.html">Fragment Pager Support</a></dt>
12- <dd>A support class for using the framework Fragment APIs to build
13- a user interface where the user can fling left or right to switch
14- between fragments.</dd>
12+ <dd>Demonstrates the use of the v4 support class ViewPager with a
13+ FragmentPagerAdapter to build a user interface where the user can fling
14+ left or right to switch between fragments.</dd>
15+ <dt><a href="FragmentStatePagerSupport.html">Fragment State Pager Support</a></dt>
16+ <dd>Demonstrates the use of the v4 support class ViewPager with a
17+ FragmentStatePagerAdapter to build a user interface where the user can fling
18+ left or right to switch between fragments. This versions of the adapter
19+ doesn't keep around the fragment instances that ViewPager has destroyed.</dd>
1520 </dl>
--- a/samples/Support4Demos/AndroidManifest.xml
+++ b/samples/Support4Demos/AndroidManifest.xml
@@ -24,7 +24,7 @@
2424
2525 <uses-permission android:name="android.permission.READ_CONTACTS" />
2626
27- <uses-sdk android:minSdkVersion="4" />
27+ <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="13" />
2828
2929 <!-- This app has not been optimized for large screens. -->
3030 <supports-screens android:requiresSmallestWidthDp="320"
@@ -155,6 +155,14 @@
155155 </intent-filter>
156156 </activity>
157157
158+ <activity android:name=".app.FragmentStatePagerSupport"
159+ android:label="@string/fragment_state_pager_support">
160+ <intent-filter>
161+ <action android:name="android.intent.action.MAIN" />
162+ <category android:name="com.example.android.supportv4.SUPPORT4_SAMPLE_CODE" />
163+ </intent-filter>
164+ </activity>
165+
158166 <activity android:name=".app.LoaderCursorSupport"
159167 android:label="@string/loader_cursor_support">
160168 <intent-filter>
--- a/samples/Support4Demos/res/layout/fragment_pager.xml
+++ b/samples/Support4Demos/res/layout/fragment_pager.xml
@@ -21,12 +21,12 @@
2121 android:gravity="center_horizontal"
2222 android:layout_width="match_parent" android:layout_height="match_parent">
2323
24- <android.support.v4.app.FragmentPager
24+ <android.support.v4.view.ViewPager
2525 android:id="@+id/pager"
2626 android:layout_width="match_parent"
2727 android:layout_height="0px"
2828 android:layout_weight="1">
29- </android.support.v4.app.FragmentPager>
29+ </android.support.v4.view.ViewPager>
3030
3131 <LinearLayout android:orientation="horizontal"
3232 android:gravity="center" android:measureWithLargestChild="true"
--- a/samples/Support4Demos/res/values/strings.xml
+++ b/samples/Support4Demos/res/values/strings.xml
@@ -81,6 +81,8 @@
8181 <string name="first">First</string>
8282 <string name="last">Last</string>
8383
84+ <string name="fragment_state_pager_support">Fragment/State Pager</string>
85+
8486 <string name="loader_cursor_support">Loader/Cursor</string>
8587
8688 <string name="loader_throttle_support">Loader/Throttle</string>
--- 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 com.example.android.supportv4.R;
2222 import android.os.Bundle;
2323 import android.support.v4.app.Fragment;
2424 import android.support.v4.app.FragmentActivity;
25-import android.support.v4.app.FragmentPager;
25+import android.support.v4.app.FragmentManager;
26+import android.support.v4.app.FragmentPagerAdapter;
2627 import android.support.v4.app.ListFragment;
28+import android.support.v4.view.ViewPager;
2729 import android.util.Log;
2830 import android.view.LayoutInflater;
2931 import android.view.View;
@@ -34,19 +36,22 @@ import android.widget.Button;
3436 import android.widget.ListView;
3537 import android.widget.TextView;
3638
37-public class FragmentPagerSupport extends FragmentActivity
38- implements FragmentPager.Adapter {
39+public class FragmentPagerSupport extends FragmentActivity {
3940 static final int NUM_ITEMS = 10;
4041
41- FragmentPager mPager;
42+ MyAdapter mAdapter;
43+
44+ ViewPager mPager;
4245
4346 @Override
4447 protected void onCreate(Bundle savedInstanceState) {
4548 super.onCreate(savedInstanceState);
4649 setContentView(R.layout.fragment_pager);
4750
48- mPager = (FragmentPager)findViewById(R.id.pager);
49- mPager.setAdapter(this);
51+ mAdapter = new MyAdapter(getSupportFragmentManager());
52+
53+ mPager = (ViewPager)findViewById(R.id.pager);
54+ mPager.setAdapter(mAdapter);
5055
5156 // Watch for button clicks.
5257 Button button = (Button)findViewById(R.id.goto_first);
@@ -63,14 +68,20 @@ public class FragmentPagerSupport extends FragmentActivity
6368 });
6469 }
6570
66- @Override
67- public int getCount() {
68- return NUM_ITEMS;
69- }
71+ public static class MyAdapter extends FragmentPagerAdapter {
72+ public MyAdapter(FragmentManager fm) {
73+ super(fm);
74+ }
7075
71- @Override
72- public Fragment getItem(int position) {
73- return ArrayListFragment.newInstance(position);
76+ @Override
77+ public int getCount() {
78+ return NUM_ITEMS;
79+ }
80+
81+ @Override
82+ public Fragment getItem(int position) {
83+ return ArrayListFragment.newInstance(position);
84+ }
7485 }
7586
7687 public static class ArrayListFragment extends ListFragment {
--- /dev/null
+++ b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStatePagerSupport.java
@@ -0,0 +1,140 @@
1+/*
2+ * Copyright (C) 2011 The Android Open Source Project
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+package com.example.android.supportv4.app;
18+
19+import android.support.v4.app.Fragment;
20+import android.support.v4.app.FragmentActivity;
21+import android.support.v4.app.FragmentManager;
22+import android.support.v4.app.FragmentStatePagerAdapter;
23+import android.support.v4.app.ListFragment;
24+import android.support.v4.view.ViewPager;
25+
26+import android.os.Bundle;
27+import android.util.Log;
28+import android.view.LayoutInflater;
29+import android.view.View;
30+import android.view.ViewGroup;
31+import android.view.View.OnClickListener;
32+import android.widget.ArrayAdapter;
33+import android.widget.Button;
34+import android.widget.ListView;
35+import android.widget.TextView;
36+
37+import com.example.android.supportv4.Cheeses;
38+import com.example.android.supportv4.R;
39+
40+public class FragmentStatePagerSupport extends FragmentActivity {
41+ static final int NUM_ITEMS = 10;
42+
43+ MyAdapter mAdapter;
44+
45+ ViewPager mPager;
46+
47+ @Override
48+ protected void onCreate(Bundle savedInstanceState) {
49+ super.onCreate(savedInstanceState);
50+ setContentView(R.layout.fragment_pager);
51+
52+ mAdapter = new MyAdapter(getSupportFragmentManager());
53+
54+ mPager = (ViewPager)findViewById(R.id.pager);
55+ mPager.setAdapter(mAdapter);
56+
57+ // Watch for button clicks.
58+ Button button = (Button)findViewById(R.id.goto_first);
59+ button.setOnClickListener(new OnClickListener() {
60+ public void onClick(View v) {
61+ mPager.setCurrentItem(0);
62+ }
63+ });
64+ button = (Button)findViewById(R.id.goto_last);
65+ button.setOnClickListener(new OnClickListener() {
66+ public void onClick(View v) {
67+ mPager.setCurrentItem(NUM_ITEMS-1);
68+ }
69+ });
70+ }
71+
72+ public static class MyAdapter extends FragmentStatePagerAdapter {
73+ public MyAdapter(FragmentManager fm) {
74+ super(fm);
75+ }
76+
77+ @Override
78+ public int getCount() {
79+ return NUM_ITEMS;
80+ }
81+
82+ @Override
83+ public Fragment getItem(int position) {
84+ return ArrayListFragment.newInstance(position);
85+ }
86+ }
87+
88+ public static class ArrayListFragment extends ListFragment {
89+ int mNum;
90+
91+ /**
92+ * Create a new instance of CountingFragment, providing "num"
93+ * as an argument.
94+ */
95+ static ArrayListFragment newInstance(int num) {
96+ ArrayListFragment f = new ArrayListFragment();
97+
98+ // Supply num input as an argument.
99+ Bundle args = new Bundle();
100+ args.putInt("num", num);
101+ f.setArguments(args);
102+
103+ return f;
104+ }
105+
106+ /**
107+ * When creating, retrieve this instance's number from its arguments.
108+ */
109+ @Override
110+ public void onCreate(Bundle savedInstanceState) {
111+ super.onCreate(savedInstanceState);
112+ mNum = getArguments() != null ? getArguments().getInt("num") : 1;
113+ }
114+
115+ /**
116+ * The Fragment's UI is just a simple text view showing its
117+ * instance number.
118+ */
119+ @Override
120+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
121+ Bundle savedInstanceState) {
122+ View v = inflater.inflate(R.layout.fragment_pager_list, container, false);
123+ View tv = v.findViewById(R.id.text);
124+ ((TextView)tv).setText("Fragment #" + mNum);
125+ return v;
126+ }
127+
128+ @Override
129+ public void onActivityCreated(Bundle savedInstanceState) {
130+ super.onActivityCreated(savedInstanceState);
131+ setListAdapter(new ArrayAdapter<String>(getActivity(),
132+ android.R.layout.simple_list_item_1, Cheeses.sCheeseStrings));
133+ }
134+
135+ @Override
136+ public void onListItemClick(ListView l, View v, int position, long id) {
137+ Log.i("FragmentList", "Item clicked: " + id);
138+ }
139+ }
140+}
--- 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 @@ public class LoaderThrottleSupport extends FragmentActivity {
6363 /**
6464 * The authority we use to get to our sample provider.
6565 */
66- public static final String AUTHORITY = "com.example.android.apis.support.app.LoaderThrottle";
66+ public static final String AUTHORITY = "com.example.android.apis.supportv4.app.LoaderThrottle";
6767
6868 /**
6969 * Definition of the contract for the main table of our provider.
--- 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 @@ and loaders.</p>
4545 <dd>Demonstrates populating custom menu items from a Fragment.</dd>
4646
4747 <dt><a href="FragmentPagerSupport.html">Fragment Pager Support</a></dt>
48- <dd>A support class for using the Fragment APIs to build
49- a user interface where the user can fling left or right to switch
50- between fragments.</dd>
48+ <dd>Demonstrates the use of the support class ViewPager with a
49+ FragmentPagerAdapter to build a user interface where the user can fling
50+ left or right to switch between fragments.</dd>
51+
52+ <dt><a href="FragmentStatePagerSupport.html">Fragment State Pager Support</a></dt>
53+ <dd>Demonstrates the use of the support class ViewPager with a
54+ FragmentStatePagerAdapter to build a user interface where the user can fling
55+ left or right to switch between fragments. This versions of the adapter
56+ doesn't keep around the fragment instances that ViewPager has destroyed.</dd>
5157
5258 <dt><a href="FragmentReceiveResultSupport.html">Fragment Receive Result</a></dt>
5359 <dd>Demonstrates starting a new Activity from a Fragment, and receiving