diff options
author | Winson Chung <winsonc@google.com> | 2012-02-13 13:03:52 -0800 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2012-02-13 13:03:52 -0800 |
commit | a1cdab039292f3d809528c0e2e38580b37864d8d (patch) | |
tree | 696d35b58eea07325f0a839d95eafdf79f9c0583 /src/com/android/launcher2 | |
parent | 9659d0c3a5c29f880bc12d1051e3e3beae2d4a87 (diff) | |
download | android_packages_apps_Trebuchet-a1cdab039292f3d809528c0e2e38580b37864d8d.tar.gz android_packages_apps_Trebuchet-a1cdab039292f3d809528c0e2e38580b37864d8d.tar.bz2 android_packages_apps_Trebuchet-a1cdab039292f3d809528c0e2e38580b37864d8d.zip |
Reverting: "Animating the drag view scale up and down when dragging items."
Change-Id: I133ff2631834a4b97e1e4750fb7c07793ddeba69
Diffstat (limited to 'src/com/android/launcher2')
-rw-r--r-- | src/com/android/launcher2/AppsCustomizePagedView.java | 8 | ||||
-rw-r--r-- | src/com/android/launcher2/DragController.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher2/DragLayer.java | 85 | ||||
-rw-r--r-- | src/com/android/launcher2/DragView.java | 40 | ||||
-rw-r--r-- | src/com/android/launcher2/DropTarget.java | 3 | ||||
-rw-r--r-- | src/com/android/launcher2/FolderIcon.java | 11 | ||||
-rw-r--r-- | src/com/android/launcher2/InfoDropTarget.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 4 |
8 files changed, 78 insertions, 81 deletions
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java index 8db1ab694..7cfe3be2f 100644 --- a/src/com/android/launcher2/AppsCustomizePagedView.java +++ b/src/com/android/launcher2/AppsCustomizePagedView.java @@ -201,6 +201,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen private Canvas mCanvas; private Drawable mDefaultWidgetBackground; private IconCache mIconCache; + private int mDragViewMultiplyColor; // Dimens private int mContentWidth; @@ -242,6 +243,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen Resources resources = context.getResources(); mDefaultWidgetBackground = resources.getDrawable(R.drawable.default_widget_preview_holo); mAppIconSize = resources.getDimensionPixelSize(R.dimen.app_icon_size); + mDragViewMultiplyColor = resources.getColor(R.color.drag_view_multiply_color); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppsCustomizePagedView, 0, 0); mMaxAppCellCountX = a.getInt(R.styleable.AppsCustomizePagedView_maxAppCellCountX, -1); @@ -578,6 +580,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen // Save the preview for the outline generation, then dim the preview outline = Bitmap.createScaledBitmap(preview, preview.getWidth(), preview.getHeight(), false); + mCanvas.setBitmap(preview); + mCanvas.drawColor(mDragViewMultiplyColor, PorterDuff.Mode.MULTIPLY); + mCanvas.setBitmap(null); // Start the drag alphaClipPaint = null; @@ -903,6 +908,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen d.setBounds(x, y, x + w, y + h); d.draw(c); d.setBounds(oldBounds); // Restore the bounds + if (multiplyColor != 0xFFFFFFFF) { + c.drawColor(mDragViewMultiplyColor, PorterDuff.Mode.MULTIPLY); + } c.setBitmap(null); } } diff --git a/src/com/android/launcher2/DragController.java b/src/com/android/launcher2/DragController.java index 425f301ae..8658eebae 100644 --- a/src/com/android/launcher2/DragController.java +++ b/src/com/android/launcher2/DragController.java @@ -394,9 +394,7 @@ public class DragController { listener.onDragEnd(); } if (mDragObject.dragView != null) { - if (!mDragObject.deferDragViewCleanupPostAnimation) { - mDragObject.dragView.remove(); - } + mDragObject.dragView.remove(); mDragObject.dragView = null; } } diff --git a/src/com/android/launcher2/DragLayer.java b/src/com/android/launcher2/DragLayer.java index 05596ef67..c315b6018 100644 --- a/src/com/android/launcher2/DragLayer.java +++ b/src/com/android/launcher2/DragLayer.java @@ -62,10 +62,13 @@ public class DragLayer extends FrameLayout { private ValueAnimator mDropAnim = null; private ValueAnimator mFadeOutAnim = null; private TimeInterpolator mCubicEaseOutInterpolator = new DecelerateInterpolator(1.5f); - private DragView mDropView = null; + private View mDropView = null; private int mAnchorViewInitialScrollX = 0; private View mAnchorView = null; + private int[] mDropViewPos = new int[2]; + private float mDropViewScale; + private float mDropViewAlpha; private boolean mHoverPointClosesFolder = false; private Rect mHitRect = new Rect(); private int mWorkspaceIndex = -1; @@ -487,7 +490,7 @@ public class DragLayer extends FrameLayout { onCompleteRunnable, true, duration, anchorView); } - private void animateViewIntoPosition(final DragView view, final int fromX, final int fromY, + private void animateViewIntoPosition(final View view, final int fromX, final int fromY, final int toX, final int toY, float finalScale, Runnable onCompleteRunnable, boolean fadeOut, int duration, View anchorView) { Rect from = new Rect(fromX, fromY, fromX + @@ -518,10 +521,10 @@ public class DragLayer extends FrameLayout { * anchored to in case scrolling is currently taking place. Note: currently this is * only used for the X dimension for the case of the workspace. */ - public void animateView(final DragView view, final Rect from, final Rect to, - final float finalAlpha, final float finalScale, int duration, - final Interpolator motionInterpolator, final Interpolator alphaInterpolator, - final Runnable onCompleteRunnable, final boolean fadeOut, View anchorView) { + public void animateView(final View view, final Rect from, final Rect to, final float finalAlpha, + final float finalScale, int duration, final Interpolator motionInterpolator, + final Interpolator alphaInterpolator, final Runnable onCompleteRunnable, + final boolean fadeOut, View anchorView) { // Calculate the duration of the animation based on the object's distance final float dist = (float) Math.sqrt(Math.pow(to.left - from.left, 2) + Math.pow(to.top - from.top, 2)); @@ -544,10 +547,8 @@ public class DragLayer extends FrameLayout { mFadeOutAnim.cancel(); } - // Show the drop view if it was previously hidden mDropView = view; - mDropView.cancelAnimation(); - mDropView.resetLayoutParams(); + final float initialAlpha = view.getAlpha(); mDropAnim = new ValueAnimator(); if (alphaInterpolator == null || motionInterpolator == null) { mDropAnim.setInterpolator(mCubicEaseOutInterpolator); @@ -558,39 +559,29 @@ public class DragLayer extends FrameLayout { } mAnchorView = anchorView; - final float initialAlpha = view.getAlpha(); - final float initialScale = mDropView.getScaleX(); - mDropAnim.setDuration(duration); mDropAnim.setFloatValues(0.0f, 1.0f); mDropAnim.removeAllUpdateListeners(); mDropAnim.addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { final float percent = (Float) animation.getAnimatedValue(); - final int width = view.getMeasuredWidth(); - final int height = view.getMeasuredHeight(); + // Invalidate the old position + int width = view.getMeasuredWidth(); + int height = view.getMeasuredHeight(); + invalidate(mDropViewPos[0], mDropViewPos[1], + mDropViewPos[0] + width, mDropViewPos[1] + height); float alphaPercent = alphaInterpolator == null ? percent : alphaInterpolator.getInterpolation(percent); float motionPercent = motionInterpolator == null ? percent : motionInterpolator.getInterpolation(percent); - float scale = finalScale * percent + initialScale * (1 - percent); - float alpha = finalAlpha * alphaPercent + initialAlpha * (1 - alphaPercent); - - float fromLeft = from.left + (initialScale - 1f) * width / 2; - float fromTop = from.top + (initialScale - 1f) * height / 2; - int x = (int) (fromLeft + Math.round(((to.left - fromLeft) * motionPercent))); - int y = (int) (fromTop + Math.round(((to.top - fromTop) * motionPercent))); - - int xPos = x - mDropView.getScrollX() + (mAnchorView != null - ? (mAnchorViewInitialScrollX - mAnchorView.getScrollX()) : 0); - int yPos = y - mDropView.getScrollY(); - mDropView.setTranslationX(xPos); - mDropView.setTranslationY(yPos); - mDropView.setScaleX(scale); - mDropView.setScaleY(scale); - mDropView.setAlpha(alpha); - invalidate(); + + mDropViewPos[0] = from.left + (int) Math.round(((to.left - from.left) * motionPercent)); + mDropViewPos[1] = from.top + (int) Math.round(((to.top - from.top) * motionPercent)); + mDropViewScale = percent * finalScale + (1 - percent); + mDropViewAlpha = alphaPercent * finalAlpha + (1 - alphaPercent) * initialAlpha; + invalidate(mDropViewPos[0], mDropViewPos[1], + mDropViewPos[0] + width, mDropViewPos[1] + height); } }); mDropAnim.addListener(new AnimatorListenerAdapter() { @@ -601,7 +592,6 @@ public class DragLayer extends FrameLayout { if (fadeOut) { fadeOutDragView(); } else { - mDropView.remove(); mDropView = null; } } @@ -617,15 +607,15 @@ public class DragLayer extends FrameLayout { mFadeOutAnim.addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { final float percent = (Float) animation.getAnimatedValue(); - - float alpha = 1 - percent; - mDropView.setAlpha(alpha); - invalidate(); + mDropViewAlpha = 1 - percent; + int width = mDropView.getMeasuredWidth(); + int height = mDropView.getMeasuredHeight(); + invalidate(mDropViewPos[0], mDropViewPos[1], + mDropViewPos[0] + width, mDropViewPos[1] + height); } }); mFadeOutAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { - mDropView.remove(); mDropView = null; } }); @@ -675,4 +665,25 @@ public class DragLayer extends FrameLayout { return i; } } + + @Override + protected void dispatchDraw(Canvas canvas) { + super.dispatchDraw(canvas); + if (mDropView != null) { + // We are animating an item that was just dropped on the home screen. + // Render its View in the current animation position. + canvas.save(Canvas.MATRIX_SAVE_FLAG); + final int xPos = mDropViewPos[0] - mDropView.getScrollX() + (mAnchorView != null + ? (mAnchorViewInitialScrollX - mAnchorView.getScrollX()) : 0); + final int yPos = mDropViewPos[1] - mDropView.getScrollY(); + int width = mDropView.getMeasuredWidth(); + int height = mDropView.getMeasuredHeight(); + canvas.translate(xPos, yPos); + canvas.translate((1 - mDropViewScale) * width / 2, (1 - mDropViewScale) * height / 2); + canvas.scale(mDropViewScale, mDropViewScale); + mDropView.setAlpha(mDropViewAlpha); + mDropView.draw(canvas); + canvas.restore(); + } + } } diff --git a/src/com/android/launcher2/DragView.java b/src/com/android/launcher2/DragView.java index 7be70a25a..a3063b6e9 100644 --- a/src/com/android/launcher2/DragView.java +++ b/src/com/android/launcher2/DragView.java @@ -32,8 +32,6 @@ import android.view.animation.DecelerateInterpolator; import com.android.launcher.R; public class DragView extends View { - private static float sDragAlpha = 0.8f; - private Bitmap mBitmap; private Paint mPaint; private int mRegistrationX; @@ -67,13 +65,20 @@ public class DragView extends View { mDragLayer = launcher.getDragLayer(); final Resources res = getResources(); - final float scale = res.getInteger(R.integer.config_dragViewScaleFactor) / 100f; - final float offsetX = res.getDimensionPixelSize(R.dimen.dragViewOffsetX); - final float offsetY = res.getDimensionPixelSize(R.dimen.dragViewOffsetY); + final int dragScale = res.getInteger(R.integer.config_dragViewExtraPixels); + + Matrix scale = new Matrix(); + final float scaleFactor = (width + dragScale) / width; + if (scaleFactor != 1.0f) { + scale.setScale(scaleFactor, scaleFactor); + } + + final int offsetX = res.getDimensionPixelSize(R.dimen.dragViewOffsetX); + final int offsetY = res.getDimensionPixelSize(R.dimen.dragViewOffsetY); // Animate the view into the correct position mAnim = ValueAnimator.ofFloat(0.0f, 1.0f); - mAnim.setDuration(150); + mAnim.setDuration(110); mAnim.setInterpolator(new DecelerateInterpolator(2.5f)); mAnim.addUpdateListener(new AnimatorUpdateListener() { @Override @@ -85,9 +90,6 @@ public class DragView extends View { mOffsetX += deltaX; mOffsetY += deltaY; - setScaleX(1f + (value * (scale - 1f))); - setScaleY(1f + (value * (scale - 1f))); - setAlpha(sDragAlpha * value + (1f - value)); if (getParent() == null) { animation.cancel(); @@ -95,14 +97,12 @@ public class DragView extends View { DragLayer.LayoutParams lp = mLayoutParams; lp.x += deltaX; lp.y += deltaY; - lp.width = mBitmap.getWidth(); - lp.height = mBitmap.getHeight(); mDragLayer.requestLayout(); } } }); - mBitmap = Bitmap.createBitmap(bitmap, left, top, width, height); + mBitmap = Bitmap.createBitmap(bitmap, left, top, width, height, scale, true); setDragRegion(new Rect(0, 0, width, height)); // The point in our scaled bitmap that the touch events are located @@ -208,18 +208,6 @@ public class DragView extends View { mAnim.start(); } - public void cancelAnimation() { - if (mAnim != null && mAnim.isRunning()) { - mAnim.cancel(); - } - } - - public void resetLayoutParams() { - DragLayer.LayoutParams lp = mLayoutParams; - lp.x = lp.y = 0; - mOffsetX = mOffsetY = 0; - } - /** * Move the window containing this view. * @@ -234,9 +222,7 @@ public class DragView extends View { } void remove() { - if (getParent() != null) { - mDragLayer.removeView(DragView.this); - } + mDragLayer.removeView(DragView.this); } int[] getPosition(int[] result) { diff --git a/src/com/android/launcher2/DropTarget.java b/src/com/android/launcher2/DropTarget.java index e49f7829b..4172da243 100644 --- a/src/com/android/launcher2/DropTarget.java +++ b/src/com/android/launcher2/DropTarget.java @@ -55,9 +55,6 @@ public interface DropTarget { /** Indicates that the drag operation was cancelled */ public boolean cancelled = false; - /** Defers removing the DragView from the DragLayer until after the drop animation. */ - public boolean deferDragViewCleanupPostAnimation = true; - public DragObject() { } } diff --git a/src/com/android/launcher2/FolderIcon.java b/src/com/android/launcher2/FolderIcon.java index a02351630..2a711f88b 100644 --- a/src/com/android/launcher2/FolderIcon.java +++ b/src/com/android/launcher2/FolderIcon.java @@ -295,14 +295,14 @@ public class FolderIcon extends LinearLayout implements FolderListener { } public void performCreateAnimation(final ShortcutInfo destInfo, final View destView, - final ShortcutInfo srcInfo, final DragView srcView, Rect dstRect, + final ShortcutInfo srcInfo, final View srcView, Rect dstRect, float scaleRelativeToDragLayer, Runnable postAnimationRunnable) { Drawable animateDrawable = ((TextView) destView).getCompoundDrawables()[1]; computePreviewDrawingParams(animateDrawable.getIntrinsicWidth(), destView.getMeasuredWidth()); // This will animate the dragView (srcView) into the new folder - onDrop(srcInfo, srcView, dstRect, scaleRelativeToDragLayer, 1, postAnimationRunnable, null); + onDrop(srcInfo, srcView, dstRect, scaleRelativeToDragLayer, 1, postAnimationRunnable); // This will animate the first item from it's position as an icon into its // position as the first item in the preview @@ -320,9 +320,8 @@ public class FolderIcon extends LinearLayout implements FolderListener { mFolderRingAnimator.animateToNaturalState(); } - private void onDrop(final ShortcutInfo item, DragView animateView, Rect finalRect, - float scaleRelativeToDragLayer, int index, Runnable postAnimationRunnable, - DragObject d) { + private void onDrop(final ShortcutInfo item, View animateView, Rect finalRect, + float scaleRelativeToDragLayer, int index, Runnable postAnimationRunnable) { item.cellX = -1; item.cellY = -1; @@ -383,7 +382,7 @@ public class FolderIcon extends LinearLayout implements FolderListener { item = (ShortcutInfo) d.dragInfo; } mFolder.notifyDrop(); - onDrop(item, d.dragView, null, 1.0f, mInfo.contents.size(), d.postAnimationRunnable, d); + onDrop(item, d.dragView, null, 1.0f, mInfo.contents.size(), d.postAnimationRunnable); } public DropTarget getDropTargetDelegate(DragObject d) { diff --git a/src/com/android/launcher2/InfoDropTarget.java b/src/com/android/launcher2/InfoDropTarget.java index 21fe8baca..dba845b04 100644 --- a/src/com/android/launcher2/InfoDropTarget.java +++ b/src/com/android/launcher2/InfoDropTarget.java @@ -29,7 +29,6 @@ import android.view.View; import android.view.ViewGroup; import com.android.launcher.R; -import com.android.launcher2.DropTarget.DragObject; public class InfoDropTarget extends ButtonDropTarget { @@ -86,9 +85,6 @@ public class InfoDropTarget extends ButtonDropTarget { if (componentName != null) { mLauncher.startApplicationDetailsActivity(componentName); } - - // There is no post-drop animation, so clean up the DragView now - d.deferDragViewCleanupPostAnimation = false; return false; } diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 41a2bfb0f..746c68229 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -169,6 +169,7 @@ public class Workspace extends SmoothPagedView private Bitmap mDragOutline = null; private final Rect mTempRect = new Rect(); private final int[] mTempXY = new int[2]; + private int mDragViewMultiplyColor; private float mOverscrollFade = 0; // Paint used to draw external drop outline @@ -290,6 +291,7 @@ public class Workspace extends SmoothPagedView mSpringLoadedShrinkFactor = res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f; + mDragViewMultiplyColor = res.getColor(R.color.drag_view_multiply_color); // if the value is manually specified, use that instead cellCountX = a.getInt(R.styleable.Workspace_cellCountX, cellCountX); @@ -1792,6 +1794,7 @@ public class Workspace extends SmoothPagedView canvas.setBitmap(b); drawDragView(v, canvas, padding, true); mOutlineHelper.applyOuterBlur(b, canvas, outlineColor); + canvas.drawColor(mDragViewMultiplyColor, PorterDuff.Mode.MULTIPLY); canvas.setBitmap(null); return b; @@ -2244,7 +2247,6 @@ public class Workspace extends SmoothPagedView mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, cell, duration, disableHardwareLayersRunnable, this); } else { - d.deferDragViewCleanupPostAnimation = false; cell.setVisibility(VISIBLE); } parent.onDropChild(cell); |