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" /> +