Swipeable-Cards
Swipeable-Cards copied to clipboard
Programmatically swipe left/right
Hi there! First of all I need to thank you for this cool library.
I need to add like/dislike buttons just like the Tinder app and I'm wondering if there is an easy way to trigger the swipe animation programmatically by tapping the two buttons.
Hi guys, for those interested in this feature I've added two methods to CardContainer.java
public void dislike(){
final View topCard = mTopCard;
mTopCard = getChildAt(getChildCount() - 2);
CardModel cardModel = (CardModel)getAdapter().getItem(0);
if(mTopCard != null)
mTopCard.setLayerType(LAYER_TYPE_HARDWARE, null);
topCard.animate()
.setDuration(500)
.alpha(.75f)
.setInterpolator(new LinearInterpolator())
.x(-topCard.getWidth())
.y(topCard.getY())
.rotation(-45)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
removeViewInLayout(topCard);
ensureFull();
}
@Override
public void onAnimationCancel(Animator animation) {
onAnimationEnd(animation);
}
});
if(cardModel.getOnCardDimissedListener() != null){
cardModel.getOnCardDimissedListener().onDislike();
}
}
public void like(){
final View topCard = mTopCard;
mTopCard = getChildAt(getChildCount() - 2);
CardModel cardModel = (CardModel)getAdapter().getItem(0);
if(mTopCard != null)
mTopCard.setLayerType(LAYER_TYPE_HARDWARE, null);
topCard.animate()
.setDuration(500)
.alpha(.75f)
.setInterpolator(new LinearInterpolator())
.x(topCard.getWidth())
.y(topCard.getY())
.rotation(45)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
removeViewInLayout(topCard);
ensureFull();
}
@Override
public void onAnimationCancel(Animator animation) {
onAnimationEnd(animation);
}
});
if(cardModel.getOnCardDimissedListener() != null){
cardModel.getOnCardDimissedListener().onLike();
}
}
Of course you can adjust the animation's parameters to fit your needs. I have made several adjustment to the library based on my project's needs (including fading green and red stamps over the photos), so I'm not able to submit a pull request now: I'll try to do it as soon as possible when the project will be completed.
Bye
Thanks alot matteinn... Its very cool. Thanks.
Thanks matteinn. You're so sweet!!! I just need the methods at the moment!.
I added below lines in like and dislike methods to have like and dislike drawables:
((ImageView) getChildAt(getChildCount() - 1).findViewById(
R.id.interested_image)).setVisibility(View.VISIBLE);
((ImageView) getChildAt(getChildCount() - 1).findViewById(
R.id.not_interested_image)).setVisibility(View.VISIBLE);
I just added two imageviews(not_interested_image and interested_image) one on another overlaying on card in xml and made their Visibility "gone" by default.
@matteinn where From i call like() and dislike(). And also touch is not sensitive, If having any idea?
will you ever submit your pull request @matteinn?
@fadelakin @matteinn Yeah great work. Would love to see a pull.
Thanks Matteinn.
I was in huge trouble.
After searching a lot, i found your solution and it was best.
Thanks once again.
Hi Matteinn,
When i click the button very fast before animation end it gives array index out of bounds exception.
I tried a a lot to resolve this issue but unable to resolve.
Please help me out.