Package totalcross.ui

Class Flick

  • All Implemented Interfaces:
    EventHandler, PenListener, TimerListener

    public class Flick
    extends java.lang.Object
    implements PenListener, TimerListener
    Flick Add flick animations to Containers with ScrollBars. The animations conditionally start on the PenUp after drag events. The animations simulate friction using the constant acceleration formula: x = x0 + v0 * (t - t0) + a * (t - t0)^2 / 2 The position at t -= t0 is: position = x0 + v0 * t + a * t^2 / 2; This class is for internal use. You should use the ScrollContainer class instead.
    • Field Detail

      • HORIZONTAL_DIRECTION_ONLY

        public static final int HORIZONTAL_DIRECTION_ONLY
        See Also:
        Constant Field Values
      • VERTICAL_DIRECTION_ONLY

        public static final int VERTICAL_DIRECTION_ONLY
        See Also:
        Constant Field Values
      • forcedFlickDirection

        public int forcedFlickDirection
      • currentFlick

        public static Flick currentFlick
        Indicates that a flick animation is running. Only one can run at a time.
      • defaultFrameRate

        public static int defaultFrameRate
        Desired animation frame rate in frames/second.
      • frameRate

        public int frameRate
      • defaultShortestFlick

        public static int defaultShortestFlick
        Shortest flick animation allowed to start in milliseconds. Used to compute the minimum initial velocity. If a flick animation will come to rest in a shorter time than this it isn't done.
      • shortestFlick

        public int shortestFlick
      • defaultLongestFlick

        public static int defaultLongestFlick
        Longest flick animation allowed in milliseconds. The maximum initial velocity is limited so that no flick animation takes longer than this to come to rest. Changing this property will affect the flick object of all Controls. If you have access to a flick control, you can use the longestFlick property instead. Otherwise, set this property to a new value before constructing the control and then set it back to the original value (2500) after the control is constructed.
      • longestFlick

        public int longestFlick
      • defaultFlickAcceleration

        public static double defaultFlickAcceleration
        Flick acceleration in inches/second^2. This value simulates friction to slow the flick motion. Defaults to 2.95 for screen height > 320, or 1.6 otherwise.
      • flickAcceleration

        public double flickAcceleration
      • isDragging

        public static boolean isDragging
        True if the user is dragging a control that owns a Flick but the flick didn't started yet (in that case, currentFlick would not be null).
      • maximumAccelerationMultiplier

        public int maximumAccelerationMultiplier
        The maximum accelleration that can be applied when the user keep dragging the container. Defaults to 5.
      • dontPropagate

        public boolean dontPropagate
        When a ScrollContainer is inside another one, by default, both can be scrolled at the same time. Set this flag to false at the topmost one to prevent this from occuring.
    • Constructor Detail

      • Flick

        public Flick​(Scrollable s)
        Create a Flick animation object for a FlickableContainer.
    • Method Detail

      • setPagePosition

        public void setPagePosition​(PagePosition pp)
        Call this method to set the PagePosition control that will be updated with the current page as the flick occurs. It must have all properties already set, since the Flick will only change the current position.
      • setScrollDistance

        public void setScrollDistance​(int v)
        Used in page scrolls, defines the distance that should be scrolled. Recomputes the time and the initial velocity to ensure that this is the amount that will be scrolled. Also updates distanceToAbortScroll.
        See Also:
        setDistanceToAbortScroll(int)
      • setDistanceToAbortScroll

        public void setDistanceToAbortScroll​(int v)
        The distance used to abort the scroll. Set to 0 to make it always scroll a page, even if it dragged just a bit. Defaults to scrollDistance/5. Be sure to call the method setScrollDistance before calling this one.
        See Also:
        setScrollDistance(int)
      • addScrollableListener

        public void addScrollableListener​(Scrollable s)
        Adds another listener of Scrollable events.
      • addEventSource

        public void addEventSource​(Control c)
        Adds an event source to whom this flick will grab pen events.
      • removeEventSource

        public void removeEventSource​(Control c)
        Remove a previously added event source.
      • isValidDirection

        public boolean isValidDirection​(int direction)
      • penDrag

        public void penDrag​(DragEvent e)
        Resets the drag start parameters if the direction changes.
        Specified by:
        penDrag in interface PenListener
        See Also:
        PenEvent
      • callListeners

        public void callListeners​(boolean started,
                                  boolean atPenDown)
        Calls the listeners of this flick.