Example usage for android.animation AnimatorListenerAdapter AnimatorListenerAdapter

List of usage examples for android.animation AnimatorListenerAdapter AnimatorListenerAdapter

Introduction

In this page you can find the example usage for android.animation AnimatorListenerAdapter AnimatorListenerAdapter.

Prototype

AnimatorListenerAdapter

Source Link

Usage

From source file:com.android.launcher3.Folder.java

public void animateOpen() {
    if (!(getParent() instanceof DragLayer))
        return;/*from   w w  w.  j  av  a 2s  .com*/

    Animator openFolderAnim = null;
    final Runnable onCompleteRunnable;
    if (!Utilities.isLmpOrAbove()) {
        positionAndSizeAsIcon();
        centerAboutIcon();

        PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
        PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
        PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
        final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
        oa.setDuration(mExpandDuration);
        openFolderAnim = oa;

        setLayerType(LAYER_TYPE_HARDWARE, null);
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                setLayerType(LAYER_TYPE_NONE, null);
            }
        };
    } else {
        prepareReveal();
        centerAboutIcon();

        int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
        int height = getFolderHeight();

        float transX = -0.075f * (width / 2 - getPivotX());
        float transY = -0.075f * (height / 2 - getPivotY());
        setTranslationX(transX);
        setTranslationY(transY);
        PropertyValuesHolder tx = PropertyValuesHolder.ofFloat("translationX", transX, 0);
        PropertyValuesHolder ty = PropertyValuesHolder.ofFloat("translationY", transY, 0);

        int rx = (int) Math.max(Math.max(width - getPivotX(), 0), getPivotX());
        int ry = (int) Math.max(Math.max(height - getPivotY(), 0), getPivotY());
        float radius = (float) Math.sqrt(rx * rx + ry * ry);
        AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
        Animator reveal = LauncherAnimUtils.createCircularReveal(this, (int) getPivotX(), (int) getPivotY(), 0,
                radius);
        reveal.setDuration(mMaterialExpandDuration);
        reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));

        mContent.setAlpha(0f);
        Animator iconsAlpha = LauncherAnimUtils.ofFloat(mContent, "alpha", 0f, 1f);
        iconsAlpha.setDuration(mMaterialExpandDuration);
        iconsAlpha.setStartDelay(mMaterialExpandStagger);
        iconsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));

        mFolderName.setAlpha(0f);
        Animator textAlpha = LauncherAnimUtils.ofFloat(mFolderName, "alpha", 0f, 1f);
        textAlpha.setDuration(mMaterialExpandDuration);
        textAlpha.setStartDelay(mMaterialExpandStagger);
        textAlpha.setInterpolator(new AccelerateInterpolator(1.5f));

        Animator drift = LauncherAnimUtils.ofPropertyValuesHolder(this, tx, ty);
        drift.setDuration(mMaterialExpandDuration);
        drift.setStartDelay(mMaterialExpandStagger);
        drift.setInterpolator(new LogDecelerateInterpolator(60, 0));

        anim.play(drift);
        anim.play(iconsAlpha);
        anim.play(textAlpha);
        anim.play(reveal);

        openFolderAnim = anim;

        mContent.setLayerType(LAYER_TYPE_HARDWARE, null);
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                mContent.setLayerType(LAYER_TYPE_NONE, null);
            }
        };
    }
    openFolderAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                    String.format(getContext().getString(R.string.folder_opened), mContent.getCountX(),
                            mContent.getCountY()));
            mState = STATE_ANIMATING;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = STATE_OPEN;

            if (onCompleteRunnable != null) {
                onCompleteRunnable.run();
            }

            setFocusOnFirstChild();
        }
    });
    openFolderAnim.start();

    // Make sure the folder picks up the last drag move even if the finger doesn't move.
    if (mDragController.isDragging()) {
        mDragController.forceTouchMove();
    }
}

From source file:com.example.mego.adas.directions.ui.DirectionsFragment.java

/**
 * method to hide edit text with animation
 *///w  ww . j av  a 2 s.c  o m
private void hideEditText(final LinearLayout view) {
    int cx = view.getRight() - 30;
    int cy = view.getBottom() - 60;
    int initialRadius = view.getWidth();
    Animator anim = null;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0);
    }
    if (anim != null) {
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.INVISIBLE);
            }
        });
    }
    isEditTextVisible = false;
    if (anim != null) {
        anim.start();
    }
}

