Java Code Examples for android.animation.ValueAnimator#setInterpolator()

The following examples show how to use android.animation.ValueAnimator#setInterpolator() . 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: Case1Scene.java    From scene with Apache License 2.0 7 votes vote down vote up
@NonNull
@Override
protected Animator onPopAnimator(final AnimationInfo fromInfo, final AnimationInfo toInfo) {
    final View toView = toInfo.mSceneView;
    final View fromView = fromInfo.mSceneView;

    ValueAnimator fromAlphaAnimator = ObjectAnimator.ofFloat(fromView, View.ALPHA, 1.0f, 0.0f);
    fromAlphaAnimator.setInterpolator(new LinearInterpolator());
    fromAlphaAnimator.setDuration(150 * 20);
    fromAlphaAnimator.setStartDelay(50 * 20);

    ValueAnimator fromTranslateAnimator = ObjectAnimator.ofFloat(fromView, View.TRANSLATION_Y, 0, 0.08f * toView.getHeight());
    fromTranslateAnimator.setInterpolator(new AccelerateInterpolator(2));
    fromTranslateAnimator.setDuration(200 * 20);

    ValueAnimator toAlphaAnimator = ObjectAnimator.ofFloat(toView, View.ALPHA, 0.7f, 1.0f);
    toAlphaAnimator.setInterpolator(new LinearOutSlowInInterpolator());
    toAlphaAnimator.setDuration(20 * 20);
    return TransitionUtils.mergeAnimators(fromAlphaAnimator, fromTranslateAnimator, toAlphaAnimator);
}
 
Example 2
Source File: PreferenceCard.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
protected void animateOpen() {
    mExpanded = true;
    int toHeight = gap * 2;

    for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);
        child.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        toHeight += child.getMeasuredHeight();
    }

    ValueAnimator anim = ValueAnimator.ofInt(getHeight(), toHeight);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            getLayoutParams().height = (int) animation.getAnimatedValue();
            requestLayout();
        }
    });
    anim.setInterpolator(new DecelerateInterpolator());
    anim.start();
}
 
Example 3
Source File: SmoothCheckBox.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
private void startCheckedAnimation() {
    ValueAnimator animator = ValueAnimator.ofFloat(1.0f, 0f);
    animator.setDuration(mAnimDuration / 3 * 2);
    animator.setInterpolator(new LinearInterpolator());
    animator.addUpdateListener(animation -> {
        mScaleVal = (float) animation.getAnimatedValue();
        mFloorColor = getGradientColor(mUnCheckedColor, mCheckedColor, 1 - mScaleVal);
        postInvalidate();
    });
    animator.start();

    ValueAnimator floorAnimator = ValueAnimator.ofFloat(1.0f, 0.8f, 1.0f);
    floorAnimator.setDuration(mAnimDuration);
    floorAnimator.setInterpolator(new LinearInterpolator());
    floorAnimator.addUpdateListener(animation -> {
        mFloorScale = (float) animation.getAnimatedValue();
        postInvalidate();
    });
    floorAnimator.start();

    drawTickDelayed();
}
 
Example 4
Source File: RefreshCircleHeader.java    From timecat with Apache License 2.0 6 votes vote down vote up
@Override
public int onFinish(@NonNull RefreshLayout layout, boolean success) {
    mShowOuter = false;
    mShowBoll = false;
    ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mFinishRatio = (float) animation.getAnimatedValue();
            RefreshCircleHeader.this.invalidate();
        }
    });
    animator.setInterpolator(new AccelerateInterpolator());
    animator.setDuration(DURATION_FINISH);
    animator.start();
    return DURATION_FINISH;
}
 
Example 5
Source File: NumberAnimTextView.java    From Mobike with Apache License 2.0 6 votes vote down vote up
private void start() {
    if (!isEnableAnim) { // 禁止动画
        setText(mPrefixString + format(new BigDecimal(mNumEnd)) + mPostfixString);
        return;
    }
    ValueAnimator animator = ValueAnimator.ofObject(new BigDecimalEvaluator(), new BigDecimal(mNumStart), new BigDecimal(mNumEnd));
    animator.setDuration(mDuration);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            BigDecimal value = (BigDecimal) valueAnimator.getAnimatedValue();
            setText(mPrefixString + format(value) + mPostfixString);
        }
    });
    animator.start();
}
 
