diff options
Diffstat (limited to 'src/com/android/launcher3/Workspace.java')
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 2f58571d4..eb2b19df0 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -479,7 +479,6 @@ public class Workspace extends SmoothPagedView } public void removeAllWorkspaceScreens() { - Launcher.addDumpLog(TAG, "10249126 - removeAllWorkspaceScreens()", true); // Remove the pages and clear the screen models removeAllViews(); mScreenOrder.clear(); @@ -490,7 +489,6 @@ public class Workspace extends SmoothPagedView // Find the index to insert this view into. If the empty screen exists, then // insert it before that. int insertIndex = mScreenOrder.indexOf(EXTRA_EMPTY_SCREEN_ID); - Launcher.addDumpLog(TAG, "10249126 - insertNewWorkspaceScreenBeforeEmptyScreen(" + insertIndex + ")", true); if (insertIndex < 0) { insertIndex = mScreenOrder.size(); } @@ -502,9 +500,6 @@ public class Workspace extends SmoothPagedView } public long insertNewWorkspaceScreen(long screenId, int insertIndex) { - String log = "10249126 - insertNewWorkspaceScreen(" + screenId + ", " + insertIndex + ")"; - Launcher.addDumpLog(TAG, log, true); - if (mWorkspaceScreens.containsKey(screenId)) { throw new RuntimeException("Screen id " + screenId + " already exists!"); } @@ -522,7 +517,6 @@ public class Workspace extends SmoothPagedView } public void createCustomContentPage() { - Launcher.addDumpLog(TAG, "10249126 - createCustomContentPage()", true); CellLayout customScreen = (CellLayout) mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null); @@ -540,8 +534,6 @@ public class Workspace extends SmoothPagedView } public void removeCustomContentPage() { - Launcher.addDumpLog(TAG, "10249126 - removeCustomContentPage()", true); - CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID); if (customScreen == null) { throw new RuntimeException("Expected custom content screen to exist"); @@ -609,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); @@ -620,13 +609,13 @@ public class Workspace extends SmoothPagedView } } - public long commitExtraEmptyScreen() { - Launcher.addDumpLog(TAG, "10249126 - commitExtraEmptyScreen()", true); - - // Write all the logs to disk - Launcher.addDumpLog(TAG, "10249126 - commitExtraEmptyScreen() - dumping logs to disk", true); - mLauncher.dumpLogsToLocalData(false); + 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); mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID); @@ -643,13 +632,11 @@ public class Workspace extends SmoothPagedView public CellLayout getScreenWithId(long screenId) { - Launcher.addDumpLog(TAG, "10249126 - getScreenWithId(" + screenId + ")", true); CellLayout layout = mWorkspaceScreens.get(screenId); return layout; } public long getIdForScreen(CellLayout layout) { - Launcher.addDumpLog(TAG, "10249126 - getIdForScreen()", true); Iterator<Long> iter = mWorkspaceScreens.keySet().iterator(); while (iter.hasNext()) { long id = iter.next(); @@ -661,7 +648,6 @@ public class Workspace extends SmoothPagedView } public int getPageIndexForScreenId(long screenId) { - Launcher.addDumpLog(TAG, "10249126 - getPageIndexForScreenId(" + screenId + ")", true); return indexOfChild(mWorkspaceScreens.get(screenId)); } @@ -682,8 +668,6 @@ public class Workspace extends SmoothPagedView return; } - Launcher.addDumpLog(TAG, "10249126 - stripEmptyScreens()", true); - int currentPage = getNextPage(); ArrayList<Long> removeScreens = new ArrayList<Long>(); for (Long id: mWorkspaceScreens.keySet()) { @@ -699,7 +683,6 @@ public class Workspace extends SmoothPagedView int pageShift = 0; for (Long id: removeScreens) { - Launcher.addDumpLog(TAG, "10249126 - \tremove(" + id + ")", true); CellLayout cl = mWorkspaceScreens.get(id); mWorkspaceScreens.remove(id); mScreenOrder.remove(id); @@ -1058,9 +1041,6 @@ public class Workspace extends SmoothPagedView sp, mLauncher.getWindowManager(), mWallpaperManager); } - - - protected void snapToPage(int whichPage, Runnable r) { if (mDelayedSnapToPageRunnable != null) { mDelayedSnapToPageRunnable.run(); @@ -1083,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() { @@ -1096,7 +1078,6 @@ public class Workspace extends SmoothPagedView updateOffset(false); } - private void updateOffset(boolean force) { if (mWaitingForUpdate || force) { mWaitingForUpdate = false; @@ -1138,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); @@ -1179,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(); } } @@ -1746,7 +1751,6 @@ public class Workspace extends SmoothPagedView mScreenOrder.add(getIdForScreen(cl)); } - Launcher.addDumpLog(TAG, "10249126 - onEndReordering()", true); mLauncher.getModel().updateWorkspaceScreenOrder(mLauncher, mScreenOrder); // Re-enable auto layout transitions for page deletion. |