Example usage for android.view View setTranslationX

List of usage examples for android.view View setTranslationX

Introduction

In this page you can find the example usage for android.view View setTranslationX.

Prototype

public void setTranslationX(float translationX) 

Source Link

Document

Sets the horizontal location of this view relative to its #getLeft() left position.

Usage

From source file:com.arlib.floatingsearchview.util.view.MenuView.java

/**
 * Hides all the menu items flagged with "ifRoom"
 *
 * @param withAnim//from w w w.  j  a  va  2s. co m
 */
public void hideIfRoomItems(boolean withAnim) {

    if (mMenu == -1)
        return;

    mActionShowAlwaysItems.clear();
    cancelChildAnimListAndClear();

    List<MenuItemImpl> showAlwaysActionItems = filter(mMenuItems, new MenuItemImplPredicate() {
        @Override
        public boolean apply(MenuItemImpl menuItem) {
            return menuItem.requiresActionButton();
        }
    });

    int actionItemIndex;
    for (actionItemIndex = 0; actionItemIndex < mActionItems.size()
            && actionItemIndex < showAlwaysActionItems.size(); actionItemIndex++) {

        final MenuItemImpl actionItem = showAlwaysActionItems.get(actionItemIndex);

        if (mActionItems.get(actionItemIndex).getItemId() != showAlwaysActionItems.get(actionItemIndex)
                .getItemId()) {

            ImageView action = (ImageView) getChildAt(actionItemIndex);
            action.setImageDrawable(Util.setIconColor(actionItem.getIcon(), mActionIconColor));

            action.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (mMenuCallback != null)
                        mMenuCallback.onMenuItemSelected(mMenuBuilder, actionItem);
                }
            });

        }

        mActionShowAlwaysItems.add(actionItem);
    }

    final int diff = mActionItems.size() - actionItemIndex + (mHasOverflow ? 1 : 0);

    anims = new ArrayList<>();

    for (int i = 0; i < actionItemIndex; i++) {
        final View currentChild = getChildAt(i);
        final float destTransX = ACTION_DIMENSION_PX * diff - (mHasOverflow ? Util.dpToPx(8) : 0);
        anims.add(ViewPropertyObjectAnimator.animate(currentChild)
                .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                .setInterpolator(new AccelerateInterpolator()).addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {

                        currentChild.setTranslationX(destTransX);
                    }
                }).translationXBy(destTransX).get());
    }

    for (int i = actionItemIndex; i < diff + actionItemIndex; i++) {

        final View currentView = getChildAt(i);

        currentView.setClickable(false);

        if (i != getChildCount() - 1)
            anims.add(ViewPropertyObjectAnimator.animate(currentView)
                    .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                    .addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {

                            currentView.setTranslationX(ACTION_DIMENSION_PX);
                        }
                    }).translationXBy(ACTION_DIMENSION_PX).get());

        anims.add(ViewPropertyObjectAnimator.animate(currentView)
                .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                .addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {

                        currentView.setScaleX(0.5f);
                    }
                }).scaleX(.5f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView)
                .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                .addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {

                        currentView.setScaleY(0.5f);
                    }
                }).scaleY(.5f).get());
        anims.add(ViewPropertyObjectAnimator.animate(getChildAt(i))
                .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                .addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {

                        currentView.setAlpha(0.0f);
                    }
                }).alpha(0.0f).get());
    }

    final int actinItemsCount = actionItemIndex;
    if (!anims.isEmpty()) {

        AnimatorSet animSet = new AnimatorSet();
        if (!withAnim)
            animSet.setDuration(0);
        animSet.playTogether(anims.toArray(new ObjectAnimator[anims.size()]));
        animSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                if (mOnVisibleWidthChanged != null)
                    mOnVisibleWidthChanged.onVisibleWidthChanged(((int) ACTION_DIMENSION_PX * actinItemsCount));
            }
        });
        animSet.start();
    }

}

From source file:com.jinzht.pro.swipelistview.SwipeListViewTouchListener.java

/**
 * Reset the state of front view when the it's recycled by ListView
 *
 * @param frontView view to re-draw//  ww  w.j av  a2s .c  om
 */
protected void reloadSwipeStateInView(View frontView, int position) {
    if (!opened.get(position)) {
        frontView.setTranslationX(0.0f);
    } else {
        if (openedRight.get(position)) {
            frontView.setTranslationX(swipeListView.getWidth());
        } else {
            frontView.setTranslationX(-swipeListView.getWidth());
        }
    }

}

