Example usage for android.animation Animator setDuration

List of usage examples for android.animation Animator setDuration

Introduction

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

Prototype

public abstract Animator setDuration(long duration);

Source Link

Document

Sets the duration of the animation.

Usage

From source file:babbq.com.searchplace.SearchActivity.java

@OnClick(R.id.fab)
protected void save() {
    // show the save confirmation bubble
    fab.setVisibility(View.INVISIBLE);
    confirmSaveContainer.setVisibility(View.VISIBLE);
    resultsScrim.setVisibility(View.VISIBLE);

    // expand it once it's been measured and show a scrim over the search results
    confirmSaveContainer.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override/*from   ww w.  ja  v  a 2 s.c o  m*/
        public boolean onPreDraw() {
            // expand the confirmation
            confirmSaveContainer.getViewTreeObserver().removeOnPreDrawListener(this);
            Animator reveal = ViewAnimationUtils.createCircularReveal(confirmSaveContainer,
                    confirmSaveContainer.getWidth() / 2, confirmSaveContainer.getHeight() / 2,
                    fab.getWidth() / 2, confirmSaveContainer.getWidth() / 2);
            reveal.setDuration(250L);
            reveal.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                    android.R.interpolator.fast_out_slow_in));
            reveal.start();

            // show the scrim
            int centerX = (fab.getLeft() + fab.getRight()) / 2;
            int centerY = (fab.getTop() + fab.getBottom()) / 2;
            Animator revealScrim = ViewAnimationUtils.createCircularReveal(resultsScrim, centerX, centerY, 0,
                    (float) Math.hypot(centerX, centerY));
            revealScrim.setDuration(400L);
            revealScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                    android.R.interpolator.linear_out_slow_in));
            revealScrim.start();
            ObjectAnimator fadeInScrim = ObjectAnimator.ofArgb(resultsScrim, ViewUtils.BACKGROUND_COLOR,
                    Color.TRANSPARENT, ContextCompat.getColor(SearchActivity.this, R.color.scrim));
            fadeInScrim.setDuration(800L);
            fadeInScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                    android.R.interpolator.linear_out_slow_in));
            fadeInScrim.start();

            // ease in the checkboxes
            //                saveDribbble.setAlpha(0.6f);
            //                saveDribbble.setTranslationY(saveDribbble.getHeight() * 0.4f);
            //                saveDribbble.animate()
            //                        .alpha(1f)
            //                        .translationY(0f)
            //                        .setDuration(200L)
            //                        .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
            //                                android.R.interpolator.linear_out_slow_in));
            //                saveDesignerNews.setAlpha(0.6f);
            //                saveDesignerNews.setTranslationY(saveDesignerNews.getHeight() * 0.5f);
            //                saveDesignerNews.animate()
            //                        .alpha(1f)
            //                        .translationY(0f)
            //                        .setDuration(200L)
            //                        .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
            //                                android.R.interpolator.linear_out_slow_in));
            return false;
        }
    });
}

From source file:com.androidinspain.deskclock.timer.TimerFragment.java

/**
 * @param toView one of {@link #mTimersView} or {@link #mCreateTimerView}
 * @param timerToRemove the timer to be removed during the animation; {@code null} if no timer
 *      should be removed//from  ww w . j av  a2s .c  o  m
 * @param animateDown {@code true} if the views should animate upwards, otherwise downwards
 */