Example 6
Source File: PreferenceCard.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
protected void animateClosed() {
    mExpanded = false;
    int toHeight = gap * 2;
    toHeight += getChildAt(0).getHeight();

    ValueAnimator anim = ValueAnimator.ofInt(getHeight(), toHeight);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            getLayoutParams().height = (int) animation.getAnimatedValue();
            requestLayout();
        }
    });
    anim.setInterpolator(new DecelerateInterpolator());
    anim.start();
}
 
Example 7
Source File: BarVerticalChart.java    From OXChart with Apache License 2.0 5 votes vote down vote up
/**
 * 创建动画
 */
@Override
protected ValueAnimator initAnim() {
    if (dataList.size() > 0) {
        ValueAnimator anim = ValueAnimator.ofObject(new AngleEvaluator(), 0f, 1f);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        return anim;
    }
    return null;
}
 
Example 8
Source File: CallbackExampleComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
private static Animator createScaleAnimator(final DynamicValue<Float> scale) {
  final ValueAnimator scaleAnimator = ValueAnimator.ofFloat(1f, SCALE_TO, 1f);
  scaleAnimator.setDuration(ANIMATION_DURATION_MS);
  scaleAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
  scaleAnimator.addUpdateListener(
      new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
          scale.set((Float) animation.getAnimatedValue());
        }
      });
  return scaleAnimator;
}
 
Example 9
Source File: MultiTouchImageView.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
void animateScale(float start, float end, final float px, final float py) {
    final ValueAnimator animator = ValueAnimator.ofFloat(start, end);

    animator.setDuration(SCALE_ANIMATION_DURATION);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.addUpdateListener(valueAnimator -> {
        final float scale = (float) valueAnimator.getAnimatedValue();
        final float ds = scale / getScale();

        setScale(ds, px, py);
        setImageMatrix();
    });
    animator.start();
}
 
Example 10
Source File: DynamicPieChartViewOld.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private Animator b()
{
    ValueAnimator valueanimator = ValueAnimator.ofFloat(new float[] {
        0.0F, 1.0F
    });
    valueanimator.addListener(new m(this));
    valueanimator.addUpdateListener(new n(this));
    valueanimator.setDuration(3500L);
    valueanimator.setInterpolator(new LinearInterpolator());
    valueanimator.setRepeatMode(1);
    valueanimator.setRepeatCount(-1);
    return valueanimator;
}
 
Example 11
Source File: CircularSplashView.java    From HaiNaBaiChuan with Apache License 2.0 5 votes vote down vote up
public void startAnim() {
    RectF startRect = new RectF(targetSize.centerX(), targetSize.centerY(), targetSize.centerX(), targetSize.centerY());
    ValueAnimator rectSize = ValueAnimator.ofObject(new RectFEvaluator(), startRect, targetSize);
    rectSize.setDuration(animDuration);
    rectSize.setInterpolator(new QuintOut());
    rectSize.setStartDelay(startDelay);
    rectSize.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            drawingRect = (RectF) animation.getAnimatedValue();
            invalidate();
        }
    });
    rectSize.start();
}
 
Example 12
Source File: FloatingActionButtonImpl.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
private ValueAnimator createElevationAnimator(@NonNull ShadowAnimatorImpl impl) {
  final ValueAnimator animator = new ValueAnimator();
  animator.setInterpolator(ELEVATION_ANIM_INTERPOLATOR);
  animator.setDuration(ELEVATION_ANIM_DURATION);
  animator.addListener(impl);
  animator.addUpdateListener(impl);
  animator.setFloatValues(0, 1);
  return animator;
}
 
Example 13
Source File: DialogSceneAnimatorExecutor.java    From scene with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
protected Animator onPopAnimator(final AnimationInfo fromInfo, final AnimationInfo toInfo) {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(fromInfo.mSceneView.getAlpha(), 0.0f);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            fromInfo.mSceneView.setAlpha((float) animation.getAnimatedValue());
        }
    });
    valueAnimator.setInterpolator(new DecelerateInterpolator());
    valueAnimator.setDuration(ANIMATION_DURATION);
    return valueAnimator;
}
 
