Example usage for android.animation ValueAnimator addUpdateListener

List of usage examples for android.animation ValueAnimator addUpdateListener

Introduction

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

Prototype

public void addUpdateListener(AnimatorUpdateListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent update events through the life of an animation.

Usage

From source file:io.jawg.osmcontributor.ui.fragments.MapFragment.java

@Subscribe(threadMode = ThreadMode.MAIN)
public void onPleaseChangePoiPosition(PleaseChangePoiPosition event) {
    Timber.d("Received event PleaseChangePoiPosition");
    if (configManager.hasPoiModification()) {
        switchMode(MapMode.POI_POSITION_EDITION);
        creationPin.setVisibility(View.GONE);

        ValueAnimator valueAnimator = ValueAnimator.ofFloat(0,
                OsmAnimatorUpdateListener.STEPS_CENTER_ANIMATION);
        valueAnimator.setDuration(900);//from w  w w .j  av a 2s .c  om
        valueAnimator.addUpdateListener(new OsmAnimatorUpdateListener(mapboxMap.getCameraPosition().target,
                markerSelected.getPosition(), mapboxMap));

        valueAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                creationPin.setVisibility(View.VISIBLE);
                hideMarker(markerSelected);
            }
        });
        valueAnimator.start();
    } else {
        Toast.makeText(getActivity(), getResources().getString(R.string.point_modification_forbidden),
                Toast.LENGTH_SHORT).show();
    }
}

From source file:android.support.v17.leanback.widget.AbstractMediaItemPresenter.java

/**
 * Each media item row can have multiple focusable elements; the details on the left and a set
 * of optional custom actions on the right.
 * The selector is a highlight that moves to highlight to cover whichever views is in focus.
 *
 * @param selectorView the selector view used to highlight an individual element within a row.
 * @param focusChangedView The component within the media row whose focus got changed.
 * @param layoutAnimator the ValueAnimator producing animation frames for the selector's width
 *                       and x-translation, generated by this method and stored for the each
 *                       {@link ViewHolder}.
 * @param isDetails Whether the changed-focused view is for a media item details (true) or
 *                  an action (false).//w  ww.j  a v  a 2 s.  c o m
 */
private static ValueAnimator updateSelector(final View selectorView, View focusChangedView,
        ValueAnimator layoutAnimator, boolean isDetails) {
    int animationDuration = focusChangedView.getContext().getResources()
            .getInteger(android.R.integer.config_shortAnimTime);
    DecelerateInterpolator interpolator = new DecelerateInterpolator();

    int layoutDirection = ViewCompat.getLayoutDirection(selectorView);
    if (!focusChangedView.hasFocus()) {
        // if neither of the details or action views are in focus (ie. another row is in focus),
        // animate the selector out.
        selectorView.animate().cancel();
        selectorView.animate().alpha(0f).setDuration(animationDuration).setInterpolator(interpolator).start();
        // keep existing layout animator
        return layoutAnimator;
    } else {
        // cancel existing layout animator
        if (layoutAnimator != null) {
            layoutAnimator.cancel();
            layoutAnimator = null;
        }
        float currentAlpha = selectorView.getAlpha();
        selectorView.animate().alpha(1f).setDuration(animationDuration).setInterpolator(interpolator).start();

        final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) selectorView.getLayoutParams();
        ViewGroup rootView = (ViewGroup) selectorView.getParent();
        sTempRect.set(0, 0, focusChangedView.getWidth(), focusChangedView.getHeight());
        rootView.offsetDescendantRectToMyCoords(focusChangedView, sTempRect);
        if (isDetails) {
            if (layoutDirection == View.LAYOUT_DIRECTION_RTL) {
                sTempRect.right += rootView.getHeight();
                sTempRect.left -= rootView.getHeight() / 2;
            } else {
                sTempRect.left -= rootView.getHeight();
                sTempRect.right += rootView.getHeight() / 2;
            }
        }
        final int targetLeft = sTempRect.left;
        final int targetWidth = sTempRect.width();
        final float deltaWidth = lp.width - targetWidth;
        final float deltaLeft = lp.leftMargin - targetLeft;

        if (deltaLeft == 0f && deltaWidth == 0f) {
            // no change needed
        } else if (currentAlpha == 0f) {
            // change selector to the proper width and marginLeft without animation.
            lp.width = targetWidth;
            lp.leftMargin = targetLeft;
            selectorView.requestLayout();
        } else {
            // animate the selector to the proper width and marginLeft.
            layoutAnimator = ValueAnimator.ofFloat(0f, 1f);
            layoutAnimator.setDuration(animationDuration);
            layoutAnimator.setInterpolator(interpolator);

            layoutAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    // Set width to the proper width for this animation step.
                    float fractionToEnd = 1f - valueAnimator.getAnimatedFraction();
                    lp.leftMargin = Math.round(targetLeft + deltaLeft * fractionToEnd);
                    lp.width = Math.round(targetWidth + deltaWidth * fractionToEnd);
                    selectorView.requestLayout();
                }
            });
            layoutAnimator.start();
        }
        return layoutAnimator;

    }
}

