From 72d598400da7cef9c7fc4f99bb1fcd7ff0710011 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Wed, 22 Feb 2012 13:51:36 -0800 Subject: Animating the widget previews on drag from AppsCustomize. Change-Id: I223d66bb447c40e6870be46bb27f107f0e428a95 --- .../android/launcher2/AppsCustomizePagedView.java | 40 ++++++++++++++++------ src/com/android/launcher2/DragController.java | 35 ++++++------------- src/com/android/launcher2/DragView.java | 6 ++-- src/com/android/launcher2/PagedViewWidget.java | 4 --- src/com/android/launcher2/Workspace.java | 2 +- 5 files changed, 44 insertions(+), 43 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java index 865c8947b..2001ad929 100644 --- a/src/com/android/launcher2/AppsCustomizePagedView.java +++ b/src/com/android/launcher2/AppsCustomizePagedView.java @@ -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 diff --git a/src/com/android/launcher2/DragController.java b/src/com/android/launcher2/DragController.java index 425f301ae..d75c164b3 100644 --- a/src/com/android/launcher2/DragController.java +++ b/src/com/android/launcher2/DragController.java @@ -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)); diff --git a/src/com/android/launcher2/DragView.java b/src/com/android/launcher2/DragView.java index 79f9b8139..1b3029334 100644 --- a/src/com/android/launcher2/DragView.java +++ b/src/com/android/launcher2/DragView.java @@ -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)); } diff --git a/src/com/android/launcher2/PagedViewWidget.java b/src/com/android/launcher2/PagedViewWidget.java index 5ba869118..670717e49 100644 --- a/src/com/android/launcher2/PagedViewWidget.java +++ b/src/com/android/launcher2/PagedViewWidget.java @@ -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); diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 1643be537..94304e5f5 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -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 -- cgit v1.2.3