public class

ChangeBounds

extends Transition

 java.lang.Object

androidx.transition.Transition

↳androidx.transition.ChangeBounds

Gradle dependencies

compile group: 'androidx.transition', name: 'transition', version: '1.5.1'

  • groupId: androidx.transition
  • artifactId: transition
  • version: 1.5.1

Artifact androidx.transition:transition:1.5.1 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.transition:transition com.android.support:transition

Androidx class mapping:

androidx.transition.ChangeBounds android.support.transition.ChangeBounds

Overview

This transition captures the layout bounds of target views before and after the scene change and animates those changes during the transition.

A ChangeBounds transition can be described in a resource file by using the tag changeBounds, along with the other standard attributes of Transition.

Summary

Fields
from TransitionMATCH_ID, MATCH_INSTANCE, MATCH_ITEM_ID, MATCH_NAME
Constructors
publicChangeBounds()

publicChangeBounds(Context context, AttributeSet attrs)

Methods
public abstract voidcaptureEndValues(TransitionValues transitionValues)

Captures the values in the end scene for the properties that this transition monitors.

public abstract voidcaptureStartValues(TransitionValues transitionValues)

Captures the values in the start scene for the properties that this transition monitors.

public AnimatorcreateAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues)

This method creates an animation that will be run for this transition given the information in the startValues and endValues structures captured earlier for the start and end scenes.

public booleangetResizeClip()

Returns true when the ChangeBounds will resize by changing the clip bounds during the view animation or false when bounds are changed.

public java.lang.StringgetTransitionProperties()

Returns the set of property names used stored in the TransitionValues object passed into Transition.captureStartValues(TransitionValues) that this transition cares about for the purposes of canceling overlapping animations.

public booleanisSeekingSupported()

Returns true if the Transition can be used by TransitionManager.controlDelayedTransition(ViewGroup, Transition).

public voidsetResizeClip(boolean resizeClip)

When resizeClip is true, ChangeBounds resizes the view using the clipBounds instead of changing the dimensions of the view during the animation.

from TransitionaddListener, addTarget, animate, cancel, clone, end, excludeChildren, excludeTarget, getDuration, getEpicenter, getEpicenterCallback, getInterpolator, getName, getPathMotion, getPropagation, getRootTransition, getStartDelay, getTargetIds, getTargetNames, getTargets, getTargetTypes, getTransitionValues, isTransitionRequired, pause, removeListener, removeTarget, resume, runAnimators, setDuration, setEpicenterCallback, setInterpolator, setMatchOrder, setPathMotion, setPropagation, setStartDelay, start, toString
from java.lang.Objectequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructors

public ChangeBounds()

public ChangeBounds(Context context, AttributeSet attrs)

Methods

public boolean isSeekingSupported()

Returns true if the Transition can be used by TransitionManager.controlDelayedTransition(ViewGroup, Transition). This means that any the state must be ready before any Animator returned by Transition.createAnimator(ViewGroup, TransitionValues, TransitionValues) has started and if the Animator has ended, it must be able to restore the state when starting in reverse. If a Transition must know when the entire transition has ended, a Transition.TransitionListener can be added to Transition.getRootTransition() and it can listen for Transition.TransitionListener.onTransitionEnd(Transition).

public java.lang.String getTransitionProperties()

Returns the set of property names used stored in the TransitionValues object passed into Transition.captureStartValues(TransitionValues) that this transition cares about for the purposes of canceling overlapping animations. When any transition is started on a given scene root, all transitions currently running on that same scene root are checked to see whether the properties on which they based their animations agree with the end values of the same properties in the new transition. If the end values are not equal, then the old animation is canceled since the new transition will start a new animation to these new values. If the values are equal, the old animation is allowed to continue and no new animation is started for that transition.

A transition does not need to override this method. However, not doing so will mean that the cancellation logic outlined in the previous paragraph will be skipped for that transition, possibly leading to artifacts as old transitions and new transitions on the same targets run in parallel, animating views toward potentially different end values.

Returns:

An array of property names as described in the class documentation for TransitionValues. The default implementation returns null.

public void setResizeClip(boolean resizeClip)

When resizeClip is true, ChangeBounds resizes the view using the clipBounds instead of changing the dimensions of the view during the animation. When resizeClip is false, ChangeBounds resizes the View by changing its dimensions.

