Search in sources :

Example 11 with BaseCard

use of it.gmariotti.cardslib.library.internal.base.BaseCard in project cardslib by gabrielemariotti.

the class GplayCardCustomSource method init.

private void init() {
    CardHeader header = new CardHeader(getContext());
    header.setButtonOverflowVisible(true);
    header.setTitle("Google Maps");
    header.setPopupMenu(R.menu.popupmain, new CardHeader.OnClickCardHeaderPopupMenuListener() {

        @Override
        public void onMenuItemClick(BaseCard card, MenuItem item) {
            Toast.makeText(getContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
        }
    });
    addCardHeader(header);
    CardThumbnail thumbnail = new CardThumbnail(getContext());
    thumbnail.setCustomSource(new CardThumbnail.CustomSource() {

        @Override
        public String getTag() {
            return "com.google.android.apps.maps";
        }

        @Override
        public Bitmap getBitmap() {
            PackageManager pm = mContext.getPackageManager();
            Bitmap bitmap = null;
            try {
                bitmap = drawableToBitmap(pm.getApplicationIcon(getTag()));
            } catch (PackageManager.NameNotFoundException e) {
            }
            return bitmap;
        }

        private Bitmap drawableToBitmap(Drawable drawable) {
            if (drawable instanceof BitmapDrawable) {
                return ((BitmapDrawable) drawable).getBitmap();
            }
            Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
            drawable.draw(canvas);
            return bitmap;
        }
    });
    addCardThumbnail(thumbnail);
}
Also used : Canvas(android.graphics.Canvas) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) MenuItem(android.view.MenuItem) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CardThumbnail(it.gmariotti.cardslib.library.internal.CardThumbnail)

Example 12 with BaseCard

use of it.gmariotti.cardslib.library.internal.base.BaseCard in project cardslib by gabrielemariotti.

the class HeaderFragment method init_standard_header_with_overflow_button_dynamic_menu.

/**
     * This method builds a standard header with overflow button with a dynamic menu
     */
private void init_standard_header_with_overflow_button_dynamic_menu() {
    //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();
        }
    });
    //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_dynamic);
    cardView.setCard(card);
}
Also used : BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) CardView(it.gmariotti.cardslib.library.view.CardView) MenuItem(android.view.MenuItem) BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CustomExpandCard(it.gmariotti.cardslib.demo.cards.CustomExpandCard) CustomHeaderInnerCard(it.gmariotti.cardslib.demo.cards.CustomHeaderInnerCard) Card(it.gmariotti.cardslib.library.internal.Card) PopupMenu(android.widget.PopupMenu)

Example 13 with BaseCard

use of it.gmariotti.cardslib.library.internal.base.BaseCard in project cardslib by gabrielemariotti.

the class TodoNativeCardFragment method init_simple_card.

private void init_simple_card() {
    Card card = new Card(getActivity());
    CardHeader header = new CardHeader(getActivity());
    header.setTitle("Header");
    //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 CardViewNative
    CardViewNative CardViewNative = (CardViewNative) getActivity().findViewById(R.id.carddemo_card_id);
    CardViewNative.setCard(card);
}
Also used : BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) MenuItem(android.view.MenuItem) BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) Card(it.gmariotti.cardslib.library.internal.Card) CardViewNative(it.gmariotti.cardslib.library.view.CardViewNative)

Example 14 with BaseCard

use of it.gmariotti.cardslib.library.internal.base.BaseCard in project cardslib by gabrielemariotti.

the class NativeHeaderFragment 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 CardViewNative
    CardViewNative cardViewNative = (CardViewNative) getActivity().findViewById(R.id.carddemo_header_overflow_dynamic2);
    cardViewNative.setCard(card);
}
Also used : BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) MenuItem(android.view.MenuItem) BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CustomExpandCard(it.gmariotti.cardslib.demo.cards.CustomExpandCard) CustomHeaderInnerCard(it.gmariotti.cardslib.demo.cards.CustomHeaderInnerCard) Card(it.gmariotti.cardslib.library.internal.Card) PopupMenu(android.widget.PopupMenu) CardViewNative(it.gmariotti.cardslib.library.view.CardViewNative)

Example 15 with BaseCard

use of it.gmariotti.cardslib.library.internal.base.BaseCard in project cardslib by gabrielemariotti.

the class NativeRecyclerViewFragment 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;
}
Also used : CardExpand(it.gmariotti.cardslib.library.internal.CardExpand) BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) ArrayList(java.util.ArrayList) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) MenuItem(android.view.MenuItem) CardRecyclerView(it.gmariotti.cardslib.library.recyclerview.view.CardRecyclerView) View(android.view.View) BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) Card(it.gmariotti.cardslib.library.internal.Card)

Aggregations

MenuItem (android.view.MenuItem)15 CardHeader (it.gmariotti.cardslib.library.internal.CardHeader)15 BaseCard (it.gmariotti.cardslib.library.internal.base.BaseCard)15 Card (it.gmariotti.cardslib.library.internal.Card)10 CustomExpandCard (it.gmariotti.cardslib.demo.cards.CustomExpandCard)6 CustomHeaderInnerCard (it.gmariotti.cardslib.demo.cards.CustomHeaderInnerCard)6 PopupMenu (android.widget.PopupMenu)4 CardViewNative (it.gmariotti.cardslib.library.view.CardViewNative)4 View (android.view.View)3 CardExpand (it.gmariotti.cardslib.library.internal.CardExpand)3 CardView (it.gmariotti.cardslib.library.view.CardView)3 ArrayList (java.util.ArrayList)3 CardRecyclerView (it.gmariotti.cardslib.library.recyclerview.view.CardRecyclerView)2 PackageManager (android.content.pm.PackageManager)1 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1 CardThumbnail (it.gmariotti.cardslib.library.internal.CardThumbnail)1 CardListView (it.gmariotti.cardslib.library.view.CardListView)1