android.animation.TimeInterpolator Java Examples

The following examples show how to use android.animation.TimeInterpolator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExitAnimation.java    From Depth with MIT License 6 votes vote down vote up
@Override
public void prepareAnimators(DepthRelativeLayout target, int index, int animationDelay) {
    final TimeInterpolator interpolator = new ExpoIn();

    final float finalTranslationY = exitConfiguration.getFinalYPercent() * target.getResources().getDisplayMetrics().heightPixels;
    final float finalTranslationX = exitConfiguration.getFinalXPercent() * target.getResources().getDisplayMetrics().widthPixels;

    final long totalDuration = exitConfiguration.getDuration();

    final ObjectAnimator translationY2 = ObjectAnimator.ofFloat(target, View.TRANSLATION_Y, finalTranslationY);
    translationY2.setDuration(totalDuration);
    //translationY2.setInterpolator(new AccelerateInterpolator());
    translationY2.setInterpolator(interpolator);
    translationY2.setStartDelay(animationDelay);
    attachListener(translationY2);
    add(translationY2);

    final ObjectAnimator translationX2 = ObjectAnimator.ofFloat(target, View.TRANSLATION_X, finalTranslationX);
    translationX2.setDuration(totalDuration);
    translationX2.setInterpolator(interpolator);
    translationX2.setStartDelay(animationDelay);
    add(translationX2);
}
 
Example #2
Source File: PageView.java    From Virtualview-Android with MIT License 6 votes vote down vote up
private TimeInterpolator getTimeInterpolater() {
    switch (mAnimationStyle) {
        case ViewBaseCommon.ANIMATION_LINEAR:
            return new LinearInterpolator();
        case ViewBaseCommon.ANIMATION_DECELERATE:
            return new DecelerateInterpolator();
        case ViewBaseCommon.ANIMATION_ACCELERATE:
            return new AccelerateInterpolator();
        case ViewBaseCommon.ANIMATION_ACCELERATEDECELERATE:
            return new AccelerateDecelerateInterpolator();
        case ViewBaseCommon.ANIMATION_SPRING:
            return new SpringInterpolator();
        default:
            return new LinearInterpolator();
    }
}
 
Example #3
Source File: StaggeredAnimationGroupTest.java    From StaggeredAnimationGroup with Apache License 2.0 6 votes vote down vote up
@Test
public void preparePartialTransition_setsPartialInterpolator() {
    //given
    final StaggeredAnimationGroup spiedGroup = prepareSpiedGroup();
    final TimeInterpolator testInterpolator = new LinearOutSlowInInterpolator();
    final Transition spiedTransition = spy(new AutoTransition());
    final StaggeredAnimationGroup.PartialTransitionFactory factory =
            new StaggeredAnimationGroup.PartialTransitionFactory() {
                @Override
                public Transition createPartialTransition(boolean show, int viewId, int indexInTransition) {
                    return spiedTransition;
                }
            };
    spiedGroup.setPartialTransitionFactory(factory);
    spiedGroup.setPartialInterpolator(testInterpolator);

    //when
    spiedGroup.preparePartialTransition(true, 0, 0);

    //then
    verify(spiedTransition, times(1)).setInterpolator(testInterpolator);
}
 
Example #4
Source File: ExpandableRelativeLayout.java    From ExpandableLayout with Apache License 2.0 6 votes vote down vote up
/**
 * Moves to bottom(VERTICAL) or right(HORIZONTAL) of child view
 * Sets 0 to duration if you want to move immediately.
 *
 * @param index        index child view index
 * @param duration
 * @param interpolator use the default interpolator if the argument is null.
 */
public void moveChild(int index, long duration, @Nullable TimeInterpolator interpolator) {
    if (isAnimating) return;

    final int destination = getChildPosition(index) +
            (isVertical() ? getPaddingBottom() : getPaddingRight());
    if (duration <= 0) {
        isExpanded = destination > closePosition;
        setLayoutSize(destination);
        requestLayout();
        notifyListeners();
        return;
    }
    createExpandAnimator(getCurrentPosition(), destination,
            duration, interpolator == null ? this.interpolator : interpolator).start();
}
 
Example #5
Source File: OverScroller.java    From Animer with Apache License 2.0 5 votes vote down vote up
public void setInterpolator(TimeInterpolator interpolator) {
    if (interpolator == null) {
        mInterpolator = SCROLL;
    } else {
        mInterpolator = interpolator;
    }
}
 
