Search in sources :

Example 1 with MorphDrawable

use of io.plaidapp.ui.drawable.MorphDrawable in project plaid by nickbutcher.

the class MorphTransform method createAnimator.

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) {
    final Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues);
    if (changeBounds == null)
        return null;
    TimeInterpolator interpolator = getInterpolator();
    if (interpolator == null) {
        interpolator = AnimUtils.getFastOutSlowInInterpolator(sceneRoot.getContext());
    }
    final MorphDrawable background = new MorphDrawable(startColor, startCornerRadius);
    endValues.view.setBackground(background);
    final Animator color = ObjectAnimator.ofArgb(background, MorphDrawable.COLOR, endColor);
    final Animator corners = ObjectAnimator.ofFloat(background, MorphDrawable.CORNER_RADIUS, endCornerRadius);
    // ease in the dialog's child views (fade in & staggered slide up)
    if (endValues.view instanceof ViewGroup) {
        final ViewGroup vg = (ViewGroup) endValues.view;
        final long duration = getDuration() / 2;
        float offset = vg.getHeight() / 3;
        for (int i = 0; i < vg.getChildCount(); i++) {
            View v = vg.getChildAt(i);
            v.setTranslationY(offset);
            v.setAlpha(0f);
            v.animate().alpha(1f).translationY(0f).setDuration(duration).setStartDelay(duration).setInterpolator(interpolator);
            offset *= 1.8f;
        }
    }
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(changeBounds, corners, color);
    transition.setDuration(getDuration());
    transition.setInterpolator(interpolator);
    return transition;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ViewGroup(android.view.ViewGroup) MorphDrawable(io.plaidapp.ui.drawable.MorphDrawable) AnimatorSet(android.animation.AnimatorSet) TimeInterpolator(android.animation.TimeInterpolator) View(android.view.View)

Example 2 with MorphDrawable

use of io.plaidapp.ui.drawable.MorphDrawable in project plaid by nickbutcher.

the class MorphDialogToFab method createAnimator.

@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues);
    if (startValues == null || endValues == null || changeBounds == null) {
        return null;
    }
    Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR);
    Integer startCornerRadius = (Integer) startValues.values.get(PROPERTY_CORNER_RADIUS);
    Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR);
    Integer endCornerRadius = (Integer) endValues.values.get(PROPERTY_CORNER_RADIUS);
    if (startColor == null || startCornerRadius == null || endColor == null || endCornerRadius == null) {
        return null;
    }
    MorphDrawable background = new MorphDrawable(startColor, startCornerRadius);
    endValues.view.setBackground(background);
    Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor);
    Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius);
    // hide child views (offset down & fade out)
    if (endValues.view instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) endValues.view;
        for (int i = 0; i < vg.getChildCount(); i++) {
            View v = vg.getChildAt(i);
            v.animate().alpha(0f).translationY(v.getHeight() / 3).setStartDelay(0L).setDuration(50L).setInterpolator(getFastOutLinearInInterpolator(vg.getContext())).start();
        }
    }
    AnimatorSet transition = new AnimatorSet();
    transition.playTogether(changeBounds, corners, color);
    transition.setDuration(300);
    transition.setInterpolator(getFastOutSlowInInterpolator(sceneRoot.getContext()));
    return transition;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ViewGroup(android.view.ViewGroup) MorphDrawable(io.plaidapp.ui.drawable.MorphDrawable) AnimatorSet(android.animation.AnimatorSet) View(android.view.View)

Aggregations

Animator (android.animation.Animator)2 AnimatorSet (android.animation.AnimatorSet)2 ObjectAnimator (android.animation.ObjectAnimator)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 MorphDrawable (io.plaidapp.ui.drawable.MorphDrawable)2 TimeInterpolator (android.animation.TimeInterpolator)1