From f9e8626fd0a51ddd91668bd1b658438194738743 Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Mon, 19 Jun 2017 19:45:13 -0700 Subject: Fix shadow problems with Folder animation. The shadow from the top of the Folder is visible through the transparent part of the 'preview' background. When we remove the elevation as part of the animation, the shadow jumps into visibility when the animation is done. To solve this, we remove the elevation during the Folder animation and * Animate the elevation at the end of the Folder opening animation. * Animate the shadow of the FolderIcon bg in once the Folder is closed. Bug: 62787582 Bug: 35064148 Change-Id: Id5d8fcbfa4f74882531334f12488560da2496faf --- src/com/android/launcher3/folder/Folder.java | 5 +++- .../launcher3/folder/FolderAnimationManager.java | 6 ++++ src/com/android/launcher3/folder/FolderIcon.java | 35 +++++++++++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) (limited to 'src/com/android/launcher3/folder') diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java index fc25c9ab2..283835153 100644 --- a/src/com/android/launcher3/folder/Folder.java +++ b/src/com/android/launcher3/folder/Folder.java @@ -791,8 +791,11 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC mDragController.removeDropTarget(this); clearFocus(); if (mFolderIcon != null) { - mFolderIcon.setBackgroundVisible(true); mFolderIcon.setVisibility(View.VISIBLE); + if (FeatureFlags.LAUNCHER3_NEW_FOLDER_ANIMATION) { + mFolderIcon.setBackgroundVisible(true); + mFolderIcon.mBackground.fadeInBackgroundShadow(); + } if (wasAnimated) { mFolderIcon.mBackground.animateBackgroundStroke(); if (mFolderIcon.hasBadge()) { diff --git a/src/com/android/launcher3/folder/FolderAnimationManager.java b/src/com/android/launcher3/folder/FolderAnimationManager.java index bb2d1a2f5..74e8d3b29 100644 --- a/src/com/android/launcher3/folder/FolderAnimationManager.java +++ b/src/com/android/launcher3/folder/FolderAnimationManager.java @@ -221,6 +221,12 @@ public class FolderAnimationManager { mFolder.setTranslationY(0.0f); mFolder.setScaleX(1f); mFolder.setScaleY(1f); + + if (mIsOpening) { + getAnimator(mFolder, View.TRANSLATION_Z, -mFolder.getElevation(), 0) + .setDuration(150) + .start(); + } } }); diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java index aaa19afa5..ca5d308f0 100644 --- a/src/com/android/launcher3/folder/FolderIcon.java +++ b/src/com/android/launcher3/folder/FolderIcon.java @@ -555,6 +555,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { private int mBgColor; private float mStrokeWidth; private int mStrokeAlpha = MAX_BG_OPACITY; + private int mShadowAlpha = 255; private View mInvalidateDelegate; public int previewSize; @@ -580,6 +581,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { ValueAnimator mScaleAnimator; ObjectAnimator mStrokeAlphaAnimator; + ObjectAnimator mShadowAnimator; private static final Property STROKE_ALPHA = new Property(Integer.class, "strokeAlpha") { @@ -595,6 +597,20 @@ public class FolderIcon extends FrameLayout implements FolderListener { } }; + private static final Property SHADOW_ALPHA = + new Property(Integer.class, "shadowAlpha") { + @Override + public Integer get(PreviewBackground previewBackground) { + return previewBackground.mShadowAlpha; + } + + @Override + public void set(PreviewBackground previewBackground, Integer alpha) { + previewBackground.mShadowAlpha = alpha; + previewBackground.invalidate(); + } + }; + public void setup(Launcher launcher, View invalidateDelegate, int availableSpace, int topPadding) { mInvalidateDelegate = invalidateDelegate; @@ -692,10 +708,11 @@ public class FolderIcon extends FrameLayout implements FolderListener { mShaderMatrix.setScale(shadowRadius, shadowRadius); mShaderMatrix.postTranslate(radius + offsetX, shadowRadius + offsetY); mShadowShader.setLocalMatrix(mShaderMatrix); + mPaint.setAlpha(mShadowAlpha); mPaint.setShader(mShadowShader); canvas.drawPaint(mPaint); + mPaint.setAlpha(255); mPaint.setShader(null); - if (canvas.isHardwareAccelerated()) { mPaint.setXfermode(mShadowPorterDuffXfermode); canvas.drawCircle(radius + offsetX, radius + offsetY, radius, mPaint); @@ -705,6 +722,22 @@ public class FolderIcon extends FrameLayout implements FolderListener { canvas.restoreToCount(saveCount); } + public void fadeInBackgroundShadow() { + if (mShadowAnimator != null) { + mShadowAnimator.cancel(); + } + mShadowAnimator = ObjectAnimator + .ofInt(this, SHADOW_ALPHA, 0, 255) + .setDuration(100); + mShadowAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mShadowAnimator = null; + } + }); + mShadowAnimator.start(); + } + public void animateBackgroundStroke() { if (mStrokeAlphaAnimator != null) { mStrokeAlphaAnimator.cancel(); -- cgit v1.2.3