From 6f455b583f6c37eafcb357b0727dbb0133db21ad Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Wed, 27 Mar 2019 08:27:16 -0700 Subject: [PATCH] Fix sizing of FloatingIconView so that it matches the workspace. * Added a cross fade at the end for text and shadows. * Animate in FolderIcon bg/dot/text after swapping. Bug: 129297366 Change-Id: Ieeb5d7b8fb389a2f7ee263d38b3021ffdefefd93 --- src/com/android/launcher3/BubbleTextView.java | 3 +- src/com/android/launcher3/folder/Folder.java | 3 +- .../android/launcher3/folder/FolderIcon.java | 9 +++ .../launcher3/views/FloatingIconView.java | 78 +++++++++++++++---- 4 files changed, 76 insertions(+), 17 deletions(-) diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index d75006e893..4dd2e0a764 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -480,7 +480,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, */ public ObjectAnimator createTextAlphaAnimator(boolean fadeIn) { float toAlpha = shouldTextBeVisible() && fadeIn ? 1 : 0; - return ObjectAnimator.ofFloat(this, TEXT_ALPHA_PROPERTY, toAlpha); + float fromAlpha = toAlpha == 1 ? 0 : 1f; + return ObjectAnimator.ofFloat(this, TEXT_ALPHA_PROPERTY, fromAlpha, toAlpha); } @Override diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java index 7a14b36b03..bcddd037e8 100644 --- a/src/com/android/launcher3/folder/Folder.java +++ b/src/com/android/launcher3/folder/Folder.java @@ -618,8 +618,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo mFolderIcon.setBackgroundVisible(true); mFolderIcon.mFolderName.setTextVisibility(true); if (wasAnimated) { - mFolderIcon.mBackground.fadeInBackgroundShadow(); - mFolderIcon.mBackground.animateBackgroundStroke(); + mFolderIcon.animateBgShadowAndStroke(); mFolderIcon.onFolderClose(mContent.getCurrentPage()); if (mFolderIcon.hasDot()) { mFolderIcon.animateDotScale(0f, 1f); diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java index 71c91488be..521f5c1631 100644 --- a/src/com/android/launcher3/folder/FolderIcon.java +++ b/src/com/android/launcher3/folder/FolderIcon.java @@ -189,6 +189,15 @@ public class FolderIcon extends FrameLayout implements FolderListener { return icon; } + public void animateBgShadowAndStroke() { + mBackground.fadeInBackgroundShadow(); + mBackground.animateBackgroundStroke(); + } + + public BubbleTextView getFolderName() { + return mFolderName; + } + public void getPreviewBounds(Rect outBounds) { mBackground.getBounds(outBounds); } diff --git a/src/com/android/launcher3/views/FloatingIconView.java b/src/com/android/launcher3/views/FloatingIconView.java index 2a5418d081..a4f89a7180 100644 --- a/src/com/android/launcher3/views/FloatingIconView.java +++ b/src/com/android/launcher3/views/FloatingIconView.java @@ -19,6 +19,8 @@ import static com.android.launcher3.config.FeatureFlags.ADAPTIVE_ICON_WINDOW_ANI import android.animation.Animator; import android.animation.AnimatorListenerAdapter; +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.content.Context; import android.graphics.Canvas; @@ -47,6 +49,7 @@ import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.anim.Interpolators; import com.android.launcher3.dragndrop.DragLayer; +import com.android.launcher3.dragndrop.FolderAdaptiveIcon; import com.android.launcher3.folder.FolderIcon; import com.android.launcher3.folder.FolderShape; import com.android.launcher3.graphics.ShiftedBitmapDrawable; @@ -157,11 +160,13 @@ public class FloatingIconView extends View implements Animator.AnimatorListener, @Override public void onAnimationEnd(Animator animator) { - if (mRevealAnimator != null) { - mRevealAnimator.end(); - } if (mEndRunnable != null) { mEndRunnable.run(); + } else { + // End runnable also ends the reveal animator, so we manually handle it here. + if (mRevealAnimator != null) { + mRevealAnimator.end(); + } } } @@ -221,6 +226,7 @@ public class FloatingIconView extends View implements Animator.AnimatorListener, new Handler(Looper.getMainLooper()).post(() -> { if (isAdaptiveIcon) { mIsAdaptiveIcon = true; + boolean isFolderIcon = finalDrawable instanceof FolderAdaptiveIcon; AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) finalDrawable; Drawable background = adaptiveIcon.getBackground(); @@ -234,20 +240,27 @@ public class FloatingIconView extends View implements Animator.AnimatorListener, } mForeground = foreground; - mFinalDrawableBounds.set(iconOffset, iconOffset, lp.width - - iconOffset, mOriginalHeight - iconOffset); if (mForeground instanceof ShiftedBitmapDrawable && v instanceof FolderIcon) { ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mForeground; ((FolderIcon) v).getPreviewBounds(sTmpRect); sbd.setShiftX(sbd.getShiftX() - sTmpRect.left); sbd.setShiftY(sbd.getShiftY() - sTmpRect.top); } + + int blurMargin = mBlurSizeOutline / 2; + mFinalDrawableBounds.set(0, 0, lp.width, mOriginalHeight); + if (!isFolderIcon) { + mFinalDrawableBounds.inset(iconOffset - blurMargin, iconOffset - blurMargin); + } mForeground.setBounds(mFinalDrawableBounds); mBackground.setBounds(mFinalDrawableBounds); - int blurMargin = mBlurSizeOutline / 2; - mStartRevealRect.set(blurMargin, blurMargin , lp.width - blurMargin, - mOriginalHeight - blurMargin); + if (isFolderIcon) { + mStartRevealRect.set(0, 0, lp.width, mOriginalHeight); + } else { + mStartRevealRect.set(mBlurSizeOutline, mBlurSizeOutline, + lp.width - mBlurSizeOutline, mOriginalHeight - mBlurSizeOutline); + } if (aspectRatio > 0) { lp.height = (int) Math.max(lp.height, lp.width * aspectRatio); @@ -380,12 +393,49 @@ public class FloatingIconView extends View implements Animator.AnimatorListener, originalView.setVisibility(INVISIBLE); } }; - view.mEndRunnable = () -> { - ((ViewGroup) dragLayer.getParent()).getOverlay().remove(view); - if (hideOriginal) { - originalView.setVisibility(VISIBLE); - } - }; + if (hideOriginal) { + view.mEndRunnable = () -> { + AnimatorSet fade = new AnimatorSet(); + fade.setDuration(200); + fade.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationStart(Animator animation) { + originalView.setVisibility(VISIBLE); + + if (originalView instanceof FolderIcon) { + FolderIcon folderIcon = (FolderIcon) originalView; + folderIcon.setBackgroundVisible(false); + folderIcon.getFolderName().setTextVisibility(false); + } + } + + @Override + public void onAnimationEnd(Animator animation) { + ((ViewGroup) dragLayer.getParent()).getOverlay().remove(view); + + if (view.mRevealAnimator != null) { + view.mRevealAnimator.end(); + } + } + }); + + if (originalView instanceof FolderIcon) { + FolderIcon folderIcon = (FolderIcon) originalView; + fade.play(folderIcon.getFolderName().createTextAlphaAnimator(true)); + fade.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + folderIcon.setBackgroundVisible(true); + folderIcon.animateBgShadowAndStroke(); + folderIcon.animateDotScale(0, 1f); + } + }); + } else { + fade.play(ObjectAnimator.ofFloat(originalView, ALPHA, 0f, 1f)); + } + fade.start(); + }; + } return view; } }