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
This commit is contained in:
Sunny Goyal 2017-06-23 09:34:06 -07:00
parent 9314b7c01d
commit 4e5a878bc4
2 changed files with 17 additions and 44 deletions

View File

@ -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 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
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 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
}
};
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 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
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 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
* 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);
}

View File

@ -37,6 +37,7 @@ import com.android.launcher3.LauncherAnimUtils;
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 @@ public class FolderAnimationManager {
}
};
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 @@ public class FolderAnimationManager {
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 @@ public class FolderAnimationManager {
// 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 @@ public class FolderAnimationManager {
@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);