-
public abstract class ViewDragHelper.Callback
A Callback is used as a communication channel with the ViewDragHelper back to theparent view using it.
on*
methods are invoked on siginficant events and severalaccessor methods are expected to provide the ViewDragHelper with more informationabout the state of the parent view upon request. The callback also makes decisionsgoverning the range and draggability of child views.
-
-
Method Summary
Modifier and Type Method Description void
onViewDragStateChanged(int state)
Called when the drag state changes. void
onViewPositionChanged(@NonNull() View changedView, int left, int top, @Px() int dx, @Px() int dy)
Called when the captured view's position changes as the result of a drag or settle. void
onViewCaptured(@NonNull() View capturedChild, int activePointerId)
Called when a child view is captured for dragging or settling. void
onViewReleased(@NonNull() View releasedChild, float xvel, float yvel)
Called when the child view is no longer being actively dragged.The fling velocity is also supplied, if relevant. void
onEdgeTouched(int edgeFlags, int pointerId)
Called when one of the subscribed edges in the parent view has been touchedby the user while no child view is currently captured. boolean
onEdgeLock(int edgeFlags)
Called when the given edge may become locked. void
onEdgeDragStarted(int edgeFlags, int pointerId)
Called when the user has started a deliberate drag away from oneof the subscribed edges in the parent view while no child view is currently captured. int
getOrderedChildIndex(int index)
Called to determine the Z-order of child views. int
getViewHorizontalDragRange(@NonNull() View child)
Return the magnitude of a draggable child view's horizontal range of motion in pixels.This method should return 0 for views that cannot move horizontally. int
getViewVerticalDragRange(@NonNull() View child)
Return the magnitude of a draggable child view's vertical range of motion in pixels.This method should return 0 for views that cannot move vertically. abstract boolean
tryCaptureView(@NonNull() View child, int pointerId)
Called when the user's input indicates that they want to capture the given child viewwith the pointer indicated by pointerId. int
clampViewPositionHorizontal(@NonNull() View child, int left, int dx)
Restrict the motion of the dragged child view along the horizontal axis.The default implementation does not allow horizontal motion; the extendingclass must override this method and provide the desired clamping. int
clampViewPositionVertical(@NonNull() View child, int top, int dy)
Restrict the motion of the dragged child view along the vertical axis.The default implementation does not allow vertical motion; the extendingclass must override this method and provide the desired clamping. -
-
Method Detail
-
onViewDragStateChanged
void onViewDragStateChanged(int state)
Called when the drag state changes. See the
STATE_*
constantsfor more information.- Parameters:
state
- The new drag state
-
onViewPositionChanged
void onViewPositionChanged(@NonNull() View changedView, int left, int top, @Px() int dx, @Px() int dy)
Called when the captured view's position changes as the result of a drag or settle.
- Parameters:
changedView
- View whose position changedleft
- New X coordinate of the left edge of the viewtop
- New Y coordinate of the top edge of the viewdx
- Change in X position from the last calldy
- Change in Y position from the last call
-
onViewCaptured
void onViewCaptured(@NonNull() View capturedChild, int activePointerId)
Called when a child view is captured for dragging or settling. The ID of the pointercurrently dragging the captured view is supplied. If activePointerId isidentified as INVALID_POINTER the capture is programmatic instead ofpointer-initiated.
- Parameters:
capturedChild
- Child view that was capturedactivePointerId
- Pointer id tracking the child capture
-
onViewReleased
void onViewReleased(@NonNull() View releasedChild, float xvel, float yvel)
Called when the child view is no longer being actively dragged.The fling velocity is also supplied, if relevant. The velocity values maybe clamped to system minimums or maximums.
Calling code may decide to fling or otherwise release the view to let itsettle into place. It should do so using settleCapturedViewAt or flingCapturedView. If the Callback invokesone of these methods, the ViewDragHelper will enter STATE_SETTLING and the view capture will not fully end until it comes to a complete stop.If neither of these methods is invoked before
onViewReleased
returns,the view will stop in place and the ViewDragHelper will return to STATE_IDLE.- Parameters:
releasedChild
- The captured child view now being releasedxvel
- X velocity of the pointer as it left the screen in pixels per second.yvel
- Y velocity of the pointer as it left the screen in pixels per second.
-
onEdgeTouched
void onEdgeTouched(int edgeFlags, int pointerId)
Called when one of the subscribed edges in the parent view has been touchedby the user while no child view is currently captured.
- Parameters:
edgeFlags
- A combination of edge flags describing the edge(s) currently touchedpointerId
- ID of the pointer touching the described edge(s)
-
onEdgeLock
boolean onEdgeLock(int edgeFlags)
Called when the given edge may become locked. This can happen if an edge dragwas preliminarily rejected before beginning, but after onEdgeTouched was called. This method should return true to lock this edge or false to leave itunlocked. The default behavior is to leave edges unlocked.
- Parameters:
edgeFlags
- A combination of edge flags describing the edge(s) locked
-
onEdgeDragStarted
void onEdgeDragStarted(int edgeFlags, int pointerId)
Called when the user has started a deliberate drag away from oneof the subscribed edges in the parent view while no child view is currently captured.
- Parameters:
edgeFlags
- A combination of edge flags describing the edge(s) draggedpointerId
- ID of the pointer touching the described edge(s)
-
getOrderedChildIndex
int getOrderedChildIndex(int index)
Called to determine the Z-order of child views.
- Parameters:
index
- the ordered position to query for
-
getViewHorizontalDragRange
int getViewHorizontalDragRange(@NonNull() View child)
Return the magnitude of a draggable child view's horizontal range of motion in pixels.This method should return 0 for views that cannot move horizontally.
- Parameters:
child
- Child view to check
-
getViewVerticalDragRange
int getViewVerticalDragRange(@NonNull() View child)
Return the magnitude of a draggable child view's vertical range of motion in pixels.This method should return 0 for views that cannot move vertically.
- Parameters:
child
- Child view to check
-
tryCaptureView
abstract boolean tryCaptureView(@NonNull() View child, int pointerId)
Called when the user's input indicates that they want to capture the given child viewwith the pointer indicated by pointerId. The callback should return true if the useris permitted to drag the given view with the indicated pointer.
ViewDragHelper may call this method multiple times for the same view even ifthe view is already captured; this indicates that a new pointer is trying to takecontrol of the view.
If this method returns true, a call to onViewCaptured will follow if the capture is successful.
- Parameters:
child
- Child the user is attempting to capturepointerId
- ID of the pointer attempting the capture
-
clampViewPositionHorizontal
int clampViewPositionHorizontal(@NonNull() View child, int left, int dx)
Restrict the motion of the dragged child view along the horizontal axis.The default implementation does not allow horizontal motion; the extendingclass must override this method and provide the desired clamping.
- Parameters:
child
- Child view being draggedleft
- Attempted motion along the X axisdx
- Proposed change in position for left
-
clampViewPositionVertical
int clampViewPositionVertical(@NonNull() View child, int top, int dy)
Restrict the motion of the dragged child view along the vertical axis.The default implementation does not allow vertical motion; the extendingclass must override this method and provide the desired clamping.
- Parameters:
child
- Child view being draggedtop
- Attempted motion along the Y axisdy
- Proposed change in position for top
-
-
-
-