private void animateToView(final View toView, final Timer timerToRemove, final boolean animateDown) {
    if (mCurrentView == toView) {
        return;
    }

    final boolean toTimers = toView == mTimersView;
    if (toTimers) {
        mTimersView.setVisibility(VISIBLE);
    } else {
        mCreateTimerView.setVisibility(VISIBLE);
    }
    // Avoid double-taps by enabling/disabling the set of buttons active on the new view.
    updateFab(BUTTONS_DISABLE);

    final long animationDuration = UiDataModel.getUiDataModel().getLongAnimationDuration();

    final ViewTreeObserver viewTreeObserver = toView.getViewTreeObserver();
    viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            if (viewTreeObserver.isAlive()) {
                viewTreeObserver.removeOnPreDrawListener(this);
            }

            final View view = mTimersView.findViewById(com.androidinspain.deskclock.R.id.timer_time);
            final float distanceY = view != null ? view.getHeight() + view.getY() : 0;
            final float translationDistance = animateDown ? distanceY : -distanceY;

            toView.setTranslationY(-translationDistance);
            mCurrentView.setTranslationY(0f);
            toView.setAlpha(0f);
            mCurrentView.setAlpha(1f);

            final Animator translateCurrent = ObjectAnimator.ofFloat(mCurrentView, TRANSLATION_Y,
                    translationDistance);
            final Animator translateNew = ObjectAnimator.ofFloat(toView, TRANSLATION_Y, 0f);
            final AnimatorSet translationAnimatorSet = new AnimatorSet();
            translationAnimatorSet.playTogether(translateCurrent, translateNew);
            translationAnimatorSet.setDuration(animationDuration);
            translationAnimatorSet.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

            final Animator fadeOutAnimator = ObjectAnimator.ofFloat(mCurrentView, ALPHA, 0f);
            fadeOutAnimator.setDuration(animationDuration / 2);
            fadeOutAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    super.onAnimationStart(animation);

                    // The fade-out animation and fab-shrinking animation should run together.
                    updateFab(FAB_AND_BUTTONS_SHRINK);
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    if (toTimers) {
                        showTimersView(FAB_AND_BUTTONS_EXPAND);

                        // Reset the state of the create view.
                        mCreateTimerView.reset();
                    } else {
                        showCreateTimerView(FAB_AND_BUTTONS_EXPAND);
                    }

                    if (timerToRemove != null) {
                        DataModel.getDataModel().removeTimer(timerToRemove);
                        Events.sendTimerEvent(com.androidinspain.deskclock.R.string.action_delete,
                                com.androidinspain.deskclock.R.string.label_deskclock);
                    }

                    // Update the fab and button states now that the correct view is visible and
                    // before the animation to expand the fab and buttons starts.
                    updateFab(FAB_AND_BUTTONS_IMMEDIATE);
                }
            });

            final Animator fadeInAnimator = ObjectAnimator.ofFloat(toView, ALPHA, 1f);
            fadeInAnimator.setDuration(animationDuration / 2);
            fadeInAnimator.setStartDelay(animationDuration / 2);

            final AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.playTogether(fadeOutAnimator, fadeInAnimator, translationAnimatorSet);
            animatorSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    mTimersView.setTranslationY(0f);
                    mCreateTimerView.setTranslationY(0f);
                    mTimersView.setAlpha(1f);
                    mCreateTimerView.setAlpha(1f);
                }
            });
            animatorSet.start();

            return true;
        }
    });
}

From source file:io.plaidapp.ui.DribbbleShot.java

private void expandImageAndFinish() {
    if (imageView.getOffset() != 0f) {
        Animator expandImage = ObjectAnimator.ofFloat(imageView, ParallaxScrimageView.OFFSET, 0f);
        expandImage.setDuration(80);
        expandImage.setInterpolator(//from   w  w w. ja va  2  s .c o  m
                AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in));
        expandImage.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                finishAfterTransition();
            }
        });
        expandImage.start();
    } else {
        finishAfterTransition();
    }
}

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

