From 3a644ed1ce12554fcdf5c499e959bda986d10551 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 21 May 2015 10:28:02 -0700 Subject: 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 --- res/drawable-hdpi/ic_launcher_info_active.png | Bin 3895 -> 0 bytes res/drawable-hdpi/ic_launcher_remove_active.png | Bin 2695 -> 0 bytes res/drawable-hdpi/ic_launcher_uninstall_active.png | Bin 1483 -> 0 bytes res/drawable-mdpi/ic_launcher_info_active.png | Bin 2597 -> 0 bytes res/drawable-mdpi/ic_launcher_remove_active.png | Bin 1853 -> 0 bytes res/drawable-mdpi/ic_launcher_uninstall_active.png | Bin 1274 -> 0 bytes res/drawable-xhdpi/ic_launcher_info_active.png | Bin 5449 -> 0 bytes res/drawable-xhdpi/ic_launcher_remove_active.png | Bin 2700 -> 0 bytes .../ic_launcher_uninstall_active.png | Bin 1893 -> 0 bytes res/drawable-xxhdpi/ic_launcher_info_active.png | Bin 8542 -> 0 bytes res/drawable-xxhdpi/ic_launcher_remove_active.png | Bin 5126 -> 0 bytes .../ic_launcher_uninstall_active.png | Bin 2673 -> 0 bytes res/drawable-xxxhdpi/ic_launcher_info_active.png | Bin 7999 -> 0 bytes res/drawable-xxxhdpi/ic_launcher_remove_active.png | Bin 3843 -> 0 bytes .../ic_launcher_uninstall_active.png | Bin 2776 -> 0 bytes res/drawable/info_target_selector.xml | 24 --------- res/drawable/remove_target_selector.xml | 24 --------- res/drawable/uninstall_target_selector.xml | 24 --------- res/values/colors.xml | 6 +-- src/com/android/launcher3/ButtonDropTarget.java | 59 ++++++++++++++++----- src/com/android/launcher3/DeleteDropTarget.java | 2 +- src/com/android/launcher3/DragView.java | 10 ++-- src/com/android/launcher3/InfoDropTarget.java | 2 +- src/com/android/launcher3/UninstallDropTarget.java | 2 +- 24 files changed, 59 insertions(+), 94 deletions(-) delete mode 100644 res/drawable-hdpi/ic_launcher_info_active.png delete mode 100644 res/drawable-hdpi/ic_launcher_remove_active.png delete mode 100644 res/drawable-hdpi/ic_launcher_uninstall_active.png delete mode 100644 res/drawable-mdpi/ic_launcher_info_active.png delete mode 100644 res/drawable-mdpi/ic_launcher_remove_active.png delete mode 100644 res/drawable-mdpi/ic_launcher_uninstall_active.png delete mode 100644 res/drawable-xhdpi/ic_launcher_info_active.png delete mode 100644 res/drawable-xhdpi/ic_launcher_remove_active.png delete mode 100644 res/drawable-xhdpi/ic_launcher_uninstall_active.png delete mode 100644 res/drawable-xxhdpi/ic_launcher_info_active.png delete mode 100644 res/drawable-xxhdpi/ic_launcher_remove_active.png delete mode 100644 res/drawable-xxhdpi/ic_launcher_uninstall_active.png delete mode 100644 res/drawable-xxxhdpi/ic_launcher_info_active.png delete mode 100644 res/drawable-xxxhdpi/ic_launcher_remove_active.png delete mode 100644 res/drawable-xxxhdpi/ic_launcher_uninstall_active.png delete mode 100644 res/drawable/info_target_selector.xml delete mode 100644 res/drawable/remove_target_selector.xml delete mode 100644 res/drawable/uninstall_target_selector.xml diff --git a/res/drawable-hdpi/ic_launcher_info_active.png b/res/drawable-hdpi/ic_launcher_info_active.png deleted file mode 100644 index f7a3b68fe..000000000 Binary files a/res/drawable-hdpi/ic_launcher_info_active.png and /dev/null differ diff --git a/res/drawable-hdpi/ic_launcher_remove_active.png b/res/drawable-hdpi/ic_launcher_remove_active.png deleted file mode 100644 index e53de0da4..000000000 Binary files a/res/drawable-hdpi/ic_launcher_remove_active.png and /dev/null differ diff --git a/res/drawable-hdpi/ic_launcher_uninstall_active.png b/res/drawable-hdpi/ic_launcher_uninstall_active.png deleted file mode 100644 index 22b97ee50..000000000 Binary files a/res/drawable-hdpi/ic_launcher_uninstall_active.png and /dev/null differ diff --git a/res/drawable-mdpi/ic_launcher_info_active.png b/res/drawable-mdpi/ic_launcher_info_active.png deleted file mode 100644 index ea712722d..000000000 Binary files a/res/drawable-mdpi/ic_launcher_info_active.png and /dev/null differ diff --git a/res/drawable-mdpi/ic_launcher_remove_active.png b/res/drawable-mdpi/ic_launcher_remove_active.png deleted file mode 100644 index f36cfdd2f..000000000 Binary files a/res/drawable-mdpi/ic_launcher_remove_active.png and /dev/null differ diff --git a/res/drawable-mdpi/ic_launcher_uninstall_active.png b/res/drawable-mdpi/ic_launcher_uninstall_active.png deleted file mode 100644 index e4ee9112d..000000000 Binary files a/res/drawable-mdpi/ic_launcher_uninstall_active.png and /dev/null differ diff --git a/res/drawable-xhdpi/ic_launcher_info_active.png b/res/drawable-xhdpi/ic_launcher_info_active.png deleted file mode 100644 index b438f9eb2..000000000 Binary files a/res/drawable-xhdpi/ic_launcher_info_active.png and /dev/null differ diff --git a/res/drawable-xhdpi/ic_launcher_remove_active.png b/res/drawable-xhdpi/ic_launcher_remove_active.png deleted file mode 100644 index 14ac79d41..000000000 Binary files a/res/drawable-xhdpi/ic_launcher_remove_active.png and /dev/null differ diff --git a/res/drawable-xhdpi/ic_launcher_uninstall_active.png b/res/drawable-xhdpi/ic_launcher_uninstall_active.png deleted file mode 100644 index 2c19b329d..000000000 Binary files a/res/drawable-xhdpi/ic_launcher_uninstall_active.png and /dev/null differ diff --git a/res/drawable-xxhdpi/ic_launcher_info_active.png b/res/drawable-xxhdpi/ic_launcher_info_active.png deleted file mode 100644 index d354dd33b..000000000 Binary files a/res/drawable-xxhdpi/ic_launcher_info_active.png and /dev/null differ diff --git a/res/drawable-xxhdpi/ic_launcher_remove_active.png b/res/drawable-xxhdpi/ic_launcher_remove_active.png deleted file mode 100644 index 9df44042e..000000000 Binary files a/res/drawable-xxhdpi/ic_launcher_remove_active.png and /dev/null differ diff --git a/res/drawable-xxhdpi/ic_launcher_uninstall_active.png b/res/drawable-xxhdpi/ic_launcher_uninstall_active.png deleted file mode 100644 index db7d339e6..000000000 Binary files a/res/drawable-xxhdpi/ic_launcher_uninstall_active.png and /dev/null differ diff --git a/res/drawable-xxxhdpi/ic_launcher_info_active.png b/res/drawable-xxxhdpi/ic_launcher_info_active.png deleted file mode 100644 index 162e23dc2..000000000 Binary files a/res/drawable-xxxhdpi/ic_launcher_info_active.png and /dev/null differ diff --git a/res/drawable-xxxhdpi/ic_launcher_remove_active.png b/res/drawable-xxxhdpi/ic_launcher_remove_active.png deleted file mode 100644 index c0b8ea2ee..000000000 Binary files a/res/drawable-xxxhdpi/ic_launcher_remove_active.png and /dev/null differ diff --git a/res/drawable-xxxhdpi/ic_launcher_uninstall_active.png b/res/drawable-xxxhdpi/ic_launcher_uninstall_active.png deleted file mode 100644 index 75896f3a2..000000000 Binary files a/res/drawable-xxxhdpi/ic_launcher_uninstall_active.png and /dev/null differ diff --git a/res/drawable/info_target_selector.xml b/res/drawable/info_target_selector.xml deleted file mode 100644 index 51caece53..000000000 --- a/res/drawable/info_target_selector.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - diff --git a/res/drawable/remove_target_selector.xml b/res/drawable/remove_target_selector.xml deleted file mode 100644 index 9025e8a1a..000000000 --- a/res/drawable/remove_target_selector.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - diff --git a/res/drawable/uninstall_target_selector.xml b/res/drawable/uninstall_target_selector.xml deleted file mode 100644 index 175cc20dd..000000000 --- a/res/drawable/uninstall_target_selector.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - diff --git a/res/values/colors.xml b/res/values/colors.xml index 1e89615af..a5db2fc40 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -20,9 +20,9 @@ - #DAC1C1C1 - #DAF0592B - #DA009688 + #FFC1C1C1 + #FFF0592B + #FF009688 #80000000 #80c6c5c5 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; diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java index 08186f517..fa6e74fd1 100644 --- a/src/com/android/launcher3/DeleteDropTarget.java +++ b/src/com/android/launcher3/DeleteDropTarget.java @@ -43,7 +43,7 @@ public class DeleteDropTarget extends ButtonDropTarget { // Get the hover color mHoverColor = getResources().getColor(R.color.delete_target_hover_tint); - setDrawable(R.drawable.remove_target_selector); + setDrawable(R.drawable.ic_launcher_remove_normal); } public static boolean supportsDrop(Object info) { diff --git a/src/com/android/launcher3/DragView.java b/src/com/android/launcher3/DragView.java index 120299e1d..b3323384d 100644 --- a/src/com/android/launcher3/DragView.java +++ b/src/com/android/launcher3/DragView.java @@ -38,7 +38,7 @@ import com.android.launcher3.util.Thunk; import java.util.Arrays; public class DragView extends View { - public static int COLOR_CHANGE_DURATION = 200; + public static int COLOR_CHANGE_DURATION = 120; @Thunk static float sDragAlpha = 1f; @@ -249,8 +249,7 @@ public class DragView extends View { m1.setSaturation(0); ColorMatrix m2 = new ColorMatrix(); - m2.setScale(Color.red(color) / 255f, Color.green(color) / 255f, - Color.blue(color) / 255f, Color.alpha(color) / 255f); + setColorScale(color, m2); m1.postConcat(m2); if (Utilities.isLmpOrAbove()) { @@ -355,4 +354,9 @@ public class DragView extends View { mDragLayer.removeView(DragView.this); } } + + public static void setColorScale(int color, ColorMatrix target) { + target.setScale(Color.red(color) / 255f, Color.green(color) / 255f, + Color.blue(color) / 255f, Color.alpha(color) / 255f); + } } diff --git a/src/com/android/launcher3/InfoDropTarget.java b/src/com/android/launcher3/InfoDropTarget.java index f3383ccea..0f139fa98 100644 --- a/src/com/android/launcher3/InfoDropTarget.java +++ b/src/com/android/launcher3/InfoDropTarget.java @@ -41,7 +41,7 @@ public class InfoDropTarget extends ButtonDropTarget { // Get the hover color mHoverColor = getResources().getColor(R.color.info_target_hover_tint); - setDrawable(R.drawable.info_target_selector); + setDrawable(R.drawable.ic_launcher_info_normal); } public static void startDetailsActivityForInfo(Object info, Launcher launcher) { diff --git a/src/com/android/launcher3/UninstallDropTarget.java b/src/com/android/launcher3/UninstallDropTarget.java index 0fc8f324a..419939000 100644 --- a/src/com/android/launcher3/UninstallDropTarget.java +++ b/src/com/android/launcher3/UninstallDropTarget.java @@ -28,7 +28,7 @@ public class UninstallDropTarget extends ButtonDropTarget { // Get the hover color mHoverColor = getResources().getColor(R.color.uninstall_target_hover_tint); - setDrawable(R.drawable.uninstall_target_selector); + setDrawable(R.drawable.ic_launcher_uninstall_normal); } @Override -- cgit v1.2.3