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

Fix missing reset swipe animation on newer API's #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -38,16 +40,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.
*
* <p/>
* <p>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.</p>
*
* <p/>
* <p>Example usage:</p>
*
* <p/>
* <pre>
* SwipeDismissListViewTouchListener touchListener =
* new SwipeDismissListViewTouchListener(
Expand All @@ -63,10 +65,10 @@
* listView.setOnTouchListener(touchListener);
* listView.setOnScrollListener(touchListener.makeScrollListener());
* </pre>
*
* <p/>
* <p>This class Requires API level 12 or later due to use of {@link
* ViewPropertyAnimator}.</p>
*
* <p/>
* <p>For a generalized {@link View.OnTouchListener} that makes any view dismissable,
* see {@link SwipeDismissTouchListener}.</p>
*
Expand Down Expand Up @@ -94,7 +96,6 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
private VelocityTracker mVelocityTracker;
private int mDownPosition;
private View mDownView;
private AnimatorProxy mDownViewProxy;
private boolean mPaused;

/**
Expand Down Expand Up @@ -167,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) {
Expand Down Expand Up @@ -194,7 +196,6 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
child.getHitRect(rect);
if (rect.contains(x, y)) {
mDownView = child;
mDownViewProxy = AnimatorProxy.wrap(child);
break;
}
}
Expand All @@ -208,7 +209,6 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
mVelocityTracker.addMovement(motionEvent);
} else {
mDownView = null;
mDownViewProxy= null;
}
}
return false;
Expand All @@ -232,7 +232,6 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
mDownX = 0;
mDownY = 0;
mDownView = null;
mDownViewProxy= null;
mDownPosition = ListView.INVALID_POSITION;
mSwiping = false;
break;
Expand Down Expand Up @@ -287,7 +286,6 @@ public void onAnimationEnd(Animator animation) {
mDownX = 0;
mDownY = 0;
mDownView = null;
mDownViewProxy= null;
mDownPosition = ListView.INVALID_POSITION;
mSwiping = false;
break;
Expand Down Expand Up @@ -316,9 +314,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;
Expand All @@ -343,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
Expand Down Expand Up @@ -375,8 +382,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);
Expand Down