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

Commit e0a799a2 authored by Patrick Dubroy's avatar Patrick Dubroy
Browse files

Only delay pressed feedback for Views inside a scrolling parent

Add a method on ViewGroup to determine whether it supports scrolling.
This allows us to show the pressed feedback immediately in many cases,
improving responsiveness of buttons, etc.

This patch also lengthens the timeout in order to reduce flashes
when the user is scrolling.

Change-Id: Ieb91ae7a1f8e8f7e87448f2a730381a53947996f
parent a0449f03
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21724,6 +21724,7 @@ package android.view {
    method public void setOnHierarchyChangeListener(android.view.ViewGroup.OnHierarchyChangeListener);
    method public void setPersistentDrawingCache(int);
    method protected void setStaticTransformationsEnabled(boolean);
    method public boolean shouldDelayChildPressedState();
    method public boolean showContextMenuForChild(android.view.View);
    method public android.view.ActionMode startActionModeForChild(android.view.View, android.view.ActionMode.Callback);
    method public void startLayoutAnimation();
+37 −18
Original line number Diff line number Diff line
@@ -5138,9 +5138,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
                        (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) &&
                        (event.getRepeatCount() == 0)) {
                    setPressed(true);
                    if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) {
                        postCheckForLongClick(0);
                    }
                    checkForLongClick(0);
                    return true;
                }
                break;
@@ -5535,12 +5533,33 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
                    break;

                case MotionEvent.ACTION_DOWN:
                    mHasPerformedLongPress = false;

                    // 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();
                    }

                    // For views inside a scrolling container, delay the pressed feedback for
                    // a short period in case this is a scroll.
                    if (isInScrollingContainer) {
                        mPrivateFlags |= PREPRESSED;
                        if (mPendingCheckForTap == null) {
                            mPendingCheckForTap = new CheckForTap();
                        }
                    mPrivateFlags |= PREPRESSED;
                    mHasPerformedLongPress = false;
                        postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
                    } else {
                        // Not inside a scrolling container, so show the feedback right away
                        mPrivateFlags |= PRESSED;
                        refreshDrawableState();
                        checkForLongClick(0);
                    }
                    break;

                case MotionEvent.ACTION_CANCEL:
@@ -11846,7 +11865,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
        }
    }

    private void postCheckForLongClick(int delayOffset) {
    private void checkForLongClick(int delayOffset) {
        if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) {
            mHasPerformedLongPress = false;

            if (mPendingCheckForLongPress == null) {
@@ -11856,6 +11876,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
            postDelayed(mPendingCheckForLongPress,
                    ViewConfiguration.getLongPressTimeout() - delayOffset);
        }
    }

    /**
     * Inflate a view from an XML resource.  This convenience method wraps the {@link
@@ -12166,9 +12187,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
            mPrivateFlags &= ~PREPRESSED;
            mPrivateFlags |= PRESSED;
            refreshDrawableState();
            if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) {
                postCheckForLongClick(ViewConfiguration.getTapTimeout());
            }
            checkForLongClick(ViewConfiguration.getTapTimeout());
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ public class ViewConfiguration {
     * is a tap or a scroll. If the user does not move within this interval, it is
     * considered to be a tap. 
     */
    private static final int TAP_TIMEOUT = 115;
    private static final int TAP_TIMEOUT = 180;
    
    /**
     * Defines the duration in milliseconds we will wait to see if a touch event 
+13 −0
Original line number Diff line number Diff line
@@ -4972,6 +4972,19 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        mAnimationListener = animationListener;
    }

    /**
     * Return true if the pressed state should be delayed for children or descendants of this
     * ViewGroup. Generally, this should be done for containers that can scroll, such as a List.
     * This prevents the pressed state from appearing when the user is actually trying to scroll
     * the content.
     *
     * The default implementation returns true for compatibility reasons. Subclasses that do
     * not scroll should generally override this method and return false.
     */
    public boolean shouldDelayChildPressedState() {
        return true;
    }

    /**
     * LayoutParams are used by views to tell their parents how they want to be
     * laid out. See
+5 −0
Original line number Diff line number Diff line
@@ -1193,6 +1193,11 @@ public class WebView extends AbsoluteLayout
        mHTML5VideoViewProxy = null ;
    }

    @Override
    public boolean shouldDelayChildPressedState() {
        return true;
    }

    /**
     * Adds accessibility APIs to JavaScript.
     *
Loading