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

Commit e20cd739 authored by Amin Shaikh's avatar Amin Shaikh Committed by Android (Google) Code Review
Browse files

Merge "Revert "Fix PagedTileLayout reveal animation crash.""

parents 13cb8b8d 46a48cf0
Loading
Loading
Loading
Loading
+32 −6
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
    private Scroller mScroller;

    private AnimatorSet mBounceAnimatorSet;
    private int mAnimatingToPage = -1;
    private float mLastExpansion;

    public PagedTileLayout(Context context, AttributeSet attrs) {
@@ -93,17 +94,41 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        // Suppress all touch event during reveal animation.
        if (mAnimatingToPage != -1) {
            return true;
        }
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        // Suppress all touch event during reveal animation.
        if (mAnimatingToPage != -1) {
            return true;
        }
        return super.onTouchEvent(ev);
    }

    @Override
    public void computeScroll() {
        if (!mScroller.isFinished() && mScroller.computeScrollOffset()) {
            fakeDragBy(getScrollX() - mScroller.getCurrX());
            scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
            float pageFraction = (float) getScrollX() / getWidth();
            int position = (int) pageFraction;
            float positionOffset = pageFraction - position;
            mOnPageChangeListener.onPageScrolled(position, positionOffset, getScrollX());
            // Keep on drawing until the animation has finished.
            postInvalidateOnAnimation();
            return;
        } else if (isFakeDragging()) {
            endFakeDrag();
        }
        if (mAnimatingToPage != -1) {
            setCurrentItem(mAnimatingToPage, true);
            mBounceAnimatorSet.start();
            setOffscreenPageLimit(1);
            mAnimatingToPage = -1;
        }
        super.computeScroll();
    }
@@ -262,7 +287,7 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
    }

    public void startTileReveal(Set<String> tileSpecs, final Runnable postAnimation) {
        if (tileSpecs.isEmpty() || mPages.size() < 2 || getScrollX() != 0 || !beginFakeDrag()) {
        if (tileSpecs.isEmpty() || mPages.size() < 2 || getScrollX() != 0) {
            // Do not start the reveal animation unless there are tiles to animate, multiple
            // TilePages available and the user has not already started dragging.
            return;
@@ -292,8 +317,9 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
                postAnimation.run();
            }
        });
        setOffscreenPageLimit(lastPageNumber); // Ensure the page to reveal has been inflated.
        mScroller.startScroll(getScrollX(), getScrollY(), getWidth() * lastPageNumber, 0,
        mAnimatingToPage = lastPageNumber;
        setOffscreenPageLimit(mAnimatingToPage); // Ensure the page to reveal has been inflated.
        mScroller.startScroll(getScrollX(), getScrollY(), getWidth() * mAnimatingToPage, 0,
                REVEAL_SCROLL_DURATION_MILLIS);
        postInvalidateOnAnimation();
    }