CardFragment

public class CardFragment
extends Fragment

java.lang.Object
   ↳ android.app.Fragment
     ↳ android.support.wearable.view.CardFragment


This class is deprecated.
starting with Android Wear 2.0 it is no longer encouraged to use cards for apps' UI. If you are looking to implement vertical paging pattern, consider using the SnapHelper and a RecyclerView instead.

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.

Summary

Inherited constants

int TRIM_MEMORY_BACKGROUND

int TRIM_MEMORY_COMPLETE

int TRIM_MEMORY_MODERATE

int TRIM_MEMORY_RUNNING_CRITICAL

int TRIM_MEMORY_RUNNING_LOW

int TRIM_MEMORY_RUNNING_MODERATE

int TRIM_MEMORY_UI_HIDDEN

Public constructors

CardFragment()

Public methods

static CardFragment create(CharSequence title, CharSequence text, int iconRes)

Construct a new CardFragment using the default content layout, including and icon.

static CardFragment create(CharSequence title, CharSequence description)

Construct a new CardFragment using the default content layout.

Rect getContentPadding()

Gets the padding between the inside card edge and the card content.

int getContentPaddingBottom()

Gets the padding between the inside card's bottom edge and the card content.

int getContentPaddingLeft()

Gets the padding between the inside card's left edge and the card content.

int getContentPaddingRight()

Gets the padding between the inside card's right edge and the card content.

int getContentPaddingTop()

Gets the padding between the inside card's top edge and the card content.

void onActivityCreated(Bundle savedInstanceState)
View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

Called to have subclasses instantiate their layout which is inserted within the card.

final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
void onDestroy()
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 setCardMarginBottom(int bottom)

Sets the additional margin between the bottom edge of the card shadow, and the parent view.

void setCardMarginLeft(int left)

Sets the additional margin between the left edge of the card shadow, and the parent view.

void setCardMarginRight(int right)

Sets the additional margin between the right edge of the card shadow, and the parent view.

void setCardMarginTop(int top)

Sets the additional margin between the top edge of the card shadow, and the parent view.

void setCardMargins(int left, int top, int right, int bottom)

Sets the additional margin between the card shadow edge and the parent view.

void setContentPadding(int left, int top, int right, int bottom)

Sets padding between the inside card edge and the card content.

void setContentPaddingBottom(int bottomPadding)

Sets the padding between the inside card's bottom edge and the card content.

void setContentPaddingLeft(int leftPadding)

Sets the padding between the inside card's left edge and the card content.

void setContentPaddingRight(int rightPadding)

Sets the padding between the inside card's right edge and the card content.

void setContentPaddingTop(int topPadding)

Sets the padding between the inside card's top edge and the card content.

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.

Inherited methods

