Example usage for android.transition ArcMotion getPath

List of usage examples for android.transition ArcMotion getPath

Introduction

In this page you can find the example usage for android.transition ArcMotion getPath.

Prototype

@Override
    public Path getPath(float startX, float startY, float endX, float endY) 

Source Link

Usage

From source file:io.plaidapp.ui.DesignerNewsStory.java

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
    ArcMotion arcMotion = new ArcMotion();
    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(//w w  w  .j  av a2 s . c  o m
            AnimationUtils.loadInterpolator(DesignerNewsStory.this, android.R.interpolator.fast_out_slow_in));
    show.playTogether(reveal, background, position, fadeOutFab);
    show.start();
}

From source file:com.hannesdorfmann.FeedAdapter.java

private void bindDesignerNewsStory(final Story story, final DesignerNewsStoryHolder holder) {
    holder.title.setText(story.title);/*from   www. j  ava  2 s  .  c  om*/
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CustomTabActivityHelper.openCustomTab(host,
                    DesignerNewsStory.getCustomTabIntent(host, story, null).build(), Uri.parse(story.url));
        }
    });
    holder.comments.setText(String.valueOf(story.comment_count));
    holder.comments.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View commentsView) {
            final Intent intent = new Intent();
            intent.setClass(host, DesignerNewsStory.class);
            intent.putExtra(DesignerNewsStory.EXTRA_STORY, story);
            final ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host,
                    Pair.create(holder.itemView, host.getString(R.string.transition_story_title_background)),
                    Pair.create(holder.itemView, host.getString(R.string.transition_story_background)));
            host.startActivity(intent, options.toBundle());
        }
    });
    if (pocketIsInstalled) {
        holder.pocket.setImageAlpha(178); // grumble... no xml setter, grumble...
        holder.pocket.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View view) {
                final ImageButton pocketButton = (ImageButton) view;
                // actually add to pocket
                PocketUtils.addToPocket(host, story.url);

                // setup for anim
                holder.itemView.setHasTransientState(true);
                ((ViewGroup) pocketButton.getParent().getParent()).setClipChildren(false);
                final int initialLeft = pocketButton.getLeft();
                final int initialTop = pocketButton.getTop();
                final int translatedLeft = (holder.itemView.getWidth() - pocketButton.getWidth()) / 2;
                final int translatedTop = initialTop
                        - ((holder.itemView.getHeight() - pocketButton.getHeight()) / 2);
                final ArcMotion arc = new ArcMotion();

                // animate the title & pocket icon up, scale the pocket icon up
                PropertyValuesHolder pvhTitleUp = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y,
                        -(holder.itemView.getHeight() / 5));
                PropertyValuesHolder pvhTitleFade = PropertyValuesHolder.ofFloat(View.ALPHA, 0.54f);
                Animator titleMoveFadeOut = ObjectAnimator.ofPropertyValuesHolder(holder.title, pvhTitleUp,
                        pvhTitleFade);

                Animator pocketMoveUp = ObjectAnimator.ofFloat(pocketButton, View.TRANSLATION_X,
                        View.TRANSLATION_Y,
                        arc.getPath(initialLeft, initialTop, translatedLeft, translatedTop));
                PropertyValuesHolder pvhPocketScaleUpX = PropertyValuesHolder.ofFloat(View.SCALE_X, 3f);
                PropertyValuesHolder pvhPocketScaleUpY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 3f);
                Animator pocketScaleUp = ObjectAnimator.ofPropertyValuesHolder(pocketButton, pvhPocketScaleUpX,
                        pvhPocketScaleUpY);
                ObjectAnimator pocketFadeUp = ObjectAnimator.ofInt(pocketButton, ViewUtils.IMAGE_ALPHA, 255);

                AnimatorSet up = new AnimatorSet();
                up.playTogether(titleMoveFadeOut, pocketMoveUp, pocketScaleUp, pocketFadeUp);
                up.setDuration(300);
                up.setInterpolator(
                        AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in));

                // animate everything back into place
                PropertyValuesHolder pvhTitleMoveUp = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 0f);
                PropertyValuesHolder pvhTitleFadeUp = PropertyValuesHolder.ofFloat(View.ALPHA, 1f);
                Animator titleMoveFadeIn = ObjectAnimator.ofPropertyValuesHolder(holder.title, pvhTitleMoveUp,
                        pvhTitleFadeUp);
                Animator pocketMoveDown = ObjectAnimator.ofFloat(pocketButton, View.TRANSLATION_X,
                        View.TRANSLATION_Y, arc.getPath(translatedLeft, translatedTop, 0, 0));
                PropertyValuesHolder pvhPocketScaleDownX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1f);
                PropertyValuesHolder pvhPocketScaleDownY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f);
                Animator pvhPocketScaleDown = ObjectAnimator.ofPropertyValuesHolder(pocketButton,
                        pvhPocketScaleDownX, pvhPocketScaleDownY);
                ObjectAnimator pocketFadeDown = ObjectAnimator.ofInt(pocketButton, ViewUtils.IMAGE_ALPHA, 138);

                AnimatorSet down = new AnimatorSet();
                down.playTogether(titleMoveFadeIn, pocketMoveDown, pvhPocketScaleDown, pocketFadeDown);
                down.setDuration(300);
                down.setInterpolator(
                        AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in));
                down.setStartDelay(500);

                // play it
                AnimatorSet upDown = new AnimatorSet();
                upDown.playSequentially(up, down);

                // clean up
                upDown.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        ((ViewGroup) pocketButton.getParent().getParent()).setClipChildren(true);
                        holder.itemView.setHasTransientState(false);
                    }
                });
                upDown.start();
            }
        });
    }
}