summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2014-05-12 12:44:22 -0700
committerAdam Cohen <adamcohen@google.com>2014-05-12 12:45:59 -0700
commite0aaa0d3de0eedf5501fee762e0d8279a9e3bc3c (patch)
treefeaad50d97aa53db95842f5285ad344d1397fa7a /src
parenta1f26fdb50862abe55f648925d0b07dfd28d8208 (diff)
downloadandroid_packages_apps_Trebuchet-e0aaa0d3de0eedf5501fee762e0d8279a9e3bc3c.tar.gz
android_packages_apps_Trebuchet-e0aaa0d3de0eedf5501fee762e0d8279a9e3bc3c.tar.bz2
android_packages_apps_Trebuchet-e0aaa0d3de0eedf5501fee762e0d8279a9e3bc3c.zip
Remove antiquated way of determining CellInfo during long press
-> allows us to eliminate cast of getTag() to CellInfo to fix issue 13587508 Change-Id: Id2277206765621f664b758cce800bf8423231b1e
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/CellLayout.java96
-rw-r--r--src/com/android/launcher3/Launcher.java17
2 files changed, 17 insertions, 96 deletions
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index 2436a51a3..8ca8d9105 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -76,9 +76,6 @@ public class CellLayout extends ViewGroup {
private boolean mScrollingTransformsDirty = false;
private boolean mDropPending = false;
- private final Rect mRect = new Rect();
- private final CellInfo mCellInfo = new CellInfo();
-
// 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[] mTmpXY = new int[2];
@@ -699,103 +696,20 @@ public class CellLayout extends ViewGroup {
}
@Override
- protected void onAttachedToWindow() {
- super.onAttachedToWindow();
- if (getParent() instanceof Workspace) {
- Workspace workspace = (Workspace) getParent();
- mCellInfo.screenId = workspace.getIdForScreen(this);
- }
- }
-
- public void setTagToCellInfoForPoint(int touchX, int touchY) {
- final CellInfo cellInfo = mCellInfo;
- Rect frame = mRect;
- final int x = touchX + getScrollX();
- final int y = touchY + getScrollY();
- final int count = mShortcutsAndWidgets.getChildCount();
-
- boolean found = false;
- for (int i = count - 1; i >= 0; i--) {
- final View child = mShortcutsAndWidgets.getChildAt(i);
- final LayoutParams lp = (LayoutParams) child.getLayoutParams();
-
- if ((child.getVisibility() == VISIBLE || child.getAnimation() != null) &&
- lp.isLockedToGrid) {
- child.getHitRect(frame);
-
- float scale = child.getScaleX();
- frame = new Rect(child.getLeft(), child.getTop(), child.getRight(),
- child.getBottom());
- // 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.
- frame.offset(getPaddingLeft(), getPaddingTop());
- frame.inset((int) (frame.width() * (1f - scale) / 2),
- (int) (frame.height() * (1f - scale) / 2));
-
- if (frame.contains(x, y)) {
- cellInfo.cell = child;
- cellInfo.cellX = lp.cellX;
- cellInfo.cellY = lp.cellY;
- cellInfo.spanX = lp.cellHSpan;
- cellInfo.spanY = lp.cellVSpan;
- found = true;
- break;
- }
- }
- }
-
- mLastDownOnOccupiedCell = found;
-
- if (!found) {
- final int cellXY[] = mTmpXY;
- pointToCellExact(x, y, cellXY);
-
- cellInfo.cell = null;
- cellInfo.cellX = cellXY[0];
- cellInfo.cellY = cellXY[1];
- cellInfo.spanX = 1;
- cellInfo.spanY = 1;
- }
- setTag(cellInfo);
- }
-
- @Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// First we clear the tag to ensure that on every touch down we start with a fresh slate,
// even in the case where we return early. Not clearing here was causing bugs whereby on
// long-press we'd end up picking up an item from a previous drag operation.
final int action = ev.getAction();
- if (action == MotionEvent.ACTION_DOWN) {
- clearTagCellInfo();
- }
if (mInterceptTouchListener != null && mInterceptTouchListener.onTouch(this, ev)) {
return true;
}
- if (action == MotionEvent.ACTION_DOWN) {
- setTagToCellInfoForPoint((int) ev.getX(), (int) ev.getY());
- }
-
return false;
}
- private void clearTagCellInfo() {
- final CellInfo cellInfo = mCellInfo;
- cellInfo.cell = null;
- cellInfo.cellX = -1;
- cellInfo.cellY = -1;
- cellInfo.spanX = 0;
- cellInfo.spanY = 0;
- setTag(cellInfo);
- }
-
- public CellInfo getTag() {
- return (CellInfo) super.getTag();
- }
-
/**
* Given a point, return the cell that strictly encloses that point
* @param x X coordinate of the point
@@ -3360,6 +3274,16 @@ out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) {
long screenId;
long container;
+ CellInfo(View v, ItemInfo info) {
+ cell = v;
+ cellX = info.cellX;
+ cellY = info.cellY;
+ spanX = info.spanX;
+ spanY = info.spanY;
+ screenId = info.screenId;
+ container = info.container;
+ }
+
@Override
public String toString() {
return "Cell[view=" + (cell == null ? "null" : cell.getClass())
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index c9dd56041..b97ced702 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2859,20 +2859,17 @@ public class Launcher extends Activity
}
}
- if (!(v instanceof CellLayout)) {
- v = (View) v.getParent().getParent();
- }
-
- resetAddInfo();
- CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
- // This happens when long clicking an item with the dpad/trackball
- if (longClickCellInfo == null) {
- return true;
+ CellLayout.CellInfo longClickCellInfo = null;
+ View itemUnderLongClick = null;
+ if (v.getTag() instanceof ItemInfo) {
+ ItemInfo info = (ItemInfo) v.getTag();
+ longClickCellInfo = new CellLayout.CellInfo(v, info);;
+ itemUnderLongClick = longClickCellInfo.cell;
+ resetAddInfo();
}
// The hotseat touch handling does not go through Workspace, and we always allow long press
// on hotseat items.
- final View itemUnderLongClick = longClickCellInfo.cell;
final boolean inHotseat = isHotseatLayout(v);
boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
if (allowLongPress && !mDragController.isDragging()) {