summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2012-02-28 18:11:33 -0800
committerWinson Chung <winsonc@google.com>2012-02-29 10:25:41 -0800
commit61967cb17f8fa9ee01f93e9f25a1074559b54cf3 (patch)
tree7749dd23ffc78d1e1a7a6c57f40f5453874a30bd /src
parent483e01b0ae587c891d7ead0bea5a860833f5a1fd (diff)
downloadandroid_packages_apps_Trebuchet-61967cb17f8fa9ee01f93e9f25a1074559b54cf3.tar.gz
android_packages_apps_Trebuchet-61967cb17f8fa9ee01f93e9f25a1074559b54cf3.tar.bz2
android_packages_apps_Trebuchet-61967cb17f8fa9ee01f93e9f25a1074559b54cf3.zip
Fixing flashing icon on delete, and offset of delete animation.
Change-Id: I993f2d8e54cc7052e16f318a09ada80e9b766147
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/ButtonDropTarget.java27
-rw-r--r--src/com/android/launcher2/DeleteDropTarget.java38
-rw-r--r--src/com/android/launcher2/DragView.java10
-rw-r--r--src/com/android/launcher2/InfoDropTarget.java6
4 files changed, 43 insertions, 38 deletions
diff --git a/src/com/android/launcher2/ButtonDropTarget.java b/src/com/android/launcher2/ButtonDropTarget.java
index 4ff7c9669..dc34d8828 100644
--- a/src/com/android/launcher2/ButtonDropTarget.java
+++ b/src/com/android/launcher2/ButtonDropTarget.java
@@ -19,6 +19,7 @@ package com.android.launcher2;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Paint;
+import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;
@@ -41,7 +42,7 @@ public class ButtonDropTarget extends TextView implements DropTarget, DragContro
protected boolean mActive;
/** The paint applied to the drag view on hover */
- protected final Paint mHoverPaint = new Paint();
+ protected int mHoverColor = 0;
public ButtonDropTarget(Context context, AttributeSet attrs) {
this(context, attrs, 0);
@@ -71,7 +72,7 @@ public class ButtonDropTarget extends TextView implements DropTarget, DragContro
}
public void onDragEnter(DragObject d) {
- d.dragView.setPaint(mHoverPaint);
+ d.dragView.setColor(mHoverColor);
}
public void onDragOver(DragObject d) {
@@ -79,7 +80,7 @@ public class ButtonDropTarget extends TextView implements DropTarget, DragContro
}
public void onDragExit(DragObject d) {
- d.dragView.setPaint(null);
+ d.dragView.setColor(0);
}
public void onDragStart(DragSource source, Object info, int dragAction) {
@@ -100,6 +101,26 @@ public class ButtonDropTarget extends TextView implements DropTarget, DragContro
outRect.bottom += mBottomDragPadding;
}
+ Rect getIconRect(int itemWidth, int itemHeight, int drawableWidth, int drawableHeight) {
+ DragLayer dragLayer = mLauncher.getDragLayer();
+
+ // Find the rect to animate to (the view is center aligned)
+ Rect to = new Rect();
+ dragLayer.getViewRectRelativeToSelf(this, to);
+ int width = drawableWidth;
+ int height = drawableHeight;
+ int left = to.left + getPaddingLeft();
+ int top = to.top + (getMeasuredHeight() - height) / 2;
+ to.set(left, top, left + width, top + height);
+
+ // Center the destination rect about the trash icon
+ int xOffset = (int) -(itemWidth - width) / 2;
+ int yOffset = (int) -(itemHeight - height) / 2;
+ to.offset(xOffset, yOffset);
+
+ return to;
+ }
+
@Override
public DropTarget getDropTargetDelegate(DragObject d) {
return null;
diff --git a/src/com/android/launcher2/DeleteDropTarget.java b/src/com/android/launcher2/DeleteDropTarget.java
index a6b2b5c8b..4621dea85 100644
--- a/src/com/android/launcher2/DeleteDropTarget.java
+++ b/src/com/android/launcher2/DeleteDropTarget.java
@@ -20,22 +20,21 @@ import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.TransitionDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
+import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
+import android.view.animation.LinearInterpolator;
import com.android.launcher.R;
public class DeleteDropTarget extends ButtonDropTarget {
- private static int DELETE_ANIMATION_DURATION = 250;
+ private static int DELETE_ANIMATION_DURATION = 300;
private ColorStateList mOriginalTextColor;
- private int mHoverColor = 0xFFFF0000;
private TransitionDrawable mUninstallDrawable;
private TransitionDrawable mRemoveDrawable;
private TransitionDrawable mCurrentDrawable;
@@ -58,8 +57,6 @@ public class DeleteDropTarget extends ButtonDropTarget {
// Get the hover color
Resources r = getResources();
mHoverColor = r.getColor(R.color.delete_target_hover_tint);
- mHoverPaint.setColorFilter(new PorterDuffColorFilter(
- mHoverColor, PorterDuff.Mode.SRC_ATOP));
mUninstallDrawable = (TransitionDrawable)
r.getDrawable(R.drawable.uninstall_target_selector);
mRemoveDrawable = (TransitionDrawable) r.getDrawable(R.drawable.remove_target_selector);
@@ -162,32 +159,19 @@ public class DeleteDropTarget extends ButtonDropTarget {
if (!d.dragComplete) {
mCurrentDrawable.resetTransition();
setTextColor(mOriginalTextColor);
+ } else {
+ // Restore the hover color if we are deleting
+ d.dragView.setColor(mHoverColor);
}
}
- Rect getDeleteRect(int deleteItemWidth, int deleteItemHeight) {
- DragLayer dragLayer = mLauncher.getDragLayer();
-
- Rect to = new Rect();
- dragLayer.getViewRectRelativeToSelf(this, to);
- int width = mCurrentDrawable.getIntrinsicWidth();
- int height = mCurrentDrawable.getIntrinsicHeight();
- to.set(to.left + getPaddingLeft(), to.top + getPaddingTop(),
- to.left + getPaddingLeft() + width, to.bottom);
-
- // Center the destination rect about the trash icon
- int xOffset = (int) -(deleteItemWidth - width) / 2;
- int yOffset = (int) -(deleteItemHeight - height) / 2;
- to.offset(xOffset, yOffset);
-
- return to;
- }
-
private void animateToTrashAndCompleteDrop(final DragObject d) {
DragLayer dragLayer = mLauncher.getDragLayer();
Rect from = new Rect();
dragLayer.getViewRectRelativeToSelf(d.dragView, from);
- Rect to = getDeleteRect(d.dragView.getMeasuredWidth(), d.dragView.getMeasuredHeight());
+ Rect to = getIconRect(d.dragView.getMeasuredWidth(), d.dragView.getMeasuredHeight(),
+ mCurrentDrawable.getIntrinsicWidth(), mCurrentDrawable.getIntrinsicHeight());
+ float scale = (float) to.width() / from.width();
mSearchDropTargetBar.deferOnDragEnd();
Runnable onAnimationEndRunnable = new Runnable() {
@@ -198,9 +182,9 @@ public class DeleteDropTarget extends ButtonDropTarget {
completeDrop(d);
}
};
- dragLayer.animateView(d.dragView, from, to, 0.1f, 1, 1, 0.1f, 0.1f,
+ dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f,
DELETE_ANIMATION_DURATION, new DecelerateInterpolator(2),
- new DecelerateInterpolator(1.5f), onAnimationEndRunnable,
+ new LinearInterpolator(), onAnimationEndRunnable,
DragLayer.ANIMATION_END_DISAPPEAR, null);
}
diff --git a/src/com/android/launcher2/DragView.java b/src/com/android/launcher2/DragView.java
index c3c274eca..f6c16b36e 100644
--- a/src/com/android/launcher2/DragView.java
+++ b/src/com/android/launcher2/DragView.java
@@ -25,6 +25,8 @@ import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
@@ -199,11 +201,15 @@ public class DragView extends View {
va.start();
}
- public void setPaint(Paint paint) {
- mPaint = paint;
+ public void setColor(int color) {
if (mPaint == null) {
mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
}
+ if (color != 0) {
+ mPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
+ } else {
+ mPaint.setColorFilter(null);
+ }
invalidate();
}
diff --git a/src/com/android/launcher2/InfoDropTarget.java b/src/com/android/launcher2/InfoDropTarget.java
index 21fe8baca..2e0b5c827 100644
--- a/src/com/android/launcher2/InfoDropTarget.java
+++ b/src/com/android/launcher2/InfoDropTarget.java
@@ -21,21 +21,17 @@ import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.TransitionDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import com.android.launcher.R;
-import com.android.launcher2.DropTarget.DragObject;
public class InfoDropTarget extends ButtonDropTarget {
private ColorStateList mOriginalTextColor;
private TransitionDrawable mDrawable;
- private int mHoverColor = 0xFF0000FF;
public InfoDropTarget(Context context, AttributeSet attrs) {
this(context, attrs, 0);
@@ -54,8 +50,6 @@ public class InfoDropTarget extends ButtonDropTarget {
// Get the hover color
Resources r = getResources();
mHoverColor = r.getColor(R.color.info_target_hover_tint);
- mHoverPaint.setColorFilter(new PorterDuffColorFilter(
- mHoverColor, PorterDuff.Mode.SRC_ATOP));
mDrawable = (TransitionDrawable) getCompoundDrawables()[0];
mDrawable.setCrossFadeEnabled(true);