public class SwipeEventHandler
extends java.lang.Object
implements ej.microui.util.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)
Creates a swipe event handler on a collection with heterogeneous sizes.
|
SwipeEventHandler(int size,
boolean cyclic,
boolean horizontal,
Swipeable swipeable)
Creates a swipe event handler on an element.
|
SwipeEventHandler(int itemCount,
int itemInterval,
boolean cyclic,
boolean snapToItem,
boolean horizontal,
Swipeable swipeable)
Creates a swipe event handler on a collection.
|
SwipeEventHandler(int itemCount,
int itemInterval,
boolean cyclic,
boolean horizontal,
Swipeable swipeable)
Creates a swipe event handler on a collection.
|
Modifier and Type | Method and Description |
---|---|
boolean |
handleEvent(int 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 |
setAnimationListener(AnimationListener animationListener)
Sets the animation listener.
|
void |
setDuration(long duration)
Sets the duration.
|
void |
setMotionFactory(ej.motion.MotionFactory motionFactory)
Sets the motion factory.
|
void |
stop()
Forces the end of the animation.
|
public static final int DEFAULT_DURATION
public SwipeEventHandler(int size, boolean cyclic, boolean horizontal, Swipeable swipeable)
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.java.lang.NullPointerException
- if the given swipeable is null
.java.lang.IllegalArgumentException
- if the given size is lesser than or equal to 0.public SwipeEventHandler(int itemCount, int itemInterval, boolean cyclic, boolean horizontal, Swipeable swipeable)
Equivalent to SwipeEventHandler(int, int, boolean, boolean, boolean, Swipeable)
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.java.lang.NullPointerException
- if the given swipeable is null
.java.lang.IllegalArgumentException
- if the given item count or interval is lesser than or equal to 0.public SwipeEventHandler(int itemCount, int itemInterval, boolean cyclic, boolean snapToItem, boolean horizontal, Swipeable swipeable)
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.java.lang.NullPointerException
- if the given swipeable is null
.java.lang.IllegalArgumentException
- if the given item count or interval is lesser than or equal to 0.public SwipeEventHandler(int[] itemsSize, boolean cyclic, boolean snapToItem, boolean horizontal, Swipeable swipeable)
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.java.lang.NullPointerException
- if the given swipeable is null
.java.lang.IllegalArgumentException
- if one of the given item size is lesser than or equal to 0.public void setDuration(long duration)
duration
- the duration to set.public void setMotionFactory(ej.motion.MotionFactory motionFactory)
motionFactory
- the motion factory to set.public void setAnimationListener(AnimationListener animationListener)
animationListener
- the animation listener to set or null
.public void stop()
public boolean handleEvent(int event)
handleEvent
in interface ej.microui.util.EventHandler
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.