Example #6
Source File: TranslationAnimationCreator.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an animator that can be used for x and/or y translations. When interrupted,
 * it sets a tag to keep track of the position so that it may be continued from position.
 *
 * @param view The view being moved. This may be in the overlay for onDisappear.
 * @param values The values containing the view in the view hierarchy.
 * @param viewPosX The x screen coordinate of view
 * @param viewPosY The y screen coordinate of view
 * @param startX The start translation x of view
 * @param startY The start translation y of view
 * @param endX The end translation x of view
 * @param endY The end translation y of view
 * @param interpolator The interpolator to use with this animator.
 * @return An animator that moves from (startX, startY) to (endX, endY) unless there was
 * a previous interruption, in which case it moves from the current position to (endX, endY).
 */
static Animator createAnimation(View view, TransitionValues values, int viewPosX, int viewPosY,
        float startX, float startY, float endX, float endY, TimeInterpolator interpolator,
        Transition transition) {
    float terminalX = view.getTranslationX();
    float terminalY = view.getTranslationY();
    int[] startPosition = (int[]) values.view.getTag(R.id.transitionPosition);
    if (startPosition != null) {
        startX = startPosition[0] - viewPosX + terminalX;
        startY = startPosition[1] - viewPosY + terminalY;
    }
    // Initial position is at translation startX, startY, so position is offset by that amount
    int startPosX = viewPosX + Math.round(startX - terminalX);
    int startPosY = viewPosY + Math.round(startY - terminalY);

    view.setTranslationX(startX);
    view.setTranslationY(startY);
    if (startX == endX && startY == endY) {
        return null;
    }
    Path path = new Path();
    path.moveTo(startX, startY);
    path.lineTo(endX, endY);
    ObjectAnimator anim = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            path);

    TransitionPositionListener listener = new TransitionPositionListener(view, values.view,
            startPosX, startPosY, terminalX, terminalY);
    transition.addListener(listener);
    anim.addListener(listener);
    anim.addPauseListener(listener);
    anim.setInterpolator(interpolator);
    return anim;
}
 
Example #7
Source File: ViewPropertyAnimatorRT.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void doStartAnimation(ViewPropertyAnimator parent) {
    int size = parent.mPendingAnimations.size();

    long startDelay = parent.getStartDelay();
    long duration = parent.getDuration();
    TimeInterpolator interpolator = parent.getInterpolator();
    if (interpolator == null) {
        // Documented to be LinearInterpolator in ValueAnimator.setInterpolator
        interpolator = sLinearInterpolator;
    }
    if (!RenderNodeAnimator.isNativeInterpolator(interpolator)) {
        interpolator = new FallbackLUTInterpolator(interpolator, duration);
    }
    for (int i = 0; i < size; i++) {
        NameValuesHolder holder = parent.mPendingAnimations.get(i);
        int property = RenderNodeAnimator.mapViewPropertyToRenderProperty(holder.mNameConstant);

        final float finalValue = holder.mFromValue + holder.mDeltaValue;
        RenderNodeAnimator animator = new RenderNodeAnimator(property, finalValue);
        animator.setStartDelay(startDelay);
        animator.setDuration(duration);
        animator.setInterpolator(interpolator);
        animator.setTarget(mView);
        animator.start();

        mAnimators[property] = animator;
    }

    parent.mPendingAnimations.clear();
}
 
Example #8
Source File: TransitionAnimation.java    From candybar with Apache License 2.0 5 votes vote down vote up
private static void runEnterAnimation(MoveData moveData, TimeInterpolator interpolator) {
    final View toView = moveData.toView;
    toView.setPivotX(0);
    toView.setPivotY(0);
    toView.setScaleX(moveData.widthScale);
    toView.setScaleY(moveData.heightScale);
    toView.setTranslationX(moveData.leftDelta);
    toView.setTranslationY(moveData.topDelta);

    toView.animate().setDuration(moveData.duration).
            scaleX(1).scaleY(1).
            translationX(0).translationY(0).
            setInterpolator(interpolator);
}
 
Example #9
Source File: CircleProgressView.java    From Box with Apache License 2.0 5 votes vote down vote up
public void animateIndeterminate(int durationOneCircle,
                                 TimeInterpolator interpolator) {
    animator = ObjectAnimator.ofFloat(this, "startAngle", getStartAngle(), getStartAngle() + 360);
    if (interpolator != null) animator.setInterpolator(interpolator);
    animator.setDuration(durationOneCircle);
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.setRepeatMode(ValueAnimator.RESTART);
    animator.start();
}
 
