summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2011-04-15 15:57:42 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-04-15 15:57:42 -0700
commit216342f98876a454a5c671f793a03055e7e8da19 (patch)
treec23f1153a9514d82d09ab21a3ea0e65794cc0346
parentd307d73ee1bef4a64e1992d6fe9c5d7b74ce612a (diff)
parent10b1737910ea7890ca95bbbe5363fd5aa513b856 (diff)
downloadandroid_packages_apps_Trebuchet-216342f98876a454a5c671f793a03055e7e8da19.tar.gz
android_packages_apps_Trebuchet-216342f98876a454a5c671f793a03055e7e8da19.tar.bz2
android_packages_apps_Trebuchet-216342f98876a454a5c671f793a03055e7e8da19.zip
Merge "Fixing folder creation for drops from other folders"
-rw-r--r--src/com/android/launcher2/Workspace.java70
1 files changed, 51 insertions, 19 deletions
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 66f1ceb9c..98cf62bbe 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -2273,6 +2273,48 @@ public class Workspace extends SmoothPagedView
return true;
}
+ boolean createUserFolderIfNecessary(View newView, CellLayout target, int originX,
+ int originY, boolean external) {
+ int spanX = mDragInfo != null ? mDragInfo.spanX : 1;
+ int spanY = mDragInfo != null ? mDragInfo.spanY : 1;
+
+ // First we find the cell nearest to point at which the item is dropped, without
+ // any consideration to whether there is an item there.
+ mTargetCell = findNearestArea(originX, originY,
+ spanX, spanY, target,
+ mTargetCell);
+
+ View v = target.getChildAt(mTargetCell[0], mTargetCell[1]);
+ boolean hasntMoved = mDragInfo != null && (mDragInfo.cellX == mTargetCell[0] &&
+ mDragInfo.cellY == mTargetCell[1]);
+
+ if (v == null || hasntMoved) return false;
+
+ final int screen = (mTargetCell == null) ?
+ mDragInfo.screen : indexOfChild(target);
+
+ boolean aboveShortcut = (v.getTag() instanceof ShortcutInfo);
+ boolean willBecomeShortcut = (newView.getTag() instanceof ShortcutInfo);
+
+ if (aboveShortcut && willBecomeShortcut) {
+ ShortcutInfo sourceInfo = (ShortcutInfo) newView.getTag();
+ ShortcutInfo destInfo = (ShortcutInfo) v.getTag();
+ // if the drag started here, we need to remove it from the workspace
+ if (!external) {
+ int fromScreen = mDragInfo.screen;
+ CellLayout sourceLayout = (CellLayout) getChildAt(fromScreen);
+ sourceLayout.removeView(newView);
+ }
+
+ target.removeView(v);
+ FolderIcon fi = mLauncher.addFolder(screen, mTargetCell[0], mTargetCell[1]);
+ fi.addItem(destInfo);
+ fi.addItem(sourceInfo);
+ return true;
+ }
+ return false;
+ }
+
public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
@@ -2317,30 +2359,13 @@ public class Workspace extends SmoothPagedView
if (dropTargetLayout != null) {
// Move internally
-
- // First we find the cell nearest to point at which the item is dropped, without
- // any consideration to whether there is an item there.
- mTargetCell = findNearestArea((int) mDragViewVisualCenter[0],
- (int) mDragViewVisualCenter[1], mDragInfo.spanX, mDragInfo.spanY,
- dropTargetLayout, mTargetCell);
-
final int screen = (mTargetCell == null) ?
mDragInfo.screen : indexOfChild(dropTargetLayout);
- View v = dropTargetLayout.getChildAt(mTargetCell[0], mTargetCell[1]);
- boolean hasMoved = !(mDragInfo.cellX == mTargetCell[0] &&
- mDragInfo.cellY == mTargetCell[1]);
-
// If the item being dropped is a shortcut and the nearest drop cell also contains
// a shortcut, then create a folder with the two shortcuts.
- if (v != null && (v.getTag() instanceof ShortcutInfo) &&
- dragInfo instanceof ShortcutInfo && hasMoved) {
- ShortcutInfo info1 = (ShortcutInfo) v.getTag();
- ShortcutInfo info2 = (ShortcutInfo) dragInfo;
- dropTargetLayout.removeView(v);
- FolderIcon fi = mLauncher.addFolder(screen, mTargetCell[0], mTargetCell[1]);
- fi.addItem(info1);
- fi.addItem(info2);
+ if (createUserFolderIfNecessary(cell, dropTargetLayout,
+ (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], false)) {
return;
}
@@ -2967,6 +2992,13 @@ public class Workspace extends SmoothPagedView
throw new IllegalStateException("Unknown item type: " + info.itemType);
}
+ // If the item being dropped is a shortcut and the nearest drop cell also contains
+ // a shortcut, then create a folder with the two shortcuts.
+ if (touchXY != null && createUserFolderIfNecessary(view, cellLayout, touchXY[0],
+ touchXY[1], true)) {
+ return;
+ }
+
mTargetCell = new int[2];
if (touchXY != null) {
// when dragging and dropping, just find the closest free spot