From source file:com.phonemetra.turbo.launcher.AsyncTaskCallback.java

Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) {
    if (mState == state) {
        return null;
    }/*from   w  w w.jav  a 2  s. co m*/

    // Initialize animation arrays for the first time if necessary
    initAnimationArrays();

    AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null;

    final State oldState = mState;
    final boolean oldStateIsNormal = (oldState == State.NORMAL);
    final boolean oldStateIsOverview = (oldState == State.OVERVIEW);
    setState(state);
    final boolean stateIsNormal = (state == State.NORMAL);
    final boolean stateIsOverview = (state == State.OVERVIEW);
    float finalBackgroundAlpha = stateIsOverview ? 1.0f : 0f;
    float finalPageIndicatorAlpha = stateIsOverview ? 0f : 1f;
    float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f;
    float finalWorkspaceTranslationY = stateIsOverview ? getOverviewModeTranslationY() : 0;

    boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview);
    boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal);

    mNewScale = 1.0f;

    if (state != State.NORMAL) {
        if (stateIsOverview) {
            mNewScale = mOverviewModeShrinkFactor;
        }
    }

    final int duration = getResources().getInteger(R.integer.config_overviewTransitionTime);

    for (int i = 0; i < getChildCount(); i++) {
        final CellLayout cl = (CellLayout) getChildAt(i);
        float finalAlpha = 1f;

        if (stateIsOverview) {
            cl.setVisibility(VISIBLE);
            cl.setTranslationX(0f);
            cl.setTranslationY(0f);
            cl.setPivotX(cl.getMeasuredWidth() * 0.5f);
            cl.setPivotY(cl.getMeasuredHeight() * 0.5f);
            cl.setRotation(0f);
            cl.setRotationY(0f);
            cl.setRotationX(0f);
            cl.setScaleX(1f);
            cl.setScaleY(1f);
            cl.setShortcutAndWidgetAlpha(1f);
        }

        mOldAlphas[i] = cl.getShortcutsAndWidgets().getAlpha();
        mNewAlphas[i] = finalAlpha;
        if (animated) {
            mOldBackgroundAlphas[i] = cl.getBackgroundAlpha();
            mNewBackgroundAlphas[i] = finalBackgroundAlpha;
        } else {
            cl.setBackgroundAlpha(finalBackgroundAlpha);
            cl.setShortcutAndWidgetAlpha(finalAlpha);
        }
    }

    final View overviewPanel = mLauncher.getOverviewPanel();
    if (animated) {
        anim.setDuration(duration);
        LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this);
        scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY)
                .setInterpolator(mZoomInInterpolator);
        anim.play(scale);
        ValueAnimator invalidate = ValueAnimator.ofFloat(0f, 1f);
        invalidate.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                invalidate();
            }
        });
        anim.play(invalidate);
        ObjectAnimator pageIndicatorAlpha = null;
        if (getPageIndicator() != null) {
            pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha", finalPageIndicatorAlpha);
        }
        ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(overviewPanel, "alpha",
                finalOverviewPanelAlpha);

        overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel));

        if (overviewToWorkspace) {
            overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2));
        }

        if (getPageIndicator() != null) {
            pageIndicatorAlpha.addListener(new AlphaUpdateListener(getPageIndicator()));
        }

        anim.play(overviewPanelAlpha);
        anim.play(pageIndicatorAlpha);

        for (int index = 0; index < getChildCount(); index++) {
            final int i = index;

            final CellLayout cl = (CellLayout) getChildAt(i);
            if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) {
                cl.setBackgroundAlpha(mNewBackgroundAlphas[i]);
                cl.getShortcutsAndWidgets().setAlpha(mNewAlphas[i]);
            } else {
                LauncherViewPropertyAnimator a = new LauncherViewPropertyAnimator(cl.getShortcutsAndWidgets());
                a.alpha(mNewAlphas[i]).setDuration(duration).setInterpolator(mZoomInInterpolator);
                anim.play(a);
                if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) {
                    ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f);
                    bgAnim.setInterpolator(mZoomInInterpolator);
                    bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
                        public void onAnimationUpdate(float a, float b) {
                            cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]);
                        }
                    });
                    anim.play(bgAnim);
                }
            }
        }

        anim.setStartDelay(delay);
    } else {
        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        if (getPageIndicator() != null) {
            getPageIndicator().setAlpha(finalPageIndicatorAlpha);
            AlphaUpdateListener.updateVisibility(getPageIndicator());
        }
        setScaleX(mNewScale);
        setScaleY(mNewScale);
        setTranslationY(finalWorkspaceTranslationY);
    }
    return anim;
}

