diff options
author | Adam Cohen <adamcohen@google.com> | 2013-11-08 06:45:03 -0800 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2013-11-18 15:21:29 +0000 |
commit | f9618856d6910ac385ad37762f9f067ae59a8622 (patch) | |
tree | 4e78e0d3ed7e72797a351ba9e3c9f45355bbe096 /src/com/android/launcher3/PagedView.java | |
parent | 603d19a333d53f537591107751b327cfc7b856fc (diff) | |
download | android_packages_apps_Trebuchet-f9618856d6910ac385ad37762f9f067ae59a8622.tar.gz android_packages_apps_Trebuchet-f9618856d6910ac385ad37762f9f067ae59a8622.tar.bz2 android_packages_apps_Trebuchet-f9618856d6910ac385ad37762f9f067ae59a8622.zip |
Syncing up state transition with paging transition
Change-Id: Id91e4c046cfe7d9aa6e7de10dbf57ee727ba160e
Diffstat (limited to 'src/com/android/launcher3/PagedView.java')
-rw-r--r-- | src/com/android/launcher3/PagedView.java | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index 3eecedbcc..c85449809 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -122,7 +122,8 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc protected int mNextPage = INVALID_PAGE; protected int mMaxScrollX; - protected Scroller mScroller; + protected LauncherScroller mScroller; + private Interpolator mDefaultInterpolator; private VelocityTracker mVelocityTracker; private int mPageSpacing = 0; @@ -310,7 +311,8 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc protected void init() { mDirtyPageContent = new ArrayList<Boolean>(); mDirtyPageContent.ensureCapacity(32); - mScroller = new Scroller(getContext(), new ScrollInterpolator()); + mScroller = new LauncherScroller(getContext()); + setDefaultInterpolator(new ScrollInterpolator()); mCurrentPage = 0; mCenterPagesVertically = true; @@ -330,6 +332,11 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc setOnHierarchyChangeListener(this); } + protected void setDefaultInterpolator(Interpolator interpolator) { + mDefaultInterpolator = interpolator; + mScroller.setInterpolator(mDefaultInterpolator); + } + protected void onAttachedToWindow() { super.onAttachedToWindow(); @@ -1625,11 +1632,11 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } protected void enableFreeScroll() { - setEnableFreeScroll(true, -1); + setEnableFreeScroll(true); } - protected void disableFreeScroll(int snapPage) { - setEnableFreeScroll(false, snapPage); + protected void disableFreeScroll() { + setEnableFreeScroll(false); } void updateFreescrollBounds() { @@ -1643,16 +1650,10 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } } - private void setEnableFreeScroll(boolean freeScroll, int snapPage) { + private void setEnableFreeScroll(boolean freeScroll) { mFreeScroll = freeScroll; - if (snapPage == -1) { - snapPage = getPageNearestToCenterOfScreen(); - } - - if (!mFreeScroll) { - snapToPage(snapPage); - } else { + if (mFreeScroll) { updateFreescrollBounds(); getOverviewModePages(mTempVisiblePagesRange); if (getCurrentPage() < mTempVisiblePagesRange[0]) { @@ -1910,6 +1911,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc int vX = (int) (-velocityX * scaleX); int initialScrollX = (int) (getScrollX() * scaleX); + mScroller.setInterpolator(mDefaultInterpolator); mScroller.fling(initialScrollX, getScrollY(), vX, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 0); invalidate(); @@ -2176,27 +2178,33 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } protected void snapToPageImmediately(int whichPage) { - snapToPage(whichPage, PAGE_SNAP_ANIMATION_DURATION, true); + snapToPage(whichPage, PAGE_SNAP_ANIMATION_DURATION, true, null); } protected void snapToPage(int whichPage, int duration) { - snapToPage(whichPage, duration, false); + snapToPage(whichPage, duration, false, null); } - protected void snapToPage(int whichPage, int duration, boolean immediate) { + protected void snapToPage(int whichPage, int duration, TimeInterpolator interpolator) { + snapToPage(whichPage, duration, false, interpolator); + } + + protected void snapToPage(int whichPage, int duration, boolean immediate, + TimeInterpolator interpolator) { whichPage = Math.max(0, Math.min(whichPage, getPageCount() - 1)); int newX = getScrollForPage(whichPage); final int sX = mUnboundedScrollX; final int delta = newX - sX; - snapToPage(whichPage, delta, duration, immediate); + snapToPage(whichPage, delta, duration, immediate, interpolator); } protected void snapToPage(int whichPage, int delta, int duration) { - snapToPage(whichPage, delta, duration, false); + snapToPage(whichPage, delta, duration, false, null); } - protected void snapToPage(int whichPage, int delta, int duration, boolean immediate) { + protected void snapToPage(int whichPage, int delta, int duration, boolean immediate, + TimeInterpolator interpolator) { mNextPage = whichPage; View focusedChild = getFocusedChild(); if (focusedChild != null && whichPage != mCurrentPage && @@ -2215,8 +2223,15 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } if (!mScroller.isFinished()) { - mScroller.abortAnimation(); + abortScrollerAnimation(false); + } + + if (interpolator != null) { + mScroller.setInterpolator(interpolator); + } else { + mScroller.setInterpolator(mDefaultInterpolator); } + mScroller.startScroll(mUnboundedScrollX, 0, delta, 0, duration); notifyPageSwitchListener(); @@ -2472,7 +2487,8 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc mDragView = getChildAt(dragViewIndex); mDragView.animate().scaleX(1.15f).scaleY(1.15f).setDuration(100).start(); mDragViewBaselineLeft = mDragView.getLeft(); - disableFreeScroll(-1); + snapToPage(getPageNearestToCenterOfScreen()); + disableFreeScroll(); onStartReordering(); return true; } |