use of it.gmariotti.cardslib.library.view.listener.SwipeDismissViewTouchListener 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.listener.SwipeDismissViewTouchListener 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);
}
}
Aggregations