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.hamzahrmalik.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.jav a2s .c  om*/

    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 alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animator) {
            groupOverlay.remove(revealView);
            mCurrentAnimator = null;
        }
    });

    mResultEditText.setText("");
    mFormulaEditText.setText("");
    mCurrentAnimator = animatorSet;
    animatorSet.start();

}

From source file:liam.franco.selene.activities.MainActivity.java

private void animateOpenBottomFabSheet() {
    if (bottomFabBar != null && bottomFabBar.getVisibility() == View.INVISIBLE) {
        final int[] xy = ViewUtils.viewCoordinates(fab);

        Animator animator = ViewAnimationUtils.createCircularReveal(bottomFabBar,
                (xy[0] + (fab.getMeasuredWidth() >> 1)), -bottomFabBar.getHeight(),
                UIUtils.convertDpToPixel(56f, App.CONTEXT),
                Math.max(bottomFabBar.getWidth(), bottomFabBar.getHeight()));
        animator.setDuration(500);
        animator.setStartDelay(7000);//from  w  w  w  .  j  a va 2  s  .co m
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                if (fab != null) {
                    fab.setVisibility(View.GONE);
                }

                if (bottomFabBar != null) {
                    bottomFabBar.setVisibility(View.VISIBLE);
                }
            }
        });
        animator.start();
    }
}

From source file:ca.zadrox.dota2esportticker.ui.TeamDetailActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void createCircularReveal() {

    mHeaderTeamLogo.setVisibility(View.VISIBLE);
    mHeaderTeamLogo.setImageBitmap(mTeam.logo);

    if (mHeaderBox.isAttachedToWindow()) {
        mHeaderTeamLogo.setTranslationY(-UIUtils.calculateActionBarSize(this) - mHeaderTeamLogo.getHeight());

        mHeaderTeamLogo.animate().translationY(0).setDuration(100)
                .setInterpolator(new AccelerateDecelerateInterpolator())
                .setListener(new Animator.AnimatorListener() {
                    @Override//from w  w w . ja v  a 2 s .c  o  m
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        int cx = (mHeaderBox.getLeft() + mHeaderBox.getRight()) / 2;
                        int cy = (mHeaderBox.getTop() + mHeaderBox.getBottom()) / 2;

                        int finalRadius = Math.max(mHeaderBox.getWidth(), mHeaderBox.getHeight());

                        final Animator anim = ViewAnimationUtils.createCircularReveal(mHeaderBox, cx, cy, 0,
                                finalRadius);

                        anim.setDuration(250);
                        anim.setInterpolator(new AccelerateDecelerateInterpolator());
                        anim.addListener(new Animator.AnimatorListener() {
                            @Override
                            public void onAnimationStart(Animator animation) {
                                mHeaderTeamName.setAlpha(1);
                                mHeaderTeamLogo.setImageBitmap(mTeam.logo);
                                mHeaderBox.setBackgroundColor(mTeam.palette
                                        .getDarkVibrantColor(getResources().getColor(R.color.theme_primary)));
                            }

                            @Override
                            public void onAnimationEnd(Animator animation) {

                            }

                            @Override
                            public void onAnimationCancel(Animator animation) {

                            }

                            @Override
                            public void onAnimationRepeat(Animator animation) {

                            }
                        });
                        anim.start();
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                }).start();

    } else {
        mHeaderTeamName.setAlpha(1);
        mHeaderTeamLogo.setImageBitmap(mTeam.logo);
        mHeaderBox.setBackgroundColor(
                mTeam.palette.getDarkVibrantColor(getResources().getColor(R.color.theme_primary)));
    }
}

From source file:com.androidinspain.deskclock.alarms.dataadapter.ExpandedAlarmViewHolder.java