From source file:se.kth.csc.stayawhile.swipe.QueueTouchListener.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalLayoutParamsHeight = lp.height;
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override/*w w  w .  j a v  a 2s  .  c o  m*/
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);

                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }

                mQueueSwipeListener.onDismiss(mRecyclerView, dismissPositions);

                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = ListView.INVALID_POSITION;

                ViewGroup.LayoutParams lp;
                for (PendingActionData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    pendingDismiss.view.setAlpha(mAlpha);
                    pendingDismiss.view.setTranslationX(0);

                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalLayoutParamsHeight;

                    pendingDismiss.view.setLayoutParams(lp);
                }

                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mRecyclerView.dispatchTouchEvent(cancelEvent);

                mPendingDismisses.clear();
                mAnimatingPosition = ListView.INVALID_POSITION;
            }
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });

    mPendingDismisses.add(new PendingActionData(dismissPosition, dismissView));
    animator.start();
}

From source file:com.rbware.github.androidcouchpotato.widget.AbstractMediaItemPresenter.java

/**
 * Each media item row can have multiple focusable elements; the details on the left and a set
 * of optional custom actions on the right.
 * The selector is a highlight that moves to highlight to cover whichever views is in focus.
 *
 * @param selectorView the selector view used to highlight an individual element within a row.
 * @param focusChangedView The component within the media row whose focus got changed.
 * @param layoutAnimator the ValueAnimator producing animation frames for the selector's width
 *                       and x-translation, generated by this method and stored for the each
 *                       {@link ViewHolder}.
 * @param isDetails Whether the changed-focused view is for a media item details (true) or
 *                  an action (false)./*ww  w .  ja v a 2 s  .co  m*/
 */
static ValueAnimator updateSelector(final View selectorView, View focusChangedView,
        ValueAnimator layoutAnimator, boolean isDetails) {
    int animationDuration = focusChangedView.getContext().getResources()
            .getInteger(android.R.integer.config_shortAnimTime);
    DecelerateInterpolator interpolator = new DecelerateInterpolator();

    int layoutDirection = ViewCompat.getLayoutDirection(selectorView);
    if (!focusChangedView.hasFocus()) {
        // if neither of the details or action views are in focus (ie. another row is in focus),
        // animate the selector out.
        selectorView.animate().cancel();
        selectorView.animate().alpha(0f).setDuration(animationDuration).setInterpolator(interpolator).start();
        // keep existing layout animator
        return layoutAnimator;
    } else {
        // cancel existing layout animator
        if (layoutAnimator != null) {
            layoutAnimator.cancel();
            layoutAnimator = null;
        }
        float currentAlpha = selectorView.getAlpha();
        selectorView.animate().alpha(1f).setDuration(animationDuration).setInterpolator(interpolator).start();

        final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) selectorView.getLayoutParams();
        ViewGroup rootView = (ViewGroup) selectorView.getParent();
        sTempRect.set(0, 0, focusChangedView.getWidth(), focusChangedView.getHeight());
        rootView.offsetDescendantRectToMyCoords(focusChangedView, sTempRect);
        if (isDetails) {
            if (layoutDirection == View.LAYOUT_DIRECTION_RTL) {
                sTempRect.right += rootView.getHeight();
                sTempRect.left -= rootView.getHeight() / 2;
            } else {
                sTempRect.left -= rootView.getHeight();
                sTempRect.right += rootView.getHeight() / 2;
            }
        }
        final int targetLeft = sTempRect.left;
        final int targetWidth = sTempRect.width();
        final float deltaWidth = lp.width - targetWidth;
        final float deltaLeft = lp.leftMargin - targetLeft;

        if (deltaLeft == 0f && deltaWidth == 0f) {
            // no change needed
        } else if (currentAlpha == 0f) {
            // change selector to the proper width and marginLeft without animation.
            lp.width = targetWidth;
            lp.leftMargin = targetLeft;
            selectorView.requestLayout();
        } else {
            // animate the selector to the proper width and marginLeft.
            layoutAnimator = ValueAnimator.ofFloat(0f, 1f);
            layoutAnimator.setDuration(animationDuration);
            layoutAnimator.setInterpolator(interpolator);

            layoutAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    // Set width to the proper width for this animation step.
                    float fractionToEnd = 1f - valueAnimator.getAnimatedFraction();
                    lp.leftMargin = Math.round(targetLeft + deltaLeft * fractionToEnd);
                    lp.width = Math.round(targetWidth + deltaWidth * fractionToEnd);
                    selectorView.requestLayout();
                }
            });
            layoutAnimator.start();
        }
        return layoutAnimator;

    }
}

