summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/ButtonDropTarget.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-05-21 10:28:02 -0700
committerSunny Goyal <sunnygoyal@google.com>2015-05-21 10:30:46 -0700
commit3a644ed1ce12554fcdf5c499e959bda986d10551 (patch)
treee02999e9e8078ac84bb3350701214eae9553d743 /src/com/android/launcher3/ButtonDropTarget.java
parentc393b0765df8d2d34b3b996b71700a705b7d0106 (diff)
downloadandroid_packages_apps_Trebuchet-3a644ed1ce12554fcdf5c499e959bda986d10551.tar.gz
android_packages_apps_Trebuchet-3a644ed1ce12554fcdf5c499e959bda986d10551.tar.bz2
android_packages_apps_Trebuchet-3a644ed1ce12554fcdf5c499e959bda986d10551.zip
Using color filter when animating the drop target instead to TransitionDrawable
> No more flickering when crossfading between two bitmaps in small duration > Allows us to control the color directly without depending on the assets Change-Id: Ie7ed8bb94baf560e9b939cca624ed1bad457732c
Diffstat (limited to 'src/com/android/launcher3/ButtonDropTarget.java')
-rw-r--r--src/com/android/launcher3/ButtonDropTarget.java59
1 files changed, 46 insertions, 13 deletions
diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java
index 80b542f1d..4cd28c034 100644
--- a/src/com/android/launcher3/ButtonDropTarget.java
+++ b/src/com/android/launcher3/ButtonDropTarget.java
@@ -16,14 +16,20 @@
package com.android.launcher3;
+import android.animation.AnimatorSet;
+import android.animation.FloatArrayEvaluator;
import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
+import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
+import android.graphics.ColorMatrix;
+import android.graphics.ColorMatrixColorFilter;
import android.graphics.PointF;
import android.graphics.Rect;
-import android.graphics.drawable.TransitionDrawable;
+import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
@@ -55,9 +61,11 @@ public abstract class ButtonDropTarget extends TextView
protected int mHoverColor = 0;
protected ColorStateList mOriginalTextColor;
- protected TransitionDrawable mDrawable;
+ protected Drawable mDrawable;
+
+ private AnimatorSet mCurrentColorAnim;
+ private ColorMatrix mSrcFilter, mDstFilter, mCurrentFilter;
- private ObjectAnimator mCurrentColorAnim;
public ButtonDropTarget(Context context, AttributeSet attrs) {
this(context, attrs, 0);
@@ -86,8 +94,7 @@ public abstract class ButtonDropTarget extends TextView
protected void setDrawable(int resId) {
// We do not set the drawable in the xml as that inflates two drawables corresponding to
// drawableLeft and drawableStart.
- mDrawable = (TransitionDrawable) getResources().getDrawable(resId);
- mDrawable.setCrossFadeEnabled(true);
+ mDrawable = getResources().getDrawable(resId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
setCompoundDrawablesRelativeWithIntrinsicBounds(mDrawable, null, null, null);
@@ -111,10 +118,13 @@ public abstract class ButtonDropTarget extends TextView
public final void onDragEnter(DragObject d) {
d.dragView.setColor(mHoverColor);
if (Utilities.isLmpOrAbove()) {
- mDrawable.startTransition(DragView.COLOR_CHANGE_DURATION);
animateTextColor(mHoverColor);
} else {
- mDrawable.startTransition(0);
+ if (mCurrentFilter == null) {
+ mCurrentFilter = new ColorMatrix();
+ }
+ DragView.setColorScale(mHoverColor, mCurrentFilter);
+ mDrawable.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
setTextColor(mHoverColor);
}
}
@@ -124,12 +134,11 @@ public abstract class ButtonDropTarget extends TextView
// Do nothing
}
- protected void resetHoverColor() {
+ protected void resetHoverColor() {
if (Utilities.isLmpOrAbove()) {
- mDrawable.reverseTransition(DragView.COLOR_CHANGE_DURATION);
animateTextColor(mOriginalTextColor.getDefaultColor());
} else {
- mDrawable.resetTransition();
+ mDrawable.setColorFilter(null);
setTextColor(mOriginalTextColor);
}
}
@@ -139,8 +148,32 @@ public abstract class ButtonDropTarget extends TextView
if (mCurrentColorAnim != null) {
mCurrentColorAnim.cancel();
}
- mCurrentColorAnim = ObjectAnimator.ofArgb(this, "textColor", targetColor);
+
+ mCurrentColorAnim = new AnimatorSet();
mCurrentColorAnim.setDuration(DragView.COLOR_CHANGE_DURATION);
+
+ if (mSrcFilter == null) {
+ mSrcFilter = new ColorMatrix();
+ mDstFilter = new ColorMatrix();
+ mCurrentFilter = new ColorMatrix();
+ }
+
+ DragView.setColorScale(getTextColor(), mSrcFilter);
+ DragView.setColorScale(targetColor, mDstFilter);
+ ValueAnimator anim1 = ValueAnimator.ofObject(
+ new FloatArrayEvaluator(mCurrentFilter.getArray()),
+ mSrcFilter.getArray(), mDstFilter.getArray());
+ anim1.addUpdateListener(new AnimatorUpdateListener() {
+
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ mDrawable.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
+ invalidate();
+ }
+ });
+
+ mCurrentColorAnim.play(anim1);
+ mCurrentColorAnim.play(ObjectAnimator.ofArgb(this, "textColor", targetColor));
mCurrentColorAnim.start();
}
@@ -155,10 +188,10 @@ public abstract class ButtonDropTarget extends TextView
}
}
- @Override
+ @Override
public final void onDragStart(DragSource source, Object info, int dragAction) {
mActive = supportsDrop(source, info);
- mDrawable.resetTransition();
+ mDrawable.setColorFilter(null);
if (mCurrentColorAnim != null) {
mCurrentColorAnim.cancel();
mCurrentColorAnim = null;