Search in sources :

Example 1 with CardHeader

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

the class NativeFabFragment 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) CardListView(it.gmariotti.cardslib.library.view.CardListView) View(android.view.View) BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) Card(it.gmariotti.cardslib.library.internal.Card)

Example 2 with CardHeader

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

the class NativeExpandPicassoFragment method initCard.

/**
 * This method builds a simple cards list
 */
private void initCard() {
    // Only for test scope, use images on assets folder
    String[] fileName = { "file:///android_asset/images/sea.jpg", "file:///android_asset/images/snow.jpg", "file:///android_asset/images/water.jpg", "file:///android_asset/images/img2.jpg", "file:///android_asset/images/rose.jpg" };
    // Only for test scope, use 5 different header titles
    int[] resTitleId = { R.string.carddemo_extras_header_expand_area_inside_sea, R.string.carddemo_extras_header_expand_area_inside_snow, R.string.carddemo_extras_header_expand_area_inside_water, R.string.carddemo_extras_header_expand_area_inside_img2, R.string.carddemo_extras_header_expand_area_inside_rose };
    // Remove debugging from Picasso
    Picasso.with(getActivity()).setDebugging(false);
    // Init an array of Cards
    ArrayList<Card> cards = new ArrayList<Card>();
    for (int j = 1; j < 30; j++) {
        for (int i = 0; i < 10; i++) {
            // Card
            CardInside card = new CardInside(this.getActivity());
            // Create a CardHeader
            CardHeader header = new CardHeader(getActivity(), R.layout.carddemo_extras_expandinside_inner_base_header);
            if (i % 2 == 0) {
                // Set the header title
                header.setTitle(getString(resTitleId[(int) (i / 2) % 5]));
                // Add Header to card
                card.addCardHeader(header);
                // Add an expand area
                CardExpandInside expand = new CardExpandInside(getActivity(), fileName[(int) (i / 2) % 5]);
                card.addCardExpand(expand);
            } else {
                // Set the header title
                header.setTitle(getString(R.string.carddemo_extras_header_expand_area_inside));
                // Add Header to card
                card.addCardHeader(header);
                // Only for test scope, use a random number
                int randomNumber = (int) (Math.random() * 6);
                // Add an expand area
                CardExpandInsideSquare expand = new CardExpandInsideSquare(getActivity(), randomNumber);
                card.addCardExpand(expand);
            }
            // Add a viewToClickExpand to enable click on whole card
            ViewToClickToExpand viewToClickToExpand = ViewToClickToExpand.builder().highlightView(false).setupCardElement(ViewToClickToExpand.CardElementUI.CARD);
            card.setViewToClickToExpand(viewToClickToExpand);
            cards.add(card);
        }
    }
    // Set the arrayAdapter
    CardArrayAdapter mCardArrayAdapter = new CardArrayAdapter(getActivity(), cards);
    CardListView listView = (CardListView) getActivity().findViewById(R.id.carddemo_extra_list_mixinside);
    // Add an animator
    AnimationAdapter animCardArrayAdapter = new AlphaInAnimationAdapter(mCardArrayAdapter);
    animCardArrayAdapter.setAbsListView(listView);
    // animCardArrayAdapter.setInitialDelayMillis(500);
    if (listView != null) {
        listView.setExternalAdapter(animCardArrayAdapter, mCardArrayAdapter);
    }
}
Also used : ViewToClickToExpand(it.gmariotti.cardslib.library.internal.ViewToClickToExpand) AlphaInAnimationAdapter(com.nhaarman.listviewanimations.appearance.simple.AlphaInAnimationAdapter) ArrayList(java.util.ArrayList) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) CardArrayAdapter(it.gmariotti.cardslib.library.internal.CardArrayAdapter) Card(it.gmariotti.cardslib.library.internal.Card) CardListView(it.gmariotti.cardslib.library.view.CardListView) AlphaInAnimationAdapter(com.nhaarman.listviewanimations.appearance.simple.AlphaInAnimationAdapter) AnimationAdapter(com.nhaarman.listviewanimations.appearance.AnimationAdapter)

Example 3 with CardHeader

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

