public class EdgeEffect
extends java.lang.Object
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
View.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.
| Modifier and Type | Field and Description |
|---|---|
static int |
DIRECTION_HORIZONTAL |
static int |
DIRECTION_VERTICAL |
| Constructor and Description |
|---|
EdgeEffect(android.content.Context context,
int direction)
Construct a new EdgeEffect with a theme appropriate for the provided context.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
draw(android.graphics.Canvas canvas)
Draw into the provided canvas.
|
void |
finish()
Immediately finish the current animation.
|
android.graphics.Rect |
getBounds(boolean reverse)
Returns the bounds of the edge effect.
|
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 |
onRelease()
Call when the object is released after being pulled.
|
void |
setPosition(int x,
int y)
Set the position of this edge effect in pixels.
|
void |
setSize(int width,
int height)
Set the size of this edge effect in pixels.
|
public static final int DIRECTION_VERTICAL
public static final int DIRECTION_HORIZONTAL
public EdgeEffect(android.content.Context context,
int direction)
context - Context used to provide theming and resource information for the EdgeEffectpublic void setSize(int width,
int height)
width - Effect width in pixelsheight - Effect height in pixelspublic void setPosition(int x,
int y)
getBounds(boolean).x - The position of the edge effect on the X axisy - The position of the edge effect on the Y axispublic boolean isFinished()
draw(Canvas) the host widget should schedule another
drawing pass to continue the animation.public void finish()
isFinished() will return true.public void onPull(float deltaDistance)
View.invalidate() after this
and draw the results accordingly.deltaDistance - 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.public void onRelease()
View.invalidate() and thereby
draw the results accordingly.public void onAbsorb(int velocity)
When using a Scroller or OverScroller,
the method getCurrVelocity will provide a reasonable approximation
to use here.
velocity - Velocity at impact in pixels per second.public boolean draw(android.graphics.Canvas canvas)
canvas - Canvas to draw intopublic android.graphics.Rect getBounds(boolean reverse)