diff options
author | Michael Jurka <mikejurka@google.com> | 2013-09-20 01:22:36 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-09-20 01:22:36 +0000 |
commit | 8be886da011371e60863b2f4d2cd1dcb1581505a (patch) | |
tree | aad6c6a693eeea291e79823e9790e281327f3ea9 | |
parent | c8c9045712e393e62a90341b130f757a6d2b645a (diff) | |
parent | 2f81731e0986e21bd8407a8793112433795a2d2e (diff) | |
download | android_packages_apps_Trebuchet-8be886da011371e60863b2f4d2cd1dcb1581505a.tar.gz android_packages_apps_Trebuchet-8be886da011371e60863b2f4d2cd1dcb1581505a.tar.bz2 android_packages_apps_Trebuchet-8be886da011371e60863b2f4d2cd1dcb1581505a.zip |
Merge "Improve parallax" into jb-ub-now-indigo-rose
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 0fa417a99..41cea6a94 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -601,10 +601,7 @@ public class Workspace extends SmoothPagedView } public void removeExtraEmptyScreen() { - int nScreens = getChildCount(); - nScreens = hasCustomContent() ? nScreens - 1 : nScreens; - - if (mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) && nScreens > 1) { + if (hasExtraEmptyScreen()) { CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID); mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID); mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID); @@ -612,6 +609,12 @@ public class Workspace extends SmoothPagedView } } + public boolean hasExtraEmptyScreen() { + int nScreens = getChildCount(); + nScreens = hasCustomContent() ? nScreens - 1 : nScreens; + return mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) && nScreens > 1; + } + public long commitExtraEmptyScreen() { CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID); mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID); @@ -1038,9 +1041,6 @@ public class Workspace extends SmoothPagedView sp, mLauncher.getWindowManager(), mWallpaperManager); } - - - protected void snapToPage(int whichPage, Runnable r) { if (mDelayedSnapToPageRunnable != null) { mDelayedSnapToPageRunnable.run(); @@ -1063,7 +1063,9 @@ public class Workspace extends SmoothPagedView boolean mAnimating; long mAnimationStartTime; float mAnimationStartOffset; - final int ANIMATION_DURATION = 250; + private final int ANIMATION_DURATION = 250; + // Don't use all the wallpaper for parallax until you have at least this many pages + private final int MIN_PARALLAX_PAGE_SPAN = 4; int mNumScreens; public WallpaperOffsetInterpolator() { @@ -1076,7 +1078,6 @@ public class Workspace extends SmoothPagedView updateOffset(false); } - private void updateOffset(boolean force) { if (mWaitingForUpdate || force) { mWaitingForUpdate = false; @@ -1118,19 +1119,43 @@ public class Workspace extends SmoothPagedView if (getChildCount() <= 1) { return 0; } - final int lastIndex = isLayoutRtl() ? 0 : getChildCount() - 1; + + // Exclude the leftmost page final int firstIndex = isLayoutRtl() ? getChildCount() - 2 : 1; + // Exclude the last extra empty screen (if we have > MIN_PARALLAX_PAGE_SPAN pages) + int extra = numExtraScreensToIgnore(); + final int lastIndex = isLayoutRtl() ? 0 + extra : getChildCount() - 1 - extra; + int firstPageScrollX = getScrollForPage(firstIndex); int scrollRange = getScrollForPage(lastIndex) - firstPageScrollX; if (scrollRange == 0) { return 0; } else { - // do different behavior if it's a live wallpaper? - float offset = (getScrollX() - firstPageScrollX) / (float) scrollRange; - return offset; + // TODO: do different behavior if it's a live wallpaper? + float offset = Math.min(1, (getScrollX() - firstPageScrollX) / (float) scrollRange); + offset = Math.max(0, offset); + // Don't use up all the wallpaper parallax until you have at least + // MIN_PARALLAX_PAGE_SPAN pages + int numScrollingPages = getNumScreensExcludingExtraEmptyScreenAndLeftmost(); + int parallaxPageSpan = Math.max(MIN_PARALLAX_PAGE_SPAN, numScrollingPages) - 1; + return offset * (numScrollingPages - 1) / parallaxPageSpan; + } + } + + private int numExtraScreensToIgnore() { + int numScrollingPages = getChildCount() - 1; + if (numScrollingPages > MIN_PARALLAX_PAGE_SPAN && hasExtraEmptyScreen()) { + return 1; + } else { + return 0; } } + private int getNumScreensExcludingExtraEmptyScreenAndLeftmost() { + int numScrollingPages = getChildCount() - 1 - numExtraScreensToIgnore(); + return numScrollingPages; + } + public void syncWithScroll() { float offset = wallpaperOffsetForCurrentScroll(); mWallpaperOffset.setFinalX(offset); @@ -1159,12 +1184,12 @@ public class Workspace extends SmoothPagedView public void setFinalX(float x) { scheduleUpdate(); mFinalOffset = Math.max(0f, Math.min(x, 1.0f)); - if (getChildCount() != mNumScreens) { + if (getNumScreensExcludingExtraEmptyScreenAndLeftmost() != mNumScreens) { if (mNumScreens > 0) { // Don't animate if we're going from 0 screens animateToFinal(); } - mNumScreens = getChildCount(); + mNumScreens = getNumScreensExcludingExtraEmptyScreenAndLeftmost(); } } |