Example 14
Source File: SimpleAnimationUtils.java    From SimpleSearchView with Apache License 2.0 5 votes vote down vote up
public static Animator verticalSlideView(@NonNull View view, int fromHeight, int toHeight, int duration, @Nullable final AnimationListener listener) {
    ValueAnimator anim = ValueAnimator
            .ofInt(fromHeight, toHeight);

    anim.addUpdateListener(animation -> {
        view.getLayoutParams().height = (int) (Integer) animation.getAnimatedValue();
        view.requestLayout();
    });

    anim.addListener(new DefaultActionAnimationListener(view, listener));

    anim.setDuration(duration);
    anim.setInterpolator(getDefaultInterpolator());
    return anim;
}
 
Example 15
Source File: AnimationUtils.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
public static void removeBookmarkWithAnimation(@NonNull final View bookmarkImage, Animator.AnimatorListener animatorListener) {
    bookmarkImage.setPivotY(0);
    ValueAnimator moveAnim = ObjectAnimator.ofFloat(bookmarkImage, View.SCALE_Y, 1, 2, 0);
    moveAnim.setDuration(1000);
    moveAnim.setInterpolator(new DecelerateInterpolator());
    moveAnim.addListener(animatorListener);
    moveAnim.start();
}
 
Example 16
Source File: SampleActivity.java    From CompositionAvatar with MIT License 5 votes vote down vote up
private void dynamicGap(CompositionAvatarView view) {
    ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
    animator.setDuration(2000);
    animator.setStartDelay(1000);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.addUpdateListener(animation -> view.setGap((Float) animation.getAnimatedValue()));

    mGapAnimator = animator;
}
 
Example 17
Source File: ProSwipeButton.java    From proSwipeButton with MIT License 5 votes vote down vote up
private void animateHintBack() {
    final ValueAnimator positionAnimator =
            ValueAnimator.ofFloat(arrowHintContainer.getX(), 0);
    positionAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    positionAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float x = (Float) positionAnimator.getAnimatedValue();
            arrowHintContainer.setX(x);
        }
    });

    positionAnimator.setDuration(200);
    positionAnimator.start();
}
 
Example 18
Source File: PlayerFragment.java    From android-material-motion with Apache License 2.0 4 votes vote down vote up
@OnClick(R.id.fab)
public void onButtonClick() {
  setUpPauseDrawable();
  final float playPauseY = playPause.getY() + background.getY();
  float endX = background.getWidth() / 2;
  float endY = playPauseY + playPause.getHeight() / 2;
  float startX = 0;
  float startY = 0;
  final float curveRadius = background.getHeight() / 3;

  final float offsetX = endX - (actionButton.getX() + actionButton.getWidth() / 2);
  final float offsetY = endY - (actionButton.getY() + actionButton.getHeight() / 2);

  endX = offsetX;
  endY = offsetY;

  Path arcPath = new Path();

  float midX = startX + ((endX - startX) / 2);
  float midY = startY + ((endY - startY) / 2);
  float xDiff = midX - startX;
  float yDiff = midY - startY;

  double angle = (Math.atan2(yDiff, xDiff) * (180 / Math.PI)) - 90;
  double angleRadians = Math.toRadians(angle);

  float pointX = (float) (midX + curveRadius * Math.cos(angleRadians));
  float pointY = (float) (midY + curveRadius * Math.sin(angleRadians));

  arcPath.moveTo(0, 0);
  arcPath.cubicTo(0, 0, pointX, pointY, endX, endY);

  ValueAnimator pathAnimator = ValueAnimator.ofFloat(0, 1);
  pathAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    private float point[] = new float[2];
    private volatile boolean isFired;
    private PathMeasure pathMeasure = new PathMeasure(arcPath, false);

    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
      final float value = animation.getAnimatedFraction();
      // Gets the point at the fractional path length
      pathMeasure.getPosTan(pathMeasure.getLength() * value, point, null);

      // Sets view location to the above point
      actionButton.setTranslationX(point[0]);
      actionButton.setTranslationY(point[1]);

      if (!isFired) {
        if (animation.getAnimatedFraction() >= 0.35) {
          isFired = true;
          setUpReveal();
          runButtonAnimation();
          //reveal and animate the thumb
          runRevealNProgress();
          //stretch out the top divider
          runTopDividerScale();
          //expand the bottom divider
          runBottomDividerScale();
          //scale icon, swap icon, scale icon
          runIconScale(0, R.drawable.ic_play_bottom, Color.WHITE);
        }
      }
    }
  });
  pathAnimator.setInterpolator(new DecelerateInterpolator());
  pathAnimator.setDuration(duration(R.integer.path_duration));
  pathAnimator.start();
}
 
