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

Commit 23f31a1c authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Only activate FastScroller when it's needed" into klp-dev

parents 5b068bbb b9f2722f
Loading
Loading
Loading
Loading
+12 −4
Original line number Original line Diff line number Diff line
@@ -1250,7 +1250,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            mFastScroller.setEnabled(true);
            mFastScroller.setEnabled(true);
        }
        }


        recomputePadding();
        resolvePadding();


        if (mFastScroller != null) {
        if (mFastScroller != null) {
            mFastScroller.updateLayout();
            mFastScroller.updateLayout();
@@ -1312,7 +1312,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
     * @see #setFastScrollAlwaysVisible(boolean)
     * @see #setFastScrollAlwaysVisible(boolean)
     */
     */
    public boolean isFastScrollAlwaysVisible() {
    public boolean isFastScrollAlwaysVisible() {
        if (mFastScroller == null) {
            return mFastScrollEnabled && mFastScrollAlwaysVisible;
            return mFastScrollEnabled && mFastScrollAlwaysVisible;
        } else {
            return mFastScroller.isEnabled() && mFastScroller.isAlwaysShowEnabled();
        }
    }
    }


    @Override
    @Override
@@ -1331,7 +1335,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
     */
     */
    @ViewDebug.ExportedProperty
    @ViewDebug.ExportedProperty
    public boolean isFastScrollEnabled() {
    public boolean isFastScrollEnabled() {
        if (mFastScroller == null) {
            return mFastScrollEnabled;
            return mFastScrollEnabled;
        } else {
            return mFastScroller.isEnabled();
        }
    }
    }


    @Override
    @Override
@@ -1356,7 +1364,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
     */
     */
    @Override
    @Override
    protected boolean isVerticalScrollBarHidden() {
    protected boolean isVerticalScrollBarHidden() {
        return mFastScrollEnabled;
        return isFastScrollEnabled();
    }
    }


    /**
    /**
+51 −44
Original line number Original line Diff line number Diff line
@@ -152,9 +152,6 @@ class FastScroller {
    /** The number of headers at the top of the view. */
    /** The number of headers at the top of the view. */
    private int mHeaderCount;
    private int mHeaderCount;


    /** The number of items in the list. */
    private int mItemCount = -1;

    /** The index of the current section. */
    /** The index of the current section. */
    private int mCurrentSection = -1;
    private int mCurrentSection = -1;


@@ -324,6 +321,7 @@ class FastScroller {


        getSectionsFromIndexer();
        getSectionsFromIndexer();
        refreshDrawablePressedState();
        refreshDrawablePressedState();
        updateLongList(listView.getChildCount(), listView.getCount());
        setScrollbarPosition(mList.getVerticalScrollbarPosition());
        setScrollbarPosition(mList.getVerticalScrollbarPosition());
        postAutoHide();
        postAutoHide();
    }
    }
@@ -343,14 +341,10 @@ class FastScroller {
     * @param enabled Whether the fast scroll thumb is enabled.
     * @param enabled Whether the fast scroll thumb is enabled.
     */
     */
    public void setEnabled(boolean enabled) {
    public void setEnabled(boolean enabled) {
        if (mEnabled != enabled) {
            mEnabled = enabled;
            mEnabled = enabled;


        if (enabled) {
            onStateDependencyChanged();
            if (mAlwaysShow) {
                setState(STATE_VISIBLE);
            }
        } else {
            stop();
        }
        }
    }
    }


@@ -358,19 +352,17 @@ class FastScroller {
     * @return Whether the fast scroll thumb is enabled.
     * @return Whether the fast scroll thumb is enabled.
     */
     */
    public boolean isEnabled() {
    public boolean isEnabled() {
        return mEnabled;
        return mEnabled && (mLongList || mAlwaysShow);
    }
    }


    /**
    /**
     * @param alwaysShow Whether the fast scroll thumb should always be shown
     * @param alwaysShow Whether the fast scroll thumb should always be shown
     */
     */
    public void setAlwaysShow(boolean alwaysShow) {
    public void setAlwaysShow(boolean alwaysShow) {
        if (mAlwaysShow != alwaysShow) {
            mAlwaysShow = alwaysShow;
            mAlwaysShow = alwaysShow;


        if (alwaysShow) {
            onStateDependencyChanged();
            setState(STATE_VISIBLE);
        } else if (mState == STATE_VISIBLE) {
            postAutoHide();
        }
        }
    }
    }


@@ -382,6 +374,23 @@ class FastScroller {
        return mAlwaysShow;
        return mAlwaysShow;
    }
    }


    /**
     * Called when one of the variables affecting enabled state changes.
     */
    private void onStateDependencyChanged() {
        if (isEnabled()) {
            if (isAlwaysShowEnabled()) {
                setState(STATE_VISIBLE);
            } else if (mState == STATE_VISIBLE) {
                postAutoHide();
            }
        } else {
            stop();
        }

        mList.resolvePadding();
    }

    public void setScrollBarStyle(int style) {
    public void setScrollBarStyle(int style) {
        if (mScrollBarStyle != style) {
        if (mScrollBarStyle != style) {
            mScrollBarStyle = style;
            mScrollBarStyle = style;
@@ -439,6 +448,18 @@ class FastScroller {
            final int firstVisibleItem = mList.getFirstVisiblePosition();
            final int firstVisibleItem = mList.getFirstVisiblePosition();
            setThumbPos(getPosFromItemCount(firstVisibleItem, visibleItemCount, totalItemCount));
            setThumbPos(getPosFromItemCount(firstVisibleItem, visibleItemCount, totalItemCount));
        }
        }

        updateLongList(visibleItemCount, totalItemCount);
    }

    private void updateLongList(int visibleItemCount, int totalItemCount) {
        final boolean longList = visibleItemCount > 0
                && totalItemCount / visibleItemCount >= MIN_PAGES;
        if (mLongList != longList) {
            mLongList = longList;

            onStateDependencyChanged();
        }
    }
    }


    /**
    /**
@@ -795,19 +816,8 @@ class FastScroller {
        mList.postDelayed(mDeferHide, FADE_TIMEOUT);
        mList.postDelayed(mDeferHide, FADE_TIMEOUT);
    }
    }


    private boolean isLongList(int visibleItemCount, int totalItemCount) {
        // Are there enough pages to require fast scroll? Recompute only if
        // total count changes.
        if (mItemCount != totalItemCount && visibleItemCount > 0) {
            mItemCount = totalItemCount;
            mLongList = mItemCount / visibleItemCount >= MIN_PAGES;
        }

        return mLongList;
    }

    public void onScroll(int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    public void onScroll(int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        if (!mEnabled || !mAlwaysShow && !isLongList(visibleItemCount, totalItemCount)) {
        if (!isEnabled()) {
            setState(STATE_NONE);
            setState(STATE_NONE);
            return;
            return;
        }
        }
@@ -1221,7 +1231,7 @@ class FastScroller {
    }
    }


    public boolean onInterceptTouchEvent(MotionEvent ev) {
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (!mEnabled) {
        if (!isEnabled()) {
            return false;
            return false;
        }
        }


@@ -1233,14 +1243,18 @@ class FastScroller {
                    // need to allow the parent time to decide whether it wants
                    // need to allow the parent time to decide whether it wants
                    // to intercept events. If it does, we will receive a CANCEL
                    // to intercept events. If it does, we will receive a CANCEL
                    // event.
                    // event.
                    if (mList.isInScrollingContainer()) {
                    if (!mList.isInScrollingContainer()) {
                        beginDrag();
                        return true;
                    }

                    mInitialTouchY = ev.getY();
                    mInitialTouchY = ev.getY();
                    startPendingDrag();
                    startPendingDrag();
                        return false;
                }
                }

                break;
                    beginDrag();
            case MotionEvent.ACTION_MOVE:
                    return true;
                if (!isPointInside(ev.getX(), ev.getY())) {
                    cancelPendingDrag();
                }
                }
                break;
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_UP:
@@ -1253,7 +1267,7 @@ class FastScroller {
    }
    }


    public boolean onInterceptHoverEvent(MotionEvent ev) {
    public boolean onInterceptHoverEvent(MotionEvent ev) {
        if (!mEnabled) {
        if (!isEnabled()) {
            return false;
            return false;
        }
        }


@@ -1269,18 +1283,11 @@ class FastScroller {
    }
    }


    public boolean onTouchEvent(MotionEvent me) {
    public boolean onTouchEvent(MotionEvent me) {
        if (!mEnabled) {
        if (!isEnabled()) {
            return false;
            return false;
        }
        }


        switch (me.getActionMasked()) {
        switch (me.getActionMasked()) {
            case MotionEvent.ACTION_DOWN: {
                if (isPointInside(me.getX(), me.getY())) {
                    beginDrag();
                    return true;
                }
            } break;

            case MotionEvent.ACTION_UP: {
            case MotionEvent.ACTION_UP: {
                if (mHasPendingDrag) {
                if (mHasPendingDrag) {
                    // Allow a tap to scroll.
                    // Allow a tap to scroll.