public abstract class

GridPagerAdapter

extends Object

Note: The Wearable Support Library classes under the android.support.wearable package are subject to change. For the full Android API reference, see Reference.

java.lang.Object
   ↳ android.support.wearable.view.GridPagerAdapter
Known Direct Subclasses

Class Overview

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.

Summary

Constants
int OPTION_DISABLE_PARALLAX Disables zooming and parallax scrolling of the background.
int PAGE_DEFAULT_OPTIONS Default background options.
Fields
public static final Drawable BACKGROUND_NONE This value indicates that no background should drawn.
public static final Point POSITION_NONE
public static final Point POSITION_UNCHANGED
Public Constructors
GridPagerAdapter()
Public Methods
abstract void destroyItem(ViewGroup container, int row, int column, Object object)
Removes a page for the given position.
void finishUpdate(ViewGroup container)
Called when the a change in the shown pages has been completed.
Drawable getBackgroundForPage(int row, int column)
Provides content to be displayed as background for a specific page.
Drawable getBackgroundForRow(int row)
Provides content to be displayed as the default background for all pages on the given row.
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.
Point getItemPosition(Object object)
Called when the host view is attempting to determine if an item's position has changed.
int getOptionsForPage(int row, int column)
Provides a set of features to apply to a page background.
abstract int getRowCount()
Returns the number of rows available.
abstract Object instantiateItem(ViewGroup container, int row, int column)
Creates the page for the given position.
abstract boolean isViewFromObject(View view, 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 notifyPageBackgroundChanged(int row, int column)
This method should be called if the value returned by getBackgroundForPage(int, int) or options returned by getOptionsForPage(int, int) change.
void notifyRowBackgroundChanged(int row)
This method should be called if the value returned by getBackgroundForRow(int) changes.
void registerDataSetObserver(DataSetObserver observer)
Register an observer to receive callbacks related to the adapter's data changing.
void restoreState(Parcelable savedState, ClassLoader classLoader)
Restores the previously saved state of this adapter.
Parcelable saveState()
Saves the current state of this adapter.
void setCurrentColumnForRow(int row, int currentColumn)
Called to inform the adapter of which column is now current for the given row.
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.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int OPTION_DISABLE_PARALLAX

Disables zooming and parallax scrolling of the background.

Constant Value: 1 (0x00000001)

public static final int PAGE_DEFAULT_OPTIONS

Default background options. Parallax scrolling is enabled.

Constant Value: 0 (0x00000000)

Fields

public static final Drawable BACKGROUND_NONE

This value indicates that no background should drawn. See getBackgroundForRow(int) and getBackgroundForPage(int, int) for specific effects.

public static final Point POSITION_NONE

public static final Point POSITION_UNCHANGED

Public Constructors

public GridPagerAdapter ()

Public Methods

public abstract void destroyItem (ViewGroup container, int row, int column, 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).

public 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

public Drawable getBackgroundForPage (int row, int column)

Provides content to be displayed as background for a specific page.

The return value BACKGROUND_NONE indicates that there is no page-specific background. and the row background should be used (if any).

The return value of this method can be cached. notifyPageBackgroundChanged(int, int) may be used to invalidate a previously returned value. getBackgroundForPage(int, int) will then be called to request the new value when necessary.

Parameters
row the row of the page
column the column of the page

public Drawable getBackgroundForRow (int row)

Provides content to be displayed as the default background for all pages on the given row.

The return value BACKGROUND_NONE causes no background to be displayed, except for those applied by getBackgroundForPage(int, int).

The return value of this method can be cached. notifyRowBackgroundChanged(int) may be used to invalidate a previously returned value. getBackgroundForRow(int) will then be called to request the new value when necessary.

Parameters
row the row of the page
Returns
  • a drawable to display for the row

public abstract int getColumnCount (int row)

Returns the maximum number of columns for each row. The number of columns may vary by row.

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

public Point getItemPosition (Object object)

Called when the host view is attempting to determine if an item's position has changed. Returns POSITION_UNCHANGED if the position of the given item has not changed or POSITION_NONE if the item is no longer present in the adapter.

The default implementation assumes that all items have been removed and always returns POSITION_NONE. This causes all fragments to be detached and re-attached as needed.

Parameters
object Object representing an item, previously returned by a call to instantiateItem(ViewGroup, int, int).
Returns
  • object's new position with row from [0, getRowCount()] and column from [0, getColumnCount(row)], POSITION_UNCHANGED if the object's position has not changed, or POSITION_NONE if the item is no longer present.

public int getOptionsForPage (int row, int column)

Provides a set of features to apply to a page background. The return value should be a combination of one or more of the following, combined via bitwise-or:

The default return value is PAGE_DEFAULT_OPTIONS.

Parameters
row the row of the page
column the column of the page
Returns
  • a bitwise OR of all requested options

public abstract int getRowCount ()

Returns the number of rows available.

public abstract 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

public abstract boolean isViewFromObject (View view, 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

public void notifyDataSetChanged ()

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

public void notifyPageBackgroundChanged (int row, int column)

This method should be called if the value returned by getBackgroundForPage(int, int) or options returned by getOptionsForPage(int, int) change. Any cached value are removed and the the new value will be requested when necessary.

public void notifyRowBackgroundChanged (int row)

This method should be called if the value returned by getBackgroundForRow(int) changes. Any cached value is removed and the the new value will be requested when necessary.

public void registerDataSetObserver (DataSetObserver observer)

Register an observer to receive callbacks related to the adapter's data changing.

Parameters
observer The DataSetObserver which will receive callbacks.

public void restoreState (Parcelable savedState, ClassLoader classLoader)

Restores the previously saved state of this adapter.

public Parcelable saveState ()

Saves the current state of this adapter.

public 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

public 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.

public void unregisterDataSetObserver (DataSetObserver observer)

Unregister an observer from callbacks related to the adapter's data changing.

Parameters
observer The DataSetObserver which will be unregistered.