Search in sources :

Example 6 with CardViewWrapper

use of it.gmariotti.cardslib.library.view.base.CardViewWrapper in project cardslib by gabrielemariotti.

the class MayKnowCard method setupInnerViewElements.

@Override
public void setupInnerViewElements(ViewGroup parent, View view) {
    TextView title = (TextView) view.findViewById(R.id.carddemo_mayknow_main_inner_title);
    TextView subtitle = (TextView) view.findViewById(R.id.carddemo_mayknow_main_inner_subtitle);
    TextView add = (TextView) view.findViewById(R.id.carddemo_mayknow_main_inner_button);
    title.setText(getContext().getString(R.string.may_know_card_inner_title));
    subtitle.setText(getContext().getString(R.string.may_know_card_inner_subtitle));
    add.setClickable(true);
    CardViewWrapper cardView = getCardView();
    CardThumbnailView thumb = cardView.getInternalThumbnailLayout();
    if (thumb != null) {
        ViewGroup.LayoutParams lp = thumb.getLayoutParams();
        if (lp instanceof ViewGroup.MarginLayoutParams) {
            ((ViewGroup.MarginLayoutParams) lp).setMargins(25, 0, 0, 5);
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) CardViewWrapper(it.gmariotti.cardslib.library.view.base.CardViewWrapper) CardThumbnailView(it.gmariotti.cardslib.library.view.component.CardThumbnailView)

Example 7 with CardViewWrapper

use of it.gmariotti.cardslib.library.view.base.CardViewWrapper in project cardslib by gabrielemariotti.

the class CardView method setupListeners.

/**
     * Setup All listeners
     */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
protected void setupListeners() {
    //Swipe listener
    if (mCard.isSwipeable()) {
        this.setOnTouchListener(new SwipeDismissViewTouchListener(this, mCard, new SwipeDismissViewTouchListener.DismissCallbacks() {

            @Override
            public boolean canDismiss(Card card) {
                return card.isSwipeable();
            }

            @Override
            public void onDismiss(CardViewWrapper cardView, Card card) {
                final ViewGroup vg = (ViewGroup) (((View) cardView).getParent());
                if (vg != null) {
                    vg.removeView((View) cardView);
                    card.onSwipeCard();
                }
            }
        }));
    } else {
        this.setOnTouchListener(null);
    }
    //OnClick listeners and partial listener
    //Reset Partial Listeners
    resetPartialListeners();
    if (mCard.isClickable()) {
        //Set the onClickListener
        if (!mCard.isMultiChoiceEnabled()) {
            if (mCard.getOnClickListener() != null) {
                this.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (mCard.getOnClickListener() != null)
                            mCard.getOnClickListener().onClick(mCard, v);
                    }
                });
            //Prevent multiple events
            //if (!mCard.isSwipeable() && mCard.getOnSwipeListener() == null) {
            //    this.setClickable(true);
            //}
            } else {
                HashMap<Integer, Card.OnCardClickListener> mMultipleOnClickListner = mCard.getMultipleOnClickListener();
                if (mMultipleOnClickListner != null && !mMultipleOnClickListner.isEmpty()) {
                    for (int key : mMultipleOnClickListner.keySet()) {
                        View viewClickable = decodeAreaOnClickListener(key);
                        final Card.OnCardClickListener mListener = mMultipleOnClickListner.get(key);
                        if (viewClickable != null) {
                            //Add listener to this view
                            viewClickable.setOnClickListener(new OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    //Callback to card listener
                                    if (mListener != null)
                                        mListener.onClick(mCard, v);
                                }
                            });
                            //Add Selector to this view
                            if (key > Card.CLICK_LISTENER_ALL_VIEW) {
                                mHelperImpl.setCardSelector(viewClickable, getResources().getDrawable(R.drawable.card_selector));
                            }
                        }
                    }
                } else {
                    //There aren't listners
                    this.setClickable(false);
                }
            }
        }
    } else {
        this.setClickable(false);
    }
    //LongClick listener
    if (mCard.isLongClickable()) {
        this.setOnLongClickListener(new OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                if (mCard.getOnLongClickListener() != null)
                    return mCard.getOnLongClickListener().onLongClick(mCard, v);
                return false;
            }
        });
    } else {
        this.setLongClickable(false);
    }
}
Also used : ViewGroup(android.view.ViewGroup) View(android.view.View) CardThumbnailView(it.gmariotti.cardslib.library.view.component.CardThumbnailView) CardHeaderView(it.gmariotti.cardslib.library.view.component.CardHeaderView) SuppressLint(android.annotation.SuppressLint) Card(it.gmariotti.cardslib.library.internal.Card) CardViewWrapper(it.gmariotti.cardslib.library.view.base.CardViewWrapper) SwipeDismissViewTouchListener(it.gmariotti.cardslib.library.view.listener.SwipeDismissViewTouchListener) SuppressLint(android.annotation.SuppressLint)

