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

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

Merge "Improve ListView smooth scrolling timing"

parents 213fc950 234a5715
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -16,11 +16,12 @@

package android.widget;

import com.android.internal.R;

import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
@@ -56,8 +57,6 @@ import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputConnectionWrapper;
import android.view.inputmethod.InputMethodManager;

import com.android.internal.R;

import java.util.ArrayList;
import java.util.List;

@@ -3074,8 +3073,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te

            // Estimate how many screens we should travel
            final float screenTravelCount = (float) viewTravelCount / childCount;
            mScrollDuration = (int) (SCROLL_DURATION / screenTravelCount);
            mScrollDuration = screenTravelCount < 1 ? (int) (screenTravelCount * SCROLL_DURATION) :
                    (int) (SCROLL_DURATION / screenTravelCount);
            mLastSeenPos = INVALID_POSITION;

            post(this);
        }

@@ -3213,9 +3214,15 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            }

            case MOVE_OFFSET: {
                final int childCount = getChildCount();
                if (mLastSeenPos == firstPos) {
                    // No new views, let things keep going.
                    post(this);
                    return;
                }

                mLastSeenPos = firstPos;

                final int childCount = getChildCount();
                final int position = mTargetPos;
                final int lastPos = firstPos + childCount - 1;

@@ -3228,7 +3235,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                } else {
                    // On-screen, just scroll.
                    final int targetTop = getChildAt(position - firstPos).getTop();
                    smoothScrollBy(targetTop - mOffsetFromTop, mScrollDuration);
                    final int distance = targetTop - mOffsetFromTop;
                    smoothScrollBy(distance,
                            (int) (mScrollDuration * ((float) distance / getHeight())));
                }
                break;
            }