GridPagerAdapter

public abstract class GridPagerAdapter
extends Object

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


该组件负责提供 GridViewPager请求的 GridViewPager

内容组织成页面的行和列,其中每个页面由一个视图表示。 每行可能包含不同数量的列。

除了内容视图之外,还会查询此适配器是否为每个页面显示背景。 当相同的背景跨越多个页面时,会自动缩放和平移,以便在页面内容移动时为其移动创建视差效果。 默认情况下,不提供背景。

Summary

Constants

int OPTION_DISABLE_PARALLAX

禁用缩放和视差滚动背景。

int PAGE_DEFAULT_OPTIONS

默认背景选项。

Fields

public static final Drawable BACKGROUND_NONE

该值表示不应绘制背景。

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)

移除给定位置的页面。

void finishUpdate(ViewGroup container)

在所示页面中的更改完成时调用。

Drawable getBackgroundForPage(int row, int column)

提供内容作为特定页面的背景显示。

Drawable getBackgroundForRow(int row)

提供内容作为给定行上所有页面的默认背景显示。

abstract int getColumnCount(int row)

返回每一行的最大列数。

int getCurrentColumnForRow(int row, int currentColumn)

返回在垂直导航到指定行时到达的列。

Point getItemPosition(Object object)

当主视图试图确定某个项目的位置是否已更改时调用。

int getOptionsForPage(int row, int column)

提供一组适用于页面背景的功能。

abstract int getRowCount()

返回可用的行数。

abstract Object instantiateItem(ViewGroup container, int row, int column)

为给定位置创建页面。

abstract boolean isViewFromObject(View view, Object object)

确定页面视图是否与 instantiateItem(ViewGroup, int, int)返回的特定键对象相关联。

void notifyDataSetChanged()

如果支持此适配器的数据发生更改并且关联的视图应该更新,应该由应用程序调用此方法。

void notifyPageBackgroundChanged(int row, int column)

如果 getBackgroundForPage(int, int)返回的值或 getOptionsForPage(int, int)返回的 getOptionsForPage(int, int)更改,则应调用此方法。

void notifyRowBackgroundChanged(int row)

如果 getBackgroundForRow(int)返回的值发生更改,则应该调用此方法。

void registerDataSetObserver(DataSetObserver observer)

注册观察者以接收与适配器数据更改有关的回调。

void restoreState(Parcelable savedState, ClassLoader classLoader)

恢复此适配器以前保存的状态。

Parcelable saveState()

保存此适配器的当前状态。

void setCurrentColumnForRow(int row, int currentColumn)

调用以通知适配器哪一列现在是给定行的当前行。

void startUpdate(ViewGroup container)

当所显示页面的变化即将开始时调用。

void unregisterDataSetObserver(DataSetObserver observer)

从与适配器数据更改相关的回调中注销观察者。

Protected methods

void applyItemPosition(Object object, Point position)

getItemPosition(Object)之后 getItemPosition(Object)以允许超类更新他们的内部簿记,如果子类重写了 getItemPosition(Object)

Inherited methods

From class java.lang.Object

Constants

OPTION_DISABLE_PARALLAX

int OPTION_DISABLE_PARALLAX

禁用缩放和视差滚动背景。

常数值:1(0x00000001)

PAGE_DEFAULT_OPTIONS

int PAGE_DEFAULT_OPTIONS

默认背景选项。 视差滚动已启用。

常量值:0(0x00000000)

Fields

BACKGROUND_NONE

Drawable BACKGROUND_NONE

该值表示不应绘制背景。 有关特定效果,请参阅getBackgroundForRow(int)getBackgroundForPage(int, int)

POSITION_NONE

Point POSITION_NONE

POSITION_UNCHANGED

Point POSITION_UNCHANGED

Public constructors

GridPagerAdapter

GridPagerAdapter ()

Public methods

destroyItem

void destroyItem (ViewGroup container,
                int row,
                int column,
                Object object)

移除给定位置的页面。 适配器负责从容器中移除视图,但它只能确保在从finishUpdate(ViewGroup)返回时完成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

void finishUpdate (ViewGroup container)

在所示页面中的更改完成时调用。 此时,您必须确保所有页面实际上已根据需要添加或从容器中移除。

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

getBackgroundForPage

