Search in sources :

Example 6 with ViewToClickToExpand

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

the class NativeCardExpandFragment method init_custom_card_expand_programmatic.

/**
     * This method builds a card with a collpse/expand action in programmatic way
     */
private void init_custom_card_expand_programmatic() {
    //Create a Card
    final Card card = new Card(getActivity());
    //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);
    ViewToClickToExpand viewToClickToExpand = ViewToClickToExpand.builder().enableForExpandAction();
    card.setViewToClickToExpand(viewToClickToExpand);
    TextView tx = (TextView) getActivity().findViewById(R.id.carddemo_example_card_expand6_text);
    tx.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            card.doToogleExpand();
        }
    });
    //Set card in the cardView
    CardViewNative cardView = (CardViewNative) getActivity().findViewById(R.id.carddemo_example_card_expand6);
    cardView.setCard(card);
}
Also used : ViewToClickToExpand(it.gmariotti.cardslib.library.internal.ViewToClickToExpand) CardExpand(it.gmariotti.cardslib.library.internal.CardExpand) TextView(android.widget.TextView) ImageView(android.widget.ImageView) 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 7 with ViewToClickToExpand

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

the class ExpandPicassoFragment 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 8 with ViewToClickToExpand

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

the class CardView method setupExpandCollapseActionListener.

//--------------------------------------------------------------------------
// Expandable Actions and Listeners
//--------------------------------------------------------------------------
/**
     * Add ClickListener to expand and collapse hidden view
     */
protected void setupExpandCollapseActionListener() {
    if (mInternalExpandLayout != null) {
        mInternalExpandLayout.setVisibility(View.GONE);
        boolean internal_blockForLongClickOnImageButtonExpand = false;
        ViewToClickToExpand viewToClickToExpand = null;
        //ButtonExpandVisible has a priority to viewClickToExpand
        if (mCardHeader != null && mCardHeader.isButtonExpandVisible()) {
            viewToClickToExpand = ViewToClickToExpand.builder().setupView(mInternalHeaderLayout.getImageButtonExpand()).highlightView(true);
            internal_blockForLongClickOnImageButtonExpand = true;
        } else if (mCard.getViewToClickToExpand() != null) {
            viewToClickToExpand = mCard.getViewToClickToExpand();
        }
        if (viewToClickToExpand != null) {
            TitleViewOnClickListener titleViewOnClickListener = new TitleViewOnClickListener(mInternalExpandLayout, mCard, viewToClickToExpand.isViewToSelect());
            /*if (mCardHeader!=null && mCardHeader.isButtonExpandVisible() && mInternalHeaderLayout != null) {
                    mInternalHeaderLayout.setOnClickExpandCollapseActionListener(titleViewOnClickListener);
                }*/
            View viewToClick = viewToClickToExpand.getViewToClick();
            if (viewToClick != null) {
                if (internal_blockForLongClickOnImageButtonExpand) {
                    //The long click on Header button is now allowed
                    viewToClick.setOnClickListener(titleViewOnClickListener);
                } else {
                    if (viewToClickToExpand.isUseLongClick()) {
                        viewToClick.setOnLongClickListener(new TitleViewOnLongClickListener(titleViewOnClickListener));
                    } else {
                        viewToClick.setOnClickListener(titleViewOnClickListener);
                    }
                }
            } else {
                ViewToClickToExpand.CardElementUI cardElementUI = viewToClickToExpand.getCardElementUIToClick();
                if (cardElementUI != null) {
                    switch(cardElementUI) {
                        case CARD:
                            viewToClick = this;
                            break;
                        case HEADER:
                            viewToClick = getInternalHeaderLayout();
                            break;
                        case THUMBNAIL:
                            viewToClick = getInternalThumbnailLayout();
                            break;
                        case MAIN_CONTENT:
                            viewToClick = getInternalContentLayout();
                            break;
                    }
                    if (viewToClick != null) {
                        if (viewToClickToExpand.isUseLongClick()) {
                            viewToClick.setOnLongClickListener(new TitleViewOnLongClickListener(titleViewOnClickListener));
                        } else {
                            viewToClick.setOnClickListener(titleViewOnClickListener);
                        }
                    }
                }
            }
            if (isExpanded()) {
                //Make layout visible and button selected
                mInternalExpandLayout.setVisibility(View.VISIBLE);
                if (viewToClick != null) {
                    if (viewToClickToExpand.isViewToSelect())
                        viewToClick.setSelected(true);
                }
            } else {
                //Make layout hidden and button not selected
                mInternalExpandLayout.setVisibility(View.GONE);
                if (viewToClick != null) {
                    if (viewToClickToExpand.isViewToSelect())
                        viewToClick.setSelected(false);
                }
            }
        }
    }
}
Also used : ViewToClickToExpand(it.gmariotti.cardslib.library.internal.ViewToClickToExpand) View(android.view.View) CardThumbnailView(it.gmariotti.cardslib.library.view.component.CardThumbnailView) CardHeaderView(it.gmariotti.cardslib.library.view.component.CardHeaderView)

Example 9 with ViewToClickToExpand

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

the class CardExpandFragment 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
    CardView cardView = (CardView) 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) CardView(it.gmariotti.cardslib.library.view.CardView) Card(it.gmariotti.cardslib.library.internal.Card) CustomCard(it.gmariotti.cardslib.demo.cards.CustomCard)

Example 10 with ViewToClickToExpand

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

the class CardExpandFragment method init_custom_card_expand.

/**
     * This method builds a custom card with expand/collapse action clickable in all card view
     */
private void init_custom_card_expand() {
    //Create a Card
    CustomCard card = new CustomCard(getActivity());
    //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
    CardView cardView = (CardView) getActivity().findViewById(R.id.carddemo_example_card_expand2);
    ViewToClickToExpand viewToClickToExpand = ViewToClickToExpand.builder().setupView(cardView);
    card.setViewToClickToExpand(viewToClickToExpand);
    cardView.setCard(card);
}
Also used : ViewToClickToExpand(it.gmariotti.cardslib.library.internal.ViewToClickToExpand) CustomCard(it.gmariotti.cardslib.demo.cards.CustomCard) CardExpand(it.gmariotti.cardslib.library.internal.CardExpand) CardView(it.gmariotti.cardslib.library.view.CardView)

Aggregations

ViewToClickToExpand (it.gmariotti.cardslib.library.internal.ViewToClickToExpand)10 CustomCard (it.gmariotti.cardslib.demo.cards.CustomCard)6 Card (it.gmariotti.cardslib.library.internal.Card)6 View (android.view.View)4 CardExpand (it.gmariotti.cardslib.library.internal.CardExpand)4 CardHeader (it.gmariotti.cardslib.library.internal.CardHeader)4 CardView (it.gmariotti.cardslib.library.view.CardView)3 CardViewNative (it.gmariotti.cardslib.library.view.CardViewNative)3 ImageView (android.widget.ImageView)2 ScrollView (android.widget.ScrollView)2 TextView (android.widget.TextView)2 AnimationAdapter (com.nhaarman.listviewanimations.appearance.AnimationAdapter)2 AlphaInAnimationAdapter (com.nhaarman.listviewanimations.appearance.simple.AlphaInAnimationAdapter)2 CardArrayAdapter (it.gmariotti.cardslib.library.internal.CardArrayAdapter)2 CardListView (it.gmariotti.cardslib.library.view.CardListView)2 CardHeaderView (it.gmariotti.cardslib.library.view.component.CardHeaderView)2 CardThumbnailView (it.gmariotti.cardslib.library.view.component.CardThumbnailView)2 ArrayList (java.util.ArrayList)2