From 26bf9e163d8661b836409411cbc4aa7ffdff3ed1 Mon Sep 17 00:00:00 2001 From: poovamraj Date: Thu, 15 Dec 2016 03:44:07 +0530 Subject: [PATCH] added onclick and onlongclick to swipestacklistener --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +-- library/build.gradle | 6 ++-- .../java/link/fls/swipestack/SwipeHelper.java | 30 ++++++++++++++----- .../java/link/fls/swipestack/SwipeStack.java | 18 +++++++++++ 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 23b974a..b1ed112 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 122a0dc..1f53425 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/library/build.gradle b/library/build.gradle index 234b010..520e805 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -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 @@ -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 { diff --git a/library/src/main/java/link/fls/swipestack/SwipeHelper.java b/library/src/main/java/link/fls/swipestack/SwipeHelper.java index 43b7b72..30473ae 100644 --- a/library/src/main/java/link/fls/swipestack/SwipeHelper.java +++ b/library/src/main/java/link/fls/swipestack/SwipeHelper.java @@ -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; @@ -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: @@ -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; + 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; @@ -205,5 +222,4 @@ public void swipeViewToLeft() { public void swipeViewToRight() { swipeViewToRight(mAnimationDuration); } - } diff --git a/library/src/main/java/link/fls/swipestack/SwipeStack.java b/library/src/main/java/link/fls/swipestack/SwipeStack.java index 175e28d..f0d3364 100644 --- a/library/src/main/java/link/fls/swipestack/SwipeStack.java +++ b/library/src/main/java/link/fls/swipestack/SwipeStack.java @@ -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. * @@ -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(); + + /** + * Called when there is a long click action. + */ + void onLongClick(long duration); } /**