From source file:co.ceryle.radiorealbutton.library.RadioRealButtonGroup.java

private void animateSelectorSliding(int toPosition, String property, boolean hasAnimation,
        boolean enableDeselection) {
    boolean isViewDrawn = buttons.size() > 0 && buttons.get(0).getWidth() > 0;
    if (!isViewDrawn) {
        if (initialPosition != -1)
            v_selectors.get(initialPosition).setVisibility(INVISIBLE);
        v_selectors.get(toPosition).setVisibility(VISIBLE);
        initialPosition = toPosition;// w  ww .  j a  v  a2 s.c om
        return;
    }

    if (initialPosition < 0) {
        initialPosition = 0;

        View view = v_selectors.get(initialPosition);
        view.setTranslationX(-buttons.get(initialPosition).getWidth());
        view.setVisibility(VISIBLE);
    }

    if (enableDeselection && toPosition == lastPosition && buttons.get(toPosition).isChecked()) {
        toPosition = lastPosition > numberOfButtons / 2 ? numberOfButtons : -1;
    }

    float position = toPosition - initialPosition;

    float value = buttons.get(initialPosition).getWidth() * position + dividerSize * position;
    ObjectAnimator animator = createAnimator(v_selectors.get(initialPosition), property, value, false,
            hasAnimation);
    animator.start();
}

From source file:edward.com.recyclerview.BaseItemAnimator.java

@Override
public void endAnimation(ViewHolder item) {
    final View view = item.itemView;
    // this will trigger end callback which should set properties to their target values.
    view.animate().cancel();//  w  ww.  j a va 2s .c o  m
    // TODO if some other animations are chained to end, how do we cancel them as well?
    for (int i = mPendingMoves.size() - 1; i >= 0; i--) {
        MoveInfo moveInfo = mPendingMoves.get(i);
        if (moveInfo.holder == item) {
            view.setTranslationY(0);
            view.setTranslationX(0);
            dispatchMoveFinished(item);
            mPendingMoves.remove(i);
        }
    }
    endChangeAnimation(mPendingChanges, item);
    if (mPendingRemovals.remove(item)) {
        reset(item.itemView);
        dispatchRemoveFinished(item);
    }
    if (mPendingAdditions.remove(item)) {
        reset(item.itemView);
        dispatchAddFinished(item);
    }

    for (int i = mChangesList.size() - 1; i >= 0; i--) {
        ArrayList<ChangeInfo> changes = mChangesList.get(i);
        endChangeAnimation(changes, item);
        if (changes.isEmpty()) {
            mChangesList.remove(i);
        }
    }
    for (int i = mMovesList.size() - 1; i >= 0; i--) {
        ArrayList<MoveInfo> moves = mMovesList.get(i);
        for (int j = moves.size() - 1; j >= 0; j--) {
            MoveInfo moveInfo = moves.get(j);
            if (moveInfo.holder == item) {
                view.setTranslationY(0);
                view.setTranslationX(0);
                dispatchMoveFinished(item);
                moves.remove(j);
                if (moves.isEmpty()) {
                    mMovesList.remove(i);
                }
                break;
            }
        }
    }
    for (int i = mAdditionsList.size() - 1; i >= 0; i--) {
        ArrayList<ViewHolder> additions = mAdditionsList.get(i);
        if (additions.remove(item)) {
            reset(item.itemView);
            dispatchAddFinished(item);
            if (additions.isEmpty()) {
                mAdditionsList.remove(i);
            }
        }
    }

    // animations should be ended by the cancel above.
    if (mRemoveAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException(
                "after animation is cancelled, item should not be in " + "mRemoveAnimations list");
    }

    if (mAddAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException(
                "after animation is cancelled, item should not be in " + "mAddAnimations list");
    }

    if (mChangeAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException(
                "after animation is cancelled, item should not be in " + "mChangeAnimations list");
    }

    if (mMoveAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException(
                "after animation is cancelled, item should not be in " + "mMoveAnimations list");
    }
    dispatchFinishedWhenDone();
}

From source file:nu.yona.app.ui.tour.YonaCarrouselActivity.java

