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

Commit 618c8f1e authored by Joe Onorato's avatar Joe Onorato Committed by Android (Google) Code Review
Browse files

Merge "Make ScrollView only do overscroll if you're grabbing the child view."

parents 27eb2414 9f0e8eea
Loading
Loading
Loading
Loading
+49 −21
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.FocusFinder;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -51,6 +52,8 @@ import java.util.List;
 * <p>ScrollView only supports vertical scrolling.
 */
public class ScrollView extends FrameLayout {
    private static final String TAG = "ScrollView";

    static final int ANIMATED_SCROLL_GAP = 250;

    static final float MAX_SCROLL_FACTOR = 0.5f;
@@ -360,6 +363,17 @@ public class ScrollView extends FrameLayout {
        return handled;
    }

    private boolean inChild(int x, int y) {
        if (getChildCount() > 0) {
            final View child = getChildAt(0);
            return !(y < child.getTop()
                    || y >= child.getBottom()
                    || x < child.getLeft()
                    || x >= child.getRight());
        }
        return false;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        /*
@@ -399,6 +413,11 @@ public class ScrollView extends FrameLayout {
                break;

            case MotionEvent.ACTION_DOWN:
                if (!inChild((int)ev.getX(), (int)y)) {
                    mIsBeingDragged = false;
                    break;
                }

                /* Remember location of down touch */
                mLastMotionY = y;

@@ -451,10 +470,16 @@ public class ScrollView extends FrameLayout {
                    mScroller.abortAnimation();
                }

                if (!inChild((int)ev.getX(), (int)y)) {
                    mIsBeingDragged = false;
                    return false;
                }

                // Remember where the motion event started
                mLastMotionY = y;
                break;
            case MotionEvent.ACTION_MOVE:
                if (mIsBeingDragged) {
                    // Scroll to follow the motion event
                    final int deltaY = (int) (mLastMotionY - y);
                    mLastMotionY = y;
@@ -462,7 +487,9 @@ public class ScrollView extends FrameLayout {
                    overscrollBy(0, deltaY, 0, mScrollY, 0, getScrollRange(),
                            0, getOverscrollMax());
                    break;
                }
            case MotionEvent.ACTION_UP:
                if (mIsBeingDragged) {
                    final VelocityTracker velocityTracker = mVelocityTracker;
                    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                    int initialVelocity = (int) velocityTracker.getYVelocity();
@@ -483,6 +510,7 @@ public class ScrollView extends FrameLayout {
                        mVelocityTracker = null;
                    }
                }
        }
        return true;
    }