void dump(String arg0, FileDescriptor arg1, PrintWriter arg2, String[] arg3)
final boolean equals(Object arg0)
final Activity getActivity()
boolean getAllowEnterTransitionOverlap()
boolean getAllowReturnTransitionOverlap()
final Bundle getArguments()
final FragmentManager getChildFragmentManager()
Context getContext()
Transition getEnterTransition()
Transition getExitTransition()
final FragmentManager getFragmentManager()
final Object getHost()
final int getId()
final LayoutInflater getLayoutInflater()
LoaderManager getLoaderManager()
final Fragment getParentFragment()
Transition getReenterTransition()
final Resources getResources()
final boolean getRetainInstance()
Transition getReturnTransition()
Transition getSharedElementEnterTransition()
Transition getSharedElementReturnTransition()
final String getString(int arg0, Object... arg1)
final String getString(int arg0)
final String getTag()
final Fragment getTargetFragment()
final int getTargetRequestCode()
final CharSequence getText(int arg0)
boolean getUserVisibleHint()
View getView()
final int hashCode()
static Fragment instantiate(Context arg0, String arg1)
static Fragment instantiate(Context arg0, String arg1, Bundle arg2)
final boolean isAdded()
final boolean isDetached()
final boolean isHidden()
final boolean isInLayout()
final boolean isRemoving()
final boolean isResumed()
final boolean isStateSaved()
final boolean isVisible()
void onActivityCreated(Bundle arg0)
void onActivityResult(int arg0, int arg1, Intent arg2)
void onAttach(Activity arg0)
void onAttach(Context arg0)
void onAttachFragment(Fragment arg0)
void onConfigurationChanged(Configuration arg0)
boolean onContextItemSelected(MenuItem arg0)
void onCreate(Bundle arg0)
Animator onCreateAnimator(int arg0, boolean arg1, int arg2)
void onCreateContextMenu(ContextMenu arg0, View arg1, ContextMenu.ContextMenuInfo arg2)
void onCreateOptionsMenu(Menu arg0, MenuInflater arg1)
View onCreateView(LayoutInflater arg0, ViewGroup arg1, Bundle arg2)
void onDestroy()
void onDestroyOptionsMenu()
void onDestroyView()
void onDetach()
LayoutInflater onGetLayoutInflater(Bundle arg0)
void onHiddenChanged(boolean arg0)
void onInflate(AttributeSet arg0, Bundle arg1)
void onInflate(Activity arg0, AttributeSet arg1, Bundle arg2)
void onInflate(Context arg0, AttributeSet arg1, Bundle arg2)
void onLowMemory()
void onMultiWindowModeChanged(boolean arg0)
void onMultiWindowModeChanged(boolean arg0, Configuration arg1)
boolean onOptionsItemSelected(MenuItem arg0)
void onOptionsMenuClosed(Menu arg0)
void onPause()
void onPictureInPictureModeChanged(boolean arg0, Configuration arg1)
void onPictureInPictureModeChanged(boolean arg0)
void onPrepareOptionsMenu(Menu arg0)
void onRequestPermissionsResult(int arg0, String[] arg1, int[] arg2)
void onResume()
void onSaveInstanceState(Bundle arg0)
void onStart()
void onStop()
void onTrimMemory(int arg0)
void onViewCreated(View arg0, Bundle arg1)
void onViewStateRestored(Bundle arg0)
void postponeEnterTransition()
void registerForContextMenu(View arg0)
final void requestPermissions(String[] arg0, int arg1)
void setAllowEnterTransitionOverlap(boolean arg0)
void setAllowReturnTransitionOverlap(boolean arg0)
void setArguments(Bundle arg0)
void setEnterSharedElementCallback(SharedElementCallback arg0)
void setEnterTransition(Transition arg0)
void setExitSharedElementCallback(SharedElementCallback arg0)
void setExitTransition(Transition arg0)
void setHasOptionsMenu(boolean arg0)
void setInitialSavedState(Fragment.SavedState arg0)
void setMenuVisibility(boolean arg0)
void setReenterTransition(Transition arg0)
void setRetainInstance(boolean arg0)
void setReturnTransition(Transition arg0)
void setSharedElementEnterTransition(Transition arg0)
void setSharedElementReturnTransition(Transition arg0)
void setTargetFragment(Fragment arg0, int arg1)
void setUserVisibleHint(boolean arg0)
boolean shouldShowRequestPermissionRationale(String arg0)
void startActivity(Intent arg0)
void startActivity(Intent arg0, Bundle arg1)
void startActivityForResult(Intent arg0, int arg1)
void startActivityForResult(Intent arg0, int arg1, Bundle arg2)
void startIntentSenderForResult(IntentSender arg0, int arg1, Intent arg2, int arg3, int arg4, int arg5, Bundle arg6)
void startPostponedEnterTransition()
String toString()
void unregisterForContextMenu(View arg0)
Object clone()
boolean equals(Object arg0)
void finalize()
final Class<?> getClass()
int hashCode()
final void notify()
final void notifyAll()
String toString()
final void wait(long arg0, int arg1)
final void wait(long arg0)
final void wait()
abstract void onTrimMemory(int arg0)
abstract void onCreateContextMenu(ContextMenu arg0, View arg1, ContextMenu.ContextMenuInfo arg2)
abstract void onConfigurationChanged(Configuration arg0)
abstract void onLowMemory()

Constants

EXPAND_DOWN

public static final int EXPAND_DOWN

Constant Value: 1 (0x00000001)

EXPAND_UP

public static final int EXPAND_UP

Constant Value: -1 (0xffffffff)

KEY_ICON_RESOURCE

public static final String KEY_ICON_RESOURCE

Constant Value: "CardFragment_icon"

KEY_TEXT

public static final String KEY_TEXT

Constant Value: "CardFragment_text"

KEY_TITLE