From source file:com.dish.browser.activity.BrowserActivity.java

private void changeToolbarBackground(Bitmap favicon) {
    Palette.from(favicon).generate(new Palette.PaletteAsyncListener() {
        @Override//from   w  w  w.j a v a 2 s  . co m
        public void onGenerated(Palette palette) {

            // OR with opaque black to remove transparency glitches
            int color = 0xff000000
                    | palette.getVibrantColor(mActivity.getResources().getColor(R.color.primary_color));

            int finalColor; // Lighten up the dark color if it is
            // too dark
            if (isColorTooDark(color)) {
                finalColor = mixTwoColors(mActivity.getResources().getColor(R.color.primary_color), color,
                        0.25f);
            } else {
                finalColor = color;
            }

            ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), mBackground.getColor(),
                    finalColor);

            anim.addUpdateListener(new AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    int color = (Integer) animation.getAnimatedValue();
                    mBackground.setColor(color);
                    getWindow().setBackgroundDrawable(mBackground);
                    mToolbarLayout.setBackgroundColor(color);
                }

            });

            anim.setDuration(300);
            anim.start();

        }
    });
}

From source file:com.brandon.mailbox.RecyclerSwipeListener.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.
    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalLayoutParamsHeight = lp.height;
    final int originalHeight = dismissView.getHeight();
    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override//from  www  .java  2s .co m
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);
                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }
                if (mFinalDelta < 0) {
                    mSwipeListener.onDismissedBySwipeLeft(mRecyclerView, dismissPositions);
                } else {
                    mSwipeListener.onDismissedBySwipeRight(mRecyclerView, dismissPositions);
                }
                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = ListView.INVALID_POSITION;
                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    pendingDismiss.view.setAlpha(mAlpha);
                    pendingDismiss.view.setTranslationX(0);
                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalLayoutParamsHeight;
                    pendingDismiss.view.setLayoutParams(lp);
                }
                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mRecyclerView.dispatchTouchEvent(cancelEvent);
                mPendingDismisses.clear();
                mAnimatingPosition = ListView.INVALID_POSITION;
            }
        }
    });
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });
    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}

From source file:com.itude.mobile.mobbl.blueprint.app.view.listeners.SwipeDismissRecyclerViewTouchListener.java

private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight;
    if (mIsVertical)
        originalHeight = dismissView.getWidth();
    else/*from w ww. ja  va  2s. c om*/
        originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);

                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }
                mCallbacks.onDismiss(dismissView, dismissPosition);

                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = ListView.INVALID_POSITION;

                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    pendingDismiss.view.setAlpha(1f);
                    if (mIsVertical)
                        pendingDismiss.view.setTranslationY(0);
                    else
                        pendingDismiss.view.setTranslationX(0);
                    lp = pendingDismiss.view.getLayoutParams();
                    if (mIsVertical)
                        lp.width = originalHeight;
                    else
                        lp.height = originalHeight;

                    pendingDismiss.view.setLayoutParams(lp);
                }

                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mRecyclerView.dispatchTouchEvent(cancelEvent);

                mPendingDismisses.clear();
            }
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            if (mIsVertical)
                lp.width = (Integer) valueAnimator.getAnimatedValue();
            else
                lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });

    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}

From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java

private void animateKeyguardStatusBarIn(long duration) {
    mKeyguardStatusBar.setVisibility(View.VISIBLE);
    mKeyguardStatusBar.setAlpha(0f);/*  w ww . ja va 2 s  . c om*/
    ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
    anim.addUpdateListener(mStatusBarAnimateAlphaListener);
    anim.setDuration(duration);
    anim.setInterpolator(mDozeAnimationInterpolator);
    anim.start();
}

From source file:br.com.halph.agendafeliz.util.SwipeableRecyclerViewTouchListener.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalLayoutParamsHeight = lp.height;
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override// ww w  .j  a  v a  2 s. co  m
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);

                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }

                if (mFinalDelta < 0) {
                    mSwipeListener.onDismissedBySwipeLeft(mRecyclerView, dismissPositions);
                } else {
                    mSwipeListener.onDismissedBySwipeRight(mRecyclerView, dismissPositions);
                }

                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = ListView.INVALID_POSITION;

                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    pendingDismiss.view.setAlpha(mAlpha);
                    pendingDismiss.view.setTranslationX(0);

                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalLayoutParamsHeight;

                    pendingDismiss.view.setLayoutParams(lp);
                }

                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mRecyclerView.dispatchTouchEvent(cancelEvent);

                mPendingDismisses.clear();
                mAnimatingPosition = ListView.INVALID_POSITION;
            }
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });

    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}