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

Commit 319bdc45 authored by Selim Cinek's avatar Selim Cinek
Browse files

Opimized the number of calls to updateChildren.

Improved the performance by batching multiple calls to updateChildren
to a single call on preDraw.

Change-Id: I386edeb15ac35201d39afcac8beaa48b09245448
parent f4c1996d
Loading
Loading
Loading
Loading
+21 −18
Original line number Original line Diff line number Diff line
@@ -106,13 +106,15 @@ public class NotificationStackScrollLayout extends ViewGroup
    private ExpandableView.OnHeightChangedListener mOnHeightChangedListener;
    private ExpandableView.OnHeightChangedListener mOnHeightChangedListener;
    private boolean mChildHierarchyDirty;
    private boolean mChildHierarchyDirty;
    private boolean mIsExpanded = true;
    private boolean mIsExpanded = true;
    private ViewTreeObserver.OnPreDrawListener mAfterLayoutPreDrawListener
    private boolean mChildrenNeedUpdate;
    private ViewTreeObserver.OnPreDrawListener mPreDrawListener
            = new ViewTreeObserver.OnPreDrawListener() {
            = new ViewTreeObserver.OnPreDrawListener() {
        @Override
        @Override
        public boolean onPreDraw() {
        public boolean onPreDraw() {
            updateScrollPositionIfNecessary();
            if (mChildrenNeedUpdate) {
                updateChildren();
                updateChildren();
            getViewTreeObserver().removeOnPreDrawListener(this);
                mChildrenNeedUpdate = false;
            }
            return true;
            return true;
        }
        }
    };
    };
@@ -179,6 +181,7 @@ public class NotificationStackScrollLayout extends ViewGroup
        mPaddingBetweenElements = context.getResources()
        mPaddingBetweenElements = context.getResources()
                .getDimensionPixelSize(R.dimen.notification_padding);
                .getDimensionPixelSize(R.dimen.notification_padding);
        mStackScrollAlgorithm = new StackScrollAlgorithm(context);
        mStackScrollAlgorithm = new StackScrollAlgorithm(context);
        getViewTreeObserver().addOnPreDrawListener(mPreDrawListener);
    }
    }


    @Override
    @Override
@@ -206,7 +209,8 @@ public class NotificationStackScrollLayout extends ViewGroup
        }
        }
        setMaxLayoutHeight(getHeight() - mEmptyMarginBottom);
        setMaxLayoutHeight(getHeight() - mEmptyMarginBottom);
        updateContentHeight();
        updateContentHeight();
        getViewTreeObserver().addOnPreDrawListener(mAfterLayoutPreDrawListener);
        updateScrollPositionIfNecessary();
        requestChildrenUpdate();
    }
    }


    public void setChildLocationsChangedListener(OnChildLocationsChangedListener listener) {
    public void setChildLocationsChangedListener(OnChildLocationsChangedListener listener) {
@@ -270,6 +274,11 @@ public class NotificationStackScrollLayout extends ViewGroup
        }
        }
    }
    }


    private void requestChildrenUpdate() {
        mChildrenNeedUpdate = true;
        invalidate();
    }

    private boolean isCurrentlyAnimating() {
    private boolean isCurrentlyAnimating() {
        return mStateAnimator.isRunning();
        return mStateAnimator.isRunning();
    }
    }
@@ -290,7 +299,7 @@ public class NotificationStackScrollLayout extends ViewGroup
            mTopPadding = topPadding;
            mTopPadding = topPadding;
            updateAlgorithmHeightAndPadding();
            updateAlgorithmHeightAndPadding();
            updateContentHeight();
            updateContentHeight();
            updateChildren();
            requestChildrenUpdate();
        }
        }
    }
    }


@@ -325,7 +334,7 @@ public class NotificationStackScrollLayout extends ViewGroup
        if (stackHeight != mCurrentStackHeight) {
        if (stackHeight != mCurrentStackHeight) {
            mCurrentStackHeight = stackHeight;
            mCurrentStackHeight = stackHeight;
            updateAlgorithmHeightAndPadding();
            updateAlgorithmHeightAndPadding();
            updateChildren();
            requestChildrenUpdate();
        }
        }
    }
    }


@@ -659,19 +668,13 @@ public class NotificationStackScrollLayout extends ViewGroup
        }
        }
    }
    }


    public void customScrollBy(int y) {
    private void customScrollTo(int y) {
        mOwnScrollY += y;
        updateChildren();
    }

    public void customScrollTo(int y) {
        mOwnScrollY = y;
        mOwnScrollY = y;
        updateChildren();
        updateChildren();
    }
    }


    @Override
    @Override
    protected void onOverScrolled(int scrollX, int scrollY,
    protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
                                  boolean clampedX, boolean clampedY) {
        // Treat animating scrolls differently; see #computeScroll() for why.
        // Treat animating scrolls differently; see #computeScroll() for why.
        if (!mScroller.isFinished()) {
        if (!mScroller.isFinished()) {
            final int oldX = mScrollX;
            final int oldX = mScrollX;
@@ -1115,7 +1118,7 @@ public class NotificationStackScrollLayout extends ViewGroup
            if (mOnHeightChangedListener != null) {
            if (mOnHeightChangedListener != null) {
                mOnHeightChangedListener.onHeightChanged(view);
                mOnHeightChangedListener.onHeightChanged(view);
            }
            }
            updateChildren();
            requestChildrenUpdate();
        }
        }
    }
    }


@@ -1125,7 +1128,7 @@ public class NotificationStackScrollLayout extends ViewGroup
    }
    }


    public void onChildAnimationFinished() {
    public void onChildAnimationFinished() {
        updateChildren();
        requestChildrenUpdate();
        mAnimationEvents.clear();
        mAnimationEvents.clear();
    }
    }