From source file:com.mark.quick.ui.view.snackbar.BaseTransientBottomBar.java

private void animateViewOut(final int event) {
    if (Build.VERSION.SDK_INT >= 12) {
        //TODO CHANGE 0
        mView.setTranslationY(0);/*from   w  w  w .j  a  v a2s .  com*/
        final ValueAnimator animator = new ValueAnimator();
        //TODO CHANGE ?
        animator.setIntValues(0, -mView.getHeight());
        animator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                mContentViewCallback.animateContentOut(0, ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                onViewHidden(event);
            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            private int mPreviousAnimatedIntValue = 0;

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int currentAnimatedIntValue = (int) animator.getAnimatedValue();
                if (USE_OFFSET_API) {
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue);
                } else {
                    mView.setTranslationY(currentAnimatedIntValue);
                }
                mPreviousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = android.view.animation.AnimationUtils.loadAnimation(mView.getContext(),
                R.anim.design_snackbar_out);
        anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewHidden(event);
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

From source file:com.amaze.filemanager.ui.views.Indicator.java

private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) {

    // create the actual move animator
    ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo);

    // also set up a pending retreat anim  this starts when the move is 75% complete
    retreatAnimation = new PendingRetreatAnimator(was, now, steps,
            now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f))
                    : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f)));
    retreatAnimation.addListener(new AnimatorListenerAdapter() {
        @Override//from  www. java 2 s  .co  m
        public void onAnimationEnd(Animator animation) {
            resetState();
            pageChanging = false;
        }
    });
    moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            // todo avoid autoboxing
            selectedDotX = (Float) valueAnimator.getAnimatedValue();
            retreatAnimation.startIfNecessary(selectedDotX);
            postInvalidateOnAnimation();
        }
    });
    moveSelected.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            // set a flag so that we continue to draw the unselected dot in the target position
            // until the selected dot has finished moving into place
            selectedDotInPosition = false;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // set a flag when anim finishes so that we don't draw both selected & unselected
            // page dots
            selectedDotInPosition = true;
        }
    });
    // slightly delay the start to give the joins a chance to run
    // unless dot isn't in position yet  then don't delay!
    moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4l : 0l);
    moveSelected.setDuration(animDuration * 3l / 4l);
    moveSelected.setInterpolator(interpolator);
    return moveSelected;
}

From source file:com.amaze.carbonfilemanager.ui.views.Indicator.java

private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) {

    // create the actual move animator
    ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo);

    // also set up a pending retreat anim  this starts when the move is 75% complete
    retreatAnimation = new PendingRetreatAnimator(was, now, steps,
            now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f))
                    : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f)));
    retreatAnimation.addListener(new AnimatorListenerAdapter() {
        @Override//from   w  w w.j  av a  2  s  . co m
        public void onAnimationEnd(Animator animation) {
            resetState();
            pageChanging = false;
        }
    });
    moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            // todo avoid autoboxing
            selectedDotX = (Float) valueAnimator.getAnimatedValue();
            retreatAnimation.startIfNecessary(selectedDotX);
            postInvalidateOnAnimation();
        }
    });
    moveSelected.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            // set a flag so that we continue to draw the unselected dot in the target position
            // until the selected dot has finished moving into place
            selectedDotInPosition = false;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // set a flag when anim finishes so that we don't draw both selected & unselected
            // page dots
            selectedDotInPosition = true;
        }
    });
    // slightly delay the start to give the joins a chance to run
    // unless dot isn't in position yet  then don't delay!
    moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4L : 0L);
    moveSelected.setDuration(animDuration * 3L / 4L);
    moveSelected.setInterpolator(interpolator);
    return moveSelected;
}

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Anim the alert and the main view accordingly
 *
 * @param alertView         View Resources to animate
 * @param mainView          ViewGroup resources
 * @param configuration     describes all device configuration information
 * @param translationYAlert Move alert panel to be displayed
 * @param translationYMain  Move main windows screen
 * @param animIn            true animate panel to be displayed else animate panel to hide
 * @return Animated views/*w  ww.ja v  a  2 s .  com*/
 */
