From 0e6a713fca3261021fcaca62c75dad8486c5e39f Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Fri, 23 Aug 2013 12:55:10 -0700 Subject: [PATCH] Fixing issue where dragging final items out of hot seat folder can causes inconsistency issue. - Fixing restoring of workspace screens on rotation (and flash of custom content page indicator) - Fixing NPE on long pressing on empty screen to go into overview mode --- src/com/android/launcher3/Folder.java | 5 ++-- src/com/android/launcher3/Launcher.java | 31 ++++++++++++++---------- src/com/android/launcher3/Workspace.java | 12 +++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java index 6308bb7929..3aa91333c1 100644 --- a/src/com/android/launcher3/Folder.java +++ b/src/com/android/launcher3/Folder.java @@ -1062,9 +1062,10 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList mLauncher.removeFolder(mInfo); } // We add the child after removing the folder to prevent both from existing at - // the same time in the CellLayout. + // the same time in the CellLayout. We need to add the new item with addInScreenFromBind() + // to ensure that hotseat items are placed correctly. if (child != null) { - mLauncher.getWorkspace().addInScreen(child, mInfo.container, mInfo.screenId, + mLauncher.getWorkspace().addInScreenFromBind(child, mInfo.container, mInfo.screenId, mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY); } } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 7fc7033fc4..ce4a78c3f9 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -2537,14 +2537,16 @@ public class Launcher extends Activity boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress(); if (allowLongPress && !mDragController.isDragging()) { if (itemUnderLongClick == null) { - // User long pressed on empty space - mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, - HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); - // Disabling reordering until we sort out some issues. - if (mWorkspace.isInOverviewMode()) { - mWorkspace.startReordering(v); - } else { - mWorkspace.enterOverviewMode(); + if (mWorkspace.hasNonCustomEmptyScreens()) { + // User long pressed on empty space + mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, + HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); + // Disabling reordering until we sort out some issues. + if (mWorkspace.isInOverviewMode()) { + mWorkspace.startReordering(v); + } else { + mWorkspace.enterOverviewMode(); + } } } else { if (!(itemUnderLongClick instanceof Folder)) { @@ -3502,7 +3504,15 @@ public class Launcher extends Activity @Override public void bindScreens(ArrayList orderedScreenIds) { bindAddScreens(orderedScreenIds); + + // Create the new empty page mWorkspace.addExtraEmptyScreen(); + + // Create the custom content page (this call updates mDefaultScreen which calls + // setCurrentPage() so ensure that all pages are added before calling this) + if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) { + mWorkspace.createCustomContentPage(); + } } @Override @@ -3744,11 +3754,6 @@ public class Launcher extends Activity mSavedState = null; } - // Create the custom content page here before onLayout to prevent flashing - if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) { - mWorkspace.createCustomContentPage(); - } - mWorkspace.restoreInstanceStateForRemainingPages(); // If we received the result of any pending adds while the loader was running (e.g. the diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index ba18b8de7e..d33e650411 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -567,6 +567,18 @@ public class Workspace extends SmoothPagedView return -1; } + public boolean hasNonCustomEmptyScreens() { + Log.w(TAG, "10249126 - hasNonCustomEmptyScreens()"); + Iterator iter = mWorkspaceScreens.keySet().iterator(); + while (iter.hasNext()) { + long id = iter.next(); + if (id >= 0) { + return true; + } + } + return false; + } + ArrayList getScreenOrder() { return mScreenOrder; }