diff options
author | Tony Wickham <twickham@google.com> | 2016-07-15 17:23:07 -0700 |
---|---|---|
committer | Tony Wickham <twickham@google.com> | 2016-07-19 13:58:51 -0700 |
commit | 8f58e61d02fcb0ca90a2803e76a8792ec2c1f99a (patch) | |
tree | 2cba823be7962a2100c62acf086784f69fcae0fc /src/com/android/launcher3/shortcuts/DeepShortcutView.java | |
parent | 1e3d490e08b06750d467e144e5d74ea420c59613 (diff) | |
download | android_packages_apps_Trebuchet-8f58e61d02fcb0ca90a2803e76a8792ec2c1f99a.tar.gz android_packages_apps_Trebuchet-8f58e61d02fcb0ca90a2803e76a8792ec2c1f99a.tar.bz2 android_packages_apps_Trebuchet-8f58e61d02fcb0ca90a2803e76a8792ec2c1f99a.zip |
Update shortcut animations.
- Open animation: shortcuts reveal using modified circular reveal
(so that it reveals in the pill shape instead of a circle);
slight translation away from the original icon; scale icon and text.
- Hover animation: scale the shortcut pill and translate others away.
Bug: 28980830
Bug: 30127368
Change-Id: I8ed05c7a082f2c2a3f6c663da7259f6cd33e394f
Diffstat (limited to 'src/com/android/launcher3/shortcuts/DeepShortcutView.java')
-rw-r--r-- | src/com/android/launcher3/shortcuts/DeepShortcutView.java | 109 |
1 files changed, 97 insertions, 12 deletions
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutView.java b/src/com/android/launcher3/shortcuts/DeepShortcutView.java index 7997d1e2e..f9dd336a2 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutView.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutView.java @@ -16,19 +16,32 @@ package com.android.launcher3.shortcuts; +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; import android.content.Context; +import android.content.res.Resources; +import android.graphics.Rect; import android.support.annotation.IntDef; import android.util.AttributeSet; +import android.view.animation.DecelerateInterpolator; +import android.widget.FrameLayout; import com.android.launcher3.BubbleTextView; +import com.android.launcher3.LauncherAnimUtils; +import com.android.launcher3.LauncherViewPropertyAnimator; import com.android.launcher3.R; +import com.android.launcher3.util.PillRevealOutlineProvider; /** - * A {@link BubbleTextView} that represents a deep shortcut within an app. + * A {@link android.widget.FrameLayout} that contains a {@link DeepShortcutView}. + * This lets us animate the DeepShortcutView (icon and text) separately from the background. */ -public class DeepShortcutView extends BubbleTextView { +public class DeepShortcutView extends FrameLayout { + + private static final float HOVER_SCALE = 1.05f; - private static final float HOVER_SCALE = 1.1f; // The direction this view should translate when animating the hover state. // This allows hovered shortcuts to "push" other shortcuts away. @IntDef({DIRECTION_UP, DIRECTION_NONE, DIRECTION_DOWN}) @@ -37,12 +50,18 @@ public class DeepShortcutView extends BubbleTextView { public static final int DIRECTION_UP = -1; public static final int DIRECTION_NONE = 0; public static final int DIRECTION_DOWN = 1; + @TranslationDirection private int mTranslationDirection = DIRECTION_NONE; private int mSpacing; + private int mRadius; + private Rect mPillRect; private int mTop; private boolean mIsHoveringOver = false; + private LauncherViewPropertyAnimator mHoverAnimator; + + private BubbleTextView mBubbleText; public DeepShortcutView(Context context) { this(context, null, 0); @@ -56,10 +75,76 @@ public class DeepShortcutView extends BubbleTextView { super(context, attrs, defStyle); mSpacing = getResources().getDimensionPixelSize(R.dimen.deep_shortcuts_spacing); + mRadius = getResources().getDimensionPixelSize(R.dimen.bg_pill_radius); + mPillRect = new Rect(); + mHoverAnimator = new LauncherViewPropertyAnimator(this); + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + mBubbleText = (BubbleTextView) findViewById(R.id.deep_shortcut); } - public int getSpacing() { - return mSpacing; + public BubbleTextView getBubbleText() { + return mBubbleText; + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + mPillRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight()); + } + + @Override + public void setPivotX(float pivotX) { + super.setPivotX(pivotX); + mBubbleText.setPivotX(pivotX); + } + + @Override + public void setPivotY(float pivotY) { + super.setPivotY(pivotY); + mBubbleText.setPivotY(pivotY); + } + + /** + * Creates an animator to play when the shortcut container is being opened. + * + * @param animationIndex The index at which this animation will be started + * relative to other DeepShortcutView open animations. + */ + public Animator createOpenAnimation(int animationIndex, boolean isContainerAboveIcon) { + final Resources res = getResources(); + setVisibility(INVISIBLE); + + AnimatorSet openAnimation = LauncherAnimUtils.createAnimatorSet(); + + Animator reveal = new PillRevealOutlineProvider((int) getPivotX(), (int) getPivotY(), + mPillRect, mRadius).createRevealAnimator(this); + reveal.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationStart(Animator animation) { + setVisibility(VISIBLE); + } + }); + + float transY = res.getDimensionPixelSize(R.dimen.deep_shortcut_anim_translation_y); + Animator translationY = ObjectAnimator.ofFloat(this, TRANSLATION_Y, + isContainerAboveIcon ? transY : -transY, 0); + + // Only scale mBubbleText (the icon and text, not the background). + mBubbleText.setScaleX(0); + mBubbleText.setScaleY(0); + LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(mBubbleText) + .scaleX(1).scaleY(1); + + openAnimation.playTogether(reveal, translationY, scale); + openAnimation.setStartDelay(animationIndex * res.getInteger( + R.integer.config_deepShortcutOpenStagger)); + openAnimation.setDuration(res.getInteger(R.integer.config_deepShortcutOpenDuration)); + openAnimation.setInterpolator(new DecelerateInterpolator()); + return openAnimation; } /** @@ -95,16 +180,16 @@ public class DeepShortcutView extends BubbleTextView { /** * If this shortcut is being hovered over, we scale it up. If another shortcut is being hovered * over, we translate this one away from it to account for its increased size. - * - * TODO: apply motion spec here */ private void animateHoverState() { + if (mHoverAnimator.isRunning()) { + return; + } float scale = mIsHoveringOver ? HOVER_SCALE : 1f; - setScaleX(scale); - setScaleY(scale); - - float translation = (HOVER_SCALE - 1f) * getHeight(); - setTranslationY(translation * mTranslationDirection); + float translateY = (HOVER_SCALE - 1f) * getHeight() * mTranslationDirection; + mHoverAnimator.scaleX(scale).scaleY(scale).translationY(translateY) + .setDuration(getResources().getInteger(R.integer.config_deepShortcutHoverDuration)) + .start(); } public boolean isHoveringOver() { |