@Override
public void transformPage(View view, float position) {

    final int pageWidth = view.getWidth();

    /*/*  w w w  . j a  va  2 s.c om*/
     * When a page's alpha is set to 0 it's visibility should also be set to gone.
     * Even though the view isn't visible it can still be interacted with if it isn't gone and is drawn on top.
     */

    /*
     * Position is checked right up next to -1 and 1. The reason is because sometimes the position doesn't seem to come
     * all the way through as a whole number. Meaning it seems it would stop so very close to -1 or 0 (for example) and
     * the code to make necessary views 'gone' never gets called. So then there could be an invisible view on top that is
     * still able to be interacted with.
     */

    if (position < -TRANFORMATION_POSITION) { // [-Infinity,-1)
                                              // This page is way off-screen to the left so hide it.
        view.setAlpha(0);
        view.setTranslationX(pageWidth);
    } else if (position <= TRANFORMATION_POSITION) { // (-1, 1)
                                                     // The further the page is from being center page the more transparent it is.
        view.setAlpha(getAlpha(position));
        // Counteract the default slide transition
        view.setTranslationX(pageWidth * -position);
        // Make sure the page is visible
        view.setVisibility(View.VISIBLE);
    } else { // (1,+Infinity]
             // This page is way off-screen to the right so hide it.
        view.setAlpha(0);
        view.setVisibility(View.GONE);
        view.setTranslationX(-pageWidth);
    }
}

From source file:com.fastbootmobile.encore.app.ArtistActivity.java

@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_artist);

    mHandler = new Handler();

    FragmentManager fm = getSupportFragmentManager();
    mActiveFragment = (ArtistFragment) fm.findFragmentByTag(TAG_FRAGMENT);

    if (savedInstanceState == null) {
        mHero = Utils.dequeueBitmap(BITMAP_ARTIST_HERO);
        mInitialIntent = getIntent().getExtras();
    } else {//from w  w  w  . j a  va 2 s  . c o  m
        mHero = Utils.dequeueBitmap(BITMAP_ARTIST_HERO);
        mInitialIntent = savedInstanceState.getBundle(EXTRA_RESTORE_INTENT);
    }

    if (mActiveFragment == null) {
        mActiveFragment = new ArtistFragment();
        fm.beginTransaction().add(R.id.container, mActiveFragment, TAG_FRAGMENT).commit();
    }

    mActiveFragment.setArguments(mHero, mInitialIntent);

    // Remove the activity title as we don't want it here
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setTitle("");
    }

    mIsEntering = true;

    if (Utils.hasLollipop()) {
        setEnterSharedElementCallback(new SharedElementCallback() {
            @Override
            public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
                View fab = mActiveFragment.findViewById(R.id.fabPlay);
                fab.setVisibility(View.VISIBLE);

                // get the center for the clipping circle
                int cx = fab.getMeasuredWidth() / 2;
                int cy = fab.getMeasuredHeight() / 2;

                // get the final radius for the clipping circle
                final int finalRadius = fab.getWidth();

                // create and start the animator for this view
                // (the start radius is zero)
                Animator anim;
                if (mIsEntering) {
                    anim = ViewAnimationUtils.createCircularReveal(fab, cx, cy, 0, finalRadius);
                } else {
                    anim = ViewAnimationUtils.createCircularReveal(fab, cx, cy, finalRadius, 0);
                }
                anim.setInterpolator(new DecelerateInterpolator());
                anim.start();

                fab.setTranslationX(-fab.getMeasuredWidth() / 4.0f);
                fab.setTranslationY(-fab.getMeasuredHeight() / 4.0f);
                fab.animate().translationX(0.0f).translationY(0.0f)
                        .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime))
                        .setInterpolator(new DecelerateInterpolator()).start();

                final View artistName = mActiveFragment.findViewById(R.id.tvArtist);
                if (artistName != null) {
                    cx = artistName.getMeasuredWidth() / 4;
                    cy = artistName.getMeasuredHeight() / 2;
                    final int duration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
                    final int radius = Utils.getEnclosingCircleRadius(artistName, cx, cy);

                    if (mIsEntering) {
                        artistName.setVisibility(View.INVISIBLE);
                        Utils.animateCircleReveal(artistName, cx, cy, 0, radius, duration, 300);
                    } else {
                        artistName.setVisibility(View.VISIBLE);
                        Utils.animateCircleReveal(artistName, cx, cy, radius, 0, duration, 0);
                    }
                }
            }
        });
    }

    getWindow().getDecorView()
            .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

From source file:com.oceansky.yellow.app.ArtistActivity.java

