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);
}
}
}
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);
}
}
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);
}
}
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);
}
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;
}
Aggregations