summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2011-06-09 15:06:52 -0700
committerAdam Cohen <adamcohen@google.com>2011-06-09 15:10:43 -0700
commit76078c4ef35b6e95fb6d8129a32cf52a36625e28 (patch)
tree85eaddc65ac4b5fb7a57c52bbc0b84e3017c35be /src/com
parentc0dcf597084d00e4c23a7fea5fd0738f6c095a6b (diff)
downloadandroid_packages_apps_Trebuchet-76078c4ef35b6e95fb6d8129a32cf52a36625e28.tar.gz
android_packages_apps_Trebuchet-76078c4ef35b6e95fb6d8129a32cf52a36625e28.tar.bz2
android_packages_apps_Trebuchet-76078c4ef35b6e95fb6d8129a32cf52a36625e28.zip
Fixing up some folder-related drag and drop bugs
Change-Id: I712ffd0ccfc0154a5a9e74e3f585157a86986882
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/launcher2/Folder.java44
-rw-r--r--src/com/android/launcher2/FolderIcon.java7
-rw-r--r--src/com/android/launcher2/FolderInfo.java7
-rw-r--r--src/com/android/launcher2/Workspace.java85
4 files changed, 96 insertions, 47 deletions
diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java
index 08907c99a..d6be3072c 100644
--- a/src/com/android/launcher2/Folder.java
+++ b/src/com/android/launcher2/Folder.java
@@ -84,6 +84,7 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL
private ArrayList<View> mItemsInReadingOrder = new ArrayList<View>();
private Drawable mIconDrawable;
boolean mItemsInvalidated = false;
+ ShortcutInfo mCurrentDragInfo;
/**
* Used to inflate the Workspace from XML.
@@ -147,7 +148,10 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL
mDragItemPosition[0] = item.cellX;
mDragItemPosition[1] = item.cellY;
mIconDrawable = ((TextView) v).getCompoundDrawables()[1];
- mInfo.remove(item);
+
+ mCurrentDragInfo = item;
+ mItemsInvalidated = true;
+ mInfo.itemsChanged();
mDragItem = item;
} else {
@@ -388,8 +392,13 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL
} else {
item = (ShortcutInfo) d.dragInfo;
}
+
+ // Dragged from self onto self
+ if (item == mCurrentDragInfo) {
+ mInfo.remove(item);
+ }
+
mInfo.add(item);
- LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
}
protected boolean findAndSetEmptyCells(ShortcutInfo item) {
@@ -397,8 +406,6 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL
if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
item.cellX = emptyCell[0];
item.cellY = emptyCell[1];
- LauncherModel.addOrMoveItemInDatabase(
- mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
return true;
} else {
return false;
@@ -449,6 +456,21 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL
}
public void onDropCompleted(View target, DragObject d, boolean success) {
+ if (!success) {
+ if (d.dragView != null) {
+ if (target instanceof CellLayout) {
+ // TODO: we should animate the item back to the folder in this case
+ }
+ }
+ mCurrentDragInfo = null;
+ mItemsInvalidated = true;
+ mInfo.itemsChanged();
+ } else {
+ if (target != this) {
+ mInfo.remove(mCurrentDragInfo);
+ mCurrentDragInfo = null;
+ }
+ }
}
public boolean isDropEnabled() {
@@ -580,6 +602,8 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL
findAndSetEmptyCells(item);
}
createAndAddShortcut(item);
+ LauncherModel.addOrMoveItemInDatabase(
+ mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
}
public int getItemCount() {
@@ -608,14 +632,24 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL
}
}
+ public void onItemsChanged() {
+ }
+
public ArrayList<View> getItemsInReadingOrder() {
+ return getItemsInReadingOrder(true);
+ }
+
+ public ArrayList<View> getItemsInReadingOrder(boolean includeCurrentDragItem) {
if (mItemsInvalidated) {
mItemsInReadingOrder.clear();
for (int j = 0; j < mContent.getCountY(); j++) {
for (int i = 0; i < mContent.getCountX(); i++) {
View v = mContent.getChildAt(i, j);
if (v != null) {
- mItemsInReadingOrder.add(v);
+ ShortcutInfo info = (ShortcutInfo) v.getTag();
+ if (info != mCurrentDragInfo || includeCurrentDragItem) {
+ mItemsInReadingOrder.add(v);
+ }
}
}
}
diff --git a/src/com/android/launcher2/FolderIcon.java b/src/com/android/launcher2/FolderIcon.java
index 449068c56..18b242bfa 100644
--- a/src/com/android/launcher2/FolderIcon.java
+++ b/src/com/android/launcher2/FolderIcon.java
@@ -316,7 +316,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {
int baselineWidth = (int) (d.getIntrinsicWidth() * baselineIconScale);
float maxPerpectiveShift = baselineHeight * PERSPECTIVE_SHIFT_FACTOR;
- ArrayList<View> items = mFolder.getItemsInReadingOrder();
+ ArrayList<View> items = mFolder.getItemsInReadingOrder(false);
int firstItemIndex = Math.max(0, items.size() - NUM_ITEMS_IN_PREVIEW);
int xShift = (int) (mOriginalWidth - baselineWidth) / 2;
@@ -352,6 +352,11 @@ public class FolderIcon extends FrameLayout implements FolderListener {
canvas.restore();
}
+ public void onItemsChanged() {
+ invalidate();
+ requestLayout();
+ }
+
public void onAdd(ShortcutInfo item) {
invalidate();
requestLayout();
diff --git a/src/com/android/launcher2/FolderInfo.java b/src/com/android/launcher2/FolderInfo.java
index 12ed27c29..805a51f39 100644
--- a/src/com/android/launcher2/FolderInfo.java
+++ b/src/com/android/launcher2/FolderInfo.java
@@ -86,8 +86,15 @@ class FolderInfo extends ItemInfo {
}
}
+ void itemsChanged() {
+ for (int i = 0; i < listeners.size(); i++) {
+ listeners.get(i).onItemsChanged();
+ }
+ }
+
interface FolderListener {
public void onAdd(ShortcutInfo item);
public void onRemove(ShortcutInfo item);
+ public void onItemsChanged();
}
}
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 812763f86..5c3399c1d 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -2350,23 +2350,11 @@ public class Workspace extends SmoothPagedView
lp.oldY = viewY - (layout.getTop() + layout.getTopPadding() - mScrollY);
}
- /*
- * We should be careful that this method cannot result in any synchronous requestLayout()
- * calls, as it is called from onLayout().
- */
- public void animateViewIntoPosition(final View view) {
- final CellLayout parent = (CellLayout) view.getParent().getParent();
- final CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams();
-
- // Convert the animation params to be relative to the Workspace, not the CellLayout
- final int fromX = lp.oldX + parent.getLeft() + parent.getLeftPadding();
- final int fromY = lp.oldY + parent.getTop() + parent.getTopPadding();
-
- final int dx = lp.x - lp.oldX;
- final int dy = lp.y - lp.oldY;
+ public void animateViewIntoPosition(final View view, final int fromX, final int fromY,
+ final int dX, final int dY, final Runnable animationEndRunnable) {
// Calculate the duration of the animation based on the object's distance
- final float dist = (float) Math.sqrt(dx*dx + dy*dy);
+ final float dist = (float) Math.sqrt(dX*dX + dY*dY);
final Resources res = getResources();
final float maxDist = (float) res.getInteger(R.integer.config_dropAnimMaxDist);
int duration = res.getInteger(R.integer.config_dropAnimMaxDuration);
@@ -2388,10 +2376,7 @@ public class Workspace extends SmoothPagedView
}
public void onAnimationEnd(Animator animation) {
- if (mDropView != null) {
- mDropView.setVisibility(View.VISIBLE);
- mDropView = null;
- }
+ animationEndRunnable.run();
}
});
@@ -2405,8 +2390,8 @@ public class Workspace extends SmoothPagedView
invalidate(mDropViewPos[0], mDropViewPos[1],
mDropViewPos[0] + view.getWidth(), mDropViewPos[1] + view.getHeight());
- mDropViewPos[0] = fromX + (int) (percent * dx + 0.5f);
- mDropViewPos[1] = fromY + (int) (percent * dy + 0.5f);
+ mDropViewPos[0] = fromX + (int) (percent * dX + 0.5f);
+ mDropViewPos[1] = fromY + (int) (percent * dY + 0.5f);
invalidate(mDropViewPos[0], mDropViewPos[1],
mDropViewPos[0] + view.getWidth(), mDropViewPos[1] + view.getHeight());
}
@@ -2415,6 +2400,32 @@ public class Workspace extends SmoothPagedView
mDropAnim.start();
}
+ /*
+ * We should be careful that this method cannot result in any synchronous requestLayout()
+ * calls, as it is called from onLayout().
+ */
+ public void animateViewIntoPosition(final View view) {
+ final CellLayout parent = (CellLayout) view.getParent().getParent();
+ final CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams();
+
+ // Convert the animation params to be relative to the Workspace, not the CellLayout
+ final int fromX = lp.oldX + parent.getLeft() + parent.getLeftPadding();
+ final int fromY = lp.oldY + parent.getTop() + parent.getTopPadding();
+
+ final int dx = lp.x - lp.oldX;
+ final int dy = lp.y - lp.oldY;
+
+ Runnable animationEndRunnable = new Runnable() {
+ public void run() {
+ if (mDropView != null) {
+ mDropView.setVisibility(View.VISIBLE);
+ mDropView = null;
+ }
+ }
+ };
+ animateViewIntoPosition(view, fromX, fromY, dx, dy, animationEndRunnable);
+ }
+
/**
* {@inheritDoc}
*/
@@ -2530,6 +2541,7 @@ public class Workspace extends SmoothPagedView
scrollToNewPageWithoutMovingPages(dragTargetIndex);
}
}
+ CellLayout dropTargetLayout = mDragTargetLayout;
if (d.dragSource != this) {
final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0],
@@ -2541,22 +2553,9 @@ public class Workspace extends SmoothPagedView
((ItemInfo) d.dragInfo).dropPos = touchXY;
return;
}
- onDropExternal(touchXY, d.dragInfo, mDragTargetLayout, false, d.dragView);
+ onDropExternal(touchXY, d.dragInfo, dropTargetLayout, false, d.dragView);
} else if (mDragInfo != null) {
final View cell = mDragInfo.cell;
- CellLayout dropTargetLayout = mDragTargetLayout;
- boolean dropInscrollArea = false;
-
- // Handle the case where the user drops when in the scroll area.
- // This is treated as a drop on the adjacent page.
- if (dropTargetLayout == null && mInScrollArea) {
- dropInscrollArea = true;
- if (mPendingScrollDirection == DragController.SCROLL_LEFT) {
- dropTargetLayout = (CellLayout) getChildAt(mCurrentPage - 1);
- } else if (mPendingScrollDirection == DragController.SCROLL_RIGHT) {
- dropTargetLayout = (CellLayout) getChildAt(mCurrentPage + 1);
- }
- }
if (dropTargetLayout != null) {
// Move internally
@@ -2570,8 +2569,9 @@ public class Workspace extends SmoothPagedView
mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], (int)
mDragViewVisualCenter[1], spanX, spanY, dropTargetLayout, mTargetCell);
// 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.
+ // cell also contains a shortcut, then create a folder with the two shortcuts.
+ boolean dropInscrollArea = mCurrentPage != screen;
+
if (!dropInscrollArea && createUserFolderIfNecessary(cell, dropTargetLayout,
mTargetCell, false)) {
return;
@@ -2588,7 +2588,7 @@ public class Workspace extends SmoothPagedView
(int) mDragViewVisualCenter[1], mDragInfo.spanX, mDragInfo.spanY, cell,
dropTargetLayout, mTargetCell);
- if (screen != mCurrentPage) {
+ if (dropInscrollArea && mShrinkState != ShrinkState.SPRING_LOADED) {
snapToPage(screen);
}
@@ -2600,6 +2600,7 @@ public class Workspace extends SmoothPagedView
mDragInfo.spanY);
}
+
// update the item's position after drop
final ItemInfo info = (ItemInfo) cell.getTag();
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
@@ -2655,7 +2656,7 @@ public class Workspace extends SmoothPagedView
}
}
- private void getViewLocationRelativeToSelf(View v, int[] location) {
+ public void getViewLocationRelativeToSelf(View v, int[] location) {
getLocationOnScreen(location);
int x = location[0];
int y = location[1];
@@ -3113,7 +3114,6 @@ public class Workspace extends SmoothPagedView
if (dragOverView != mLastDragOverView) {
cancelFolderCreation();
if (mLastDragOverView != null && mLastDragOverView instanceof FolderIcon) {
-
((FolderIcon) mLastDragOverView).onDragExit(d.dragInfo);
}
}
@@ -3249,6 +3249,9 @@ public class Workspace extends SmoothPagedView
private void onDropExternal(int[] touchXY, Object dragInfo,
CellLayout cellLayout, boolean insertAtFirst, DragView dragView) {
int screen = indexOfChild(cellLayout);
+ if (screen != mCurrentPage && mShrinkState != ShrinkState.SPRING_LOADED) {
+ snapToPage(screen);
+ }
if (dragInfo instanceof PendingAddItemInfo) {
PendingAddItemInfo info = (PendingAddItemInfo) dragInfo;
// When dragging and dropping from customization tray, we deal with creating
@@ -3452,7 +3455,7 @@ public class Workspace extends SmoothPagedView
if (mDragTargetLayout != null) {
mDragTargetLayout.onDragExit();
- mDragTargetLayout = null;
+ mDragTargetLayout = layout;
}
// In portrait, need to redraw the edge glow when entering the scroll area
if (getHeight() > getWidth()) {