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:com.android.deskclock.timer.TimerFragment.java

/**
 * @param timerToRemove the timer to be removed during the animation
 *///  w w  w. j ava 2  s.  c o m
private void animateTimerRemove(final Timer timerToRemove) {
    final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0);
    fadeOut.setDuration(mShortAnimationDuration);
    fadeOut.setInterpolator(new DecelerateInterpolator());
    fadeOut.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            DataModel.getDataModel().removeTimer(timerToRemove);
            Events.sendTimerEvent(R.string.action_delete, R.string.label_deskclock);
        }
    });

    final Animator fadeIn = ObjectAnimator.ofFloat(mViewPager, ALPHA, 0, 1);
    fadeIn.setDuration(mShortAnimationDuration);
    fadeIn.setInterpolator(new AccelerateInterpolator());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(fadeOut).before(fadeIn);
    animatorSet.start();
}

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

private Animator getAlertAnimator(final View source, final int titleResId, final String infoText,
        final String accessibilityText, final int revealColor, final int backgroundColor) {
    final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);/*from  ww w .ja  va2  s.  c o  m*/
    containerView.addView(revealView);

    // TODO: Fade out source icon over the reveal (like LOLLIPOP version).

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS);
    revealAnimator.setInterpolator(REVEAL_INTERPOLATOR);
    revealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.setVisibility(View.VISIBLE);
            mAlertTitleView.setText(titleResId);

            if (infoText != null) {
                mAlertInfoView.setText(infoText);
                mAlertInfoView.setVisibility(View.VISIBLE);
            }
            mContentView.setVisibility(View.GONE);

            getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));
        }
    });

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet alertAnimator = new AnimatorSet();
    alertAnimator.play(revealAnimator).before(fadeAnimator);
    alertAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.announceForAccessibility(accessibilityText);
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            }, ALERT_DISMISS_DELAY_MILLIS);
        }
    });

    return alertAnimator;
}

From source file:com.stasbar.knowyourself.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 w  w  w . j  a  v  a2s . co  m
private void animateToView(View toView, final Timer timerToRemove) {
    if (mCurrentView == toView) {
        return;
    }

    final boolean toTimers = toView == mTimersView;

    final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration();
    final Animator rotateFrom = ObjectAnimator.ofFloat(mCurrentView, SCALE_X, 1, 0);
    rotateFrom.setDuration(duration);
    rotateFrom.setInterpolator(new DecelerateInterpolator());
    rotateFrom.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (timerToRemove != null) {
                DataModel.getDataModel().removeTimer(timerToRemove);
                ((MainActivity) getActivity()).stopActivity(activityItem, timerToRemove);
            }

            mCurrentView.setScaleX(1);
            if (toTimers) {
                showTimersView();
            } else {
                showCreateTimerView();
            }

        }
    });

    final Animator rotateTo = ObjectAnimator.ofFloat(toView, SCALE_X, 0, 1);
    rotateTo.setDuration(duration);
    rotateTo.setInterpolator(new AccelerateInterpolator());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(rotateFrom).before(rotateTo);
    animatorSet.start();
}

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

private Animator getRotateFromAnimator(View view) {
    final Animator animator = new ObjectAnimator().ofFloat(view, View.SCALE_X, 1.0f, 0.0f);
    animator.setDuration(ROTATE_ANIM_DURATION_MILIS);
    animator.setInterpolator(DECELERATE_INTERPOLATOR);
    return animator;
}

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

private Animator getRotateToAnimator(View view) {
    final Animator animator = new ObjectAnimator().ofFloat(view, View.SCALE_X, 0.0f, 1.0f);
    animator.setDuration(ROTATE_ANIM_DURATION_MILIS);
    animator.setInterpolator(ACCELERATE_INTERPOLATOR);
    return animator;
}

From source file:io.plaidapp.ui.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   w ww .j a va  2 s. co  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.onyx.deskclock.deskclock.alarms.AlarmActivity.java

private Animator getAlertAnimator(final View source, final int titleResId, final String infoText,
        final String accessibilityText, final int revealColor, final int backgroundColor) {
    final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);//from w w  w. j  a  v  a  2  s  .  c  om
    containerView.addView(revealView);

    // TODO: Fade out source icon over the reveal (like LOLLIPOP version).

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS);
    revealAnimator.setInterpolator(REVEAL_INTERPOLATOR);
    revealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.setVisibility(View.VISIBLE);
            mAlertTitleView.setText(titleResId);

            if (infoText != null) {
                mAlertInfoView.setText(infoText);
                mAlertInfoView.setVisibility(View.VISIBLE);
            }
            mContentView.setVisibility(View.GONE);

            getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));
        }
    });

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet alertAnimator = new AnimatorSet();
    alertAnimator.play(revealAnimator).before(fadeAnimator);
    alertAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            if (Build.VERSION.SDK_INT >= 16) {
                mAlertView.announceForAccessibility(accessibilityText);
            }

            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            }, ALERT_DISMISS_DELAY_MILLIS);
        }
    });

    return alertAnimator;
}

