Example usage for android.animation Animator setInterpolator

List of usage examples for android.animation Animator setInterpolator

Introduction

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

Prototype

public abstract void setInterpolator(TimeInterpolator value);

Source Link

Document

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

Usage

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  ww. ja va  2 s . c om*/

          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:com.bachhuberdesign.deckbuildergwent.util.FabTransform.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues,
        final TransitionValues endValues) {
    if (startValues == null || endValues == null)
        return null;

    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);

    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Interpolator fastOutSlowInInterpolator = AnimUtils.getFastOutSlowInInterpolator();
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;

    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
                makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }//from  w w w  .j  a  va2s  .co m

    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }

    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab)
        fabColor.setAlpha(0);
    view.getOverlay().add(fabColor);

    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(),
            iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab)
        fabIcon.setAlpha(0);
    view.getOverlay().add(fabIcon);

    // Since the view that's being transition to always seems to be on the top (z-order), we have
    // to make a copy of the "from" view and put it in the "to" view's overlay, then fade it out.
    // There has to be another way to do this, right?
    Drawable dialogView = null;
    if (!fromFab) {
        startValues.view.setDrawingCacheEnabled(true);
        startValues.view.buildDrawingCache();
        Bitmap viewBitmap = startValues.view.getDrawingCache();
        dialogView = new BitmapDrawable(view.getResources(), viewBitmap);
        dialogView.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
        view.getOverlay().add(dialogView);
    }

    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, startBounds.width() / 2,
                (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2));
        circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator());
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2),
                endBounds.width() / 2);
        circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator());

        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                final ViewOutlineProvider fabOutlineProvider = view.getOutlineProvider();

                view.setOutlineProvider(new ViewOutlineProvider() {
                    boolean hasRun = false;

                    @Override
                    public void getOutline(final View view, Outline outline) {
                        final int left = (view.getWidth() - endBounds.width()) / 2;
                        final int top = (view.getHeight() - endBounds.height()) / 2;

                        outline.setOval(left, top, left + endBounds.width(), top + endBounds.height());

                        if (!hasRun) {
                            hasRun = true;
                            view.setClipToOutline(true);

                            // We have to remove this as soon as it's laid out so we can get the shadow back
                            view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
                                @Override
                                public boolean onPreDraw() {
                                    if (view.getWidth() == endBounds.width()
                                            && view.getHeight() == endBounds.height()) {
                                        view.setOutlineProvider(fabOutlineProvider);
                                        view.setClipToOutline(false);
                                        view.getViewTreeObserver().removeOnPreDrawListener(this);
                                        return true;
                                    }

                                    return true;
                                }
                            });
                        }
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);

    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0)
                    : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);

    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }

    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);

    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (dialogView != null) {
        final Animator dialogViewFade = ObjectAnimator.ofInt(dialogView, "alpha", 0)
                .setDuration(twoThirdsDuration);
        dialogViewFade.setInterpolator(fastOutSlowInInterpolator);
        transition.playTogether(dialogViewFade);
    }
    transition.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            // Clean up
            view.getOverlay().clear();

            if (!fromFab) {
                view.setTranslationX(0);
                view.setTranslationY(0);
                view.setTranslationZ(0);

                view.measure(makeMeasureSpec(endBounds.width(), View.MeasureSpec.EXACTLY),
                        makeMeasureSpec(endBounds.height(), View.MeasureSpec.EXACTLY));
                view.layout(endBounds.left, endBounds.top, endBounds.right, endBounds.bottom);
            }

        }
    });
    return new AnimUtils.NoPauseAnimator(transition);
}

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

@OnClick({ R.id.scrim, R.id.searchback })
protected void dismiss() {
    // translate the icon to match position in the launching activity
    searchBackContainer.animate().translationX(searchBackDistanceX).setDuration(600L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in))
            .setListener(new AnimatorListenerAdapter() {
                @Override/*from  w  w w  .j  a  va 2s. c  om*/
                public void onAnimationEnd(Animator animation) {
                    finishAfterTransition();
                }
            }).start();
    // 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, android.R.interpolator.fast_out_linear_in))
            .setListener(null).start();
    searchBackground.animate().alpha(0f).setStartDelay(300L).setDuration(160L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in))
            .setListener(null).start();

    // if we're showing search results, circular hide them
    if (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, android.R.interpolator.fast_out_linear_in))
            .setListener(null).start();
}

From source file:orbin.deskclock.timer.TimerFragment.java

/**
 * @param timerToRemove the timer to be removed during the animation
 *//*from   w  ww .j a  v  a2  s  .c o  m*/
private void animateTimerRemove(final Timer timerToRemove) {
    final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration();

    final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0);
    fadeOut.setDuration(duration);
    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(duration);
    fadeIn.setInterpolator(new AccelerateInterpolator());

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

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

private Animator getIconSelectionAnimator() {
    Animator animator = null;
    switch (mTabType) {
    case TAB_TYPE_OPTIONS:
        animator = ObjectAnimator.ofFloat(tabIcon, "rotation", 180);
        break;/*from   w  w  w .  ja v a2s . co  m*/
    case TAB_TYPE_WEB_HEADS:
        animator = ObjectAnimator.ofFloat(tabIcon, "rotation", 125);
        break;
    case TAB_TYPE_CUSTOMIZE:
        animator = ObjectAnimator.ofFloat(tabIcon, "scaleY", 1.2f);
        ((ObjectAnimator) animator).setRepeatMode(ValueAnimator.REVERSE);
        ((ObjectAnimator) animator).setRepeatCount(3);
        animator.setInterpolator(new LinearInterpolator());
        break;
    }
    if (animator != null)
        animator.setDuration(250);
    return animator;
}

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

@OnClick({ R.id.scrim, R.id.searchback })
protected void dismiss() {
    // translate the icon to match position in the launching activity
    searchBackContainer.animate().translationX(searchBackDistanceX).setDuration(600L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in))
            .setListener(new AnimatorListenerAdapter() {
                @Override//  w ww  .ja v a2  s  .  co m
                public void onAnimationEnd(Animator animation) {
                    finishAfterTransition();
                }
            }).start();
    // 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, android.R.interpolator.fast_out_linear_in))
            .setListener(null).start();
    searchBackground.animate().alpha(0f).setStartDelay(300L).setDuration(160L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in))
            .setListener(null).start();
    if (searchToolbar.getZ() != 0f) {
        searchToolbar.animate().z(0f).setDuration(600L)
                .setInterpolator(
                        AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in))
                .start();
    }

    // if we're showing search results, circular hide them
    if (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, android.R.interpolator.fast_out_linear_in))
            .setListener(null).start();
}

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

/**
 * @param timerToRemove the timer to be removed during the animation
 *///  ww  w  . j  a  v  a  2s  . c o  m
private void animateTimerRemove(final Timer timerToRemove) {
    final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration();

    final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0);
    fadeOut.setDuration(duration);
    fadeOut.setInterpolator(new DecelerateInterpolator());
    fadeOut.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            DataModel.getDataModel().removeTimer(timerToRemove);
            Events.sendTimerEvent(com.wizardsofm.deskclock.R.string.action_delete,
                    com.wizardsofm.deskclock.R.string.label_deskclock);
        }
    });

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

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

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();//from   w ww. j  av a2s . 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();
}

From source file:orbin.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// w w  w  .  j av a2s .c om
 */
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.
    updateFab(DISABLE_BUTTONS);

    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);
                Events.sendTimerEvent(R.string.action_delete, R.string.label_deskclock);
            }

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

    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();
}