use of com.android.launcher3.dragndrop.DragView in project android_packages_apps_Launcher3 by crdroidandroid.
the class DragLayer method animateViewIntoPosition.
public void animateViewIntoPosition(DragView dragView, final View child, int duration, View anchorView) {
ShortcutAndWidgetContainer parentChildren = (ShortcutAndWidgetContainer) child.getParent();
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
parentChildren.measureChild(child);
parentChildren.layoutChild(child);
Rect dragViewBounds = new Rect();
getViewRectRelativeToSelf(dragView, dragViewBounds);
final int fromX = dragViewBounds.left;
final int fromY = dragViewBounds.top;
float[] coord = new float[2];
float childScale = child.getScaleX();
coord[0] = lp.x + (child.getMeasuredWidth() * (1 - childScale) / 2);
coord[1] = lp.y + (child.getMeasuredHeight() * (1 - childScale) / 2);
// Since the child hasn't necessarily been laid out, we force the lp to be updated with
// the correct coordinates (above) and use these to determine the final location
float scale = getDescendantCoordRelativeToSelf((View) child.getParent(), coord);
// We need to account for the scale of the child itself, as the above only accounts for
// for the scale in parents.
scale *= childScale;
int toX = Math.round(coord[0]);
int toY = Math.round(coord[1]);
float toScale = scale;
if (child instanceof DraggableView) {
// This code is fairly subtle. Please verify drag and drop is pixel-perfect in a number
// of scenarios before modifying (from all apps, from workspace, different grid-sizes,
// shortcuts from in and out of Launcher etc).
DraggableView d = (DraggableView) child;
Rect destRect = new Rect();
d.getWorkspaceVisualDragBounds(destRect);
// In most cases this additional scale factor should be a no-op (1). It mainly accounts
// for alternate grids where the source and destination icon sizes are different
toScale *= ((1f * destRect.width()) / (dragView.getMeasuredWidth() - dragView.getBlurSizeOutline()));
// This accounts for the offset of the DragView created by scaling it about its
// center as it animates into place.
float scaleShiftX = dragView.getMeasuredWidth() * (1 - toScale) / 2;
float scaleShiftY = dragView.getMeasuredHeight() * (1 - toScale) / 2;
toX += scale * destRect.left - toScale * dragView.getBlurSizeOutline() / 2 - scaleShiftX;
toY += scale * destRect.top - toScale * dragView.getBlurSizeOutline() / 2 - scaleShiftY;
}
child.setVisibility(INVISIBLE);
Runnable onCompleteRunnable = () -> child.setVisibility(VISIBLE);
animateViewIntoPosition(dragView, fromX, fromY, toX, toY, 1, 1, 1, toScale, toScale, onCompleteRunnable, ANIMATION_END_DISAPPEAR, duration, anchorView);
}
use of com.android.launcher3.dragndrop.DragView in project android_packages_apps_Launcher3 by crdroidandroid.
the class ButtonDropTarget method onDrop.
/**
* On drop animate the dropView to the icon.
*/
@Override
public void onDrop(final DragObject d, final DragOptions options) {
if (options.isFlingToDelete) {
// FlingAnimation handles the animation and then calls completeDrop().
return;
}
final DragLayer dragLayer = mLauncher.getDragLayer();
final DragView dragView = d.dragView;
final Rect from = new Rect();
dragLayer.getViewRectRelativeToSelf(d.dragView, from);
final Rect to = getIconRect(d);
final float scale = (float) to.width() / from.width();
dragView.disableColorExtraction();
dragView.detachContentView(/* reattachToPreviousParent= */
true);
mDropTargetBar.deferOnDragEnd();
Runnable onAnimationEndRunnable = () -> {
completeDrop(d);
mDropTargetBar.onDragEnd();
mLauncher.getStateManager().goToState(NORMAL);
// Only re-enable updates once the workspace is back to normal, which will be after the
// current frame.
post(dragView::resumeColorExtraction);
};
dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f, DRAG_VIEW_DROP_DURATION, Interpolators.DEACCEL_2, Interpolators.LINEAR, onAnimationEndRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null);
}
use of com.android.launcher3.dragndrop.DragView in project android_packages_apps_Launcher3 by crdroidandroid.
the class CellLayout method getViewsIntersectingRegion.
// For a given cell and span, fetch the set of views intersecting the region.
private void getViewsIntersectingRegion(int cellX, int cellY, int spanX, int spanY, View dragView, Rect boundingRect, ArrayList<View> intersectingViews) {
if (boundingRect != null) {
boundingRect.set(cellX, cellY, cellX + spanX, cellY + spanY);
}
intersectingViews.clear();
Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY);
Rect r1 = new Rect();
final int count = mShortcutsAndWidgets.getChildCount();
for (int i = 0; i < count; i++) {
View child = mShortcutsAndWidgets.getChildAt(i);
if (child == dragView)
continue;
LayoutParams lp = (LayoutParams) child.getLayoutParams();
r1.set(lp.cellX, lp.cellY, lp.cellX + lp.cellHSpan, lp.cellY + lp.cellVSpan);
if (Rect.intersects(r0, r1)) {
mIntersectingViews.add(child);
if (boundingRect != null) {
boundingRect.union(r1);
}
}
}
}
use of com.android.launcher3.dragndrop.DragView in project android_packages_apps_Launcher3 by crdroidandroid.
the class CellLayout method animateItemsToSolution.
private void animateItemsToSolution(ItemConfiguration solution, View dragView, boolean commitDragView) {
GridOccupancy occupied = DESTRUCTIVE_REORDER ? mOccupied : mTmpOccupied;
occupied.clear();
int childCount = mShortcutsAndWidgets.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = mShortcutsAndWidgets.getChildAt(i);
if (child == dragView)
continue;
CellAndSpan c = solution.map.get(child);
if (c != null) {
animateChildToPosition(child, c.cellX, c.cellY, REORDER_ANIMATION_DURATION, 0, DESTRUCTIVE_REORDER, false);
occupied.markCells(c, true);
}
}
if (commitDragView) {
occupied.markCells(solution, true);
}
}
use of com.android.launcher3.dragndrop.DragView in project android_packages_apps_Launcher3 by crdroidandroid.
the class CellLayout method copySolutionToTempState.
private void copySolutionToTempState(ItemConfiguration solution, View dragView) {
mTmpOccupied.clear();
int childCount = mShortcutsAndWidgets.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = mShortcutsAndWidgets.getChildAt(i);
if (child == dragView)
continue;
LayoutParams lp = (LayoutParams) child.getLayoutParams();
CellAndSpan c = solution.map.get(child);
if (c != null) {
lp.tmpCellX = c.cellX;
lp.tmpCellY = c.cellY;
lp.cellHSpan = c.spanX;
lp.cellVSpan = c.spanY;
mTmpOccupied.markCells(c, true);
}
}
mTmpOccupied.markCells(solution, true);
}
Aggregations