Merge "Fix issues with drag and drop from All Apps in non-default grids" into ub-launcher3-rvc-dev

This commit is contained in:
Adam Cohen
2020-05-11 18:38:15 +00:00
committed by Android (Google) Code Review
8 changed files with 53 additions and 18 deletions
+17 -1
View File
@@ -722,11 +722,27 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
}
@Override
public void getVisualDragBounds(Rect bounds) {
public void getWorkspaceVisualDragBounds(Rect bounds) {
DeviceProfile grid = mActivity.getDeviceProfile();
BubbleTextView.getIconBounds(this, bounds, grid.iconSizePx);
}
private int getIconSizeForDisplay(int display) {
DeviceProfile grid = mActivity.getDeviceProfile();
switch (display) {
case DISPLAY_ALL_APPS:
return grid.allAppsIconSizePx;
case DISPLAY_WORKSPACE:
case DISPLAY_FOLDER:
default:
return grid.iconSizePx;
}
}
public void getSourceVisualDragBounds(Rect bounds) {
BubbleTextView.getIconBounds(this, bounds, getIconSizeForDisplay(mDisplay));
}
@Override
public void prepareDrawDragView() {
if (getIcon() instanceof FastBitmapDrawable) {
+5 -5
View File
@@ -1441,6 +1441,10 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
mOutlineProvider = previewProvider;
if (draggableView == null && child instanceof DraggableView) {
draggableView = (DraggableView) child;
}
// The drag bitmap follows the touch point around on the screen
final Bitmap b = previewProvider.createDragBitmap();
int halfPadding = previewProvider.previewPadding / 2;
@@ -1451,12 +1455,8 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
Point dragVisualizeOffset = null;
Rect dragRect = new Rect();
if (draggableView == null && child instanceof DraggableView) {
draggableView = (DraggableView) child;
}
if (draggableView != null) {
draggableView.getVisualDragBounds(dragRect);
draggableView.getSourceVisualDragBounds(dragRect);
dragLayerY += dragRect.top;
dragVisualizeOffset = new Point(- halfPadding, halfPadding);
}
@@ -274,19 +274,29 @@ public class DragLayer extends BaseDragLayer<Launcher> {
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;
d.getVisualDragBounds(dragViewBounds);
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 - scale) / 2;
float scaleShiftY = dragView.getMeasuredHeight() * (1 - scale) / 2;
float scaleShiftX = dragView.getMeasuredWidth() * (1 - toScale) / 2;
float scaleShiftY = dragView.getMeasuredHeight() * (1 - toScale) / 2;
toX += scale * (dragViewBounds.left - dragView.getBlurSizeOutline() / 2) - scaleShiftX;
toY += scale * (dragViewBounds.top - dragView.getBlurSizeOutline() / 2) - scaleShiftY;
toX += scale * destRect.left - toScale * dragView.getBlurSizeOutline() / 2 - scaleShiftX;
toY += scale * destRect.top - toScale * dragView.getBlurSizeOutline() / 2 - scaleShiftY;
}
child.setVisibility(INVISIBLE);
@@ -53,5 +53,14 @@ public interface DraggableView {
*
* @param bounds Visual bounds in the views coordinates will be written here.
*/
default void getVisualDragBounds(Rect bounds) { }
default void getWorkspaceVisualDragBounds(Rect bounds) { }
/**
* Same as above, but accounts for differing icon sizes between source and destination
*
* @param bounds Visual bounds in the views coordinates will be written here.
*/
default void getSourceVisualDragBounds(Rect bounds) {
getWorkspaceVisualDragBounds(bounds);
}
}
@@ -758,7 +758,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
}
@Override
public void getVisualDragBounds(Rect bounds) {
public void getWorkspaceVisualDragBounds(Rect bounds) {
getPreviewBounds(bounds);
}
}
@@ -77,7 +77,7 @@ public class DragPreviewProvider {
if (mView instanceof DraggableView) {
DraggableView dv = (DraggableView) mView;
dv.prepareDrawDragView();
dv.getVisualDragBounds(mTempRect);
dv.getSourceVisualDragBounds(mTempRect);
destCanvas.translate(blurSizeOutline / 2 - mTempRect.left,
blurSizeOutline / 2 - mTempRect.top);
mView.draw(destCanvas);
@@ -95,7 +95,7 @@ public class DragPreviewProvider {
// Assume scaleX == scaleY, which is always the case for workspace items.
float scale = mView.getScaleX();
if (mView instanceof DraggableView) {
((DraggableView) mView).getVisualDragBounds(mTempRect);
((DraggableView) mView).getSourceVisualDragBounds(mTempRect);
width = mTempRect.width();
height = mTempRect.height();
} else {
@@ -218,7 +218,7 @@ public abstract class NavigableAppWidgetHostView extends AppWidgetHostView
}
@Override
public void getVisualDragBounds(Rect bounds) {
public void getWorkspaceVisualDragBounds(Rect bounds) {
int width = (int) (getMeasuredWidth() * mScaleToFit);
int height = (int) (getMeasuredHeight() * mScaleToFit);
@@ -55,7 +55,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
private static final int FADE_IN_DURATION_MS = 90;
/** Widget cell width is calculated by multiplying this factor to grid cell width. */
private static final float WIDTH_SCALE = 2.6f;
private static final float WIDTH_SCALE = 3f;
/** Widget preview width is calculated by multiplying this factor to the widget cell width. */
private static final float PREVIEW_SCALE = 0.8f;
@@ -104,7 +104,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
}
private void setContainerWidth() {
mCellSize = (int) (mDeviceProfile.cellWidthPx * WIDTH_SCALE);
mCellSize = (int) (mDeviceProfile.allAppsIconSizePx * WIDTH_SCALE);
mPresetPreviewSize = (int) (mCellSize * PREVIEW_SCALE);
}