From a888158880fea53479447d883391f552604e46b6 Mon Sep 17 00:00:00 2001 From: Dave Hawkey Date: Tue, 17 Sep 2013 15:55:33 -0600 Subject: Support for dynamically adding/removing -1 screen Change-Id: Ife68b64c04498e336192caf895edb9a090dcdc26 --- src/com/android/launcher3/Workspace.java | 51 ++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 16 deletions(-) (limited to 'src/com/android/launcher3/Workspace.java') diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 2758b8743..be2eb1d05 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -52,7 +52,6 @@ import android.view.Display; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import android.view.ViewParent; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.TextView; @@ -540,6 +539,24 @@ public class Workspace extends SmoothPagedView setCurrentPage(getCurrentPage() + 1); } + 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"); + } + + mWorkspaceScreens.remove(CUSTOM_CONTENT_SCREEN_ID); + mScreenOrder.remove(CUSTOM_CONTENT_SCREEN_ID); + removeView(customScreen); + mCustomContentCallbacks = null; + + // Ensure that the current page and default page are maintained. + mDefaultPage = mOriginalDefaultPage - 1; + setCurrentPage(getCurrentPage() - 1); + } + public void addToCustomContentPage(View customContent, CustomContentCallbacks callbacks) { if (getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID) < 0) { throw new RuntimeException("Expected custom content screen to exist"); @@ -1326,30 +1343,32 @@ public class Workspace extends SmoothPagedView } private void updateStateForCustomContent(int screenCenter) { + float translationX = 0; + float progress = 0; if (hasCustomContent()) { int index = mScreenOrder.indexOf(CUSTOM_CONTENT_SCREEN_ID); int scrollDelta = getScrollForPage(index + 1) - getScrollX(); - float translationX = Math.max(scrollDelta, 0); - float progress = (1.0f * scrollDelta) / + translationX = Math.max(scrollDelta, 0); + progress = (1.0f * scrollDelta) / (getScrollForPage(index + 1) - getScrollForPage(index)); progress = Math.max(0, progress); + } - if (Float.compare(progress, mLastCustomContentScrollProgress) == 0) return; - mLastCustomContentScrollProgress = progress; + if (Float.compare(progress, mLastCustomContentScrollProgress) == 0) return; + mLastCustomContentScrollProgress = progress; - setBackgroundAlpha(progress * 0.8f); + setBackgroundAlpha(progress * 0.8f); - if (mLauncher.getHotseat() != null) { - mLauncher.getHotseat().setTranslationX(translationX); - } + if (mLauncher.getHotseat() != null) { + mLauncher.getHotseat().setTranslationX(translationX); + } - if (getPageIndicator() != null) { - getPageIndicator().setTranslationX(translationX); - } + if (getPageIndicator() != null) { + getPageIndicator().setTranslationX(translationX); + } - if (mCustomContentCallbacks != null) { - mCustomContentCallbacks.onScrollProgressChanged(progress); - } + if (mCustomContentCallbacks != null) { + mCustomContentCallbacks.onScrollProgressChanged(progress); } } @@ -3793,7 +3812,7 @@ public class Workspace extends SmoothPagedView @Override protected void dispatchRestoreInstanceState(SparseArray container) { // We don't dispatch restoreInstanceState to our children using this code path. - // Some pages will be restored immediately as their items are bound immediately, and + // Some pages will be restored immediately as their items are bound immediately, and // others we will need to wait until after their items are bound. mSavedStates = container; } -- cgit v1.2.3