private Animator createExpandingAnimator(AlarmItemViewHolder oldHolder, long duration) {
    final View oldView = oldHolder.itemView;
    final View newView = itemView;
    final Animator boundsAnimator = AnimatorUtils.getBoundsAnimator(newView, oldView, newView);
    boundsAnimator.setDuration(duration);
    boundsAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    final Animator backgroundAnimator = ObjectAnimator.ofPropertyValuesHolder(newView,
            PropertyValuesHolder.ofInt(AnimatorUtils.BACKGROUND_ALPHA, 0, 255));
    backgroundAnimator.setDuration(duration);

    final View oldArrow = oldHolder.arrow;
    final Rect oldArrowRect = new Rect(0, 0, oldArrow.getWidth(), oldArrow.getHeight());
    final Rect newArrowRect = new Rect(0, 0, arrow.getWidth(), arrow.getHeight());
    ((ViewGroup) newView).offsetDescendantRectToMyCoords(arrow, newArrowRect);
    ((ViewGroup) oldView).offsetDescendantRectToMyCoords(oldArrow, oldArrowRect);
    final float arrowTranslationY = oldArrowRect.bottom - newArrowRect.bottom;

    arrow.setTranslationY(arrowTranslationY);
    arrow.setVisibility(View.VISIBLE);
    clock.setVisibility(View.VISIBLE);
    onOff.setVisibility(View.VISIBLE);

    final long longDuration = (long) (duration * ANIM_LONG_DURATION_MULTIPLIER);
    final Animator repeatAnimation = ObjectAnimator.ofFloat(repeat, View.ALPHA, 1f).setDuration(longDuration);
    final Animator repeatDaysAnimation = ObjectAnimator.ofFloat(repeatDays, View.ALPHA, 1f)
            .setDuration(longDuration);//from  www.  j ava2  s  .  com
    final Animator ringtoneAnimation = ObjectAnimator.ofFloat(ringtone, View.ALPHA, 1f)
            .setDuration(longDuration);
    final Animator dismissAnimation = ObjectAnimator.ofFloat(preemptiveDismissButton, View.ALPHA, 1f)
            .setDuration(longDuration);
    final Animator vibrateAnimation = ObjectAnimator.ofFloat(vibrate, View.ALPHA, 1f).setDuration(longDuration);
    final Animator editLabelAnimation = ObjectAnimator.ofFloat(editLabel, View.ALPHA, 1f)
            .setDuration(longDuration);
    final Animator hairLineAnimation = ObjectAnimator.ofFloat(hairLine, View.ALPHA, 1f)
            .setDuration(longDuration);
    final Animator deleteAnimation = ObjectAnimator.ofFloat(delete, View.ALPHA, 1f).setDuration(longDuration);
    final Animator arrowAnimation = ObjectAnimator.ofFloat(arrow, View.TRANSLATION_Y, 0f).setDuration(duration);
    arrowAnimation.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    // Set the stagger delays; delay the first by the amount of time it takes for the collapse
    // to complete, then stagger the expansion with the remaining time.
    long startDelay = (long) (duration * ANIM_STANDARD_DELAY_MULTIPLIER);
    final int numberOfItems = countNumberOfItems();
    final long delayIncrement = (long) (duration * ANIM_SHORT_DELAY_INCREMENT_MULTIPLIER) / (numberOfItems - 1);
    repeatAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    final boolean daysVisible = repeatDays.getVisibility() == View.VISIBLE;
    if (daysVisible) {
        repeatDaysAnimation.setStartDelay(startDelay);
        startDelay += delayIncrement;
    }
    ringtoneAnimation.setStartDelay(startDelay);
    vibrateAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    editLabelAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    hairLineAnimation.setStartDelay(startDelay);
    if (preemptiveDismissButton.getVisibility() == View.VISIBLE) {
        dismissAnimation.setStartDelay(startDelay);
        startDelay += delayIncrement;
    }
    deleteAnimation.setStartDelay(startDelay);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(backgroundAnimator, repeatAnimation, boundsAnimator, repeatDaysAnimation,
            vibrateAnimation, ringtoneAnimation, editLabelAnimation, deleteAnimation, hairLineAnimation,
            dismissAnimation, arrowAnimation);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animator) {
            AnimatorUtils.startDrawableAnimation(arrow);
        }
    });
    return animatorSet;
}

From source file:org.goodev.material.SearchActivity.java

