Class 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 int DEFAULT_DURATION
      Default animation duration.
    • 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
      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.
      protected boolean onDragged​(int pointerX, int pointerY)
      Returns false 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​(ej.motion.Function motionFunction)
      Sets the motion function.
      void setSwipeListener​(SwipeListener swipeListener)
      Sets the swipe listener.
      void stop()
      Forces the end of the animation.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_DURATION

        public static final int DEFAULT_DURATION
        Default animation duration.
        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 - 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.
        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 - 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.
        Throws:
        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.
      • 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 - 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.
        Throws:
        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.
      • 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 - 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.
        Throws:
        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.
    • 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 or null.
      • stop

        public void stop()
        Forces the end of the animation.
      • onPressed

        protected boolean onPressed​(int pointerX,
                                    int pointerY)
        Description copied from class: PointerEventHandler
        Returns 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.

        Overrides:
        onPressed in class PointerEventHandler
        Parameters:
        pointerX - the Pointer event X, relative to the attached widget.
        pointerY - the Pointer event Y, relative to the attached widget.
        Returns:
        true if the event has been processed, false if it should be dispatched to other handlers.
      • onDragged

        protected boolean onDragged​(int pointerX,
                                    int pointerY)
        Description copied from class: PointerEventHandler
        Returns 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.

        Overrides:
        onDragged in class PointerEventHandler
        Parameters:
        pointerX - the Pointer event X, relative to the attached widget.
        pointerY - the Pointer event Y, relative to the attached widget.
        Returns:
        true if the event has been processed, false if it should be dispatched to other handlers.
      • onReleased

        protected boolean onReleased​(int pointerX,
                                     int pointerY)
        Description copied from class: PointerEventHandler
        Returns false by default.

        Override this method to react on RELEASED events.
        Returns true to prevent other widgets to also handle this event.

        Overrides:
        onReleased in class PointerEventHandler
        Parameters:
        pointerX - the Pointer event X, relative to the attached widget.
        pointerY - the Pointer event Y, relative to the attached widget.
        Returns:
        true if the event has been processed, false if it should be dispatched to other handlers.
      • 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.

        Parameters:
        position - the position to set.
      • 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.

        Parameters:
        stop - the expected end position.
        duration - the duration of the animation.