summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2/CellLayout.java
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2011-04-15 12:07:39 -0700
committerAdam Cohen <adamcohen@google.com>2011-04-15 13:29:26 -0700
commite3e27a854f3eca363d3c5ce353d19de475272d87 (patch)
tree5a627c3aa3869bd2c97e7945b0b19be9966b6fb3 /src/com/android/launcher2/CellLayout.java
parentdf0353815c629fc678824b07a234b89a1ff94208 (diff)
downloadandroid_packages_apps_Trebuchet-e3e27a854f3eca363d3c5ce353d19de475272d87.tar.gz
android_packages_apps_Trebuchet-e3e27a854f3eca363d3c5ce353d19de475272d87.tar.bz2
android_packages_apps_Trebuchet-e3e27a854f3eca363d3c5ce353d19de475272d87.zip
Cleaning up drag and drop visulization and drop location determination
-Visualization and drop location always match now -Improved the location determination/visualization for widgets in spring loaded mode -Simplified and fixed some other discrepencies Change-Id: I4b46f415a547e4df778c70a8b87f341a909d10c1
Diffstat (limited to 'src/com/android/launcher2/CellLayout.java')
-rw-r--r--src/com/android/launcher2/CellLayout.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index ac9d54d65..9cb963c02 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -736,6 +736,22 @@ public class CellLayout extends ViewGroup {
result[1] = vStartPadding + cellY * (mCellHeight + mHeightGap);
}
+ /**
+ * Given a cell coordinate, return the point that represents the upper left corner of that cell
+ *
+ * @param cellX X coordinate of the cell
+ * @param cellY Y coordinate of the cell
+ *
+ * @param result Array of 2 ints to hold the x and y coordinate of the point
+ */
+ void cellToCenterPoint(int cellX, int cellY, int[] result) {
+ final int hStartPadding = getLeftPadding();
+ final int vStartPadding = getTopPadding();
+
+ result[0] = hStartPadding + cellX * (mCellWidth + mWidthGap) + mCellWidth / 2;
+ result[1] = vStartPadding + cellY * (mCellHeight + mHeightGap) + mCellHeight / 2;
+ }
+
int getCellWidth() {
return mCellWidth;
}
@@ -1021,6 +1037,12 @@ public class CellLayout extends ViewGroup {
// mark space take by ignoreView as available (method checks if ignoreView is null)
markCellsAsUnoccupiedForView(ignoreView);
+ // For items with a spanX / spanY > 1, the passed in point (pixelX, pixelY) corresponds
+ // to the center of the item, but we are searching based on the top-left cell, so
+ // we translate the point over to correspond to the top-left.
+ pixelX -= (mCellWidth + mWidthGap) * (spanX - 1) / 2f;
+ pixelY -= (mCellHeight + mHeightGap) * (spanY - 1) / 2f;
+
// Keep track of best-scoring drop area
final int[] bestXY = result != null ? result : new int[2];
double bestDistance = Double.MAX_VALUE;
@@ -1045,7 +1067,7 @@ public class CellLayout extends ViewGroup {
}
}
final int[] cellXY = mTmpCellXY;
- cellToPoint(x, y, cellXY);
+ cellToCenterPoint(x, y, cellXY);
double distance = Math.sqrt(Math.pow(cellXY[0] - pixelX, 2)
+ Math.pow(cellXY[1] - pixelY, 2));