Skip to content

Commit

Permalink
More FAB transition improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbutcher committed May 17, 2016
1 parent 2fb9a45 commit 318db0a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
27 changes: 2 additions & 25 deletions app/src/main/java/io/plaidapp/ui/DribbbleShot.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,15 @@
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ActivityOptions;
import android.app.SharedElementCallback;
import android.app.assist.AssistContent;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.customtabs.CustomTabsIntent;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
Expand Down Expand Up @@ -155,7 +150,6 @@ protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dribbble_shot);
dribbblePrefs = DribbblePrefs.get(this);
setExitSharedElementCallback(fabLoginSharedElementCallback);
getWindow().getSharedElementReturnTransition().addListener(shotReturnHomeListener);
circleTransform = new CircleTransform(this);

Expand Down Expand Up @@ -598,25 +592,8 @@ public void onClick(View view) {
}
};

private SharedElementCallback fabLoginSharedElementCallback = new SharedElementCallback() {
@Override
public Parcelable onCaptureSharedElementSnapshot(View sharedElement,
Matrix viewToGlobalMatrix,
RectF screenBounds) {
// store a snapshot of the fab to fade out when morphing to the login dialog
int bitmapWidth = Math.round(screenBounds.width());
int bitmapHeight = Math.round(screenBounds.height());
Bitmap bitmap = null;
if (bitmapWidth > 0 && bitmapHeight > 0) {
bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
sharedElement.draw(new Canvas(bitmap));
}
return bitmap;
}
};

private Transition.TransitionListener shotReturnHomeListener = new AnimUtils
.TransitionListenerAdapter() {
private Transition.TransitionListener shotReturnHomeListener =
new AnimUtils.TransitionListenerAdapter() {
@Override
public void onTransitionStart(Transition transition) {
super.onTransitionStart(transition);
Expand Down
27 changes: 19 additions & 8 deletions app/src/main/java/io/plaidapp/ui/transitions/FabTransform.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public Animator createAnimator(final ViewGroup sceneRoot,
final long twoThirdsDuration = duration * 2 / 3;

if (!fromFab) {
// Force measure / layout the dialog back to it's orig bounds
// Force measure / layout the dialog back to it's original bounds
view.measure(
makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
Expand Down Expand Up @@ -195,18 +195,20 @@ public Animator createAnimator(final ViewGroup sceneRoot,
final Animator circularReveal;
if (fromFab) {
circularReveal = ViewAnimationUtils.createCircularReveal(view,
(view.getRight() - view.getLeft()) / 2,
(view.getBottom() - view.getTop()) / 2,
view.getWidth() / 2,
view.getHeight() / 2,
startBounds.width() / 2,
(float) Math.hypot(endBounds.width() / 2, endBounds.width() / 2));
circularReveal.setInterpolator(
AnimUtils.getFastOutLinearInInterpolator(sceneRoot.getContext()));
} else {
circularReveal = ViewAnimationUtils.createCircularReveal(view,
(view.getRight() - view.getLeft()) / 2,
(view.getBottom() - view.getTop()) / 2,
view.getWidth() / 2,
view.getHeight() / 2,
(float) Math.hypot(startBounds.width() / 2, startBounds.width() / 2),
endBounds.width() / 2);
circularReveal.setInterpolator(
AnimUtils.getLinearOutSlowInInterpolator(sceneRoot.getContext()));

// Persist the end clip i.e. stay at FAB size after the reveal has run
circularReveal.addListener(new AnimatorListenerAdapter() {
Expand All @@ -224,8 +226,6 @@ public void getOutline(View view, Outline outline) {
});
}
});
circularReveal.setInterpolator(
AnimUtils.getLinearOutSlowInInterpolator(sceneRoot.getContext()));
}
circularReveal.setDuration(duration);

Expand Down Expand Up @@ -258,7 +258,7 @@ public void getOutline(View view, Outline outline) {
}

// Fade in/out the fab color & icon overlays
final Animator colorFade = ObjectAnimator.ofArgb(fabColor, "alpha", fromFab ? 0 : 255);
final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
if (!fromFab) {
colorFade.setStartDelay(halfDuration);
Expand All @@ -269,10 +269,21 @@ public void getOutline(View view, Outline outline) {
colorFade.setInterpolator(fastOutSlowInInterpolator);
iconFade.setInterpolator(fastOutSlowInInterpolator);

// Work around issue with elevation shadows. At the end of the return transition the shared
// element's shadow is drawn twice (by each activity) which is jarring. This workaround
// still causes the shadow to snap, but it's better than seeing it double drawn.
Animator elevation = null;
if (!fromFab) {
elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation());
elevation.setDuration(duration);
elevation.setInterpolator(fastOutSlowInInterpolator);
}

// Run all animations together
final AnimatorSet transition = new AnimatorSet();
transition.playTogether(circularReveal, translate, colorFade, iconFade);
transition.playTogether(fadeContents);
if (elevation != null) transition.play(elevation);
if (fromFab) {
transition.addListener(new AnimatorListenerAdapter() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public Animator createAnimator(final ViewGroup sceneRoot,
transition.playTogether(changeBounds, corners, color);
transition.setDuration(getDuration());
transition.setInterpolator(interpolator);
return new AnimUtils.NoPauseAnimator(transition);
return transition;
}

}

0 comments on commit 318db0a

Please sign in to comment.