When resizeClip is set to true, the clip bounds is modified by ChangeBounds. Therefore, is not compatible with ChangeBounds in this mode.

Parameters:

resizeClip: Used to indicate whether the view bounds should be modified or the clip bounds should be modified by ChangeBounds.

See also: android.view.View

public boolean getResizeClip()

Returns true when the ChangeBounds will resize by changing the clip bounds during the view animation or false when bounds are changed. The default value is false.

Returns:

true when the ChangeBounds will resize by changing the clip bounds during the view animation or false when bounds are changed. The default value is false.

public abstract void captureStartValues(TransitionValues transitionValues)

Captures the values in the start scene for the properties that this transition monitors. These values are then passed as the startValues structure in a later call to Transition.createAnimator(ViewGroup, TransitionValues, TransitionValues). The main concern for an implementation is what the properties are that the transition cares about and what the values are for all of those properties. The start and end values will be compared later during the Transition.createAnimator(ViewGroup, TransitionValues, TransitionValues) method to determine what, if any, animations, should be run.

Subclasses must implement this method. The method should only be called by the transition system; it is not intended to be called from external classes.

Parameters:

transitionValues: The holder for any values that the Transition wishes to store. Values are stored in the values field of this TransitionValues object and are keyed from a String value. For example, to store a view's rotation value, a transition might call transitionValues.values.put("appname:transitionname:rotation", view.getRotation()). The target view will already be stored in the transitionValues structure when this method is called.

See also: Transition.captureEndValues(TransitionValues), Transition.createAnimator(ViewGroup, TransitionValues, TransitionValues)

public abstract void captureEndValues(TransitionValues transitionValues)

Captures the values in the end scene for the properties that this transition monitors. These values are then passed as the endValues structure in a later call to Transition.createAnimator(ViewGroup, TransitionValues, TransitionValues). The main concern for an implementation is what the properties are that the transition cares about and what the values are for all of those properties. The start and end values will be compared later during the Transition.createAnimator(ViewGroup, TransitionValues, TransitionValues) method to determine what, if any, animations, should be run.

Subclasses must implement this method. The method should only be called by the transition system; it is not intended to be called from external classes.

Parameters:

transitionValues: The holder for any values that the Transition wishes to store. Values are stored in the values field of this TransitionValues object and are keyed from a String value. For example, to store a view's rotation value, a transition might call transitionValues.values.put("appname:transitionname:rotation", view.getRotation()). The target view will already be stored in the transitionValues structure when this method is called.

See also: Transition.captureStartValues(TransitionValues), Transition.createAnimator(ViewGroup, TransitionValues, TransitionValues)

public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues)

This method creates an animation that will be run for this transition given the information in the startValues and endValues structures captured earlier for the start and end scenes. Subclasses of Transition should override this method. The method should only be called by the transition system; it is not intended to be called from external classes.

This method is called by the transition's parent (all the way up to the topmost Transition in the hierarchy) with the sceneRoot and start/end values that the transition may need to set up initial target values and construct an appropriate animation. For example, if an overall Transition is a TransitionSet consisting of several child transitions in sequence, then some of the child transitions may want to set initial values on target views prior to the overall Transition commencing, to put them in an appropriate state for the delay between that start and the child Transition start time. For example, a transition that fades an item in may wish to set the starting alpha value to 0, to avoid it blinking in prior to the transition actually starting the animation. This is necessary because the scene change that triggers the Transition will automatically set the end-scene on all target views, so a Transition that wants to animate from a different value should set that value prior to returning from this method.

Additionally, a Transition can perform logic to determine whether the transition needs to run on the given target and start/end values. For example, a transition that resizes objects on the screen may wish to avoid running for views which are not present in either the start or end scenes.

If there is an animator created and returned from this method, the transition mechanism will apply any applicable duration, startDelay, and interpolator to that animation and start it. A return value of null indicates that no animation should run. The default implementation returns null.

The method is called for every applicable target object, which is stored in the TransitionValues.view field.

Parameters:

sceneRoot: The root of the transition hierarchy.
startValues: The values for a specific target in the start scene.
endValues: The values for the target in the end scene.

Returns:

A Animator to be started at the appropriate time in the overall transition for this scene change. A null value means no animation should be run.

Source

/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.transition;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Property;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.res.TypedArrayUtils;

import java.util.Map;