@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_artist);

    mHandler = new Handler();

    FragmentManager fm = getSupportFragmentManager();
    mActiveFragment = (ArtistFragment) fm.findFragmentByTag(TAG_FRAGMENT);

    if (savedInstanceState == null) {
        mHero = Utils.dequeueBitmap(BITMAP_ARTIST_HERO);
        mInitialIntent = getIntent().getExtras();
    } else {/*from w  ww .ja v  a2s  .com*/
        mHero = Utils.dequeueBitmap(BITMAP_ARTIST_HERO);
        mInitialIntent = savedInstanceState.getBundle(EXTRA_RESTORE_INTENT);
    }

    if (mActiveFragment == null) {
        mActiveFragment = new ArtistFragment();
        fm.beginTransaction().add(R.id.container, mActiveFragment, TAG_FRAGMENT).commit();
    }

    try {
        mActiveFragment.setArguments(mHero, mInitialIntent);
    } catch (IllegalStateException e) {
        Log.e(TAG, "Invalid artist!", e);
    }

    // Remove the activity title as we don't want it here
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setTitle("");
    }

    mIsEntering = true;

    if (Utils.hasLollipop()) {
        setEnterSharedElementCallback(new SharedElementCallback() {
            @Override
            public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
                View fab = mActiveFragment.findViewById(R.id.fabPlay);
                fab.setVisibility(View.VISIBLE);

                // get the center for the clipping circle
                int cx = fab.getMeasuredWidth() / 2;
                int cy = fab.getMeasuredHeight() / 2;

                // get the final radius for the clipping circle
                final int finalRadius = fab.getWidth();

                // create and start the animator for this view
                // (the start radius is zero)
                Animator anim;
                if (mIsEntering) {
                    anim = ViewAnimationUtils.createCircularReveal(fab, cx, cy, 0, finalRadius);
                } else {
                    anim = ViewAnimationUtils.createCircularReveal(fab, cx, cy, finalRadius, 0);
                }
                anim.setInterpolator(new DecelerateInterpolator());
                anim.start();

                fab.setTranslationX(-fab.getMeasuredWidth() / 4.0f);
                fab.setTranslationY(-fab.getMeasuredHeight() / 4.0f);
                fab.animate().translationX(0.0f).translationY(0.0f)
                        .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime))
                        .setInterpolator(new DecelerateInterpolator()).start();

                final View artistName = mActiveFragment.findViewById(R.id.tvArtist);
                if (artistName != null) {
                    cx = artistName.getMeasuredWidth() / 4;
                    cy = artistName.getMeasuredHeight() / 2;
                    final int duration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
                    final int radius = Utils.getEnclosingCircleRadius(artistName, cx, cy);

                    if (mIsEntering) {
                        artistName.setVisibility(View.INVISIBLE);
                        Utils.animateCircleReveal(artistName, cx, cy, 0, radius, duration, 300);
                    } else {
                        artistName.setVisibility(View.VISIBLE);
                        Utils.animateCircleReveal(artistName, cx, cy, radius, 0, duration, 0);
                    }
                }
            }
        });
    }

    getWindow().getDecorView()
            .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

From source file:com.mjw.android.swipe.SwipeListViewTouchListener.java

/**
 * Reset the state of front view when the it's recycled by ListView
 * /*  ww  w  .  j  a  v  a  2 s.  c o  m*/
 * @param frontView
 *            view to re-draw
 */
protected void reloadSwipeStateInView(View frontView, int position) {

    // dirty hack. yolo.
    if (position > opened.size() - 1) {
        return;
    }
    if (!opened.get(position)) {
        frontView.setTranslationX(0.0f);
    } else {
        if (openedRight.get(position)) {
            frontView.setTranslationX(swipeListView.getWidth());
        } else {
            frontView.setTranslationX(-swipeListView.getWidth());
        }
    }

}

