public class SwipeHelper
extends java.lang.Object
SwipeConsumer to consume the motion event| 限定符和类型 | 字段和说明 |
|---|---|
static int |
INVALID_POINTER
A null/invalid pointer ID.
|
static int |
POINTER_NESTED_FLY |
static int |
POINTER_NESTED_SCROLL |
static int |
STATE_DRAGGING
A view is currently being dragged.
|
static int |
STATE_IDLE
A view is not currently being dragged or animating as a result of a fling/snap.
|
static int |
STATE_NONE_TOUCH |
static int |
STATE_SETTLING
A view is currently settling into place as a result of a fling or
predefined non-interactive motion.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
abort()
cancel(), but also abort all motion in progress and snap to the end of any
animation. |
void |
cancel()
The result of a call to this method is equivalent to
processTouchEvent(android.view.MotionEvent) receiving an ACTION_CANCEL event. |
boolean |
continueSettling() |
static SwipeHelper |
create(android.view.ViewGroup forParent,
float sensitivity,
SwipeConsumer cb) |
static SwipeHelper |
create(android.view.ViewGroup forParent,
float sensitivity,
SwipeConsumer consumer,
android.view.animation.Interpolator interpolator)
Factory method to create a new SwipeHelper.
|
static SwipeHelper |
create(android.view.ViewGroup forParent,
SwipeConsumer consumer) |
static SwipeHelper |
create(android.view.ViewGroup forParent,
SwipeConsumer consumer,
android.view.animation.Interpolator interpolator)
Factory method to create a new SwipeHelper.
|
void |
dispatchViewReleased(float xvel,
float yvel)
Like all callback events this must happen on the UI thread, but release
involves some extra semantics.
|
int |
getActivePointerId() |
int |
getDragState()
Retrieve the current drag state of this helper.
|
int |
getMaxSettleDuration() |
float |
getMinVelocity()
Return the currently configured minimum velocity.
|
SwipeConsumer |
getSwipeConsumer() |
int |
getTouchSlop() |
boolean |
isPointerDown(int pointerId)
Check if the given pointer ID represents a pointer that is currently down (to the best
of the SwipeHelper's knowledge).
|
boolean |
nestedScrollingDrag(int dx,
int dy,
int[] consumed,
boolean fly) |
void |
nestedScrollingRelease() |
boolean |
nestedScrollingTrySwipe(int dx,
int dy,
boolean fly) |
void |
processTouchEvent(android.view.MotionEvent ev)
Process a touch event received by the parent view.
|
void |
setInterpolator(android.content.Context context,
android.view.animation.Interpolator interpolator) |
void |
setMaxSettleDuration(int maxSettleDuration) |
SwipeHelper |
setMinVelocity(float minVel)
Set the minimum velocity that will be detected as having a magnitude greater than zero
in pixels per second.
|
void |
setSensitivity(float sensitivity) |
boolean |
settleCapturedViewAt(int finalX,
int finalY)
Settle the captured view at the given (left, top) position.
|
boolean |
shouldInterceptTouchEvent(android.view.MotionEvent ev)
Check if this event as provided to the parent view's onInterceptTouchEvent should
cause the parent to intercept the touch event stream.
|
boolean |
smoothSlideTo(int finalX,
int finalY) |
boolean |
smoothSlideTo(int startX,
int startY,
int finalX,
int finalY)
Animate the view
child to the given (left, top) position. |
public static final int INVALID_POINTER
public static final int POINTER_NESTED_SCROLL
public static final int POINTER_NESTED_FLY
public static final int STATE_IDLE
public static final int STATE_DRAGGING
public static final int STATE_SETTLING
public static final int STATE_NONE_TOUCH
public static SwipeHelper create(android.view.ViewGroup forParent, SwipeConsumer consumer, android.view.animation.Interpolator interpolator)
forParent - Parent view to monitorconsumer - Callback to provide information and receive eventsinterpolator - interpolator for animationpublic static SwipeHelper create(android.view.ViewGroup forParent, SwipeConsumer consumer)
public static SwipeHelper create(android.view.ViewGroup forParent, float sensitivity, SwipeConsumer consumer, android.view.animation.Interpolator interpolator)
forParent - Parent view to monitorsensitivity - Multiplier for how sensitive the helper should be about detecting
the start of a drag. Larger values are more sensitive. 1.0f is normal.consumer - Callback to provide information and receive eventsinterpolator - interpolator for animationpublic static SwipeHelper create(android.view.ViewGroup forParent, float sensitivity, SwipeConsumer cb)
public void setSensitivity(float sensitivity)
public void setInterpolator(android.content.Context context,
android.view.animation.Interpolator interpolator)
public SwipeHelper setMinVelocity(float minVel)
minVel - Minimum velocity to detectpublic float getMinVelocity()
public int getDragState()
STATE_IDLE, STATE_DRAGGING or STATE_SETTLING or STATE_NONE_TOUCH.public int getActivePointerId()
INVALID_POINTER.public int getTouchSlop()
public void cancel()
processTouchEvent(android.view.MotionEvent) receiving an ACTION_CANCEL event.public void abort()
cancel(), but also abort all motion in progress and snap to the end of any
animation.public boolean smoothSlideTo(int startX,
int startY,
int finalX,
int finalY)
child to the given (left, top) position.
If this method returns true, the caller should invoke continueSettling()
on each subsequent frame to continue the motion until it returns false. If this method
returns false there is no further work to do to complete the movement.startX - start x positionstartY - start y positionfinalX - Final x positionfinalY - Final y positioncontinueSettling() callspublic boolean smoothSlideTo(int finalX,
int finalY)
public boolean settleCapturedViewAt(int finalX,
int finalY)
continueSettling()
on each subsequent frame to continue the motion until it returns false. If this method
returns false there is no further work to do to complete the movement.finalX - Settled left edge position for the captured viewfinalY - Settled top edge position for the captured viewcontinueSettling() callspublic boolean continueSettling()
public void dispatchViewReleased(float xvel,
float yvel)
settleCapturedViewAt(int, int)xvel - x velocityyvel - y velocitypublic boolean isPointerDown(int pointerId)
The state used to report this information is populated by the methods
shouldInterceptTouchEvent(android.view.MotionEvent) or
processTouchEvent(android.view.MotionEvent). If one of these methods has not
been called for all relevant MotionEvents to track, the information reported
by this method may be stale or incorrect.
pointerId - pointer ID to check; corresponds to IDs provided by MotionEventpublic boolean shouldInterceptTouchEvent(android.view.MotionEvent ev)
ev - MotionEvent provided to onInterceptTouchEventpublic void processTouchEvent(android.view.MotionEvent ev)
ev - The touch event received by the parent viewpublic boolean nestedScrollingTrySwipe(int dx,
int dy,
boolean fly)
public boolean nestedScrollingDrag(int dx,
int dy,
int[] consumed,
boolean fly)
public void nestedScrollingRelease()
public SwipeConsumer getSwipeConsumer()
public int getMaxSettleDuration()
public void setMaxSettleDuration(int maxSettleDuration)