/**
 * This transition captures the layout bounds of target views before and after
 * the scene change and animates those changes during the transition.
 *
 * <p>A ChangeBounds transition can be described in a resource file by using the
 * tag <code>changeBounds</code>, along with the other standard attributes of Transition.</p>
 */
public class ChangeBounds extends Transition {

    private static final String PROPNAME_BOUNDS = "android:changeBounds:bounds";
    private static final String PROPNAME_CLIP = "android:changeBounds:clip";
    private static final String PROPNAME_PARENT = "android:changeBounds:parent";
    private static final String PROPNAME_WINDOW_X = "android:changeBounds:windowX";
    private static final String PROPNAME_WINDOW_Y = "android:changeBounds:windowY";
    private static final String[] sTransitionProperties = {
            PROPNAME_BOUNDS,
            PROPNAME_CLIP,
            PROPNAME_PARENT,
            PROPNAME_WINDOW_X,
            PROPNAME_WINDOW_Y
    };

    private static final Property<ViewBounds, PointF> TOP_LEFT_PROPERTY =
            new Property<ViewBounds, PointF>(PointF.class, "topLeft") {
                @Override
                public void set(ViewBounds viewBounds, PointF topLeft) {
                    viewBounds.setTopLeft(topLeft);
                }

                @Override
                public PointF get(ViewBounds viewBounds) {
                    return null;
                }
            };

    private static final Property<ViewBounds, PointF> BOTTOM_RIGHT_PROPERTY =
            new Property<ViewBounds, PointF>(PointF.class, "bottomRight") {
                @Override
                public void set(ViewBounds viewBounds, PointF bottomRight) {
                    viewBounds.setBottomRight(bottomRight);
                }

                @Override
                public PointF get(ViewBounds viewBounds) {
                    return null;
                }
            };

    private static final Property<View, PointF> BOTTOM_RIGHT_ONLY_PROPERTY =
            new Property<View, PointF>(PointF.class, "bottomRight") {
                @Override
                public void set(View view, PointF bottomRight) {
                    int left = view.getLeft();
                    int top = view.getTop();
                    int right = Math.round(bottomRight.x);
                    int bottom = Math.round(bottomRight.y);
                    ViewUtils.setLeftTopRightBottom(view, left, top, right, bottom);
                }

                @Override
                public PointF get(View view) {
                    return null;
                }
            };

    private static final Property<View, PointF> TOP_LEFT_ONLY_PROPERTY =
            new Property<View, PointF>(PointF.class, "topLeft") {
                @Override
                public void set(View view, PointF topLeft) {
                    int left = Math.round(topLeft.x);
                    int top = Math.round(topLeft.y);
                    int right = view.getRight();
                    int bottom = view.getBottom();
                    ViewUtils.setLeftTopRightBottom(view, left, top, right, bottom);
                }

                @Override
                public PointF get(View view) {
                    return null;
                }
            };

    private static final Property<View, PointF> POSITION_PROPERTY =
            new Property<View, PointF>(PointF.class, "position") {
                @Override
                public void set(View view, PointF topLeft) {
                    int left = Math.round(topLeft.x);
                    int top = Math.round(topLeft.y);
                    int right = left + view.getWidth();
                    int bottom = top + view.getHeight();
                    ViewUtils.setLeftTopRightBottom(view, left, top, right, bottom);
                }

                @Override
                public PointF get(View view) {
                    return null;
                }
            };

    private boolean mResizeClip = false;

    private static final RectEvaluator sRectEvaluator = new RectEvaluator();

    public ChangeBounds() {
    }

    public ChangeBounds(@NonNull Context context, @NonNull AttributeSet attrs) {
        super(context, attrs);

        TypedArray a = context.obtainStyledAttributes(attrs, Styleable.CHANGE_BOUNDS);
        boolean resizeClip = TypedArrayUtils.getNamedBoolean(a, (XmlResourceParser) attrs,
                "resizeClip", Styleable.ChangeBounds.RESIZE_CLIP, false);
        a.recycle();
        setResizeClip(resizeClip);
    }

    @Override
    public boolean isSeekingSupported() {
        return true;
    }

    @NonNull
    @Override
    public String[] getTransitionProperties() {
        return sTransitionProperties;
    }

