Increasing the size of the drag icon when a shortcut is dragged
Change-Id: I7d768657300d3229e05d1eb18aec3720a9098ffc
This commit is contained in:
@@ -79,7 +79,7 @@ public class HolographicOutlineHelper {
|
||||
* Applies a more expensive and accurate outline to whatever is currently drawn in a specified
|
||||
* bitmap.
|
||||
*/
|
||||
void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas, int color,
|
||||
public void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas, int color,
|
||||
int outlineColor) {
|
||||
applyExpensiveOutlineWithBlur(srcDst, srcDstCanvas, color, outlineColor, true);
|
||||
}
|
||||
|
||||
@@ -4456,13 +4456,6 @@ public class Launcher extends Activity
|
||||
UserHandleCompat.myUserHandle());
|
||||
}
|
||||
|
||||
// TODO: This method should be a part of LauncherSearchCallback
|
||||
public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
|
||||
dragView.setTag(dragInfo);
|
||||
mWorkspace.onExternalDragStartedWithItem(dragView);
|
||||
mWorkspace.beginExternalDragShared(dragView, source);
|
||||
}
|
||||
|
||||
protected void moveWorkspaceToDefaultScreen() {
|
||||
mWorkspace.moveToDefaultScreen(false);
|
||||
}
|
||||
|
||||
@@ -35,11 +35,9 @@ import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Region.Op;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
@@ -71,6 +69,7 @@ import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.config.ProviderConfig;
|
||||
import com.android.launcher3.dragndrop.DragController;
|
||||
import com.android.launcher3.dragndrop.DragLayer;
|
||||
import com.android.launcher3.graphics.DragPreviewProvider;
|
||||
import com.android.launcher3.dragndrop.DragScroller;
|
||||
import com.android.launcher3.dragndrop.DragView;
|
||||
import com.android.launcher3.dragndrop.SpringLoadedDragController;
|
||||
@@ -248,7 +247,7 @@ public class Workspace extends PagedView
|
||||
|
||||
private HolographicOutlineHelper mOutlineHelper;
|
||||
@Thunk Bitmap mDragOutline = null;
|
||||
public static final int DRAG_BITMAP_PADDING = 2;
|
||||
public static final int DRAG_BITMAP_PADDING = DragPreviewProvider.DRAG_BITMAP_PADDING;
|
||||
private boolean mWorkspaceFadeInAdjacentScreens;
|
||||
|
||||
final WallpaperOffsetInterpolator mWallpaperOffset;
|
||||
@@ -1980,56 +1979,6 @@ public class Workspace extends PagedView
|
||||
position[0], position[1], 0, null);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* We call these methods (onDragStartedWithItemSpans/onDragStartedWithSize) whenever we
|
||||
* start a drag in Launcher, regardless of whether the drag has ever entered the Workspace
|
||||
*
|
||||
* These methods mark the appropriate pages as accepting drops (which alters their visual
|
||||
* appearance).
|
||||
*
|
||||
*/
|
||||
private static Rect getDrawableBounds(Drawable d) {
|
||||
Rect bounds = new Rect();
|
||||
d.copyBounds(bounds);
|
||||
if (bounds.width() == 0 || bounds.height() == 0) {
|
||||
bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
|
||||
} else {
|
||||
bounds.offsetTo(0, 0);
|
||||
}
|
||||
if (d instanceof PreloadIconDrawable) {
|
||||
int inset = -((PreloadIconDrawable) d).getOutset();
|
||||
bounds.inset(inset, inset);
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
|
||||
public void onExternalDragStartedWithItem(View v) {
|
||||
// Compose a drag bitmap with the view scaled to the icon size
|
||||
DeviceProfile grid = mLauncher.getDeviceProfile();
|
||||
int iconSize = grid.iconSizePx;
|
||||
int bmpWidth = v.getMeasuredWidth();
|
||||
int bmpHeight = v.getMeasuredHeight();
|
||||
|
||||
// If this is a text view, use its drawable instead
|
||||
if (v instanceof TextView) {
|
||||
Drawable d = getTextViewIcon((TextView) v);
|
||||
Rect bounds = getDrawableBounds(d);
|
||||
bmpWidth = bounds.width();
|
||||
bmpHeight = bounds.height();
|
||||
}
|
||||
|
||||
// Compose the bitmap to create the icon from
|
||||
Bitmap b = Bitmap.createBitmap(bmpWidth, bmpHeight,
|
||||
Bitmap.Config.ARGB_8888);
|
||||
mCanvas.setBitmap(b);
|
||||
drawDragView(v, mCanvas, 0);
|
||||
mCanvas.setBitmap(null);
|
||||
|
||||
// The outline is used to visualize where the item will land if dropped
|
||||
mDragOutline = createDragOutline(b, DRAG_BITMAP_PADDING, iconSize, iconSize, true);
|
||||
}
|
||||
|
||||
public void onDragStartedWithItem(PendingAddItemInfo info, Bitmap b, boolean clipAlpha) {
|
||||
// Find a page that has enough space to place this widget (after rearranging/resizing).
|
||||
// Start at the current page and search right (on LTR) until finding a page with enough
|
||||
@@ -2302,89 +2251,6 @@ public class Workspace extends PagedView
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the View v into the given Canvas.
|
||||
*
|
||||
* @param v the view to draw
|
||||
* @param destCanvas the canvas to draw on
|
||||
* @param padding the horizontal and vertical padding to use when drawing
|
||||
*/
|
||||
private static void drawDragView(View v, Canvas destCanvas, int padding) {
|
||||
destCanvas.save();
|
||||
if (v instanceof TextView) {
|
||||
Drawable d = getTextViewIcon((TextView) v);
|
||||
Rect bounds = getDrawableBounds(d);
|
||||
destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top);
|
||||
d.draw(destCanvas);
|
||||
} else {
|
||||
final Rect clipRect = sTempRect;
|
||||
v.getDrawingRect(clipRect);
|
||||
|
||||
boolean textVisible = false;
|
||||
if (v instanceof FolderIcon) {
|
||||
// For FolderIcons the text can bleed into the icon area, and so we need to
|
||||
// hide the text completely (which can't be achieved by clipping).
|
||||
if (((FolderIcon) v).getTextVisible()) {
|
||||
((FolderIcon) v).setTextVisible(false);
|
||||
textVisible = true;
|
||||
}
|
||||
}
|
||||
destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
|
||||
destCanvas.clipRect(clipRect, Op.REPLACE);
|
||||
v.draw(destCanvas);
|
||||
|
||||
// Restore text visibility of FolderIcon if necessary
|
||||
if (textVisible) {
|
||||
((FolderIcon) v).setTextVisible(true);
|
||||
}
|
||||
}
|
||||
destCanvas.restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new bitmap to show when the given View is being dragged around.
|
||||
* Responsibility for the bitmap is transferred to the caller.
|
||||
* @param expectedPadding padding to add to the drag view. If a different padding was used
|
||||
* its value will be changed
|
||||
*/
|
||||
public Bitmap createDragBitmap(View v, AtomicInteger expectedPadding) {
|
||||
Bitmap b;
|
||||
|
||||
int padding = expectedPadding.get();
|
||||
if (v instanceof TextView) {
|
||||
Drawable d = getTextViewIcon((TextView) v);
|
||||
Rect bounds = getDrawableBounds(d);
|
||||
b = Bitmap.createBitmap(bounds.width() + padding,
|
||||
bounds.height() + padding, Bitmap.Config.ARGB_8888);
|
||||
expectedPadding.set(padding - bounds.left - bounds.top);
|
||||
} else {
|
||||
b = Bitmap.createBitmap(
|
||||
v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
mCanvas.setBitmap(b);
|
||||
drawDragView(v, mCanvas, padding);
|
||||
mCanvas.setBitmap(null);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location.
|
||||
* Responsibility for the bitmap is transferred to the caller.
|
||||
*/
|
||||
private Bitmap createDragOutline(View v, int padding) {
|
||||
final int outlineColor = getResources().getColor(R.color.outline_color);
|
||||
final Bitmap b = Bitmap.createBitmap(
|
||||
v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888);
|
||||
|
||||
mCanvas.setBitmap(b);
|
||||
drawDragView(v, mCanvas, padding);
|
||||
mOutlineHelper.applyExpensiveOutlineWithBlur(b, mCanvas, outlineColor, outlineColor);
|
||||
mCanvas.setBitmap(null);
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location.
|
||||
* Responsibility for the bitmap is transferred to the caller.
|
||||
@@ -2435,29 +2301,28 @@ public class Workspace extends PagedView
|
||||
}
|
||||
|
||||
public void beginDragShared(View child, DragSource source, boolean accessible) {
|
||||
beginDragShared(child, new Point(), source, accessible);
|
||||
beginDragShared(child, new Point(), source, accessible, new DragPreviewProvider(child));
|
||||
}
|
||||
|
||||
public void beginDragShared(View child, Point relativeTouchPos, DragSource source,
|
||||
boolean accessible) {
|
||||
boolean accessible, DragPreviewProvider previewProvider) {
|
||||
child.clearFocus();
|
||||
child.setPressed(false);
|
||||
|
||||
// The outline is used to visualize where the item will land if dropped
|
||||
mDragOutline = createDragOutline(child, DRAG_BITMAP_PADDING);
|
||||
mDragOutline = previewProvider.createDragOutline(mCanvas);
|
||||
|
||||
mLauncher.onDragStarted(child);
|
||||
// The drag bitmap follows the touch point around on the screen
|
||||
AtomicInteger padding = new AtomicInteger(DRAG_BITMAP_PADDING);
|
||||
final Bitmap b = createDragBitmap(child, padding);
|
||||
final Bitmap b = previewProvider.createDragBitmap(mCanvas);
|
||||
int halfPadding = previewProvider.previewPadding / 2;
|
||||
|
||||
final int bmpWidth = b.getWidth();
|
||||
final int bmpHeight = b.getHeight();
|
||||
|
||||
float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY);
|
||||
int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2);
|
||||
int dragLayerY = Math.round(mTempXY[1] - (bmpHeight - scale * bmpHeight) / 2
|
||||
- padding.get() / 2);
|
||||
int dragLayerY = Math.round(mTempXY[1] - (bmpHeight - scale * bmpHeight) / 2 - halfPadding);
|
||||
|
||||
DeviceProfile grid = mLauncher.getDeviceProfile();
|
||||
Point dragVisualizeOffset = null;
|
||||
@@ -2483,12 +2348,11 @@ public class Workspace extends PagedView
|
||||
dragLayerY += top;
|
||||
// Note: The drag region is used to calculate drag layer offsets, but the
|
||||
// dragVisualizeOffset in addition to the dragRect (the size) to position the outline.
|
||||
dragVisualizeOffset = new Point(-padding.get() / 2, padding.get() / 2);
|
||||
dragVisualizeOffset = new Point(- halfPadding, halfPadding);
|
||||
dragRect = new Rect(left, top, right, bottom);
|
||||
} else if (child instanceof FolderIcon) {
|
||||
int previewSize = grid.folderIconSizePx;
|
||||
dragVisualizeOffset = new Point(-padding.get() / 2,
|
||||
padding.get() / 2 - child.getPaddingTop());
|
||||
dragVisualizeOffset = new Point(- halfPadding, halfPadding - child.getPaddingTop());
|
||||
dragRect = new Rect(0, child.getPaddingTop(), child.getWidth(), previewSize);
|
||||
}
|
||||
|
||||
@@ -2522,58 +2386,6 @@ public class Workspace extends PagedView
|
||||
}
|
||||
}
|
||||
|
||||
public void beginExternalDragShared(View child, DragSource source) {
|
||||
DeviceProfile grid = mLauncher.getDeviceProfile();
|
||||
int iconSize = grid.iconSizePx;
|
||||
|
||||
// Notify launcher of drag start
|
||||
mLauncher.onDragStarted(child);
|
||||
|
||||
// Compose a new drag bitmap that is of the icon size
|
||||
AtomicInteger padding = new AtomicInteger(DRAG_BITMAP_PADDING);
|
||||
final Bitmap tmpB = createDragBitmap(child, padding);
|
||||
Bitmap b = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
|
||||
Paint p = new Paint();
|
||||
p.setFilterBitmap(true);
|
||||
mCanvas.setBitmap(b);
|
||||
mCanvas.drawBitmap(tmpB, new Rect(0, 0, tmpB.getWidth(), tmpB.getHeight()),
|
||||
new Rect(0, 0, iconSize, iconSize), p);
|
||||
mCanvas.setBitmap(null);
|
||||
|
||||
// Find the child's location on the screen
|
||||
int bmpWidth = tmpB.getWidth();
|
||||
float iconScale = (float) bmpWidth / iconSize;
|
||||
float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY) * iconScale;
|
||||
int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2);
|
||||
int dragLayerY = Math.round(mTempXY[1]);
|
||||
|
||||
// Note: The drag region is used to calculate drag layer offsets, but the
|
||||
// dragVisualizeOffset in addition to the dragRect (the size) to position the outline.
|
||||
Point dragVisualizeOffset = new Point(-padding.get() / 2, padding.get() / 2);
|
||||
Rect dragRect = new Rect(0, 0, iconSize, iconSize);
|
||||
|
||||
Object dragObject = child.getTag();
|
||||
if (!(dragObject instanceof ItemInfo)) {
|
||||
String msg = "Drag started with a view that has no tag set. This "
|
||||
+ "will cause a crash (issue 11627249) down the line. "
|
||||
+ "View: " + child + " tag: " + child.getTag();
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
|
||||
// Start the drag
|
||||
DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source,
|
||||
(ItemInfo) dragObject, DragController.DRAG_ACTION_MOVE, dragVisualizeOffset,
|
||||
dragRect, scale, false);
|
||||
dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor());
|
||||
|
||||
// Recycle temporary bitmaps
|
||||
tmpB.recycle();
|
||||
|
||||
if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
|
||||
mLauncher.enterSpringLoadedDragMode();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean transitionStateShouldAllowDrop() {
|
||||
return ((!isSwitchingState() || mTransitionProgress > 0.5f) &&
|
||||
(mState == State.NORMAL || mState == State.SPRING_LOADED));
|
||||
|
||||
@@ -252,8 +252,7 @@ public class DragController implements DragDriver.EventListener, TouchController
|
||||
final float scaleDps = FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND ?
|
||||
res.getDimensionPixelSize(R.dimen.dragViewScale) : 0f;
|
||||
final DragView dragView = mDragObject.dragView = new DragView(mLauncher, b, registrationX,
|
||||
registrationY, 0, 0, b.getWidth(), b.getHeight(),
|
||||
initialDragViewScale, scaleDps);
|
||||
registrationY, initialDragViewScale, scaleDps);
|
||||
|
||||
mDragObject.dragComplete = false;
|
||||
if (mIsAccessibleDrag) {
|
||||
|
||||
@@ -84,13 +84,13 @@ public class DragView extends View {
|
||||
* @param registrationY The y coordinate of the registration point.
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public DragView(Launcher launcher, Bitmap bitmap, int registrationX, int registrationY, int left,
|
||||
int top, int width, int height, final float initialScale, final float finalScaleDps) {
|
||||
public DragView(Launcher launcher, Bitmap bitmap, int registrationX, int registrationY,
|
||||
final float initialScale, final float finalScaleDps) {
|
||||
super(launcher);
|
||||
mDragLayer = launcher.getDragLayer();
|
||||
mDragController = launcher.getDragController();
|
||||
|
||||
final float scale = (width + finalScaleDps) / width;
|
||||
final float scale = (bitmap.getWidth() + finalScaleDps) / bitmap.getWidth();
|
||||
|
||||
// Set the initial scale to avoid any jumps
|
||||
setScaleX(initialScale);
|
||||
@@ -125,8 +125,8 @@ public class DragView extends View {
|
||||
}
|
||||
});
|
||||
|
||||
mBitmap = Bitmap.createBitmap(bitmap, left, top, width, height);
|
||||
setDragRegion(new Rect(0, 0, width, height));
|
||||
mBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight());
|
||||
setDragRegion(new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()));
|
||||
|
||||
// The point in our scaled bitmap that the touch events are located
|
||||
mRegistrationX = registrationX;
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.graphics;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Region.Op;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.launcher3.HolographicOutlineHelper;
|
||||
import com.android.launcher3.PreloadIconDrawable;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* A utility class to generate preview bitmap for dragging.
|
||||
*/
|
||||
public class DragPreviewProvider {
|
||||
|
||||
public static final int DRAG_BITMAP_PADDING = 2;
|
||||
|
||||
private final Rect mTempRect = new Rect();
|
||||
|
||||
protected final View mView;
|
||||
|
||||
// The padding added to the drag view during the preview generation.
|
||||
public final int previewPadding;
|
||||
|
||||
public DragPreviewProvider(View view) {
|
||||
mView = view;
|
||||
|
||||
if (mView instanceof TextView) {
|
||||
Drawable d = Workspace.getTextViewIcon((TextView) mView);
|
||||
Rect bounds = getDrawableBounds(d);
|
||||
previewPadding = DRAG_BITMAP_PADDING - bounds.left - bounds.top;
|
||||
} else {
|
||||
previewPadding = DRAG_BITMAP_PADDING;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the View v into the given Canvas.
|
||||
*
|
||||
* @param destCanvas the canvas to draw on
|
||||
*/
|
||||
private void drawDragView(Canvas destCanvas) {
|
||||
destCanvas.save();
|
||||
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);
|
||||
d.draw(destCanvas);
|
||||
} else {
|
||||
final Rect clipRect = mTempRect;
|
||||
mView.getDrawingRect(clipRect);
|
||||
|
||||
boolean textVisible = false;
|
||||
if (mView instanceof FolderIcon) {
|
||||
// For FolderIcons the text can bleed into the icon area, and so we need to
|
||||
// hide the text completely (which can't be achieved by clipping).
|
||||
if (((FolderIcon) mView).getTextVisible()) {
|
||||
((FolderIcon) mView).setTextVisible(false);
|
||||
textVisible = true;
|
||||
}
|
||||
}
|
||||
destCanvas.translate(-mView.getScrollX() + DRAG_BITMAP_PADDING / 2,
|
||||
-mView.getScrollY() + DRAG_BITMAP_PADDING / 2);
|
||||
destCanvas.clipRect(clipRect, Op.REPLACE);
|
||||
mView.draw(destCanvas);
|
||||
|
||||
// Restore text visibility of FolderIcon if necessary
|
||||
if (textVisible) {
|
||||
((FolderIcon) mView).setTextVisible(true);
|
||||
}
|
||||
}
|
||||
destCanvas.restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new bitmap to show when the given View is being dragged around.
|
||||
* Responsibility for the bitmap is transferred to the caller.
|
||||
*/
|
||||
public Bitmap createDragBitmap(Canvas canvas) {
|
||||
Bitmap b;
|
||||
|
||||
if (mView instanceof TextView) {
|
||||
Drawable d = Workspace.getTextViewIcon((TextView) mView);
|
||||
Rect bounds = getDrawableBounds(d);
|
||||
b = Bitmap.createBitmap(bounds.width() + DRAG_BITMAP_PADDING,
|
||||
bounds.height() + DRAG_BITMAP_PADDING, Bitmap.Config.ARGB_8888);
|
||||
} else {
|
||||
b = Bitmap.createBitmap(mView.getWidth() + DRAG_BITMAP_PADDING,
|
||||
mView.getHeight() + DRAG_BITMAP_PADDING, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
canvas.setBitmap(b);
|
||||
drawDragView(canvas);
|
||||
canvas.setBitmap(null);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location.
|
||||
* Responsibility for the bitmap is transferred to the caller.
|
||||
*/
|
||||
public Bitmap createDragOutline(Canvas canvas) {
|
||||
final int outlineColor = mView.getResources().getColor(R.color.outline_color);
|
||||
final Bitmap b = Bitmap.createBitmap(mView.getWidth() + DRAG_BITMAP_PADDING,
|
||||
mView.getHeight() + DRAG_BITMAP_PADDING, Bitmap.Config.ARGB_8888);
|
||||
|
||||
canvas.setBitmap(b);
|
||||
drawDragView(canvas);
|
||||
HolographicOutlineHelper.obtain(mView.getContext())
|
||||
.applyExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor);
|
||||
canvas.setBitmap(null);
|
||||
return b;
|
||||
}
|
||||
|
||||
protected static Rect getDrawableBounds(Drawable d) {
|
||||
Rect bounds = new Rect();
|
||||
d.copyBounds(bounds);
|
||||
if (bounds.width() == 0 || bounds.height() == 0) {
|
||||
bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
|
||||
} else {
|
||||
bounds.offsetTo(0, 0);
|
||||
}
|
||||
if (d instanceof PreloadIconDrawable) {
|
||||
int inset = -((PreloadIconDrawable) d).getOutset();
|
||||
bounds.inset(inset, inset);
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.graphics;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.launcher3.HolographicOutlineHelper;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.graphics.DragPreviewProvider;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Extension of {@link DragPreviewProvider} which generates bitmaps scaled to the default icon size
|
||||
*/
|
||||
public class ScaledPreviewProvider extends DragPreviewProvider {
|
||||
|
||||
public ScaledPreviewProvider(View v) {
|
||||
super(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap createDragOutline(Canvas canvas) {
|
||||
if (mView instanceof TextView) {
|
||||
Bitmap b = drawScaledPreview(canvas);
|
||||
|
||||
final int outlineColor = mView.getResources().getColor(R.color.outline_color);
|
||||
HolographicOutlineHelper.obtain(mView.getContext())
|
||||
.applyExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor);
|
||||
canvas.setBitmap(null);
|
||||
return b;
|
||||
}
|
||||
return super.createDragOutline(canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap createDragBitmap(Canvas canvas) {
|
||||
if (mView instanceof TextView) {
|
||||
Bitmap b = drawScaledPreview(canvas);
|
||||
canvas.setBitmap(null);
|
||||
return b;
|
||||
|
||||
} else {
|
||||
return super.createDragBitmap(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap drawScaledPreview(Canvas canvas) {
|
||||
Drawable d = Workspace.getTextViewIcon((TextView) mView);
|
||||
Rect bounds = getDrawableBounds(d);
|
||||
|
||||
int size = Launcher.getLauncher(mView.getContext()).getDeviceProfile().iconSizePx;
|
||||
|
||||
final Bitmap b = Bitmap.createBitmap(
|
||||
size + DRAG_BITMAP_PADDING,
|
||||
size + DRAG_BITMAP_PADDING,
|
||||
Bitmap.Config.ARGB_8888);
|
||||
|
||||
canvas.setBitmap(b);
|
||||
canvas.save(Canvas.MATRIX_SAVE_FLAG);
|
||||
canvas.translate(DRAG_BITMAP_PADDING / 2, DRAG_BITMAP_PADDING / 2);
|
||||
canvas.scale(((float) size) / bounds.width(), ((float) size) / bounds.height(), 0, 0);
|
||||
canvas.translate(bounds.left, bounds.top);
|
||||
d.draw(canvas);
|
||||
canvas.restore();
|
||||
return b;
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ import com.android.launcher3.compat.UserHandleCompat;
|
||||
import com.android.launcher3.dragndrop.DragController;
|
||||
import com.android.launcher3.dragndrop.DragLayer;
|
||||
import com.android.launcher3.dragndrop.DragView;
|
||||
import com.android.launcher3.graphics.ScaledPreviewProvider;
|
||||
import com.android.launcher3.logging.UserEventDispatcher;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
|
||||
@@ -298,8 +299,7 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
|
||||
final int registrationY = motionDownY - dragLayerY;
|
||||
|
||||
float scaleDps = getResources().getDimensionPixelSize(R.dimen.deep_shortcuts_drag_view_scale);
|
||||
mDragView = new DragView(mLauncher, b, registrationX, registrationY,
|
||||
0, 0, b.getWidth(), b.getHeight(), 1f, scaleDps);
|
||||
mDragView = new DragView(mLauncher, b, registrationX, registrationY, 1f, scaleDps);
|
||||
mLastX = mLastY = mDistanceDragged = 0;
|
||||
mDragView.show(motionDownX, motionDownY);
|
||||
}
|
||||
@@ -429,7 +429,8 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
|
||||
if (!mLauncher.isDraggingEnabled()) return false;
|
||||
|
||||
// Long clicked on a shortcut.
|
||||
mLauncher.getWorkspace().beginDragShared(v, mIconLastTouchPos, this, false);
|
||||
mLauncher.getWorkspace().beginDragShared(v, mIconLastTouchPos, this, false,
|
||||
new ScaledPreviewProvider(v));
|
||||
// TODO: support dragging from within folder without having to close it
|
||||
mLauncher.closeFolder();
|
||||
return false;
|
||||
@@ -452,8 +453,7 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
|
||||
|
||||
@Override
|
||||
public float getIntrinsicIconScaleFactor() {
|
||||
return (float) getResources().getDimensionPixelSize(R.dimen.deep_shortcut_icon_size)
|
||||
/ mLauncher.getDeviceProfile().iconSizePx;
|
||||
return 1f;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user