Cleanup pattern for removing the extra empty screen after drag operations

-> Fixes a couple bugs: issue 12179908, issue 12372657, issue 13287732

Change-Id: I24b5abe8e432ea331eeb77407120a8cec28f6376
This commit is contained in:
Adam Cohen
2014-05-08 17:27:56 -07:00
parent 1317e2dd4a
commit 689ff16ea2
4 changed files with 37 additions and 49 deletions
@@ -808,13 +808,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
!(target instanceof DeleteDropTarget) && !(target instanceof Folder))) {
// Exit spring loaded mode if we have not successfully dropped or have not handled the
// drop in Workspace
mLauncher.getWorkspace().removeExtraEmptyScreen(true, new Runnable() {
@Override
public void run() {
mLauncher.exitSpringLoadedDragMode();
mLauncher.unlockScreenOrientation(false);
}
});
mLauncher.exitSpringLoadedDragMode();
mLauncher.unlockScreenOrientation(false);
} else {
mLauncher.unlockScreenOrientation(false);
}
+5 -16
View File
@@ -797,12 +797,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
}
// This is kind of hacky, but in general, dropping on the workspace handles removing
// the extra screen, but dropping elsewhere (back to self, or onto delete) doesn't.
if (target != mLauncher.getWorkspace()) {
mLauncher.getWorkspace().removeExtraEmptyScreen(true, null);
}
mDeleteFolderOnDropCompleted = false;
mDragInProgress = false;
mItemAddedBackToSelfViaIcon = false;
@@ -1176,20 +1170,15 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
public void onDrop(DragObject d) {
Runnable cleanUpRunnable = null;
// If we are coming from All Apps space, we need to remove the extra empty screen (which is
// normally done in Workspace#onDropExternal, as well zoom back in.
// If we are coming from All Apps space, we defer removing the extra empty screen
// until the folder closes
if (d.dragSource != mLauncher.getWorkspace() && !(d.dragSource instanceof Folder)) {
cleanUpRunnable = new Runnable() {
@Override
public void run() {
mLauncher.getWorkspace().removeExtraEmptyScreen(false, new Runnable() {
@Override
public void run() {
mLauncher.exitSpringLoadedDragModeDelayed(true,
Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT_FOLDER_CLOSE,
null);
}
}, CLOSE_FOLDER_DELAY_MS, false);
mLauncher.exitSpringLoadedDragModeDelayed(true,
Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
null);
}
};
}
+6 -7
View File
@@ -215,7 +215,6 @@ public class Launcher extends Activity
static final int APPWIDGET_HOST_ID = 1024;
public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT_FOLDER_CLOSE = 400;
private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
private static final int ACTIVITY_START_DELAY = 1000;
@@ -779,7 +778,7 @@ public class Launcher extends Activity
data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
if (resultCode == RESULT_CANCELED) {
completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
} else if (resultCode == RESULT_OK) {
addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
@@ -833,7 +832,7 @@ public class Launcher extends Activity
}
};
}
mWorkspace.removeExtraEmptyScreen(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
false);
return;
}
@@ -856,10 +855,10 @@ public class Launcher extends Activity
} else {
completeAdd(args);
}
mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
} else if (resultCode == RESULT_CANCELED) {
mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
}
mDragLayer.clearAnimatedView();
@@ -2119,7 +2118,7 @@ public class Launcher extends Activity
};
completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
appWidgetInfo);
mWorkspace.removeExtraEmptyScreen(true, onComplete, delay, false);
mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
}
}
@@ -3924,7 +3923,7 @@ public class Launcher extends Activity
}
// Remove the extra empty screen
mWorkspace.removeExtraEmptyScreen(false, null);
mWorkspace.removeExtraEmptyScreen(false, false);
if (!LauncherAppState.isDisableAllApps() &&
addedApps != null && mAppsCustomizeContent != null) {
+24 -19
View File
@@ -135,6 +135,7 @@ public class Workspace extends SmoothPagedView
private ArrayList<Long> mScreenOrder = new ArrayList<Long>();
private Runnable mRemoveEmptyScreenRunnable;
private boolean mDeferRemoveExtraEmptyScreen = false;
/**
* CellInfo for the cell that is currently being dragged
@@ -397,13 +398,25 @@ public class Workspace extends SmoothPagedView
@Override
public void run() {
if (mIsDragOccuring) {
mDeferRemoveExtraEmptyScreen = false;
addExtraEmptyScreenOnDrag();
}
}
});
}
public void deferRemoveExtraEmptyScreen() {
mDeferRemoveExtraEmptyScreen = true;
}
public void onDragEnd() {
System.out.println("onDrag end workspace");
if (!mDeferRemoveExtraEmptyScreen) {
removeExtraEmptyScreen(true, mDragSourceInternal != null);
}
mIsDragOccuring = false;
updateChildrenLayersEnabled(false);
mLauncher.unlockScreenOrientation(false);
@@ -726,11 +739,11 @@ public class Workspace extends SmoothPagedView
}
}
public void removeExtraEmptyScreen(final boolean animate, final Runnable onComplete) {
removeExtraEmptyScreen(animate, onComplete, 0, false);
public void removeExtraEmptyScreen(final boolean animate, boolean stripEmptyScreens) {
removeExtraEmptyScreenDelayed(animate, null, 0, stripEmptyScreens);
}
public void removeExtraEmptyScreen(final boolean animate, final Runnable onComplete,
public void removeExtraEmptyScreenDelayed(final boolean animate, final Runnable onComplete,
final int delay, final boolean stripEmptyScreens) {
// Log to disk
Launcher.addDumpLog(TAG, "11683562 - removeExtraEmptyScreen()", true);
@@ -744,9 +757,8 @@ public class Workspace extends SmoothPagedView
postDelayed(new Runnable() {
@Override
public void run() {
removeExtraEmptyScreen(animate, onComplete, 0, stripEmptyScreens);
removeExtraEmptyScreenDelayed(animate, onComplete, 0, stripEmptyScreens);
}
}, delay);
return;
}
@@ -3056,13 +3068,11 @@ public class Workspace extends SmoothPagedView
// cell also contains a shortcut, then create a folder with the two shortcuts.
if (!mInScrollArea && createUserFolderIfNecessary(cell, container,
dropTargetLayout, mTargetCell, distance, false, d.dragView, null)) {
removeExtraEmptyScreen(true, null, 0, true);
return;
}
if (addToExistingFolderIfNecessary(cell, dropTargetLayout, mTargetCell,
distance, d, false)) {
removeExtraEmptyScreen(true, null, 0, true);
return;
}
@@ -3168,7 +3178,6 @@ public class Workspace extends SmoothPagedView
if (finalResizeRunnable != null) {
finalResizeRunnable.run();
}
removeExtraEmptyScreen(true, null, 0, true);
}
};
mAnimatingViewIntoPlace = true;
@@ -3822,13 +3831,8 @@ public class Workspace extends SmoothPagedView
final Runnable exitSpringLoadedRunnable = new Runnable() {
@Override
public void run() {
removeExtraEmptyScreen(false, new Runnable() {
@Override
public void run() {
mLauncher.exitSpringLoadedDragModeDelayed(true,
Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
}
});
mLauncher.exitSpringLoadedDragModeDelayed(true,
Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
}
};
@@ -3890,6 +3894,11 @@ public class Workspace extends SmoothPagedView
Runnable onAnimationCompleteRunnable = new Runnable() {
@Override
public void run() {
// Normally removeExtraEmptyScreen is called in Workspace#onDragEnd, but when
// adding an item that may not be dropped right away (due to a config activity)
// we defer the removal until the activity returns.
deferRemoveExtraEmptyScreen();
// When dragging and dropping from customization tray, we deal with creating
// widgets/shortcuts/folders in a slightly different way
switch (pendingInfo.itemType) {
@@ -4190,10 +4199,6 @@ public class Workspace extends SmoothPagedView
if (mDragInfo.cell instanceof DropTarget) {
mDragController.removeDropTarget((DropTarget) mDragInfo.cell);
}
// If we move the item to anything not on the Workspace, check if any empty
// screens need to be removed. If we dropped back on the workspace, this will
// be done post drop animation.
removeExtraEmptyScreen(true, null, 0, true);
}
} else if (mDragInfo != null) {
CellLayout cellLayout;