    /**
     * When <code>resizeClip</code> is true, ChangeBounds resizes the view using the clipBounds
     * instead of changing the dimensions of the view during the animation. When
     * <code>resizeClip</code> is false, ChangeBounds resizes the View by changing its dimensions.
     *
     * <p>When resizeClip is set to true, the clip bounds is modified by ChangeBounds. Therefore,
     * {@link android.transition.ChangeClipBounds} is not compatible with ChangeBounds
     * in this mode.</p>
     *
     * @param resizeClip Used to indicate whether the view bounds should be modified or the
     *                   clip bounds should be modified by ChangeBounds.
     * @see android.view.View#setClipBounds(android.graphics.Rect)
     */
    public void setResizeClip(boolean resizeClip) {
        mResizeClip = resizeClip;
    }

    /**
     * Returns true when the ChangeBounds will resize by changing the clip bounds during the
     * view animation or false when bounds are changed. The default value is false.
     *
     * @return true when the ChangeBounds will resize by changing the clip bounds during the
     * view animation or false when bounds are changed. The default value is false.
     */
    public boolean getResizeClip() {
        return mResizeClip;
    }

    private void captureValues(TransitionValues values) {
        View view = values.view;

        if (view.isLaidOut() || view.getWidth() != 0 || view.getHeight() != 0) {
            values.values.put(PROPNAME_BOUNDS, new Rect(view.getLeft(), view.getTop(),
                    view.getRight(), view.getBottom()));
            values.values.put(PROPNAME_PARENT, values.view.getParent());
            if (mResizeClip) {
                values.values.put(PROPNAME_CLIP, view.getClipBounds());
            }
        }
    }

    @Override
    public void captureStartValues(@NonNull TransitionValues transitionValues) {
        captureValues(transitionValues);
        if (mResizeClip) {
            Rect clipSize =
                    (Rect) transitionValues.view.getTag(R.id.transition_clip);
            if (clipSize != null) {
                transitionValues.values.put(PROPNAME_CLIP, clipSize);
            }
        }
    }

    @Override
    public void captureEndValues(@NonNull TransitionValues transitionValues) {
        captureValues(transitionValues);
    }

    @Override
    @Nullable
    public Animator createAnimator(@NonNull final ViewGroup sceneRoot,
            @Nullable TransitionValues startValues, @Nullable TransitionValues endValues) {
        if (startValues == null || endValues == null) {
            return null;
        }
        Map<String, Object> startParentVals = startValues.values;
        Map<String, Object> endParentVals = endValues.values;
        ViewGroup startParent = (ViewGroup) startParentVals.get(PROPNAME_PARENT);
        ViewGroup endParent = (ViewGroup) endParentVals.get(PROPNAME_PARENT);
        if (startParent == null || endParent == null) {
            return null;
        }
        final View view = endValues.view;
        Rect startBounds = (Rect) startValues.values.get(PROPNAME_BOUNDS);
        Rect endBounds = (Rect) endValues.values.get(PROPNAME_BOUNDS);
        final int startLeft = startBounds.left;
        final int endLeft = endBounds.left;
        final int startTop = startBounds.top;
        final int endTop = endBounds.top;
        final int startRight = startBounds.right;
        final int endRight = endBounds.right;
        final int startBottom = startBounds.bottom;
        final int endBottom = endBounds.bottom;
        final int startWidth = startRight - startLeft;
        final int startHeight = startBottom - startTop;
        final int endWidth = endRight - endLeft;
        final int endHeight = endBottom - endTop;
        Rect startClip = (Rect) startValues.values.get(PROPNAME_CLIP);
        Rect endClip = (Rect) endValues.values.get(PROPNAME_CLIP);
        int numChanges = 0;
        if ((startWidth != 0 && startHeight != 0) || (endWidth != 0 && endHeight != 0)) {
            if (startLeft != endLeft || startTop != endTop) ++numChanges;
            if (startRight != endRight || startBottom != endBottom) ++numChanges;
        }
        if ((startClip != null && !startClip.equals(endClip))
                || (startClip == null && endClip != null)) {
            ++numChanges;
        }
        if (numChanges > 0) {
            Animator anim;
            if (!mResizeClip) {
                ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startRight,
                        startBottom);
                if (numChanges == 2) {
                    if (startWidth == endWidth && startHeight == endHeight) {
                        Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft,
                                endTop);
                        anim = ObjectAnimatorUtils.ofPointF(view, POSITION_PROPERTY,
                                topLeftPath);
                    } else {
                        final ViewBounds viewBounds = new ViewBounds(view);
                        Path topLeftPath = getPathMotion().getPath(startLeft, startTop,
                                endLeft, endTop);
                        ObjectAnimator topLeftAnimator = ObjectAnimatorUtils
                                .ofPointF(viewBounds, TOP_LEFT_PROPERTY, topLeftPath);

                        Path bottomRightPath = getPathMotion().getPath(startRight, startBottom,
                                endRight, endBottom);
                        ObjectAnimator bottomRightAnimator = ObjectAnimatorUtils.ofPointF(
                                viewBounds, BOTTOM_RIGHT_PROPERTY, bottomRightPath);
                        AnimatorSet set = new AnimatorSet();
                        set.playTogether(topLeftAnimator, bottomRightAnimator);
                        anim = set;
                        set.addListener(new AnimatorListenerAdapter() {
                            // We need a strong reference to viewBounds until the
                            // animator ends (The ObjectAnimator holds only a weak reference).
                            @SuppressWarnings("unused")
                            private final ViewBounds mViewBounds = viewBounds;
                        });
                    }
                } else if (startLeft != endLeft || startTop != endTop) {
                    Path topLeftPath = getPathMotion().getPath(startLeft, startTop,
                            endLeft, endTop);
                    anim = ObjectAnimatorUtils.ofPointF(view, TOP_LEFT_ONLY_PROPERTY,
                            topLeftPath);
                } else {
                    Path bottomRight = getPathMotion().getPath(startRight, startBottom,
                            endRight, endBottom);
                    anim = ObjectAnimatorUtils.ofPointF(view, BOTTOM_RIGHT_ONLY_PROPERTY,
                            bottomRight);
                }
            } else {
                int maxWidth = Math.max(startWidth, endWidth);
                int maxHeight = Math.max(startHeight, endHeight);

                ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startLeft + maxWidth,
                        startTop + maxHeight);