Example #10
Source File: ExpandableSelectorAnimator.java    From ExpandableSelector with Apache License 2.0 5 votes vote down vote up
private void expandButtons() {
  int numberOfButtons = buttons.size();
  Animator[] animations = new Animator[numberOfButtons];
  for (int i = 0; i < numberOfButtons; i++) {
    View button = buttons.get(i);
    TimeInterpolator interpolator = getExpandAnimatorInterpolation();
    float toY = calculateExpandedYPosition(i);
    animations[i] = createAnimatorForButton(interpolator, button, toY);
  }
  playAnimatorsTogether(animations);
}
 
Example #11
Source File: AnimUtils.java    From materialup with Apache License 2.0 5 votes vote down vote up
@Override
public TimeInterpolator getInterpolator() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return mAnimator.getInterpolator();
    }
    if (mAnimator instanceof ObjectAnimator) {
        return ((ObjectAnimator) mAnimator).getInterpolator();
    }
    return null;
}
 
Example #12
Source File: TransitionAnimation.java    From candybar with Apache License 2.0 5 votes vote down vote up
public static MoveData startAnimation(Context context, final View toView, Bundle transitionBundle, Bundle savedInstanceState, final int duration, final TimeInterpolator interpolator) {
    final TransitionData transitionData = new TransitionData(context, transitionBundle);
    if (transitionData.imageFilePath != null) {
        setImageToView(toView, transitionData.imageFilePath);
    }
    final MoveData moveData = new MoveData();
    moveData.toView = toView;
    moveData.duration = duration;
    if (savedInstanceState == null) {
        ViewTreeObserver observer = toView.getViewTreeObserver();
        observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

            @Override
            public boolean onPreDraw() {
                toView.getViewTreeObserver().removeOnPreDrawListener(this);

                int[] screenLocation = new int[2];
                toView.getLocationOnScreen(screenLocation);
                moveData.leftDelta = transitionData.thumbnailLeft - screenLocation[0];
                moveData.topDelta = transitionData.thumbnailTop - screenLocation[1];

                moveData.widthScale = (float) transitionData.thumbnailWidth / toView.getWidth();
                moveData.heightScale = (float) transitionData.thumbnailHeight / toView.getHeight();

                runEnterAnimation(moveData, interpolator);

                return true;
            }
        });
    }
    return moveData;
}
 
Example #13
Source File: ExpandableRelativeLayout.java    From ExpandableLayout with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void collapse(final long duration, final @Nullable TimeInterpolator interpolator) {
    if (isAnimating) return;

    if (duration <= 0) {
        move(closePosition, duration, interpolator);
        return;
    }
    createExpandAnimator(getCurrentPosition(), closePosition, duration, interpolator).start();
}
 
Example #14
Source File: ChangeTranslation.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to handle creating and running the Animator.
 */
private Animator createAnimation(View view, float[] startTranslation, float[] endTranslation,
                                 Animator.AnimatorListener listener, TimeInterpolator interpolator) {
    if (startTranslation == null || endTranslation == null ||
            startTranslation.length != endTranslation.length || equals(startTranslation, endTranslation)) {
        // run listener if we're noop'ing the animation, to get the end-state results now
        if (listener != null) {
            listener.onAnimationEnd(null);
        }
        return null;
    }

    final AnimatorSet anim = new AnimatorSet();
    ObjectAnimator animX = null, animY = null;

    if ((mTranslationDirection & X) != 0) {
        animX = ObjectAnimator.ofFloat(view, View.X,
                startTranslation[0], endTranslation[0]);
    }

    if ((mTranslationDirection & Y) != 0) {
        animY = ObjectAnimator.ofFloat(view, View.Y,
                startTranslation[1], endTranslation[1]);
    }

    if (null != animX && null == animY) anim.play(animX);
    if (null == animX && null != animY) anim.play(animY);
    if (null != animX && null != animY) anim.playTogether(animX, animY);
    if (null == animX && null == animY) return null;

    if (listener != null) {
        anim.addListener(listener);
    }

    anim.setInterpolator(interpolator);
    return anim;
}
 
