Most visited

Recently visited

Added in API level 14

EdgeEffect

public class EdgeEffect
extends Object

java.lang.Object
   ↳ android.widget.EdgeEffect


This class performs the graphical effect used at the edges of scrollable widgets when the user scrolls beyond the content bounds in 2D space.

EdgeEffect is stateful. Custom widgets using EdgeEffect should create an instance for each edge that should show the effect, feed it input data using the methods onAbsorb(int), onPull(float), and onRelease(), and draw the effect using draw(Canvas) in the widget's overridden draw(Canvas) method. If isFinished() returns false after drawing, the edge effect's animation is not yet complete and the widget should schedule another drawing pass to continue the animation.

When drawing, widgets should draw their main content and child views first, usually by invoking super.draw(canvas) from an overridden draw method. (This will invoke onDraw and dispatch drawing to child views as needed.) The edge effect may then be drawn on top of the view's content using the draw(Canvas) method.

Summary

Public constructors

EdgeEffect(Context context)

Construct a new EdgeEffect with a theme appropriate for the provided context.

Public methods

boolean draw(Canvas canvas)

Draw into the provided canvas.

void finish()

Immediately finish the current animation.

int getColor()

Return the color of this edge effect in argb.

int getMaxHeight()

Return the maximum height that the edge effect will be drawn at given the original input size.

boolean isFinished()

Reports if this EdgeEffect's animation is finished.

void onAbsorb(int velocity)

Call when the effect absorbs an impact at the given velocity.

void onPull(float deltaDistance)

A view should call this when content is pulled away from an edge by the user.

void onPull(float deltaDistance, float displacement)

A view should call this when content is pulled away from an edge by the user.

void onRelease()

Call when the object is released after being pulled.

void setColor(int color)

Set the color of this edge effect in argb.

void setSize(int width, int height)

Set the size of this edge effect in pixels.

Inherited methods

From class java.lang.Object

Public constructors

EdgeEffect

Added in API level 14
EdgeEffect (Context context)

Construct a new EdgeEffect with a theme appropriate for the provided context.

Parameters
context Context: Context used to provide theming and resource information for the EdgeEffect

Public methods

draw

Added in API level 14
boolean draw (Canvas canvas)

Draw into the provided canvas. Assumes that the canvas has been rotated accordingly and the size has been set. The effect will be drawn the full width of X=0 to X=width, beginning from Y=0 and extending to some factor < 1.f of height.

Parameters
canvas Canvas: Canvas to draw into
Returns
boolean true if drawing should continue beyond this frame to continue the animation

finish

Added in API level 14
void finish ()

Immediately finish the current animation. After this call isFinished() will return true.

getColor

Added in API level 21
int getColor ()

Return the color of this edge effect in argb.

Returns
int The color of this edge effect in argb

getMaxHeight

Added in API level 21
int getMaxHeight ()

Return the maximum height that the edge effect will be drawn at given the original input size.

Returns
int The maximum height of the edge effect

isFinished

Added in API level 14
boolean isFinished ()

Reports if this EdgeEffect's animation is finished. If this method returns false after a call to draw(Canvas) the host widget should schedule another drawing pass to continue the animation.

Returns
boolean true if animation is finished, false if drawing should continue on the next frame.

onAbsorb

Added in API level 14
void onAbsorb (int velocity)

Call when the effect absorbs an impact at the given velocity. Used when a fling reaches the scroll boundary.

When using a Scroller or OverScroller, the method getCurrVelocity will provide a reasonable approximation to use here.

Parameters
velocity int: Velocity at impact in pixels per second.

onPull

Added in API level 14
void onPull (float deltaDistance)

A view should call this when content is pulled away from an edge by the user. This will update the state of the current visual effect and its associated animation. The host view should always invalidate() after this and draw the results accordingly.

Views using EdgeEffect should favor onPull(float, float) when the displacement of the pull point is known.

Parameters
deltaDistance float: Change in distance since the last call. Values may be 0 (no change) to 1.f (full length of the view) or negative values to express change back toward the edge reached to initiate the effect.

onPull

Added in API level 21
void onPull (float deltaDistance, 
                float displacement)

A view should call this when content is pulled away from an edge by the user. This will update the state of the current visual effect and its associated animation. The host view should always invalidate() after this and draw the results accordingly.

Parameters
deltaDistance float: Change in distance since the last call. Values may be 0 (no change) to 1.f (full length of the view) or negative values to express change back toward the edge reached to initiate the effect.
displacement float: The displacement from the starting side of the effect of the point initiating the pull. In the case of touch this is the finger position. Values may be from 0-1.

onRelease

Added in API level 14
void onRelease ()

Call when the object is released after being pulled. This will begin the "decay" phase of the effect. After calling this method the host view should invalidate() and thereby draw the results accordingly.

setColor

Added in API level 21
void setColor (int color)

Set the color of this edge effect in argb.

Parameters
color int: Color in argb

setSize

Added in API level 14
void setSize (int width, 
                int height)

Set the size of this edge effect in pixels.

Parameters
width int: Effect width in pixels
height int: Effect height in pixels

Hooray!