Example usage for android.animation ValueAnimator setInterpolator

List of usage examples for android.animation ValueAnimator setInterpolator

Introduction

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

Prototype

@Override
public void setInterpolator(TimeInterpolator value) 

Source Link

Document

The time interpolator used in calculating the elapsed fraction of this animation.

Usage

From source file:com.android.nobug.view.pattern.PatternView.java

private void startLineEndAnimation(final CellState state, final float startX, final float startY,
        final float targetX, final float targetY) {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/* www .  ja v  a  2  s . com*/
        public void onAnimationUpdate(ValueAnimator animation) {
            float t = (float) animation.getAnimatedValue();
            state.lineEndX = (1 - t) * startX + t * targetX;
            state.lineEndY = (1 - t) * startY + t * targetY;
            invalidate();
        }
    });
    valueAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            state.lineAnimator = null;
        }
    });
    valueAnimator.setInterpolator(mFastOutSlowInInterpolator);
    valueAnimator.setDuration(100);
    valueAnimator.start();
    state.lineAnimator = valueAnimator;
}

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).//from  w w w. ja va  2  s  .  c  om
 */
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:io.authme.sdk.widget.LockPatternView.java

private void startSizeAnimation(float start, float end, long duration, Interpolator interpolator,
        final CellState state, final Runnable endRunnable) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        FloatAnimator animator = new FloatAnimator(start, end, duration);
        animator.addEventListener(new FloatAnimator.SimpleEventListener() {

            @Override//from   ww w . j a v a2  s .  co  m
            public void onAnimationUpdate(FloatAnimator animator) {
                state.size = (Float) animator.getAnimatedValue();
                invalidate();
            }// onAnimationUpdate()

            @Override
            public void onAnimationEnd(FloatAnimator animator) {
                if (endRunnable != null)
                    endRunnable.run();
            }// onAnimationEnd()

        });
        animator.start();
    } // API < 11
    else {
        ValueAnimator valueAnimator = ValueAnimator.ofFloat(start, end);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                state.size = (Float) animation.getAnimatedValue();
                invalidate();
            }

        });
        if (endRunnable != null) {
            valueAnimator.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    if (endRunnable != null)
                        endRunnable.run();
                }

            });
        }
        valueAnimator.setInterpolator(interpolator);
        valueAnimator.setDuration(duration);
        valueAnimator.start();
    } // API 11+
}

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  ww  w  . j av a 2s .c  om*/

    // 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: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)./* w  w w. j  a  v  a2s . 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:io.plaidapp.about.ui.widget.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//from w w w  .  j ava 2  s .  c  om
        public void onAnimationEnd(Animator animation) {
            resetState();
            pageChanging = false;
        }
    });
    moveSelected.addUpdateListener(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.settings.widget.DotsPageIndicator.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)));

    moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from  w w w .  j a va 2 s  .  co m
        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.leanlauncher.Workspace.java

