android.support.wearable.view
Class GridViewPager

java.lang.Object
  extended by ViewGroup
      extended by android.support.wearable.view.GridViewPager

public class GridViewPager
extends ViewGroup

Layout manager that allows the user to both vertically and horizontally through pages of data. You supply an implementation of a GridPagerAdapter to generate the pages that the view shows.


Nested Class Summary
static class GridViewPager.LayoutParams
          Layout parameters that should be supplied for views added to a ViewPager.
static interface GridViewPager.OnAdapterChangeListener
          Used internally to monitor when adapters are switched.
static interface GridViewPager.OnPageChangeListener
          Callback interface for responding to changing state of the selected page.
 
Field Summary
static int SCROLL_STATE_CONTENT_SETTLING
           
static int SCROLL_STATE_DRAGGING
          Indicates that the pager is currently being dragged by the user.
static int SCROLL_STATE_IDLE
          Indicates that the pager is in an idle, settled state.
static int SCROLL_STATE_SETTLING
          Indicates that the pager is in the process of settling to a final position.
 
Constructor Summary
GridViewPager(Context context)
           
GridViewPager(Context context, AttributeSet attrs)
           
GridViewPager(Context context, AttributeSet attrs, int defStyle)
           
 
Method Summary
 void addView(View child, int index, ViewGroup.LayoutParams params)
           
 boolean canScrollHorizontally(int direction)
           
 boolean canScrollVertically(int direction)
           
protected  boolean checkLayoutParams(ViewGroup.LayoutParams p)
           
 void computeScroll()
           
 void debug()
           
protected  void debug(int depth)
           
protected static java.lang.String debugIndent(int depth)
           
 boolean dispatchKeyEvent(KeyEvent event)
           
protected  ViewGroup.LayoutParams generateDefaultLayoutParams()
           
 ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)
           
protected  ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
           
 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.
protected  void measureChild(View child, GridViewPager.LayoutParams lp)
          Used to measure all page views.
 WindowInsets onApplyWindowInsets(WindowInsets insets)
           
 void onAttachedToWindow()
           
protected  void onDetachedFromWindow()
           
 boolean onInterceptTouchEvent(MotionEvent ev)
           
protected  void onLayout(boolean changed, int l, int t, int r, int b)
           
protected  void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
           
 void onRestoreInstanceState(Parcelable state)
           
 Parcelable onSaveInstanceState()
           
protected  void onSizeChanged(int w, int h, int oldw, int oldh)
           
 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 setCurrentItem(int row, int column)
          Set the currently selected page.
 void setCurrentItem(int row, int column, boolean smoothScroll)
          Set the currently selected page.
 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)
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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.

See Also:
Constant Field Values

SCROLL_STATE_DRAGGING

public static final int SCROLL_STATE_DRAGGING
Indicates that the pager is currently being dragged by the user.

See Also:
Constant Field Values

SCROLL_STATE_SETTLING

public static final int SCROLL_STATE_SETTLING
Indicates that the pager is in the process of settling to a final position.

See Also:
Constant Field Values

SCROLL_STATE_CONTENT_SETTLING

public static final int SCROLL_STATE_CONTENT_SETTLING
See Also:
Constant Field Values
Constructor Detail

GridViewPager

public GridViewPager(Context context)

GridViewPager

public GridViewPager(Context context,
                     AttributeSet attrs)

GridViewPager

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

onAttachedToWindow

public void onAttachedToWindow()

onApplyWindowInsets

public WindowInsets onApplyWindowInsets(WindowInsets insets)

requestFitSystemWindows

public void requestFitSystemWindows()

onDetachedFromWindow

protected void onDetachedFromWindow()

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 - the adapter to assign

scrollTo

public void scrollTo(int x,
                     int y)

getAdapter

public GridPagerAdapter getAdapter()

setOnAdapterChangeListener

public void setOnAdapterChangeListener(GridViewPager.OnAdapterChangeListener listener)

setCurrentItem

public void setCurrentItem(int row,
                           int column)
Set the currently selected page. If the ViewPager has already been through its first layout with its current adapter there will be a smooth animated transition between the current item and the specified item.

Parameters:
item - Item index to select

setCurrentItem

public void setCurrentItem(int row,
                           int column,
                           boolean smoothScroll)
Set the currently selected page.

Parameters:
item - Item index to select
smoothScroll - True to smoothly scroll to the new item, false to transition immediately

getCurrentItem

public Point getCurrentItem()

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 - Listener to set

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:
How many pages will be kept offscreen on all sides
See Also:
#setOffscreenPageLimit(int)

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 - How many pages will be kept offscreen in an idle state.

setPageMargins

public void setPageMargins(int rowMarginPx,
                           int columnMarginPx)
Sets the margin between pages.

Parameters:
rowMarginPx - vertical distance between adjacent pages in pixels
columnMarginPx - horizontal distance between adjacent pages in pixels

getPageRowMargin

public int getPageRowMargin()
Returns the margin between rows of pages.

Returns:
the vertical distance between adjacent pages in pixels

getPageColumnMargin

public int getPageColumnMargin()
Return the margin between columns of pages.

Returns:
columnMarginPx horizontal distance between adjacent pages in pixels

onSaveInstanceState

public Parcelable onSaveInstanceState()

onRestoreInstanceState

public void onRestoreInstanceState(Parcelable state)

addView

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

removeView

public void removeView(View view)

onMeasure

protected void onMeasure(int widthMeasureSpec,
                         int heightMeasureSpec)

measureChild

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


onSizeChanged

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

onLayout

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

computeScroll

public void computeScroll()

onInterceptTouchEvent

public boolean onInterceptTouchEvent(MotionEvent ev)

onTouchEvent

public boolean onTouchEvent(MotionEvent ev)

canScrollHorizontally

public boolean canScrollHorizontally(int direction)

canScrollVertically

public boolean canScrollVertically(int direction)

dispatchKeyEvent

public boolean dispatchKeyEvent(KeyEvent event)

generateDefaultLayoutParams

protected ViewGroup.LayoutParams generateDefaultLayoutParams()

generateLayoutParams

protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)

checkLayoutParams

protected boolean checkLayoutParams(ViewGroup.LayoutParams p)

generateLayoutParams

public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)

debug

public void debug()

debug

protected void debug(int depth)

debugIndent

protected static java.lang.String debugIndent(int depth)