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

Commit 9d7658ac authored by George Mount's avatar George Mount Committed by Android (Google) Code Review
Browse files

Merge "Allow fling during stretch in ListView" into sc-dev

parents b8c21ea5 d317ef65
Loading
Loading
Loading
Loading
+143 −131
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ import android.view.inspector.InspectableProperty.EnumEntry;
import android.widget.RemoteViews.InteractionHandler;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;

import java.util.ArrayList;
import java.util.List;
@@ -712,20 +713,24 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
     *
     * Even though this field is practically final, we cannot make it final because there are apps
     * setting it via reflection and they need to keep working until they target Q.
     * @hide
     */
    @NonNull
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123769408)
    private EdgeEffect mEdgeGlowTop;
    @VisibleForTesting
    public EdgeEffect mEdgeGlowTop;

    /**
     * Tracks the state of the bottom edge glow.
     *
     * Even though this field is practically final, we cannot make it final because there are apps
     * setting it via reflection and they need to keep working until they target Q.
     * @hide
     */
    @NonNull
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768444)
    private EdgeEffect mEdgeGlowBottom;
    @VisibleForTesting
    public EdgeEffect mEdgeGlowBottom;

    /**
     * An estimate of how many pixels are between the top of the list and
@@ -4116,7 +4121,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                    }

                    final float x = ev.getX();
                final boolean inList = x > mListPadding.left && x < getWidth() - mListPadding.right;
                    final boolean inList =
                            x > mListPadding.left && x < getWidth() - mListPadding.right;
                    if (inList && !child.hasExplicitFocusable()) {
                        if (mPerformClick == null) {
                            mPerformClick = new PerformClick();
@@ -4129,8 +4135,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                        mResurrectToPosition = motionPosition;

                        if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                        removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ?
                                mPendingCheckForTap : mPendingCheckForLongPress);
                            removeCallbacks(mTouchMode == TOUCH_MODE_DOWN
                                    ? mPendingCheckForTap : mPendingCheckForLongPress);
                            mLayoutMode = LAYOUT_NORMAL;
                            if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                                mTouchMode = TOUCH_MODE_TAP;
@@ -4156,7 +4162,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                                        mTouchMode = TOUCH_MODE_REST;
                                        child.setPressed(false);
                                        setPressed(false);
                                    if (!mDataChanged && !mIsDetaching && isAttachedToWindow()) {
                                        if (!mDataChanged && !mIsDetaching
                                                && isAttachedToWindow()) {
                                            performClick.run();
                                        }
                                    }
@@ -4183,9 +4190,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                    final int lastChildBottom = getChildAt(childCount - 1).getBottom();
                    final int contentTop = mListPadding.top;
                    final int contentBottom = getHeight() - mListPadding.bottom;
                if (mFirstPosition == 0 && firstChildTop >= contentTop &&
                        mFirstPosition + childCount < mItemCount &&
                        lastChildBottom <= getHeight() - contentBottom) {
                    if (mFirstPosition == 0 && firstChildTop >= contentTop
                            && mFirstPosition + childCount < mItemCount
                            && lastChildBottom <= getHeight() - contentBottom) {
                        mTouchMode = TOUCH_MODE_REST;
                        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
                    } else {
@@ -4199,11 +4206,16 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                        // allow the weird behavior where you can scroll to a boundary then
                        // fling further.
                        boolean flingVelocity = Math.abs(initialVelocity) > mMinimumVelocity;
                    if (flingVelocity &&
                            !((mFirstPosition == 0 &&
                                    firstChildTop == contentTop - mOverscrollDistance) ||
                              (mFirstPosition + childCount == mItemCount &&
                                    lastChildBottom == contentBottom + mOverscrollDistance))) {
                        if (flingVelocity && !mEdgeGlowTop.isFinished()) {
                            mEdgeGlowTop.onAbsorb(initialVelocity);
                        } else if (flingVelocity && !mEdgeGlowBottom.isFinished()) {
                            mEdgeGlowBottom.onAbsorb(-initialVelocity);
                        } else if (flingVelocity
                                && !((mFirstPosition == 0
                                && firstChildTop == contentTop - mOverscrollDistance)
                                || (mFirstPosition + childCount == mItemCount
                                && lastChildBottom == contentBottom + mOverscrollDistance))
                        ) {
                            if (!dispatchNestedPreFling(0, -initialVelocity)) {
                                if (mFlingRunnable == null) {
                                    mFlingRunnable = new FlingRunnable();