Example #15
Source File: SubtitleCollapsingTextHelper.java    From collapsingtoolbarlayout-subtitle with Apache License 2.0 5 votes vote down vote up
private static float lerp(
    float startValue, float endValue, float fraction, @Nullable TimeInterpolator interpolator) {
    if (interpolator != null) {
        fraction = interpolator.getInterpolation(fraction);
    }
    return AnimationUtils.lerp(startValue, endValue, fraction);
}
 
Example #16
Source File: FlatPlayerPlaybackControlsFragment.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
private static void addAnimation(Collection<Animator> animators, View view, TimeInterpolator interpolator, int duration, int delay) {
    Animator scaleX = ObjectAnimator.ofFloat(view, View.SCALE_X, 0f, 1f);
    scaleX.setInterpolator(interpolator);
    scaleX.setDuration(duration);
    scaleX.setStartDelay(delay);
    animators.add(scaleX);

    Animator scaleY = ObjectAnimator.ofFloat(view, View.SCALE_Y, 0f, 1f);
    scaleY.setInterpolator(interpolator);
    scaleY.setDuration(duration);
    scaleY.setStartDelay(delay);
    animators.add(scaleY);
}
 
Example #17
Source File: KeyframeAssert.java    From assertj-android with Apache License 2.0 5 votes vote down vote up
public KeyframeAssert hasInterpolator(TimeInterpolator interpolator) {
  isNotNull();
  TimeInterpolator actualInterpolator = actual.getInterpolator();
  assertThat(actualInterpolator) //
      .overridingErrorMessage("Expected interpolator <%s> but was <%s>.", interpolator,
          actualInterpolator) //
      .isSameAs(interpolator);
  return this;
}
 
Example #18
Source File: PagedView.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
protected void snapToPage(int whichPage, int duration, boolean immediate,
        TimeInterpolator interpolator) {
    whichPage = validateNewPage(whichPage);

    int newX = getScrollForPage(whichPage);
    final int delta = newX - getUnboundedScrollX();
    snapToPage(whichPage, delta, duration, immediate, interpolator);
}
 
Example #19
Source File: TransitionAnimation.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
private static void runEnterAnimation(MoveData moveData, TimeInterpolator interpolator, Animator.AnimatorListener listener) {
    final View toView = moveData.toView;
    toView.setPivotX(0);
    toView.setPivotY(0);
    toView.setScaleX(moveData.widthScale);
    toView.setScaleY(moveData.heightScale);
    toView.setTranslationX(moveData.leftDelta);
    toView.setTranslationY(moveData.topDelta);

    toView.animate().setDuration(moveData.duration).scaleX(1).scaleY(1).translationX(0).translationY(0).setListener(listener).setInterpolator(interpolator);
}
 
Example #20
Source File: ExpandableLinearLayout.java    From ExpandableLayout with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void collapse(final long duration, final @Nullable TimeInterpolator interpolator) {
    if (isAnimating) return;

    if (duration <= 0) {
        move(closePosition, duration, interpolator);
        return;
    }
    createExpandAnimator(getCurrentPosition(), closePosition, duration, interpolator).start();
}
 
Example #21
Source File: FlatPlayerPlaybackControlsFragment.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
private static void addAnimation(Collection<Animator> animators, View view, TimeInterpolator interpolator, int duration, int delay) {
    Animator scaleX = ObjectAnimator.ofFloat(view, View.SCALE_X, 0f, 1f);
    scaleX.setInterpolator(interpolator);
    scaleX.setDuration(duration);
    scaleX.setStartDelay(delay);
    animators.add(scaleX);

    Animator scaleY = ObjectAnimator.ofFloat(view, View.SCALE_Y, 0f, 1f);
    scaleY.setInterpolator(interpolator);
    scaleY.setDuration(duration);
    scaleY.setStartDelay(delay);
    animators.add(scaleY);
}
 
Example #22
Source File: FilmstripView.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
private void runAnimation(final ValueAnimator animator, final float startValue,
                          final float targetValue, final long duration_ms,
                          final TimeInterpolator interpolator)
{
    if (startValue == targetValue)
    {
        return;
    }
    animator.setInterpolator(interpolator);
    animator.setDuration(duration_ms);
    animator.setFloatValues(startValue, targetValue);
    animator.start();
}
 