From source file:com.bachhuberdesign.deckbuildergwent.util.FabTransform.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues,
        final TransitionValues endValues) {
    if (startValues == null || endValues == null)
        return null;

    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);

    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Interpolator fastOutSlowInInterpolator = AnimUtils.getFastOutSlowInInterpolator();
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;

    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
                makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }//www  . j  a va  2  s. c o m

    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }

    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab)
        fabColor.setAlpha(0);
    view.getOverlay().add(fabColor);

    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(),
            iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab)
        fabIcon.setAlpha(0);
    view.getOverlay().add(fabIcon);

    // Since the view that's being transition to always seems to be on the top (z-order), we have
    // to make a copy of the "from" view and put it in the "to" view's overlay, then fade it out.
    // There has to be another way to do this, right?
    Drawable dialogView = null;
    if (!fromFab) {
        startValues.view.setDrawingCacheEnabled(true);
        startValues.view.buildDrawingCache();
        Bitmap viewBitmap = startValues.view.getDrawingCache();
        dialogView = new BitmapDrawable(view.getResources(), viewBitmap);
        dialogView.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
        view.getOverlay().add(dialogView);
    }

    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, startBounds.width() / 2,
                (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2));
        circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator());
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2),
                endBounds.width() / 2);
        circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator());

        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                final ViewOutlineProvider fabOutlineProvider = view.getOutlineProvider();

                view.setOutlineProvider(new ViewOutlineProvider() {
                    boolean hasRun = false;

                    @Override
                    public void getOutline(final View view, Outline outline) {
                        final int left = (view.getWidth() - endBounds.width()) / 2;
                        final int top = (view.getHeight() - endBounds.height()) / 2;

                        outline.setOval(left, top, left + endBounds.width(), top + endBounds.height());

                        if (!hasRun) {
                            hasRun = true;
                            view.setClipToOutline(true);

                            // We have to remove this as soon as it's laid out so we can get the shadow back
                            view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
                                @Override
                                public boolean onPreDraw() {
                                    if (view.getWidth() == endBounds.width()
                                            && view.getHeight() == endBounds.height()) {
                                        view.setOutlineProvider(fabOutlineProvider);
                                        view.setClipToOutline(false);
                                        view.getViewTreeObserver().removeOnPreDrawListener(this);
                                        return true;
                                    }

                                    return true;
                                }
                            });
                        }
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);

    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0)
                    : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);

    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }

    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);

    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (dialogView != null) {
        final Animator dialogViewFade = ObjectAnimator.ofInt(dialogView, "alpha", 0)
                .setDuration(twoThirdsDuration);
        dialogViewFade.setInterpolator(fastOutSlowInInterpolator);
        transition.playTogether(dialogViewFade);
    }
    transition.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            // Clean up
            view.getOverlay().clear();

            if (!fromFab) {
                view.setTranslationX(0);
                view.setTranslationY(0);
                view.setTranslationZ(0);

                view.measure(makeMeasureSpec(endBounds.width(), View.MeasureSpec.EXACTLY),
                        makeMeasureSpec(endBounds.height(), View.MeasureSpec.EXACTLY));
                view.layout(endBounds.left, endBounds.top, endBounds.right, endBounds.bottom);
            }

        }
    });
    return new AnimUtils.NoPauseAnimator(transition);
}

From source file:de.dreier.mytargets.utils.transitions.FabTransform.java

@Override
public Animator createAnimator(@NonNull final ViewGroup sceneRoot, final TransitionValues startValues,
        final TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }//from ww  w.ja  v  a2  s .  c  o  m

    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);

    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Rect fabBounds = fromFab ? startBounds : endBounds;
    final Interpolator fastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;

    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
                makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }

    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }

    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab) {
        fabColor.setAlpha(0);
    }
    view.getOverlay().add(fabColor);

    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(),
            iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab) {
        fabIcon.setAlpha(0);
    }
    view.getOverlay().add(fabIcon);

    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, startBounds.width() / 2,
                (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2));
        circularReveal.setInterpolator(new FastOutLinearInInterpolator());
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2),
                endBounds.width() / 2);
        circularReveal.setInterpolator(new LinearOutSlowInInterpolator());

        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setOutlineProvider(new ViewOutlineProvider() {
                    @Override
                    public void getOutline(View view, Outline outline) {
                        final int left = (view.getWidth() - fabBounds.width()) / 2;
                        final int top = (view.getHeight() - fabBounds.height()) / 2;
                        outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height());
                        view.setClipToOutline(true);
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);

    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0)
                    : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);

    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }

    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);

    // Work around issue with elevation shadows. At the end of the return transition the shared
    // element's shadow is drawn twice (by each activity) which is jarring. This workaround
    // still causes the shadow to snap, but it's better than seeing it double drawn.
    Animator elevation = null;
    if (!fromFab) {
        elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation());
        elevation.setDuration(duration);
        elevation.setInterpolator(fastOutSlowInInterpolator);
    }

    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (elevation != null) {
        transition.play(elevation);
    }
    if (fromFab) {
        transition.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // Clean up
                view.getOverlay().clear();
            }
        });
    }
    return new NoPauseAnimator(transition);
}