Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 3cc53a6

Browse files
committed
Added option to swipe a view at given position. Fixes #17
1 parent b452aa8 commit 3cc53a6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

library/src/com/haarman/listviewanimations/itemmanipulation/contextualundo/ContextualUndoAdapter.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535

3636
import com.haarman.listviewanimations.BaseAdapterDecorator;
3737
import com.nineoldandroids.animation.Animator;
38+
import com.nineoldandroids.animation.Animator.AnimatorListener;
3839
import com.nineoldandroids.animation.AnimatorListenerAdapter;
40+
import com.nineoldandroids.animation.ObjectAnimator;
3941
import com.nineoldandroids.animation.ValueAnimator;
4042
import com.nineoldandroids.view.ViewHelper;
4143

@@ -251,6 +253,44 @@ public void onRestoreInstanceState(Bundle savedInstanceState) {
251253
mCurrentRemovedId = savedInstanceState.getLong(EXTRA_ACTIVE_REMOVED_ID, -1);
252254
}
253255

256+
/**
257+
* Animate the item at given position away and show the undo {@link View}.
258+
* @param position the position.
259+
*/
260+
public void swipeViewAtPosition(int position) {
261+
mCurrentRemovedId = getItemId(position);
262+
for (int i = 0; i < getAbsListView().getChildCount(); i++) {
263+
int positionForView = getAbsListView().getPositionForView(getAbsListView().getChildAt(i));
264+
if (positionForView == position) {
265+
swipeView(getAbsListView().getChildAt(i), positionForView);
266+
}
267+
}
268+
}
269+
270+
private void swipeView(final View view, final int dismissPosition) {
271+
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "x", view.getMeasuredWidth());
272+
animator.addListener(new AnimatorListener() {
273+
274+
@Override
275+
public void onAnimationStart(Animator animator) {
276+
}
277+
278+
@Override
279+
public void onAnimationRepeat(Animator animator) {
280+
}
281+
282+
@Override
283+
public void onAnimationEnd(Animator animator) {
284+
onViewSwiped(view, dismissPosition);
285+
}
286+
287+
@Override
288+
public void onAnimationCancel(Animator animator) {
289+
}
290+
});
291+
animator.start();
292+
}
293+
254294
/**
255295
* A callback interface which is used to notify when items should be removed from the collection.
256296
*/

0 commit comments

Comments
 (0)