Search in sources :

Example 36 with CardHeader

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

the class NativeCardFragment method init_custom_card_partial_listener.

/**
 * This method builds a custom card with a swipe action
 */
private void init_custom_card_partial_listener() {
    // Create a Card
    Card card1 = new Card(getActivity(), R.layout.carddemo_example_inner_content);
    CardHeader header1 = new CardHeader(getActivity());
    header1.setTitle(getString(R.string.demo_custom_shorttitle));
    card1.addCardHeader(header1);
    // Set the card inner text
    card1.setTitle(getString(R.string.demo_card_shorttitle));
    // Set a clickListener on ContentArea
    card1.addPartialOnClickListener(Card.CLICK_LISTENER_CONTENT_VIEW, new Card.OnCardClickListener() {

        @Override
        public void onClick(Card card, View view) {
            Toast.makeText(getActivity(), "Click on Content Area", Toast.LENGTH_LONG).show();
        }
    });
    // Set card in the cardView
    CardViewNative cardView1 = (CardViewNative) getActivity().findViewById(R.id.carddemo_example_card3_listeners1);
    cardView1.setCard(card1);
    // ----------------------------------------------------------------------------------
    // Create a Card
    Card card2 = new Card(getActivity(), R.layout.carddemo_example_inner_content);
    CardHeader header2 = new CardHeader(getActivity());
    header2.setTitle(getString(R.string.demo_custom_shorttitle));
    card2.addCardHeader(header2);
    // Set the card inner text
    card2.setTitle(getString(R.string.demo_card_shorttitle));
    // Set a clickListener on Header Area
    card2.addPartialOnClickListener(Card.CLICK_LISTENER_HEADER_VIEW, new Card.OnCardClickListener() {

        @Override
        public void onClick(Card card, View view) {
            Toast.makeText(getActivity(), "Click on Header Area", Toast.LENGTH_LONG).show();
        }
    });
    // Set card in the cardView
    CardViewNative cardView2 = (CardViewNative) getActivity().findViewById(R.id.carddemo_example_card3_listeners2);
    cardView2.setCard(card2);
}
Also used : CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) View(android.view.View) Card(it.gmariotti.cardslib.library.internal.Card) CustomCard(it.gmariotti.cardslib.demo.cards.CustomCard) CardViewNative(it.gmariotti.cardslib.library.view.CardViewNative)

Example 37 with CardHeader

use of it.gmariotti.cardslib.library.internal.CardHeader 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 38 with CardHeader

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

the class NativeCardExpandFragment method init_custom_card_expand_inside.

/**
 * This method builds a card with a collpse/expand section inside
 */
private void init_custom_card_expand_inside() {
    // 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_expand_area_inside));
    // Add Header to card
    card.addCardHeader(header);
    // This provides a simple (and useless) expand area
    CardExpandInside expand = new CardExpandInside(getActivity());
    card.addCardExpand(expand);
    // Set card in the cardView
    CardViewNative cardView = (CardViewNative) getActivity().findViewById(R.id.carddemo_example_card_expand5);
    ViewToClickToExpand viewToClickToExpand = ViewToClickToExpand.builder().highlightView(false).setupView(cardView);
    card.setViewToClickToExpand(viewToClickToExpand);
    card.setOnExpandAnimatorEndListener(new Card.OnExpandAnimatorEndListener() {

        @Override
        public void onExpandEnd(Card card) {
        /*
                if (mScrollView!=null){
                    mScrollView.post(new Runnable() {
                        public void run() {
                            mScrollView.scrollTo(0, mScrollView.getBottom());
                        }
                    });
                }*/
        }
    });
    cardView.setCard(card);
}
Also used : ViewToClickToExpand(it.gmariotti.cardslib.library.internal.ViewToClickToExpand) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) Card(it.gmariotti.cardslib.library.internal.Card) CustomCard(it.gmariotti.cardslib.demo.cards.CustomCard) CardViewNative(it.gmariotti.cardslib.library.view.CardViewNative)

Example 39 with CardHeader

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

the class NativeCardExpandFragment method init_standard_header_with_expandcollapse_button.

/**
 * This method builds a standard header with base expand/collapse
 */
private void init_standard_header_with_expandcollapse_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));
    // Set visible the expand/collapse button
    header.setButtonExpandVisible(true);
    // Add Header to card
    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_customtitle3));
    card.addCardExpand(expand);
    // Set card in the cardView
    CardViewNative cardView = (CardViewNative) getActivity().findViewById(R.id.carddemo_example_card_expand1);
    cardView.setCard(card);
}
Also used : CardExpand(it.gmariotti.cardslib.library.internal.CardExpand) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) Card(it.gmariotti.cardslib.library.internal.Card) CustomCard(it.gmariotti.cardslib.demo.cards.CustomCard) CardViewNative(it.gmariotti.cardslib.library.view.CardViewNative)

Example 40 with CardHeader

use of it.gmariotti.cardslib.library.internal.CardHeader 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)

Aggregations

CardHeader (it.gmariotti.cardslib.library.internal.CardHeader)58 Card (it.gmariotti.cardslib.library.internal.Card)51 BaseCard (it.gmariotti.cardslib.library.internal.base.BaseCard)27 CustomExpandCard (it.gmariotti.cardslib.demo.cards.CustomExpandCard)20 CardView (it.gmariotti.cardslib.library.view.CardView)20 CardViewNative (it.gmariotti.cardslib.library.view.CardViewNative)20 View (android.view.View)19 CustomHeaderInnerCard (it.gmariotti.cardslib.demo.cards.CustomHeaderInnerCard)18 MenuItem (android.view.MenuItem)15 CustomCard (it.gmariotti.cardslib.demo.cards.CustomCard)12 ScrollView (android.widget.ScrollView)11 TextView (android.widget.TextView)8 CardExpand (it.gmariotti.cardslib.library.internal.CardExpand)8 CustomThumbCard (it.gmariotti.cardslib.demo.cards.CustomThumbCard)6 CardThumbnail (it.gmariotti.cardslib.library.internal.CardThumbnail)6 ArrayList (java.util.ArrayList)5 PopupMenu (android.widget.PopupMenu)4 ViewToClickToExpand (it.gmariotti.cardslib.library.internal.ViewToClickToExpand)4 CardListView (it.gmariotti.cardslib.library.view.CardListView)4 ViewGroup (android.view.ViewGroup)2