diff options
Diffstat (limited to 'src/com/android/launcher2/CellLayout.java')
-rw-r--r-- | src/com/android/launcher2/CellLayout.java | 83 |
1 files changed, 55 insertions, 28 deletions
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index 97d9bc1b5..fe69e9fd0 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -162,6 +162,7 @@ public class CellLayout extends ViewGroup { private final static PorterDuffXfermode sAddBlendMode = new PorterDuffXfermode(PorterDuff.Mode.ADD); + private final static Paint sPaint = new Paint(); public CellLayout(Context context) { this(context, null); @@ -305,7 +306,15 @@ public class CellLayout extends ViewGroup { } public void enableHardwareLayers() { - mShortcutsAndWidgets.enableHardwareLayers(); + mShortcutsAndWidgets.setLayerType(LAYER_TYPE_HARDWARE, sPaint); + } + + public void disableHardwareLayers() { + mShortcutsAndWidgets.setLayerType(LAYER_TYPE_NONE, sPaint); + } + + public void buildHardwareLayer() { + mShortcutsAndWidgets.buildLayer(); } public void setGridSize(int x, int y) { @@ -1088,7 +1097,7 @@ public class CellLayout extends ViewGroup { return true; } - ValueAnimator va = ValueAnimator.ofFloat(0f, 1f); + ValueAnimator va = LauncherAnimUtils.ofFloat(0f, 1f); va.setDuration(duration); mReorderAnimators.put(lp, va); @@ -1536,7 +1545,6 @@ public class CellLayout extends ViewGroup { int x = cellX + direction[0]; int y = cellY + direction[1]; while (x >= 0 && x + spanX <= mCountX && y >= 0 && y + spanY <= mCountY) { - boolean fail = false; for (int i = 0; i < spanX; i++) { for (int j = 0; j < spanY; j++) { @@ -1579,8 +1587,9 @@ public class CellLayout extends ViewGroup { return success; } - // This method looks in the specified direction to see if there is an additional view - // immediately adjecent in that direction + // This method looks in the specified direction to see if there are additional views adjacent + // to the current set of views in the. If there is, then these views are added to the current + // set of views. This is performed iteratively, giving a cascading push behaviour. private boolean addViewInDirection(ArrayList<View> views, Rect boundingRect, int[] direction, boolean[][] occupied, View dragView, ItemConfiguration currentState) { boolean found = false; @@ -1589,23 +1598,27 @@ public class CellLayout extends ViewGroup { Rect r0 = new Rect(boundingRect); Rect r1 = new Rect(); + // First, we consider the rect of the views that we are trying to translate int deltaX = 0; int deltaY = 0; if (direction[1] < 0) { - r0.set(r0.left, r0.top - 1, r0.right, r0.bottom); + r0.set(r0.left, r0.top - 1, r0.right, r0.bottom - 1); deltaY = -1; } else if (direction[1] > 0) { - r0.set(r0.left, r0.top, r0.right, r0.bottom + 1); + r0.set(r0.left, r0.top + 1, r0.right, r0.bottom + 1); deltaY = 1; } else if (direction[0] < 0) { - r0.set(r0.left - 1, r0.top, r0.right, r0.bottom); + r0.set(r0.left - 1, r0.top, r0.right - 1, r0.bottom); deltaX = -1; } else if (direction[0] > 0) { - r0.set(r0.left, r0.top, r0.right + 1, r0.bottom); + r0.set(r0.left + 1, r0.top, r0.right + 1, r0.bottom); deltaX = 1; } + // Now we see which views, if any, are being overlapped by shifting the current group + // of views in the desired direction. for (int i = 0; i < childCount; i++) { + // We don't need to worry about views already in our group, or the current drag view. View child = mShortcutsAndWidgets.getChildAt(i); if (views.contains(child) || child == dragView) continue; CellAndSpan c = currentState.map.get(child); @@ -1616,20 +1629,30 @@ public class CellLayout extends ViewGroup { if (!lp.canReorder) { return false; } - boolean pushed = false; - for (int x = c.x; x < c.x + c.spanX; x++) { - for (int y = c.y; y < c.y + c.spanY; y++) { - boolean inBounds = x - deltaX >= 0 && x -deltaX < mCountX - && y - deltaY >= 0 && y - deltaY < mCountY; - if (inBounds && occupied[x - deltaX][y - deltaY]) { - pushed = true; + // First we verify that the view in question is at the border of the extents + // of the block of items we are pushing + if ((direction[0] < 0 && c.x == r0.left) || + (direction[0] > 0 && c.x == r0.right - 1) || + (direction[1] < 0 && c.y == r0.top) || + (direction[1] > 0 && c.y == r0.bottom - 1)) { + boolean pushed = false; + // Since the bounding rect is a course description of the region (there can + // be holes at the edge of the block), we need to check to verify that a solid + // piece is intersecting. This ensures that interlocking is possible. + for (int x = c.x; x < c.x + c.spanX; x++) { + for (int y = c.y; y < c.y + c.spanY; y++) { + if (occupied[x - deltaX][y - deltaY]) { + pushed = true; + break; + } + if (pushed) break; } } - } - if (pushed) { - views.add(child); - boundingRect.union(c.x, c.y, c.x + c.spanX, c.y + c.spanY); - found = true; + if (pushed) { + views.add(child); + boundingRect.union(c.x, c.y, c.x + c.spanX, c.y + c.spanY); + found = true; + } } } } @@ -1670,7 +1693,7 @@ public class CellLayout extends ViewGroup { int top = boundingRect.top; int left = boundingRect.left; // We mark more precisely which parts of the bounding rect are truly occupied, allowing - // for tetris-style interlocking. + // for interlocking. for (View v: dup) { CellAndSpan c = currentState.map.get(v); markCellsForView(c.x - left, c.y - top, c.spanX, c.spanY, blockOccupied, true); @@ -2070,7 +2093,7 @@ public class CellLayout extends ViewGroup { if (finalDeltaX == 0 && finalDeltaY == 0) { return; } - ValueAnimator va = ValueAnimator.ofFloat(0f, 1f); + ValueAnimator va = LauncherAnimUtils.ofFloat(0f, 1f); a = va; va.setRepeatMode(ValueAnimator.REVERSE); va.setRepeatCount(ValueAnimator.INFINITE); @@ -2112,13 +2135,13 @@ public class CellLayout extends ViewGroup { a.cancel(); } - AnimatorSet s = new AnimatorSet(); + AnimatorSet s = LauncherAnimUtils.createAnimatorSet(); a = s; s.playTogether( - ObjectAnimator.ofFloat(child, "scaleX", 1f), - ObjectAnimator.ofFloat(child, "scaleY", 1f), - ObjectAnimator.ofFloat(child, "translationX", 0f), - ObjectAnimator.ofFloat(child, "translationY", 0f) + LauncherAnimUtils.ofFloat(child, "scaleX", 1f), + LauncherAnimUtils.ofFloat(child, "scaleY", 1f), + LauncherAnimUtils.ofFloat(child, "translationX", 0f), + LauncherAnimUtils.ofFloat(child, "translationY", 0f) ); s.setDuration(REORDER_ANIMATION_DURATION); s.setInterpolator(new android.view.animation.DecelerateInterpolator(1.5f)); @@ -2147,6 +2170,10 @@ public class CellLayout extends ViewGroup { // We do a null check here because the item info can be null in the case of the // AllApps button in the hotseat. if (info != null) { + if (info.cellX != lp.tmpCellX || info.cellY != lp.tmpCellY || + info.spanX != lp.cellHSpan || info.spanY != lp.cellVSpan) { + info.requiresDbUpdate = true; + } info.cellX = lp.cellX = lp.tmpCellX; info.cellY = lp.cellY = lp.tmpCellY; info.spanX = lp.cellHSpan; |