                ObjectAnimator positionAnimator = null;
                if (startLeft != endLeft || startTop != endTop) {
                    Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft,
                            endTop);
                    positionAnimator = ObjectAnimatorUtils.ofPointF(view, POSITION_PROPERTY,
                            topLeftPath);
                }
                boolean startClipIsNull = startClip == null;
                if (startClipIsNull) {
                    startClip = new Rect(0, 0, startWidth, startHeight);
                }
                boolean endClipIsNull = endClip == null;
                if (endClipIsNull) {
                    endClip = new Rect(0, 0, endWidth, endHeight);
                }
                ObjectAnimator clipAnimator = null;
                if (!startClip.equals(endClip)) {
                    view.setClipBounds(startClip);
                    clipAnimator = ObjectAnimator.ofObject(view, "clipBounds", sRectEvaluator,
                            startClip, endClip);
                    ClipListener listener = new ClipListener(view,
                            startClip, startClipIsNull, endClip, endClipIsNull,
                            startLeft, startTop, startRight, startBottom,
                            endLeft, endTop, endRight, endBottom
                    );
                    clipAnimator.addListener(listener);
                    addListener(listener);
                }
                anim = TransitionUtils.mergeAnimators(positionAnimator,
                        clipAnimator);
            }
            if (view.getParent() instanceof ViewGroup) {
                final ViewGroup parent = (ViewGroup) view.getParent();
                ViewGroupUtils.suppressLayout(parent, true);
                getRootTransition().addListener(new SuppressLayoutListener(parent));
            }
            return anim;
        }
        return null;
    }

    private static class ViewBounds {

        private int mLeft;
        private int mTop;
        private int mRight;
        private int mBottom;
        private final View mView;
        private int mTopLeftCalls;
        private int mBottomRightCalls;

        ViewBounds(View view) {
            mView = view;
        }

        void setTopLeft(PointF topLeft) {
            mLeft = Math.round(topLeft.x);
            mTop = Math.round(topLeft.y);
            mTopLeftCalls++;
            if (mTopLeftCalls == mBottomRightCalls) {
                setLeftTopRightBottom();
            }
        }

        void setBottomRight(PointF bottomRight) {
            mRight = Math.round(bottomRight.x);
            mBottom = Math.round(bottomRight.y);
            mBottomRightCalls++;
            if (mTopLeftCalls == mBottomRightCalls) {
                setLeftTopRightBottom();
            }
        }

        private void setLeftTopRightBottom() {
            ViewUtils.setLeftTopRightBottom(mView, mLeft, mTop, mRight, mBottom);
            mTopLeftCalls = 0;
            mBottomRightCalls = 0;
        }
    }

    private static class ClipListener
            extends AnimatorListenerAdapter implements TransitionListener {
        private final View mView;
        private final Rect mStartClip;
        private final boolean mStartClipIsNull;
        private final Rect mEndClip;
        private final boolean mEndClipIsNull;
        private final int mStartLeft, mStartTop, mStartRight, mStartBottom;
        private final int mEndLeft, mEndTop, mEndRight, mEndBottom;

        private boolean mIsCanceled;

        ClipListener(View view,
                Rect startClip,
                boolean startClipIsNull,
                Rect endClip,
                boolean endClipIsNull,
                int startLeft,
                int startTop,
                int startRight,
                int startBottom,
                int endLeft,
                int endTop,
                int endRight,
                int endBottom
        ) {
            mView = view;
            mStartClip = startClip;
            mStartClipIsNull = startClipIsNull;
            mEndClip = endClip;
            mEndClipIsNull = endClipIsNull;
            mStartLeft = startLeft;
            mStartTop = startTop;
            mStartRight = startRight;
            mStartBottom = startBottom;
            mEndLeft = endLeft;
            mEndTop = endTop;
            mEndRight = endRight;
            mEndBottom = endBottom;
        }

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

        @Override
        public void onAnimationEnd(Animator animation) {
            onAnimationEnd(animation, false);
        }

        @Override
        public void onAnimationStart(Animator animation, boolean isReverse) {
            int maxWidth = Math.max(mStartRight - mStartLeft, mEndRight - mEndLeft);
            int maxHeight = Math.max(mStartBottom - mStartTop, mEndBottom - mEndTop);

            int left = isReverse ? mEndLeft : mStartLeft;
            int top = isReverse ? mEndTop : mStartTop;
            ViewUtils.setLeftTopRightBottom(mView, left, top, left + maxWidth, top + maxHeight);

            Rect clip = isReverse ? mEndClip : mStartClip;
            mView.setClipBounds(clip);
        }

        @Override
        public void onAnimationEnd(Animator animation, boolean isReverse) {
            if (mIsCanceled) {
                return;
            }
            Rect clip = isReverse
                    ? (mStartClipIsNull ? null : mStartClip)
                    : (mEndClipIsNull ? null : mEndClip);
            mView.setClipBounds(clip);
            if (isReverse) {
                ViewUtils.setLeftTopRightBottom(mView, mStartLeft, mStartTop, mStartRight,
                        mStartBottom);
            } else {
                ViewUtils.setLeftTopRightBottom(mView, mEndLeft, mEndTop, mEndRight, mEndBottom);
            }
        }

        @Override
        public void onTransitionCancel(@NonNull Transition transition) {
            mIsCanceled = true;
        }

        @Override
        public void onTransitionPause(@NonNull Transition transition) {
            Rect pauseClip = mView.getClipBounds();
            mView.setTag(R.id.transition_clip, pauseClip);
            Rect clip = mEndClipIsNull ? null : mEndClip;
            mView.setClipBounds(clip);
        }

        @Override
        public void onTransitionResume(@NonNull Transition transition) {
            Rect pauseClip = (Rect) mView.getTag(R.id.transition_clip);
            mView.setTag(R.id.transition_clip, null);
            mView.setClipBounds(pauseClip);
        }

        @Override
        public void onTransitionStart(@NonNull Transition transition) {
        }

        @Override
        public void onTransitionEnd(@NonNull Transition transition) {
        }
    }

    private static class SuppressLayoutListener extends TransitionListenerAdapter {
        boolean mCanceled = false;

        final ViewGroup mParent;

        SuppressLayoutListener(@NonNull ViewGroup parent) {
            mParent = parent;
        }

        @Override
        public void onTransitionCancel(@NonNull Transition transition) {
            ViewGroupUtils.suppressLayout(mParent, false);
            mCanceled = true;
        }

        @Override
        public void onTransitionEnd(@NonNull Transition transition) {
            if (!mCanceled) {
                ViewGroupUtils.suppressLayout(mParent, false);
            }
            transition.removeListener(this);
        }

        @Override
        public void onTransitionPause(@NonNull Transition transition) {
            ViewGroupUtils.suppressLayout(mParent, false);
        }

        @Override
        public void onTransitionResume(@NonNull Transition transition) {
            ViewGroupUtils.suppressLayout(mParent, true);
        }
    }
}