use of android.view.MenuItem in project cardslib by gabrielemariotti.
the class WeatherCard method initCardHeader.
@Override
protected CardHeader initCardHeader() {
//Add Header
CardHeader header = new CardHeader(getContext());
//Add a popup menu. This method set OverFlow button to visible
header.setPopupMenu(R.menu.extras_popupmain, new CardHeader.OnClickCardHeaderPopupMenuListener() {
@Override
public void onMenuItemClick(BaseCard card, MenuItem item) {
Toast.makeText(getContext(), "Click on " + item.getTitle(), Toast.LENGTH_SHORT).show();
}
});
//should use R.string.
header.setTitle("ROMA (IT)");
return header;
}
use of android.view.MenuItem in project cardslib by gabrielemariotti.
the class RecyclerViewFragment method initCard.
/**
* This method builds a simple list of cards
*/
private ArrayList<Card> initCard() {
//Init an array of Cards
ArrayList<Card> cards = new ArrayList<Card>();
for (int i = 0; i < 200; i++) {
Card card = new Card(this.getActivity());
card.setTitle("Application example " + i);
//Create a CardHeader
CardHeader header = new CardHeader(getActivity());
//Set the header title
header.setTitle(getString(R.string.demo_header_basetitle));
if (i < 10) {
//Add a popup menu. This method set OverFlow button to visible
header.setPopupMenu(R.menu.popupmain, new CardHeader.OnClickCardHeaderPopupMenuListener() {
@Override
public void onMenuItemClick(BaseCard card, MenuItem item) {
Toast.makeText(getActivity(), "Click on " + item.getTitle(), Toast.LENGTH_SHORT).show();
}
});
card.addCardHeader(header);
} else {
//Set visible the expand/collapse button
header.setButtonExpandVisible(true);
card.addCardHeader(header);
//This provides a simple (and useless) expand area
CardExpand expand = new CardExpand(getActivity());
//Set inner title in Expand Area
expand.setTitle(getString(R.string.demo_expand_basetitle));
card.addCardExpand(expand);
if (i == 12 || i == 17 || i == 19)
card.setExpanded(true);
}
//Add ClickListener
card.setOnClickListener(new Card.OnCardClickListener() {
@Override
public void onClick(Card card, View view) {
Toast.makeText(getActivity(), "Click Listener card=" + card.getTitle(), Toast.LENGTH_SHORT).show();
}
});
cards.add(card);
}
return cards;
}
use of android.view.MenuItem in project cardslib by gabrielemariotti.
the class StockCardFragment method onCreateOptionsMenu.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.sharemenu, menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.carddemo_menu_item_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) item.getActionProvider();
mShareActionProvider.setShareIntent(getShareIntent());
super.onCreateOptionsMenu(menu, inflater);
}
use of android.view.MenuItem in project cardslib by gabrielemariotti.
the class HeaderFragment method init_standard_header_with_overflow_button_dynamic_menu_without_xml.
/**
* This method builds a standard header with overflow button with a dynamic menu
*/
private void init_standard_header_with_overflow_button_dynamic_menu_without_xml() {
//Create a Card
Card card = new Card(getActivity());
//Create a CardHeader
CardHeader header = new CardHeader(getActivity());
//Set the header title
header.setTitle(getString(R.string.demo_header_basetitle));
//Add a popup menu. This method set OverFlow button to visible
header.setButtonOverflowVisible(true);
header.setPopupMenuListener(new CardHeader.OnClickCardHeaderPopupMenuListener() {
@Override
public void onMenuItemClick(BaseCard card, MenuItem item) {
Toast.makeText(getActivity(), "Click on " + item.getTitle() + "-" + ((Card) card).getCardHeader().getTitle(), Toast.LENGTH_SHORT).show();
}
});
//Add a PopupMenuPrepareListener to add dynamically a menu entry
//it is optional.
header.setPopupMenuPrepareListener(new CardHeader.OnPrepareCardHeaderPopupMenuListener() {
@Override
public boolean onPreparePopupMenu(BaseCard card, PopupMenu popupMenu) {
popupMenu.getMenu().add("Dynamic item");
return true;
}
});
card.addCardHeader(header);
//Set card in the CardView
CardView cardView = (CardView) getActivity().findViewById(R.id.carddemo_header_overflow_dynamic2);
cardView.setCard(card);
}
use of android.view.MenuItem in project cardslib by gabrielemariotti.
the class HeaderFragment method init_standard_header_with_overflow_button.
/**
* This method builds a standard header with overflow button
*/
private void init_standard_header_with_overflow_button() {
//Create a Card
Card card = new Card(getActivity());
//Create a CardHeader
CardHeader header = new CardHeader(getActivity());
//Set the header title
header.setTitle(getString(R.string.demo_header_basetitle));
//Add a popup menu. This method set OverFlow button to visible
header.setPopupMenu(R.menu.popupmain, new CardHeader.OnClickCardHeaderPopupMenuListener() {
@Override
public void onMenuItemClick(BaseCard card, MenuItem item) {
Toast.makeText(getActivity(), "Click on " + item.getTitle(), Toast.LENGTH_SHORT).show();
}
});
card.addCardHeader(header);
//Set card in the CardView
CardView CardView = (CardView) getActivity().findViewById(R.id.carddemo_header_overflow);
CardView.setCard(card);
}
Aggregations