From 047379aa61b4719ab38ce595f23732e8f3b1b8e1 Mon Sep 17 00:00:00 2001 From: Patrick Dubroy Date: Sun, 19 Dec 2010 22:02:04 -0800 Subject: [PATCH] Don't animate tapped item if the target screen is full --- src/com/android/launcher2/CellLayout.java | 36 ++++++++++++------- .../android/launcher2/CustomizePagedView.java | 16 ++++----- src/com/android/launcher2/Workspace.java | 7 ---- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index ef4637ee57..505d46504a 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -908,19 +908,6 @@ public class CellLayout extends ViewGroup implements Dimmable { return null; } - /** - * Estimate the size that a child with the given dimensions will take in the layout. - */ - void estimateChildSize(int minWidth, int minHeight, int[] result) { - // Assuming it's placed at 0, 0, find where the bottom right cell will land - rectToCell(minWidth, minHeight, result); - - // Then figure out the rect it will occupy - cellToRect(0, 0, result[0], result[1], mRectF); - result[0] = (int)mRectF.width(); - result[1] = (int)mRectF.height(); - } - /** * Estimate where the top left cell of the dragged item will land if it is dropped. * @@ -1321,6 +1308,29 @@ public class CellLayout extends ViewGroup implements Dimmable { return result; } + /** + * Calculate the grid spans needed to fit given item + */ + public void calculateSpans(ItemInfo info) { + final int minWidth; + final int minHeight; + + if (info instanceof LauncherAppWidgetInfo) { + minWidth = ((LauncherAppWidgetInfo) info).minWidth; + minHeight = ((LauncherAppWidgetInfo) info).minHeight; + } else if (info instanceof PendingAddWidgetInfo) { + minWidth = ((PendingAddWidgetInfo) info).minWidth; + minHeight = ((PendingAddWidgetInfo) info).minHeight; + } else { + // It's not a widget, so it must be 1x1 + info.spanX = info.spanY = 1; + return; + } + int[] spans = rectToCell(minWidth, minHeight, null); + info.spanX = spans[0]; + info.spanY = spans[1]; + } + /** * Find the first vacant cell, if there is one. * diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java index 5672921723..4eb852c60a 100644 --- a/src/com/android/launcher2/CustomizePagedView.java +++ b/src/com/android/launcher2/CustomizePagedView.java @@ -21,7 +21,7 @@ import com.android.launcher.R; import org.xmlpull.v1.XmlPullParser; import android.animation.Animator; -import android.animation.Animator.AnimatorListener; +import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.animation.TimeInterpolator; @@ -40,7 +40,6 @@ import android.content.res.XmlResourceParser; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; @@ -378,11 +377,7 @@ public class CustomizePagedView extends PagedViewWithDraggableItems posAnim.setInterpolator(mQuintEaseOutInterpolator); posAnim.setDuration(ANIMATION_DURATION); - posAnim.addListener(new AnimatorListener() { - public void onAnimationCancel(Animator animation) {} - public void onAnimationRepeat(Animator animation) {} - public void onAnimationStart(Animator animation) {} - + posAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { dragLayer.removeView(dragCopy); mLauncher.addExternalItemToScreen(info, layout); @@ -443,7 +438,12 @@ public class CustomizePagedView extends PagedViewWithDraggableItems animateClickFeedback(v, new Runnable() { @Override public void run() { - animateItemOntoScreen(dragView, cl, itemInfo); + cl.calculateSpans(itemInfo); + if (cl.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY)) { + animateItemOntoScreen(dragView, cl, itemInfo); + } else { + mLauncher.showOutOfSpaceMessage(); + } } }); return; diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 0268378af4..eaa09ac803 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -2217,13 +2217,6 @@ public class Workspace extends SmoothPagedView localPixelX, localPixelY, spanX, spanY, ignoreView, recycle); } - /** - * Estimate the size that a child with the given dimensions will take in the current screen. - */ - void estimateChildSize(int minWidth, int minHeight, int[] result) { - ((CellLayout)getChildAt(mCurrentPage)).estimateChildSize(minWidth, minHeight, result); - } - void setLauncher(Launcher launcher) { mLauncher = launcher; mSpringLoadedDragController = new SpringLoadedDragController(mLauncher);