Files
Lawnchair/src/com/android/launcher3/util/RevealOutlineAnimation.java
T
Sunny Goyal a2454ad2d8 Launcher shortcuts animations update.
> The shortcut container closes with an animation
> When opening/closing the animation only the icon scales
and not the title and drag handle
> When dragging the icon, it starts from the original icon position and
moves under the user finger. The container grows to follow the drag view.

Bug: 28980830
Change-Id: Ic0353c30b682d1f018cbf4d62e8a6e8e7d7d4664
2016-07-27 17:37:23 -07:00

78 lines
2.7 KiB
Java

package com.android.launcher3.util;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.graphics.Outline;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewOutlineProvider;
import com.android.launcher3.Utilities;
/**
* A {@link ViewOutlineProvider} that has helper functions to create reveal animations.
* This class should be extended so that subclasses can define the reveal shape as the
* animation progresses from 0 to 1.
*/
public abstract class RevealOutlineAnimation extends ViewOutlineProvider {
protected Rect mOutline;
protected float mOutlineRadius;
public RevealOutlineAnimation() {
mOutline = new Rect();
}
/** Returns whether elevation should be removed for the duration of the reveal animation. */
abstract boolean shouldRemoveElevationDuringAnimation();
/** Sets the progress, from 0 to 1, of the reveal animation. */
abstract void setProgress(float progress);
public ValueAnimator createRevealAnimator(final View revealView) {
return createRevealAnimator(revealView, false);
}
public ValueAnimator createRevealAnimator(final View revealView, boolean isReversed) {
ValueAnimator va =
isReversed ? ValueAnimator.ofFloat(1f, 0f) : ValueAnimator.ofFloat(0f, 1f);
final float elevation = revealView.getElevation();
va.addListener(new AnimatorListenerAdapter() {
public void onAnimationStart(Animator animation) {
revealView.setOutlineProvider(RevealOutlineAnimation.this);
revealView.setClipToOutline(true);
if (shouldRemoveElevationDuringAnimation()) {
revealView.setTranslationZ(-elevation);
}
}
public void onAnimationEnd(Animator animation) {
revealView.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
revealView.setClipToOutline(false);
if (shouldRemoveElevationDuringAnimation()) {
revealView.setTranslationZ(0);
}
}
});
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator arg0) {
float progress = (Float) arg0.getAnimatedValue();
setProgress(progress);
revealView.invalidateOutline();
if (!Utilities.ATLEAST_LOLLIPOP_MR1) {
revealView.invalidate();
}
}
});
return va;
}
@Override
public void getOutline(View v, Outline outline) {
outline.setRoundRect(mOutline, mOutlineRadius);
}
}