private static ViewPropertyAnimator animViews(View alertView, final ViewGroup mainView,
        final Configuration configuration, int translationYAlert, int translationYMain, final boolean animIn) {
    long duration = animIn ? DURATION_IN : DURATION_OUT;
    ViewPropertyAnimator viewPropertyAnimator = null;

    if (configuration.isWithAnim()) {
        viewPropertyAnimator = alertView.animate().translationY(translationYAlert).setDuration(duration);

        if (configuration.isShiftContent()) {
            final View viewToResize = mainView.getChildAt(0);

            // Resizing the view after the animation only alert is not on screen otherwise keep size
            viewToResize.animate().translationY(translationYMain).setDuration(duration)
                    .setListener(new AnimatorListenerAdapter() {

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            resizeViewHeight(viewToResize, configuration.getHeight(), !animIn,
                                    mainView.getHeight());
                        }
                    });
        }
    } else {
        alertView.setTranslationY(translationYAlert);

        if (configuration.isShiftContent()) {
            final View viewToResize = mainView.getChildAt(0);
            viewToResize.setTranslationY(translationYMain);

            // Resizing the view
            resizeViewHeight(viewToResize, configuration.getHeight(), !animIn, mainView.getHeight());
        }
    }

    return viewPropertyAnimator;
}

From source file:com.fairphone.fplauncher3.Folder.java

public void animateOpen() {
    if (!(getParent() instanceof DragLayer)) {
        return;//from   www  . j a v  a2 s . c  om
    }

    Animator openFolderAnim;
    final Runnable onCompleteRunnable;
    if (!Utilities.isLmpOrAbove()) {
        positionAndSizeAsIcon();
        centerAboutIcon();

        PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1f);
        PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
        PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
        final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
        oa.setDuration(mExpandDuration);
        openFolderAnim = oa;

        setLayerType(LAYER_TYPE_HARDWARE, null);
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                setLayerType(LAYER_TYPE_NONE, null);
            }
        };
    } else {
        prepareReveal();
        centerAboutIcon();

        int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
        int height = getFolderHeight();

        float transX = -0.075f * (width / 2 - getPivotX());
        float transY = -0.075f * (height / 2 - getPivotY());
        final float endTransX = 0;
        final float endTransY = 0;

        setTranslationX(transX);
        setTranslationY(transY);
        PropertyValuesHolder tx = PropertyValuesHolder.ofFloat("translationX", transX, endTransX);
        PropertyValuesHolder ty = PropertyValuesHolder.ofFloat("translationY", transY, endTransY);

        int rx = (int) Math.max(Math.max(width - getPivotX(), 0), getPivotX());
        int ry = (int) Math.max(Math.max(height - getPivotY(), 0), getPivotY());
        float radius = (float) Math.sqrt(rx * rx + ry * ry);
        AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
        Animator reveal = LauncherAnimUtils.createCircularReveal(this, (int) getPivotX(), (int) getPivotY(), 0,
                radius);
        reveal.setDuration(mMaterialExpandDuration);
        reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));

        View[] alphaViewSet = new View[] { mContent, mFolderName };
        for (View view : alphaViewSet) {
            Animator alphaAnimator = setupAlphaAnimator(view, 0f, 1f, mMaterialExpandDuration,
                    mMaterialExpandStagger);
            anim.play(alphaAnimator);
        }

        /* mContent.setAlpha(0f);
         Animator iconsAlpha = LauncherAnimUtils.ofFloat(mContent, "alpha", 0f, 1f);
         iconsAlpha.setDuration(mMaterialExpandDuration);
         iconsAlpha.setStartDelay(mMaterialExpandStagger);
         iconsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
                
         mFolderName.setAlpha(0f);
         Animator textAlpha = LauncherAnimUtils.ofFloat(mFolderName, "alpha", 0f, 1f);
         textAlpha.setDuration(mMaterialExpandDuration);
         textAlpha.setStartDelay(mMaterialExpandStagger);
         textAlpha.setInterpolator(new AccelerateInterpolator(1.5f));*/

        Animator drift = LauncherAnimUtils.ofPropertyValuesHolder(this, tx, ty);
        drift.setDuration(mMaterialExpandDuration);
        drift.setStartDelay(mMaterialExpandStagger);
        drift.setInterpolator(new LogDecelerateInterpolator(60, 0));
        drift.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // in low power mode the animation doesn't play, so set the end value here
                Folder.this.setTranslationX(endTransX);
                Folder.this.setTranslationY(endTransY);
            }
        });

        anim.play(drift);
        /* anim.play(iconsAlpha);
         anim.play(textAlpha);*/
        anim.play(reveal);

        openFolderAnim = anim;

        mContent.setLayerType(LAYER_TYPE_HARDWARE, null);
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                mContent.setLayerType(LAYER_TYPE_NONE, null);
            }
        };
    }
    openFolderAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                    String.format(getContext().getString(R.string.folder_opened), mContent.getCountX(),
                            mContent.getCountY()));
            mState = STATE_ANIMATING;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = STATE_OPEN;

            if (onCompleteRunnable != null) {
                onCompleteRunnable.run();
            }

            setFocusOnFirstChild();
        }
    });
    openFolderAnim.start();

    // Make sure the folder picks up the last drag move even if the finger doesn't move.
    if (mDragController.isDragging()) {
        mDragController.forceTouchMove();
    }
}

