diff options
Diffstat (limited to 'src/com/android/dialer/widget/ViewDragHelper.java')
-rw-r--r-- | src/com/android/dialer/widget/ViewDragHelper.java | 87 |
1 files changed, 75 insertions, 12 deletions
diff --git a/src/com/android/dialer/widget/ViewDragHelper.java b/src/com/android/dialer/widget/ViewDragHelper.java index 91016d15b..e4fe12be2 100644 --- a/src/com/android/dialer/widget/ViewDragHelper.java +++ b/src/com/android/dialer/widget/ViewDragHelper.java @@ -27,7 +27,6 @@ import android.view.VelocityTracker; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; -import android.view.animation.Interpolator; import java.util.Arrays; @@ -202,6 +201,18 @@ public class ViewDragHelper { public void onViewReleased(View releasedChild, float xvel, float yvel) {} /** + * Called when the child view has been released with a fling. + * + * <p>Calling code may decide to fling or otherwise release the view to let it + * settle into place.</p> + * + * @param releasedChild The captured child view now being released + * @param xvel X velocity of the fling. + * @param yvel Y velocity of the fling. + */ + public void onViewFling(View releasedChild, float xvel, float yvel) {} + + /** * Called when one of the subscribed edges in the parent view has been touched * by the user while no child view is currently captured. * @@ -321,16 +332,6 @@ public class ViewDragHelper { } } - /** - * Interpolator defining the animation curve for mScroller - */ - private static final Interpolator sInterpolator = new Interpolator() { - public float getInterpolation(float t) { - t -= 1.0f; - return t * t * t * t * t + 1.0f; - } - }; - private final Runnable mSetIdleRunnable = new Runnable() { public void run() { setDragState(STATE_IDLE); @@ -389,7 +390,7 @@ public class ViewDragHelper { mTouchSlop = vc.getScaledTouchSlop(); mMaxVelocity = vc.getScaledMaximumFlingVelocity(); mMinVelocity = vc.getScaledMinimumFlingVelocity(); - mScroller = ScrollerCompat.create(context, sInterpolator); + mScroller = ScrollerCompat.create(context); } /** @@ -702,6 +703,46 @@ public class ViewDragHelper { } /** + * Settle the captured view based on standard free-moving fling behavior. + * The caller should invoke {@link #continueSettling(boolean)} on each subsequent frame + * to continue the motion until it returns false. + * + * @param minLeft Minimum X position for the view's left edge + * @param minTop Minimum Y position for the view's top edge + * @param maxLeft Maximum X position for the view's left edge + * @param maxTop Maximum Y position for the view's top edge + * @param yvel the Y velocity to fling with + */ + public void flingCapturedView(int minLeft, int minTop, int maxLeft, int maxTop, int yvel) { + if (!mReleaseInProgress) { + throw new IllegalStateException("Cannot flingCapturedView outside of a call to " + + "Callback#onViewReleased"); + } + mScroller.abortAnimation(); + mScroller.fling(mCapturedView.getLeft(), mCapturedView.getTop(), 0, yvel, minLeft, maxLeft, + minTop, maxTop); + + setDragState(STATE_SETTLING); + } + + /** + * Predict how far a fling with {@param yvel} will cause the view to travel from stand still. + * @return predicted y offset + */ + public int predictFlingYOffset(int yvel) { + mScroller.abortAnimation(); + mScroller.fling(0, 0, 0, yvel, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, + Integer.MAX_VALUE); + final int finalY = mScroller.getFinalY(); + mScroller.abortAnimation(); + return finalY; + } + + public int getCurrentScrollY() { + return mScroller.getCurrY(); + } + + /** * Move the captured settling view by the appropriate amount for the current time. * If <code>continueSettling</code> returns true, the caller should call it again * on the next frame to continue. @@ -750,6 +791,28 @@ public class ViewDragHelper { return mDragState == STATE_SETTLING; } + public void processNestedFling(View target, int yvel) { + mCapturedView = target; + dispatchViewFling(0, yvel); + } + + public int getVelocityMagnitude() { + // Use Math.abs() to ensure this always returns an absolute value, even if the + // ScrollerCompat implementation changes. + return (int) Math.abs(mScroller.getCurrVelocity()); + } + + private void dispatchViewFling(float xvel, float yvel) { + mReleaseInProgress = true; + mCallback.onViewFling(mCapturedView, xvel, yvel); + mReleaseInProgress = false; + + if (mDragState == STATE_DRAGGING) { + // onViewReleased didn't call a method that would have changed this. Go idle. + setDragState(STATE_IDLE); + } + } + /** * Like all callback events this must happen on the UI thread, but release * involves some extra semantics. During a release (mReleaseInProgress) |