@TargetApi(21)
private void showLollipopImpl() {
    int rootWidth = mRoot.getWidth();

    float endFabX;
    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        endFabX = rootWidth / 2f + (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 0.98f;
    } else {/*from  ww w.  j a  va 2 s .  c o  m*/
        endFabX = rootWidth / 2f - (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 1.02f;
    }

    /**
     * Animate FAB movement
     */
    final Path path = new Path();
    path.moveTo(mFab.getX(), mFab.getY());
    final float x2 = controlX;
    final float y2 = getY();
    path.quadTo(x2, y2, endFabX, getY());
    ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Fade FAB drawable
     */
    Drawable drawable = mFab.getDrawable();
    if (drawable != null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 0));
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration((long) (FAB_MORPH_DURATION / 3f));
        anim.start();
    }

    /**
     * Animate FAB elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, dpToPixels(2));
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Create circular reveal
     */
    Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2,
            (float) mFab.getWidth() / 2f, (float) (Math.hypot(getWidth() / 2, getHeight() / 2)));

    toolbarReveal.setDuration(CIRCULAR_REVEAL_DURATION);
    toolbarReveal.setTarget(this);
    toolbarReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            mFab.setVisibility(View.INVISIBLE);
            setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mMorphing = false;
        }
    });

    toolbarReveal.setInterpolator(new AccelerateInterpolator());
    toolbarReveal.setStartDelay(CIRCULAR_REVEAL_DELAY);
    toolbarReveal.start();

    /**
     * Animate FloatingToolbar elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, dpToPixels(2));
    anim.setDuration(CIRCULAR_REVEAL_DURATION);
    anim.setStartDelay(CIRCULAR_REVEAL_DELAY);
    anim.start();
}

From source file:com.pitchedapps.primenumbercalculator.Calculator.java

License:asdf

private void reveal(View sourceView, AnimatorListener listener) {
    final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) getWindow().getDecorView().getOverlay();

    final Rect displayRect = new Rect();
    mDisplayView.getGlobalVisibleRect(displayRect);

    // Make reveal cover the display and status bar.
    final View revealView = new View(this);
    revealView.setBottom(displayRect.bottom);
    revealView.setLeft(displayRect.left);
    revealView.setRight(displayRect.right);
    revealView.setBackgroundColor(themeClearAccent);
    groupOverlay.add(revealView);// w w w  . j  av  a 2 s.  com

    final int[] clearLocation = new int[2];
    sourceView.getLocationInWindow(clearLocation);
    clearLocation[0] += sourceView.getWidth() / 2;
    clearLocation[1] += sourceView.getHeight() / 2;

    final int revealCenterX = clearLocation[0] - revealView.getLeft();
    final int revealCenterY = clearLocation[1] - revealView.getTop();

    final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
    final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
    final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
    final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

    final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
            revealCenterY, 0.0f, revealRadius);
    revealAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));

    final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
    alphaAnimator.addListener(listener);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(revealAnimator).before(alphaAnimator);
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            groupOverlay.remove(revealView);
            mCurrentAnimator = null;
        }
    });

    mCurrentAnimator = animatorSet;
    animatorSet.start();
}

From source file:bottombar.BottomBar.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void backgroundCircularRevealAnimation(View clickedView, final int newColor) {
    int centerX = (int) (ViewCompat.getX(clickedView) + (clickedView.getMeasuredWidth() / 2));
    int yOffset = isTabletMode ? (int) ViewCompat.getY(clickedView) : 0;
    int centerY = yOffset + clickedView.getMeasuredHeight() / 2;
    int startRadius = 0;
    int finalRadius = isTabletMode ? outerContainer.getHeight() : outerContainer.getWidth();

    Animator animator = ViewAnimationUtils.createCircularReveal(backgroundOverlay, centerX, centerY,
            startRadius, finalRadius);/*  w  ww  . j  a v a  2s  .  c  o m*/

    if (isTabletMode) {
        animator.setDuration(500);
    }

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            onEnd();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            onEnd();
        }

        private void onEnd() {
            outerContainer.setBackgroundColor(newColor);
            backgroundOverlay.setVisibility(View.INVISIBLE);
            ViewCompat.setAlpha(backgroundOverlay, 1);
        }
    });

    animator.start();
}

From source file:com.android.calculator2.Calculator.java

private void reveal(View sourceView, int colorRes, AnimatorListener listener) {
    final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) getWindow().getDecorView().getOverlay();

    final Rect displayRect = new Rect();
    mDisplayView.getGlobalVisibleRect(displayRect);

    // Make reveal cover the display and status bar.
    final View revealView = new View(this);
    revealView.setBottom(displayRect.bottom);
    revealView.setLeft(displayRect.left);
    revealView.setRight(displayRect.right);
    revealView.setBackgroundColor(getResources().getColor(colorRes));
    groupOverlay.add(revealView);/*from  w w w .  java  2s  .co  m*/

    final int[] clearLocation = new int[2];
    sourceView.getLocationInWindow(clearLocation);
    clearLocation[0] += sourceView.getWidth() / 2;
    clearLocation[1] += sourceView.getHeight() / 2;

    final int revealCenterX = clearLocation[0] - revealView.getLeft();
    final int revealCenterY = clearLocation[1] - revealView.getTop();

    final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
    final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
    final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
    final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

    final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
            revealCenterY, 0.0f, revealRadius);
    revealAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    revealAnimator.addListener(listener);

    final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(revealAnimator).before(alphaAnimator);
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            groupOverlay.remove(revealView);
            mCurrentAnimator = null;
        }
    });

    mCurrentAnimator = animatorSet;
    animatorSet.start();
}

From source file:org.huxizhijian.hhcomicviewer.ui.entry.ComicDetailsActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void animateRevealShow(View viewRoot) {
    //???/* w  w  w  .j  av  a  2s.  c o m*/
    int cx = (viewRoot.getLeft() + viewRoot.getRight()) / 2;
    int cy = (viewRoot.getTop() + viewRoot.getBottom()) / 2;
    //?
    int finalRadius = Math.max(viewRoot.getWidth(), viewRoot.getHeight());

    Animator anim = ViewAnimationUtils.createCircularReveal(viewRoot, cx, cy, 0, finalRadius);
    viewRoot.setVisibility(View.VISIBLE); //??
    anim.setDuration(getResources().getInteger(R.integer.anim_duration_medium));//
    anim.setInterpolator(new AccelerateInterpolator());//? ??
    anim.start();
}

