Last active
November 9, 2017 10:33
-
-
Save michelelacorte/c1b5e561975ed3056f9a04e23c94439f to your computer and use it in GitHub Desktop.
New App Shortcuts animation (PopupContainerWithArrow.java class)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Code from commit | |
https://github.com/Deletescape-Media/Lawnchair/blob/alpha/app/src/main/java/ch/deletescape/lawnchair/popup/PopupContainerWithArrow.java | |
*/ | |
private Point startPoint(int y) { | |
int x; | |
x = mIsLeftAligned != mIsRtl ? R.dimen.popup_arrow_horizontal_center_start : R.dimen.popup_arrow_horizontal_center_end; | |
x = getResources().getDimensionPixelSize(x); | |
if (!mIsLeftAligned) { | |
x = getMeasuredWidth() - x; | |
} | |
int measuredHeight = ((getMeasuredHeight() - getPaddingTop()) - getPaddingBottom()) - y; | |
int paddingTop = getPaddingTop(); | |
if (!mIsAboveIcon) { | |
y = measuredHeight; | |
} | |
return new Point(x, paddingTop + y); | |
} | |
private void animateOpen() { | |
final AnimatorSet shortcutA = LauncherAnimUtils.createAnimatorSet(); | |
final int itemCount = getItemCount(); | |
setVisibility(View.VISIBLE); | |
mIsOpen = true; | |
final long duration = getResources().getInteger( | |
R.integer.config_popupOpenCloseDuration); | |
TimeInterpolator interpolator = new AccelerateDecelerateInterpolator(); | |
int totalHeight = 0; | |
for (int i = 0; i < itemCount; i++) { | |
totalHeight += getItemViewAt(i).getMeasuredHeight(); | |
} | |
Point startPoint = startPoint(totalHeight); | |
int y = mIsAboveIcon ? getPaddingTop() : startPoint.y; | |
float radius = getItemViewAt(0).getBackgroundRadius(); | |
mStartRect.set(startPoint.x, startPoint.y, startPoint.x, startPoint.y); | |
mEndRect.set(0, y, getMeasuredWidth(), totalHeight + y); | |
ValueAnimator revealAnim = new RoundedRectRevealOutlineProvider(radius, | |
radius, mStartRect, mEndRect).createRevealAnimator(this, false); | |
revealAnim.setDuration(duration); | |
revealAnim.setInterpolator(interpolator); | |
Animator fadeAnim = ObjectAnimator.ofFloat(this, ALPHA, 0.0f, 1.0f); | |
fadeAnim.setDuration(duration); | |
fadeAnim.setInterpolator(interpolator); | |
shortcutA.play(fadeAnim); | |
shortcutA.addListener(new AnimatorListenerAdapter() { | |
@Override | |
public void onAnimationEnd(Animator animation) { | |
mOpenCloseAnimator = null; | |
Utilities.sendCustomAccessibilityEvent( | |
PopupContainerWithArrow.this, | |
AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, | |
getContext().getString(R.string.action_deep_shortcut)); | |
} | |
}); | |
mArrow.setScaleX(0); | |
mArrow.setScaleY(0); | |
Animator arrowScale = createArrowScaleAnim(1).setDuration((long) getResources().getInteger(R.integer.config_popupArrowOpenDuration)); | |
mOpenCloseAnimator = shortcutA; | |
shortcutA.playSequentially(revealAnim, arrowScale); | |
shortcutA.start(); | |
} | |
protected void animateClose() { | |
if (!mIsOpen) { | |
return; | |
} | |
final AnimatorSet shortcutA = LauncherAnimUtils.createAnimatorSet(); | |
final int itemCount = getItemCount(); | |
mEndRect.setEmpty(); | |
if (mOpenCloseAnimator != null) { | |
if (Utilities.ATLEAST_NOUGAT) { | |
Outline outline = new Outline(); | |
getOutlineProvider().getOutline(this, outline); | |
outline.getRect(mEndRect); | |
} | |
mOpenCloseAnimator.cancel(); | |
} | |
mIsOpen = false; | |
int totalHeight = 0; | |
for (int i = 0; i < itemCount; i++) { | |
totalHeight += getItemViewAt(i).getHeight(); | |
} | |
final long duration = (long) getResources().getInteger(R.integer.config_popupOpenCloseDuration); | |
final TimeInterpolator interpolator = new AccelerateDecelerateInterpolator(); | |
Point startPoint = startPoint(totalHeight); | |
int y = mIsAboveIcon ? getPaddingTop() : startPoint.y; | |
float radius = getItemViewAt(0).getBackgroundRadius(); | |
mStartRect.set(startPoint.x, startPoint.y, startPoint.x, startPoint.y); | |
if (mEndRect.isEmpty()) { | |
mEndRect.set(0, y, getMeasuredWidth(), totalHeight + y); | |
} | |
Animator revealAnimator = new RoundedRectRevealOutlineProvider(radius, | |
radius, mStartRect, mEndRect).createRevealAnimator(this, true); | |
revealAnimator.setDuration(duration); | |
revealAnimator.setInterpolator(interpolator); | |
shortcutA.play(revealAnimator); | |
Animator fadeAnimator = ObjectAnimator.ofFloat(this, ALPHA, 0); | |
fadeAnimator.setDuration(duration); | |
fadeAnimator.setInterpolator(interpolator); | |
shortcutA.play(fadeAnimator); | |
shortcutA.addListener(new AnimatorListenerAdapter() { | |
@Override | |
public void onAnimationEnd(Animator animation) { | |
mOpenCloseAnimator = null; | |
if (mDeferContainerRemoval) { | |
setVisibility(INVISIBLE); | |
} else { | |
closeComplete(); | |
} | |
} | |
}); | |
mOpenCloseAnimator = shortcutA; | |
shortcutA.start(); | |
mOriginalIcon.forceHideBadge(false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/Deletescape-Media/Lawnchair/blob/alpha/app/src/main/java/ch/deletescape/lawnchair/popup/PopupContainerWithArrow.java