Example #23
Source File: EyebrowsScaleAnimator.java    From Eyebrows with MIT License 5 votes vote down vote up
public EyebrowsScaleAnimator(int minDuration, int maxDuration, TimeInterpolator interpolator, float startSize, float endSize) {
    this.minDuration = minDuration;
    this.maxDuration = maxDuration;
    this.mInterpolator = interpolator;
    this.startSize = startSize;
    this.endSize = endSize;
}
 
Example #24
Source File: CircularRevealTransition.java    From CrazyDaily with Apache License 2.0 4 votes vote down vote up
@Override
public void setInterpolator(TimeInterpolator timeInterpolator) {
    mAnimator.setInterpolator(timeInterpolator);
}
 
Example #25
Source File: TransitionAnims.java    From ActivityOptionsICS with Eclipse Public License 1.0 4 votes vote down vote up
public TimeInterpolator getAnimsInterpolator() {
	return mTimeInterpolator;
}
 
Example #26
Source File: CircularFragReveal.java    From Man-Man with GNU General Public License v3.0 4 votes vote down vote up
public Builder setUnrevealInt(TimeInterpolator interpolator) {
    Log.d(TAG, "setUnrevealInt(interpolator[" + interpolator + "])");
    this.unrevealInterpolator = interpolator;
    return this;
}
 
Example #27
Source File: ScaleInAnimation.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
/**
 * @param interpolator
 *            The interpolator of the entire animation to set.
 */
public ScaleInAnimation setInterpolator(TimeInterpolator interpolator) {
	this.interpolator = interpolator;
	return this;
}
 
Example #28
Source File: ExplodeAnimation.java    From FriendBook with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return The interpolator of the entire animation.
 */
public TimeInterpolator getInterpolator() {
    return interpolator;
}
 
Example #29
Source File: Animation.java    From MusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
public static TimeInterpolator getEasingInterpolator(int id) {
    switch (id) {
        case 0:
            return new EasingInterpolator(Ease.LINEAR);
        case 1:
            return new EasingInterpolator(Ease.QUAD_IN);
        case 2:
            return new EasingInterpolator(Ease.QUAD_OUT);
        case 3:
            return new EasingInterpolator(Ease.QUAD_IN_OUT);
        case 4:
            return new EasingInterpolator(Ease.CUBIC_IN);
        case 5:
            return new EasingInterpolator(Ease.CUBIC_OUT);
        case 6:
            return new EasingInterpolator(Ease.CUBIC_IN_OUT);
        case 7:
            return new EasingInterpolator(Ease.QUART_IN);
        case 8:
            return new EasingInterpolator(Ease.QUART_OUT);
        case 9:
            return new EasingInterpolator(Ease.QUART_IN_OUT);
        case 10:
            return new EasingInterpolator(Ease.QUINT_IN);
        case 11:
            return new EasingInterpolator(Ease.QUINT_OUT);
        case 12:
            return new EasingInterpolator(Ease.QUINT_IN_OUT);
        case 13:
            return new EasingInterpolator(Ease.SINE_IN);
        case 14:
            return new EasingInterpolator(Ease.SINE_OUT);
        case 15:
            return new EasingInterpolator(Ease.SINE_IN_OUT);
        case 16:
            return new EasingInterpolator(Ease.BACK_IN);
        case 17:
            return new EasingInterpolator(Ease.BACK_OUT);
        case 18:
            return new EasingInterpolator(Ease.BACK_IN_OUT);
        case 19:
            return new EasingInterpolator(Ease.CIRC_IN);
        case 20:
            return new EasingInterpolator(Ease.CIRC_OUT);
        case 21:
            return new EasingInterpolator(Ease.CIRC_IN_OUT);
        case 22:
            return new EasingInterpolator(Ease.BOUNCE_IN);
        case 23:
            return new EasingInterpolator(Ease.BOUNCE_OUT);
        case 24:
            return new EasingInterpolator(Ease.BOUNCE_IN_OUT);
        case 25:
            return new EasingInterpolator(Ease.ELASTIC_IN);
        case 26:
            return new EasingInterpolator(Ease.ELASTIC_OUT);
        case 27:
            return new EasingInterpolator(Ease.ELASTIC_IN_OUT);
        default:
            return new EasingInterpolator(Ease.LINEAR);
    }
}
 
Example #30
Source File: BlinkAnimation.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
/**
 * @return The interpolator of the entire animation.
 */
public TimeInterpolator getInterpolator() {
	return interpolator;
}