summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2/DragView.java
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2012-02-06 16:43:52 -0800
committerWinson Chung <winsonc@google.com>2012-02-07 16:16:27 -0800
commit42c29aedf2b518c4317fc534f3c87711b57bc9b5 (patch)
tree634f6f3152ea96be08a361328f3a54d8dff99dea /src/com/android/launcher2/DragView.java
parent6af9af057f2e40c54a4ed447c4628eef7dc15683 (diff)
downloadandroid_packages_apps_Trebuchet-42c29aedf2b518c4317fc534f3c87711b57bc9b5.tar.gz
android_packages_apps_Trebuchet-42c29aedf2b518c4317fc534f3c87711b57bc9b5.tar.bz2
android_packages_apps_Trebuchet-42c29aedf2b518c4317fc534f3c87711b57bc9b5.zip
Animating the drag view scale up and down when dragging items.
- Also fixing up how we draw the drag view alpha Change-Id: Ied82aec9d52274b0fe65c989eab818b0264a9eb2
Diffstat (limited to 'src/com/android/launcher2/DragView.java')
-rw-r--r--src/com/android/launcher2/DragView.java40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/com/android/launcher2/DragView.java b/src/com/android/launcher2/DragView.java
index a3063b6e9..7be70a25a 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 Paint mPaint;
private int mRegistrationX;
@@ -65,20 +67,13 @@ 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 scale = res.getInteger(R.integer.config_dragViewScaleFactor) / 100f;
+ final float offsetX = res.getDimensionPixelSize(R.dimen.dragViewOffsetX);
+ final float offsetY = res.getDimensionPixelSize(R.dimen.dragViewOffsetY);
// 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
@@ -90,6 +85,9 @@ 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();
@@ -97,12 +95,14 @@ 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, 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
@@ -208,6 +208,18 @@ 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.
*
@@ -222,7 +234,9 @@ public class DragView extends View {
}
void remove() {
- mDragLayer.removeView(DragView.this);
+ if (getParent() != null) {
+ mDragLayer.removeView(DragView.this);
+ }
}
int[] getPosition(int[] result) {