From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setOrAnimateIconTo(final ImageView imageView, final int imageResId, boolean animate) {
    if (UIUtils.hasICS() && imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();//  w w  w  .j  a  v  a  2s. c  o m
            imageView.setAlpha(1f);
        }
    }

    animate = animate && UIUtils.hasICS();
    if (animate) {
        int duration = getResources().getInteger(android.R.integer.config_shortAnimTime);

        Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f);
        outAnimator.setDuration(duration / 2);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageResource(imageResId);
            }
        });

        AnimatorSet inAnimator = new AnimatorSet();
        inAnimator.setDuration(duration);
        inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f));

        AnimatorSet set = new AnimatorSet();
        set.playSequentially(outAnimator, inAnimator);
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setTag(null);
            }
        });
        imageView.setTag(set);
        set.start();
    } else {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:de.janniskilian.xkcdreader.presentation.components.showcomics.ShowComicsActivity.java

@Override
public void endSearchMode(boolean animate) {
    Utils.hideKeyboard(this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (animate) {
            // If the device has rotated, we need to calculate a new center for the animation.
            if (searchButtonCenter == null) {
                final View actionMenuView = searchToolbar.getChildAt(2);
                final ViewGroup actionMenuViewGroup = (ViewGroup) actionMenuView;
                final View button = actionMenuViewGroup.getChildAt(0);
                System.out.println(button.getClass());

                searchButtonCenter = new Point(
                        (int) (button.getX() + actionMenuView.getX() - button.getWidth() / 2),
                        (int) (button.getY() + actionMenuView.getY() + button.getHeight() / 2));
            }/*from  w w w .  j a v  a  2s  . co  m*/

            final Animator animator = ViewAnimationUtils.createCircularReveal(searchToolbar,
                    searchButtonCenter.x, searchButtonCenter.y, searchToolbar.getWidth(), 0);
            animator.setDuration(revealStatusBarDuration);
            animator.addListener(new EndSearchModeAnimationListener(searchToolbar));
            toolbar.setVisibility(View.VISIBLE);
            animator.start();
        } else {
            searchToolbar.setVisibility(View.INVISIBLE);
        }

        setSupportActionBar(toolbar);
    } else {
        toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.primary));

        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setHomeButtonEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(false);
            actionBar.setCustomView(R.layout.toolbar_search);
            actionBar.setDisplayShowCustomEnabled(false);
            actionBar.setDisplayShowTitleEnabled(true);
        }
    }

    viewPager.setVisibility(View.VISIBLE);
    if (animate) {
        searchResults.animate().alpha(0).setDuration(crossfadeViewPagerSearchDuration)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        searchResults.setVisibility(View.GONE);
                    }
                });

        viewPager.animate().alpha(1).setDuration(crossfadeViewPagerSearchDuration).setListener(null);
    } else {
        viewPager.setAlpha(1);
        searchResults.setAlpha(0);
        searchResults.setVisibility(View.GONE);
    }

    searchInputSub.unsubscribe();
    searchInputLengthSub.unsubscribe();
    invalidateOptionsMenu();
}

From source file:com.android.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  w w  w  .j av a2s.co m*/
 */
private void animateToView(View toView, final Timer timerToRemove) {
    if (mCurrentView == toView) {
        throw new IllegalStateException("toView is already the current view");
    }

    final boolean toTimers = toView == mTimersView;

    // Avoid double-taps by enabling/disabling the set of buttons active on the new view.
    mLeftButton.setEnabled(toTimers);
    mRightButton.setEnabled(toTimers);
    mCancelCreateButton.setEnabled(!toTimers);

    final Animator rotateFrom = ObjectAnimator.ofFloat(mCurrentView, SCALE_X, 1, 0);
    rotateFrom.setDuration(mShortAnimationDuration);
    rotateFrom.setInterpolator(new DecelerateInterpolator());
    rotateFrom.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (timerToRemove != null) {
                DataModel.getDataModel().removeTimer(timerToRemove);
                Events.sendTimerEvent(R.string.action_delete, R.string.label_deskclock);
            }

            mCurrentView.setScaleX(1);
            if (toTimers) {
                showTimersView();
            } else {
                showCreateTimerView();
            }
        }
    });

    final Animator rotateTo = ObjectAnimator.ofFloat(toView, SCALE_X, 0, 1);
    rotateTo.setDuration(mShortAnimationDuration);
    rotateTo.setInterpolator(new AccelerateInterpolator());

    final float preScale = toTimers ? 0 : 1;
    final float postScale = toTimers ? 1 : 0;
    final Animator fabAnimator = getScaleAnimator(mFab, preScale, postScale);
    final Animator leftButtonAnimator = getScaleAnimator(mLeftButton, preScale, postScale);
    final Animator rightButtonAnimator = getScaleAnimator(mRightButton, preScale, postScale);

    final AnimatorSet buttons = new AnimatorSet();
    buttons.setDuration(toTimers ? mMediumAnimationDuration : mShortAnimationDuration);
    buttons.play(leftButtonAnimator).with(rightButtonAnimator).with(fabAnimator);
    buttons.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mLeftButton.setVisibility(toTimers ? VISIBLE : INVISIBLE);
            mRightButton.setVisibility(toTimers ? VISIBLE : INVISIBLE);

            mFab.setScaleX(1);
            mFab.setScaleY(1);
            mLeftButton.setScaleX(1);
            mLeftButton.setScaleY(1);
            mRightButton.setScaleX(1);
            mRightButton.setScaleY(1);
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(rotateFrom).before(rotateTo).with(buttons);
    animatorSet.start();
}