Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52964243 authored by Gilles Debunne's avatar Gilles Debunne
Browse files

New OverScroller with edge bouncing effect.

OverScroller has been made a Scroller child class. Both use a physical constant deceleration
force to compute the animation. OverScroller also includes a rubber edge bounce effect.

Approved by Jim Palmer.

Change-Id: I3f43a03694b8cb6bfa0784c2663b37c9c39322cc
parent 415b46c3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5728,7 +5728,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
     * of the thumb within the scrollbar's track.</p>
     *
     * <p>The range is expressed in arbitrary units that must be the same as the
     * units used by {@link #computeHorizontalScrollRange()} and
     * units used by {@link #computeVerticalScrollRange()} and
     * {@link #computeVerticalScrollOffset()}.</p>
     *
     * <p>The default extent is the drawing height of this view.</p>
+2 −2
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ public class DecelerateInterpolator implements Interpolator {
    /**
     * Constructor
     * 
     * @param factor Degree to which the animation should be eased. Seting factor to 1.0f produces
     * @param factor Degree to which the animation should be eased. Setting factor to 1.0f produces
     *        an upside-down y=x^2 parabola. Increasing factor above 1.0f makes exaggerates the
     *        ease-out effect (i.e., it starts even faster and ends evens slower)
     */
+23 −10
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
@@ -2388,6 +2389,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
    protected void onOverscrolled(int scrollX, int scrollY,
            boolean clampedX, boolean clampedY) {
        mScrollY = scrollY;

        if (clampedY) {
            // Velocity is broken by hitting the limit; don't start a fling off of this.
            if (mVelocityTracker != null) {
@@ -2561,7 +2563,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        /**
         * Tracks the decay of a fling scroll
         */
        private OverScroller mScroller;
        private final OverScroller mScroller;

        /**
         * Y value reported by mScroller on the previous fling
@@ -2598,6 +2600,21 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te

        void startOverfling(int initialVelocity) {
            mScroller.fling(0, mScrollY, 0, initialVelocity, 0, 0, 0, 0, 0, getHeight());
            edgeReached();
            mTouchMode = TOUCH_MODE_OVERFLING;
            invalidate();
            post(this);
        }

        void edgeReached() {
            mScroller.notifyVerticalEdgeReached(mScrollY, 0, Integer.MAX_VALUE);
            mTouchMode = TOUCH_MODE_OVERFLING;
            invalidate();
            post(this);
        }

        void marginReached() {
            mScroller.notifyVerticalBoundaryReached(mScrollY, 0);
            mTouchMode = TOUCH_MODE_OVERFLING;
            invalidate();
            post(this);
@@ -2677,11 +2694,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                        overscrollBy(0, overshoot, 0, mScrollY, 0, 0,
                                0, getOverscrollMax(), false);
                    }
                    float vel = scroller.getCurrVelocity();
                    if (delta > 0) {
                        vel = -vel;
                    }
                    startOverfling(Math.round(vel));
                    edgeReached();
                    break;
                }

@@ -2738,7 +2751,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        private int mBoundPos;
        private int mLastSeenPos;
        private int mScrollDuration;
        private int mExtraScroll;
        private final int mExtraScroll;
        
        PositionScroller() {
            mExtraScroll = ViewConfiguration.get(mContext).getScaledFadingEdgeLength();
@@ -3977,7 +3990,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            for (int i = 0; i < count; i++) {
                if (activeViews[i] != null) {
                    result = false;
                    android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG,
                    Log.d(ViewDebug.CONSISTENCY_LOG_TAG,
                            "AbsListView " + this + " has a view in its active recycler: " +
                                    activeViews[i]);
                }
@@ -4005,12 +4018,12 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            final View view = scrap.get(i);
            if (view.getParent() != null) {
                result = false;
                android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, "AbsListView " + this +
                Log.d(ViewDebug.CONSISTENCY_LOG_TAG, "AbsListView " + this +
                        " has a view in its scrap heap still attached to a parent: " + view);
            }
            if (indexOfChild(view) >= 0) {
                result = false;
                android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, "AbsListView " + this +
                Log.d(ViewDebug.CONSISTENCY_LOG_TAG, "AbsListView " + this +
                        " has a view in its scrap heap that is also a direct child: " + view);
            }
        }
+248 −372

File changed.

Preview size limit exceeded, changes collapsed.

+2 −1
Original line number Diff line number Diff line
@@ -1272,7 +1272,7 @@ public class ScrollView extends FrameLayout {
     * Fling the scroll view
     *
     * @param velocityY The initial velocity in the Y direction. Positive
     *                  numbers mean that the finger/curor is moving down the screen,
     *                  numbers mean that the finger/cursor is moving down the screen,
     *                  which means we want to scroll towards the top.
     */
    public void fling(int velocityY) {
@@ -1307,6 +1307,7 @@ public class ScrollView extends FrameLayout {
     *
     * <p>This version also clamps the scrolling to the bounds of our child.
     */
    @Override
    public void scrollTo(int x, int y) {
        // we rely on the fact the View.scrollBy calls scrollTo.
        if (getChildCount() > 0) {
Loading