GridViewPager

public class GridViewPager
extends ViewGroup

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.support.wearable.view.GridViewPager


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.

Layout manager that allows the user to navigate both vertically and horizontally through pages of content. You supply an implementation of a GridPagerAdapter to generate pages for the view to show.

Summary

Nested classes

class GridViewPager.LayoutParams

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.  

interface GridViewPager.OnAdapterChangeListener

This interface 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.  

interface GridViewPager.OnPageChangeListener

This interface 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.  

Constants

int SCROLL_STATE_CONTENT_SETTLING

int SCROLL_STATE_DRAGGING

Indicates that the pager is currently being dragged by the user.

int SCROLL_STATE_IDLE

Indicates that the pager is in an idle, settled state.

int SCROLL_STATE_SETTLING

Indicates that the pager is in the process of settling to a final position.

Inherited constants

Inherited fields

Public constructors

GridViewPager(Context context)
GridViewPager(Context context, AttributeSet attrs)
GridViewPager(Context context, AttributeSet attrs, int defStyle)

Public methods

void addView(View child, int index, ViewGroup.LayoutParams params)
boolean canScrollHorizontally(int direction)
boolean canScrollVertically(int direction)
void computeScroll()
WindowInsets dispatchApplyWindowInsets(WindowInsets insets)
boolean dispatchKeyEvent(KeyEvent event)
ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)
GridPagerAdapter getAdapter()
Point getCurrentItem()
int getOffscreenPageCount()

Returns the number of pages that will be retained on the sides of the current page in the view hierarchy in an idle state.

int getPageColumnMargin()

Return the margin between columns of pages.

int getPageRowMargin()

Returns the margin between rows of pages.

void measureChild(View child, GridViewPager.LayoutParams lp)

Used to measure all page views.

WindowInsets onApplyWindowInsets(WindowInsets insets)
void onAttachedToWindow()
boolean onInterceptTouchEvent(MotionEvent ev)
void onPageScrolled(int positionX, int positionY, float offsetX, float offsetY, int offsetLeftPx, int offsetTopPx)

This method will be invoked when the current page is scrolled, either as part of a programmatically initiated smooth scroll or a user initiated touch scroll.

void onRestoreInstanceState(Parcelable state)
Parcelable onSaveInstanceState()
boolean onTouchEvent(MotionEvent ev)
void removeView(View view)
void requestFitSystemWindows()
void scrollTo(int x, int y)
void setAdapter(GridPagerAdapter adapter)

Assigns an adapter to provide the content for this pager.

void setConsumeWindowInsets(boolean consume)

Sets whether the grid view pager should consume insets during dispatchApplyWindowInsets(WindowInsets).

void setOffscreenPageCount(int limit)

Set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state.

void setOnAdapterChangeListener(GridViewPager.OnAdapterChangeListener listener)

Set a listener that will be invoked whenever the adapter is changed.

void setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener listener)
void setOnPageChangeListener(GridViewPager.OnPageChangeListener listener)

Set a listener that will be invoked whenever the page changes or is incrementally scrolled.

void setPageMargins(int rowMarginPx, int columnMarginPx)

Sets the margin between pages.

void setSlideAnimationDuration(int slideAnimationDuration)

Protected methods

boolean checkLayoutParams(ViewGroup.LayoutParams p)
ViewGroup.LayoutParams generateDefaultLayoutParams()
ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
void onDetachedFromWindow()
void onLayout(boolean changed, int l, int t, int r, int b)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void onSizeChanged(int w, int h, int oldw, int oldh)

Inherited methods

Constants

SCROLL_STATE_CONTENT_SETTLING

public static final int SCROLL_STATE_CONTENT_SETTLING

Constant Value: 3 (0x00000003)

SCROLL_STATE_DRAGGING

public static final int SCROLL_STATE_DRAGGING

Indicates that the pager is currently being dragged by the user.

Constant Value: 1 (0x00000001)

