I want to make view like below image... swipe to choose in ANDROID.
i found one library on github:
https://github.com/kikoso/Swipeable-Cards
http://grishma102.blogspot.in/2014/04/tinder-app-like-control-with-animation.html
but in this lib there no option to show image LIKED or NOPE over CARD, just like showing in above image
can any one help me how to add these future in this library.
EDITED 10-10-2014
I have create view group class inside that i have made onTouchListener
i am trying to get on onClickListener inside onTouchListener
my issue is when i am touch on to left and right corner before click event some time its rotate view then click is work, so how i stop it when click is work another issue is when animation stop its also fire click event
any one help me to improve below code?
this.imageContainerLayout.setOnTouchListener(new OnTouchListener() {
private long startClickTime;
private float x1;
private float y1;
private float x2;
private float y2;
private float _dx;
private float _dy;
@Override
public boolean onTouch(View v, MotionEvent event) {
x_cord = (int) event.getRawX();
y_cord = (int) event.getRawY();
Log.e("start x_cord-->" + x_cord, "y_cord--->" + y_cord);
boolean defaultResult = v.onTouchEvent(event);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
x = (int) event.getRawX();
y = (int) event.getRawY();
this.startClickTime = Calendar.getInstance()
.getTimeInMillis();
x1 = event.getRawX();
y1 = event.getRawY();
return true;
case MotionEvent.ACTION_MOVE:
x_cord = (int) event.getRawX(); // Updated for more
// smoother animation.
y_cord = (int) event.getRawY();
Log.e("move x_cord-->" + x_cord, "y_cord--->" + y_cord);
CardView_new.this.setX(event.getRawX() - x);
CardView_new.this.setY(event.getRawY() - y);
if (x_cord >= screenCenter) {
/**
* rotate image
* */
CardView_new.this
.setRotation((float) (0.02454369260617026D * (x_cord - screenCenter)));
if (x_cord > (screenCenter + (screenCenter / 2))) {
buttonLike.setAlpha(1);
buttonDislike.setAlpha(0);
if (x_cord > (windowwidth - (screenCenter / 4))) {
Likes = 2;
moveIs = true;
} else {
Likes = 0;
moveIs = true;
}
} else {
Likes = 0;
buttonLike.setAlpha(0);
moveIs = false;
}
buttonDislike.setAlpha(0);
} else {
// rotate
/**
* rotate image
* */
CardView_new.this
.setRotation((float) (0.02454369260617026D * (x_cord - screenCenter)));
if (x_cord < (screenCenter / 2)) {
buttonDislike.setAlpha(1);
buttonLike.setAlpha(0);
if (x_cord < (screenCenter / 4)) {
Likes = 1;
moveIs = true;
} else {
Likes = 0;
moveIs = true;
}
} else {
Likes = 0;
buttonDislike.setAlpha(0);
moveIs = false;
}
buttonLike.setAlpha(0);
}
return true;
case MotionEvent.ACTION_UP:
x_cord = (int) event.getRawX();
y_cord = (int) event.getRawY();
buttonDislike.setAlpha(0);
buttonLike.setAlpha(0);
x2 = event.getRawX();
y2 = event.getRawY();
_dx = x2 - x1;
_dy = y2 - y1;
long l = Calendar.getInstance().getTimeInMillis()
- this.startClickTime;
if ((l < 400L)
&& distance(x1, y1, x2, y2) < MAX_CLICK_DISTANCE) {
Log.e("start Activity", "start activity");
CardView_new.this.setX(0);
CardView_new.this.setY(0);
CardView_new.this.setRotation(0);
if (moveIs == false) {
Intent i = new Intent((Activity) getContext(),
DetailsActivity.class);
((Activity) getContext()).startActivity(i);
}
return true;
} else if (Likes == 0) {
CardView_new.this.setX(0);
CardView_new.this.setY(0);
CardView_new.this.setRotation(0);
if (moveIs) {
moveIs = true;
return true;
} else {
moveIs = false;
return false;
}
} else if (Likes == 1) {
parentView.removeView(CardView_new.this);
CardView_new.this.mOnCardDimissedDelegate
.onLike(CardView_new.this);
Log.e("Likes==1", "Likes==1");
moveIs = true;
return true;
} else if (Likes == 2) {
parentView.removeView(CardView_new.this);
CardView_new.this.mOnCardDimissedDelegate
.onDislike(CardView_new.this);
Log.e("Likes==2", "Likes==2");
moveIs = true;
return true;
}
default:
return false;
}
}
});
Create four new global float variable x_cord, y_cord, x_cordIn & y_cordIn.
I have used this library: https://github.com/kikoso/Swipeable-Cards
You need to modify it. After modification's, you will achieve it (See Screenshots below). Let me Explain.
1.) std_card_inner.xml
This xml is used to inflate the card row in the adapter class of the library. I have modified it to add two imageviews containing the like and dislike button and a textview to show the text "like" or "dislike" when user clicks any imageview.
2.) SimpleCardStackAdapter.java
This is the adapter for the cards. I have modified it to add the click listeners for both like and dislike imageview and a textview to show the text. When user clicks like button, i have added a boolean variable in the card model which stores the like/dislike value. True for like and false for dislike.
3.) CardModel.java
Finally, here I have added that boolean variable which stores the value for like/dislike.
This is the final result:
Screenshot 1
Screenshot 2
Use RossDeckView, a lite one allowing to swipe in whatever direction you would like.
I got a result for like and unlike button to flip images to left and right.
Use this Swipe Cards like tinder swipe Sample.
MainActivity.java:
Inside the
MyAppAdapter getView()
method,add these below codes:Add these below codes outside of
MyAppAdapter class
:Thanks to @nirav kalola for this Sample.
Use a viewpager, and change the OnPageChangeListener.
http://developer.android.com/reference/android/support/v4/view/ViewPager.OnPageChangeListener.html
Just overload the onPageScrolled(int position, float positionOffset, int positionOffsetPixels) method. The int is related to the item's index on the adapter, so you can use that to identify the image.
Example:
With the help of Swipecard library, i made UI like tinder swipe card animation.
You can download example here, where i explained step by step there.