public abstract class

ViewDragHelper.Callback

extends java.lang.Object

 java.lang.Object

↳androidx.customview.widget.ViewDragHelper.Callback

Overview

A Callback is used as a communication channel with the ViewDragHelper back to the parent view using it. on*methods are invoked on siginficant events and several accessor methods are expected to provide the ViewDragHelper with more information about the state of the parent view upon request. The callback also makes decisions governing the range and draggability of child views.

Summary

Constructors
publicCallback()

Methods
public intclampViewPositionHorizontal(View child, int left, int dx)

Restrict the motion of the dragged child view along the horizontal axis.

public intclampViewPositionVertical(View child, int top, int dy)

Restrict the motion of the dragged child view along the vertical axis.

public intgetOrderedChildIndex(int index)

Called to determine the Z-order of child views.

public intgetViewHorizontalDragRange(View child)

Return the magnitude of a draggable child view's horizontal range of motion in pixels.

public intgetViewVerticalDragRange(View child)

Return the magnitude of a draggable child view's vertical range of motion in pixels.

public voidonEdgeDragStarted(int edgeFlags, int pointerId)

Called when the user has started a deliberate drag away from one of the subscribed edges in the parent view while no child view is currently captured.

public booleanonEdgeLock(int edgeFlags)

Called when the given edge may become locked.

public voidonEdgeTouched(int edgeFlags, int pointerId)

Called when one of the subscribed edges in the parent view has been touched by the user while no child view is currently captured.

public voidonViewCaptured(View capturedChild, int activePointerId)

Called when a child view is captured for dragging or settling.

public voidonViewDragStateChanged(int state)

Called when the drag state changes.

public voidonViewPositionChanged(View changedView, int left, int top, int dx, int dy)

Called when the captured view's position changes as the result of a drag or settle.

public voidonViewReleased(View releasedChild, float xvel, float yvel)

Called when the child view is no longer being actively dragged.

public abstract booleantryCaptureView(View child, int pointerId)

Called when the user's input indicates that they want to capture the given child view with the pointer indicated by pointerId.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Callback()

Methods

public void onViewDragStateChanged(int state)

Called when the drag state changes. See the STATE_* constants for more information.

Parameters:

state: The new drag state

See also: ViewDragHelper.STATE_IDLE, ViewDragHelper.STATE_DRAGGING, ViewDragHelper.STATE_SETTLING

public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy)

Called when the captured view's position changes as the result of a drag or settle.

Parameters:

changedView: View whose position changed
left: New X coordinate of the left edge of the view
top: New Y coordinate of the top edge of the view
dx: Change in X position from the last call
dy: Change in Y position from the last call

public void onViewCaptured(View capturedChild, int activePointerId)

Called when a child view is captured for dragging or settling. The ID of the pointer currently dragging the captured view is supplied. If activePointerId is identified as ViewDragHelper.INVALID_POINTER the capture is programmatic instead of pointer-initiated.

Parameters:

capturedChild: Child view that was captured
activePointerId: Pointer id tracking the child capture

public void onViewReleased(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 may be clamped to system minimums or maximums.

Calling code may decide to fling or otherwise release the view to let it settle into place. It should do so using ViewDragHelper.settleCapturedViewAt(int, int) or ViewDragHelper.flingCapturedView(int, int, int, int). If the Callback invokes one of these methods, the ViewDragHelper will enter ViewDragHelper.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 ViewDragHelper.STATE_IDLE.

Parameters:

releasedChild: The captured child view now being released
xvel: 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.

public void onEdgeTouched(int edgeFlags, int pointerId)

Called when one of the subscribed edges in the parent view has been touched by the user while no child view is currently captured.

Parameters:

edgeFlags: A combination of edge flags describing the edge(s) currently touched
pointerId: ID of the pointer touching the described edge(s)

See also: ViewDragHelper.EDGE_LEFT, ViewDragHelper.EDGE_TOP, ViewDragHelper.EDGE_RIGHT, ViewDragHelper.EDGE_BOTTOM

public boolean onEdgeLock(int edgeFlags)

Called when the given edge may become locked. This can happen if an edge drag was preliminarily rejected before beginning, but after ViewDragHelper.Callback.onEdgeTouched(int, int) was called. This method should return true to lock this edge or false to leave it unlocked. The default behavior is to leave edges unlocked.

Parameters:

edgeFlags: A combination of edge flags describing the edge(s) locked

Returns:

true to lock the edge, false to leave it unlocked

public void onEdgeDragStarted(int edgeFlags, int pointerId)

Called when the user has started a deliberate drag away from one of 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) dragged
pointerId: ID of the pointer touching the described edge(s)

See also: ViewDragHelper.EDGE_LEFT, ViewDragHelper.EDGE_TOP, ViewDragHelper.EDGE_RIGHT, ViewDragHelper.EDGE_BOTTOM

public int getOrderedChildIndex(int index)

Called to determine the Z-order of child views.

Parameters:

index: the ordered position to query for

Returns:

index of the view that should be ordered at position index

public int getViewHorizontalDragRange(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

Returns:

range of horizontal motion in pixels

public int getViewVerticalDragRange(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

Returns:

range of vertical motion in pixels

public abstract boolean tryCaptureView(View child, int pointerId)

Called when the user's input indicates that they want to capture the given child view with the pointer indicated by pointerId. The callback should return true if the user is permitted to drag the given view with the indicated pointer.

ViewDragHelper may call this method multiple times for the same view even if the view is already captured; this indicates that a new pointer is trying to take control of the view.

If this method returns true, a call to ViewDragHelper.Callback will follow if the capture is successful.

Parameters:

child: Child the user is attempting to capture
pointerId: ID of the pointer attempting the capture

Returns:

true if capture should be allowed, false otherwise

public int clampViewPositionHorizontal(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 extending class must override this method and provide the desired clamping.

Parameters:

child: Child view being dragged
left: Attempted motion along the X axis
dx: Proposed change in position for left

Returns:

The new clamped position for left

public int clampViewPositionVertical(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 extending class must override this method and provide the desired clamping.

Parameters:

child: Child view being dragged
top: Attempted motion along the Y axis
dy: Proposed change in position for top

Returns:

The new clamped position for top