android.support.wearable.view
Class CardFragment

java.lang.Object
  extended by Fragment
      extended by android.support.wearable.view.CardFragment

public class CardFragment
extends Fragment

Presents content within an expandable, vertically scrollable card. The default layout contains a title, icon and text, but may be replaced by overriding onCreateContentView(LayoutInflater, ViewGroup, Bundle).

Additional methods are supplied for adjusting the appearance of the card, including whether content should clip or appear as expandable, and the maximum height of the card.

See Also:
setCardGravity(int), setExpansionEnabled(boolean), setExpansionDirection(int), setExpansionFactor(float)

Field Summary
static int EXPAND_DOWN
           
static int EXPAND_UP
           
static java.lang.String KEY_ICON_RESOURCE
           
static java.lang.String KEY_TEXT
           
static java.lang.String KEY_TITLE
           
 
Constructor Summary
CardFragment()
           
 
Method Summary
static CardFragment create(java.lang.CharSequence title, java.lang.CharSequence description)
          Construct a new CardFragment using the default content layout.
static CardFragment create(java.lang.CharSequence title, java.lang.CharSequence text, int iconRes)
          Construct a new CardFragment using the default content layout, including and icon.
 View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
          Called to have subclasses instantiate their layout which is inserted within the card.
 View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
           
 void onResume()
           
 void scrollToBottom()
          Sets the card scroll position as far down as possible so the bottom edge is visible.
 void scrollToTop()
          Sets the card scroll position as far up as possible so the top edge is visible.
 void setCardGravity(int gravity)
          Assigns vertical gravity to the card, which determines where it should float when the card and it's content are shorter than the page.
 void setExpansionDirection(int direction)
          Adjusts which direction the card height will expand.
 void setExpansionEnabled(boolean enabled)
          Enables support contents which maybe be larger than the card's container.
 void setExpansionFactor(float factor)
          Sets the allowed maximum height of the card as a multiple of the parent height.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXPAND_UP

public static final int EXPAND_UP
See Also:
Constant Field Values

EXPAND_DOWN

public static final int EXPAND_DOWN
See Also:
Constant Field Values

KEY_TITLE

public static final java.lang.String KEY_TITLE
See Also:
Constant Field Values

KEY_TEXT

public static final java.lang.String KEY_TEXT
See Also:
Constant Field Values

KEY_ICON_RESOURCE

public static final java.lang.String KEY_ICON_RESOURCE
See Also:
Constant Field Values
Constructor Detail

CardFragment

public CardFragment()
Method Detail

create

public static CardFragment create(java.lang.CharSequence title,
                                  java.lang.CharSequence description)
Construct a new CardFragment using the default content layout.

Parameters:
title - the card title displayed on the first line
description - the card text displayed below the title
Returns:
a new CardFragment

create

public static CardFragment create(java.lang.CharSequence title,
                                  java.lang.CharSequence text,
                                  int iconRes)
Construct a new CardFragment using the default content layout, including and icon.

Parameters:
title - the card title displayed on the first line
text - the card text displayed below the title
iconRes - a resourceId for an icon to be displayed next to the title
Returns:
a new CardFragment

setExpansionEnabled

public void setExpansionEnabled(boolean enabled)
Enables support contents which maybe be larger than the card's container. When expansion is enabled, and the contents are larger than the card, the top or bottom edge will fade to indicate this. The expansion factor must also be increased to allow the card to increase in height.


setExpansionDirection

public void setExpansionDirection(int direction)
Adjusts which direction the card height will expand. This also determines which edge is rendered with a faded edge when more content is available by scrolling.

Parameters:
direction - a direction constant, either EXPAND_UP or EXPAND_DOWN

setCardGravity

public void setCardGravity(int gravity)
Assigns vertical gravity to the card, which determines where it should float when the card and it's content are shorter than the page.

Parameters:
gravity - a vertical gravity, either Gravity#TOP or Gravity#BOTTOM

setExpansionFactor

public void setExpansionFactor(float factor)
Sets the allowed maximum height of the card as a multiple of the parent height. If expansion is enabled, The card will increase in height up to this amount as needed to accommodate content.

Parameters:
factor - the vertical height multiplier to set the maximum height

scrollToTop

public void scrollToTop()
Sets the card scroll position as far up as possible so the top edge is visible.


scrollToBottom

public void scrollToBottom()
Sets the card scroll position as far down as possible so the bottom edge is visible.


onCreateView

public final View onCreateView(LayoutInflater inflater,
                               ViewGroup container,
                               Bundle savedInstanceState)

onResume

public void onResume()

onCreateContentView

public View onCreateContentView(LayoutInflater inflater,
                                ViewGroup container,
                                Bundle savedInstanceState)
Called to have subclasses instantiate their layout which is inserted within the card. Override this method to supply your own custom layout for the card content.

Parameters:
inflater - The LayoutInflater object that can be used to inflate any views in the fragment
container - If non-null, this is the parent view that the fragment's UI should be attached to. The fragment should not add the view itself, but this can be used to generate the LayoutParams of the view
savedInstanceState - If non-null, this fragment is being re-constructed from a previous saved state as given here
Returns:
Return the View for the fragment's UI, or null