public class SwipeEventHandler extends PointerEventHandler
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(Widget widget,
int[] itemsSize,
boolean cyclic,
boolean snapToItem,
boolean horizontal,
Swipeable swipeable,
Animator animator)
Creates a swipe event handler on a collection with heterogeneous sizes.
|
SwipeEventHandler(Widget widget,
int size,
boolean cyclic,
boolean horizontal,
Swipeable swipeable,
Animator animator)
Creates a swipe event handler on an element.
|
SwipeEventHandler(Widget widget,
int itemCount,
int itemInterval,
boolean cyclic,
boolean snapToItem,
boolean horizontal,
Swipeable swipeable,
Animator animator)
Creates a swipe event handler on a collection.
|
SwipeEventHandler(Widget widget,
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.
|
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 |
moveToBeginning()
Moves to the beginning.
|
void |
moveToBeginning(long duration)
Moves to the beginning.
|
void |
moveToEnd()
Moves to the end.
|
void |
moveToEnd(long duration)
Moves to the end.
|
protected boolean |
onDragged(int pointerX,
int pointerY)
Returns
false by default. |
protected void |
onExited()
Does nothing by default.
|
protected boolean |
onPressed(int pointerX,
int pointerY)
Returns
false by default. |
protected boolean |
onReleased(int pointerX,
int pointerY)
Returns
false by default. |
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.
|
handleEvent
public static final int DEFAULT_DURATION
public SwipeEventHandler(Widget widget, 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.
widget
- the attached widget.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 there is no item size or if one of the given item size is lesser than or equal to 0.public SwipeEventHandler(Widget widget, int size, boolean cyclic, boolean horizontal, Swipeable swipeable, Animator animator)
widget
- the attached widget.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(Widget widget, 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.
widget
- the attached widget.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(Widget widget, int itemCount, int itemInterval, boolean cyclic, boolean horizontal, Swipeable swipeable, Animator animator)
Equivalent to SwipeEventHandler(Widget, int, int, boolean, boolean, boolean, Swipeable, Animator)
without snapping to the collection items.
widget
- the attached widget.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 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.
Should be called in the UI thread to avoid concurrency issues.
position
- the position to set.MicroUI.isUIThread()
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.
Should be called in the UI thread to avoid concurrency issues.
stop
- the expected end position.duration
- the duration of the animation.MicroUI.isUIThread()
public void moveToBeginning()
moveTo(int)
public void moveToBeginning(long duration)
moveTo(int,long)
public void moveToEnd()
moveTo(int)
public void moveToEnd(long duration)
moveTo(int,long)
protected boolean onDragged(int pointerX, int pointerY)
PointerEventHandler
false
by default.
Override this method to react on DRAGGED
events.
Returns true
to get event focus. Other widgets will no longer receive pointer events until next
RELEASED
.
onDragged
in class PointerEventHandler
pointerX
- the Pointer
event X, relative to the attached widget.pointerY
- the Pointer
event Y, relative to the attached widget.true
if the event has been processed, false
if it should be dispatched to other handlers.protected void onExited()
PointerEventHandler
Override this method to react on focus loss events.
onExited
in class PointerEventHandler
protected boolean onPressed(int pointerX, int pointerY)
PointerEventHandler
false
by default.
Override this method to react on PRESSED
events.
Returns true
to get event focus. Other widgets will no longer receive pointer events until next
RELEASED
.
onPressed
in class PointerEventHandler
pointerX
- the Pointer
event X, relative to the attached widget.pointerY
- the Pointer
event Y, relative to the attached widget.true
if the event has been processed, false
if it should be dispatched to other handlers.protected boolean onReleased(int pointerX, int pointerY)
PointerEventHandler
false
by default.
Override this method to react on RELEASED
events.
Returns true
to prevent other widgets to also handle this event.
onReleased
in class PointerEventHandler
pointerX
- the Pointer
event X, relative to the attached widget.pointerY
- the Pointer
event Y, relative to the attached widget.true
if the event has been processed, false
if it should be dispatched to other handlers.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()