Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to select swipeable directions #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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" />
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 28 additions & 10 deletions example/src/main/java/com/lorentzos/swipecards/MyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
});

Expand Down Expand Up @@ -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();
}



Expand Down
1 change: 1 addition & 0 deletions example/src/main/res/layout/activity_my.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<include layout="@layout/buttons" />
Expand Down
14 changes: 14 additions & 0 deletions example/src/main/res/layout/buttons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,25 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/top"
android:layout_margin="10dp"
android:text="Top"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/right"
android:layout_margin="10dp"
android:text="Right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/bottom"
android:layout_margin="10dp"
android:text="Bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>
22 changes: 21 additions & 1 deletion example/src/main/res/layout/item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<View
Expand All @@ -29,7 +30,26 @@
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_margin="10dp"
android:layout_gravity="right"
android:layout_gravity="right|center_vertical"
android:background="#5AF" />


<View
android:id="@+id/item_swipe_top_indicator"
android:alpha="0"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_margin="10dp"
android:layout_gravity="top|center_horizontal"
android:background="#ffc3ff93" />

<View
android:id="@+id/item_swipe_bottom_indicator"
android:alpha="0"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_margin="10dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#ffffa56e" />

</FrameLayout>
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;

/**
Expand Down
35 changes: 35 additions & 0 deletions library/src/main/java/com/lorentzos/flingswipe/Direction.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading