diff options
author | Winson Chung <winsonc@google.com> | 2012-02-13 18:29:29 -0800 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2012-02-13 19:05:25 -0800 |
commit | 7bd1bbb509f9569fa18d6b4d33242679fd98bc9b (patch) | |
tree | a97556f231f5867d3d254ffad9f4b4e7bbfaafec /src/com/android/launcher2/DragView.java | |
parent | d83f5f4db328fbd152491bbf9fa13abc94bd6f25 (diff) | |
download | android_packages_apps_Trebuchet-7bd1bbb509f9569fa18d6b4d33242679fd98bc9b.tar.gz android_packages_apps_Trebuchet-7bd1bbb509f9569fa18d6b4d33242679fd98bc9b.tar.bz2 android_packages_apps_Trebuchet-7bd1bbb509f9569fa18d6b4d33242679fd98bc9b.zip |
Animating the drag view scale up and down when dragging items.
Change-Id: Ic97d74a14964c6bdc23305b2d378b13a1f2e3664
Diffstat (limited to 'src/com/android/launcher2/DragView.java')
-rw-r--r-- | src/com/android/launcher2/DragView.java | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/src/com/android/launcher2/DragView.java b/src/com/android/launcher2/DragView.java index 15d9c5449..90b2083a0 100644 --- a/src/com/android/launcher2/DragView.java +++ b/src/com/android/launcher2/DragView.java @@ -32,6 +32,8 @@ 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 Bitmap mCrossFadeBitmap; private Paint mPaint; @@ -48,8 +50,6 @@ public class DragView extends View { private float mOffsetX = 0.0f; private float mOffsetY = 0.0f; - private DragLayer.LayoutParams mLayoutParams; - /** * Construct the drag view. * <p> @@ -67,20 +67,14 @@ public class DragView extends View { mDragLayer = launcher.getDragLayer(); final Resources res = getResources(); - 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); + final float offsetX = res.getDimensionPixelSize(R.dimen.dragViewOffsetX); + final float offsetY = res.getDimensionPixelSize(R.dimen.dragViewOffsetY); + final float scaleDps = res.getDimensionPixelSize(R.dimen.dragViewScale); + final float scale = (width + scaleDps) / width; // Animate the view into the correct position mAnim = ValueAnimator.ofFloat(0.0f, 1.0f); - mAnim.setDuration(110); + mAnim.setDuration(150); mAnim.setInterpolator(new DecelerateInterpolator(2.5f)); mAnim.addUpdateListener(new AnimatorUpdateListener() { @Override @@ -92,19 +86,20 @@ 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(); } else { - DragLayer.LayoutParams lp = mLayoutParams; - lp.x += deltaX; - lp.y += deltaY; - mDragLayer.requestLayout(); + setTranslationX(getTranslationX() + deltaX); + setTranslationY(getTranslationY() + deltaY); } } }); - mBitmap = Bitmap.createBitmap(bitmap, left, top, width, height, scale, true); + mBitmap = Bitmap.createBitmap(bitmap, left, top, width, height); setDragRegion(new Rect(0, 0, width, height)); // The point in our scaled bitmap that the touch events are located @@ -236,14 +231,24 @@ public class DragView extends View { DragLayer.LayoutParams lp = new DragLayer.LayoutParams(0, 0); lp.width = mBitmap.getWidth(); lp.height = mBitmap.getHeight(); - lp.x = touchX - mRegistrationX; - lp.y = touchY - mRegistrationY; lp.customPosition = true; setLayoutParams(lp); - mLayoutParams = lp; + setTranslationX(touchX - mRegistrationX); + setTranslationY(touchY - mRegistrationY); mAnim.start(); } + public void cancelAnimation() { + if (mAnim != null && mAnim.isRunning()) { + mAnim.cancel(); + } + } + + public void resetLayoutParams() { + mOffsetX = mOffsetY = 0; + requestLayout(); + } + /** * Move the window containing this view. * @@ -251,22 +256,14 @@ public class DragView extends View { * @param touchY the y coordinate the user touched in DragLayer coordinates */ void move(int touchX, int touchY) { - DragLayer.LayoutParams lp = mLayoutParams; - lp.x = touchX - mRegistrationX + (int) mOffsetX; - lp.y = touchY - mRegistrationY + (int) mOffsetY; - mDragLayer.requestLayout(); + setTranslationX(touchX - mRegistrationX + (int) mOffsetX); + setTranslationY(touchY - mRegistrationY + (int) mOffsetY); } void remove() { - mDragLayer.removeView(DragView.this); - } - - int[] getPosition(int[] result) { - DragLayer.LayoutParams lp = mLayoutParams; - if (result == null) result = new int[2]; - result[0] = lp.x; - result[1] = lp.y; - return result; + if (getParent() != null) { + mDragLayer.removeView(DragView.this); + } } } |