diff --git a/README.md b/README.md
index 0efb68586b..c02581cbe0 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Swipecards
Travis master: [![Build Status](https://travis-ci.org/Diolor/Swipecards.svg?branch=master)](https://travis-ci.org/Diolor/Swipecards)
-A Tinder-like cards effect as of August 2014. You can swipe left or right to like or dislike the content.
+A Tinder-like cards effect as of August 2014. You can swipe in all directions to like or dislike the content.
The library creates a similar effect to Tinder's swipable cards with Fling animation.
It was inspired by [Kikoso's Swipeable-Cards] but I decided to create a more simple and fresh approach with less bugs.
@@ -146,6 +146,7 @@ You can optionally specify some attrs for the animation and the stack. The easie
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rotation_degrees="16"
+ app:direction="HORIZONTAL"
app:max_visible="4"
app:min_adapter_stack="6" />
```
diff --git a/build.gradle b/build.gradle
index 285cc33e5a..d01709ab24 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:0.14.4'
+ classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
diff --git a/example/src/main/java/com/lorentzos/swipecards/MyActivity.java b/example/src/main/java/com/lorentzos/swipecards/MyActivity.java
index 9be01027fc..78c2a632a1 100644
--- a/example/src/main/java/com/lorentzos/swipecards/MyActivity.java
+++ b/example/src/main/java/com/lorentzos/swipecards/MyActivity.java
@@ -8,6 +8,7 @@
import android.widget.ArrayAdapter;
import android.widget.Toast;
+import com.lorentzos.flingswipe.Direction;
import com.lorentzos.flingswipe.SwipeFlingAdapterView;
import java.util.ArrayList;
@@ -57,16 +58,22 @@ public void removeFirstObjectInAdapter() {
}
@Override
- public void onLeftCardExit(Object dataObject) {
- //Do something on the left!
+ public void onCardExit(int direction, Object dataObject) {
+
//You also have access to the original object.
//If you want to use it just cast it (String) dataObject
- makeToast(MyActivity.this, "Left!");
- }
- @Override
- public void onRightCardExit(Object dataObject) {
- makeToast(MyActivity.this, "Right!");
+ if (Direction.hasLeft(direction)){
+ makeToast(MyActivity.this, "Left!");
+ } else if (Direction.hasRight(direction)){
+ makeToast(MyActivity.this, "Right!");
+ } else if (Direction.hasTop(direction)){
+ makeToast(MyActivity.this, "Top!");
+ } else if (Direction.hasBottom(direction)){
+ makeToast(MyActivity.this, "Bottom!");
+ } else {
+ makeToast(MyActivity.this, "No known direction!");
+ }
}
@Override
@@ -79,10 +86,12 @@ public void onAdapterAboutToEmpty(int itemsInAdapter) {
}
@Override
- public void onScroll(float scrollProgressPercent) {
+ public void onScroll(float scrollProgressPercentHorizontal, float scrollProgressPercentVertical) {
View view = flingContainer.getSelectedView();
- view.findViewById(R.id.item_swipe_right_indicator).setAlpha(scrollProgressPercent < 0 ? -scrollProgressPercent : 0);
- view.findViewById(R.id.item_swipe_left_indicator).setAlpha(scrollProgressPercent > 0 ? scrollProgressPercent : 0);
+ view.findViewById(R.id.item_swipe_right_indicator).setAlpha(scrollProgressPercentHorizontal < 0 ? -scrollProgressPercentHorizontal : 0);
+ view.findViewById(R.id.item_swipe_left_indicator).setAlpha(scrollProgressPercentHorizontal > 0 ? scrollProgressPercentHorizontal : 0);
+ view.findViewById(R.id.item_swipe_bottom_indicator).setAlpha(scrollProgressPercentVertical < 0 ? -scrollProgressPercentVertical : 0);
+ view.findViewById(R.id.item_swipe_top_indicator).setAlpha(scrollProgressPercentVertical > 0 ? scrollProgressPercentVertical : 0);
}
});
@@ -115,6 +124,15 @@ public void left() {
flingContainer.getTopCardListener().selectLeft();
}
+ @OnClick(R.id.top)
+ public void top() {
+ flingContainer.getTopCardListener().selectTop();
+ }
+
+ @OnClick(R.id.bottom)
+ public void bottom() {
+ flingContainer.getTopCardListener().selectBottom();
+ }
diff --git a/example/src/main/res/layout/activity_my.xml b/example/src/main/res/layout/activity_my.xml
index 6456767964..5f1122089f 100644
--- a/example/src/main/res/layout/activity_my.xml
+++ b/example/src/main/res/layout/activity_my.xml
@@ -9,6 +9,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rotation_degrees="15.5"
+ app:direction="HORIZONTAL"
tools:context=".MyActivity" />
diff --git a/example/src/main/res/layout/buttons.xml b/example/src/main/res/layout/buttons.xml
index 993e0f840d..334cc49af4 100644
--- a/example/src/main/res/layout/buttons.xml
+++ b/example/src/main/res/layout/buttons.xml
@@ -14,6 +14,13 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
+
+
+
+
\ No newline at end of file
diff --git a/example/src/main/res/layout/item.xml b/example/src/main/res/layout/item.xml
index 9fa2b047d7..ebef326c3b 100644
--- a/example/src/main/res/layout/item.xml
+++ b/example/src/main/res/layout/item.xml
@@ -21,6 +21,7 @@
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_margin="10dp"
+ android:layout_gravity="left|center_vertical"
android:background="#A5F" />
+
+
+
+
+
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
index 98eda57851..5ab40c59ba 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,5 +1,5 @@
-VERSION_NAME=1.0.8
-VERSION_CODE=1
+VERSION_NAME=1.1
+VERSION_CODE=2
BUILD_TOOLS_VERSION=21.1.1
MIN_SDK_VERSION=14
TARGET_SDK_VERSION=21
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 1bd781a665..b68b036b2b 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Tue Sep 30 09:51:54 EEST 2014
+#Tue May 19 17:32:01 CEST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
diff --git a/library/src/main/java/com/lorentzos/flingswipe/BaseFlingAdapterView.java b/library/src/main/java/com/lorentzos/flingswipe/BaseFlingAdapterView.java
index 489d38b341..383252ac14 100644
--- a/library/src/main/java/com/lorentzos/flingswipe/BaseFlingAdapterView.java
+++ b/library/src/main/java/com/lorentzos/flingswipe/BaseFlingAdapterView.java
@@ -2,7 +2,6 @@
import android.content.Context;
import android.util.AttributeSet;
-import android.view.View;
import android.widget.AdapterView;
/**
diff --git a/library/src/main/java/com/lorentzos/flingswipe/Direction.java b/library/src/main/java/com/lorentzos/flingswipe/Direction.java
new file mode 100644
index 0000000000..d61a41b509
--- /dev/null
+++ b/library/src/main/java/com/lorentzos/flingswipe/Direction.java
@@ -0,0 +1,35 @@
+package com.lorentzos.flingswipe;
+
+/**
+ * Created by mklepp on 19/05/15.
+ */
+public class Direction {
+ // must be aligned with direction enum in /res/values/attrs.xml
+ public static final int LEFT = 1;
+ public static final int TOP = 2;
+ public static final int RIGHT = 4;
+ public static final int BOTTOM = 8;
+
+ public static final int HORIZONTAL = LEFT | RIGHT;
+ public static final int VERTICAL = BOTTOM | TOP;
+
+ public static boolean hasLeft(int direction){
+ return hasDirection(direction, LEFT);
+ }
+
+ public static boolean hasRight(int direction){
+ return hasDirection(direction, RIGHT);
+ }
+
+ public static boolean hasTop(int direction){
+ return hasDirection(direction, TOP);
+ }
+
+ public static boolean hasBottom(int direction){
+ return hasDirection(direction, BOTTOM);
+ }
+
+ public static boolean hasDirection(int direction, int directionToCheck){
+ return ((direction & directionToCheck) == directionToCheck);
+ }
+}
diff --git a/library/src/main/java/com/lorentzos/flingswipe/FlingCardListener.java b/library/src/main/java/com/lorentzos/flingswipe/FlingCardListener.java
index 4b241014dd..18905916b8 100644
--- a/library/src/main/java/com/lorentzos/flingswipe/FlingCardListener.java
+++ b/library/src/main/java/com/lorentzos/flingswipe/FlingCardListener.java
@@ -23,10 +23,13 @@ public class FlingCardListener implements View.OnTouchListener {
private final int objectH;
private final int objectW;
private final int parentWidth;
+ private final int parentHeight;
private final FlingListener mFlingListener;
private final Object dataObject;
private final float halfWidth;
+ private final float halfHeight;
private float BASE_ROTATION_DEGREES;
+ private int DIRECTION;
private float aPosX;
private float aPosY;
@@ -48,10 +51,10 @@ public class FlingCardListener implements View.OnTouchListener {
public FlingCardListener(View frame, Object itemAtPosition, FlingListener flingListener) {
- this(frame,itemAtPosition, 15f, flingListener);
+ this(frame,itemAtPosition, 15f, Direction.HORIZONTAL, flingListener);
}
- public FlingCardListener(View frame, Object itemAtPosition, float rotation_degrees, FlingListener flingListener) {
+ public FlingCardListener(View frame, Object itemAtPosition, float rotation_degrees, int DIRECTION, FlingListener flingListener) {
super();
this.frame = frame;
this.objectX = frame.getX();
@@ -59,11 +62,13 @@ public FlingCardListener(View frame, Object itemAtPosition, float rotation_degre
this.objectH = frame.getHeight();
this.objectW = frame.getWidth();
this.halfWidth = objectW/2f;
+ this.halfHeight = objectH/2f;
this.dataObject = itemAtPosition;
this.parentWidth = ((ViewGroup) frame.getParent()).getWidth();
+ this.parentHeight = ((ViewGroup) frame.getParent()).getHeight();
this.BASE_ROTATION_DEGREES = rotation_degrees;
+ this.DIRECTION = DIRECTION;
this.mFlingListener = flingListener;
-
}
@@ -146,7 +151,7 @@ public boolean onTouch(View view, MotionEvent event) {
frame.setX(aPosX);
frame.setY(aPosY);
frame.setRotation(rotation);
- mFlingListener.onScroll(getScrollProgressPercent());
+ mFlingListener.onScroll(getScrollProgressPercentVertical(), getScrollProgressPercentHorizontal());
break;
case MotionEvent.ACTION_CANCEL: {
@@ -158,7 +163,7 @@ public boolean onTouch(View view, MotionEvent event) {
return true;
}
- private float getScrollProgressPercent() {
+ private float getScrollProgressPercentVertical() {
if (movedBeyondLeftBorder()) {
return -1f;
} else if (movedBeyondRightBorder()) {
@@ -169,16 +174,35 @@ private float getScrollProgressPercent() {
}
}
+ private float getScrollProgressPercentHorizontal() {
+ if (movedBeyondTopBorder()) {
+ return -1f;
+ } else if (movedBeyondBottomBorder()) {
+ return 1f;
+ } else {
+ float zeroToOneValue = (aPosY + halfHeight - topBorder()) / (bottomBorder() - topBorder());
+ return zeroToOneValue * 2f - 1f;
+ }
+ }
+
private boolean resetCardViewOnStack() {
- if(movedBeyondLeftBorder()){
+ float scrollHorizontal = getScrollProgressPercentHorizontal();
+ float scrollVertical = getScrollProgressPercentVertical();
+ if(movedBeyondLeftBorder() && Direction.hasLeft(DIRECTION)){
// Left Swipe
- onSelected(true, getExitPoint(-objectW), 100 );
- mFlingListener.onScroll(-1.0f);
- }else if(movedBeyondRightBorder()) {
+ onSelected(Direction.LEFT, getExitXPoint(-objectW), 100);
+ }else if(movedBeyondRightBorder() && Direction.hasRight(DIRECTION)) {
// Right Swipe
- onSelected(false, getExitPoint(parentWidth), 100 );
- mFlingListener.onScroll(1.0f);
+ onSelected(Direction.RIGHT, getExitXPoint(parentWidth), 100);
+ }else if(movedBeyondTopBorder() && Direction.hasTop(DIRECTION)) {
+ // Top Swipe
+ onSelected(Direction.TOP, getExitYPoint(-objectH), 100);
+ }else if(movedBeyondBottomBorder() && Direction.hasBottom(DIRECTION)) {
+ // Bottom Swipe
+ onSelected(Direction.BOTTOM, getExitYPoint(parentHeight), 100);
}else {
+ scrollHorizontal = 0;
+ scrollVertical = 0;
float abslMoveDistance = Math.abs(aPosX-objectX);
aPosX = 0;
aPosY = 0;
@@ -190,11 +214,11 @@ private boolean resetCardViewOnStack() {
.x(objectX)
.y(objectY)
.rotation(0);
- mFlingListener.onScroll(0.0f);
if(abslMoveDistance<4.0){
mFlingListener.onClick(dataObject);
}
}
+ mFlingListener.onScroll(scrollHorizontal, scrollVertical);
return false;
}
@@ -206,6 +230,14 @@ private boolean movedBeyondRightBorder() {
return aPosX+halfWidth > rightBorder();
}
+ private boolean movedBeyondTopBorder() {
+ return aPosY+halfHeight < topBorder();
+ }
+
+ private boolean movedBeyondBottomBorder() {
+ return aPosY+halfHeight > bottomBorder();
+ }
+
public float leftBorder(){
return parentWidth/4.f;
@@ -215,18 +247,31 @@ public float rightBorder(){
return 3*parentWidth/4.f;
}
+ public float topBorder(){
+ return parentHeight/4.f;
+ }
+
+ public float bottomBorder(){
+ return 3*parentHeight/4.f;
+ }
- public void onSelected(final boolean isLeft,
- float exitY, long duration){
+ public void onSelected(final int direction,
+ float exitOther, long duration){
isAnimationRunning = true;
- float exitX;
- if(isLeft) {
+ float exitX = exitOther;
+ if(Direction.hasLeft(direction)) {
exitX = -objectW-getRotationWidthOffset();
- }else {
+ }else if(Direction.hasRight(direction)) {
exitX = parentWidth+getRotationWidthOffset();
}
+ float exitY = exitOther;
+ if(Direction.hasTop(direction)) {
+ exitY = -objectH-getRotationHeightOffset();
+ }else if(Direction.hasBottom(direction)) {
+ exitY = parentHeight+getRotationHeightOffset();
+ }
this.frame.animate()
.setDuration(duration)
.setInterpolator(new AccelerateInterpolator())
@@ -235,17 +280,13 @@ public void onSelected(final boolean isLeft,
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
- if (isLeft) {
- mFlingListener.onCardExited();
- mFlingListener.leftExit(dataObject);
- } else {
- mFlingListener.onCardExited();
- mFlingListener.rightExit(dataObject);
- }
+ mFlingListener.exit(direction, dataObject);
+
+ mFlingListener.onCardExited();
isAnimationRunning = false;
}
})
- .rotation(getExitRotation(isLeft));
+ .rotation(getExitRotation(direction));
}
@@ -256,7 +297,7 @@ public void onAnimationEnd(Animator animation) {
*/
public void selectLeft(){
if(!isAnimationRunning)
- onSelected(true, objectY, 200);
+ onSelected(Direction.LEFT, objectY, 200);
}
/**
@@ -264,11 +305,27 @@ public void selectLeft(){
*/
public void selectRight(){
if(!isAnimationRunning)
- onSelected(false, objectY, 200);
+ onSelected(Direction.RIGHT, objectY, 200);
+ }
+
+ /**
+ * Starts a default top exit animation.
+ */
+ public void selectTop(){
+ if(!isAnimationRunning)
+ onSelected(Direction.TOP, objectX, 200);
+ }
+
+ /**
+ * Starts a default bottom exit animation.
+ */
+ public void selectBottom(){
+ if(!isAnimationRunning)
+ onSelected(Direction.BOTTOM, objectX, 200);
}
- private float getExitPoint(int exitXPoint) {
+ private float getExitXPoint(int exitXPoint) {
float[] x = new float[2];
x[0] = objectX;
x[1] = aPosX;
@@ -283,12 +340,28 @@ private float getExitPoint(int exitXPoint) {
return (float) regression.slope() * exitXPoint + (float) regression.intercept();
}
- private float getExitRotation(boolean isLeft){
+ private float getExitYPoint(int exitYPoint) {
+ float[] x = new float[2];
+ x[0] = objectX;
+ x[1] = aPosX;
+
+ float[] y = new float[2];
+ y[0] = objectY;
+ y[1] = aPosY;
+
+ LinearRegression regression =new LinearRegression(x,y);
+
+ //Your typical y = ax+b linear regression
+ // x = (y-b)/a
+ return (float) ((exitYPoint - (float) regression.intercept())/regression.slope());
+ }
+
+ private float getExitRotation(int direction){
float rotation= BASE_ROTATION_DEGREES * 2.f * (parentWidth - objectX)/parentWidth;
if (touchPosition == TOUCH_BELOW) {
rotation = -rotation;
}
- if(isLeft){
+ if(Direction.hasTop(direction) || Direction.hasLeft(direction)){
rotation = -rotation;
}
return rotation;
@@ -306,6 +379,10 @@ private float getRotationWidthOffset() {
return objectW/MAX_COS - objectW;
}
+ private float getRotationHeightOffset() {
+ return objectH/MAX_COS - objectH;
+ }
+
public void setRotationDegrees(float degrees) {
this.BASE_ROTATION_DEGREES = degrees;
@@ -314,10 +391,9 @@ public void setRotationDegrees(float degrees) {
protected interface FlingListener {
public void onCardExited();
- public void leftExit(Object dataObject);
- public void rightExit(Object dataObject);
+ public void exit(int direction, Object dataObject);
public void onClick(Object dataObject);
- public void onScroll(float scrollProgressPercent);
+ public void onScroll(float scrollProgressPercentHorizontal, float scrollProgressPercentVertical);
}
}
diff --git a/library/src/main/java/com/lorentzos/flingswipe/SwipeFlingAdapterView.java b/library/src/main/java/com/lorentzos/flingswipe/SwipeFlingAdapterView.java
index ad499fa1b9..d64db18de9 100644
--- a/library/src/main/java/com/lorentzos/flingswipe/SwipeFlingAdapterView.java
+++ b/library/src/main/java/com/lorentzos/flingswipe/SwipeFlingAdapterView.java
@@ -20,7 +20,7 @@
public class SwipeFlingAdapterView extends BaseFlingAdapterView {
-
+ public int DIRECTION = Direction.HORIZONTAL;
private int MAX_VISIBLE = 4;
private int MIN_ADAPTER_STACK = 6;
private float ROTATION_DEGREES = 15.f;
@@ -34,7 +34,6 @@ public class SwipeFlingAdapterView extends BaseFlingAdapterView {
private OnItemClickListener mOnItemClickListener;
private FlingCardListener flingCardListener;
-
public SwipeFlingAdapterView(Context context) {
this(context, null);
}
@@ -50,6 +49,7 @@ public SwipeFlingAdapterView(Context context, AttributeSet attrs, int defStyle)
MAX_VISIBLE = a.getInt(R.styleable.SwipeFlingAdapterView_max_visible, MAX_VISIBLE);
MIN_ADAPTER_STACK = a.getInt(R.styleable.SwipeFlingAdapterView_min_adapter_stack, MIN_ADAPTER_STACK);
ROTATION_DEGREES = a.getFloat(R.styleable.SwipeFlingAdapterView_rotation_degrees, ROTATION_DEGREES);
+ DIRECTION = a.getInt(R.styleable.SwipeFlingAdapterView_direction, DIRECTION);
a.recycle();
}
@@ -57,22 +57,22 @@ public SwipeFlingAdapterView(Context context, AttributeSet attrs, int defStyle)
/**
* A shortcut method to set both the listeners and the adapter.
*
- * @param context The activity context which extends onFlingListener, OnItemClickListener or both
+ * @param context The activity context which extends onFlingListener, OnItemClickListener or both
* @param mAdapter The adapter you have to set.
*/
public void init(final Context context, Adapter mAdapter) {
- if(context instanceof onFlingListener) {
+ if (context instanceof onFlingListener) {
mFlingListener = (onFlingListener) context;
- }else{
+ } else {
throw new RuntimeException("Activity does not implement SwipeFlingAdapterView.onFlingListener");
}
- if(context instanceof OnItemClickListener){
+ if (context instanceof OnItemClickListener) {
mOnItemClickListener = (OnItemClickListener) context;
}
setAdapter(mAdapter);
}
- @Override
+ @Override
public View getSelectedView() {
return mActiveCard;
}
@@ -96,14 +96,14 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
mInLayout = true;
final int adapterCount = mAdapter.getCount();
- if(adapterCount == 0) {
+ if (adapterCount == 0) {
removeAllViewsInLayout();
- }else {
+ } else {
View topCard = getChildAt(LAST_OBJECT_IN_STACK);
- if(mActiveCard!=null && topCard!=null && topCard==mActiveCard) {
+ if (mActiveCard != null && topCard != null && topCard == mActiveCard) {
removeViewsInLayout(0, LAST_OBJECT_IN_STACK);
layoutChildren(1, adapterCount);
- }else{
+ } else {
// Reset the UI and set top view listener
removeAllViewsInLayout();
layoutChildren(0, adapterCount);
@@ -112,13 +112,13 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
}
mInLayout = false;
-
- if(adapterCount < MAX_VISIBLE) mFlingListener.onAdapterAboutToEmpty(adapterCount);
+
+ if (adapterCount < MAX_VISIBLE) mFlingListener.onAdapterAboutToEmpty(adapterCount);
}
- private void layoutChildren(int startingIndex, int adapterCount){
- while (startingIndex < Math.min(adapterCount, MAX_VISIBLE) ) {
+ private void layoutChildren(int startingIndex, int adapterCount) {
+ while (startingIndex < Math.min(adapterCount, MAX_VISIBLE)) {
View newUnderChild = mAdapter.getView(startingIndex, null, this);
if (newUnderChild.getVisibility() != GONE) {
makeAndAddView(newUnderChild);
@@ -166,7 +166,7 @@ private void makeAndAddView(View child) {
int childTop;
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
- childLeft = (getWidth() + getPaddingLeft() - getPaddingRight() - w) / 2 +
+ childLeft = (getWidth() + getPaddingLeft() - getPaddingRight() - w) / 2 +
lp.leftMargin - lp.rightMargin;
break;
case Gravity.END:
@@ -179,7 +179,7 @@ private void makeAndAddView(View child) {
}
switch (verticalGravity) {
case Gravity.CENTER_VERTICAL:
- childTop = (getHeight() + getPaddingTop() - getPaddingBottom() - h) / 2 +
+ childTop = (getHeight() + getPaddingTop() - getPaddingBottom() - h) / 2 +
lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
@@ -195,66 +195,63 @@ private void makeAndAddView(View child) {
}
-
-
/**
- * Set the top view and add the fling listener
- */
+ * Set the top view and add the fling listener
+ */
private void setTopView() {
- if(getChildCount()>0){
+ if (getChildCount() > 0) {
mActiveCard = getChildAt(LAST_OBJECT_IN_STACK);
- if(mActiveCard!=null) {
+ if (mActiveCard != null) {
flingCardListener = new FlingCardListener(mActiveCard, mAdapter.getItem(0),
- ROTATION_DEGREES, new FlingCardListener.FlingListener() {
+ ROTATION_DEGREES, DIRECTION, new FlingCardListener.FlingListener() {
- @Override
- public void onCardExited() {
- mActiveCard = null;
- mFlingListener.removeFirstObjectInAdapter();
- }
+ @Override
+ public void onCardExited() {
+ mActiveCard = null;
+ mFlingListener.removeFirstObjectInAdapter();
+ }
- @Override
- public void leftExit(Object dataObject) {
- mFlingListener.onLeftCardExit(dataObject);
- }
+ @Override
+ public void exit(int direction, Object dataObject) {
+ mFlingListener.onCardExit(direction, dataObject);
+ }
- @Override
- public void rightExit(Object dataObject) {
- mFlingListener.onRightCardExit(dataObject);
- }
+ @Override
+ public void onClick(Object dataObject) {
+ if (mOnItemClickListener != null)
+ mOnItemClickListener.onItemClicked(0, dataObject);
- @Override
- public void onClick(Object dataObject) {
- if(mOnItemClickListener!=null)
- mOnItemClickListener.onItemClicked(0, dataObject);
+ }
- }
-
- @Override
- public void onScroll(float scrollProgressPercent) {
- mFlingListener.onScroll(scrollProgressPercent);
- }
- });
+ @Override
+ public void onScroll(float scrollProgressPercentHorizontal, float scrollProgressPercentVertical) {
+ mFlingListener.onScroll(scrollProgressPercentHorizontal, scrollProgressPercentVertical);
+ }
+ });
mActiveCard.setOnTouchListener(flingCardListener);
}
}
}
- public FlingCardListener getTopCardListener() throws NullPointerException{
- if(flingCardListener==null){
+ public FlingCardListener getTopCardListener() throws NullPointerException {
+ if (flingCardListener == null) {
throw new NullPointerException();
}
return flingCardListener;
}
- public void setMaxVisible(int MAX_VISIBLE){
+ public void setDirection(int DIRECTION) {
+ this.DIRECTION = DIRECTION;
+ }
+
+ public void setMaxVisible(int MAX_VISIBLE) {
this.MAX_VISIBLE = MAX_VISIBLE;
}
- public void setMinStackInAdapter(int MIN_ADAPTER_STACK){
+ public void setMinStackInAdapter(int MIN_ADAPTER_STACK) {
this.MIN_ADAPTER_STACK = MIN_ADAPTER_STACK;
}
@@ -273,7 +270,7 @@ public void setAdapter(Adapter adapter) {
mAdapter = adapter;
- if (mAdapter != null && mDataSetObserver == null) {
+ if (mAdapter != null && mDataSetObserver == null) {
mDataSetObserver = new AdapterDataSetObserver();
mAdapter.registerDataSetObserver(mDataSetObserver);
}
@@ -283,13 +280,11 @@ public void setFlingListener(onFlingListener onFlingListener) {
this.mFlingListener = onFlingListener;
}
- public void setOnItemClickListener(OnItemClickListener onItemClickListener){
+ public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
this.mOnItemClickListener = onItemClickListener;
}
-
-
@Override
public LayoutParams generateLayoutParams(AttributeSet attrs) {
return new FrameLayout.LayoutParams(getContext(), attrs);
@@ -316,10 +311,12 @@ public interface OnItemClickListener {
public interface onFlingListener {
public void removeFirstObjectInAdapter();
- public void onLeftCardExit(Object dataObject);
- public void onRightCardExit(Object dataObject);
+
+ public void onCardExit(int direction, Object dataObject);
+
public void onAdapterAboutToEmpty(int itemsInAdapter);
- public void onScroll(float scrollProgressPercent);
+
+ public void onScroll(float scrollProgressPercentHorizontal, float scrollProgressPercentVertical);
}
diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml
index 5bfd83361e..d1187b810f 100644
--- a/library/src/main/res/values/attrs.xml
+++ b/library/src/main/res/values/attrs.xml
@@ -2,10 +2,19 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file