Example 8 with CardViewWrapper

use of it.gmariotti.cardslib.library.view.base.CardViewWrapper in project cardslib by gabrielemariotti.

the class CardViewNative method setupListeners.

/**
     * Setup All listeners
     */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
protected void setupListeners() {
    //Swipe listener
    if (mCard.isSwipeable()) {
        this.setOnTouchListener(new SwipeDismissViewTouchListener(this, mCard, new SwipeDismissViewTouchListener.DismissCallbacks() {

            @Override
            public boolean canDismiss(Card card) {
                return card.isSwipeable();
            }

            @Override
            public void onDismiss(CardViewWrapper cardView, Card card) {
                final ViewGroup vg = (ViewGroup) (((View) cardView).getParent());
                if (vg != null) {
                    vg.removeView((View) cardView);
                    card.onSwipeCard();
                }
            }
        }));
    } else {
        this.setOnTouchListener(null);
    }
    //OnClick listeners and partial listener
    //Reset Partial Listeners
    resetPartialListeners();
    if (mCard.isClickable()) {
        //Set the onClickListener
        if (!mCard.isMultiChoiceEnabled()) {
            if (mCard.getOnClickListener() != null) {
                this.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (mCard.getOnClickListener() != null)
                            mCard.getOnClickListener().onClick(mCard, v);
                    }
                });
            //Prevent multiple events
            //if (!mCard.isSwipeable() && mCard.getOnSwipeListener() == null) {
            //    this.setClickable(true);
            //}
            } else {
                HashMap<Integer, Card.OnCardClickListener> mMultipleOnClickListner = mCard.getMultipleOnClickListener();
                if (mMultipleOnClickListner != null && !mMultipleOnClickListner.isEmpty()) {
                    for (int key : mMultipleOnClickListner.keySet()) {
                        View viewClickable = decodeAreaOnClickListener(key);
                        final Card.OnCardClickListener mListener = mMultipleOnClickListner.get(key);
                        if (viewClickable != null) {
                            //Add listener to this view
                            viewClickable.setOnClickListener(new OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    //Callback to card listener
                                    if (mListener != null)
                                        mListener.onClick(mCard, v);
                                }
                            });
                            //Add Selector to this view
                            if (key > Card.CLICK_LISTENER_ALL_VIEW) {
                                mHelperImpl.setBackground(viewClickable, mHelperImpl.getResourceFromAttrs(getContext(), android.R.attr.selectableItemBackground));
                            }
                        }
                    }
                } else {
                    //There aren't listners
                    this.setClickable(false);
                }
            }
        }
    } else {
        this.setClickable(false);
    }
    //LongClick listener
    if (mCard.isLongClickable()) {
        this.setOnLongClickListener(new OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                if (mCard.getOnLongClickListener() != null)
                    return mCard.getOnLongClickListener().onLongClick(mCard, v);
                return false;
            }
        });
    } else {
        this.setLongClickable(false);
    }
}
Also used : ViewGroup(android.view.ViewGroup) View(android.view.View) CardThumbnailView(it.gmariotti.cardslib.library.view.component.CardThumbnailView) CardHeaderView(it.gmariotti.cardslib.library.view.component.CardHeaderView) SuppressLint(android.annotation.SuppressLint) Card(it.gmariotti.cardslib.library.internal.Card) CardViewWrapper(it.gmariotti.cardslib.library.view.base.CardViewWrapper) SwipeDismissViewTouchListener(it.gmariotti.cardslib.library.view.listener.SwipeDismissViewTouchListener) SuppressLint(android.annotation.SuppressLint)

Example 9 with CardViewWrapper

