diff options
Diffstat (limited to 'src/com/android/launcher3/Workspace.java')
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 139 |
1 files changed, 108 insertions, 31 deletions
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 9f4fa8a50..0d966f42a 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -52,6 +52,7 @@ 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; @@ -112,6 +113,8 @@ public class Workspace extends SmoothPagedView private int mOriginalDefaultPage; private int mDefaultPage; + private ShortcutAndWidgetContainer mDragSourceInternal; + // The screen id used for the empty screen always present to the right. private final static long EXTRA_EMPTY_SCREEN_ID = -201; private final static long CUSTOM_CONTENT_SCREEN_ID = -301; @@ -354,7 +357,7 @@ public class Workspace extends SmoothPagedView return r; } - public void onDragStart(DragSource source, Object info, int dragAction) { + public void onDragStart(final DragSource source, Object info, int dragAction) { mIsDragOccuring = true; updateChildrenLayersEnabled(false); mLauncher.lockScreenOrientation(); @@ -362,6 +365,14 @@ public class Workspace extends SmoothPagedView // Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging InstallShortcutReceiver.enableInstallQueue(); UninstallShortcutReceiver.enableUninstallQueue(); + post(new Runnable() { + @Override + public void run() { + if (mIsDragOccuring) { + addExtraEmptyScreenOnDrag(); + } + } + }); } public void onDragEnd() { @@ -372,6 +383,9 @@ public class Workspace extends SmoothPagedView // Re-enable any Un/InstallShortcutReceiver and now process any queued items InstallShortcutReceiver.disableAndFlushInstallQueue(getContext()); UninstallShortcutReceiver.disableAndFlushUninstallQueue(getContext()); + + removeExtraEmptyScreen(); + mDragSourceInternal = null; } /** @@ -490,6 +504,10 @@ public class Workspace extends SmoothPagedView String log = "10249126 - insertNewWorkspaceScreen(" + screenId + ", " + insertIndex + ")"; Launcher.addDumpLog(TAG, log, true); + if (mWorkspaceScreens.containsKey(screenId)) { + throw new RuntimeException("Screen id " + screenId + " already exists!"); + } + CellLayout newScreen = (CellLayout) mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null); @@ -540,6 +558,49 @@ public class Workspace extends SmoothPagedView mCustomContentCallbacks = callbacks; } + public void addExtraEmptyScreenOnDrag() { + boolean lastChildOnScreen = false; + boolean childOnFinalScreen = false; + + if (mDragSourceInternal != null) { + if (mDragSourceInternal.getChildCount() == 1) { + lastChildOnScreen = true; + } + CellLayout cl = (CellLayout) mDragSourceInternal.getParent(); + if (indexOfChild(cl) == getChildCount() - 1) { + childOnFinalScreen = true; + } + } + + // If this is the last item on the final screen + if (lastChildOnScreen && childOnFinalScreen) { + return; + } + if (!mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID)) { + insertNewWorkspaceScreen(EXTRA_EMPTY_SCREEN_ID); + } + } + + public boolean addExtraEmptyScreen() { + if (!mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID)) { + insertNewWorkspaceScreen(EXTRA_EMPTY_SCREEN_ID); + return true; + } + return false; + } + + public void removeExtraEmptyScreen() { + int nScreens = getChildCount(); + nScreens = hasCustomContent() ? nScreens - 1 : nScreens; + + if (mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) && nScreens > 1) { + CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID); + mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID); + mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID); + removeView(cl); + } + } + public long commitExtraEmptyScreen() { Launcher.addDumpLog(TAG, "10249126 - commitExtraEmptyScreen()", true); @@ -555,17 +616,12 @@ public class Workspace extends SmoothPagedView mWorkspaceScreens.put(newId, cl); mScreenOrder.add(newId); - addExtraEmptyScreen(); - // Update the model for the new screen mLauncher.getModel().updateWorkspaceScreenOrder(mLauncher, mScreenOrder); return newId; } - public void addExtraEmptyScreen() { - insertNewWorkspaceScreen(EXTRA_EMPTY_SCREEN_ID); - } public CellLayout getScreenWithId(long screenId) { Launcher.addDumpLog(TAG, "10249126 - getScreenWithId(" + screenId + ")", true); @@ -630,16 +686,27 @@ public class Workspace extends SmoothPagedView } } + // We enforce at least one page to add new items to. In the case that we remove the last + // such screen, we convert the last screen to the empty screen + int minScreens = hasCustomContent() ? 2 : 1; + 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); - if (indexOfChild(cl) < currentPage) { - pageShift++; + + if (getChildCount() > minScreens) { + if (indexOfChild(cl) < currentPage) { + pageShift++; + } + removeView(cl); + } else { + // if this is the last non-custom content screen, convert it to the empty screen + mWorkspaceScreens.put(EXTRA_EMPTY_SCREEN_ID, cl); + mScreenOrder.add(EXTRA_EMPTY_SCREEN_ID); } - removeView(cl); } if (!removeScreens.isEmpty()) { @@ -1269,9 +1336,10 @@ public class Workspace extends SmoothPagedView } private void updateStateForCustomContent(int screenCenter) { - if (hasCustomContent() && !isSmall() && !isSwitchingState()) { + 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) / (getScrollForPage(index + 1) - getScrollForPage(index)); progress = Math.max(0, progress); @@ -1280,28 +1348,13 @@ public class Workspace extends SmoothPagedView mLastCustomContentScrollProgress = progress; setBackgroundAlpha(progress * 0.8f); - float height = getViewportHeight(); - if (getPageIndicator() != null) { - height -= getPageIndicator().getTop(); - } else if (mLauncher.getHotseat() != null) { - height -= mLauncher.getHotseat().getTop(); - } - float transY = progress * height; if (mLauncher.getHotseat() != null) { - mLauncher.getHotseat().setTranslationY(transY); - mLauncher.getHotseat().setAlpha(1 - progress); + mLauncher.getHotseat().setTranslationX(translationX); } if (getPageIndicator() != null) { - final float alpha = 1 - progress; - final View pi = getPageIndicator(); - getPageIndicator().setAlpha(alpha); - if (alpha < ALPHA_CUTOFF_THRESHOLD && pi.getVisibility() != INVISIBLE) { - pi.setVisibility(INVISIBLE); - } else if (alpha > ALPHA_CUTOFF_THRESHOLD && pi.getVisibility() != VISIBLE) { - pi.setVisibility(VISIBLE); - } + getPageIndicator().setTranslationX(translationX); } if (mCustomContentCallbacks != null) { @@ -2133,6 +2186,11 @@ public class Workspace extends SmoothPagedView mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale); + + if (child.getParent() instanceof ShortcutAndWidgetContainer) { + mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); + } + b.recycle(); } @@ -4072,20 +4130,39 @@ public class Workspace extends SmoothPagedView } } - void moveToDefaultScreen(boolean animate) { + private void moveToScreen(int page, boolean animate) { if (!isSmall()) { if (animate) { - snapToPage(mDefaultPage); + snapToPage(page); } else { - setCurrentPage(mDefaultPage); + setCurrentPage(page); } } - View child = getChildAt(mDefaultPage); + View child = getChildAt(page); if (child != null) { child.requestFocus(); } } + void moveToDefaultScreen(boolean animate) { + moveToScreen(mDefaultPage, animate); + } + + void moveToCustomContentScreen(boolean animate) { + if (hasCustomContent()) { + int ccIndex = getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID); + if (animate) { + snapToPage(ccIndex); + } else { + setCurrentPage(ccIndex); + } + View child = getChildAt(ccIndex); + if (child != null) { + child.requestFocus(); + } + } + } + @Override protected int getPageIndicatorMarker(int pageIndex) { if (getScreenIdForPageIndex(pageIndex) == CUSTOM_CONTENT_SCREEN_ID) { |