15c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn/*
25c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Copyright (C) 2011 The Android Open Source Project
35c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn *
45c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License");
55c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * you may not use this file except in compliance with the License.
65c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * You may obtain a copy of the License at
75c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn *
85c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn *      http://www.apache.org/licenses/LICENSE-2.0
95c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn *
105c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Unless required by applicable law or agreed to in writing, software
115c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS,
125c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * See the License for the specific language governing permissions and
145c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * limitations under the License.
155c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */
165c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
175c1637087453de15e31861f073eae5133c4e9f7bDianne Hackbornpackage android.support.v4.view;
185c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
198fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powellimport android.database.DataSetObservable;
208fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powellimport android.database.DataSetObserver;
215c1637087453de15e31861f073eae5133c4e9f7bDianne Hackbornimport android.os.Parcelable;
225c1637087453de15e31861f073eae5133c4e9f7bDianne Hackbornimport android.view.View;
23583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powellimport android.view.ViewGroup;
245c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
255c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn/**
265c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Base class providing the adapter to populate pages inside of
275c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * a {@link ViewPager}.  You will most likely want to use a more
285c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * specific implementation of this, such as
295c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * {@link android.support.v4.app.FragmentPagerAdapter} or
305c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * {@link android.support.v4.app.FragmentStatePagerAdapter}.
31583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell *
32583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * <p>When you implement a PagerAdapter, you must override the following methods
33583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * at minimum:</p>
34583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * <ul>
35583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * <li>{@link #instantiateItem(ViewGroup, int)}</li>
36583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * <li>{@link #destroyItem(ViewGroup, int, Object)}</li>
37583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * <li>{@link #getCount()}</li>
38583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * <li>{@link #isViewFromObject(View, Object)}</li>
39583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * </ul>
40583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell *
41583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * <p>PagerAdapter is more general than the adapters used for
42583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * {@link android.widget.AdapterView AdapterViews}. Instead of providing a
43583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * View recycling mechanism directly ViewPager uses callbacks to indicate the
44583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * steps taken during an update. A PagerAdapter may implement a form of View
45583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * recycling if desired or use a more sophisticated method of managing page
46583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * Views such as Fragment transactions where each page is represented by its
47583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * own Fragment.</p>
48583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell *
49583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * <p>ViewPager associates each page with a key Object instead of working with
50583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * Views directly. This key is used to track and uniquely identify a given page
51583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * independent of its position in the adapter. A call to the PagerAdapter method
52583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * {@link #startUpdate(ViewGroup)} indicates that the contents of the ViewPager
53583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * are about to change. One or more calls to {@link #instantiateItem(ViewGroup, int)}
54583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * and/or {@link #destroyItem(ViewGroup, int, Object)} will follow, and the end
55583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * of an update will be signaled by a call to {@link #finishUpdate(ViewGroup)}.
56583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * By the time {@link #finishUpdate(ViewGroup) finishUpdate} returns the views
57583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * associated with the key objects returned by
58583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * {@link #instantiateItem(ViewGroup, int) instantiateItem} should be added to
59583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * the parent ViewGroup passed to these methods and the views associated with
60583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * the keys passed to {@link #destroyItem(ViewGroup, int, Object) destroyItem}
61583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * should be removed. The method {@link #isViewFromObject(View, Object)} identifies
62583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * whether a page View is associated with a given key object.</p>
63583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell *
64583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * <p>A very simple PagerAdapter may choose to use the page Views themselves
65583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * as key objects, returning them from {@link #instantiateItem(ViewGroup, int)}
66583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * after creation and adding them to the parent ViewGroup. A matching
67583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * {@link #destroyItem(ViewGroup, int, Object)} implementation would remove the
68583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * View from the parent ViewGroup and {@link #isViewFromObject(View, Object)}
69583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * could be implemented as <code>return view == object;</code>.</p>
70583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell *
71583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * <p>PagerAdapter supports data set changes. Data set changes must occur on the
72583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * main thread and must end with a call to {@link #notifyDataSetChanged()} similar
73583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * to AdapterView adapters derived from {@link android.widget.BaseAdapter}. A data
74583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * set change may involve pages being added, removed, or changing position. The
75583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * ViewPager will keep the current page active provided the adapter implements
76583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * the method {@link #getItemPosition(Object)}.</p>
775c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */
785c1637087453de15e31861f073eae5133c4e9f7bDianne Hackbornpublic abstract class PagerAdapter {
7938cc44cffde90f6fe689b0df6b82f49481a981f7Chris Banes    private final DataSetObservable mObservable = new DataSetObservable();
8038cc44cffde90f6fe689b0df6b82f49481a981f7Chris Banes    private DataSetObserver mViewPagerObserver;
813661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell
823661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell    public static final int POSITION_UNCHANGED = -1;
833661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell    public static final int POSITION_NONE = -2;
843661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell
855c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
863661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     * Return the number of views available.
875c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
885c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    public abstract int getCount();
895c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
905c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
915c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * Called when a change in the shown pages is going to start being made.
925c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @param container The containing View which is displaying this adapter's
935c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * page views.
945c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
95583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    public void startUpdate(ViewGroup container) {
96583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell        startUpdate((View) container);
97583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    }
985c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
995c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
1005c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * Create the page for the given position.  The adapter is responsible
1015c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * for adding the view to the container given here, although it only
1025c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * must ensure this is done by the time it returns from
1030574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * {@link #finishUpdate(ViewGroup)}.
1045c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     *
1055c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @param container The containing View in which the page will be shown.
1065c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @param position The page position to be instantiated.
1075c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @return Returns an Object representing the new page.  This does not
1085c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * need to be a View, but can be some other container of the page.
1095c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
110583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    public Object instantiateItem(ViewGroup container, int position) {
111583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell        return instantiateItem((View) container, position);
112583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    }
113583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell
114583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    /**
115583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * Remove a page for the given position.  The adapter is responsible
116583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * for removing the view from its container, although it only must ensure
1170574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * this is done by the time it returns from {@link #finishUpdate(ViewGroup)}.
118583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     *
119583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param container The containing View from which the page will be removed.
120583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param position The page position to be removed.
121583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param object The same object that was returned by
122583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * {@link #instantiateItem(View, int)}.
123583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     */
124583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    public void destroyItem(ViewGroup container, int position, Object object) {
125583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell        destroyItem((View) container, position, object);
126583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    }
127583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell
128583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    /**
129583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * Called to inform the adapter of which item is currently considered to
130583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * be the "primary", that is the one show to the user as the current page.
131583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     *
132583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param container The containing View from which the page will be removed.
133583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param position The page position that is now the primary.
134583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param object The same object that was returned by
135583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * {@link #instantiateItem(View, int)}.
136583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     */
137583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    public void setPrimaryItem(ViewGroup container, int position, Object object) {
138583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell        setPrimaryItem((View) container, position, object);
139583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    }
140583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell
141583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    /**
142583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * Called when the a change in the shown pages has been completed.  At this
143583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * point you must ensure that all of the pages have actually been added or
144583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * removed from the container as appropriate.
145583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param container The containing View which is displaying this adapter's
146583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * page views.
147583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     */
148583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    public void finishUpdate(ViewGroup container) {
149583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell        finishUpdate((View) container);
150583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    }
151583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell
152583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    /**
153583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * Called when a change in the shown pages is going to start being made.
154583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param container The containing View which is displaying this adapter's
155583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * page views.
156583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     *
157583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @deprecated Use {@link #startUpdate(ViewGroup)}
158583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     */
159d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette    @Deprecated
160583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    public void startUpdate(View container) {
161583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    }
162583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell
163583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    /**
164583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * Create the page for the given position.  The adapter is responsible
165583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * for adding the view to the container given here, although it only
166583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * must ensure this is done by the time it returns from
167583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * {@link #finishUpdate(ViewGroup)}.
168583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     *
169583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param container The containing View in which the page will be shown.
170583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param position The page position to be instantiated.
171583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @return Returns an Object representing the new page.  This does not
172583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * need to be a View, but can be some other container of the page.
173583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     *
174583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @deprecated Use {@link #instantiateItem(ViewGroup, int)}
175583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     */
176d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette    @Deprecated
177583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    public Object instantiateItem(View container, int position) {
178583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell        throw new UnsupportedOperationException(
179583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell                "Required method instantiateItem was not overridden");
180583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    }
1815c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
1825c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
1835c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * Remove a page for the given position.  The adapter is responsible
1845c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * for removing the view from its container, although it only must ensure
1850574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * this is done by the time it returns from {@link #finishUpdate(View)}.
1865c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     *
1875c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @param container The containing View from which the page will be removed.
1885c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @param position The page position to be removed.
1895c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @param object The same object that was returned by
1905c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * {@link #instantiateItem(View, int)}.
191583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     *
192583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @deprecated Use {@link #destroyItem(ViewGroup, int, Object)}
1935c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
194d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette    @Deprecated
195583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    public void destroyItem(View container, int position, Object object) {
196583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell        throw new UnsupportedOperationException("Required method destroyItem was not overridden");
197583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    }
1985c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
1995c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
2002a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * Called to inform the adapter of which item is currently considered to
2012a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * be the "primary", that is the one show to the user as the current page.
2022a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     *
2032a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * @param container The containing View from which the page will be removed.
2042a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * @param position The page position that is now the primary.
2052a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * @param object The same object that was returned by
2062a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * {@link #instantiateItem(View, int)}.
207583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     *
208583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @deprecated Use {@link #setPrimaryItem(ViewGroup, int, Object)}
2092a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     */
210d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette    @Deprecated
2112a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    public void setPrimaryItem(View container, int position, Object object) {
2122a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    }
2132a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
2142a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    /**
2155c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * Called when the a change in the shown pages has been completed.  At this
2165c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * point you must ensure that all of the pages have actually been added or
2175c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * removed from the container as appropriate.
2185c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @param container The containing View which is displaying this adapter's
2195c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * page views.
220583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     *
221fd0bd8336ced5879d3aaa8d96195ba8dce5b5dacAdam Powell     * @deprecated Use {@link #finishUpdate(ViewGroup)}
2225c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
223d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette    @Deprecated
224583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    public void finishUpdate(View container) {
225583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    }
2265c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
227583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    /**
228583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * Determines whether a page View is associated with a specific key object
229583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * as returned by {@link #instantiateItem(ViewGroup, int)}. This method is
230583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * required for a PagerAdapter to function properly.
231583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     *
232583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param view Page View to check for association with <code>object</code>
233583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param object Object to check for association with <code>view</code>
234583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @return true if <code>view</code> is associated with the key object <code>object</code>
235583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     */
2365c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    public abstract boolean isViewFromObject(View view, Object object);
2375c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
238583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    /**
239583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * Save any instance state associated with this adapter and its pages that should be
240583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * restored if the current UI state needs to be reconstructed.
241583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     *
242583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @return Saved state for this adapter
243583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     */
244583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    public Parcelable saveState() {
245583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell        return null;
246583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    }
2475c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
248583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    /**
249583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * Restore any instance state associated with this adapter and its pages
250583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * that was previously saved by {@link #saveState()}.
251583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     *
252583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param state State previously saved by a call to {@link #saveState()}
253583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     * @param loader A ClassLoader that should be used to instantiate any restored objects
254583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell     */
255583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    public void restoreState(Parcelable state, ClassLoader loader) {
256583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell    }
2573661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell
2583661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell    /**
2593661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     * Called when the host view is attempting to determine if an item's position
2603661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     * has changed. Returns {@link #POSITION_UNCHANGED} if the position of the given
2613661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     * item has not changed or {@link #POSITION_NONE} if the item is no longer present
2623661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     * in the adapter.
2633661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     *
2643661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     * <p>The default implementation assumes that items will never
2653661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     * change position and always returns {@link #POSITION_UNCHANGED}.
2663661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     *
2673661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     * @param object Object representing an item, previously returned by a call to
2683661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     *               {@link #instantiateItem(View, int)}.
2693661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     * @return object's new position index from [0, {@link #getCount()}),
2703661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     *         {@link #POSITION_UNCHANGED} if the object's position has not changed,
2713661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     *         or {@link #POSITION_NONE} if the item is no longer present.
2723661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     */
2733661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell    public int getItemPosition(Object object) {
2743661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell        return POSITION_UNCHANGED;
2753661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell    }
2763661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell
2773661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell    /**
2783661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     * This method should be called by the application if the data backing this adapter has changed
2793661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     * and associated views should update.
2803661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell     */
2813661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell    public void notifyDataSetChanged() {
28238cc44cffde90f6fe689b0df6b82f49481a981f7Chris Banes        synchronized (this) {
28338cc44cffde90f6fe689b0df6b82f49481a981f7Chris Banes            if (mViewPagerObserver != null) {
28438cc44cffde90f6fe689b0df6b82f49481a981f7Chris Banes                mViewPagerObserver.onChanged();
28538cc44cffde90f6fe689b0df6b82f49481a981f7Chris Banes            }
28638cc44cffde90f6fe689b0df6b82f49481a981f7Chris Banes        }
2878fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell        mObservable.notifyChanged();
2888fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell    }
2898fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell
290fba5d14230cf87eb238050b4a1ebe457a85dc0b6Adam Cohen    /**
291fba5d14230cf87eb238050b4a1ebe457a85dc0b6Adam Cohen     * Register an observer to receive callbacks related to the adapter's data changing.
292fba5d14230cf87eb238050b4a1ebe457a85dc0b6Adam Cohen     *
293fba5d14230cf87eb238050b4a1ebe457a85dc0b6Adam Cohen     * @param observer The {@link android.database.DataSetObserver} which will receive callbacks.
294fba5d14230cf87eb238050b4a1ebe457a85dc0b6Adam Cohen     */
295fba5d14230cf87eb238050b4a1ebe457a85dc0b6Adam Cohen    public void registerDataSetObserver(DataSetObserver observer) {
2968fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell        mObservable.registerObserver(observer);
2973661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell    }
2983661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell
299fba5d14230cf87eb238050b4a1ebe457a85dc0b6Adam Cohen    /**
300fba5d14230cf87eb238050b4a1ebe457a85dc0b6Adam Cohen     * Unregister an observer from callbacks related to the adapter's data changing.
301fba5d14230cf87eb238050b4a1ebe457a85dc0b6Adam Cohen     *
302fba5d14230cf87eb238050b4a1ebe457a85dc0b6Adam Cohen     * @param observer The {@link android.database.DataSetObserver} which will be unregistered.
303fba5d14230cf87eb238050b4a1ebe457a85dc0b6Adam Cohen     */
304fba5d14230cf87eb238050b4a1ebe457a85dc0b6Adam Cohen    public void unregisterDataSetObserver(DataSetObserver observer) {
3058fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell        mObservable.unregisterObserver(observer);
3068fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell    }
3078fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell
30838cc44cffde90f6fe689b0df6b82f49481a981f7Chris Banes    void setViewPagerObserver(DataSetObserver observer) {
30938cc44cffde90f6fe689b0df6b82f49481a981f7Chris Banes        synchronized (this) {
31038cc44cffde90f6fe689b0df6b82f49481a981f7Chris Banes            mViewPagerObserver = observer;
31138cc44cffde90f6fe689b0df6b82f49481a981f7Chris Banes        }
31238cc44cffde90f6fe689b0df6b82f49481a981f7Chris Banes    }
31338cc44cffde90f6fe689b0df6b82f49481a981f7Chris Banes
3148fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell    /**
3158fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell     * This method may be called by the ViewPager to obtain a title string
3168fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell     * to describe the specified page. This method may return null
3178fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell     * indicating no title for this page. The default implementation returns
3188fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell     * null.
3198fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell     *
3208fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell     * @param position The position of the title requested
3218fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell     * @return A title for the requested page
3228fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell     */
3238fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell    public CharSequence getPageTitle(int position) {
3248fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell        return null;
3253661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell    }
326a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell
327a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell    /**
328a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell     * Returns the proportional width of a given page as a percentage of the
32931bb17f88734747206586eeb3eb57123e3cc2434Adam Powell     * ViewPager's measured width from (0.f-1.f]
330a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell     *
331a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell     * @param position The position of the page requested
332a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell     * @return Proportional width for the given page position
333a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell     */
334a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell    public float getPageWidth(int position) {
335a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell        return 1.f;
336a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell    }
3375c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn}
338