public class SwipeEventHandler extends Object implements EventHandler
When the pointer is pressed and dragged, the content follows the pointer.
On pointer release, the moved content stops progressively (depending on the speed of the movement).
The content may be cyclic, that means that when a bound is reached (beginning or end), the other bound is displayed.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_DURATION
Default animation duration.
|
Constructor and Description |
---|
SwipeEventHandler(int[] itemsSize,
boolean cyclic,
boolean snapToItem,
boolean horizontal,
Swipeable swipeable,
Animator animator)
Creates a swipe event handler on a collection with heterogeneous sizes.
|
SwipeEventHandler(int size,
boolean cyclic,
boolean horizontal,
Swipeable swipeable,
Animator animator)
Creates a swipe event handler on an element.
|
SwipeEventHandler(int itemCount,
int itemInterval,
boolean cyclic,
boolean snapToItem,
boolean horizontal,
Swipeable swipeable,
Animator animator)
Creates a swipe event handler on a collection.
|
SwipeEventHandler(int itemCount,
int itemInterval,
boolean cyclic,
boolean horizontal,
Swipeable swipeable,
Animator animator)
Creates a swipe event handler on a collection.
|
Modifier and Type | Method and Description |
---|---|
int |
getCurrentPosition()
Gets the current position of this swipe event handler.
|
boolean |
handleEvent(int event)
Handles an event.
|
int |
limit(int position)
Limits a position between 0 and the content size.
|
void |
moveTo(int position)
Moves to a position.
|
void |
moveTo(int stop,
long duration)
Animates the move to a position.
|
void |
setDuration(long duration)
Sets the duration.
|
void |
setMotionFunction(Function motionFunction)
Sets the motion function.
|
void |
setSwipeListener(SwipeListener swipeListener)
Sets the swipe listener.
|
void |
stop()
Forces the end of the animation.
|
public static final int DEFAULT_DURATION
public SwipeEventHandler(int[] itemsSize, boolean cyclic, boolean snapToItem, boolean horizontal, Swipeable swipeable, Animator animator)
If the snap parameter is set, when the pointer is released, the swipeable is snapped to the closest snapping
point (i.e. the closest item offset). See moveTo(int, long)
for more information.
itemsSize
- the size of the items.cyclic
- true
if the collection to swipe is cyclic, false
otherwise.snapToItem
- true
if the items are snapped, false
otherwise.horizontal
- true
if the collection to swipe is horizontal, false
otherwise.swipeable
- the swipeable.animator
- the animator to use to execute the release animation.NullPointerException
- if the given swipeable is null
.IllegalArgumentException
- if one of the given item size is lesser than or equal to 0.public SwipeEventHandler(int size, boolean cyclic, boolean horizontal, Swipeable swipeable, Animator animator)
size
- the available size.cyclic
- true
if the element to swipe is cyclic, false
otherwise.horizontal
- true
if the element to swipe is horizontal, false
otherwise.swipeable
- the swipeable.animator
- the animator to use to execute the release animation.IllegalArgumentException
- if the given size is lesser than or equal to 0.public SwipeEventHandler(int itemCount, int itemInterval, boolean cyclic, boolean snapToItem, boolean horizontal, Swipeable swipeable, Animator animator)
If the snap parameter is set, when the pointer is released, the swipeable is snapped to the closest snapping
point (i.e. the closest multiple of interval). See moveTo(int, long)
for more information.
itemCount
- the number of items.itemInterval
- the interval between items center.cyclic
- true
if the collection to swipe is cyclic, false
otherwise.snapToItem
- true
if the items are snapped, false
otherwise.horizontal
- true
if the collection to swipe is horizontal, false
otherwise.swipeable
- the swipeable.animator
- the animator to use to execute the release animation.NullPointerException
- if the given swipeable is null
.IllegalArgumentException
- if the given item count or interval is lesser than or equal to 0.public SwipeEventHandler(int itemCount, int itemInterval, boolean cyclic, boolean horizontal, Swipeable swipeable, Animator animator)
Equivalent to SwipeEventHandler(int, int, boolean, boolean, boolean, Swipeable, Animator)
without
snapping to the collection items.
itemCount
- the number of items.itemInterval
- the interval between items center.cyclic
- true
if the collection to swipe is cyclic, false
otherwise.horizontal
- true
if the collection to swipe is horizontal, false
otherwise.swipeable
- the swipeable.animator
- the animator to use to execute the release animation.NullPointerException
- if the given swipeable is null
.IllegalArgumentException
- if the given item count or interval is lesser than or equal to 0.public int getCurrentPosition()
public boolean handleEvent(int event)
EventHandler
handleEvent
in interface EventHandler
event
- the event to handle.true
if the event is consumed, false
otherwise.Event
public int limit(int position)
position
- the position to limit.public void moveTo(int position)
If the snap parameter is set, the given position is snapped to the closest multiple of the interval size between elements.
position
- the position to set.public void moveTo(int stop, long duration)
If the snap parameter is set, the given position is snapped to the closest multiple of the interval size between elements.
stop
- the expected end position.duration
- the duration of the animation.public void setDuration(long duration)
duration
- the duration to set.public void setMotionFunction(Function motionFunction)
motionFunction
- the motion function to set.public void setSwipeListener(@Nullable SwipeListener swipeListener)
swipeListener
- the swipe listener to set or null
.public void stop()