From source file:com.github.shareme.gwsinkpageindicator.library.InkPageIndicator.java

private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) {

    // create the actual move animator
    ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo);

    // also set up a pending retreat anim  this starts when the move is 75% complete
    retreatAnimation = new PendingRetreatAnimator(was, now, steps,
            now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f))
                    : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f)));
    retreatAnimation.addListener(new AnimatorListenerAdapter() {
        @Override/*w w w  .  j  a  v a  2  s  .com*/
        public void onAnimationEnd(Animator animation) {
            resetState();
            pageChanging = false;
        }
    });
    moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            // todo avoid autoboxing
            selectedDotX = (Float) valueAnimator.getAnimatedValue();
            retreatAnimation.startIfNecessary(selectedDotX);
            postInvalidateOnAnimation();
        }
    });
    moveSelected.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            // set a flag so that we continue to draw the unselected dot in the target position
            // until the selected dot has finished moving into place
            selectedDotInPosition = false;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // set a flag when anim finishes so that we don't draw both selected & unselected
            // page dots
            selectedDotInPosition = true;
        }
    });
    // slightly delay the start to give the joins a chance to run
    // unless dot isn't in position yet  then don't delay!
    moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4l : 0l);
    moveSelected.setDuration(animDuration * 3l / 4l);
    moveSelected.setInterpolator(interpolator);
    return moveSelected;
}

From source file:com.android.deskclock.alarms.AlarmActivity.java

private ValueAnimator getAlarmBounceAnimator(float translationX, final int hintResId) {
    final ValueAnimator bounceAnimator = ObjectAnimator.ofFloat(mAlarmButton, View.TRANSLATION_X,
            mAlarmButton.getTranslationX(), translationX, 0.0f);
    bounceAnimator.setInterpolator(AnimatorUtils.DECELERATE_ACCELERATE_INTERPOLATOR);
    bounceAnimator.setDuration(ALARM_BOUNCE_DURATION_MILLIS);
    bounceAnimator.addListener(new AnimatorListenerAdapter() {
        @Override/*from   w  w  w  .jav a2  s  .co  m*/
        public void onAnimationStart(Animator animator) {
            mHintView.setText(hintResId);
            if (mHintView.getVisibility() != View.VISIBLE) {
                mHintView.setVisibility(View.VISIBLE);
                ObjectAnimator.ofFloat(mHintView, View.ALPHA, 0.0f, 1.0f).start();
            }
        }
    });
    return bounceAnimator;
}

From source file:com.modprobe.profit.ExpandingListView.java

/**
 * This method collapses the view that was clicked and animates all the views
 * around it to close around the collapsing view. There are several steps required
 * to do this which are outlined below.//from   w  w  w . j  a  v a2s.  co m
 *
 * 1. Update the layout parameters of the view clicked so as to minimize its height
 *    to the original collapsed (default) state.
 * 2. After invoking a layout, the listview will shift all the cells so as to display
 *    them most efficiently. Therefore, during the first predraw pass, the listview
 *    must be offset by some amount such that given the custom bound change upon
 *    collapse, all the cells that need to be on the screen after the layout
 *    are rendered by the listview.
 * 3. On the second predraw pass, all the items are first returned to their original
 *    location (before the first layout).
 * 4. The collapsing view's bounds are animated to what the final values should be.
 * 5. The bounds above the collapsing view are animated downwards while the bounds
 *    below the collapsing view are animated upwards.
 * 6. The extra text is faded out as its contents become visible throughout the
 *    animation process.
 */

