GridPagerAdapter

public abstract class GridPagerAdapter
extends Object

java.lang.Object
   ↳ android.support.wearable.view.GridPagerAdapter


This class is deprecated.
starting with Android Wear 2.0 we no longer encourage bi-directional spacial models for apps. If you are looking to implement vertical paging pattern, consider using the SnapHelper and a RecyclerView instead.

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.

Protected methods

void applyItemPosition(Object object, Point position)

Called after getItemPosition(Object) to allow superclasses to update their internal bookkeeping if a subclass has overridden getItemPosition(Object).

Inherited methods

Constants

OPTION_DISABLE_PARALLAX

public static final int OPTION_DISABLE_PARALLAX

Disables zooming and parallax scrolling of the background.

Constant Value: 1 (0x00000001)

PAGE_DEFAULT_OPTIONS

public static final int PAGE_DEFAULT_OPTIONS

Default background options. Parallax scrolling is enabled.

Constant Value: 0 (0x00000000)

Fields

BACKGROUND_NONE

public static final Drawable BACKGROUND_NONE

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

POSITION_NONE

public static final Point POSITION_NONE

POSITION_UNCHANGED

public static final Point POSITION_UNCHANGED

Public constructors

GridPagerAdapter

public GridPagerAdapter ()

Public methods

destroyItem

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 ViewGroup: The containing View from which the page will be removed.

row int: the row to be destroyed

column int: the column within the row to be destroyed

object Object: The same object that was returned by instantiateItem(ViewGroup, int, int).

finishUpdate

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 ViewGroup: The containing View which is displaying this adapter's page views

getBackgroundForPage

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 int: the row of the page

column int: the column of the page

Returns
Drawable

getBackgroundForRow

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 int: the row of the page

Returns
Drawable a drawable to display for the row

getColumnCount

public abstract int getColumnCount (int row)

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

Parameters
row int

Returns
int

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 int: the row in question

currentColumn int: the column which is currently centered

Returns
int the column to arrive at

getItemPosition

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: Object representing an item, previously returned by a call to instantiateItem(ViewGroup, int, int).

Returns
Point 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.

getOptionsForPage

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 int: the row of the page

column int: the column of the page

Returns
int a bitwise OR of all requested options

getRowCount

public abstract int getRowCount ()

Returns the number of rows available.

Returns
int

instantiateItem

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 ViewGroup: containing View in which the page will be shown

row int: the row to be instantiated

column int: the column within the row to be instantiated

Returns
Object a an object representing the new page

isViewFromObject

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 View: Page View to check for association with object

object Object: Object to check for association with view

Returns
boolean true if view is associated with the key object object

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.

notifyPageBackgroundChanged

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.

Parameters
row int

column int

notifyRowBackgroundChanged

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.

Parameters
row int

registerDataSetObserver

public void registerDataSetObserver (DataSetObserver observer)

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

Parameters
observer DataSetObserver: The DataSetObserver which will receive callbacks.

restoreState

public void restoreState (Parcelable savedState, 
                ClassLoader classLoader)

Restores the previously saved state of this adapter.

Parameters
savedState Parcelable

classLoader ClassLoader

saveState

public Parcelable saveState ()

Saves the current state of this adapter.

Returns
Parcelable

setCurrentColumnForRow

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 int: the row for the column change

currentColumn int: the column which is now current

startUpdate

public void startUpdate (ViewGroup container)

Called when a change in the shown pages is going to start being made.

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

unregisterDataSetObserver

public void unregisterDataSetObserver (DataSetObserver observer)

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

Parameters
observer DataSetObserver: The DataSetObserver which will be unregistered.

Protected methods

applyItemPosition

protected void applyItemPosition (Object object, 
                Point position)

Called after getItemPosition(Object) to allow superclasses to update their internal bookkeeping if a subclass has overridden getItemPosition(Object).

Parameters
object Object: Object representing the item passed to getItemPosition(Object).

position Point: position which was returned from getItemPosition(Object).