|
35 | 35 |
|
36 | 36 | import com.haarman.listviewanimations.BaseAdapterDecorator; |
37 | 37 | import com.nineoldandroids.animation.Animator; |
| 38 | +import com.nineoldandroids.animation.Animator.AnimatorListener; |
38 | 39 | import com.nineoldandroids.animation.AnimatorListenerAdapter; |
| 40 | +import com.nineoldandroids.animation.ObjectAnimator; |
39 | 41 | import com.nineoldandroids.animation.ValueAnimator; |
40 | 42 | import com.nineoldandroids.view.ViewHelper; |
41 | 43 |
|
@@ -251,6 +253,44 @@ public void onRestoreInstanceState(Bundle savedInstanceState) { |
251 | 253 | mCurrentRemovedId = savedInstanceState.getLong(EXTRA_ACTIVE_REMOVED_ID, -1); |
252 | 254 | } |
253 | 255 |
|
| 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 | + |
254 | 294 | /** |
255 | 295 | * A callback interface which is used to notify when items should be removed from the collection. |
256 | 296 | */ |
|
0 commit comments