The Google Glass Explorer Edition SDK is deprecated. This documentation is no longer being maintained. If you're interested in developing Glass solutions for enterprise clients, visit the Google Glass Enterprise Edition developer documentation.

CardScrollView

Added in API level XE12

A View that shows horizontally scrolling children views, referred to as cards.

The cards come from the CardScrollAdapter that is associated with the CardScrollView. Each card visually represents a certain Object item.

See Scrolling cards in activities for more information.

General usage

  1. Build a set of cards using a standard view hierarchy or the CardBuilder class.
  2. Implement a CardScrollAdapter to supply the set of cards to the CardScrollView. Each card has a unique Object identifier and represents a certain Object item.
  3. Set your activity's content view to be the CardScrollView or use the CardScrollView in a layout.

Handling scrolling and interaction

CardScrollView notifies you with the following listener interfaces that are inherited from AdapterView:

Nested Classes
enum CardScrollView.Animation Defines animation type used to navigate to, insert, or delete a card. 
Inherited Constants
Inherited Fields
Public Constructors
CardScrollView(Context context, AttributeSet attrs, int defStyle)
Public Methods
void
boolean
animate(int position, CardScrollView.Animation animationType)
void
CardScrollAdapter
long
int
View
boolean
boolean
boolean
onKeyDown(int keyCode, KeyEvent event)
void
onWindowFocusChanged(boolean hasWindowFocus)
void
void
setEmptyView(View emptyView)
void
void
setSelection(int position)
Protected Methods
boolean
boolean
void
void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onVisibilityChanged(View changedView, int visibility)
Inherited Methods

Public Constructors

Added in API level XE12

public CardScrollView (Context context)

Added in API level XE12

public CardScrollView (Context context, AttributeSet attrs)

Added in API level XE12

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

Public Methods

Added in API level XE12

public void activate ()

Tells the CardScrollView to activate and be ready for display. TODO(ajcbik): investigate if we can replace [de]activate with focus events, see b/17574566 request.

Added in API level XE21

public boolean animate (int position, CardScrollView.Animation animationType)

Animates for card at given position, where animationType should be one of:

  • NAVIGATION: moves to given card from any position, regular navigation,
  • INSERTION: moves to given card, which appears into view, after insertion,
  • DELETION: given card disappears from view, if selected, after deletion.
The animation is skipped if the scroller is deactivated, if a prior autonomous animation is still ongoing, or if the position is invalid. A deletion animation only occurs if the deleted card is currently selected.

The insertion and deletion animation should be used after doing the corresponding mutation in CardScrollAdapter. The animation will call the notifyDataSetChanged() on the adapter at the proper moment in the animation, even when skipped or terminated early.

Sample usage:

 .... insert card at p-th position in adapter ....
 animate(p, INSERTION);    // calls notifyDataSetChanged() on adapter
 

Parameters
position of the card involved in the animation
animationType controls the type of animation to use
Returns
  • whether animation was started
Added in API level XE12

public void deactivate ()

Tells the CardScrollView to deactivate; it will not be displayed until after activate() is called again.

Added in API level XE12

public CardScrollAdapter getAdapter ()

public long getSelectedItemId ()

Added in API level XE12

public int getSelectedItemPosition ()

Added in API level XE12

public View getSelectedView ()

Added in API level XE12

public boolean isActivated ()

public boolean isHorizontalScrollBarEnabled ()

public boolean onKeyDown (int keyCode, KeyEvent event)

public void onWindowFocusChanged (boolean hasWindowFocus)

Added in API level XE12

public void setAdapter (CardScrollAdapter adapter)

public void setEmptyView (View emptyView)

The setEmptyView(View) is unsupported by the CardScrollView.

To get proper animation and tuggable behavior, use an adapter with a single empty view for empty data sets instead.

public void setHorizontalScrollBarEnabled (boolean enable)

Added in API level XE12

public void setSelection (int position)

Protected Methods

protected boolean awakenScrollBars ()

Awakens the horizontal scrollbar, if any.

protected boolean dispatchGenericFocusedEvent (MotionEvent event)

protected void initializeScrollbars (TypedArray a)

Added in API level XE12

protected void onLayout (boolean changed, int left, int top, int right, int bottom)

protected void onVisibilityChanged (View changedView, int visibility)