android.support.wearable.view
Class FragmentGridPagerAdapter

java.lang.Object
  extended by android.support.wearable.view.GridPagerAdapter
      extended by android.support.wearable.view.FragmentGridPagerAdapter

public abstract class FragmentGridPagerAdapter
extends GridPagerAdapter

An implementation of GridPagerAdapter which represents each page as a Fragment.

A minimal implementation needs only the abstract methods: GridPagerAdapter.getRowCount(), GridPagerAdapter.getColumnCount(int), getFragment(int, int).

If any changes are made to the data, GridPagerAdapter.notifyDataSetChanged() must be called to notify the adapter of the change, so it can be reflected in the View.

If pages the data at be inserted or removed, performance can be improved by implementing getFragmentId(int, int) to to provide a stable ID for each item, based on the content.


Constructor Summary
FragmentGridPagerAdapter(FragmentManager fm)
           
 
Method Summary
protected  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.
 int getCurrentColumnForRow(int row, int currentColumn)
          Returns the column to arrive at when navigating vertically to the specified row.
abstract  Fragment getFragment(int row, int column)
          Returns the Fragment at the specified row number and column number.
protected  long getFragmentId(int row, int column)
          Returns a unique identifier for the Fragment at the given row/column position.
protected  Fragment instantiateItem(ViewGroup container, int row, int column)
          Creates the page for the given position.
 boolean isViewFromObject(View view, java.lang.Object object)
          Determines whether a page View is associated with a specific key object as returned by GridPagerAdapter.instantiateItem(ViewGroup, int, int).
 
Methods inherited from class android.support.wearable.view.GridPagerAdapter
getBackground, getColumnCount, getRowCount, notifyDataSetChanged, registerDataSetObserver, restoreState, saveState, setCurrentColumnForRow, startUpdate, unregisterDataSetObserver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FragmentGridPagerAdapter

public FragmentGridPagerAdapter(FragmentManager fm)
Method Detail

getFragment

public abstract Fragment getFragment(int row,
                                     int column)
Returns the Fragment at the specified row number and column number.

Fragment instances MAY be stored and reused ONLY if no structural changes are made to the data set or if getFragmentId(int, int) is overridden to provide a stable identifier for each the item at each position.

Parameters:
row - the row of the position
column - the column of the position

getCurrentColumnForRow

public int getCurrentColumnForRow(int row,
                                  int currentColumn)
Description copied from class: GridPagerAdapter
Returns the column to arrive at when navigating vertically to the specified row.

The default implementation simply returns 0.

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

getFragmentId

protected long getFragmentId(int row,
                             int column)
Returns a unique identifier for the Fragment at the given row/column position.

The default implementation returns a fixed number based on the position. Subclasses should override this method if the positions of items can change.

Parameters:
row - the row that this item is at
column - the column within this row that the item is at
Returns:
Unique identifier for the item at position

instantiateItem

protected Fragment instantiateItem(ViewGroup container,
                                   int row,
                                   int column)
Description copied from class: GridPagerAdapter
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 GridPagerAdapter.finishUpdate(ViewGroup)

Specified by:
instantiateItem in class GridPagerAdapter
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

isViewFromObject

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

Specified by:
isViewFromObject in class GridPagerAdapter
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

destroyItem

protected void destroyItem(ViewGroup container,
                           int row,
                           int column,
                           java.lang.Object object)
Description copied from class: GridPagerAdapter
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 GridPagerAdapter.finishUpdate(ViewGroup).

Specified by:
destroyItem in class GridPagerAdapter
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 GridPagerAdapter.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.

Overrides:
finishUpdate in class GridPagerAdapter
Parameters:
container - The containing View which is displaying this adapter's page views