Refactor / Cleanup / Simplify a bunch of dnd related rendering / animation

Addresses:
=> Fix folder icon drop location mapping (was very far off)
=> Fix BubbleTextView drop animation shifted by a few pixels
=> Get rid multiple unnecessary calls to setDragMode(none), was breaking
   some of the reorder flow; still some issues to address here.
=> Fix folder icon parallax (didn't work when the folder had a dot)

Test: manual

Change-Id: I5959cf341996f75d30212353ec096ed25bf40ea5
This commit is contained in:
Adam Cohen committed 2020-03-21 01:26:09 +00:00
1 parent 0465b4d71e
commit 650869973a
16 files changed
+355 -274

No files matched your search

+65 -50
View File
@@ -58,6 +58,7 @@ import com.android.launcher3.accessibility.WorkspaceAccessibilityHelper;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.anim.PropertyListBuilder;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DraggableView;
import com.android.launcher3.folder.PreviewBackground;
import com.android.launcher3.graphics.DragPreviewProvider;
import com.android.launcher3.graphics.RotationMode;
@@ -105,6 +106,11 @@ public class CellLayout extends ViewGroup implements Transposable {
@Thunk final int[] mTmpPoint = new int[2];
@Thunk final int[] mTempLocation = new int[2];
// Used to visualize / debug the Grid of the CellLayout
private static final boolean VISUALIZE_GRID = false;
private Rect mVisualizeGridRect = new Rect();
private Paint mVisualizeGridPaint = new Paint();
private GridOccupancy mOccupied;
private GridOccupancy mTmpOccupied;
@@ -483,6 +489,37 @@ public class CellLayout extends ViewGroup implements Transposable {
mFolderLeaveBehind.drawLeaveBehind(canvas);
canvas.restore();
}
if (VISUALIZE_GRID) {
visualizeGrid(canvas);
}
}
protected void visualizeGrid(Canvas canvas) {
mVisualizeGridRect.set(0, 0, mCellWidth, mCellHeight);
mVisualizeGridPaint.setStrokeWidth(4);
for (int i = 0; i < mCountX; i++) {
for (int j = 0; j < mCountY; j++) {
canvas.save();
int transX = i * mCellWidth;
int transY = j * mCellHeight;
canvas.translate(getPaddingLeft() + transX, getPaddingTop() + transY);
mVisualizeGridPaint.setStyle(Paint.Style.FILL);
mVisualizeGridPaint.setColor(Color.argb(80, 255, 100, 100));
canvas.drawRect(mVisualizeGridRect, mVisualizeGridPaint);
mVisualizeGridPaint.setStyle(Paint.Style.STROKE);
mVisualizeGridPaint.setColor(Color.argb(255, 255, 100, 100));
canvas.drawRect(mVisualizeGridRect, mVisualizeGridPaint);
canvas.restore();
}
}
}
@Override
@@ -949,8 +986,8 @@ public class CellLayout extends ViewGroup implements Transposable {
return false;
}
void visualizeDropLocation(View v, DragPreviewProvider outlineProvider, int cellX, int cellY,
int spanX, int spanY, boolean resize, DropTarget.DragObject dragObject) {
void visualizeDropLocation(DraggableView v, DragPreviewProvider outlineProvider, int cellX, int
cellY, int spanX, int spanY, boolean resize, DropTarget.DragObject dragObject) {
final int oldDragCellX = mDragCell[0];
final int oldDragCellY = mDragCell[1];
@@ -960,9 +997,6 @@ public class CellLayout extends ViewGroup implements Transposable {
Bitmap dragOutline = outlineProvider.generatedDragOutline;
if (cellX != oldDragCellX || cellY != oldDragCellY) {
Point dragOffset = dragObject.dragView.getDragVisualizeOffset();
Rect dragRegion = dragObject.dragView.getDragRegion();
mDragCell[0] = cellX;
mDragCell[1] = cellY;
@@ -971,50 +1005,27 @@ public class CellLayout extends ViewGroup implements Transposable {
mDragOutlineCurrent = (oldIndex + 1) % mDragOutlines.length;
Rect r = mDragOutlines[mDragOutlineCurrent];
cellToRect(cellX, cellY, spanX, spanY, r);
int left = r.left;
int top = r.top;
int width = dragOutline.getWidth();
int height = dragOutline.getHeight();
if (resize) {
cellToRect(cellX, cellY, spanX, spanY, r);
if (v instanceof LauncherAppWidgetHostView) {
DeviceProfile profile = mActivity.getWallpaperDeviceProfile();
Utilities.shrinkRect(r, profile.appWidgetScale.x, profile.appWidgetScale.y);
}
} else {
// Find the top left corner of the rect the object will occupy
final int[] topLeft = mTmpPoint;
cellToPoint(cellX, cellY, topLeft);
int left = topLeft[0];
int top = topLeft[1];
if (v != null && dragOffset == null) {
// When drawing the drag outline, it did not account for margin offsets
// added by the view's parent.
MarginLayoutParams lp = (MarginLayoutParams) v.getLayoutParams();
left += lp.leftMargin;
top += lp.topMargin;
// Offsets due to the size difference between the View and the dragOutline.
// There is a size difference to account for the outer blur, which may lie
// outside the bounds of the view.
top += ((mCellHeight * spanY) - dragOutline.getHeight()) / 2;
// We center about the x axis
left += ((mCellWidth * spanX) - dragOutline.getWidth()) / 2;
} else {
if (dragOffset != null && dragRegion != null) {
// Center the drag region *horizontally* in the cell and apply a drag
// outline offset
left += dragOffset.x + ((mCellWidth * spanX) - dragRegion.width()) / 2;
int cHeight = getShortcutsAndWidgets().getCellContentHeight();
int cellPaddingY = (int) Math.max(0, ((mCellHeight - cHeight) / 2f));
top += dragOffset.y + cellPaddingY;
} else {
// Center the drag outline in the cell
left += ((mCellWidth * spanX) - dragOutline.getWidth()) / 2;
top += ((mCellHeight * spanY) - dragOutline.getHeight()) / 2;
}
}
r.set(left, top, left + dragOutline.getWidth(), top + dragOutline.getHeight());
width = r.width();
height = r.height();
}
if (v != null && v.getViewType() == DraggableView.DRAGGABLE_ICON) {
left += ((mCellWidth * spanX) - dragOutline.getWidth()) / 2;
int cHeight = getShortcutsAndWidgets().getCellContentHeight();
int cellPaddingY = (int) Math.max(0, ((mCellHeight - cHeight) / 2f));
top += cellPaddingY;
}
r.set(left, top, left + width, top + height);
Utilities.scaleRectAboutCenter(r, mChildScale);
mDragOutlineAnims[mDragOutlineCurrent].setTag(dragOutline);
mDragOutlineAnims[mDragOutlineCurrent].animateIn();
@@ -1900,7 +1911,7 @@ public class CellLayout extends ViewGroup implements Transposable {
// This method starts or changes the reorder preview animations
private void beginOrAdjustReorderPreviewAnimations(ItemConfiguration solution,
View dragView, int delay, int mode) {
View dragView, int mode) {
int childCount = mShortcutsAndWidgets.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = mShortcutsAndWidgets.getChildAt(i);
@@ -1967,6 +1978,8 @@ public class CellLayout extends ViewGroup implements Transposable {
this.child = child;
this.mode = mode;
// TODO issue!
setInitialAnimationValues(false);
finalScale = (mChildScale - (CHILD_DIVIDEND / child.getWidth())) * initScale;
finalDeltaX = initDeltaX;
@@ -2162,6 +2175,8 @@ public class CellLayout extends ViewGroup implements Transposable {
*/
private void getDirectionVectorForDrop(int dragViewCenterX, int dragViewCenterY, int spanX,
int spanY, View dragView, int[] resultDirection) {
//TODO(adamcohen) b/151776141 use the items visual center for the direction vector
int[] targetDestination = new int[2];
findNearestArea(dragViewCenterX, dragViewCenterY, spanX, spanY, targetDestination);
@@ -2272,7 +2287,7 @@ public class CellLayout extends ViewGroup implements Transposable {
setItemPlacementDirty(false);
} else {
beginOrAdjustReorderPreviewAnimations(swapSolution, dragView,
REORDER_ANIMATION_DURATION, ReorderPreviewAnimation.MODE_PREVIEW);
ReorderPreviewAnimation.MODE_PREVIEW);
}
mShortcutsAndWidgets.requestLayout();
}
@@ -2326,7 +2341,7 @@ public class CellLayout extends ViewGroup implements Transposable {
if (mode == MODE_SHOW_REORDER_HINT) {
if (finalSolution != null) {
beginOrAdjustReorderPreviewAnimations(finalSolution, dragView, 0,
beginOrAdjustReorderPreviewAnimations(finalSolution, dragView,
ReorderPreviewAnimation.MODE_HINT);
result[0] = finalSolution.cellX;
result[1] = finalSolution.cellY;
@@ -2366,7 +2381,7 @@ public class CellLayout extends ViewGroup implements Transposable {
setItemPlacementDirty(false);
} else {
beginOrAdjustReorderPreviewAnimations(finalSolution, dragView,
REORDER_ANIMATION_DURATION, ReorderPreviewAnimation.MODE_PREVIEW);
ReorderPreviewAnimation.MODE_PREVIEW);
}
}
} else {