From 5e81f5b25f4dc4a76f3bf4611541379d213d5146 Mon Sep 17 00:00:00 2001 From: Nick Butcher Date: Mon, 11 Jul 2016 14:45:31 +0100 Subject: [PATCH] Fixed FAB enter transition on N. --- .../java/io/plaidapp/ui/DribbbleShot.java | 37 +++++++--------- .../java/io/plaidapp/ui/transitions/Pop.java | 43 +++---------------- .../java/io/plaidapp/ui/widget/FABToggle.java | 23 +++++++--- .../res/layout/activity_dribbble_shot.xml | 3 +- .../res/transition/dribbble_shot_enter.xml | 28 +++--------- .../res/transition/dribbble_shot_return.xml | 20 ++++----- 6 files changed, 53 insertions(+), 101 deletions(-) diff --git a/app/src/main/java/io/plaidapp/ui/DribbbleShot.java b/app/src/main/java/io/plaidapp/ui/DribbbleShot.java index e465d5888..4888c4499 100644 --- a/app/src/main/java/io/plaidapp/ui/DribbbleShot.java +++ b/app/src/main/java/io/plaidapp/ui/DribbbleShot.java @@ -153,7 +153,6 @@ protected void onCreate(final Bundle savedInstanceState) { dribbblePrefs = DribbblePrefs.get(this); getWindow().getSharedElementReturnTransition().addListener(shotReturnHomeListener); circleTransform = new CircleTransform(this); - ButterKnife.bind(this); View shotDescription = getLayoutInflater().inflate(R.layout.dribbble_shot_description, commentsList, false); @@ -188,7 +187,7 @@ public void onDragDismissed() { final Intent intent = getIntent(); if (intent.hasExtra(EXTRA_SHOT)) { shot = intent.getParcelableExtra(EXTRA_SHOT); - bindShot(true, savedInstanceState != null); + bindShot(true); } else if (intent.getData() != null) { final HttpUrl url = HttpUrl.parse(intent.getDataString()); if (url.pathSize() == 2 && url.pathSegments().get(0).equals("shots")) { @@ -201,7 +200,7 @@ public void onDragDismissed() { @Override public void onResponse(Call call, Response response) { shot = response.body(); - bindShot(false, true); + bindShot(false); } @Override @@ -268,7 +267,7 @@ public void onProvideAssistContent(AssistContent outContent) { outContent.setWebUri(Uri.parse(shot.url)); } - private void bindShot(final boolean postponeEnterTransition, final boolean animateFabManually) { + private void bindShot(final boolean postponeEnterTransition) { final Resources res = getResources(); // load the main image @@ -290,7 +289,7 @@ private void bindShot(final boolean postponeEnterTransition, final boolean anima public boolean onPreDraw() { imageView.getViewTreeObserver().removeOnPreDrawListener(this); calculateFabPosition(); - enterAnimation(animateFabManually); + enterAnimation(); if (postponeEnterTransition) startPostponedEnterTransition(); return true; } @@ -671,10 +670,10 @@ private void calculateFabPosition() { /** * Animate in the title, description and author – can't do this in a content transition as they - * are within the ListView so do it manually. Also handle the FAB tanslation here so that it + * are within the ListView so do it manually. Also animate the FAB translation here so that it * plays nicely with #calculateFabPosition */ - private void enterAnimation(boolean animateFabManually) { + private void enterAnimation() { Interpolator interp = getFastOutSlowInInterpolator(this); int offset = title.getHeight(); viewEnterAnimation(title, offset, interp); @@ -682,9 +681,9 @@ private void enterAnimation(boolean animateFabManually) { offset *= 1.5f; viewEnterAnimation(description, offset, interp); } - // animate the fab without touching the alpha as this is handled in the content transition offset *= 1.5f; float fabTransY = fab.getTranslationY(); + fab.setAlpha(0f); fab.setTranslationY(fabTransY + offset); fab.animate() .translationY(fabTransY) @@ -703,23 +702,19 @@ private void enterAnimation(boolean animateFabManually) { .setInterpolator(interp) .start(); - if (animateFabManually) { - // we rely on the window enter content transition to show the fab. This isn't run on - // orientation changes so manually show it. - Animator showFab = ObjectAnimator.ofPropertyValuesHolder(fab, - PropertyValuesHolder.ofFloat(View.ALPHA, 0f, 1f), - PropertyValuesHolder.ofFloat(View.SCALE_X, 0f, 1f), - PropertyValuesHolder.ofFloat(View.SCALE_Y, 0f, 1f)); - showFab.setStartDelay(300L); - showFab.setDuration(300L); - showFab.setInterpolator(getLinearOutSlowInInterpolator(this)); - showFab.start(); - } + Animator showFab = ObjectAnimator.ofPropertyValuesHolder(fab, + PropertyValuesHolder.ofFloat(View.ALPHA, 0f, 1f), + PropertyValuesHolder.ofFloat(View.SCALE_X, 0f, 1f), + PropertyValuesHolder.ofFloat(View.SCALE_Y, 0f, 1f)); + showFab.setStartDelay(300L); + showFab.setDuration(300L); + showFab.setInterpolator(getLinearOutSlowInInterpolator(this)); + showFab.start(); } private void viewEnterAnimation(View view, float offset, Interpolator interp) { view.setTranslationY(offset); - view.setAlpha(0.8f); + view.setAlpha(0.6f); view.animate() .translationY(0f) .alpha(1f) diff --git a/app/src/main/java/io/plaidapp/ui/transitions/Pop.java b/app/src/main/java/io/plaidapp/ui/transitions/Pop.java index 49dd3c162..10af3be8c 100644 --- a/app/src/main/java/io/plaidapp/ui/transitions/Pop.java +++ b/app/src/main/java/io/plaidapp/ui/transitions/Pop.java @@ -26,66 +26,33 @@ import android.view.View; import android.view.ViewGroup; -import io.plaidapp.util.AnimUtils; - /** - * A transition that animates the alpha & scale X & Y of a view simultaneously. + * A transition that animates the alpha, scale X & Y of a view simultaneously. */ public class Pop extends Visibility { - private static final String PROPNAME_ALPHA = "plaid:pop:alpha"; - private static final String PROPNAME_SCALE_X = "plaid:pop:scaleX"; - private static final String PROPNAME_SCALE_Y = "plaid:pop:scaleY"; - - private static final String[] transitionProperties = { - PROPNAME_ALPHA, - PROPNAME_SCALE_X, - PROPNAME_SCALE_Y - }; - public Pop(Context context, AttributeSet attrs) { super(context, attrs); } - @Override - public String[] getTransitionProperties() { - return transitionProperties; - } - - @Override - public void captureStartValues(TransitionValues transitionValues) { - super.captureStartValues(transitionValues); - transitionValues.values.put(PROPNAME_ALPHA, 0f); - transitionValues.values.put(PROPNAME_SCALE_X, 0f); - transitionValues.values.put(PROPNAME_SCALE_Y, 0f); - } - - @Override - public void captureEndValues(TransitionValues transitionValues) { - super.captureEndValues(transitionValues); - transitionValues.values.put(PROPNAME_ALPHA, 1f); - transitionValues.values.put(PROPNAME_SCALE_X, 1f); - transitionValues.values.put(PROPNAME_SCALE_Y, 1f); - } - @Override public Animator onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) { - return new AnimUtils.NoPauseAnimator(ObjectAnimator.ofPropertyValuesHolder( + return ObjectAnimator.ofPropertyValuesHolder( endValues.view, PropertyValuesHolder.ofFloat(View.ALPHA, 0f, 1f), PropertyValuesHolder.ofFloat(View.SCALE_X, 0f, 1f), - PropertyValuesHolder.ofFloat(View.SCALE_Y, 0f, 1f))); + PropertyValuesHolder.ofFloat(View.SCALE_Y, 0f, 1f)); } @Override public Animator onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) { - return new AnimUtils.NoPauseAnimator(ObjectAnimator.ofPropertyValuesHolder( + return ObjectAnimator.ofPropertyValuesHolder( endValues.view, PropertyValuesHolder.ofFloat(View.ALPHA, 1f, 0f), PropertyValuesHolder.ofFloat(View.SCALE_X, 1f, 0f), - PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f, 0f))); + PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f, 0f)); } } diff --git a/app/src/main/java/io/plaidapp/ui/widget/FABToggle.java b/app/src/main/java/io/plaidapp/ui/widget/FABToggle.java index 46313f73c..ab8ee307d 100644 --- a/app/src/main/java/io/plaidapp/ui/widget/FABToggle.java +++ b/app/src/main/java/io/plaidapp/ui/widget/FABToggle.java @@ -17,13 +17,14 @@ package io.plaidapp.ui.widget; import android.content.Context; -import android.support.v4.view.ViewCompat; import android.util.AttributeSet; import android.widget.Checkable; import android.widget.ImageButton; +import io.plaidapp.util.ViewOffsetHelper; + /** - * A {@link Checkable} {@link ImageButton} which has a minimum offset i.e. translation Y. + * A {@link Checkable} {@link ImageButton} which can be offset vertically. */ public class FABToggle extends ImageButton implements Checkable { @@ -31,16 +32,19 @@ public class FABToggle extends ImageButton implements Checkable { private boolean isChecked = false; private int minOffset; + private int offset = 0; + private ViewOffsetHelper offsetHelper; public FABToggle(Context context, AttributeSet attrs) { super(context, attrs); + offsetHelper = new ViewOffsetHelper(this); } - public void setOffset(int offset) { - offset = Math.max(minOffset, offset); - if (getTranslationY() != offset) { - setTranslationY(offset); - ViewCompat.postInvalidateOnAnimation(this); + public void setOffset(int newOffset) { + if (newOffset != offset) { + newOffset = Math.max(minOffset, newOffset); + offsetHelper.setTopAndBottomOffset(newOffset); + postInvalidateOnAnimation(); } } @@ -72,4 +76,9 @@ public int[] onCreateDrawableState(int extraSpace) { return drawableState; } + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + offsetHelper.onViewLayout(); + } } diff --git a/app/src/main/res/layout/activity_dribbble_shot.xml b/app/src/main/res/layout/activity_dribbble_shot.xml index 81e64c174..70efdfa15 100644 --- a/app/src/main/res/layout/activity_dribbble_shot.xml +++ b/app/src/main/res/layout/activity_dribbble_shot.xml @@ -95,8 +95,7 @@ android:layout_gravity="end" android:layout_marginEnd="@dimen/padding_normal" android:stateListAnimator="@animator/raise" - android:src="@drawable/fab_heart" - android:alpha="0" /> + android:src="@drawable/fab_heart" /> diff --git a/app/src/main/res/transition/dribbble_shot_enter.xml b/app/src/main/res/transition/dribbble_shot_enter.xml index 784c9af8e..a27eb21e2 100644 --- a/app/src/main/res/transition/dribbble_shot_enter.xml +++ b/app/src/main/res/transition/dribbble_shot_enter.xml @@ -15,26 +15,12 @@ limitations under the License. --> - - - - - - - - - - - - - - - - + android:duration="@android:integer/config_mediumAnimTime"> + + + + + diff --git a/app/src/main/res/transition/dribbble_shot_return.xml b/app/src/main/res/transition/dribbble_shot_return.xml index 5bd672fdd..a27eb21e2 100644 --- a/app/src/main/res/transition/dribbble_shot_return.xml +++ b/app/src/main/res/transition/dribbble_shot_return.xml @@ -15,16 +15,12 @@ limitations under the License. --> - - - - - - - - - - + android:interpolator="@android:interpolator/fast_out_slow_in" + android:duration="@android:integer/config_mediumAnimTime"> + + + + +