Skip to content
This repository was archived by the owner on Jul 22, 2019. It is now read-only.
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta5'
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.novoda:bintray-release:0.3.4'
}
}
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 @@
#Mon Dec 28 10:00:20 PST 2015
#Thu Dec 15 03:17:16 IST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6 changes: 3 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def final String VERSION_NAME = "0.3.0"
def final int VERSION_CODE = 30

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 25
buildToolsVersion "25.0.0"

defaultConfig {
minSdkVersion 16
Expand All @@ -25,7 +25,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:appcompat-v7:25.0.1'
}

publish {
Expand Down
30 changes: 23 additions & 7 deletions library/src/main/java/link/fls/swipestack/SwipeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@
package link.fls.swipestack;

import android.animation.Animator;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.animation.OvershootInterpolator;

import java.util.Calendar;

import link.fls.swipestack.util.AnimationUtils;

public class SwipeHelper implements View.OnTouchListener {

private final SwipeStack mSwipeStack;
private View mObservedView;

private boolean mListenForTouchEvents;
private float mDownX;
private float mDownY;
private float mInitialX;
private float mInitialY;
private int mPointerId;

private float x1;
private float y1;
private float mRotateDegrees = SwipeStack.DEFAULT_SWIPE_ROTATION;
private float mOpacityEnd = SwipeStack.DEFAULT_SWIPE_OPACITY;
private int mAnimationDuration = SwipeStack.DEFAULT_ANIMATION_DURATION;
Expand All @@ -45,19 +50,19 @@ public SwipeHelper(SwipeStack swipeStack) {

@Override
public boolean onTouch(View v, MotionEvent event) {

Log.d("EVENT",event+"");
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if(!mListenForTouchEvents || !mSwipeStack.isEnabled()) {
return false;
}

x1 = event.getX();
y1 = event.getY();
v.getParent().requestDisallowInterceptTouchEvent(true);
mSwipeStack.onSwipeStart();
mPointerId = event.getPointerId(0);
mDownX = event.getX(mPointerId);
mDownY = event.getY(mPointerId);

return true;

case MotionEvent.ACTION_MOVE:
Expand Down Expand Up @@ -92,12 +97,24 @@ public boolean onTouch(View v, MotionEvent event) {
return true;

case MotionEvent.ACTION_UP:
float x2 = event.getX();
float y2 = event.getY();
dx = x2 -x1;
dy = y2 -y1;
float MAX_CLICK_DISTANCE = 0.5f;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be better defined as a constant on the class (private static final) for better organization. I also find that a value a little above this works better.

if(dx < MAX_CLICK_DISTANCE && dy < MAX_CLICK_DISTANCE &&
dx >= 0 && dy >= 0){
long clickDuration = event.getEventTime() -event.getDownTime();
mSwipeStack.onClick();
if(clickDuration > ViewConfiguration.getLongPressTimeout()){
mSwipeStack.onLongClick(clickDuration);
}
}
v.getParent().requestDisallowInterceptTouchEvent(false);
mSwipeStack.onSwipeEnd();
checkViewPosition();

return true;

}

return false;
Expand Down Expand Up @@ -205,5 +222,4 @@ public void swipeViewToLeft() {
public void swipeViewToRight() {
swipeViewToRight(mAnimationDuration);
}

}
18 changes: 18 additions & 0 deletions library/src/main/java/link/fls/swipestack/SwipeStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ public void onViewSwipedToRight() {
removeTopView();
}

public void onClick(){
mListener.onClick();
}

public void onLongClick(long duration){
mListener.onLongClick(duration);
}

/**
* Returns the current adapter position.
*
Expand Down Expand Up @@ -438,6 +446,16 @@ public interface SwipeStackListener {
* Called when the last view has been dismissed.
*/
void onStackEmpty();

/**
* Called when there is a click action.
*/
void onClick();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to update the javadoc on the listener, adding mentions of these new methods.


/**
* Called when there is a long click action.
*/
void onLongClick(long duration);
}

/**
Expand Down