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

Commit e21f89c8 authored by Adam Powell's avatar Adam Powell Committed by Android (Google) Code Review
Browse files

Merge "Fix bug 5159596 - Slider grabs touch point when trying to scroll a list"

parents b3faa42f 1029866a
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -6249,15 +6249,7 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
                    }
                    // Walk up the hierarchy to determine if we're inside a scrolling container.
                    boolean isInScrollingContainer = false;
                    ViewParent p = getParent();
                    while (p != null && p instanceof ViewGroup) {
                        if (((ViewGroup) p).shouldDelayChildPressedState()) {
                            isInScrollingContainer = true;
                            break;
                        }
                        p = p.getParent();
                    }
                    boolean isInScrollingContainer = isInScrollingContainer();
                    // For views inside a scrolling container, delay the pressed feedback for
                    // a short period in case this is a scroll.
@@ -6306,6 +6298,20 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
        return false;
    }
    /**
     * @hide
     */
    public boolean isInScrollingContainer() {
        ViewParent p = getParent();
        while (p != null && p instanceof ViewGroup) {
            if (((ViewGroup) p).shouldDelayChildPressedState()) {
                return true;
            }
            p = p.getParent();
        }
        return false;
    }
    /**
     * Remove the longpress detection timer.
     */
+43 −10
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.ViewConfiguration;

public abstract class AbsSeekBar extends ProgressBar {
    private Drawable mThumb;
@@ -49,6 +50,10 @@ public abstract class AbsSeekBar extends ProgressBar {
    private static final int NO_ALPHA = 0xFF;
    private float mDisabledAlpha;
    
    private int mScaledTouchSlop;
    private float mTouchDownX;
    private boolean mIsDragging;

    public AbsSeekBar(Context context) {
        super(context);
    }
@@ -74,6 +79,8 @@ public abstract class AbsSeekBar extends ProgressBar {
                com.android.internal.R.styleable.Theme, 0, 0);
        mDisabledAlpha = a.getFloat(com.android.internal.R.styleable.Theme_disabledAlpha, 0.5f);
        a.recycle();

        mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    /**
@@ -324,20 +331,42 @@ public abstract class AbsSeekBar extends ProgressBar {
        
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (isInScrollingContainer()) {
                    mTouchDownX = event.getX();
                } else {
                    setPressed(true);
                    onStartTrackingTouch();
                    trackTouchEvent(event);
                    attemptClaimDrag();
                }
                break;
                
            case MotionEvent.ACTION_MOVE:
                if (mIsDragging) {
                    trackTouchEvent(event);
                } else {
                    final float x = event.getX();
                    if (Math.abs(x - mTouchDownX) > mScaledTouchSlop) {
                        setPressed(true);
                        onStartTrackingTouch();
                        trackTouchEvent(event);
                        attemptClaimDrag();
                    }
                }
                break;
                
            case MotionEvent.ACTION_UP:
                if (mIsDragging) {
                    trackTouchEvent(event);
                    onStopTrackingTouch();
                    setPressed(false);
                } else {
                    // Touch up when we never crossed the touch slop threshold should
                    // be interpreted as a tap-seek to that location.
                    onStartTrackingTouch();
                    trackTouchEvent(event);
                    onStopTrackingTouch();
                }
                // ProgressBar doesn't know to repaint the thumb drawable
                // in its inactive state when the touch stops (because the
                // value has not apparently changed)
@@ -345,8 +374,10 @@ public abstract class AbsSeekBar extends ProgressBar {
                break;
                
            case MotionEvent.ACTION_CANCEL:
                if (mIsDragging) {
                    onStopTrackingTouch();
                    setPressed(false);
                }
                invalidate(); // see above explanation
                break;
        }
@@ -388,6 +419,7 @@ public abstract class AbsSeekBar extends ProgressBar {
     * This is called when the user has started touching this widget.
     */
    void onStartTrackingTouch() {
        mIsDragging = true;
    }

    /**
@@ -395,6 +427,7 @@ public abstract class AbsSeekBar extends ProgressBar {
     * canceled.
     */
    void onStopTrackingTouch() {
        mIsDragging = false;
    }

    /**
+2 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ public class SeekBar extends AbsSeekBar {
    
    @Override
    void onStartTrackingTouch() {
        super.onStartTrackingTouch();
        if (mOnSeekBarChangeListener != null) {
            mOnSeekBarChangeListener.onStartTrackingTouch(this);
        }
@@ -111,6 +112,7 @@ public class SeekBar extends AbsSeekBar {
    
    @Override
    void onStopTrackingTouch() {
        super.onStopTrackingTouch();
        if (mOnSeekBarChangeListener != null) {
            mOnSeekBarChangeListener.onStopTrackingTouch(this);
        }