From source file:org.chromium.chrome.browser.widget.animation.FocusAnimator.java

private void startAnimator(final Runnable callback) {
    // Don't animate anything if the number of children changed.
    if (mInitialNumberOfChildren != mLayout.getChildCount()) {
        finishAnimation(callback);/* w  w  w .  j av a 2s  .c o m*/
        return;
    }

    // Don't animate if children are already all in the correct places.
    boolean isAnimationNecessary = false;
    ArrayList<Integer> finalChildTops = calculateChildTops();
    for (int i = 0; i < finalChildTops.size() && !isAnimationNecessary; i++) {
        isAnimationNecessary |= finalChildTops.get(i).compareTo(mInitialTops.get(i)) != 0;
    }
    if (!isAnimationNecessary) {
        finishAnimation(callback);
        return;
    }

    // Animate each child moving and changing size to match their final locations.
    ArrayList<Animator> animators = new ArrayList<Animator>();
    ValueAnimator childAnimator = ValueAnimator.ofFloat(0f, 1f);
    animators.add(childAnimator);
    for (int i = 0; i < mLayout.getChildCount(); i++) {
        // The child is already where it should be.
        if (mInitialTops.get(i).compareTo(finalChildTops.get(i)) == 0
                && mInitialTops.get(i + 1).compareTo(finalChildTops.get(i + 1)) == 0) {
            continue;
        }

        final View child = mLayout.getChildAt(i);
        final int translationDifference = mInitialTops.get(i) - finalChildTops.get(i);
        final int oldHeight = mInitialTops.get(i + 1) - mInitialTops.get(i);
        final int newHeight = finalChildTops.get(i + 1) - finalChildTops.get(i);

        // Translate the child to its new place while changing where its bottom is drawn to
        // animate the child changing height without causing another layout.
        childAnimator.addUpdateListener(new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float progress = (Float) animation.getAnimatedValue();
                child.setTranslationY(translationDifference * (1f - progress));

                if (oldHeight != newHeight) {
                    float animatedHeight = oldHeight * (1f - progress) + newHeight * progress;
                    child.setBottom(child.getTop() + (int) animatedHeight);
                }
            }
        });

        // Explicitly place the child in its final position in the end.
        childAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animator) {
                child.setTranslationY(0);
                child.setBottom(child.getTop() + newHeight);
            }
        });
    }

    // Animate the height of the container itself changing.
    int oldContainerHeight = mInitialTops.get(mInitialTops.size() - 1);
    int newContainerHeight = finalChildTops.get(finalChildTops.size() - 1);
    ValueAnimator layoutAnimator = ValueAnimator.ofInt(oldContainerHeight, newContainerHeight);
    layoutAnimator.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mLayout.setBottom(((Integer) animation.getAnimatedValue()));
            requestChildFocus();
        }
    });
    animators.add(layoutAnimator);

    // Set up and kick off the animation.
    AnimatorSet animator = new AnimatorSet();
    animator.setDuration(ANIMATION_LENGTH_MS);
    animator.setInterpolator(new LinearOutSlowInInterpolator());
    animator.playTogether(animators);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            finishAnimation(callback);

            // Request a layout to put everything in the right final place.
            mLayout.requestLayout();
        }
    });
    animator.start();
}

From source file:com.taobao.weex.dom.action.AnimationAction.java

private void startAnimation(@NonNull WXSDKInstance instance, @Nullable WXComponent component) {
    if (component != null) {
        if (component.getHostView() == null) {
            WXAnimationModule.AnimationHolder holder = new WXAnimationModule.AnimationHolder(mAnimationBean,
                    callback);/*from  w ww.  j  a va  2  s  .c  o  m*/
            component.postAnimation(holder);
        } else {
            try {
                Animator animator = createAnimator(component.getHostView(),
                        instance.getInstanceViewPortWidth());
                if (animator != null) {
                    Animator.AnimatorListener animatorCallback = createAnimatorListener(instance, callback);
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2
                            && component.isLayerTypeEnabled()) {
                        component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null);
                    }
                    Interpolator interpolator = createTimeInterpolator();
                    if (animatorCallback != null) {
                        animator.addListener(animatorCallback);
                    }
                    if (interpolator != null) {
                        animator.setInterpolator(interpolator);
                    }
                    animator.setDuration(mAnimationBean.duration);
                    animator.start();
                }
            } catch (RuntimeException e) {
                WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
            }
        }
    }
}