Page Summary
-
The CardBuilder class is used for creating Glass-themed cards with various layouts.
-
General usage involves creating a CardBuilder object, setting content, and getting a View or RemoteViews object.
-
When using EMBED_INSIDE, CardBuilder treats different embedded layouts the same for recycling unless distinguished by view types.
-
CardBuilder offers methods to add images, set text, footnotes, headings, subheadings, icons, attribution icons, and timestamps.
-
The class provides methods to get a View or RemoteViews representation of the card and manage view types for adapters.
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
- Create a
CardBuilderobject, passing the desiredCardBuilder.Layoutto the constructor. - Set content on the card with the
add/set*family of methods. - Get the
Viewby callinggetView()or get aRemoteViewsobject withgetRemoteViews().
Recycling note for embedded layouts
When usingEMBED_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 | |||||||||||
| CardBuilder | |||||||||||
| CardBuilder |
addImage(int imageId)
|
||||||||||
| void | |||||||||||
| int | |||||||||||
| RemoteViews | |||||||||||
| View | |||||||||||
| View |
getView()
|
||||||||||
| static int | |||||||||||
| CardBuilder |
setAttributionIcon(Bitmap iconBitmap)
|
||||||||||
| CardBuilder |
setAttributionIcon(Drawable iconDrawable)
|
||||||||||
| CardBuilder |
setAttributionIcon(int iconId)
|
||||||||||
| CardBuilder |
setEmbeddedLayout(int layoutResId)
|
||||||||||
| CardBuilder |
setFootnote(CharSequence footnote)
|
||||||||||
| CardBuilder |
setFootnote(int footnoteId)
|
||||||||||
| CardBuilder |
setHeading(CharSequence heading)
|
||||||||||
| CardBuilder |
setHeading(int headingId)
|
||||||||||
| CardBuilder | |||||||||||
| CardBuilder | |||||||||||
| CardBuilder |
setIcon(int iconId)
|
||||||||||
| CardBuilder |
setSubheading(CharSequence subheading)
|
||||||||||
| CardBuilder |
setSubheading(int subheadingId)
|
||||||||||
| CardBuilder |
setText(int textId)
|
||||||||||
| CardBuilder |
setText(CharSequence text)
|
||||||||||
| CardBuilder |
setTimestamp(CharSequence timestamp)
|
||||||||||
| CardBuilder |
setTimestamp(int timestampId)
|
||||||||||
| CardBuilder |
showStackIndicator(boolean visible)
|
||||||||||
| Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Public Constructors
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
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
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
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
public void clearImages ()
Clears all images that were previously added to the card.
public int getItemViewType ()
Returns the view type of this particular card.
Useful in combination with an adapter.
See getItemViewType(int).
public RemoteViews getRemoteViews ()
Returns a RemoteViews representation of this card.
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
|
public static int getViewTypeCount ()
Returns the total number of view types cards can take.
Useful in combination with an adapter.
See getViewTypeCount().
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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