summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorMichael Jurka <mikejurka@google.com>2010-10-14 15:35:17 -0700
committerMichael Jurka <mikejurka@google.com>2010-10-14 15:45:30 -0700
commitd718d6a7ba424b600052a147e5633a201a04ccb7 (patch)
treeaa7fbc5e110fc359bfac46a90a6b78c855c5df09 /src/com
parent7a75bd48bf1d7ab4bc6f288a411467879be10b05 (diff)
downloadandroid_packages_apps_Trebuchet-d718d6a7ba424b600052a147e5633a201a04ccb7.tar.gz
android_packages_apps_Trebuchet-d718d6a7ba424b600052a147e5633a201a04ccb7.tar.bz2
android_packages_apps_Trebuchet-d718d6a7ba424b600052a147e5633a201a04ccb7.zip
fix setting/unsetting hover on thumbnailed screens
cleaned up dragenter / dragexit events so they're only received by CellLayouts if the workspace isn't small ignoring enter/exit scrollarea events when workspace is small
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/launcher2/CellLayout.java2
-rw-r--r--src/com/android/launcher2/Workspace.java219
2 files changed, 106 insertions, 115 deletions
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index c7c850b65..57953c0e7 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -1088,8 +1088,6 @@ public class CellLayout extends ViewGroup implements Dimmable {
mDragCell[0] = -1;
mDragCell[1] = -1;
- setHover(false);
-
// Fade out the drag indicators
if (mCrosshairsAnimator != null) {
mCrosshairsAnimator.animateOut();
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 4de182218..1b6b1396e 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -1048,50 +1048,46 @@ public class Workspace extends SmoothPagedView
public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
- CellLayout cellLayout;
+ if (mDragTargetLayout == null) {
+ // cancel the drag if we're not over a screen at time of drop
+ // TODO: maybe add a nice fade here?
+ return;
+ }
int originX = x - xOffset;
int originY = y - yOffset;
if (mIsSmall || mIsInUnshrinkAnimation) {
- cellLayout = findMatchingPageForDragOver(dragView, originX, originY, xOffset, yOffset);
- if (cellLayout == null) {
- // cancel the drag if we're not over a mini-screen at time of drop
- // TODO: maybe add a nice fade here?
- return;
- }
// get originX and originY in the local coordinate system of the screen
mTempOriginXY[0] = originX;
mTempOriginXY[1] = originY;
- mapPointFromSelfToChild(cellLayout, mTempOriginXY);
+ mapPointFromSelfToChild(mDragTargetLayout, mTempOriginXY);
originX = (int)mTempOriginXY[0];
originY = (int)mTempOriginXY[1];
- } else {
- cellLayout = getCurrentDropLayout();
}
if (source != this) {
- onDropExternal(originX, originY, dragInfo, cellLayout);
+ onDropExternal(originX, originY, dragInfo, mDragTargetLayout);
} else {
// Move internally
if (mDragInfo != null) {
final View cell = mDragInfo.cell;
mTargetCell = findNearestVacantArea(originX, originY,
- mDragInfo.spanX, mDragInfo.spanY, cell, cellLayout,
+ mDragInfo.spanX, mDragInfo.spanY, cell, mDragTargetLayout,
mTargetCell);
- int screen = indexOfChild(cellLayout);
+ int screen = indexOfChild(mDragTargetLayout);
if (screen != mDragInfo.screen) {
final CellLayout originalCellLayout = (CellLayout) getChildAt(mDragInfo.screen);
originalCellLayout.removeView(cell);
addInScreen(cell, screen, mTargetCell[0], mTargetCell[1],
mDragInfo.spanX, mDragInfo.spanY);
}
- cellLayout.onDropChild(cell);
+ mDragTargetLayout.onDropChild(cell);
// update the item's position after drop
final ItemInfo info = (ItemInfo) cell.getTag();
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
- cellLayout.onMove(cell, mTargetCell[0], mTargetCell[1]);
+ mDragTargetLayout.onMove(cell, mTargetCell[0], mTargetCell[1]);
lp.cellX = mTargetCell[0];
lp.cellY = mTargetCell[1];
cell.setId(LauncherModel.getCellLayoutChildId(-1, mDragInfo.screen,
@@ -1106,15 +1102,17 @@ public class Workspace extends SmoothPagedView
public void onDragEnter(DragSource source, int x, int y, int xOffset,
int yOffset, DragView dragView, Object dragInfo) {
- getCurrentDropLayout().onDragEnter(dragView);
- showOutlines();
+ if (!mIsSmall) {
+ getCurrentDropLayout().onDragEnter(dragView);
+ showOutlines();
+ }
}
public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
if (mIsSmall || mIsInUnshrinkAnimation) {
- // If we're shrunken, don't let anyone drag on folders/etc that are on the mini-screens
+ // If we're shrunken, don't let anyone drag on folders/etc that are on the mini-screens
return null;
}
// We may need to delegate the drag to a child view. If a 1x1 item
@@ -1167,7 +1165,7 @@ public class Workspace extends SmoothPagedView
* coordinate space. The argument xy is modified with the return result.
*
* if cachedInverseMatrix is not null, this method will just use that matrix instead of
- * computing it itself; we use this to avoid redudant matrix inversions in
+ * computing it itself; we use this to avoid redundant matrix inversions in
* findMatchingPageForDragOver
*
*/
@@ -1292,87 +1290,79 @@ public class Workspace extends SmoothPagedView
}
}
}
-
- if (bestMatchingScreen != mDragTargetLayout) {
- if (mDragTargetLayout != null) {
- mDragTargetLayout.onDragExit();
- }
- mDragTargetLayout = bestMatchingScreen;
- // TODO: Should we be calling mDragTargetLayout.onDragEnter() here?
- }
return bestMatchingScreen;
}
public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
- CellLayout currentLayout;
- int originX = x - xOffset;
- int originY = y - yOffset;
- if (mIsSmall || mIsInUnshrinkAnimation) {
- currentLayout = findMatchingPageForDragOver(
- dragView, originX, originY, xOffset, yOffset);
-
- if (currentLayout == null) {
- return;
- }
-
- currentLayout.setHover(true);
- // get originX and originY in the local coordinate system of the screen
- mTempOriginXY[0] = originX;
- mTempOriginXY[1] = originY;
- mapPointFromSelfToChild(currentLayout, mTempOriginXY);
- originX = (int)mTempOriginXY[0];
- originY = (int)mTempOriginXY[1];
- } else {
- currentLayout = getCurrentDropLayout();
- }
-
- final ItemInfo item = (ItemInfo)dragInfo;
-
- if (dragInfo instanceof LauncherAppWidgetInfo) {
- LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo)dragInfo;
-
- if (widgetInfo.spanX == -1) {
- // Calculate the grid spans needed to fit this widget
- int[] spans = currentLayout.rectToCell(widgetInfo.minWidth, widgetInfo.minHeight, null);
- item.spanX = spans[0];
- item.spanY = spans[1];
- }
- }
-
- if (source instanceof AllAppsPagedView) {
- // This is a hack to fix the point used to determine which cell an icon from the all
- // apps screen is over
- if (item != null && item.spanX == 1 && currentLayout != null) {
- int dragRegionLeft = (dragView.getWidth() - currentLayout.getCellWidth()) / 2;
+ // When touch is inside the scroll area, skip dragOver actions for the current screen
+ if (!mInScrollArea) {
+ CellLayout layout;
+ int originX = x - xOffset;
+ int originY = y - yOffset;
+ if (mIsSmall || mIsInUnshrinkAnimation) {
+ layout = findMatchingPageForDragOver(
+ dragView, originX, originY, xOffset, yOffset);
+
+ if (layout != mDragTargetLayout) {
+ if (mDragTargetLayout != null) {
+ mDragTargetLayout.setHover(false);
+ }
+ mDragTargetLayout = layout;
+ if (mDragTargetLayout != null) {
+ mDragTargetLayout.setHover(true);
+ }
+ }
+ } else {
+ layout = getCurrentDropLayout();
+
+ final ItemInfo item = (ItemInfo)dragInfo;
+ if (dragInfo instanceof LauncherAppWidgetInfo) {
+ LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo)dragInfo;
+
+ if (widgetInfo.spanX == -1) {
+ // Calculate the grid spans needed to fit this widget
+ int[] spans = layout.rectToCell(
+ widgetInfo.minWidth, widgetInfo.minHeight, null);
+ item.spanX = spans[0];
+ item.spanY = spans[1];
+ }
+ }
- originX += dragRegionLeft - dragView.getDragRegionLeft();
- if (dragView.getDragRegionWidth() != currentLayout.getCellWidth()) {
- dragView.setDragRegion(dragView.getDragRegionLeft(), dragView.getDragRegionTop(),
- currentLayout.getCellWidth(), dragView.getDragRegionHeight());
+ if (source instanceof AllAppsPagedView) {
+ // This is a hack to fix the point used to determine which cell an icon from
+ // the all apps screen is over
+ if (item != null && item.spanX == 1 && layout != null) {
+ int dragRegionLeft = (dragView.getWidth() - layout.getCellWidth()) / 2;
+
+ originX += dragRegionLeft - dragView.getDragRegionLeft();
+ if (dragView.getDragRegionWidth() != layout.getCellWidth()) {
+ dragView.setDragRegion(dragView.getDragRegionLeft(),
+ dragView.getDragRegionTop(),
+ layout.getCellWidth(),
+ dragView.getDragRegionHeight());
+ }
+ }
}
- }
- }
- // When touch is inside the scroll area, skip dragOver actions for the current screen
- if (!mInScrollArea) {
- if (currentLayout != mDragTargetLayout) {
- if (mDragTargetLayout != null) {
- mDragTargetLayout.onDragExit();
+ if (layout != mDragTargetLayout) {
+ if (mDragTargetLayout != null) {
+ mDragTargetLayout.onDragExit();
+ }
+ layout.onDragEnter(dragView);
+ mDragTargetLayout = layout;
}
- currentLayout.onDragEnter(dragView);
- mDragTargetLayout = currentLayout;
- }
- // only visualize the drop locations for moving icons within the home screen on tablet
- // on phone, we also visualize icons dragged in from All Apps
- if ((!LauncherApplication.isScreenXLarge() || source == this)
- && mDragTargetLayout != null) {
- final View child = (mDragInfo == null) ? null : mDragInfo.cell;
- int localOriginX = originX - (mDragTargetLayout.getLeft() - mScrollX);
- int localOriginY = originY - (mDragTargetLayout.getTop() - mScrollY);
- mDragTargetLayout.visualizeDropLocation(
- child, mDragOutline, localOriginX, localOriginY, item.spanX, item.spanY);
+ // only visualize the drop locations for moving icons within the home screen on
+ // tablet on phone, we also visualize icons dragged in from All Apps
+ if ((!LauncherApplication.isScreenXLarge() || source == this)
+ && mDragTargetLayout != null) {
+ final View child = (mDragInfo == null) ? null : mDragInfo.cell;
+ int localOriginX = originX - (mDragTargetLayout.getLeft() - mScrollX);
+ int localOriginY = originY - (mDragTargetLayout.getTop() - mScrollY);
+ mDragTargetLayout.visualizeDropLocation(child, mDragOutline,
+ localOriginX, localOriginY, item.spanX, item.spanY);
+ }
}
}
}
@@ -1485,6 +1475,8 @@ public class Workspace extends SmoothPagedView
* screen while a scroll is in progress.
*/
private CellLayout getCurrentDropLayout() {
+ // if we're currently small, use findMatchingPageForDragOver instead
+ if (mIsSmall) return null;
int index = mScroller.isFinished() ? mCurrentPage : mNextPage;
return (CellLayout) getChildAt(index);
}
@@ -1504,24 +1496,21 @@ public class Workspace extends SmoothPagedView
*/
public boolean acceptDrop(DragSource source, int x, int y,
int xOffset, int yOffset, DragView dragView, Object dragInfo) {
- CellLayout layout;
- if (mIsSmall || mIsInUnshrinkAnimation) {
- layout = findMatchingPageForDragOver(
- dragView, x - xOffset, y - yOffset, xOffset, yOffset);
- if (layout == null) {
- // cancel the drag if we're not over a mini-screen at time of drop
- return false;
- }
- } else {
- layout = getCurrentDropLayout();
+ // call onDragOver one more time, in case the current layout has changed
+ onDragOver(source, x, y, xOffset, yOffset, dragView, dragInfo);
+
+ if (mDragTargetLayout == null) {
+ // cancel the drag if we're not over a screen at time of drop
+ return false;
}
+
final CellLayout.CellInfo dragCellInfo = mDragInfo;
final int spanX = dragCellInfo == null ? 1 : dragCellInfo.spanX;
final int spanY = dragCellInfo == null ? 1 : dragCellInfo.spanY;
final View ignoreView = dragCellInfo == null ? null : dragCellInfo.cell;
- if (layout.findCellForSpanIgnoring(null, spanX, spanY, ignoreView)) {
+ if (mDragTargetLayout.findCellForSpanIgnoring(null, spanX, spanY, ignoreView)) {
return true;
} else {
mLauncher.showOutOfSpaceMessage();
@@ -1608,24 +1597,28 @@ public class Workspace extends SmoothPagedView
@Override
public void onEnterScrollArea(int direction) {
- mInScrollArea = true;
- final int screen = getCurrentPage() + ((direction == DragController.SCROLL_LEFT) ? -1 : 1);
- if (0 <= screen && screen < getChildCount()) {
- ((CellLayout) getChildAt(screen)).setHover(true);
- }
+ if (!mIsSmall && !mIsInUnshrinkAnimation) {
+ mInScrollArea = true;
+ final int screen = getCurrentPage() + ((direction == DragController.SCROLL_LEFT) ? -1 : 1);
+ if (0 <= screen && screen < getChildCount()) {
+ ((CellLayout) getChildAt(screen)).setHover(true);
+ }
- if (mDragTargetLayout != null) {
- mDragTargetLayout.onDragExit();
- mDragTargetLayout = null;
+ if (mDragTargetLayout != null) {
+ mDragTargetLayout.onDragExit();
+ mDragTargetLayout = null;
+ }
}
}
@Override
public void onExitScrollArea() {
- mInScrollArea = false;
- final int childCount = getChildCount();
- for (int i = 0; i < childCount; i++) {
- ((CellLayout) getChildAt(i)).setHover(false);
+ if (mInScrollArea) {
+ mInScrollArea = false;
+ final int childCount = getChildCount();
+ for (int i = 0; i < childCount; i++) {
+ ((CellLayout) getChildAt(i)).setHover(false);
+ }
}
}