diff options
author | 2018-07-31 10:44:11 -0400 | |
---|---|---|
committer | 2018-07-31 10:44:11 -0400 | |
commit | b3ed28c84d5572e585c9339ef311c772c62afe2f (patch) | |
tree | c2e7f0be6c8c6cffd9e2b743f7dc26f53e392821 | |
parent | 15640720bf8640bbb4d2c831b28e5a4e0789999e (diff) |
Fix PagedTileLayout reveal animation crash.
Use ViewPager's fake dragging API instead of manually changing scroll
positions to ensure proper touch handling during the drag animation.
Change-Id: Ie006262bd01f723a282be209ec8639953d3d84a0
Fixes: 111845732
Test: manual
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java | 38 |
1 files changed, 6 insertions, 32 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java index f13f4899baed..91f1d3dcab4a 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java +++ b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java @@ -55,7 +55,6 @@ 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) { @@ -95,40 +94,16 @@ 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()) { - scrollTo(mScroller.getCurrX(), mScroller.getCurrY()); - float pageFraction = (float) getScrollX() / getWidth(); - int position = (int) pageFraction; - float positionOffset = pageFraction - position; - mOnPageChangeListener.onPageScrolled(position, positionOffset, getScrollX()); + fakeDragBy(getScrollX() - mScroller.getCurrX()); // Keep on drawing until the animation has finished. postInvalidateOnAnimation(); return; - } - if (mAnimatingToPage != -1) { - setCurrentItem(mAnimatingToPage, true); + } else if (isFakeDragging()) { + endFakeDrag(); mBounceAnimatorSet.start(); setOffscreenPageLimit(1); - mAnimatingToPage = -1; } super.computeScroll(); } @@ -287,7 +262,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) { + if (tileSpecs.isEmpty() || mPages.size() < 2 || getScrollX() != 0 || !beginFakeDrag()) { // Do not start the reveal animation unless there are tiles to animate, multiple // TilePages available and the user has not already started dragging. return; @@ -317,9 +292,8 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout { postAnimation.run(); } }); - mAnimatingToPage = lastPageNumber; - setOffscreenPageLimit(mAnimatingToPage); // Ensure the page to reveal has been inflated. - mScroller.startScroll(getScrollX(), getScrollY(), getWidth() * mAnimatingToPage, 0, + setOffscreenPageLimit(lastPageNumber); // Ensure the page to reveal has been inflated. + mScroller.startScroll(getScrollX(), getScrollY(), getWidth() * lastPageNumber, 0, REVEAL_SCROLL_DURATION_MILLIS); postInvalidateOnAnimation(); } |