Animating the widget previews on drag from AppsCustomize.
Change-Id: I223d66bb447c40e6870be46bb27f107f0e428a95
This commit is contained in:
@@ -32,16 +32,16 @@ import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.MaskFilter;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.TableMaskFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Process;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
@@ -620,6 +620,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
||||
// Compose the drag image
|
||||
Bitmap preview;
|
||||
Bitmap outline;
|
||||
float scale = 1f;
|
||||
if (createItemInfo instanceof PendingAddWidgetInfo) {
|
||||
PendingAddWidgetInfo createWidgetInfo = mCreateWidgetInfo;
|
||||
createItemInfo = createWidgetInfo;
|
||||
@@ -629,8 +630,24 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
||||
createItemInfo.spanX = spanXY[0];
|
||||
createItemInfo.spanY = spanXY[1];
|
||||
|
||||
FastBitmapDrawable previewDrawable = (FastBitmapDrawable) image.getDrawable();
|
||||
float minScale = 1.25f;
|
||||
int minWidth, minHeight;
|
||||
minWidth = Math.max((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]);
|
||||
minHeight = Math.max((int) (previewDrawable.getIntrinsicHeight() * minScale), size[1]);
|
||||
preview = getWidgetPreview(createWidgetInfo.componentName, createWidgetInfo.previewImage,
|
||||
createWidgetInfo.icon, spanXY[0], spanXY[1], size[0], size[1]);
|
||||
createWidgetInfo.icon, spanXY[0], spanXY[1], minWidth, minHeight);
|
||||
|
||||
// Determine the image view drawable scale relative to the preview
|
||||
float[] mv = new float[9];
|
||||
Matrix m = new Matrix();
|
||||
m.setRectToRect(
|
||||
new RectF(0f, 0f, (float) preview.getWidth(), (float) preview.getHeight()),
|
||||
new RectF(0f, 0f, (float) previewDrawable.getIntrinsicWidth(),
|
||||
(float) previewDrawable.getIntrinsicHeight()),
|
||||
Matrix.ScaleToFit.START);
|
||||
m.getValues(mv);
|
||||
scale = (float) mv[0];
|
||||
} else {
|
||||
// Workaround for the fact that we don't keep the original ResolveInfo associated with
|
||||
// the shortcut around. To get the icon, we just render the preview image (which has
|
||||
@@ -663,7 +680,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
||||
mLauncher.lockScreenOrientationOnLargeUI();
|
||||
mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, alphaClipPaint);
|
||||
mDragController.startDrag(image, preview, this, createItemInfo,
|
||||
DragController.DRAG_ACTION_COPY, null);
|
||||
DragController.DRAG_ACTION_COPY, null, scale);
|
||||
outline.recycle();
|
||||
preview.recycle();
|
||||
}
|
||||
@@ -695,7 +712,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
||||
mLauncher.enterSpringLoadedDragMode();
|
||||
}
|
||||
}
|
||||
},150);
|
||||
}, 150);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1035,10 +1052,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
||||
if (widgetPreviewExists) {
|
||||
bitmapWidth = drawable.getIntrinsicWidth();
|
||||
bitmapHeight = drawable.getIntrinsicHeight();
|
||||
|
||||
// Cap the size so widget previews don't appear larger than the actual widget
|
||||
maxWidth = Math.min(maxWidth, mWidgetSpacingLayout.estimateCellWidth(cellHSpan));
|
||||
maxHeight = Math.min(maxHeight, mWidgetSpacingLayout.estimateCellHeight(cellVSpan));
|
||||
} else {
|
||||
// Determine the size of the bitmap for the preview image we will generate
|
||||
// TODO: This actually uses the apps customize cell layout params, where as we make want
|
||||
@@ -1214,8 +1227,13 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
||||
if (rawInfo instanceof AppWidgetProviderInfo) {
|
||||
AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo;
|
||||
int[] cellSpans = mLauncher.getSpanForWidget(info, null);
|
||||
|
||||
int maxWidth = Math.min(data.maxImageWidth,
|
||||
mWidgetSpacingLayout.estimateCellWidth(cellSpans[0]));
|
||||
int maxHeight = Math.min(data.maxImageHeight,
|
||||
mWidgetSpacingLayout.estimateCellHeight(cellSpans[1]));
|
||||
Bitmap b = getWidgetPreview(info.provider, info.previewImage, info.icon,
|
||||
cellSpans[0], cellSpans[1], data.maxImageWidth, data.maxImageHeight);
|
||||
cellSpans[0], cellSpans[1], maxWidth, maxHeight);
|
||||
images.add(b);
|
||||
} else if (rawInfo instanceof ResolveInfo) {
|
||||
// Fill in the shortcuts information
|
||||
|
||||
@@ -185,7 +185,7 @@ public class DragController {
|
||||
int dragLayerX = loc[0];
|
||||
int dragLayerY = loc[1];
|
||||
|
||||
startDrag(b, dragLayerX, dragLayerY, source, dragInfo, dragAction, null, dragRegion);
|
||||
startDrag(b, dragLayerX, dragLayerY, source, dragInfo, dragAction, null, dragRegion, 1f);
|
||||
b.recycle();
|
||||
|
||||
if (dragAction == DRAG_ACTION_MOVE) {
|
||||
@@ -206,36 +206,22 @@ public class DragController {
|
||||
* Makes dragging feel more precise, e.g. you can clip out a transparent border
|
||||
*/
|
||||
public void startDrag(View v, Bitmap bmp, DragSource source, Object dragInfo, int dragAction,
|
||||
Rect dragRegion) {
|
||||
Rect dragRegion, float initialDragViewScale) {
|
||||
int[] loc = mCoordinatesTemp;
|
||||
mLauncher.getDragLayer().getLocationInDragLayer(v, loc);
|
||||
int dragLayerX = loc[0];
|
||||
int dragLayerY = loc[1];
|
||||
int dragLayerX = loc[0] + v.getPaddingLeft() +
|
||||
(int) ((initialDragViewScale * bmp.getWidth() - bmp.getWidth()) / 2);
|
||||
int dragLayerY = loc[1] + v.getPaddingTop() +
|
||||
(int) ((initialDragViewScale * bmp.getHeight() - bmp.getHeight()) / 2);
|
||||
|
||||
startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, dragAction, null, dragRegion);
|
||||
startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, dragAction, null, dragRegion,
|
||||
initialDragViewScale);
|
||||
|
||||
if (dragAction == DRAG_ACTION_MOVE) {
|
||||
v.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a drag.
|
||||
*
|
||||
* @param b The bitmap to display as the drag image. It will be re-scaled to the
|
||||
* enlarged size.
|
||||
* @param dragLayerX The x position in the DragLayer of the left-top of the bitmap.
|
||||
* @param dragLayerY The y position in the DragLayer of the left-top of the bitmap.
|
||||
* @param source An object representing where the drag originated
|
||||
* @param dragInfo The data associated with the object that is being dragged
|
||||
* @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
|
||||
* {@link #DRAG_ACTION_COPY}
|
||||
*/
|
||||
public void startDrag(Bitmap b, int dragLayerX, int dragLayerY,
|
||||
DragSource source, Object dragInfo, int dragAction) {
|
||||
startDrag(b, dragLayerX, dragLayerY, source, dragInfo, dragAction, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a drag.
|
||||
*
|
||||
@@ -251,7 +237,8 @@ public class DragController {
|
||||
* Makes dragging feel more precise, e.g. you can clip out a transparent border
|
||||
*/
|
||||
public void startDrag(Bitmap b, int dragLayerX, int dragLayerY,
|
||||
DragSource source, Object dragInfo, int dragAction, Point dragOffset, Rect dragRegion) {
|
||||
DragSource source, Object dragInfo, int dragAction, Point dragOffset, Rect dragRegion,
|
||||
float initialDragViewScale) {
|
||||
if (PROFILE_DRAWING_DURING_DRAG) {
|
||||
android.os.Debug.startMethodTracing("Launcher");
|
||||
}
|
||||
@@ -286,7 +273,7 @@ public class DragController {
|
||||
mVibrator.vibrate(VIBRATE_DURATION);
|
||||
|
||||
final DragView dragView = mDragObject.dragView = new DragView(mLauncher, b, registrationX,
|
||||
registrationY, 0, 0, b.getWidth(), b.getHeight());
|
||||
registrationY, 0, 0, b.getWidth(), b.getHeight(), initialDragViewScale);
|
||||
|
||||
if (dragOffset != null) {
|
||||
dragView.setDragVisualizeOffset(new Point(dragOffset));
|
||||
|
||||
@@ -62,7 +62,7 @@ public class DragView extends View {
|
||||
* @param registrationY The y coordinate of the registration point.
|
||||
*/
|
||||
public DragView(Launcher launcher, Bitmap bitmap, int registrationX, int registrationY,
|
||||
int left, int top, int width, int height) {
|
||||
int left, int top, int width, int height, final float initialScale) {
|
||||
super(launcher);
|
||||
mDragLayer = launcher.getDragLayer();
|
||||
|
||||
@@ -86,8 +86,8 @@ public class DragView extends View {
|
||||
|
||||
mOffsetX += deltaX;
|
||||
mOffsetY += deltaY;
|
||||
setScaleX(1f + (value * (scale - 1f)));
|
||||
setScaleY(1f + (value * (scale - 1f)));
|
||||
setScaleX(initialScale + (value * (scale - initialScale)));
|
||||
setScaleY(initialScale + (value * (scale - initialScale)));
|
||||
if (sDragAlpha != 1f) {
|
||||
setAlpha(sDragAlpha * value + (1f - value));
|
||||
}
|
||||
|
||||
@@ -38,8 +38,6 @@ public class PagedViewWidget extends LinearLayout {
|
||||
|
||||
private static boolean sDeletePreviewsWhenDetachedFromWindow = true;
|
||||
|
||||
private ImageView mPreviewImageView;
|
||||
|
||||
private String mDimensionsFormatString;
|
||||
CheckForShortPress mPendingCheckForShortPress = null;
|
||||
ShortPressListener mShortPressListener = null;
|
||||
@@ -90,7 +88,6 @@ public class PagedViewWidget extends LinearLayout {
|
||||
image.setMaxWidth(maxWidth);
|
||||
}
|
||||
image.setContentDescription(info.label);
|
||||
mPreviewImageView = image;
|
||||
final TextView name = (TextView) findViewById(R.id.widget_name);
|
||||
name.setText(info.label);
|
||||
final TextView dims = (TextView) findViewById(R.id.widget_dims);
|
||||
@@ -103,7 +100,6 @@ public class PagedViewWidget extends LinearLayout {
|
||||
CharSequence label = info.loadLabel(pm);
|
||||
final ImageView image = (ImageView) findViewById(R.id.widget_preview);
|
||||
image.setContentDescription(label);
|
||||
mPreviewImageView = image;
|
||||
final TextView name = (TextView) findViewById(R.id.widget_name);
|
||||
name.setText(label);
|
||||
final TextView dims = (TextView) findViewById(R.id.widget_dims);
|
||||
|
||||
@@ -1962,7 +1962,7 @@ public class Workspace extends SmoothPagedView
|
||||
}
|
||||
|
||||
mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(),
|
||||
DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect);
|
||||
DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, 1f);
|
||||
b.recycle();
|
||||
|
||||
// Show the scrolling indicator when you pick up an item
|
||||
|
||||
Reference in New Issue
Block a user