@OnClick({ R.id.scrim, R.id.searchback })
protected void dismiss() {
    int interpolator = UI.isLollipop() ? android.R.interpolator.fast_out_slow_in
            : android.R.interpolator.accelerate_decelerate;
    int backInterpolator = UI.isLollipop() ? android.R.interpolator.fast_out_linear_in
            : android.R.interpolator.accelerate_decelerate;
    // translate the icon to match position in the launching activity
    searchBackContainer.animate().translationX(searchBackDistanceX).setDuration(600L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, interpolator))
            .setListener(new AnimatorListenerAdapter() {
                @Override// w ww. j a va 2s . c  o m
                public void onAnimationEnd(Animator animation) {
                    supportFinishAfterTransition();
                }
            }).start();
    if (UI.isLollipop()) {

        // transform from back icon to search icon
        AnimatedVectorDrawable backToSearch = (AnimatedVectorDrawable) ContextCompat.getDrawable(this,
                R.drawable.avd_back_to_search);
        searchBack.setImageDrawable(backToSearch);
        // clear the background else the touch ripple moves with the translation which looks bad
        searchBack.setBackground(null);
        backToSearch.start();
    }
    // fade out the other search chrome
    searchView.animate().alpha(0f).setStartDelay(0L).setDuration(120L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator)).setListener(null).start();
    searchBackground.animate().alpha(0f).setStartDelay(300L).setDuration(160L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator)).setListener(null).start();
    if (UI.isLollipop()) {
        if (searchToolbar.getZ() != 0f) {
            searchToolbar.animate().z(0f).setDuration(600L)
                    .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator)).start();
        }

    }

    // if we're showing search results, circular hide them
    if (UI.isLollipop() && resultsContainer.getHeight() > 0) {
        Animator closeResults = ViewAnimationUtils.createCircularReveal(resultsContainer, searchIconCenterX, 0,
                (float) Math.hypot(searchIconCenterX, resultsContainer.getHeight()), 0f);
        closeResults.setDuration(500L);
        closeResults.setInterpolator(
                AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in));
        closeResults.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                resultsContainer.setVisibility(View.INVISIBLE);
            }
        });
        closeResults.start();
    }

    // fade out the scrim
    scrim.animate().alpha(0f).setDuration(400L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator)).setListener(null).start();
}

From source file:org.ciasaboark.tacere.activity.AboutActivity.java

@TargetApi(21)
private void toggleVisibilityCircularReveal(final View view) {
    if (view.getVisibility() == View.VISIBLE) {
        //the view is visible, so animate it out then set visibility to GONE
        int cx;/*from  www.  jav a  2 s  .c om*/
        int cy;
        if (this.x == null || this.y == null) {
            // get the center for the clipping circle
            cx = (view.getLeft() + view.getRight()) / 2;
            cy = (view.getTop() + view.getBottom()) / 2;
        } else {
            //a touch event has been recorded, use the last known coordinates
            cx = this.x;
            cy = this.y;
        }

        // get the initial radius for the clipping circle
        int initialRadius = view.getWidth();

        // create the animation (the final radius is zero)
        Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.INVISIBLE);
            }
        });
        anim.setDuration(700);
        // start the animation
        anim.start();
    } else {
        //the view is not visible (either GONE or INVISIBILE), set visibility to VISIBLE, then
        //animate in
        int cx;
        int cy;
        if (this.x == null || this.y == null) {
            // get the center for the clipping circle
            cx = (view.getLeft() + view.getRight()) / 2;
            cy = (view.getTop() + view.getBottom()) / 2;
        } else {
            //a touch event has been recorded, use the last known coordinates
            cx = this.x;
            cy = this.y;
        }

        // get the final radius for the clipping circle
        int finalRadius = view.getWidth();

        // create and start the animator for this view
        // (the start radius is zero)
        Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
        anim.setDuration(500);
        view.setVisibility(View.VISIBLE);
        anim.start();
    }
}

From source file:im.ene.lab.attiq.ui.activities.SearchActivity.java

