Skip to content

Commit 8de75ad

Browse files
author
Denis Miller
committed
Merged pull request flschweiger#33 from flschweiger#33
2 parents 95a446b + 26bf9e1 commit 8de75ad

File tree

5 files changed

+47
-13
lines changed

5 files changed

+47
-13
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.1.0'
8+
classpath 'com.android.tools.build:gradle:2.2.0'
99
classpath 'com.novoda:bintray-release:0.3.4'
1010
}
1111
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Dec 28 10:00:20 PST 2015
1+
#Thu Dec 15 03:17:16 IST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

library/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ def final String VERSION_NAME = "0.3.0"
55
def final int VERSION_CODE = 30
66

77
android {
8-
compileSdkVersion 23
9-
buildToolsVersion "23.0.2"
8+
compileSdkVersion 25
9+
buildToolsVersion "25.0.0"
1010

1111
defaultConfig {
1212
minSdkVersion 16
@@ -25,7 +25,7 @@ android {
2525
dependencies {
2626
compile fileTree(dir: 'libs', include: ['*.jar'])
2727
testCompile 'junit:junit:4.12'
28-
compile 'com.android.support:appcompat-v7:23.1.1'
28+
compile 'com.android.support:appcompat-v7:25.0.1'
2929
}
3030

3131
publish {

library/src/main/java/link/fls/swipestack/SwipeHelper.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,29 @@
1717
package link.fls.swipestack;
1818

1919
import android.animation.Animator;
20+
import android.support.annotation.Nullable;
21+
import android.util.Log;
2022
import android.view.MotionEvent;
2123
import android.view.View;
24+
import android.view.ViewConfiguration;
2225
import android.view.animation.OvershootInterpolator;
2326

27+
import java.util.Calendar;
28+
2429
import link.fls.swipestack.util.AnimationUtils;
2530

2631
public class SwipeHelper implements View.OnTouchListener {
2732

2833
private final SwipeStack mSwipeStack;
2934
private View mObservedView;
30-
3135
private boolean mListenForTouchEvents;
3236
private float mDownX;
3337
private float mDownY;
3438
private float mInitialX;
3539
private float mInitialY;
3640
private int mPointerId;
37-
41+
private float x1;
42+
private float y1;
3843
private float mRotateDegrees = SwipeStack.DEFAULT_SWIPE_ROTATION;
3944
private float mOpacityEnd = SwipeStack.DEFAULT_SWIPE_OPACITY;
4045
private int mAnimationDuration = SwipeStack.DEFAULT_ANIMATION_DURATION;
@@ -45,19 +50,19 @@ public SwipeHelper(SwipeStack swipeStack) {
4550

4651
@Override
4752
public boolean onTouch(View v, MotionEvent event) {
48-
53+
Log.d("EVENT",event+"");
4954
switch (event.getAction()) {
5055
case MotionEvent.ACTION_DOWN:
5156
if(!mListenForTouchEvents || !mSwipeStack.isEnabled()) {
5257
return false;
5358
}
54-
59+
x1 = event.getX();
60+
y1 = event.getY();
5561
v.getParent().requestDisallowInterceptTouchEvent(true);
5662
mSwipeStack.onSwipeStart();
5763
mPointerId = event.getPointerId(0);
5864
mDownX = event.getX(mPointerId);
5965
mDownY = event.getY(mPointerId);
60-
6166
return true;
6267

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

9499
case MotionEvent.ACTION_UP:
100+
float x2 = event.getX();
101+
float y2 = event.getY();
102+
dx = x2 -x1;
103+
dy = y2 -y1;
104+
float MAX_CLICK_DISTANCE = 0.5f;
105+
if(dx < MAX_CLICK_DISTANCE && dy < MAX_CLICK_DISTANCE &&
106+
dx >= 0 && dy >= 0){
107+
long clickDuration = event.getEventTime() -event.getDownTime();
108+
mSwipeStack.onClick();
109+
if(clickDuration > ViewConfiguration.getLongPressTimeout()){
110+
mSwipeStack.onLongClick(clickDuration);
111+
}
112+
}
95113
v.getParent().requestDisallowInterceptTouchEvent(false);
96114
mSwipeStack.onSwipeEnd();
97115
checkViewPosition();
98116

99117
return true;
100-
101118
}
102119

103120
return false;
@@ -205,5 +222,4 @@ public void swipeViewToLeft() {
205222
public void swipeViewToRight() {
206223
swipeViewToRight(mAnimationDuration);
207224
}
208-
209225
}

library/src/main/java/link/fls/swipestack/SwipeStack.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ public void onViewSwipedToRight() {
321321
if (mListener != null) mListener.onViewSwipedToRight(swipedPosition);
322322
}
323323

324+
public void onClick(){
325+
mListener.onClick();
326+
}
327+
328+
public void onLongClick(long duration){
329+
mListener.onLongClick(duration);
330+
}
331+
324332
/**
325333
* Returns the current adapter position.
326334
*
@@ -449,6 +457,16 @@ public interface SwipeStackListener {
449457
* Called when the last view has been dismissed.
450458
*/
451459
void onStackEmpty();
460+
461+
/**
462+
* Called when there is a click action.
463+
*/
464+
void onClick();
465+
466+
/**
467+
* Called when there is a long click action.
468+
*/
469+
void onLongClick(long duration);
452470
}
453471

454472
/**

0 commit comments

Comments
 (0)