android.support.wearable.view
Class GridPagerAdapter

java.lang.Object
  extended by android.support.wearable.view.GridPagerAdapter
Direct Known Subclasses:
FragmentGridPagerAdapter

public abstract class GridPagerAdapter
extends java.lang.Object

This component is responsible for providing views requested by a GridViewPager.

Content is organized into rows and columns of pages, where each page is represented by a View. Each row may contain a different number of columns.

In addition to content views, this adapter is also queried for backgrounds to be displayed for each page. When the same background spans multiple pages, it's automatically zoomed and panned to create a parallax effect against the movement of the page content as it moves. By default, no background is provided.


Constructor Summary
GridPagerAdapter()
           
 
Method Summary
protected abstract  void destroyItem(ViewGroup container, int row, int column, java.lang.Object object)
          Removes a page for the given position.
protected  void finishUpdate(ViewGroup container)
          Called when the a change in the shown pages has been completed.
 ImageReference getBackground(int row, int column)
          Provides a reference to an image to be displayed as the background for this page.
abstract  int getColumnCount(int row)
          Returns the maximum number of columns for each row.
 int getCurrentColumnForRow(int row, int currentColumn)
          Returns the column to arrive at when navigating vertically to the specified row.
abstract  int getRowCount()
          Returns the number of rows available.
protected abstract  java.lang.Object instantiateItem(ViewGroup container, int row, int column)
          Creates the page for the given position.
abstract  boolean isViewFromObject(View view, java.lang.Object object)
          Determines whether a page View is associated with a specific key object as returned by instantiateItem(ViewGroup, int, int).
 void notifyDataSetChanged()
          This method should be called by the application if the data backing this adapter has changed and associated views should update.
 void registerDataSetObserver(DataSetObserver observer)
          Register an observer to receive callbacks related to the adapter's data changing.
 void restoreState(Parcelable savedState, java.lang.ClassLoader classLoader)
          Restores the previously saved state of this adapter.
 Parcelable saveState()
          Saves the current state of this adapter.
protected  void setCurrentColumnForRow(int row, int currentColumn)
          Called to inform the adapter of which column is now current for the given row.
protected  void startUpdate(ViewGroup container)
          Called when a change in the shown pages is going to start being made.
 void unregisterDataSetObserver(DataSetObserver observer)
          Unregister an observer from callbacks related to the adapter's data changing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridPagerAdapter

public GridPagerAdapter()
Method Detail

getRowCount

public abstract int getRowCount()
Returns the number of rows available.


getColumnCount

public abstract int getColumnCount(int row)
Returns the maximum number of columns for each row. The number of columns may vary by row.


getCurrentColumnForRow

public int getCurrentColumnForRow(int row,
                                  int currentColumn)
Returns the column to arrive at when navigating vertically to the specified row.

The default implementation simply returns 0.

Parameters:
row - the row in question
currentColumn - the column which is currently centered
Returns:
the column to arrive at

setCurrentColumnForRow

protected void setCurrentColumnForRow(int row,
                                      int currentColumn)
Called to inform the adapter of which column is now current for the given row. This information could be stored and used to implement getCurrentColumnForRow(int, int). The default implementation does nothing.

Parameters:
row - the row for the column change
currentColumn - the column which is now current

startUpdate

protected void startUpdate(ViewGroup container)
Called when a change in the shown pages is going to start being made.

Parameters:
container - The containing View which is displaying this adapter's page views.

instantiateItem

protected abstract java.lang.Object instantiateItem(ViewGroup container,
                                                    int row,
                                                    int column)
Creates the page for the given position. The adapter is responsible for adding the view to the container given here, although it only must ensure this is done by the time it returns from finishUpdate(ViewGroup)

Parameters:
container - containing View in which the page will be shown
row - the row to be instantiated
column - the column within the row to be instantiated
Returns:
a an object representing the new page

destroyItem

protected abstract void destroyItem(ViewGroup container,
                                    int row,
                                    int column,
                                    java.lang.Object object)
Removes a page for the given position. The adapter is responsible for removing the view from its container, although it only must ensure this is done by the time it returns from finishUpdate(ViewGroup).

Parameters:
container - The containing View from which the page will be removed.
row - the row to be destroyed
column - the column within the row to be destroyed
object - The same object that was returned by instantiateItem(ViewGroup, int, int).

finishUpdate

protected void finishUpdate(ViewGroup container)
Called when the a change in the shown pages has been completed. At this point you must ensure that all of the pages have actually been added or removed from the container as appropriate.

Parameters:
container - The containing View which is displaying this adapter's page views

isViewFromObject

public abstract boolean isViewFromObject(View view,
                                         java.lang.Object object)
Determines whether a page View is associated with a specific key object as returned by instantiateItem(ViewGroup, int, int). This method is required for a PagerAdapter to function properly.

Parameters:
view - Page View to check for association with object
object - Object to check for association with view
Returns:
true if view is associated with the key object object

getBackground

public ImageReference getBackground(int row,
                                    int column)
Provides a reference to an image to be displayed as the background for this page.

Parameters:
row - the row of the page
column - the column of the page
Returns:
a reference to an image to display, or ImageReference.NONE for no page background

registerDataSetObserver

public void registerDataSetObserver(DataSetObserver observer)
Register an observer to receive callbacks related to the adapter's data changing.

Parameters:
observer - The android.database.DataSetObserver which will receive callbacks.

unregisterDataSetObserver

public void unregisterDataSetObserver(DataSetObserver observer)
Unregister an observer from callbacks related to the adapter's data changing.

Parameters:
observer - The android.database.DataSetObserver which will be unregistered.

notifyDataSetChanged

public void notifyDataSetChanged()
This method should be called by the application if the data backing this adapter has changed and associated views should update.


saveState

public Parcelable saveState()
Saves the current state of this adapter.


restoreState

public void restoreState(Parcelable savedState,
                         java.lang.ClassLoader classLoader)
Restores the previously saved state of this adapter.