public abstract class SwipeTouchListener extends Object implements View.OnTouchListener, TouchEventHandler
View.OnTouchListener that makes the list items in a AbsListView swipeable.
Implementations of this class should implement afterViewFling(android.view.View, int) to specify what to do after an item has been swiped.| Modifier | Constructor and Description |
|---|---|
protected |
SwipeTouchListener(com.nhaarman.listviewanimations.util.ListViewWrapper listViewWrapper)
Constructs a new
SwipeTouchListener for the given AbsListView. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterCancelSwipe(View view,
int position)
Called after the restore animation of a canceled swipe movement ends.
|
protected abstract void |
afterViewFling(View view,
int position)
Called after the fling animation of a succesful swipe ends.
|
protected void |
beforeViewFling(View view,
int position)
Called when the user lifted their finger off the screen, and the
View should be swiped away. |
void |
disableSwipe()
Disables the swipe behavior.
|
void |
enableSwipe()
Enables the swipe behavior.
|
void |
fling(int position)
Flings the
View corresponding to given position out of sight. |
protected int |
getActiveSwipeCount()
Returns the number of active swipe animations.
|
com.nhaarman.listviewanimations.util.ListViewWrapper |
getListViewWrapper() |
protected View |
getSwipeView(View view)
Returns the
View that should be swiped away. |
boolean |
isInteracting() |
boolean |
isSwiping()
Returns whether the user is currently swiping an item.
|
void |
notifyDataSetChanged()
Notifies this
SwipeTouchListener that the adapter contents have changed. |
protected void |
onCancelSwipe(View view,
int position)
Called when the swipe movement is canceled.
|
protected void |
onStartSwipe(View view,
int position)
Called when the user starts swiping a
View. |
boolean |
onTouch(View view,
MotionEvent event) |
boolean |
onTouchEvent(MotionEvent event) |
protected void |
restoreViewPresentation(View view)
|
void |
setDismissableManager(DismissableManager dismissableManager)
Sets the
DismissableManager to specify which views can or cannot be swiped. |
void |
setMinimumAlpha(float minimumAlpha)
Set the minimum value of the alpha property swiping Views should have.
|
void |
setParentIsHorizontalScrollContainer()
If the
AbsListView is hosted inside a parent(/grand-parent/etc) that can scroll horizontally, horizontal swipes won't
work, because the parent will prevent touch-events from reaching the AbsListView. |
void |
setTouchChild(int childResId)
Sets the resource id of a child view that should be touched to engage swipe.
|
protected abstract boolean |
willLeaveDataSetOnFling(View view,
int position)
Returns whether flinging the item at given position in the current state
would cause it to be removed from the data set.
|
protected SwipeTouchListener(com.nhaarman.listviewanimations.util.ListViewWrapper listViewWrapper)
SwipeTouchListener for the given AbsListView.public void setDismissableManager(DismissableManager dismissableManager)
DismissableManager to specify which views can or cannot be swiped.dismissableManager - null for no restrictions.public void setMinimumAlpha(float minimumAlpha)
minimumAlpha - the alpha value between 0.0f and 1.0f.public void setParentIsHorizontalScrollContainer()
AbsListView is hosted inside a parent(/grand-parent/etc) that can scroll horizontally, horizontal swipes won't
work, because the parent will prevent touch-events from reaching the AbsListView.
Call this method to fix this behavior.
Note that this will prevent the parent from scrolling horizontally when the user touches anywhere in a list item.public void setTouchChild(int childResId)
childResId - The resource id of the list items' child that the user should touch to be able to swipe the list items.public void notifyDataSetChanged()
SwipeTouchListener that the adapter contents have changed.public boolean isSwiping()
true if the user is swiping an item.public com.nhaarman.listviewanimations.util.ListViewWrapper getListViewWrapper()
public void enableSwipe()
public void disableSwipe()
public void fling(int position)
View corresponding to given position out of sight.
Calling this method has the same effect as manually swiping an item off the screen.position - the position of the item in the ListAdapter. Must be visible.public boolean isInteracting()
isInteracting in interface TouchEventHandlerpublic boolean onTouchEvent(MotionEvent event)
onTouchEvent in interface TouchEventHandlerpublic boolean onTouch(View view, MotionEvent event)
onTouch in interface View.OnTouchListenerprotected void onStartSwipe(View view, int position)
View.view - the View that is being swiped.position - the position of the item in the ListAdapter corresponding to the View.protected void onCancelSwipe(View view, int position)
view - the View that was swiped.position - the position of the item in the ListAdapter corresponding to the View.protected void afterCancelSwipe(View view, int position)
view - the View that is being swiped.position - the position of the item in the ListAdapter corresponding to the View.protected void beforeViewFling(View view, int position)
View should be swiped away. A fling animation starts at this point.view - the View that is being flinged.position - the position of the item in the ListAdapter corresponding to the View.protected abstract boolean willLeaveDataSetOnFling(View view, int position)
view - the View that would be flinged.position - the position of the item in the ListAdapter corresponding to the View.true if the item would leave the data set, false otherwise.protected abstract void afterViewFling(View view, int position)
view - the View that is being swiped.position - the position of the item in the ListAdapter corresponding to the View.protected void restoreViewPresentation(View view)
View's alpha and translationX values.
Users of this class should call this method when recycling Views.view - the View whose presentation should be restored.protected int getActiveSwipeCount()