Animator getChangeStateAnimation(final State state, boolean animated, int delay, ArrayList<View> layerViews) {
    if (mState == state) {
        return null;
    }/*from w ww. j a va  2  s  . c o m*/

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

    // We only want a single instance of a workspace animation to be running at once, so
    // we cancel any incomplete transition.
    if (mStateAnimator != null) {
        mStateAnimator.cancel();
    }
    mStateAnimator = anim;

    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 stateIsSpringLoaded = (state == State.SPRING_LOADED);
    final boolean stateIsNormalHidden = (state == State.NORMAL_HIDDEN);
    final boolean stateIsOverviewHidden = (state == State.OVERVIEW_HIDDEN);
    final boolean stateIsOverview = (state == State.OVERVIEW);
    float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f;
    float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f;
    float finalWorkspaceTranslationY = stateIsOverview || stateIsOverviewHidden ? getOverviewModeTranslationY()
            : 0;

    boolean workspaceToAllApps = (oldStateIsNormal && stateIsNormalHidden);
    boolean overviewToAllApps = (oldStateIsOverview && stateIsOverviewHidden);
    boolean allAppsToWorkspace = (stateIsNormalHidden && stateIsNormal);
    boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview);
    boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal);

    mNewScale = 1.0f;

    if (state != State.NORMAL) {
        if (stateIsSpringLoaded) {
            mNewScale = mSpringLoadedShrinkFactor;
        } else if (stateIsOverview || stateIsOverviewHidden) {
            mNewScale = mOverviewModeShrinkFactor;
        }
    }

    final int duration;
    if (workspaceToAllApps || overviewToAllApps) {
        duration = HIDE_WORKSPACE_DURATION; //getResources().getInteger(R.integer.config_workspaceUnshrinkTime);
    } else if (workspaceToOverview || overviewToWorkspace) {
        duration = getResources().getInteger(R.integer.config_overviewTransitionTime);
    } else {
        duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime);
    }

    final CellLayout cl = mWorkspace;
    float initialAlpha = cl.getShortcutsAndWidgets().getAlpha();
    float finalAlpha;
    if (stateIsNormalHidden || stateIsOverviewHidden) {
        finalAlpha = 0f;
    } else {
        finalAlpha = 1f;
    }

    // If we are animating to/from the small state, then hide the side pages and fade the
    // current page in
    if (!mIsSwitchingState) {
        if (workspaceToAllApps || allAppsToWorkspace) {
            if (allAppsToWorkspace) {
                initialAlpha = 0f;
            }
            cl.setShortcutAndWidgetAlpha(initialAlpha);
        }
    }

    float oldAlpha = initialAlpha;
    float newAlpha = finalAlpha;
    if (animated) {
        mOldBackgroundAlpha = cl.getBackgroundAlpha();
        mNewBackgroundAlpha = finalBackgroundAlpha;
    } else {
        cl.setBackgroundAlpha(finalBackgroundAlpha);
        cl.setShortcutAndWidgetAlpha(finalAlpha);
    }

    final View overviewPanel = mLauncher.getOverviewPanel();
    if (animated) {
        LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this);
        scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY).setDuration(duration)
                .setInterpolator(mZoomInInterpolator);
        anim.play(scale);
        float currentAlpha = cl.getShortcutsAndWidgets().getAlpha();
        if (oldAlpha == 0 && newAlpha == 0) {
            cl.setBackgroundAlpha(mNewBackgroundAlpha);
            cl.setShortcutAndWidgetAlpha(newAlpha);
        } else {
            if (layerViews != null) {
                layerViews.add(cl);
            }
            if (oldAlpha != newAlpha || currentAlpha != newAlpha) {
                LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator(
                        cl.getShortcutsAndWidgets());
                alphaAnim.alpha(newAlpha).setDuration(duration).setInterpolator(mZoomInInterpolator);
                anim.play(alphaAnim);
            }
            if (mOldBackgroundAlpha != 0 || mNewBackgroundAlpha != 0) {
                ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f);
                bgAnim.setInterpolator(mZoomInInterpolator);
                bgAnim.setDuration(duration);
                bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
                    public void onAnimationUpdate(float a, float b) {
                        cl.setBackgroundAlpha(a * mOldBackgroundAlpha + b * mNewBackgroundAlpha);
                    }
                });
                anim.play(bgAnim);
            }
        }

        Animator overviewPanelAlpha = new LauncherViewPropertyAnimator(overviewPanel)
                .alpha(finalOverviewPanelAlpha).withLayer();
        overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel));

        // For animation optimations, we may need to provide the Launcher transition
        // with a set of views on which to force build layers in certain scenarios.
        overviewPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        if (layerViews != null) {
            layerViews.add(overviewPanel);
        }

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

        overviewPanelAlpha.setDuration(duration);

        anim.play(overviewPanelAlpha);
        anim.setStartDelay(delay);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mStateAnimator = null;
            }
        });
    } else {
        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        setScaleX(mNewScale);
        setScaleY(mNewScale);
        setTranslationY(finalWorkspaceTranslationY);
    }

    if (stateIsNormal) {
        animateBackgroundGradient(0f, animated);
    } else {
        animateBackgroundGradient(getResources().getInteger(R.integer.config_workspaceScrimAlpha) / 100f,
                animated);
    }
    return anim;
}

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

private void flingSettings(float vel, boolean expand, final Runnable onFinishRunnable, boolean isClick) {
    float target = expand ? mQsMaxExpansionHeight : mQsMinExpansionHeight;
    if (target == mQsExpansionHeight) {
        mScrollYOverride = -1;/*from   w  w  w .j a  v a  2  s  . co  m*/
        if (onFinishRunnable != null) {
            onFinishRunnable.run();
        }
        return;
    }
    boolean belowFalsingThreshold = isBelowFalsingThreshold();
    if (belowFalsingThreshold) {
        vel = 0;
    }
    mScrollView.setBlockFlinging(true);
    ValueAnimator animator = ValueAnimator.ofFloat(mQsExpansionHeight, target);
    if (isClick) {
        animator.setInterpolator(mTouchResponseInterpolator);
        animator.setDuration(368);
    } else {
        mFlingAnimationUtils.apply(animator, mQsExpansionHeight, target, vel);
    }
    if (belowFalsingThreshold) {
        animator.setDuration(350);
    }
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            setQsExpansion((Float) animation.getAnimatedValue());
        }
    });
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mScrollView.setBlockFlinging(false);
            mScrollYOverride = -1;
            mQsExpansionAnimator = null;
            if (onFinishRunnable != null) {
                onFinishRunnable.run();
            }
        }
    });
    animator.start();
    mQsExpansionAnimator = animator;
    mQsAnimatorExpand = expand;
}

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

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