public static final String KEY_TITLE

Constant Value: "CardFragment_title"

Public constructors

CardFragment

public CardFragment ()

Public methods

create

public static CardFragment create (CharSequence title, 
                CharSequence text, 
                int iconRes)

Construct a new CardFragment using the default content layout, including and icon.

Parameters
title CharSequence: the card title displayed on the first line

text CharSequence: the card text displayed below the title

iconRes int: a resourceId for an icon to be displayed next to the title

Returns
CardFragment a new CardFragment

create

public static CardFragment create (CharSequence title, 
                CharSequence description)

Construct a new CardFragment using the default content layout.

Parameters
title CharSequence: the card title displayed on the first line

description CharSequence: the card text displayed below the title

Returns
CardFragment a new CardFragment

getContentPadding

public Rect getContentPadding ()

Gets the padding between the inside card edge and the card content.

Returns
Rect

getContentPaddingBottom

public int getContentPaddingBottom ()

Gets the padding between the inside card's bottom edge and the card content.

Returns
int

getContentPaddingLeft

public int getContentPaddingLeft ()

Gets the padding between the inside card's left edge and the card content.

Returns
int

getContentPaddingRight

public int getContentPaddingRight ()

Gets the padding between the inside card's right edge and the card content.

Returns
int

getContentPaddingTop

public int getContentPaddingTop ()

Gets the padding between the inside card's top edge and the card content.

Returns
int

onActivityCreated

public void onActivityCreated (Bundle savedInstanceState)

Parameters
savedInstanceState Bundle

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 LayoutInflater: The LayoutInflater object that can be used to inflate any views in the fragment

container ViewGroup: 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 Bundle: If non-null, this fragment is being re-constructed from a previous saved state as given here

Returns
View Return the View for the fragment's UI, or null

onCreateView

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

Parameters
inflater LayoutInflater

container ViewGroup

savedInstanceState Bundle

Returns
View

onDestroy

public void onDestroy ()

scrollToBottom

public void scrollToBottom ()

Sets the card scroll position as far down as possible so the bottom edge is visible.

scrollToTop

public void scrollToTop ()

Sets the card scroll position as far up as possible so the top edge is visible.

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 int: a vertical gravity, either Gravity.TOP or Gravity.BOTTOM

setCardMarginBottom

public void setCardMarginBottom (int bottom)

Sets the additional margin between the bottom edge of the card shadow, and the parent view.

Parameters
bottom int: the top margin

setCardMarginLeft

public void setCardMarginLeft (int left)

Sets the additional margin between the left edge of the card shadow, and the parent view.

Parameters
left int: the top margin

setCardMarginRight

public void setCardMarginRight (int right)

Sets the additional margin between the right edge of the card shadow, and the parent view.

Parameters
right int: the top margin

setCardMarginTop

public void setCardMarginTop (int top)

Sets the additional margin between the top edge of the card shadow, and the parent view.

Parameters
top int: the top margin

setCardMargins

public void setCardMargins (int left, 
                int top, 
                int right, 
                int bottom)

Sets the additional margin between the card shadow edge and the parent view.

Parameters
left int: the left margin

top int: the top margin

right int: the right margin

bottom int: the bottom margin

setContentPadding

public void setContentPadding (int left, 
                int top, 
                int right, 
                int bottom)

Sets padding between the inside card edge and the card content.

Parameters
left int: the left padding

top int: the top padding

right int: the right padding

bottom int: the bottom padding

setContentPaddingBottom

public void setContentPaddingBottom (int bottomPadding)

Sets the padding between the inside card's bottom edge and the card content.

Parameters
bottomPadding int: the bottom padding

setContentPaddingLeft

public void setContentPaddingLeft (int leftPadding)

Sets the padding between the inside card's left edge and the card content.

Parameters
leftPadding int: the left padding

setContentPaddingRight

public void setContentPaddingRight (int rightPadding)

Sets the padding between the inside card's right edge and the card content.

Parameters
rightPadding int: the right padding

setContentPaddingTop

public void setContentPaddingTop (int topPadding)

Sets the padding between the inside card's top edge and the card content.

Parameters
topPadding int

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 int: a direction constant, either EXPAND_UP or EXPAND_DOWN

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.

Parameters
enabled boolean

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 float: the vertical height multiplier to set the maximum height