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.

CardBuilder

Added in API level XE21

The CardBuilder class helps with building Glass-themed cards with various layouts.

See Creating Glass-styled cards for more information and sample code.

General usage

  1. Create a CardBuilder object, passing the desired CardBuilder.Layout to the constructor.
  2. Set content on the card with the add/set* family of methods.
  3. Get the View by calling getView() or get a RemoteViews object with getRemoteViews().

Recycling note for embedded layouts

When using EMBED_INSIDE CardBuilder makes no distinction between different embedded layouts when recycling views. If you have two CardBuilder instances with EMBED_INSIDE but one has layout A and the other has layout B, they will be treated as the same by CardBuilder.

If this behavior is undesirable (for example, when using a CardScrollAdapter with different embedded layouts), you must distinguish them by returning different view types from getItemViewType(int) so that the recycler only sends you convertViews with nested layouts that you expect for a particular item.

If you need to support cards with multiple embedded layouts alongside the built-in layouts, we recommend that you return view types numbered getViewTypeCount(), CardBuilder.getViewTypeCount() + 1, and so on.

Nested Classes
enum CardBuilder.Layout Defines the visual layouts for cards. 
Public Constructors
Public Methods
CardBuilder
addImage(Drawable imageDrawable)
CardBuilder
addImage(Bitmap imageBitmap)
CardBuilder
addImage(int imageId)
void
int
RemoteViews
View
getView(View convertView, ViewGroup parent)
View
static int
CardBuilder
CardBuilder
CardBuilder
setAttributionIcon(int iconId)
CardBuilder
setEmbeddedLayout(int layoutResId)
CardBuilder
CardBuilder
setFootnote(int footnoteId)
CardBuilder
CardBuilder
setHeading(int headingId)
CardBuilder
setIcon(Bitmap iconBitmap)
CardBuilder
setIcon(Drawable iconDrawable)
CardBuilder
setIcon(int iconId)
CardBuilder
CardBuilder
setSubheading(int subheadingId)
CardBuilder
setText(int textId)
CardBuilder
CardBuilder
CardBuilder
setTimestamp(int timestampId)
CardBuilder
showStackIndicator(boolean visible)
Inherited Methods

Public Constructors

Added in API level XE21

public CardBuilder (Context context, CardBuilder.Layout layout)

Constructs a new CardBuilder.

Parameters
context the Context that will be used by the builder to create its views.
layout the desired layout for the card

Public Methods

Added in API level XE21

public CardBuilder addImage (Drawable imageDrawable)

Adds an image, specified as a Drawable, to the card.

This method only applies to cards that are converted into views using getView(). RemoteViews built by CardBuilder only support Bitmap and resource-based images. Drawable images on RemoteViews are not supported.

Parameters
imageDrawable the Drawable image to add
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder addImage (Bitmap imageBitmap)

Adds an image, specified as a Bitmap, to the card.

Parameters
imageBitmap the Bitmap image to add
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder addImage (int imageId)

Adds an image, specified as a drawable resource, to the card.

Parameters
imageId the resource ID of the image to add
Returns
  • this object for call chaining
Added in API level XE21

public void clearImages ()

Clears all images that were previously added to the card.

Added in API level XE21

public int getItemViewType ()

Returns the view type of this particular card.

Useful in combination with an adapter. See getItemViewType(int).

Added in API level XE21

public RemoteViews getRemoteViews ()

Returns a RemoteViews representation of this card.

Added in API level XE21

public View getView (View convertView, ViewGroup parent)

Returns a View representation of this card.

Useful in combination with an adapter. See getView(int, View, ViewGroup).

Parameters
convertView an old view to reuse, if possible; can be null Note: if this view does not have the right type, this method creates a new view
parent that this view will eventually be attached to, maybe null
Added in API level XE21

public View getView ()

Returns a View representation of this card.

Added in API level XE21

public static int getViewTypeCount ()

Returns the total number of view types cards can take.

Useful in combination with an adapter. See getViewTypeCount().

Added in API level XE22

public CardBuilder setAttributionIcon (Bitmap iconBitmap)

Sets the attribution icon for the card using a Bitmap.

Parameters
iconBitmap the Bitmap to use as the attribution icon
Returns
  • this object for call chaining
Added in API level XE22

public CardBuilder setAttributionIcon (Drawable iconDrawable)

Sets the attribution icon for the card using a Drawable.

This method only applies to cards that are converted into views using getView(). RemoteViews built by CardBuilder only support Bitmap and resource-based images. Drawable images on RemoteViews are not supported.

Parameters
iconDrawable the Drawable to use as the attribution icon
Returns
  • this object for call chaining
Added in API level XE22

public CardBuilder setAttributionIcon (int iconId)

Sets the attribution icon for the card using a drawable resource.

Parameters
iconId the resource ID to use as the attribution icon
Returns
  • this object for call chaining
Added in API level XE22

public CardBuilder setEmbeddedLayout (int layoutResId)

Sets the resource ID of the layout to embed in the card.

Parameters
layoutResId the resource ID of the layout to embed in the card
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder setFootnote (CharSequence footnote)

Sets the footnote text for the card.

Parameters
footnote the footnote text for this card
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder setFootnote (int footnoteId)

Sets the footnote text for the card using a string resource.

Parameters
footnoteId the footnote text resource ID for this card
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder setHeading (CharSequence heading)

Sets the heading text for the card.

Parameters
heading the heading text for this card
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder setHeading (int headingId)

Sets the heading text for the card using a string resource.

Parameters
headingId the heading text resource ID for this card
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder setIcon (Bitmap iconBitmap)

Sets the icon for the card using a Bitmap.

Parameters
iconBitmap the Bitmap to use as the icon
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder setIcon (Drawable iconDrawable)

Sets the icon for the card using a Drawable.

This method only applies to cards that are converted into views using getView(). RemoteViews built by CardBuilder only support Bitmap and resource-based images. Drawable images on RemoteViews are not supported.

Parameters
iconDrawable the Drawable to use as the icon
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder setIcon (int iconId)

Sets the icon for the card using a drawable resource.

Parameters
iconId the resource ID to use as the icon
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder setSubheading (CharSequence subheading)

Sets the subheading text for the card.

Parameters
subheading the subheading text for this card
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder setSubheading (int subheadingId)

Sets the subheading text for the card using a string resource.

Parameters
subheadingId the subheading text resource ID for this card
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder setText (int textId)

Sets the main text for the card using a string resource.

Parameters
textId main text resource ID for this card
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder setText (CharSequence text)

Sets the main text for the card.

Parameters
text main text for this card
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder setTimestamp (CharSequence timestamp)

Sets the timestamp text for the card.

Parameters
timestamp the timestamp text for this card
Returns
  • this object for call chaining
Added in API level XE21

public CardBuilder setTimestamp (int timestampId)

Sets the timestamp text for the card using a string resource.

Parameters
timestampId the timestamp text resource ID for this card
Returns
  • this object for call chaining
Added in API level XE22

public CardBuilder showStackIndicator (boolean visible)

Shows an indicator if visible is true that this card represents a stack of cards, rather than a single card.

Parameters
visible true to show the stack indicator, or false to hide it
Returns
  • this object for call chaining