summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/launcher2/CellLayout.java30
-rw-r--r--src/com/android/launcher2/Folder.java10
-rw-r--r--src/com/android/launcher2/FolderIcon.java77
-rw-r--r--src/com/android/launcher2/Launcher.java21
-rw-r--r--src/com/android/launcher2/Workspace.java28
5 files changed, 110 insertions, 56 deletions
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 6f59d1f3c..1841713f5 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -792,27 +792,35 @@ public class CellLayout extends ViewGroup {
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
+ // First we clear the tag to ensure that on every touch down we start with a fresh slate,
+ // even in the case where we return early. Not clearing here was causing bugs whereby on
+ // long-press we'd end up picking up an item from a previous drag operation.
+ final int action = ev.getAction();
+
+ if (action == MotionEvent.ACTION_DOWN) {
+ clearTagCellInfo();
+ }
+
if (mInterceptTouchListener != null && mInterceptTouchListener.onTouch(this, ev)) {
return true;
}
- final int action = ev.getAction();
- final CellInfo cellInfo = mCellInfo;
if (action == MotionEvent.ACTION_DOWN) {
setTagToCellInfoForPoint((int) ev.getX(), (int) ev.getY());
- } else if (action == MotionEvent.ACTION_UP) {
- cellInfo.cell = null;
- cellInfo.cellX = -1;
- cellInfo.cellY = -1;
- cellInfo.spanX = 0;
- cellInfo.spanY = 0;
- setTag(cellInfo);
}
-
return false;
}
- @Override
+ private void clearTagCellInfo() {
+ final CellInfo cellInfo = mCellInfo;
+ cellInfo.cell = null;
+ cellInfo.cellX = -1;
+ cellInfo.cellY = -1;
+ cellInfo.spanX = 0;
+ cellInfo.spanY = 0;
+ setTag(cellInfo);
+ }
+
public CellInfo getTag() {
return (CellInfo) super.getTag();
}
diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java
index c490d5e6d..1fcfebc5a 100644
--- a/src/com/android/launcher2/Folder.java
+++ b/src/com/android/launcher2/Folder.java
@@ -297,13 +297,19 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
ArrayList<ShortcutInfo> children = info.contents;
ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
setupContentForNumItems(children.size());
+ int count = 0;
for (int i = 0; i < children.size(); i++) {
ShortcutInfo child = (ShortcutInfo) children.get(i);
if (!createAndAddShortcut(child)) {
overflow.add(child);
+ } else {
+ count++;
}
}
+ // We rearrange the items in case there are any empty gaps
+ setupContentForNumItems(count);
+
// If our folder has too many items we prune them from the list. This is an issue
// when upgrading from the old Folders implementation which could contain an unlimited
// number of items.
@@ -507,8 +513,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
// by another item. If it is, we need to find the next available slot and assign
// it that position. This is an issue when upgrading from the old Folders implementation
// which could contain an unlimited number of items.
- if (mContent.getChildAt(item.cellX, item.cellY) != null ||
- item.cellX < 0 || item.cellY < 0) {
+ if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
+ || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
if (!findAndSetEmptyCells(item)) {
return false;
}
diff --git a/src/com/android/launcher2/FolderIcon.java b/src/com/android/launcher2/FolderIcon.java
index 10928c05e..f1a150856 100644
--- a/src/com/android/launcher2/FolderIcon.java
+++ b/src/com/android/launcher2/FolderIcon.java
@@ -321,44 +321,53 @@ public class FolderIcon extends LinearLayout implements FolderListener {
float scaleRelativeToDragLayer, int index, Runnable postAnimationRunnable) {
item.cellX = -1;
item.cellY = -1;
- DragLayer dragLayer = mLauncher.getDragLayer();
- Rect from = new Rect();
- dragLayer.getViewRectRelativeToSelf(animateView, from);
- Rect to = finalRect;
- if (to == null) {
- to = new Rect();
- Workspace workspace = mLauncher.getWorkspace();
- // Set cellLayout and this to it's final state to compute final animation locations
- workspace.setFinalTransitionTransform((CellLayout) getParent().getParent());
- float scaleX = getScaleX();
- float scaleY = getScaleY();
- setScaleX(1.0f);
- setScaleY(1.0f);
- scaleRelativeToDragLayer = dragLayer.getDescendantRectRelativeToSelf(this, to);
- // Finished computing final animation locations, restore current state
- setScaleX(scaleX);
- setScaleY(scaleY);
- workspace.resetTransitionTransform((CellLayout) getParent().getParent());
- }
- int[] center = new int[2];
- float scale = getLocalCenterForIndex(index, center);
- center[0] = (int) Math.round(scaleRelativeToDragLayer * center[0]);
- center[1] = (int) Math.round(scaleRelativeToDragLayer * center[1]);
+ // Typically, the animateView corresponds to the DragView; however, if this is being done
+ // after a configuration activity (ie. for a Shortcut being dragged from AllApps) we
+ // will not have a view to animate
+ if (animateView != null) {
+ DragLayer dragLayer = mLauncher.getDragLayer();
+ Rect from = new Rect();
+ dragLayer.getViewRectRelativeToSelf(animateView, from);
+ Rect to = finalRect;
+ if (to == null) {
+ to = new Rect();
+ Workspace workspace = mLauncher.getWorkspace();
+ // Set cellLayout and this to it's final state to compute final animation locations
+ workspace.setFinalTransitionTransform((CellLayout) getParent().getParent());
+ float scaleX = getScaleX();
+ float scaleY = getScaleY();
+ setScaleX(1.0f);
+ setScaleY(1.0f);
+ scaleRelativeToDragLayer = dragLayer.getDescendantRectRelativeToSelf(this, to);
+ // Finished computing final animation locations, restore current state
+ setScaleX(scaleX);
+ setScaleY(scaleY);
+ workspace.resetTransitionTransform((CellLayout) getParent().getParent());
+ }
- to.offset(center[0] - animateView.getMeasuredWidth() / 2,
- center[1] - animateView.getMeasuredHeight() / 2);
+ int[] center = new int[2];
+ float scale = getLocalCenterForIndex(index, center);
+ center[0] = (int) Math.round(scaleRelativeToDragLayer * center[0]);
+ center[1] = (int) Math.round(scaleRelativeToDragLayer * center[1]);
- float finalAlpha = index < NUM_ITEMS_IN_PREVIEW ? 0.5f : 0f;
+ to.offset(center[0] - animateView.getMeasuredWidth() / 2,
+ center[1] - animateView.getMeasuredHeight() / 2);
- dragLayer.animateView(animateView, from, to, finalAlpha, scale * scaleRelativeToDragLayer,
- DROP_IN_ANIMATION_DURATION, new DecelerateInterpolator(2),
- new AccelerateInterpolator(2), postAnimationRunnable, false);
- postDelayed(new Runnable() {
- public void run() {
- addItem(item);
- }
- }, DROP_IN_ANIMATION_DURATION);
+ float finalAlpha = index < NUM_ITEMS_IN_PREVIEW ? 0.5f : 0f;
+
+ dragLayer.animateView(animateView, from, to, finalAlpha,
+ scale * scaleRelativeToDragLayer, DROP_IN_ANIMATION_DURATION,
+ new DecelerateInterpolator(2), new AccelerateInterpolator(2),
+ postAnimationRunnable, false);
+ postDelayed(new Runnable() {
+ public void run() {
+ addItem(item);
+ }
+ }, DROP_IN_ANIMATION_DURATION);
+ } else {
+ addItem(item);
+ }
}
public void onDrop(DragObject d) {
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index ad0c42b24..dc0120bb2 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -40,7 +40,6 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.Intent.ShortcutIconResource;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -51,7 +50,6 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
-import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
@@ -87,6 +85,7 @@ import android.widget.Toast;
import com.android.common.Search;
import com.android.launcher.R;
+import com.android.launcher2.DropTarget.DragObject;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -801,11 +800,25 @@ public final class Launcher extends Activity
boolean foundCellSpan = false;
+ ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
+ final View view = createShortcut(info);
+
// First we check if we already know the exact location where we want to add this item.
if (cellX >= 0 && cellY >= 0) {
cellXY[0] = cellX;
cellXY[1] = cellY;
foundCellSpan = true;
+
+ // If appropriate, either create a folder or add to an existing folder
+ if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY,
+ true, null,null)) {
+ return;
+ }
+ DragObject dragObject = new DragObject();
+ dragObject.dragInfo = info;
+ if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, dragObject, true)) {
+ return;
+ }
} else if (touchXY != null) {
// when dragging and dropping, just find the closest free spot
int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
@@ -819,11 +832,9 @@ public final class Launcher extends Activity
return;
}
- final ShortcutInfo info = mModel.addShortcut(
- this, data, container, screen, cellXY[0], cellXY[1], false);
+ LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
if (!mRestoring) {
- final View view = createShortcut(info);
mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
isWorkspaceLocked());
}
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index c04762fa3..b6a1666ab 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -2208,8 +2208,15 @@ public class Workspace extends SmoothPagedView
sourceInfo.cellX = -1;
sourceInfo.cellY = -1;
- fi.performCreateAnimation(destInfo, v, sourceInfo, dragView, folderLocation, scale,
- postAnimationRunnable);
+ // If the dragView is null, we can't animate
+ boolean animate = dragView != null;
+ if (animate) {
+ fi.performCreateAnimation(destInfo, v, sourceInfo, dragView, folderLocation, scale,
+ postAnimationRunnable);
+ } else {
+ fi.addItem(destInfo);
+ fi.addItem(sourceInfo);
+ }
return true;
}
return false;
@@ -2996,8 +3003,21 @@ public class Workspace extends SmoothPagedView
if (info instanceof PendingAddItemInfo) {
final PendingAddItemInfo pendingInfo = (PendingAddItemInfo) dragInfo;
- mTargetCell = findNearestVacantArea(touchXY[0], touchXY[1], spanX, spanY, null,
- cellLayout, mTargetCell);
+ boolean findNearestVacantCell = true;
+ if (pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
+ mTargetCell = findNearestArea((int) touchXY[0], (int) touchXY[1], spanX, spanY,
+ cellLayout, mTargetCell);
+ if (willCreateUserFolder((ItemInfo) d.dragInfo, mDragTargetLayout, mTargetCell,
+ true) || willAddToExistingUserFolder((ItemInfo) d.dragInfo,
+ mDragTargetLayout, mTargetCell)) {
+ findNearestVacantCell = false;
+ }
+ }
+ if (findNearestVacantCell) {
+ mTargetCell = findNearestVacantArea(touchXY[0], touchXY[1], spanX, spanY, null,
+ cellLayout, mTargetCell);
+ }
+
Runnable onAnimationCompleteRunnable = new Runnable() {
@Override
public void run() {