SCROLL_STATE_IDLE

public static final int SCROLL_STATE_IDLE

Indicates that the pager is in an idle, settled state. The current page is fully in view and no animation is in progress.

Constant Value: 0 (0x00000000)

SCROLL_STATE_SETTLING

public static final int SCROLL_STATE_SETTLING

Indicates that the pager is in the process of settling to a final position.

Constant Value: 2 (0x00000002)

Public constructors

GridViewPager

public GridViewPager (Context context)

Parameters
context Context

GridViewPager

public GridViewPager (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

GridViewPager

public GridViewPager (Context context, 
                AttributeSet attrs, 
                int defStyle)

Parameters
context Context

attrs AttributeSet

defStyle int

Public methods

addView

public void addView (View child, 
                int index, 
                ViewGroup.LayoutParams params)

Parameters
child View

index int

params ViewGroup.LayoutParams

canScrollHorizontally

public boolean canScrollHorizontally (int direction)

Parameters
direction int

Returns
boolean

canScrollVertically

public boolean canScrollVertically (int direction)

Parameters
direction int

Returns
boolean

computeScroll

public void computeScroll ()

dispatchApplyWindowInsets

public WindowInsets dispatchApplyWindowInsets (WindowInsets insets)

Parameters
insets WindowInsets

Returns
WindowInsets

dispatchKeyEvent

public boolean dispatchKeyEvent (KeyEvent event)

Parameters
event KeyEvent

Returns
boolean

generateLayoutParams

public ViewGroup.LayoutParams generateLayoutParams (AttributeSet attrs)

Parameters
attrs AttributeSet

Returns
ViewGroup.LayoutParams

getAdapter

public GridPagerAdapter getAdapter ()

Returns
GridPagerAdapter

getCurrentItem

public Point getCurrentItem ()

Returns
Point

getOffscreenPageCount

public int getOffscreenPageCount ()

Returns the number of pages that will be retained on the sides of the current page in the view hierarchy in an idle state. Defaults to 1.

Returns
int How many pages will be kept off-screen on all sides

getPageColumnMargin

public int getPageColumnMargin ()

Return the margin between columns of pages.

Returns
int columnMarginPx horizontal distance between adjacent pages in pixels

getPageRowMargin

public int getPageRowMargin ()

Returns the margin between rows of pages.

Returns
int the vertical distance between adjacent pages in pixels

measureChild

public void measureChild (View child, 
                GridViewPager.LayoutParams lp)

Used to measure all page views. Views with a dimension of match_parent or a specific size will be measured with EXACTLY, while those with wrap_content will be measured as UNSPECIFIED to allow them to become as large as desired.

Parameters
child View

lp GridViewPager.LayoutParams

onApplyWindowInsets

public WindowInsets onApplyWindowInsets (WindowInsets insets)

Parameters
insets WindowInsets

Returns
WindowInsets

onAttachedToWindow

public void onAttachedToWindow ()

onInterceptTouchEvent

public boolean onInterceptTouchEvent (MotionEvent ev)

Parameters
ev MotionEvent

Returns
boolean

onPageScrolled

public void onPageScrolled (int positionX, 
                int positionY, 
                float offsetX, 
                float offsetY, 
                int offsetLeftPx, 
                int offsetTopPx)

This method will be invoked when the current page is scrolled, either as part of a programmatically initiated smooth scroll or a user initiated touch scroll. If you override this method you must call through to the superclass implementation (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled returns.

Parameters
positionX int: column index of the first page currently being displayed. Page positionX+1 will be visible if offsetX is nonzero.

positionY int: row index of the first page currently being displayed. Page positionY+1 will be visible if offseyY is nonzero.

offsetX float: Value from [0, 1) indicating the left offset from the page at positionX.

offsetY float: Value from [0, 1) indicating the top offset from the page at positionY.

offsetLeftPx int: Value in pixels indicating the offset from positionX.

offsetTopPx int: Value in pixels indicating the offset from positionY.

onRestoreInstanceState

public void onRestoreInstanceState (Parcelable state)

Parameters
state Parcelable

onSaveInstanceState

public Parcelable onSaveInstanceState ()

Returns
Parcelable

onTouchEvent

public boolean onTouchEvent (MotionEvent ev)

Parameters
ev MotionEvent

Returns
boolean

removeView

public void removeView (View view)

Parameters
view View

requestFitSystemWindows

public void requestFitSystemWindows ()

scrollTo

public void scrollTo (int x, 
                int y)

Parameters
x int

y int

setAdapter

public void setAdapter (GridPagerAdapter adapter)

Assigns an adapter to provide the content for this pager. Any existing content is removed and discarded and the position is reset to 0,0.

Parameters
adapter GridPagerAdapter: the adapter to assign

setConsumeWindowInsets

public void setConsumeWindowInsets (boolean consume)

Sets whether the grid view pager should consume insets during dispatchApplyWindowInsets(WindowInsets). The default behavior is to consume insets.

Parameters
consume boolean: true to consume, false otherwise.

setOffscreenPageCount

public void setOffscreenPageCount (int limit)

Set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state. Pages beyond this limit will be recreated from the adapter when needed.

This is offered as an optimization. If you know in advance the number of pages you will need to support or have lazy-loading mechanisms in place on your pages, tweaking this setting can have benefits in perceived smoothness of paging animations and interaction. If you have a small number of pages (3-4) that you can keep active all at once, less time will be spent in layout for newly created view subtrees as the user pages back and forth.

You should keep this limit low, especially if your pages have complex layouts. This setting defaults to 1.

Parameters
limit int: How many pages will be kept offscreen in an idle state.

setOnAdapterChangeListener

public void setOnAdapterChangeListener (GridViewPager.OnAdapterChangeListener listener)

Set a listener that will be invoked whenever the adapter is changed. See GridViewPager.OnAdapterChangeListener.

Parameters
listener GridViewPager.OnAdapterChangeListener: Listener to set

setOnApplyWindowInsetsListener

public void setOnApplyWindowInsetsListener (View.OnApplyWindowInsetsListener listener)

Parameters
listener View.OnApplyWindowInsetsListener

setOnPageChangeListener

public void setOnPageChangeListener (GridViewPager.OnPageChangeListener listener)

Set a listener that will be invoked whenever the page changes or is incrementally scrolled. See GridViewPager.OnPageChangeListener.

Parameters
listener GridViewPager.OnPageChangeListener: Listener to set

setPageMargins

public void setPageMargins (int rowMarginPx, 
                int columnMarginPx)

Sets the margin between pages.

Parameters
rowMarginPx int: vertical distance between adjacent pages in pixels

columnMarginPx int: horizontal distance between adjacent pages in pixels

setSlideAnimationDuration

public void setSlideAnimationDuration (int slideAnimationDuration)

Parameters
slideAnimationDuration int

Protected methods

checkLayoutParams

protected boolean checkLayoutParams (ViewGroup.LayoutParams p)

Parameters
p ViewGroup.LayoutParams

Returns
boolean

generateDefaultLayoutParams

protected ViewGroup.LayoutParams generateDefaultLayoutParams ()

Returns
ViewGroup.LayoutParams

generateLayoutParams

protected ViewGroup.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)

Parameters
p ViewGroup.LayoutParams

Returns
ViewGroup.LayoutParams

onDetachedFromWindow

protected void onDetachedFromWindow ()

onLayout

protected void onLayout (boolean changed, 
                int l, 
                int t, 
                int r, 
                int b)

Parameters
changed boolean

l int

t int

r int

b int

onMeasure

protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int

onSizeChanged

protected void onSizeChanged (int w, 
                int h, 
                int oldw, 
                int oldh)

Parameters
w int

h int

oldw int

oldh int