the class GoogleNowNativeWeatherCard method initCardHeader.

@Override
protected CardHeader initCardHeader() {
    // Add Header
    CardHeader header = new CardHeader(getContext(), R.layout.carddemo_googlenowweather_native_inner_header);
    // Add a popup menu. This method set OverFlow button to visible
    header.setPopupMenu(R.menu.popup_item, new CardHeader.OnClickCardHeaderPopupMenuListener() {

        @Override
        public void onMenuItemClick(BaseCard card, MenuItem item) {
            switch(item.getItemId()) {
                case R.id.action_add:
                    // Example: add an item
                    WeatherObject w1 = new WeatherObject(GoogleNowNativeWeatherCard.this);
                    w1.city = "Madrid";
                    w1.temperature = 24;
                    w1.weatherIcon = R.drawable.ic_action_sun;
                    w1.setObjectId(w1.city);
                    mLinearListAdapter.add(w1);
                    break;
                case R.id.action_remove:
                    // Example: remove an item
                    mLinearListAdapter.remove(mLinearListAdapter.getItem(0));
                    break;
            }
        }
    });
    // should use R.string.
    header.setTitle("Weather");
    return header;
}
Also used : BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) MenuItem(android.view.MenuItem)

Example 4 with CardHeader

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

the class GoogleNowStockCardwithList method initCardHeader.

@Override
protected CardHeader initCardHeader() {
    // Add Header
    CardHeader header = new CardHeader(getContext(), R.layout.carddemo_googlenowstock_withlist_native_inner_header) {

        @Override
        public void setupInnerViewElements(ViewGroup parent, View view) {
            super.setupInnerViewElements(parent, view);
            TextView subTitle = (TextView) view.findViewById(R.id.carddemo_googlenow_main_inner_lastupdate);
            if (subTitle != null) {
                // Should use strings.xml
                subTitle.setText("Updated: 23 minutes ago");
            }
        }
    };
    // should use strings.xml
    header.setTitle("Stocks today");
    return header;
}
Also used : ViewGroup(android.view.ViewGroup) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) TextView(android.widget.TextView) LinearListView(it.gmariotti.cardslib.library.prototypes.LinearListView) TextView(android.widget.TextView) View(android.view.View)

Example 5 with CardHeader

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

the class NativeListExpandCardFragment method init_standard_header_with_expandcollapse_button_custom_area.

/**
 * This method builds a standard header with a custom expand/collpase
 */
private Card init_standard_header_with_expandcollapse_button_custom_area(String titleHeader, int i) {
    // Create a Card
    Card card = new Card(getActivity());
    // Create a CardHeader
    CardHeader header = new CardHeader(getActivity());
    // Set the header title
    header.setTitle(titleHeader);
    // Set visible the expand/collapse button
    header.setButtonExpandVisible(true);
    // Add Header to card
    card.addCardHeader(header);
    // This provides a simple (and useless) expand area
    CustomExpandCard expand = new CustomExpandCard(getActivity(), i);
    // Add Expand Area to Card
    card.addCardExpand(expand);
    // Just an example to expand a card
    if (i == 2 || i == 7 || i == 9)
        card.setExpanded(true);
    // Swipe
    card.setSwipeable(true);
    // Animator listener
    card.setOnExpandAnimatorEndListener(new Card.OnExpandAnimatorEndListener() {

        @Override
        public void onExpandEnd(Card card) {
            Toast.makeText(getActivity(), "Expand " + card.getCardHeader().getTitle(), Toast.LENGTH_SHORT).show();
        }
    });
    card.setOnCollapseAnimatorEndListener(new Card.OnCollapseAnimatorEndListener() {

        @Override
        public void onCollapseEnd(Card card) {
            Toast.makeText(getActivity(), "Collpase " + card.getCardHeader().getTitle(), Toast.LENGTH_SHORT).show();
        }
    });
    return card;
}
Also used : CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) CustomExpandCard(it.gmariotti.cardslib.demo.cards.CustomExpandCard) CustomExpandCard(it.gmariotti.cardslib.demo.cards.CustomExpandCard) Card(it.gmariotti.cardslib.library.internal.Card)

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