diff options
author | Adam Cohen <adamcohen@google.com> | 2011-08-31 21:52:05 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-08-31 21:52:05 -0700 |
commit | 3f4889e54fbb3c09fbc88cbc33be9e489d557f82 (patch) | |
tree | bdc5291a5c6c9dcbde99c6a24dc103227781e593 /src | |
parent | 83df188ce0822f4058406e5f2878d1cf34bf413e (diff) | |
parent | beff8c6a13d5b5ad69f5a85ee0150cecd28e6341 (diff) | |
download | android_packages_apps_Trebuchet-3f4889e54fbb3c09fbc88cbc33be9e489d557f82.tar.gz android_packages_apps_Trebuchet-3f4889e54fbb3c09fbc88cbc33be9e489d557f82.tar.bz2 android_packages_apps_Trebuchet-3f4889e54fbb3c09fbc88cbc33be9e489d557f82.zip |
Merge "Fixing wallpaper scrolling to be consistent in springloaded"
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher2/Launcher.java | 1 | ||||
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 57 |
2 files changed, 42 insertions, 16 deletions
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 80f0261ed..15b272fea 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -2144,7 +2144,6 @@ public final class Launcher extends Activity // Hide the workspace scrollbar mWorkspace.hideScrollingIndicator(true); mWorkspace.hideDockDivider(true); - mWorkspace.showAllAppsAnimationComplete(); } updateWallpaperVisibility(false); } diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 6f94c9310..d191d0739 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -113,6 +113,8 @@ public class Workspace extends SmoothPagedView private int mOverScrollPageIndex = -1; private AnimatorSet mDividerAnimator; + private float mWallpaperScrollRatio = 1.0f; + private final WallpaperManager mWallpaperManager; private IBinder mWindowToken; @@ -159,7 +161,6 @@ public class Workspace extends SmoothPagedView enum State { NORMAL, SPRING_LOADED, SMALL }; private State mState = State.NORMAL; private boolean mIsSwitchingState = false; - boolean mEnableSyncWallpaper = false; private boolean mSwitchStateAfterFirstLayout = false; private State mStateAfterFirstLayout; @@ -192,7 +193,6 @@ public class Workspace extends SmoothPagedView int mWallpaperHeight; WallpaperOffsetInterpolator mWallpaperOffset; boolean mUpdateWallpaperOffsetImmediately = false; - boolean mSyncWallpaperOffsetWithScroll = true; private Runnable mDelayedResizeRunnable; // Variables relating to the creation of user folders by hovering shortcuts over shortcuts @@ -754,6 +754,11 @@ public class Workspace extends SmoothPagedView // for all apps/customize) mWallpaperManager.setWallpaperOffsetSteps(1.0f / (getChildCount() - 1), 1.0f / (3 - 1)); + // For the purposes of computing the scrollRange and overScrollOffset, we ignore + // assume that mLayoutScale is 1. This means that when we're in spring-loaded mode, + // there's no discrepancy between the wallpaper offset for a given page. + float layoutScale = mLayoutScale; + mLayoutScale = 1f; int scrollRange = getScrollRange(); float scrollProgressOffset = 0; @@ -767,8 +772,12 @@ public class Workspace extends SmoothPagedView scrollRange += 2 * overscrollOffset; } + // Again, we adjust the wallpaper offset to be consistent between values of mLayoutScale + float adjustedScrollX = mWallpaperScrollRatio * mScrollX; + mLayoutScale = layoutScale; + float scrollProgress = - mScrollX / (float) scrollRange + scrollProgressOffset; + adjustedScrollX / (float) scrollRange + scrollProgressOffset; float offsetInDips = wallpaperTravelWidth * scrollProgress + (mWallpaperWidth - wallpaperTravelWidth) / 2; // center it float offset = offsetInDips / (float) mWallpaperWidth; @@ -807,6 +816,34 @@ public class Workspace extends SmoothPagedView } } + @Override + protected void updateCurrentPageScroll() { + super.updateCurrentPageScroll(); + computeWallpaperScrollRatio(); + } + + @Override + protected void snapToPage(int whichPage) { + super.snapToPage(whichPage); + computeWallpaperScrollRatio(); + } + + private void computeWallpaperScrollRatio() { + // Here, we determine what the desired scroll would be with and without a layout scale, + // and compute a ratio between the two. This allows us to adjust the wallpaper offset + // as though there is no layout scale. + float layoutScale = mLayoutScale; + int scaled = getChildOffset(mCurrentPage) - getRelativeChildOffset(mCurrentPage); + mLayoutScale = 1.0f; + float unscaled = getChildOffset(mCurrentPage) - getRelativeChildOffset(mCurrentPage); + mLayoutScale = layoutScale; + if (scaled > 0) { + mWallpaperScrollRatio = (1.0f * unscaled) / scaled; + } else { + mWallpaperScrollRatio = 1f; + } + } + class WallpaperOffsetInterpolator { float mFinalHorizontalWallpaperOffset = 0.0f; float mFinalVerticalWallpaperOffset = 0.5f; @@ -920,9 +957,7 @@ public class Workspace extends SmoothPagedView @Override public void computeScroll() { super.computeScroll(); - if (mSyncWallpaperOffsetWithScroll) { - syncWallpaperOffsetWithScroll(); - } + syncWallpaperOffsetWithScroll(); } void showOutlines() { @@ -1411,13 +1446,6 @@ public class Workspace extends SmoothPagedView changeState(shrinkState, true); } - void showAllAppsAnimationComplete() { - if (mEnableSyncWallpaper) { - mSyncWallpaperOffsetWithScroll = true; - mEnableSyncWallpaper = true; - } - } - void changeState(final State state, boolean animated) { if (mFirstLayout) { // (mFirstLayout == "first layout has not happened yet") @@ -1440,14 +1468,13 @@ public class Workspace extends SmoothPagedView State oldState = mState; mState = state; boolean zoomIn = true; + if (state != State.NORMAL) { finalScaleFactor = mSpringLoadedShrinkFactor - (state == State.SMALL ? 0.1f : 0); finalBackgroundAlpha = 1.0f; if (oldState == State.NORMAL && state == State.SMALL) { zoomIn = false; if (animated) { - mEnableSyncWallpaper = true; - mSyncWallpaperOffsetWithScroll = false; hideScrollingIndicator(true); } setLayoutScale(finalScaleFactor); |