Search in sources :

Example 1 with GravityArcMotion

use of io.plaidapp.ui.transitions.GravityArcMotion in project plaid by nickbutcher.

the class HomeGridItemAnimator method animateAddToPocket.

private void animateAddToPocket(final FeedAdapter.DesignerNewsStoryHolder holder) {
    endAnimation(holder);
    // setup for anim
    ((ViewGroup) holder.pocket.getParent().getParent()).setClipChildren(false);
    final int initialLeft = holder.pocket.getLeft();
    final int initialTop = holder.pocket.getTop();
    final int translatedLeft = (holder.itemView.getWidth() - holder.pocket.getWidth()) / 2;
    final int translatedTop = initialTop - ((holder.itemView.getHeight() - holder.pocket.getHeight()) / 2);
    final GravityArcMotion arc = new GravityArcMotion();
    // animate the title & pocket icon up, scale the pocket icon up
    Animator titleMoveFadeOut = ObjectAnimator.ofPropertyValuesHolder(holder.title, PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, -(holder.itemView.getHeight() / 5)), PropertyValuesHolder.ofFloat(View.ALPHA, 0.54f));
    Animator pocketMoveUp = ObjectAnimator.ofFloat(holder.pocket, View.TRANSLATION_X, View.TRANSLATION_Y, arc.getPath(initialLeft, initialTop, translatedLeft, translatedTop));
    Animator pocketScaleUp = ObjectAnimator.ofPropertyValuesHolder(holder.pocket, PropertyValuesHolder.ofFloat(View.SCALE_X, 3f), PropertyValuesHolder.ofFloat(View.SCALE_Y, 3f));
    ObjectAnimator pocketFadeUp = ObjectAnimator.ofInt(holder.pocket, ViewUtils.IMAGE_ALPHA, 255);
    AnimatorSet up = new AnimatorSet();
    up.playTogether(titleMoveFadeOut, pocketMoveUp, pocketScaleUp, pocketFadeUp);
    up.setDuration(300L);
    up.setInterpolator(AnimUtils.getFastOutSlowInInterpolator(holder.itemView.getContext()));
    // animate everything back into place
    Animator titleMoveFadeIn = ObjectAnimator.ofPropertyValuesHolder(holder.title, PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 0f), PropertyValuesHolder.ofFloat(View.ALPHA, 1f));
    Animator pocketMoveDown = ObjectAnimator.ofFloat(holder.pocket, View.TRANSLATION_X, View.TRANSLATION_Y, arc.getPath(translatedLeft, translatedTop, 0, 0));
    Animator pvhPocketScaleDown = ObjectAnimator.ofPropertyValuesHolder(holder.pocket, PropertyValuesHolder.ofFloat(View.SCALE_X, 1f), PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f));
    ObjectAnimator pocketFadeDown = ObjectAnimator.ofInt(holder.pocket, ViewUtils.IMAGE_ALPHA, 178);
    AnimatorSet down = new AnimatorSet();
    down.playTogether(titleMoveFadeIn, pocketMoveDown, pvhPocketScaleDown, pocketFadeDown);
    down.setStartDelay(500L);
    down.setDuration(300L);
    down.setInterpolator(AnimUtils.getFastOutSlowInInterpolator(holder.itemView.getContext()));
    AnimatorSet addToPocketAnim = new AnimatorSet();
    addToPocketAnim.playSequentially(up, down);
    addToPocketAnim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            dispatchChangeStarting(holder, false);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            ((ViewGroup) holder.pocket.getParent().getParent()).setClipChildren(true);
            runningAddToPocket = null;
            dispatchChangeFinished(holder, false);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            holder.title.setAlpha(1f);
            holder.title.setTranslationY(0f);
            holder.pocket.setTranslationX(0f);
            holder.pocket.setTranslationY(0f);
            holder.pocket.setScaleX(1f);
            holder.pocket.setScaleY(1f);
            holder.pocket.setImageAlpha(178);
            runningAddToPocket = null;
            dispatchChangeFinished(holder, false);
        }
    });
    runningAddToPocket = Pair.create(holder, addToPocketAnim);
    addToPocketAnim.start();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) SlideInItemAnimator(io.plaidapp.ui.recyclerview.SlideInItemAnimator) ViewGroup(android.view.ViewGroup) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) GravityArcMotion(io.plaidapp.ui.transitions.GravityArcMotion) AnimatorSet(android.animation.AnimatorSet)

Example 2 with GravityArcMotion

use of io.plaidapp.ui.transitions.GravityArcMotion in project plaid by nickbutcher.

the class DesignerNewsStory method doFabExpand.

private void doFabExpand() {
    // translate the chrome placeholder ui so that it is centered on the FAB
    int fabCenterX = (fab.getLeft() + fab.getRight()) / 2;
    int fabCenterY = ((fab.getTop() + fab.getBottom()) / 2) - fabExpand.getTop();
    int translateX = fabCenterX - (fabExpand.getWidth() / 2);
    int translateY = fabCenterY - (fabExpand.getHeight() / 2);
    fabExpand.setTranslationX(translateX);
    fabExpand.setTranslationY(translateY);
    // then reveal the placeholder ui, starting from the center & same dimens as fab
    fabExpand.setVisibility(View.VISIBLE);
    Animator reveal = ViewAnimationUtils.createCircularReveal(fabExpand, fabExpand.getWidth() / 2, fabExpand.getHeight() / 2, fab.getWidth() / 2, (int) Math.hypot(fabExpand.getWidth() / 2, fabExpand.getHeight() / 2)).setDuration(fabExpandDuration);
    // translate the placeholder ui back into position along an arc
    GravityArcMotion arcMotion = new GravityArcMotion();
    arcMotion.setMinimumVerticalAngle(70f);
    Path motionPath = arcMotion.getPath(translateX, translateY, 0, 0);
    Animator position = ObjectAnimator.ofFloat(fabExpand, View.TRANSLATION_X, View.TRANSLATION_Y, motionPath).setDuration(fabExpandDuration);
    // animate from the FAB colour to the placeholder background color
    Animator background = ObjectAnimator.ofArgb(fabExpand, ViewUtils.BACKGROUND_COLOR, ContextCompat.getColor(this, R.color.designer_news), ContextCompat.getColor(this, R.color.background_light)).setDuration(fabExpandDuration);
    // fade out the fab (rapidly)
    Animator fadeOutFab = ObjectAnimator.ofFloat(fab, View.ALPHA, 0f).setDuration(60);
    // play 'em all together with the material interpolator
    AnimatorSet show = new AnimatorSet();
    show.setInterpolator(getFastOutSlowInInterpolator(DesignerNewsStory.this));
    show.playTogether(reveal, background, position, fadeOutFab);
    show.start();
}
Also used : Path(android.graphics.Path) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) SlideInItemAnimator(io.plaidapp.ui.recyclerview.SlideInItemAnimator) GravityArcMotion(io.plaidapp.ui.transitions.GravityArcMotion) AnimatorSet(android.animation.AnimatorSet)

Aggregations

Animator (android.animation.Animator)2 AnimatorSet (android.animation.AnimatorSet)2 ObjectAnimator (android.animation.ObjectAnimator)2 SlideInItemAnimator (io.plaidapp.ui.recyclerview.SlideInItemAnimator)2 GravityArcMotion (io.plaidapp.ui.transitions.GravityArcMotion)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 Path (android.graphics.Path)1 ViewGroup (android.view.ViewGroup)1