diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 775dad2c80..e3acf70b2e 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -1031,8 +1031,8 @@ public class Launcher extends BaseActivity if (!state.doNotRestore) { if (state == LauncherState.ALL_APPS) { showAppsView(false /* animated */); - } else { - // TODO: Add logic for other states + } else if (state == LauncherState.OVERVIEW) { + showOverviewMode(false); } } diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index 5258fba927..f55455b7ef 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -49,7 +49,6 @@ import android.view.animation.Interpolator; import com.android.launcher3.anim.PropertyListBuilder; import com.android.launcher3.pageindicators.PageIndicator; import com.android.launcher3.touch.OverScroll; -import com.android.launcher3.util.Themes; import com.android.launcher3.util.Thunk; import java.util.ArrayList; @@ -87,8 +86,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc public static final int INVALID_RESTORE_PAGE = -1001; private boolean mFreeScroll = false; - private int mFreeScrollMinScrollX = -1; - private int mFreeScrollMaxScrollX = -1; protected int mFlingThresholdVelocity; protected int mMinFlingVelocity; @@ -137,7 +134,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc protected int mTouchSlop; private int mMaximumVelocity; protected boolean mAllowOverScroll = true; - protected int[] mTempVisiblePagesRange = new int[2]; protected static final int INVALID_POINTER = -1; @@ -380,16 +376,8 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } private int validateNewPage(int newPage) { - int validatedPage = newPage; - // When in free scroll mode, we need to clamp to the free scroll page range. - if (mFreeScroll) { - getFreeScrollPageRange(mTempVisiblePagesRange); - validatedPage = Math.max(mTempVisiblePagesRange[0], - Math.min(newPage, mTempVisiblePagesRange[1])); - } // Ensure that it is clamped by the actual set of children in all cases - validatedPage = Utilities.boundToRange(validatedPage, 0, getPageCount() - 1); - return validatedPage; + return Utilities.boundToRange(newPage, 0, getPageCount() - 1); } /** @@ -491,13 +479,11 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc if (mFreeScroll) { // If the scroller is trying to move to a location beyond the maximum allowed // in the free scroll mode, we make sure to end the scroll operation. - if (!mScroller.isFinished() && - (x > mFreeScrollMaxScrollX || x < mFreeScrollMinScrollX)) { + if (!mScroller.isFinished() && (x > mMaxScrollX || x < 0)) { forceFinishScroller(false); } - x = Math.min(x, mFreeScrollMaxScrollX); - x = Math.max(x, mFreeScrollMinScrollX); + x = Utilities.boundToRange(x, 0, mMaxScrollX); } mUnboundedScrollX = x; @@ -886,7 +872,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc return 0; } - @Thunk void updateMaxScrollX() { + private void updateMaxScrollX() { mMaxScrollX = computeMaxScrollX(); } @@ -915,13 +901,11 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc // This ensures that when children are added, they get the correct transforms / alphas // in accordance with any scroll effects. - updateFreescrollBounds(); invalidate(); } @Override public void onChildViewRemoved(View parent, View child) { - updateFreescrollBounds(); mCurrentPage = validateNewPage(mCurrentPage); invalidate(); } @@ -974,11 +958,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc return offset; } - protected void getFreeScrollPageRange(int[] range) { - range[0] = 0; - range[1] = Math.max(0, getChildCount() - 1); - } - @Override public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { int page = indexToPage(indexOfChild(child)); @@ -1349,29 +1328,12 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc setEnableFreeScroll(false); } - void updateFreescrollBounds() { - getFreeScrollPageRange(mTempVisiblePagesRange); - if (mIsRtl) { - mFreeScrollMinScrollX = getScrollForPage(mTempVisiblePagesRange[1]); - mFreeScrollMaxScrollX = getScrollForPage(mTempVisiblePagesRange[0]); - } else { - mFreeScrollMinScrollX = getScrollForPage(mTempVisiblePagesRange[0]); - mFreeScrollMaxScrollX = getScrollForPage(mTempVisiblePagesRange[1]); - } - } - private void setEnableFreeScroll(boolean freeScroll) { boolean wasFreeScroll = mFreeScroll; mFreeScroll = freeScroll; if (mFreeScroll) { - updateFreescrollBounds(); - getFreeScrollPageRange(mTempVisiblePagesRange); - if (getCurrentPage() < mTempVisiblePagesRange[0]) { - setCurrentPage(mTempVisiblePagesRange[0]); - } else if (getCurrentPage() > mTempVisiblePagesRange[1]) { - setCurrentPage(mTempVisiblePagesRange[1]); - } + setCurrentPage(getNextPage()); } else if (wasFreeScroll) { snapToPage(getNextPage()); } @@ -1387,12 +1349,12 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc if (mDragView != null) { int dragX = (int) (mDragView.getLeft() + (mDragView.getMeasuredWidth() / 2) + mDragView.getTranslationX()); - getFreeScrollPageRange(mTempVisiblePagesRange); int minDistance = Integer.MAX_VALUE; int minIndex = indexOfChild(mDragView); - for (int i = mTempVisiblePagesRange[0]; i <= mTempVisiblePagesRange[1]; i++) { + int maxPageNo = getChildCount() - 1; + for (int i = 0; i <= maxPageNo; i++) { View page = getPageAt(i); - int pageX = (int) (page.getLeft() + page.getMeasuredWidth() / 2); + int pageX = (page.getLeft() + page.getMeasuredWidth() / 2); int d = Math.abs(dragX - pageX); if (d < minDistance) { minIndex = i; @@ -1487,11 +1449,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc final int pageUnderPointIndex = getNearestHoverOverPageIndex(); // Do not allow any page to be moved to 0th position. if (pageUnderPointIndex > 0 && pageUnderPointIndex != indexOfChild(mDragView)) { - mTempVisiblePagesRange[0] = 0; - mTempVisiblePagesRange[1] = getPageCount() - 1; - getFreeScrollPageRange(mTempVisiblePagesRange); - if (mTempVisiblePagesRange[0] <= pageUnderPointIndex && - pageUnderPointIndex <= mTempVisiblePagesRange[1] && + if (0 <= pageUnderPointIndex && pageUnderPointIndex <= getPageCount() - 1 && pageUnderPointIndex != mSidePageHoverIndex && mScroller.isFinished()) { mSidePageHoverIndex = pageUnderPointIndex; mSidePageHoverRunnable = new Runnable() { @@ -2025,18 +1983,14 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc // Do not allow the first page to be moved around if (mTouchState != TOUCH_STATE_REST || dragViewIndex <= 0) return false; - mTempVisiblePagesRange[0] = 0; - mTempVisiblePagesRange[1] = getPageCount() - 1; - getFreeScrollPageRange(mTempVisiblePagesRange); - mReorderingStarted = true; - // Check if we are within the reordering range - if (mTempVisiblePagesRange[0] <= dragViewIndex && - dragViewIndex <= mTempVisiblePagesRange[1]) { + if (0 <= dragViewIndex && dragViewIndex <= getPageCount() - 1) { // Find the drag view under the pointer mDragView = getChildAt(dragViewIndex); mDragView.animate().scaleX(1.15f).scaleY(1.15f).setDuration(100).start(); mDragViewBaselineLeft = mDragView.getLeft(); + mReorderingStarted = true; + snapToPage(getPageNearestToCenterOfScreen()); disableFreeScroll(); onStartReordering(); diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 173ff6d4a8..27d860b560 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -54,8 +54,6 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewDebug; import android.view.ViewGroup; -import android.view.accessibility.AccessibilityManager; -import android.view.accessibility.AccessibilityNodeInfo; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.Toast; @@ -576,6 +574,7 @@ public class Workspace extends PagedView mWorkspaceScreens.put(screenId, newScreen); mScreenOrder.add(insertIndex, screenId); addView(newScreen, insertIndex); + mStateTransitionAnimation.applyChildState(mState, newScreen, insertIndex); if (mLauncher.getAccessibilityDelegate().isInAccessibleDrag()) { newScreen.enableAccessibleDrag(true, CellLayout.WORKSPACE_ACCESSIBILITY_DRAG); diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java index d66255bda2..ff653d7ea7 100644 --- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java +++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java @@ -178,9 +178,6 @@ public class WorkspaceStateTransitionAnimation { * Starts a transition animation for the workspace. */ private void setWorkspaceProperty(LauncherState state, PropertySetter propertySetter) { - // Update the workspace state - int finalBackgroundAlpha = state.hasScrim ? 255 : 0; - float[] scaleAndTranslationY = state.getWorkspaceScaleAndTranslation(mLauncher); mNewScale = scaleAndTranslationY[0]; final float finalWorkspaceTranslationY = scaleAndTranslationY[1]; @@ -188,16 +185,8 @@ public class WorkspaceStateTransitionAnimation { int toPage = mWorkspace.getPageNearestToCenterOfScreen(); final int childCount = mWorkspace.getChildCount(); for (int i = 0; i < childCount; i++) { - final CellLayout cl = (CellLayout) mWorkspace.getChildAt(i); - propertySetter.setInt(cl.getScrimBackground(), - DRAWABLE_ALPHA, finalBackgroundAlpha, mZoomInInterpolator); - - // Only animate the page alpha when we actually fade pages - if (mWorkspaceFadeInAdjacentScreens) { - float finalAlpha = state == LauncherState.NORMAL && i != toPage ? 0 : 1f; - propertySetter.setFloat(cl.getShortcutsAndWidgets(), View.ALPHA, - finalAlpha, mZoomInInterpolator); - } + applyChildState(state, (CellLayout) mWorkspace.getChildAt(i), i, toPage, + propertySetter); } float finalHotseatAlpha = state.hideHotseat ? 0f : 1f; @@ -217,6 +206,24 @@ public class WorkspaceStateTransitionAnimation { state.hasScrim ? mWorkspaceScrimAlpha : 0, new DecelerateInterpolator(1.5f)); } + public void applyChildState(LauncherState state, CellLayout cl, int childIndex) { + applyChildState(state, cl, childIndex, mWorkspace.getPageNearestToCenterOfScreen(), + NO_ANIM_PROPERTY_SETTER); + } + + private void applyChildState(LauncherState state, CellLayout cl, int childIndex, + int centerPage, PropertySetter propertySetter) { + propertySetter.setInt(cl.getScrimBackground(), + DRAWABLE_ALPHA, state.hasScrim ? 255 : 0, mZoomInInterpolator); + + // Only animate the page alpha when we actually fade pages + if (mWorkspaceFadeInAdjacentScreens) { + float finalAlpha = state == LauncherState.NORMAL && childIndex != centerPage ? 0 : 1f; + propertySetter.setFloat(cl.getShortcutsAndWidgets(), View.ALPHA, + finalAlpha, mZoomInInterpolator); + } + } + private static class PropertySetter { public void setViewAlpha(Animator anim, View view, float alpha) { diff --git a/src/com/android/launcher3/states/OverviewState.java b/src/com/android/launcher3/states/OverviewState.java index 57f023cc6d..344a4f95fd 100644 --- a/src/com/android/launcher3/states/OverviewState.java +++ b/src/com/android/launcher3/states/OverviewState.java @@ -36,8 +36,7 @@ public class OverviewState extends LauncherState { // The percent to shrink the workspace during overview mode public static final float SCALE_FACTOR = 0.7f; - private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | FLAG_HIDE_HOTSEAT | - FLAG_DO_NOT_RESTORE; + private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | FLAG_HIDE_HOTSEAT; public OverviewState(int id) { super(id, ContainerType.WORKSPACE, OVERVIEW_TRANSITION_MS, 1f, STATE_FLAGS);