Package totalcross.ui
Class Flick
- java.lang.Object
-
- totalcross.ui.Flick
-
- All Implemented Interfaces:
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 Summary
Fields Modifier and Type Field Description static intBOTH_DIRECTIONSstatic FlickcurrentFlickIndicates that a flick animation is running.static doubledefaultFlickAccelerationFlick acceleration in inches/second^2.static intdefaultFrameRateDesired animation frame rate in frames/second.static intdefaultLongestFlickLongest flick animation allowed in milliseconds.static intdefaultShortestFlickShortest flick animation allowed to start in milliseconds.booleandontPropagateWhen a ScrollContainer is inside another one, by default, both can be scrolled at the same time.doubleflickAccelerationintforcedFlickDirectionintframeRatestatic intHORIZONTAL_DIRECTION_ONLYstatic booleanisDraggingTrue 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).intlongestFlickintmaximumAccelerationMultiplierThe maximum accelleration that can be applied when the user keep dragging the container.PagePositionpageposintshortestFlickstatic intVERTICAL_DIRECTION_ONLY
-
Constructor Summary
Constructors Constructor Description Flick(Scrollable s)Create a Flick animation object for a FlickableContainer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEventSource(Control c)Adds an event source to whom this flick will grab pen events.voidaddScrollableListener(Scrollable s)Adds another listener of Scrollable events.voidcallListeners(boolean started, boolean atPenDown)Calls the listeners of this flick.booleanisValidDirection(int direction)voidpenDown(PenEvent e)Indicates the start of a simple tap or a drag.voidpenDrag(DragEvent e)Resets the drag start parameters if the direction changes.voidpenDragEnd(DragEvent e)Checks whether or not to start a flick animation.voidpenDragStart(DragEvent e)Indicates the start of a drag.voidpenUp(PenEvent e)A PEN_UP event was dispatched.voidremoveEventSource(Control c)Remove a previously added event source.voidsetDistanceToAbortScroll(int v)The distance used to abort the scroll.voidsetPagePosition(PagePosition pp)Call this method to set the PagePosition control that will be updated with the current page as the flick occurs.voidsetScrollDistance(int v)Used in page scrolls, defines the distance that should be scrolled.voidtimerTriggered(TimerEvent e)Processes timer ticks to run the animation.
-
-
-
Field Detail
-
BOTH_DIRECTIONS
public static final int BOTH_DIRECTIONS
- See Also:
- Constant Field Values
-
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
-
pagepos
public PagePosition pagepos
-
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.
-
penDown
public void penDown(PenEvent e)
Indicates the start of a simple tap or a drag.- Specified by:
penDownin interfacePenListener- See Also:
PenEvent
-
isValidDirection
public boolean isValidDirection(int direction)
-
penDragStart
public void penDragStart(DragEvent e)
Indicates the start of a drag.- Specified by:
penDragStartin interfacePenListener- See Also:
PenEvent
-
penDrag
public void penDrag(DragEvent e)
Resets the drag start parameters if the direction changes.- Specified by:
penDragin interfacePenListener- See Also:
PenEvent
-
penDragEnd
public void penDragEnd(DragEvent e)
Checks whether or not to start a flick animation.- Specified by:
penDragEndin interfacePenListener- See Also:
PenEvent
-
callListeners
public void callListeners(boolean started, boolean atPenDown)Calls the listeners of this flick.
-
penUp
public void penUp(PenEvent e)
Description copied from interface:PenListenerA PEN_UP event was dispatched.- Specified by:
penUpin interfacePenListener- See Also:
PenEvent
-
timerTriggered
public void timerTriggered(TimerEvent e)
Processes timer ticks to run the animation.- Specified by:
timerTriggeredin interfaceTimerListener- See Also:
TimerEvent
-
-