Fixing two different implementations for animating text alpha

The animator in BubbleTextView maintains an internal state which was getting
invalidated by the FolderAnimator.

Change-Id: I53885fe8f1773ca62fe59f1712056f02ff9a749f
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 2306b1b..6f2c897 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -16,7 +16,6 @@
 
 package com.android.launcher3;
 
-import android.animation.Animator;
 import android.animation.ObjectAnimator;
 import android.content.Context;
 import android.content.res.ColorStateList;
@@ -70,7 +69,7 @@
     private final Launcher mLauncher;
     private Drawable mIcon;
     private final boolean mCenterVertically;
-    private OnLongClickListener mOnLongClickListener;
+
     private final CheckLongPressHelper mLongPressHelper;
     private final HolographicOutlineHelper mOutlineHelper;
     private final StylusEventHelper mStylusEventHelper;
@@ -107,7 +106,7 @@
         }
     };
 
-    private static final Property<BubbleTextView, Integer> TEXT_ALPHA_PROPERTY
+    public static final Property<BubbleTextView, Integer> TEXT_ALPHA_PROPERTY
             = new Property<BubbleTextView, Integer>(Integer.class, "textAlpha") {
         @Override
         public Integer get(BubbleTextView bubbleTextView) {
@@ -264,21 +263,6 @@
         return mIcon;
     }
 
-    /** Returns whether the layout is horizontal. */
-    public boolean isLayoutHorizontal() {
-        return mLayoutHorizontal;
-    }
-
-    @Override
-    public void setOnLongClickListener(OnLongClickListener l) {
-        super.setOnLongClickListener(l);
-        mOnLongClickListener = l;
-    }
-
-    public OnLongClickListener getOnLongClickListener() {
-        return mOnLongClickListener;
-    }
-
     @Override
     public boolean onTouchEvent(MotionEvent event) {
         // Call the superclass onTouchEvent first, because sometimes it changes the state to
@@ -474,7 +458,7 @@
      * Creates an animator to fade the text in or out.
      * @param fadeIn Whether the text should fade in or fade out.
      */
-    public Animator createTextAlphaAnimator(boolean fadeIn) {
+    public ObjectAnimator createTextAlphaAnimator(boolean fadeIn) {
         return ObjectAnimator.ofInt(this, TEXT_ALPHA_PROPERTY, fadeIn ? Color.alpha(mTextColor) : 0);
     }
 
diff --git a/src/com/android/launcher3/folder/FolderAnimationManager.java b/src/com/android/launcher3/folder/FolderAnimationManager.java
index cb86b59..7e6205a 100644
--- a/src/com/android/launcher3/folder/FolderAnimationManager.java
+++ b/src/com/android/launcher3/folder/FolderAnimationManager.java
@@ -37,6 +37,7 @@
 import com.android.launcher3.R;
 import com.android.launcher3.ShortcutAndWidgetContainer;
 import com.android.launcher3.Utilities;
+import com.android.launcher3.anim.PropertyResetListener;
 import com.android.launcher3.anim.RoundedRectRevealOutlineProvider;
 import com.android.launcher3.dragndrop.DragLayer;
 import com.android.launcher3.util.Themes;
@@ -87,23 +88,6 @@
                 }
             };
 
-    private static final Property<List<BubbleTextView>, Integer> ITEMS_TEXT_COLOR_PROPERTY =
-            new Property<List<BubbleTextView>, Integer>(Integer.class, "textColor") {
-                @Override
-                public Integer get(List<BubbleTextView> items) {
-                    return items.get(0).getCurrentTextColor();
-                }
-
-                @Override
-                public void set(List<BubbleTextView> items, Integer color) {
-                    int size = items.size();
-
-                    for (int i = 0; i < size; ++i) {
-                        items.get(i).setTextColor(color);
-                    }
-                }
-            };
-
     public FolderAnimationManager(Folder folder, boolean isOpening) {
         mFolder = folder;
         mContent = folder.mContent;
@@ -183,12 +167,6 @@
                 ColorUtils.setAlphaComponent(finalColor, mPreviewBackground.getBackgroundAlpha());
         mFolderBackground.setColor(mIsOpening ? initialColor : finalColor);
 
-        // Initialize the Folder items' text.
-        final List<BubbleTextView> items = mFolder.getItemsOnCurrentPage();
-        final int finalTextColor = Themes.getAttrColor(mContext, android.R.attr.textColorSecondary);
-        ITEMS_TEXT_COLOR_PROPERTY.set(items, mIsOpening ? Color.TRANSPARENT
-                : finalTextColor);
-
         // Set up the reveal animation that clips the Folder.
         int totalOffsetX = paddingOffsetX + previewItemOffsetX;
         Rect startRect = new Rect(
@@ -203,10 +181,22 @@
         // Create the animators.
         AnimatorSet a = LauncherAnimUtils.createAnimatorSet();
 
+        // Initialize the Folder items' text.
+        PropertyResetListener colorResetListener = new PropertyResetListener(
+                BubbleTextView.TEXT_ALPHA_PROPERTY,
+                Color.alpha(Themes.getAttrColor(mContext, android.R.attr.textColorSecondary)));
+        for (BubbleTextView icon : mFolder.getItemsOnCurrentPage()) {
+            if (mIsOpening) {
+                icon.setTextVisibility(false);
+            }
+            ObjectAnimator anim = icon.createTextAlphaAnimator(mIsOpening);
+            anim.addListener(colorResetListener);
+            play(a, anim);
+        }
+
         play(a, getAnimator(mFolder, View.TRANSLATION_X, xDistance, 0f));
         play(a, getAnimator(mFolder, View.TRANSLATION_Y, yDistance, 0f));
         play(a, getAnimator(mFolder, SCALE_PROPERTY, initialScale, finalScale));
-        play(a, getAnimator(items, ITEMS_TEXT_COLOR_PROPERTY, Color.TRANSPARENT, finalTextColor));
         play(a, getAnimator(mFolderBackground, "color", initialColor, finalColor));
         play(a, mFolderIcon.mFolderName.createTextAlphaAnimator(!mIsOpening));
         play(a, new RoundedRectRevealOutlineProvider(initialRadius, finalRadius, startRect,
@@ -216,7 +206,6 @@
             @Override
             public void onAnimationEnd(Animator animation) {
                 super.onAnimationEnd(animation);
-                ITEMS_TEXT_COLOR_PROPERTY.set(items, finalTextColor);
                 mFolder.setTranslationX(0.0f);
                 mFolder.setTranslationY(0.0f);
                 mFolder.setScaleX(1f);