Refactoring common methods
Change-Id: Id6d3072dd3a6d7f54e9591abbeffd9bd51c7403d
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index 72e2891..a3500aa 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -613,11 +613,7 @@
if (lp.cellVSpan < 0) lp.cellVSpan = mCountY;
child.setId(childId);
- if (inLayout) {
- mShortcutsAndWidgets.addView(child, index, lp, true);
- } else {
- mShortcutsAndWidgets.addView(child, index, lp, false);
- }
+ mShortcutsAndWidgets.addView(child, index, lp, inLayout);
if (markCells) markCellsAsOccupiedForView(child);
diff --git a/src/com/android/launcher3/DropTarget.java b/src/com/android/launcher3/DropTarget.java
index 64f0ac8..7ede427 100644
--- a/src/com/android/launcher3/DropTarget.java
+++ b/src/com/android/launcher3/DropTarget.java
@@ -65,6 +65,29 @@
public DragObject() {
}
+
+ /**
+ * This is used to compute the visual center of the dragView. This point is then
+ * used to visualize drop locations and determine where to drop an item. The idea is that
+ * the visual center represents the user's interpretation of where the item is, and hence
+ * is the appropriate point to use when determining drop location.
+ */
+ public final float[] getVisualCenter(float[] recycle) {
+ final float res[] = (recycle == null) ? new float[2] : recycle;
+
+ // These represent the visual top and left of drag view if a dragRect was provided.
+ // If a dragRect was not provided, then they correspond to the actual view left and
+ // top, as the dragRect is in that case taken to be the entire dragView.
+ // R.dimen.dragViewOffsetY.
+ int left = x - xOffset;
+ int top = y - yOffset;
+
+ // In order to find the visual center, we shift by half the dragRect
+ res[0] = left + dragView.getDragRegion().width() / 2;
+ res[1] = top + dragView.getDragRegion().height() / 2;
+
+ return res;
+ }
}
public static class DragEnforcer implements DragController.DragListener {
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index 6925477..786d4a2 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -27,7 +27,6 @@
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Build;
-import android.os.SystemClock;
import android.text.InputType;
import android.text.Selection;
import android.text.Spannable;
@@ -53,7 +52,6 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
/**
* Represents a set of icons chosen by the user or generated by the system.
@@ -704,17 +702,11 @@
}
public void onDragOver(DragObject d) {
- final DragView dragView = d.dragView;
final int scrollOffset = mScrollView.getScrollY();
- final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null);
+ final float[] r = d.getVisualCenter(null);
r[0] -= getPaddingLeft();
r[1] -= getPaddingTop();
- final long downTime = SystemClock.uptimeMillis();
- final MotionEvent translatedEv = MotionEvent.obtain(
- downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0);
-
- translatedEv.recycle();
mTargetCell = mContent.findNearestArea(
(int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell);
if (isLayoutRtl()) {
@@ -730,32 +722,6 @@
}
}
- // This is used to compute the visual center of the dragView. The idea is that
- // the visual center represents the user's interpretation of where the item is, and hence
- // is the appropriate point to use when determining drop location.
- private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
- DragView dragView, float[] recycle) {
- float res[];
- if (recycle == null) {
- res = new float[2];
- } else {
- res = recycle;
- }
-
- // These represent the visual top and left of drag view if a dragRect was provided.
- // If a dragRect was not provided, then they correspond to the actual view left and
- // top, as the dragRect is in that case taken to be the entire dragView.
- // R.dimen.dragViewOffsetY.
- int left = x - xOffset;
- int top = y - yOffset;
-
- // In order to find the visual center, we shift by half the dragRect
- res[0] = left + dragView.getDragRegion().width() / 2;
- res[1] = top + dragView.getDragRegion().height() / 2;
-
- return res;
- }
-
OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
public void onAlarm(Alarm alarm) {
completeDragExit();
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 4e16a45..626154e 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -2831,8 +2831,7 @@
}
if (!transitionStateShouldAllowDrop()) return false;
- mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset,
- d.dragView, mDragViewVisualCenter);
+ mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
// We want the point to be mapped to the dragTarget.
if (mLauncher.isHotseatLayout(dropTargetLayout)) {
@@ -3034,9 +3033,7 @@
}
public void onDrop(final DragObject d) {
- mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView,
- mDragViewVisualCenter);
-
+ mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
CellLayout dropTargetLayout = mDropToLayout;
// We want the point to be mapped to the dragTarget.
@@ -3542,38 +3539,6 @@
return bestMatchingScreen;
}
- // This is used to compute the visual center of the dragView. This point is then
- // used to visualize drop locations and determine where to drop an item. The idea is that
- // the visual center represents the user's interpretation of where the item is, and hence
- // is the appropriate point to use when determining drop location.
- private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
- DragView dragView, float[] recycle) {
- float res[];
- if (recycle == null) {
- res = new float[2];
- } else {
- res = recycle;
- }
-
- // First off, the drag view has been shifted in a way that is not represented in the
- // x and y values or the x/yOffsets. Here we account for that shift.
- x += getResources().getDimensionPixelSize(R.dimen.dragViewOffsetX);
- y += getResources().getDimensionPixelSize(R.dimen.dragViewOffsetY);
-
- // These represent the visual top and left of drag view if a dragRect was provided.
- // If a dragRect was not provided, then they correspond to the actual view left and
- // top, as the dragRect is in that case taken to be the entire dragView.
- // R.dimen.dragViewOffsetY.
- int left = x - xOffset;
- int top = y - yOffset;
-
- // In order to find the visual center, we shift by half the dragRect
- res[0] = left + dragView.getDragRegion().width() / 2;
- res[1] = top + dragView.getDragRegion().height() / 2;
-
- return res;
- }
-
private boolean isDragWidget(DragObject d) {
return (d.dragInfo instanceof LauncherAppWidgetInfo ||
d.dragInfo instanceof PendingAddWidgetInfo);
@@ -3598,8 +3563,7 @@
// Ensure that we have proper spans for the item that we are dropping
if (item.spanX < 0 || item.spanY < 0) throw new RuntimeException("Improper spans found");
- mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset,
- d.dragView, mDragViewVisualCenter);
+ mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
final View child = (mDragInfo == null) ? null : mDragInfo.cell;
// Identify whether we have dragged over a side page