Merge "Improve parallax" into jb-ub-now-indigo-rose

This commit is contained in:
Michael Jurka
2013-09-20 01:22:36 +00:00
committed by Android (Google) Code Review
+40 -15
View File
@@ -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();
}
}