From 36a814eb97f5807cc6e36e338d2386a843ddf825 Mon Sep 17 00:00:00 2001 From: Anton Malinskiy Date: Tue, 22 Jul 2014 12:45:01 +0400 Subject: [PATCH 1/2] Fix swipedismiss animator on newer APIs when AnimatorProxy is not need --- .../SwipeDismissListViewTouchListener.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/SuperListviewLibrary/src/main/java/com/quentindommerc/superlistview/SwipeDismissListViewTouchListener.java b/SuperListviewLibrary/src/main/java/com/quentindommerc/superlistview/SwipeDismissListViewTouchListener.java index ff60dcf..6f71f46 100644 --- a/SuperListviewLibrary/src/main/java/com/quentindommerc/superlistview/SwipeDismissListViewTouchListener.java +++ b/SuperListviewLibrary/src/main/java/com/quentindommerc/superlistview/SwipeDismissListViewTouchListener.java @@ -38,16 +38,16 @@ * dismissable. {@link ListView} is given special treatment because by default it handles touches * for its list items... i.e. it's in charge of drawing the pressed state (the list selector), * handling list item clicks, etc. - * + *

*

After creating the listener, the caller should also call * {@link ListView#setOnScrollListener(AbsListView.OnScrollListener)}, passing * in the scroll listener returned by {@link #makeScrollListener()}. If a scroll listener is * already assigned, the caller should still pass scroll changes through to this listener. This will * ensure that this {@link SwipeDismissListViewTouchListener} is paused during list view * scrolling.

- * + *

*

Example usage:

- * + *

*

  * SwipeDismissListViewTouchListener touchListener =
  *         new SwipeDismissListViewTouchListener(
@@ -63,10 +63,10 @@
  * listView.setOnTouchListener(touchListener);
  * listView.setOnScrollListener(touchListener.makeScrollListener());
  * 
- * + *

*

This class Requires API level 12 or later due to use of {@link * ViewPropertyAnimator}.

- * + *

*

For a generalized {@link View.OnTouchListener} that makes any view dismissable, * see {@link SwipeDismissTouchListener}.

* @@ -94,7 +94,6 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener { private VelocityTracker mVelocityTracker; private int mDownPosition; private View mDownView; - private AnimatorProxy mDownViewProxy; private boolean mPaused; /** @@ -194,7 +193,6 @@ public boolean onTouch(View view, MotionEvent motionEvent) { child.getHitRect(rect); if (rect.contains(x, y)) { mDownView = child; - mDownViewProxy = AnimatorProxy.wrap(child); break; } } @@ -208,7 +206,6 @@ public boolean onTouch(View view, MotionEvent motionEvent) { mVelocityTracker.addMovement(motionEvent); } else { mDownView = null; - mDownViewProxy= null; } } return false; @@ -232,7 +229,6 @@ public boolean onTouch(View view, MotionEvent motionEvent) { mDownX = 0; mDownY = 0; mDownView = null; - mDownViewProxy= null; mDownPosition = ListView.INVALID_POSITION; mSwiping = false; break; @@ -287,7 +283,6 @@ public void onAnimationEnd(Animator animation) { mDownX = 0; mDownY = 0; mDownView = null; - mDownViewProxy= null; mDownPosition = ListView.INVALID_POSITION; mSwiping = false; break; @@ -316,9 +311,17 @@ public void onAnimationEnd(Animator animation) { } if (mSwiping) { - mDownViewProxy.setTranslationX(deltaX - mSwipingSlop); - mDownViewProxy.setAlpha(Math.max(0f, Math.min(1f, + if(AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy proxy = AnimatorProxy.wrap(mDownView); + proxy.setTranslationX(deltaX - mSwipingSlop); + proxy.setAlpha(Math.max(0f, Math.min(1f, + 1f - 2f * Math.abs(deltaX) / mViewWidth))); + } else { + mDownView.setTranslationX(deltaX - mSwipingSlop); + mDownView.setAlpha(Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth))); + } + return true; } break; @@ -375,8 +378,14 @@ public void onAnimationEnd(Animator animation) { ViewGroup.LayoutParams lp; for (PendingDismissData pendingDismiss : mPendingDismisses) { // Reset view presentation - AnimatorProxy.wrap(pendingDismiss.view).setAlpha(1f); - AnimatorProxy.wrap(pendingDismiss.view).setTranslationX(0); + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(pendingDismiss.view).setAlpha(1f); + AnimatorProxy.wrap(pendingDismiss.view).setTranslationX(0); + } else { + pendingDismiss.view.setAlpha(1f); + pendingDismiss.view.setTranslationX(0); + } + lp = pendingDismiss.view.getLayoutParams(); lp.height = originalHeight; pendingDismiss.view.setLayoutParams(lp); From 1c2a80b2df7d37c86b79ab5f547b7458786629eb Mon Sep 17 00:00:00 2001 From: Anton Malinskiy Date: Tue, 22 Jul 2014 15:57:50 +0400 Subject: [PATCH 2/2] Fix lint errors --- .../superlistview/SwipeDismissListViewTouchListener.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SuperListviewLibrary/src/main/java/com/quentindommerc/superlistview/SwipeDismissListViewTouchListener.java b/SuperListviewLibrary/src/main/java/com/quentindommerc/superlistview/SwipeDismissListViewTouchListener.java index 6f71f46..a40026c 100644 --- a/SuperListviewLibrary/src/main/java/com/quentindommerc/superlistview/SwipeDismissListViewTouchListener.java +++ b/SuperListviewLibrary/src/main/java/com/quentindommerc/superlistview/SwipeDismissListViewTouchListener.java @@ -16,7 +16,9 @@ package com.quentindommerc.superlistview; +import android.annotation.TargetApi; import android.graphics.Rect; +import android.os.Build; import android.os.SystemClock; import android.support.v4.view.MotionEventCompat; import android.view.*; @@ -166,6 +168,7 @@ public void onScroll(AbsListView absListView, int i, int i1, int i2) { }; } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (mViewWidth < 2) { @@ -346,6 +349,7 @@ public int compareTo(PendingDismissData other) { } } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void performDismiss(final View dismissView, final int dismissPosition) { // Animate the dismissed list item to zero-height and fire the dismiss callback when // all dismissed list item animations have completed. This triggers layout on each animation