Fix clipping of drag outline by increasing padding.

Low resolution will be addressed in future CL.

Bug: 31915722
Change-Id: I6bdd32b7a30819fde1f15473a63ac280029b6715
This commit is contained in:
Jon Miranda 2016-10-12 20:35:59 -07:00
parent 3285da35cb
commit c9c57631a9
7 changed files with 35 additions and 21 deletions

View File

@ -247,7 +247,6 @@ public class Workspace extends PagedView
private boolean mStripScreensOnPageStopMoving = false;
private DragPreviewProvider mOutlineProvider = null;
public static final int DRAG_BITMAP_PADDING = DragPreviewProvider.DRAG_BITMAP_PADDING;
private boolean mWorkspaceFadeInAdjacentScreens;
final WallpaperOffsetInterpolator mWallpaperOffset;

View File

@ -655,7 +655,7 @@ public class DragLayer extends InsettableFrameLayout {
} else if (child instanceof FolderIcon) {
// Account for holographic blur padding on the drag view
toY += Math.round(scale * (child.getPaddingTop() - dragView.getDragRegionTop()));
toY -= scale * Workspace.DRAG_BITMAP_PADDING / 2;
toY -= scale * dragView.getBlurSizeOutline() / 2;
toY -= (1 - scale) * dragView.getMeasuredHeight() / 2;
// Center in the x coordinate about the target's drawable
toX -= (dragView.getMeasuredWidth() - Math.round(scale * child.getMeasuredWidth())) / 2;

View File

@ -52,6 +52,7 @@ public class DragView extends View {
private Bitmap mBitmap;
private Bitmap mCrossFadeBitmap;
@Thunk Paint mPaint;
private final int mBlurSizeOutline;
private final int mRegistrationX;
private final int mRegistrationY;
private final float mInitialScale;
@ -144,6 +145,8 @@ public class DragView extends View {
measure(ms, ms);
mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
mBlurSizeOutline = getResources().getDimensionPixelSize(R.dimen.blur_size_medium_outline);
if (Utilities.ATLEAST_LOLLIPOP) {
setElevation(getResources().getDimension(R.dimen.drag_elevation));
}
@ -397,4 +400,8 @@ public class DragView extends View {
target.setScale(Color.red(color) / 255f, Color.green(color) / 255f,
Color.blue(color) / 255f, Color.alpha(color) / 255f);
}
public int getBlurSizeOutline() {
return mBlurSizeOutline;
}
}

View File

@ -41,7 +41,7 @@ public class ExternalDragPreviewProvider extends DragPreviewProvider {
private final int[] mOutlineSize;
public ExternalDragPreviewProvider(Launcher launcher, ItemInfo addInfo) {
super(null);
super(null, launcher);
mLauncher = launcher;
mAddInfo = addInfo;
@ -51,7 +51,7 @@ public class ExternalDragPreviewProvider extends DragPreviewProvider {
public Rect getPreviewBounds() {
Rect rect = new Rect();
DeviceProfile dp = mLauncher.getDeviceProfile();
rect.left = DRAG_BITMAP_PADDING / 2;
rect.left = blurSizeOutline / 2;
rect.top = (mOutlineSize[1] - dp.cellHeightPx) / 2;
rect.right = rect.left + dp.iconSizePx;
rect.bottom = rect.top + dp.iconSizePx;
@ -69,8 +69,8 @@ public class ExternalDragPreviewProvider extends DragPreviewProvider {
// Use 0.9f times the radius for the actual circle to account for icon normalization.
float radius = getPreviewBounds().width() * 0.5f;
canvas.drawCircle(DRAG_BITMAP_PADDING / 2 + radius,
DRAG_BITMAP_PADDING / 2 + radius, radius * 0.9f, paint);
canvas.drawCircle(blurSizeOutline / 2 + radius,
blurSizeOutline / 2 + radius, radius * 0.9f, paint);
HolographicOutlineHelper.getInstance(mLauncher).applyExpensiveOutlineWithBlur(b, canvas);
canvas.setBitmap(null);

View File

@ -16,6 +16,7 @@
package com.android.launcher3.graphics;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
@ -28,6 +29,7 @@ import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppWidgetHostView;
import com.android.launcher3.PreloadIconDrawable;
import com.android.launcher3.R;
import com.android.launcher3.Workspace;
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.folder.FolderIcon;
@ -37,8 +39,6 @@ import com.android.launcher3.folder.FolderIcon;
*/
public class DragPreviewProvider {
public static final int DRAG_BITMAP_PADDING = 2;
private final Rect mTempRect = new Rect();
protected final View mView;
@ -46,17 +46,25 @@ public class DragPreviewProvider {
// The padding added to the drag view during the preview generation.
public final int previewPadding;
protected final int blurSizeOutline;
public Bitmap generatedDragOutline;
public DragPreviewProvider(View view) {
this(view, view.getContext());
}
public DragPreviewProvider(View view, Context context) {
mView = view;
blurSizeOutline =
context.getResources().getDimensionPixelSize(R.dimen.blur_size_medium_outline);
if (mView instanceof TextView) {
Drawable d = Workspace.getTextViewIcon((TextView) mView);
Rect bounds = getDrawableBounds(d);
previewPadding = DRAG_BITMAP_PADDING - bounds.left - bounds.top;
previewPadding = blurSizeOutline - bounds.left - bounds.top;
} else {
previewPadding = DRAG_BITMAP_PADDING;
previewPadding = blurSizeOutline;
}
}
@ -68,8 +76,8 @@ public class DragPreviewProvider {
if (mView instanceof TextView) {
Drawable d = Workspace.getTextViewIcon((TextView) mView);
Rect bounds = getDrawableBounds(d);
destCanvas.translate(DRAG_BITMAP_PADDING / 2 - bounds.left,
DRAG_BITMAP_PADDING / 2 - bounds.top);
destCanvas.translate(blurSizeOutline / 2 - bounds.left,
blurSizeOutline / 2 - bounds.top);
d.draw(destCanvas);
} else {
final Rect clipRect = mTempRect;
@ -84,8 +92,8 @@ public class DragPreviewProvider {
textVisible = true;
}
}
destCanvas.translate(-mView.getScrollX() + DRAG_BITMAP_PADDING / 2,
-mView.getScrollY() + DRAG_BITMAP_PADDING / 2);
destCanvas.translate(-mView.getScrollX() + blurSizeOutline / 2,
-mView.getScrollY() + blurSizeOutline / 2);
destCanvas.clipRect(clipRect, Op.REPLACE);
mView.draw(destCanvas);
@ -118,7 +126,7 @@ public class DragPreviewProvider {
height = (int) (mView.getHeight() * scale);
}
Bitmap b = Bitmap.createBitmap(width + DRAG_BITMAP_PADDING, height + DRAG_BITMAP_PADDING,
Bitmap b = Bitmap.createBitmap(width + blurSizeOutline, height + blurSizeOutline,
Bitmap.Config.ARGB_8888);
canvas.setBitmap(b);
@ -156,7 +164,7 @@ public class DragPreviewProvider {
height = (int) Math.floor(mView.getHeight() * scale);
}
Bitmap b = Bitmap.createBitmap(width + DRAG_BITMAP_PADDING, height + DRAG_BITMAP_PADDING,
Bitmap b = Bitmap.createBitmap(width + blurSizeOutline, height + blurSizeOutline,
Bitmap.Config.ALPHA_8);
canvas.setBitmap(b);

View File

@ -64,13 +64,13 @@ public class ShortcutDragPreviewProvider extends DragPreviewProvider {
int size = Launcher.getLauncher(mView.getContext()).getDeviceProfile().iconSizePx;
final Bitmap b = Bitmap.createBitmap(
size + DRAG_BITMAP_PADDING,
size + DRAG_BITMAP_PADDING,
size + blurSizeOutline,
size + blurSizeOutline,
config);
canvas.setBitmap(b);
canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.translate(DRAG_BITMAP_PADDING / 2, DRAG_BITMAP_PADDING / 2);
canvas.translate(blurSizeOutline / 2, blurSizeOutline / 2);
canvas.scale(((float) size) / bounds.width(), ((float) size) / bounds.height(), 0, 0);
canvas.translate(bounds.left, bounds.top);
d.draw(canvas);

View File

@ -53,8 +53,8 @@ public class PendingItemPreviewProvider extends DragPreviewProvider {
canvas.setBitmap(b);
Rect src = new Rect(0, 0, mPreviewBitmap.getWidth(), mPreviewBitmap.getHeight());
float scaleFactor = Math.min((w - DRAG_BITMAP_PADDING) / (float) mPreviewBitmap.getWidth(),
(h - DRAG_BITMAP_PADDING) / (float) mPreviewBitmap.getHeight());
float scaleFactor = Math.min((w - blurSizeOutline) / (float) mPreviewBitmap.getWidth(),
(h - blurSizeOutline) / (float) mPreviewBitmap.getHeight());
int scaledWidth = (int) (scaleFactor * mPreviewBitmap.getWidth());
int scaledHeight = (int) (scaleFactor * mPreviewBitmap.getHeight());
Rect dst = new Rect(0, 0, scaledWidth, scaledHeight);