Class SwipeEventHandler
- java.lang.Object
-
- ej.widget.event.PointerEventHandler
-
- ej.widget.swipe.SwipeEventHandler
-
- All Implemented Interfaces:
ej.microui.event.EventHandler
public class SwipeEventHandler extends PointerEventHandler
The swipe event handler responsibility is to detect pointer events (press, drag, release) and help moving over some element(s).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.
- Since:
- 2.3.0
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_DURATIONDefault animation duration.static floatDEFAULT_INTERPOLATION_RATIODefault interpolation ratio.
-
Constructor Summary
Constructors Constructor Description SwipeEventHandler(ej.mwt.Widget widget, int[] itemsSize, boolean cyclic, boolean snapToItem, boolean horizontal, Swipeable swipeable, ej.mwt.animation.Animator animator)Creates a swipe event handler on a collection with heterogeneous sizes.SwipeEventHandler(ej.mwt.Widget widget, int size, boolean cyclic, boolean horizontal, Swipeable swipeable, ej.mwt.animation.Animator animator)Creates a swipe event handler on an element.SwipeEventHandler(ej.mwt.Widget widget, int itemCount, int itemInterval, boolean cyclic, boolean snapToItem, boolean horizontal, Swipeable swipeable, ej.mwt.animation.Animator animator)Creates a swipe event handler on a collection.SwipeEventHandler(ej.mwt.Widget widget, int itemCount, int itemInterval, boolean cyclic, boolean horizontal, Swipeable swipeable, ej.mwt.animation.Animator animator)Creates a swipe event handler on a collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetCurrentPosition()Gets the current position of this swipe event handler.intlimit(int position)Limits a position between 0 and the content size.voidmoveTo(int position)Moves to a position.voidmoveTo(int stop, long duration)Animates the move to a position.voidmoveToBeginning()Moves to the beginning.voidmoveToBeginning(long duration)Moves to the beginning.voidmoveToEnd()Moves to the end.voidmoveToEnd(long duration)Moves to the end.protected booleanonDragged(int pointerX, int pointerY)Returnsfalseby default.protected voidonExited()Does nothing by default.protected booleanonPressed(int pointerX, int pointerY)Returnsfalseby default.protected booleanonReleased(int pointerX, int pointerY)Returnsfalseby default.voidsetDuration(long duration)Sets the duration.voidsetInterpolationRatio(float interpolationRatio)Sets the interpolation ratio for a swipe.voidsetMotionFunction(ej.motion.Function motionFunction)Sets the motion function.voidsetSwipeListener(SwipeListener swipeListener)Sets the swipe listener.voidstop()Forces the end of the animation.-
Methods inherited from class ej.widget.event.PointerEventHandler
handleEvent
-
-
-
-
Field Detail
-
DEFAULT_DURATION
public static final int DEFAULT_DURATION
Default animation duration.- See Also:
- Constant Field Values
-
DEFAULT_INTERPOLATION_RATIO
public static final float DEFAULT_INTERPOLATION_RATIO
Default interpolation ratio.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SwipeEventHandler
public SwipeEventHandler(ej.mwt.Widget widget, int size, boolean cyclic, boolean horizontal, Swipeable swipeable, ej.mwt.animation.Animator animator)Creates a swipe event handler on an element.- Parameters:
widget- the attached widget.size- the available size.cyclic-trueif the element to swipe is cyclic,falseotherwise.horizontal-trueif the element to swipe is horizontal,falseotherwise.swipeable- the swipeable.animator- the animator to use to execute the release animation.- Throws:
java.lang.IllegalArgumentException- if the given size is lesser than or equal to 0.
-
SwipeEventHandler
public SwipeEventHandler(ej.mwt.Widget widget, int itemCount, int itemInterval, boolean cyclic, boolean horizontal, Swipeable swipeable, ej.mwt.animation.Animator animator)Creates a swipe event handler on a collection.Equivalent to
SwipeEventHandler(Widget, int, int, boolean, boolean, boolean, Swipeable, Animator)without snapping to the collection items.- Parameters:
widget- the attached widget.itemCount- the number of items.itemInterval- the interval between items center.cyclic-trueif the collection to swipe is cyclic,falseotherwise.horizontal-trueif the collection to swipe is horizontal,falseotherwise.swipeable- the swipeable.animator- the animator to use to execute the release animation.- Throws:
java.lang.NullPointerException- if the given swipeable isnull.java.lang.IllegalArgumentException- if the given item count or interval is lesser than or equal to 0.
-
SwipeEventHandler
public SwipeEventHandler(ej.mwt.Widget widget, int itemCount, int itemInterval, boolean cyclic, boolean snapToItem, boolean horizontal, Swipeable swipeable, ej.mwt.animation.Animator animator)Creates a swipe event handler on a collection.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.- Parameters:
widget- the attached widget.itemCount- the number of items.itemInterval- the interval between items center.cyclic-trueif the collection to swipe is cyclic,falseotherwise.snapToItem-trueif the items are snapped,falseotherwise.horizontal-trueif the collection to swipe is horizontal,falseotherwise.swipeable- the swipeable.animator- the animator to use to execute the release animation.- Throws:
java.lang.NullPointerException- if the given swipeable isnull.java.lang.IllegalArgumentException- if the given item count or interval is lesser than or equal to 0.
-
SwipeEventHandler
public SwipeEventHandler(ej.mwt.Widget widget, int[] itemsSize, boolean cyclic, boolean snapToItem, boolean horizontal, Swipeable swipeable, ej.mwt.animation.Animator animator)Creates a swipe event handler on a collection with heterogeneous sizes.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.- Parameters:
widget- the attached widget.itemsSize- the size of the items.cyclic-trueif the collection to swipe is cyclic,falseotherwise.snapToItem-trueif the items are snapped,falseotherwise.horizontal-trueif the collection to swipe is horizontal,falseotherwise.swipeable- the swipeable.animator- the animator to use to execute the release animation.- Throws:
java.lang.NullPointerException- if the given swipeable isnull.java.lang.IllegalArgumentException- if there is no item size or if one of the given item size is lesser than or equal to 0.
-
-
Method Detail
-
getCurrentPosition
public int getCurrentPosition()
Gets the current position of this swipe event handler.- Returns:
- the current position of this swipe event handler.
-
setDuration
public void setDuration(long duration)
Sets the duration.- Parameters:
duration- the duration to set.
-
setMotionFunction
public void setMotionFunction(ej.motion.Function motionFunction)
Sets the motion function.- Parameters:
motionFunction- the motion function to set.
-
setSwipeListener
public void setSwipeListener(@Nullable SwipeListener swipeListener)Sets the swipe listener.- Parameters:
swipeListener- the swipe listener to set ornull.
-
stop
public void stop()
Forces the end of the animation.
-
setInterpolationRatio
public void setInterpolationRatio(float interpolationRatio)
Sets the interpolation ratio for a swipe. As the interpolation ratio approaches 1, the amount of interpolation reduces and at 1 there is no interpolation at all.- Parameters:
interpolationRatio- the ratio which determines at which rate the swipe moves to the target position, must be between 0 excluded and 1.0f included.
-
onPressed
protected boolean onPressed(int pointerX, int pointerY)Description copied from class:PointerEventHandlerReturnsfalseby default.Override this method to react on
PRESSEDevents.
Returnstrueto get event focus. Other widgets will no longer receive pointer events until nextRELEASED.- Overrides:
onPressedin classPointerEventHandler- Parameters:
pointerX- thePointerevent X, relative to the attached widget.pointerY- thePointerevent Y, relative to the attached widget.- Returns:
trueif the event has been processed,falseif it should be dispatched to other handlers.
-
onDragged
protected boolean onDragged(int pointerX, int pointerY)Description copied from class:PointerEventHandlerReturnsfalseby default.Override this method to react on
DRAGGEDevents.
Returnstrueto get event focus. Other widgets will no longer receive pointer events until nextRELEASED.- Overrides:
onDraggedin classPointerEventHandler- Parameters:
pointerX- thePointerevent X, relative to the attached widget.pointerY- thePointerevent Y, relative to the attached widget.- Returns:
trueif the event has been processed,falseif it should be dispatched to other handlers.
-
onReleased
protected boolean onReleased(int pointerX, int pointerY)Description copied from class:PointerEventHandlerReturnsfalseby default.Override this method to react on
RELEASEDevents.
Returnstrueto prevent other widgets to also handle this event.- Overrides:
onReleasedin classPointerEventHandler- Parameters:
pointerX- thePointerevent X, relative to the attached widget.pointerY- thePointerevent Y, relative to the attached widget.- Returns:
trueif the event has been processed,falseif it should be dispatched to other handlers.
-
onExited
protected void onExited()
Description copied from class:PointerEventHandlerDoes nothing by default.Override this method to react on focus loss events.
- Overrides:
onExitedin classPointerEventHandler
-
limit
public int limit(int position)
Limits a position between 0 and the content size.- Parameters:
position- the position to limit.- Returns:
- the limited position.
-
moveTo
public void moveTo(int position)
Moves to a 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.
- Parameters:
position- the position to set.- See Also:
MicroUI.isUIThread()
-
moveTo
public void moveTo(int stop, long duration)Animates the move to a 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.
- Parameters:
stop- the expected end position.duration- the duration of the animation.- See Also:
MicroUI.isUIThread()
-
moveToBeginning
public void moveToBeginning()
Moves to the beginning.- See Also:
moveTo(int)
-
moveToBeginning
public void moveToBeginning(long duration)
Moves to the beginning.- See Also:
moveTo(int,long)
-
moveToEnd
public void moveToEnd()
Moves to the end.- See Also:
moveTo(int)
-
moveToEnd
public void moveToEnd(long duration)
Moves to the end.- See Also:
moveTo(int,long)
-
-