Fixing long-press issue due to child hit-rect offset.
- Removing some unused code
Change-Id: I875e3b27372c4c507e4bbc2d36b16eba077e2121
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 5f848a8..f189cd5 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -71,7 +71,7 @@
// These are temporary variables to prevent having to allocate a new object just to
// return an (x, y) value from helper functions. Do NOT use them to maintain other state.
- private final int[] mTmpCellXY = new int[2];
+ private final int[] mTmpXY = new int[2];
private final int[] mTmpPoint = new int[2];
private final PointF mTmpPointF = new PointF();
@@ -694,6 +694,14 @@
if ((child.getVisibility() == VISIBLE || child.getAnimation() != null) &&
lp.isLockedToGrid) {
child.getHitRect(frame);
+
+ // The child hit rect is relative to the CellLayoutChildren parent, so we need to
+ // offset that by this CellLayout's padding to test an (x,y) point that is relative
+ // to this view.
+ final int tmpXY[] = mTmpXY;
+ child.getLocationOnScreen(tmpXY);
+ frame.offset(mLeftPadding, mTopPadding);
+
if (frame.contains(x, y)) {
cellInfo.cell = child;
cellInfo.cellX = lp.cellX;
@@ -708,7 +716,7 @@
}
if (!found) {
- final int cellXY[] = mTmpCellXY;
+ final int cellXY[] = mTmpXY;
pointToCellExact(x, y, cellXY);
cellInfo.cell = null;
@@ -1161,7 +1169,7 @@
}
}
}
- final int[] cellXY = mTmpCellXY;
+ final int[] cellXY = mTmpXY;
cellToCenterPoint(x, y, cellXY);
double distance = Math.sqrt(Math.pow(cellXY[0] - pixelX, 2)