Skip to content

Fork of the CardsUI library by Nadav Fima with more features, including the popular Google Now & Google Play cards views, and an additional MVC implementation

License

Notifications You must be signed in to change notification settings

Androguide/cardsui-for-android

 
 

Repository files navigation

CardsUI

An open source library offering the popular Google Now & Google Play cards views, additionnal features, view recycling and an optional Model-View-Controller structure.

Google Play Cards

This new type of card based on the new Google play design are highly customizable.

The parameters include :

  • Title text (String)
  • Description text (String)
  • Title color (String)
  • Stripe color (String)
  • Menu overflow (Boolean)
  • Touch feedback on click (Boolean)

Here is an example :

mCardView.addCard(new MyPlayCard(
        "Different Colors for Title & Stripe", 
        "You can set any color for the title and any other color for the left stripe", 
        "#f2a400", "#9d36d0", true, false));

Additionnal Features

In addition to the Google Play cards, I made a few changes to the original library by Nadav Fima.

Those changes include :

  • Setting regular cards's description text programmatically

Called like this :

mCardView.addCard(new MyCard("title string", "description string");
  • Setting stack titles's color programmatically_

Called like this :

CardStack stack = new CardStack();
stack.setTitle("Card Title");
stack.setColor("#33b5e5");
mCardView.addStack(stack);
  • Attaching arbitrary data to cards

The data property of AbstractCard allows the programmer to attach arbitrary data to any Card or even a stack of cards, since CardStack extends AbstractCard. This attached data can be set and retrived in the following fashion:

Integer myData = 42;
card.setData(myData);
//...
Integer theData = (Integer) card.getData();
// theData == 42
  • Setting custom card backgrounds

If you want to provide a custom Drawable for the Card's background, then use the setBackgroundResource() method:

card.setBackgroundResource(R.drawable.custom_card_bg);

Model-View-Controller implementation

The CardModel is essentially a copy of AbstractCard, except that it is concrete, Serializable, and specifies a target type that should be used when put through CardFactory.createCard(CardModel). CardFactory defines a single, static function, createCard(CardModel), which uses the Reflection API to inflate a CardModel into a descendant of AbstractCard as specified by model.cardClass. You can check-out an example at FLamparski's FLamparski/areabase, namely in the SummaryFragment class.

Example:

CardModel model = new CardModel("This is the card's description", "This is the card's title", BasicCard.class);
BasicCard card = (BasicCard) CardFactory.createCard(model); // This cast is safe
mCardUI.addCard(card);

Special thanks to https://github.com/FLamparski for the MVC implementation and data attachement/background modification commits.

CardsUI Generator

I'm working on a supplementary example app for the CardsUI library. This app includes a little daemon to generate cards and set their parameters with a nice animated gui. Ultimately, the aim of this app will be to generate a zip file containing the code & resources needed for the cards "activity" the user generated in the app. Considering that the cards layouts need to be on the app side, and not on the library side, this could be useful.

screenshot1 screenshot2 screenshot3 screenshot4 screenshot5 screenshot6

About

Fork of the CardsUI library by Nadav Fima with more features, including the popular Google Now & Google Play cards views, and an additional MVC implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 90.9%
  • Shell 7.8%
  • Groovy 1.3%