PagerAdapter.java revision 31bb17f88734747206586eeb3eb57123e3cc2434
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 { 798fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell private DataSetObservable mObservable = new DataSetObservable(); 803661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell 813661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell public static final int POSITION_UNCHANGED = -1; 823661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell public static final int POSITION_NONE = -2; 833661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell 845c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 853661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * Return the number of views available. 865c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 875c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public abstract int getCount(); 885c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 895c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 905c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Called when a change in the shown pages is going to start being made. 915c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param container The containing View which is displaying this adapter's 925c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * page views. 935c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 94583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell public void startUpdate(ViewGroup container) { 95583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell startUpdate((View) container); 96583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell } 975c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 985c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 995c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Create the page for the given position. The adapter is responsible 1005c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * for adding the view to the container given here, although it only 1015c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * must ensure this is done by the time it returns from 1020574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link #finishUpdate(ViewGroup)}. 1035c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * 1045c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param container The containing View in which the page will be shown. 1055c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param position The page position to be instantiated. 1065c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @return Returns an Object representing the new page. This does not 1075c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * need to be a View, but can be some other container of the page. 1085c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 109583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell public Object instantiateItem(ViewGroup container, int position) { 110583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell return instantiateItem((View) container, position); 111583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell } 112583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell 113583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell /** 114583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * Remove a page for the given position. The adapter is responsible 115583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * for removing the view from its container, although it only must ensure 1160574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * this is done by the time it returns from {@link #finishUpdate(ViewGroup)}. 117583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * 118583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param container The containing View from which the page will be removed. 119583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param position The page position to be removed. 120583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param object The same object that was returned by 121583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * {@link #instantiateItem(View, int)}. 122583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell */ 123583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell public void destroyItem(ViewGroup container, int position, Object object) { 124583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell destroyItem((View) container, position, object); 125583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell } 126583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell 127583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell /** 128583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * Called to inform the adapter of which item is currently considered to 129583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * be the "primary", that is the one show to the user as the current page. 130583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * 131583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param container The containing View from which the page will be removed. 132583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param position The page position that is now the primary. 133583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param object The same object that was returned by 134583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * {@link #instantiateItem(View, int)}. 135583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell */ 136583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell public void setPrimaryItem(ViewGroup container, int position, Object object) { 137583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell setPrimaryItem((View) container, position, object); 138583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell } 139583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell 140583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell /** 141583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * Called when the a change in the shown pages has been completed. At this 142583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * point you must ensure that all of the pages have actually been added or 143583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * removed from the container as appropriate. 144583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param container The containing View which is displaying this adapter's 145583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * page views. 146583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell */ 147583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell public void finishUpdate(ViewGroup container) { 148583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell finishUpdate((View) container); 149583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell } 150583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell 151583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell /** 152583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * Called when a change in the shown pages is going to start being made. 153583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param container The containing View which is displaying this adapter's 154583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * page views. 155583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * 156583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @deprecated Use {@link #startUpdate(ViewGroup)} 157583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell */ 158583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell public void startUpdate(View container) { 159583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell } 160583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell 161583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell /** 162583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * Create the page for the given position. The adapter is responsible 163583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * for adding the view to the container given here, although it only 164583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * must ensure this is done by the time it returns from 165583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * {@link #finishUpdate(ViewGroup)}. 166583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * 167583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param container The containing View in which the page will be shown. 168583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param position The page position to be instantiated. 169583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @return Returns an Object representing the new page. This does not 170583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * need to be a View, but can be some other container of the page. 171583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * 172583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @deprecated Use {@link #instantiateItem(ViewGroup, int)} 173583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell */ 174583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell public Object instantiateItem(View container, int position) { 175583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell throw new UnsupportedOperationException( 176583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell "Required method instantiateItem was not overridden"); 177583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell } 1785c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 1795c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 1805c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Remove a page for the given position. The adapter is responsible 1815c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * for removing the view from its container, although it only must ensure 1820574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * this is done by the time it returns from {@link #finishUpdate(View)}. 1835c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * 1845c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param container The containing View from which the page will be removed. 1855c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param position The page position to be removed. 1865c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param object The same object that was returned by 1875c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * {@link #instantiateItem(View, int)}. 188583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * 189583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @deprecated Use {@link #destroyItem(ViewGroup, int, Object)} 1905c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 191583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell public void destroyItem(View container, int position, Object object) { 192583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell throw new UnsupportedOperationException("Required method destroyItem was not overridden"); 193583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell } 1945c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 1955c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 1962a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * Called to inform the adapter of which item is currently considered to 1972a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * be the "primary", that is the one show to the user as the current page. 1982a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * 1992a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * @param container The containing View from which the page will be removed. 2002a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * @param position The page position that is now the primary. 2012a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * @param object The same object that was returned by 2022a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * {@link #instantiateItem(View, int)}. 203583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * 204583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @deprecated Use {@link #setPrimaryItem(ViewGroup, int, Object)} 2052a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn */ 2062a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn public void setPrimaryItem(View container, int position, Object object) { 2072a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 2082a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 2092a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn /** 2105c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Called when the a change in the shown pages has been completed. At this 2115c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * point you must ensure that all of the pages have actually been added or 2125c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * removed from the container as appropriate. 2135c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param container The containing View which is displaying this adapter's 2145c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * page views. 215583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * 216583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @deprecated Use {@link #setPrimaryItem(ViewGroup, int, Object)} 2175c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 218583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell public void finishUpdate(View container) { 219583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell } 2205c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 221583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell /** 222583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * Determines whether a page View is associated with a specific key object 223583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * as returned by {@link #instantiateItem(ViewGroup, int)}. This method is 224583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * required for a PagerAdapter to function properly. 225583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * 226583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param view Page View to check for association with <code>object</code> 227583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param object Object to check for association with <code>view</code> 228583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @return true if <code>view</code> is associated with the key object <code>object</code> 229583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell */ 2305c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public abstract boolean isViewFromObject(View view, Object object); 2315c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 232583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell /** 233583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * Save any instance state associated with this adapter and its pages that should be 234583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * restored if the current UI state needs to be reconstructed. 235583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * 236583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @return Saved state for this adapter 237583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell */ 238583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell public Parcelable saveState() { 239583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell return null; 240583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell } 2415c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 242583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell /** 243583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * Restore any instance state associated with this adapter and its pages 244583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * that was previously saved by {@link #saveState()}. 245583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * 246583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param state State previously saved by a call to {@link #saveState()} 247583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell * @param loader A ClassLoader that should be used to instantiate any restored objects 248583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell */ 249583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell public void restoreState(Parcelable state, ClassLoader loader) { 250583d8a1ff64c7c59dd4e11759f3d8e994ce878d9Adam Powell } 2513661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell 2523661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell /** 2533661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * Called when the host view is attempting to determine if an item's position 2543661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * has changed. Returns {@link #POSITION_UNCHANGED} if the position of the given 2553661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * item has not changed or {@link #POSITION_NONE} if the item is no longer present 2563661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * in the adapter. 2573661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * 2583661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * <p>The default implementation assumes that items will never 2593661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * change position and always returns {@link #POSITION_UNCHANGED}. 2603661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * 2613661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * @param object Object representing an item, previously returned by a call to 2623661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * {@link #instantiateItem(View, int)}. 2633661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * @return object's new position index from [0, {@link #getCount()}), 2643661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * {@link #POSITION_UNCHANGED} if the object's position has not changed, 2653661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * or {@link #POSITION_NONE} if the item is no longer present. 2663661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell */ 2673661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell public int getItemPosition(Object object) { 2683661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell return POSITION_UNCHANGED; 2693661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell } 2703661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell 2713661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell /** 2723661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * This method should be called by the application if the data backing this adapter has changed 2733661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell * and associated views should update. 2743661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell */ 2753661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell public void notifyDataSetChanged() { 2768fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell mObservable.notifyChanged(); 2778fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell } 2788fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell 2798fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell void registerDataSetObserver(DataSetObserver observer) { 2808fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell mObservable.registerObserver(observer); 2813661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell } 2823661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell 2838fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell void unregisterDataSetObserver(DataSetObserver observer) { 2848fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell mObservable.unregisterObserver(observer); 2858fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell } 2868fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell 2878fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell /** 2888fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell * This method may be called by the ViewPager to obtain a title string 2898fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell * to describe the specified page. This method may return null 2908fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell * indicating no title for this page. The default implementation returns 2918fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell * null. 2928fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell * 2938fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell * @param position The position of the title requested 2948fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell * @return A title for the requested page 2958fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell */ 2968fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell public CharSequence getPageTitle(int position) { 2978fffe01871be1806a1bdefa1f7213b660fcf5ac0Adam Powell return null; 2983661ad6c9143d58f741568f940f77ca9d38dec47Adam Powell } 299a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell 300a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell /** 301a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell * Returns the proportional width of a given page as a percentage of the 30231bb17f88734747206586eeb3eb57123e3cc2434Adam Powell * ViewPager's measured width from (0.f-1.f] 303a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell * 304a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell * @param position The position of the page requested 305a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell * @return Proportional width for the given page position 306a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell */ 307a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell public float getPageWidth(int position) { 308a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell return 1.f; 309a4a06a94df00575480d789b60ea25ce59184df1fAdam Powell } 3105c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn} 311