private void collapseView(final View view) {
    final SuggestionExpandingListViewItem viewObject = (SuggestionExpandingListViewItem) getItemAtPosition(
            getPositionForView(view));

    /* Store the original top and bottom bounds of all the cells.*/
    final int oldTop = view.getTop();
    final int oldBottom = view.getBottom();

    final HashMap<View, int[]> oldCoordinates = new HashMap<View, int[]>();

    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View v = getChildAt(i);
        ViewCompat.setHasTransientState(v, true);
        oldCoordinates.put(v, new int[] { v.getTop(), v.getBottom() });
    }

    /* Update the layout so the extra content becomes invisible.*/
    view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
            viewObject.getCollapsedHeight()));

    /* Add an onPreDraw listener. */
    final ViewTreeObserver observer = getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {

            if (!mShouldRemoveObserver) {
                /*Same as for expandingView, the parameters for setSelectionFromTop must
                * be determined such that the necessary cells of the ListView are rendered
                * and added to it.*/
                mShouldRemoveObserver = true;

                int newTop = view.getTop();
                int newBottom = view.getBottom();

                int newHeight = newBottom - newTop;
                int oldHeight = oldBottom - oldTop;
                int deltaHeight = oldHeight - newHeight;

                mTranslate = getTopAndBottomTranslations(oldTop, oldBottom, deltaHeight, false);

                int currentTop = view.getTop();
                int futureTop = oldTop + mTranslate[0];

                int firstChildStartTop = getChildAt(0).getTop();
                int firstVisiblePosition = getFirstVisiblePosition();
                int deltaTop = currentTop - futureTop;

                int i;
                int childCount = getChildCount();
                for (i = 0; i < childCount; i++) {
                    View v = getChildAt(i);
                    int height = v.getBottom() - Math.max(0, v.getTop());
                    if (deltaTop - height > 0) {
                        firstVisiblePosition++;
                        deltaTop -= height;
                    } else {
                        break;
                    }
                }

                if (i > 0) {
                    firstChildStartTop = 0;
                }

                setSelectionFromTop(firstVisiblePosition, firstChildStartTop - deltaTop);

                requestLayout();

                return false;
            }

            mShouldRemoveObserver = false;
            observer.removeOnPreDrawListener(this);

            int yTranslateTop = mTranslate[0];
            int yTranslateBottom = mTranslate[1];

            int index = indexOfChild(view);
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                View v = getChildAt(i);
                int[] old = oldCoordinates.get(v);
                if (old != null) {
                    /* If the cell was present in the ListView before the collapse and
                    * after the collapse then the bounds are reset to their old values.*/
                    v.setTop(old[0]);
                    v.setBottom(old[1]);
                    ViewCompat.setHasTransientState(v, false);
                } else {
                    /* If the cell is present in the ListView after the collapse but
                     * not before the collapse then the bounds are calculated using
                     * the bottom and top translation of the collapsing cell.*/
                    int delta = i > index ? yTranslateBottom : -yTranslateTop;
                    v.setTop(v.getTop() + delta);
                    v.setBottom(v.getBottom() + delta);
                }
            }

            final View expandingLayout = view.findViewById(R.id.expanding_layout);

            /* Animates all the cells present on the screen after the collapse. */
            ArrayList<Animator> animations = new ArrayList<Animator>();
            for (int i = 0; i < childCount; i++) {
                View v = getChildAt(i);
                if (v != view) {
                    float diff = i > index ? -yTranslateBottom : yTranslateTop;
                    animations.add(getAnimation(v, diff, diff));
                }
            }

            /* Adds animation for collapsing the cell that was clicked. */
            animations.add(getAnimation(view, yTranslateTop, -yTranslateBottom));

            /* Adds an animation for fading out the extra content. */
            animations.add(ObjectAnimator.ofFloat(expandingLayout, View.ALPHA, 1, 0));

            /* Disabled the ListView for the duration of the animation.*/
            setEnabled(false);
            setClickable(false);

            /* Play all the animations created above together at the same time. */
            AnimatorSet s = new AnimatorSet();
            s.playTogether(animations);
            s.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    expandingLayout.setVisibility(View.GONE);
                    view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
                            AbsListView.LayoutParams.WRAP_CONTENT));
                    viewObject.setExpanded(false);
                    setEnabled(true);
                    setClickable(true);
                    /* Note that alpha must be set back to 1 in case this view is reused
                    * by a cell that was expanded, but not yet collapsed, so its state
                    * should persist in an expanded state with the extra content visible.*/
                    expandingLayout.setAlpha(1);
                }
            });
            s.start();

            return true;
        }
    });
}