Skip to content

Commit

Permalink
Fixed FAB enter transition on N.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbutcher committed Jul 11, 2016
1 parent 7ff22e1 commit 5e81f5b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 101 deletions.
37 changes: 16 additions & 21 deletions app/src/main/java/io/plaidapp/ui/DribbbleShot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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")) {
Expand All @@ -201,7 +200,7 @@ public void onDragDismissed() {
@Override
public void onResponse(Call<Shot> call, Response<Shot> response) {
shot = response.body();
bindShot(false, true);
bindShot(false);
}

@Override
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -671,20 +670,20 @@ 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);
if (description.getVisibility() == View.VISIBLE) {
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)
Expand All @@ -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)
Expand Down
43 changes: 5 additions & 38 deletions app/src/main/java/io/plaidapp/ui/transitions/Pop.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}
23 changes: 16 additions & 7 deletions app/src/main/java/io/plaidapp/ui/widget/FABToggle.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,34 @@
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 {

private static final int[] CHECKED_STATE_SET = { android.R.attr.state_checked };

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();
}
}

Expand Down Expand Up @@ -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();
}
}
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_dribbble_shot.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

</FrameLayout>

Expand Down
28 changes: 7 additions & 21 deletions app/src/main/res/transition/dribbble_shot_enter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,12 @@
limitations under the License.
-->

<transitionSet
<fade
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/fast_out_slow_in"
android:transitionOrdering="together">

<transition
class="io.plaidapp.ui.transitions.Pop"
android:startDelay="300"
android:duration="300"
android:interpolator="@android:interpolator/linear_out_slow_in">
<targets>
<target android:targetId="@id/fab_heart" />
</targets>
</transition>

<fade android:duration="@android:integer/config_mediumAnimTime">
<targets>
<target android:targetId="@android:id/navigationBarBackground" />
<target android:targetId="@android:id/statusBarBackground" />
</targets>
</fade>

</transitionSet>
android:duration="@android:integer/config_mediumAnimTime">
<targets>
<target android:targetId="@android:id/navigationBarBackground" />
<target android:targetId="@android:id/statusBarBackground" />
</targets>
</fade>
20 changes: 8 additions & 12 deletions app/src/main/res/transition/dribbble_shot_return.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@
limitations under the License.
-->

<transitionSet
<fade
xmlns:android="http://schemas.android.com/apk/res/android"
android:transitionOrdering="together"
android:interpolator="@android:interpolator/fast_out_slow_in">

<fade android:duration="@android:integer/config_mediumAnimTime">
<targets>
<target android:targetId="@android:id/navigationBarBackground" />
<target android:targetId="@android:id/statusBarBackground" />
</targets>
</fade>

</transitionSet>
android:interpolator="@android:interpolator/fast_out_slow_in"
android:duration="@android:integer/config_mediumAnimTime">
<targets>
<target android:targetId="@android:id/navigationBarBackground" />
<target android:targetId="@android:id/statusBarBackground" />
</targets>
</fade>

0 comments on commit 5e81f5b

Please sign in to comment.