@OnClick({ R.id.scrim, R.id.searchback })
  protected void dismiss() {
      // if we're showing search mRecyclerView, circular hide them
      if (mResultsContainer.getHeight() > 0) {
          ViewCompat.animate(mResultsContainer).alpha(0.f).setDuration(400L).setInterpolator(LINEAR_OUT_SLOW_INT)
                  .start();/*  w  w w.ja va2 s .  co  m*/

          Animator closeResults = ViewAnimationUtils.createCircularReveal(mResultsContainer, mSearchIconCenterX,
                  0, (float) Math.hypot(mSearchIconCenterX, mResultsContainer.getHeight()), 0f);
          closeResults.setDuration(500L);
          closeResults.setInterpolator(LINEAR_OUT_SLOW_INT);
          closeResults.addListener(new AnimatorListenerAdapter() {
              @Override
              public void onAnimationEnd(Animator animation) {
                  mResultsContainer.setVisibility(View.INVISIBLE);
              }
          });

          closeResults.start();
      }

      // translate the icon to match position in the launching activity
      ViewCompat.animate(mSearchNavButtonContainer).translationX(mSearchBackDistanceX).alpha(0.f)
              .setDuration(600L).setInterpolator(LINEAR_OUT_SLOW_INT)
              .setListener(new ViewPropertyAnimatorListenerAdapter() {
                  @Override
                  public void onAnimationEnd(View view) {
                      ActivityCompat.finishAfterTransition(SearchActivity.this);
                  }
              }).start();
      // transform from back icon to search icon
      mSearchNavButton.setImageResource(R.drawable.ic_search_24dp_black);
      // clear the background else the touch ripple moves with the translation which looks bad
      mSearchNavButton.setBackground(null);
      // fade out the other search chrome
      ViewCompat.animate(mSearchView).alpha(0f).setStartDelay(0L).setDuration(120L)
              .setInterpolator(LINEAR_OUT_SLOW_INT).setListener(null).start();
      ViewCompat.animate(mSearchBackground).alpha(0f).setStartDelay(300L).setDuration(160L)
              .setInterpolator(LINEAR_OUT_SLOW_INT).setListener(null).start();
      if (ViewCompat.getZ(mSearchToolbar) != 0f) {
          ViewCompat.animate(mSearchToolbar).z(0f).setDuration(600L).setInterpolator(LINEAR_OUT_SLOW_INT).start();
      }

      // fade out the mScrim
      ViewCompat.animate(mScrim).alpha(0f).setDuration(400L).setInterpolator(LINEAR_OUT_SLOW_INT)
              .setListener(null).start();
  }

From source file:arun.com.chromer.shared.views.TabView.java

private Animator getIconUnSelectionAnimator() {
    Animator animator = null;
    switch (mTabType) {
    case TAB_TYPE_OPTIONS:
        animator = ObjectAnimator.ofFloat(tabIcon, "rotation", -180);
        break;//from ww  w  .  ja  v a2 s  .  c  o m
    case TAB_TYPE_WEB_HEADS:
        animator = ObjectAnimator.ofFloat(tabIcon, "rotation", -90);
        break;
    case TAB_TYPE_CUSTOMIZE:
        animator = ObjectAnimator.ofFloat(tabIcon, "scaleY", 0.75f);
        break;
    }
    if (animator != null)
        animator.setDuration(250);
    return animator;
}

From source file:zjut.com.laowuguanli.activity.MainActivity.java

private void showDT() {
    Animator showAnimatorA = new AlphaInAnimation(0, 1).getHideAnimators(mLinearLayoutDateTime);
    Animator showAnimatorS = new SlideInLeftAnimation(this).getShowAnimator(mLinearLayoutDateTime);
    showAnimatorA.setDuration(DURATION);
    showAnimatorS.setDuration(DURATION);
    showAnimatorA.setInterpolator(mInterpolator);
    showAnimatorS.setInterpolator(mInterpolator);
    showAnimatorA.start();/* w  w w. j a  v  a2  s .  c om*/
    showAnimatorS.start();
}

From source file:zjut.com.laowuguanli.activity.MainActivity.java

private void hideDT() {
    Animator hideAnimatorA = new AlphaInAnimation(1, 0).getHideAnimators(mLinearLayoutDateTime);
    Animator hideAnimatorS = new SlideInLeftAnimation(this).getHideAnimator(mLinearLayoutDateTime);

    hideAnimatorA.setDuration(DURATION);
    hideAnimatorS.setDuration(DURATION);
    hideAnimatorA.setInterpolator(mInterpolator);
    hideAnimatorS.setInterpolator(mInterpolator);
    hideAnimatorA.start();//from  w  w w .  j a v  a 2  s . co m
    hideAnimatorS.start();
}