Example 19
Source File: ColorFade.java    From Camera-Roll-Android-App with Apache License 2.0 4 votes vote down vote up
private static ValueAnimator getDefaultValueAnimator(int startValue, int endValue) {
    ValueAnimator animator = ValueAnimator.ofInt(startValue, endValue);
    animator.setDuration(500);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    return animator;
}
 
Example 20
Source File: ElasticBallBuilder.java    From AndroidWallet with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void computeUpdateValue(ValueAnimator animation, @FloatRange(from = 0.0, to = 1.0) float animatedValue)
{
    float offset = mCanvasTranslateOffset;
    int currState = mIsReverse ? mCurrAnimatorState + 3 : mCurrAnimatorState;
    switch (currState)
    {
        case 0:
            animation.setDuration(mDurationTime);
            animation.setInterpolator(new AccelerateInterpolator());
            mBallPoints.get(5).setOffsetX(animatedValue * offset);
            mBallPoints.get(6).setOffsetX(animatedValue * offset);
            mBallPoints.get(7).setOffsetX(animatedValue * offset);
            break;
        case 1:
            animation.setDuration(mDurationTime + 111);
            animation.setInterpolator(new DecelerateInterpolator());
            mBallPoints.get(2).setOffsetX(animatedValue * offset);
            mBallPoints.get(3).setOffsetX(animatedValue * offset);
            mBallPoints.get(4).setOffsetX(animatedValue * offset);
            mBallPoints.get(8).setOffsetX(animatedValue * offset);
            mBallPoints.get(9).setOffsetX(animatedValue * offset);
            mBallPoints.get(10).setOffsetX(animatedValue * offset);
            break;
        case 2:
            animation.setDuration(mDurationTime + 333);
            animation.setInterpolator(new BounceInterpolator());
            mBallPoints.get(0).setOffsetX(animatedValue * offset);
            mBallPoints.get(1).setOffsetX(animatedValue * offset);
            mBallPoints.get(11).setOffsetX(animatedValue * offset);
            break;
        case 3:
            animation.setDuration(mDurationTime);
            animation.setInterpolator(new AccelerateInterpolator());
            mBallPoints.get(0).setOffsetX((1 - animatedValue) * offset);
            mBallPoints.get(1).setOffsetX((1 - animatedValue) * offset);
            mBallPoints.get(11).setOffsetX((1 - animatedValue) * offset);
            break;
        case 4:
            animation.setDuration(mDurationTime + 111);
            animation.setInterpolator(new DecelerateInterpolator());
            mBallPoints.get(2).setOffsetX((1 - animatedValue) * offset);
            mBallPoints.get(3).setOffsetX((1 - animatedValue) * offset);
            mBallPoints.get(4).setOffsetX((1 - animatedValue) * offset);
            mBallPoints.get(8).setOffsetX((1 - animatedValue) * offset);
            mBallPoints.get(9).setOffsetX((1 - animatedValue) * offset);
            mBallPoints.get(10).setOffsetX((1 - animatedValue) * offset);
            break;
        case 5:
            animation.setDuration(mDurationTime + 333);
            animation.setInterpolator(new BounceInterpolator());
            mBallPoints.get(5).setOffsetX((1 - animatedValue) * offset);
            mBallPoints.get(6).setOffsetX((1 - animatedValue) * offset);
            mBallPoints.get(7).setOffsetX((1 - animatedValue) * offset);
            break;
        default:
            break;
    }
}