use of it.gmariotti.cardslib.library.view.base.CardViewWrapper in project cardslib by gabrielemariotti.

the class CardDragDropArrayAdapter method setupLongClickForDragSupport.

/**
     * Enables the longClick event to drag and drop cards
     *
     * @param position
     * @param mCard
     */
private void setupLongClickForDragSupport(int position, Card mCard) {
    CardViewWrapper mCardView = mCard.getCardView();
    mCardView.setLongClickable(true);
}
Also used : CardViewWrapper(it.gmariotti.cardslib.library.view.base.CardViewWrapper)

Example 10 with CardViewWrapper

use of it.gmariotti.cardslib.library.view.base.CardViewWrapper in project cardslib by gabrielemariotti.

the class CardGridStaggeredArrayAdapter method getView.

// -------------------------------------------------------------
// Views
// -------------------------------------------------------------
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    CardViewWrapper mCardView;
    Card mCard;
    LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    //Retrieve card from items
    mCard = (Card) getItem(position);
    if (mCard != null) {
        int layout = mRowLayoutId;
        boolean recycle = false;
        //Inflate layout
        if (view == null) {
            recycle = false;
            view = mInflater.inflate(layout, parent, false);
        } else {
            recycle = true;
        }
        //Setup card
        mCardView = (CardViewWrapper) view.findViewById(R.id.list_cardId);
        if (mCardView != null) {
            //It is important to set recycle value for inner layout elements
            mCardView.setForceReplaceInnerLayout(Card.equalsInnerLayout(mCardView.getCard(), mCard));
            //It is important to set recycle value for performance issue
            mCardView.setRecycle(recycle);
            //Save original swipeable value
            boolean origianlSwipeable = mCard.isSwipeable();
            //Set false to avoid swape card default action
            mCard.setSwipeable(false);
            mCardView.setCard(mCard);
            //mCard.setSwipeable(origianlSwipeable);
            if (origianlSwipeable)
                Log.d(TAG, "Swipe action not enabled in this type of view");
            //If card has an expandable button override animation
            if ((mCard.getCardHeader() != null && mCard.getCardHeader().isButtonExpandVisible()) || mCard.getViewToClickToExpand() != null) {
                //setupExpandCollapseListAnimation(mCardView);
                Log.d(TAG, "Expand action not enabled in this type of view");
            }
            //Setup swipeable animation
            //setupSwipeableAnimation(mCard, mCardView);
            //setupMultiChoice
            setupMultichoice(view, mCard, mCardView, position);
        }
    }
    return view;
}
Also used : LayoutInflater(android.view.LayoutInflater) CardViewWrapper(it.gmariotti.cardslib.library.view.base.CardViewWrapper) View(android.view.View) CardGridStaggeredView(it.gmariotti.cardslib.library.extra.staggeredgrid.view.CardGridStaggeredView) Card(it.gmariotti.cardslib.library.internal.Card)

Aggregations

CardViewWrapper (it.gmariotti.cardslib.library.view.base.CardViewWrapper)15 View (android.view.View)8 Card (it.gmariotti.cardslib.library.internal.Card)6 LayoutInflater (android.view.LayoutInflater)4 ViewGroup (android.view.ViewGroup)3 CardThumbnailView (it.gmariotti.cardslib.library.view.component.CardThumbnailView)3 SuppressLint (android.annotation.SuppressLint)2 AbsListView (android.widget.AbsListView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 CardListView (it.gmariotti.cardslib.library.view.CardListView)2 CardHeaderView (it.gmariotti.cardslib.library.view.component.CardHeaderView)2 SwipeDismissViewTouchListener (it.gmariotti.cardslib.library.view.listener.SwipeDismissViewTouchListener)2 ArrayList (java.util.ArrayList)2 AdapterView (android.widget.AdapterView)1 ColorCard (it.gmariotti.cardslib.demo.extras.cards.ColorCard)1 CardGridStaggeredView (it.gmariotti.cardslib.library.extra.staggeredgrid.view.CardGridStaggeredView)1 CardExpandableListView (it.gmariotti.cardslib.library.view.CardExpandableListView)1 CardGridView (it.gmariotti.cardslib.library.view.CardGridView)1 CardView (it.gmariotti.cardslib.library.view.CardView)1