EdgeEffectCompat

class EdgeEffectCompat
kotlin.Any
   ↳ androidx.core.widget.EdgeEffectCompat

Helper for accessing android.widget.EdgeEffect. This class is used to access android.widget.EdgeEffect on platform versions that support it. When running on older platforms it will result in no-ops. It should be used by views that wish to use the standard Android visual effects at the edges of scrolling containers.

Summary

Public constructors
<init>(context: Context!)

Use EdgeEffect constructor directly.

Public methods
Boolean
onAbsorb(velocity: Int)

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

Unit

Immediately finish the current animation.

Boolean

Call when the object is released after being pulled.

Boolean

Reports if this EdgeEffectCompat's animation is finished.

Boolean
onPull(deltaDistance: Float)

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

Boolean
onPull(deltaDistance: Float, displacement: Float)

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

Boolean
draw(canvas: Canvas!)

Draw into the provided canvas.

Unit
setSize(width: Int, height: Int)

Set the size of this edge effect in pixels.

static Unit
onPull(edgeEffect: EdgeEffect, deltaDistance: Float, displacement: Float)

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

Public constructors

<init>

EdgeEffectCompat(context: Context!)

Deprecated: Use EdgeEffect constructor directly.

Construct a new EdgeEffect themed using the given context.

Note: On platform versions that do not support EdgeEffect, all operations on the newly constructed object will be mocked/no-ops.

Parameters
context Context!: Context to use for theming the effect

Public methods

onAbsorb

fun onAbsorb(velocity: Int): Boolean

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

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

Parameters
velocity Int: Velocity at impact in pixels per second.
Return
Boolean: true if the host view should invalidate, false if it should not.

finish

fun finish(): Unit

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

onRelease

fun onRelease(): Boolean

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 android.view.View#invalidate() if this method returns true and thereby draw the results accordingly.

Return
Boolean: true if the host view should invalidate, false if it should not.

isFinished

fun isFinished(): Boolean

Reports if this EdgeEffectCompat'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.

Return
Boolean: true if animation is finished, false if drawing should continue on the next frame.

onPull

fun onPull(deltaDistance: Float): Boolean

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 android.view.View#invalidate() if this method returns true 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.
Return
Boolean: true if the host view should call invalidate, false if it should not.

onPull

fun onPull(deltaDistance: Float, displacement: Float): Boolean

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 android.view.View#invalidate() if this method returns true and draw the results accordingly. Views using EdgeEffect should favor EdgeEffect#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.
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.
Return
Boolean: true if the host view should call invalidate, false if it should not.

draw

fun draw(canvas: Canvas!): Boolean

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
Return
Boolean: true if drawing should continue beyond this frame to continue the animation

setSize

fun setSize(width: Int, height: Int): Unit

Set the size of this edge effect in pixels.

Parameters
width Int: Effect width in pixels
height Int: Effect height in pixels

onPull

static fun onPull(edgeEffect: EdgeEffect, deltaDistance: Float, displacement: Float): Unit

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 android.view.View#invalidate() after call this method and draw the results accordingly.

Parameters
edgeEffect EdgeEffect: The EdgeEffect that is attached to the view that is getting pulled away from an edge by the user.
deltaDistance EdgeEffect: 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 EdgeEffect: 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.

See Also

  • {@link EdgeEffect#onPull(float, float)}