public void animate(Matrix initial, Matrix target, ValueAnimator.AnimatorUpdateListener listener) { ValueAnimator animator = ValueAnimator.ofObject(new MatrixEvaluator(), initial, target); animator.addUpdateListener(new SafeListener(listener)); animator.setInterpolator(new AccelerateDecelerateInterpolator()); animator.setDuration(200); animator.start(); }
public void unSelect() { if (mCurrentState == STATE_UNSELECT) { return; } mCurrentState = STATE_UNSELECT; ValueAnimator valueAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), mLineColor, mBgLineColor); valueAnimator.setDuration(mDuration); valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { mFraction = 1 - valueAnimator.getAnimatedFraction(); mCurrentColor = (int) valueAnimator.getAnimatedValue(); invalidate(); } }); if (!valueAnimator.isRunning()) { valueAnimator.start(); } valueAnimator.start(); }
private ValueAnimator getBezierValueAnimator(LeafHolder target, RectF leafFlyRect, float progress) { BezierEvaluator evaluator = new BezierEvaluator(getPoint1(leafFlyRect), getPoint2(leafFlyRect)); int leafFlyStartY = (int) (mCurrentProgressBounds.bottom - mLeafDrawable.getIntrinsicHeight()); int leafFlyRange = (int) (mCurrentProgressBounds.height() - mLeafDrawable.getIntrinsicHeight()); int startPointY = leafFlyStartY - mRandom.nextInt(leafFlyRange); int endPointY = leafFlyStartY - mRandom.nextInt(leafFlyRange); ValueAnimator animator = ValueAnimator.ofObject(evaluator, new PointF((int) (leafFlyRect.right - mLeafDrawable.getIntrinsicWidth()), startPointY), new PointF(leafFlyRect.left, endPointY)); animator.addUpdateListener(new BezierListener(target)); animator.setTarget(target); animator.setDuration((long) ((mRandom.nextInt(300) + mDuration * DEFAULT_LEAF_FLY_DURATION_FACTOR) * (1.0f - progress))); return animator; }
public void select() { if (mCurrentState == STATE_SELECT) { return; } mCurrentState = STATE_SELECT; ValueAnimator valueAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), mBgLineColor, mLineColor); valueAnimator.setDuration(mDuration); valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { mFraction = valueAnimator.getAnimatedFraction(); mCurrentColor = (int) valueAnimator.getAnimatedValue(); invalidate(); } }); if (!valueAnimator.isRunning()) { valueAnimator.start(); } valueAnimator.start(); }
/** * Animate the text color of any view that extends {@link TextView} (Buttons, EditText...) */ public static void animateTextColor(final TextView view, long duration, @ColorInt final int colorStart, @ColorInt final int colorEnd) { if (DEBUG) { Log.d(TAG, "animateTextColor() called with: view = [" + view + "], duration = [" + duration + "], colorStart = [" + colorStart + "], colorEnd = [" + colorEnd + "]"); } ValueAnimator viewPropertyAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), colorStart, colorEnd); viewPropertyAnimator.setInterpolator(new FastOutSlowInInterpolator()); viewPropertyAnimator.setDuration(duration); viewPropertyAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { view.setTextColor((int) animation.getAnimatedValue()); } }); viewPropertyAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setTextColor(colorEnd); } @Override public void onAnimationCancel(Animator animation) { view.setTextColor(colorEnd); } }); viewPropertyAnimator.start(); }
/** * Animate the background color of a view */ public static void animateBackgroundColor(final View view, long duration, @ColorInt final int colorStart, @ColorInt final int colorEnd) { if (DEBUG) { Log.d(TAG, "animateBackgroundColor() called with: view = [" + view + "], duration = [" + duration + "], colorStart = [" + colorStart + "], colorEnd = [" + colorEnd + "]"); } final int[][] EMPTY = new int[][]{new int[0]}; ValueAnimator viewPropertyAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), colorStart, colorEnd); viewPropertyAnimator.setInterpolator(new FastOutSlowInInterpolator()); viewPropertyAnimator.setDuration(duration); viewPropertyAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { ViewCompat.setBackgroundTintList(view, new ColorStateList(EMPTY, new int[]{(int) animation.getAnimatedValue()})); } }); viewPropertyAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { ViewCompat.setBackgroundTintList(view, new ColorStateList(EMPTY, new int[]{colorEnd})); } @Override public void onAnimationCancel(Animator animation) { onAnimationEnd(animation); } }); viewPropertyAnimator.start(); }
/** * Update text color with animation */ public static void updateTextColor(final TextView textView, @ColorInt int fromColor, @ColorInt int toColor) { ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor); colorAnimation.setDuration(150); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { textView.setTextColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.start(); }
/** * Update text color with animation */ public static void updateViewBackgroundColor(final View view, @ColorInt int fromColor, @ColorInt int toColor) { ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor); colorAnimation.setDuration(150); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { view.setBackgroundColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.start(); }
/** * Update image view color with animation */ public static void updateDrawableColor(final Context context, final Drawable drawable, final ImageView imageView, @ColorInt int fromColor, @ColorInt int toColor, final boolean forceTint) { if (forceTint) { ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor); colorAnimation.setDuration(150); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { imageView.setImageDrawable(AHHelper.getTintDrawable(drawable, (Integer) animator.getAnimatedValue(), forceTint)); imageView.requestLayout(); } }); colorAnimation.start(); } }
protected void startColorAnim(final View view, final int startColor, final int endColor, long duration, Interpolator interpolator, final AnimationListener listener) { ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), startColor, endColor); anim.setDuration(duration); anim.setInterpolator(interpolator);
public CommonTabLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setWillNotDraw(false);//重写onDraw方法,需要调用这个方法来清除flag setClipChildren(false); setClipToPadding(false); this.mContext = context; mTabsContainer = new LinearLayout(context); addView(mTabsContainer); obtainAttributes(context, attrs); //get layout_height String height = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "layout_height"); //create ViewPager if (height.equals(ViewGroup.LayoutParams.MATCH_PARENT + "")) { } else if (height.equals(ViewGroup.LayoutParams.WRAP_CONTENT + "")) { } else { int[] systemAttrs = {android.R.attr.layout_height}; TypedArray a = context.obtainStyledAttributes(attrs, systemAttrs); mHeight = a.getDimensionPixelSize(0, ViewGroup.LayoutParams.WRAP_CONTENT); a.recycle(); } mValueAnimator = ValueAnimator.ofObject(new PointEvaluator(), mLastP, mCurrentP); mValueAnimator.addUpdateListener(this); }
public SegmentTabLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setWillNotDraw(false);//重写onDraw方法,需要调用这个方法来清除flag setClipChildren(false); setClipToPadding(false); this.mContext = context; mTabsContainer = new LinearLayout(context); addView(mTabsContainer); obtainAttributes(context, attrs); //get layout_height String height = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "layout_height"); //create ViewPager if (height.equals(ViewGroup.LayoutParams.MATCH_PARENT + "")) { } else if (height.equals(ViewGroup.LayoutParams.WRAP_CONTENT + "")) { } else { int[] systemAttrs = {android.R.attr.layout_height}; TypedArray a = context.obtainStyledAttributes(attrs, systemAttrs); mHeight = a.getDimensionPixelSize(0, ViewGroup.LayoutParams.WRAP_CONTENT); a.recycle(); } mValueAnimator = ValueAnimator.ofObject(new PointEvaluator(), mLastP, mCurrentP); mValueAnimator.addUpdateListener(this); }
/** * 爱心运动轨迹的动画实现 */ private ValueAnimator getBezierAnimtor(final View target) { BezierEvaluator evaluator = new BezierEvaluator(getPoint(2), getPoint(1)); ValueAnimator animator = ValueAnimator.ofObject(evaluator, new PointF((measuredWidth - drawableWidth) / 2, measuredHeight - drawableHeight), new PointF(mRandom.nextInt(getWidth()), 0)); animator.setDuration(3000); animator.setTarget(target); animator.addUpdateListener(valueAnimator -> { //获取贝塞尔曲线的运动轨迹 让爱心跟随着移动 PointF animatedValue = (PointF) valueAnimator.getAnimatedValue(); target.setX(animatedValue.x); target.setY(animatedValue.y); //增加透明度的变化 target.setAlpha(1 - valueAnimator.getAnimatedFraction()); }); return animator; }
static void changeImageColorFilter(final ImageView image, int fromColor, int toColor) { ValueAnimator imageColorChangeAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor); imageColorChangeAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { image.setColorFilter((Integer) animator.getAnimatedValue()); } }); imageColorChangeAnimation.setDuration(150); imageColorChangeAnimation.start(); }
static void changeViewBackgroundColor(final View view, int fromColor, int toColor) { ValueAnimator imageColorChangeAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor); imageColorChangeAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { view.setBackgroundColor((Integer) animator.getAnimatedValue()); } }); imageColorChangeAnimation.setDuration(150); imageColorChangeAnimation.start(); }
static void changeTextColor(final TextView textView, int fromColor, int toColor) { ValueAnimator changeTextColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor); changeTextColorAnimation.setDuration(150); changeTextColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { textView.setTextColor((Integer) animator.getAnimatedValue()); } }); changeTextColorAnimation.start(); }
public void animateBackground(int colorFrom,int colorTo){ ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { relativeLayout.setBackgroundColor((int) animator.getAnimatedValue()); } }); colorAnimation.start(); }
public void animateStatusActionBar(int colorFrom,int colorTo){ ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { getWindow().setStatusBarColor((int) animator.getAnimatedValue()); getSupportActionBar().setBackgroundDrawable(new ColorDrawable((int) animator.getAnimatedValue())); } }); colorAnimation.start(); }
private ValueAnimator genBezierAnimator(View target){ BezierEvaluator evaluator = new BezierEvaluator(getPoint(1),getPoint(2));//传入中间两个点 ValueAnimator valueAnimator = ValueAnimator.ofObject(evaluator,new PointF(mRandom.nextInt(mWidth-dWidth),-dHeight), new PointF(mRandom.nextInt(mWidth-dWidth),mHeight));//传入开始位置结束位置 valueAnimator.addUpdateListener(new BezierListener(target)); valueAnimator.addListener(new AnimatorEndListener(target)); valueAnimator.setTarget(target); valueAnimator.setDuration(3000); valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); return valueAnimator; }
private ValueAnimator getBezierValueAnimator(View target) { //初始化一个贝塞尔计算器- - 传入 BezierEvaluator evaluator = new BezierEvaluator(getPointF(2), getPointF(1)); //这里最好画个图 理解一下 传入了起点 和 终点 ValueAnimator animator = ValueAnimator.ofObject(evaluator, new PointF((mWidth - dWidth) / 2, mHeight - dHeight), new PointF(random.nextInt(getWidth()), 0)); animator.addUpdateListener(new BezierListener(target)); animator.setTarget(target); animator.setDuration(3000); return animator; }