Drawable getBackgroundForPage (int row,
                int column)

提供内容作为特定页面的背景显示。

返回值BACKGROUND_NONE表示没有页面特定的背景。 并应使用行背景(如果有的话)。

这个方法的返回值可以被缓存。 可以使用notifyPageBackgroundChanged(int, int)来使以前返回的值无效。 然后将调用getBackgroundForPage(int, int)以在必要时请求新值。

Parameters
row int: the row of the page
column int: the column of the page
Returns
Drawable

getBackgroundForRow

Drawable getBackgroundForRow (int row)

提供内容作为给定行上所有页面的默认背景显示。

返回值 BACKGROUND_NONE导致显示背景,除了由 getBackgroundForPage(int, int)应用的 getBackgroundForPage(int, int)

这个方法的返回值可以被缓存。 可以使用notifyRowBackgroundChanged(int)来使先前返回的值无效。 然后将调用getBackgroundForRow(int)以在必要时请求新值。

Parameters
row int: the row of the page
Returns
Drawable a drawable to display for the row

getColumnCount

int getColumnCount (int row)

返回每一行的最大列数。 列数可能因行而异。

Parameters
row int
Returns
int

getCurrentColumnForRow

int getCurrentColumnForRow (int row,
                int currentColumn)

返回在垂直导航到指定行时到达的列。

默认实现只返回0。

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

getItemPosition

Point getItemPosition (Object object)

当主视图试图确定某个项目的位置是否已更改时调用。 返回POSITION_UNCHANGED如果给定项目的立场没有改变或POSITION_NONE ;如果该项目不再出现在适配器。

默认实现假定所有项目已被删除并始终返回POSITION_NONE 这会导致所有碎片被分离并根据需要重新附加。

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

int getOptionsForPage (int row,
                int column)

提供一组适用于页面背景的功能。 返回值应该是以下一项或多项的组合,通过按位或 - 组合:

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

int getRowCount ()

返回可用的行数。

Returns
int

instantiateItem

Object instantiateItem (ViewGroup container,
                int row,
                int column)

为给定位置创建页面。 适配器负责将视图添加到此处给出的容器,但它只能确保在从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

boolean isViewFromObject (View view,
                Object object)

确定页面视图是否与instantiateItem(ViewGroup, int, int)返回的特定键对象相关联。 这个方法对于PagerAdapter正常运行是必需的。

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

void notifyDataSetChanged ()

如果支持此适配器的数据发生更改并且关联的视图应该更新,应该由应用程序调用此方法。

notifyPageBackgroundChanged

void notifyPageBackgroundChanged (int row,
                int column)

如果getBackgroundForPage(int, int)返回的值或getOptionsForPage(int, int)返回的getOptionsForPage(int, int)更改,则应该调用此方法。 任何缓存的值都将被删除,并在必要时请求新值。

Parameters
row int
column int

notifyRowBackgroundChanged

void notifyRowBackgroundChanged (int row)

如果getBackgroundForRow(int)返回的值发生更改,则应该调用此方法。 任何缓存的值都会被删除,并且必要时会请求新值。

Parameters
row int

registerDataSetObserver

void registerDataSetObserver (DataSetObserver observer)

注册观察者以接收与适配器数据更改有关的回调。

Parameters
observer DataSetObserver: The DataSetObserver which will receive callbacks.

restoreState

void restoreState (Parcelable savedState,
                ClassLoader classLoader)

恢复此适配器以前保存的状态。

Parameters
savedState Parcelable
classLoader ClassLoader

saveState

Parcelable saveState ()

保存此适配器的当前状态。

Returns
Parcelable

setCurrentColumnForRow

void setCurrentColumnForRow (int row,
                int currentColumn)

调用以通知适配器哪一列现在是给定行的当前行。 这些信息可以被存储并用于实现getCurrentColumnForRow(int, int) 默认实现什么都不做。

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

startUpdate

void startUpdate (ViewGroup container)

当所显示页面的变化即将开始时调用。

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

unregisterDataSetObserver

void unregisterDataSetObserver (DataSetObserver observer)

从与适配器数据更改相关的回调中注销观察者。

Parameters
observer DataSetObserver: The DataSetObserver which will be unregistered.

Protected methods

applyItemPosition

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