Java Code Examples for android.animation.ValueAnimator

The following examples show how to use android.animation.ValueAnimator. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
private void revealImageCircular() {
    int x = getX();
    int y = getY();
    int radius = getRadius();

    ValueAnimator anim =
            ViewAnimationUtils.createCircularReveal(mImageView, x, y, 0, radius);

    anim.setDuration( 1000 );
    anim.addListener( new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            mImageView.setVisibility( View.VISIBLE );
        }
    });

    anim.start();
}
 
Example 2
Source Project: SphereLayout   Source File: SLTouchListener.java    License: MIT License 6 votes vote down vote up
public SLTouchListener(SphereLayout sphereLayout) {
    mSphereLayout = sphereLayout;
    mTouchSlop = ViewConfiguration.get(mSphereLayout.getContext()).getScaledTouchSlop();
    mInterpolator = new SpringInterpolator();
    mState = new RotateState();

    mRotateAnimator = new ValueAnimator();
    mRotateAnimator.setInterpolator(mInterpolator);
    mRotateAnimator.setIntValues(MAX_ROTATE_DEGREE, 0);
    mRotateAnimator.setDuration(DURATION);

    mRotateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mState.rotateDegree = (Integer) animation.getAnimatedValue();
            mSphereLayout.rotate(mState.direction, mState.rotateDegree);
        }
    });

    mFixAnimator = new ValueAnimator();
    mFixAnimator.setInterpolator(new DecelerateInterpolator());
}
 
Example 3
Source Project: VirtualLocation   Source File: PreciseLocationActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 使组件变回原有形状
 * @param view
 */
private void repaintView(final View view){
    AnimatorSet set = new AnimatorSet();

    ValueAnimator animator = ValueAnimator.ofFloat(width, 0);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mBeginLocation
                    .getLayoutParams();
            params.leftMargin = (int) value;
            params.rightMargin = (int) value;
            view.setLayoutParams(params);
        }
    });

    ObjectAnimator animator2 = ObjectAnimator.ofFloat(view,
            "scaleX", 0.5f, 1f);
    set.setDuration(1000);
    set.setInterpolator(new AccelerateDecelerateInterpolator());
    set.playTogether(animator, animator2);
    set.start();
}
 
Example 4
Source Project: RefreshLayout   Source File: RefreshAnimeUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void startScaleAnime(final View view,
                                   float newScale, Animator.AnimatorListener listener) {
    ValueAnimator anime = ValueAnimator.ofFloat(view.getScaleX(), newScale);
    anime.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float s = Float.parseFloat(animation.getAnimatedValue().toString());
            view.setScaleX(s);
            view.setScaleY(s);
        }
    });
    if (listener != null) {
        anime.addListener(listener);
    }
    anime.setDuration(mAnimeDuration);
    anime.start();
}
 
Example 5
Source Project: AndroidDemo   Source File: PointView.java    License: Apache License 2.0 6 votes vote down vote up
private void startAnimation() {
	Point startPoint = new Point(RADIUS, RADIUS);
	Point endPoint = new Point(getWidth() - RADIUS, getHeight() - RADIUS);
	ValueAnimator anim = ValueAnimator.ofObject(new PointEvaluator(), startPoint, endPoint);
	anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
		@Override
		public void onAnimationUpdate(ValueAnimator animation) {
			currentPoint = (Point) animation.getAnimatedValue();
			invalidate();
		}
	});
	ObjectAnimator anim2 = ObjectAnimator.ofObject(this, "color", new ColorEvaluator(),
			"#00FFFF", "#FF1100");
	AnimatorSet animSet = new AnimatorSet();
	animSet.play(anim).with(anim2);
	animSet.setDuration(5000);
	animSet.start();
}
 
Example 6
Source Project: crystal-preloaders   Source File: Chronos.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected List<ValueAnimator> setupAnimation() {
    valueAnimator = ValueAnimator.ofInt(0, 360);
    valueAnimator.setDuration(7000);
    valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
    valueAnimator.setRepeatMode(ValueAnimator.RESTART);
    valueAnimator.setInterpolator(new LinearInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            degree = (int) animation.getAnimatedValue();
            getTarget().invalidate();
        }
    });

    // create animator list
    final List<ValueAnimator> animators = new ArrayList<>();
    animators.add(valueAnimator);

    return animators;
}
 
Example 7
Source Project: SmartLoadingView   Source File: SmartLoadingView.java    License: MIT License 6 votes vote down vote up
/**
 * 绘制对勾的动画
 */
private void set_draw_ok_animation() {
    animator_draw_ok = ValueAnimator.ofFloat(1, 0);
    animator_draw_ok.setDuration(duration);
    animator_draw_ok.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            startDrawOk = true;
            isDrawLoading = false;
            float value = (Float) animation.getAnimatedValue();
            effect = new DashPathEffect(new float[]{pathMeasure.getLength(), pathMeasure.getLength()}, value * pathMeasure.getLength());
            okPaint.setPathEffect(effect);
            invalidate();

        }
    });
}
 
Example 8
private void addObservable() {
    //如果是With和After的,则设置AnimatorListener监听,With和After共用一个监听
    //如果是Between的,则设置UpdateListener监听
    for (int i = 0; i < mAllNodes.size(); ++i) {
        AnimNode node = mAllNodes.get(i);
        if (node.withAbservable != null
                && node.withAbservable.size() > 0)
            node.mAnim.addListener(new WithAndAfterListener(node));
        if (node.afterAbservable != null &&
                node.afterAbservable.size() > 0)
            if (node.mAnim.getListeners() == null
                    || node.mAnim.getListeners().size() == 0)
                node.mAnim.addListener(new WithAndAfterListener(node));
        if (node.betweenAbservable != null &&
                node.betweenAbservable.size() > 0)
            if (node.mAnim instanceof ValueAnimator)
                ((ValueAnimator) node.mAnim).addUpdateListener(new BetweenListener(node));
    }
}
 
Example 9
Source Project: CoolAndroidAnim   Source File: DLetter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void startAnim() {
    mAnimator = ValueAnimator.ofFloat(0, 1).setDuration(mDuration);
    mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float factor = (float) animation.getAnimatedValue();
            //竖线
            mSecPoint.y = (int) (mFirPoint.y - mLineLength * factor);
            if (factor > 0.333f) {
                //2/3处开始画圆
                float zoroToOne = (factor - 0.333f) * 3 / 2;
                mSweepAngle = -(int) (360 * zoroToOne);
            }
        }
    });
    mAnimator.start();
}
 
Example 10
Source Project: OXChart   Source File: BaseChart.java    License: Apache License 2.0 6 votes vote down vote up
protected void startAnimation(Canvas canvas) {
    if(anim!=null){
        anim.cancel();
    }
    LogUtil.w(TAG, "开始绘制动画");
    anim = initAnim();
    if(anim==null){
        drawChart(canvas);
    }else{
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.addUpdateListener((ValueAnimator animation)->{
            evaluatorData(animation);
            invalidate();
        });
        anim.setDuration(animDuration);
        anim.start();
    }
}
 
Example 11
Source Project: RollSquareView   Source File: RollSquareView.java    License: Apache License 2.0 6 votes vote down vote up
private ValueAnimator createRollValueAnimator() {
        ValueAnimator rollAnim = ValueAnimator.ofFloat(0, 90).setDuration(mSpeed);
//        rollAnim.setInterpolator(mRollInterpolator);
        rollAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                Object animatedValue = animation.getAnimatedValue();
                mRotateDegree = (float) animatedValue;
                if (!isHardwareAccelerated()) {
                    invalidate(mDirtyRect);
                } else {
                    invalidate();
                }
            }
        });
        return rollAnim;
    }
 
Example 12
Source Project: scene   Source File: Case3Scene.java    License: Apache License 2.0 6 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 13
Source Project: widgetlab   Source File: BouncingSlidingDotView.java    License: Apache License 2.0 6 votes vote down vote up
@NonNull
private AnimatorSet getMoveAnimator(long ratioAnimationTotalDuration) {
    AnimatorSet moveAnimatorSet = new AnimatorSet();

    ValueAnimator slidingAnimator = ValueAnimator.ofInt(startLeft, 0);
    slidingAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            targetLeft = (int) animator.getAnimatedValue();
            invalidate();
        }
    });
    slidingAnimator.setInterpolator(new LinearInterpolator());
    slidingAnimator.setDuration(ratioAnimationTotalDuration);

    AnimatorSet bounceSet = getBounceAnimatorSet(ratioAnimationTotalDuration);

    moveAnimatorSet.playTogether(slidingAnimator, bounceSet);
    return moveAnimatorSet;
}
 
Example 14
Source Project: FlycoTabLayout   Source File: CommonTabLayout.java    License: MIT License 6 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    View currentTabView = mTabsContainer.getChildAt(this.mCurrentTab);
    IndicatorPoint p = (IndicatorPoint) animation.getAnimatedValue();
    mIndicatorRect.left = (int) p.left;
    mIndicatorRect.right = (int) p.right;

    if (mIndicatorWidth < 0) {   //indicatorWidth小于0时,原jpardogo's PagerSlidingTabStrip

    } else {//indicatorWidth大于0时,圆角矩形以及三角形
        float indicatorLeft = p.left + (currentTabView.getWidth() - mIndicatorWidth) / 2;

        mIndicatorRect.left = (int) indicatorLeft;
        mIndicatorRect.right = (int) (mIndicatorRect.left + mIndicatorWidth);
    }
    invalidate();
}
 
Example 15
Source Project: Camera2   Source File: AnimatedCircleDrawable.java    License: Apache License 2.0 6 votes vote down vote up
public void animateToFullSize()
{
    final ValueAnimator animator =
            ValueAnimator.ofInt(getLevel(), DRAWABLE_MAX_LEVEL);
    animator.setDuration(CIRCLE_ANIM_DURATION_MS);
    animator.setInterpolator(Gusterpolator.INSTANCE);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
    {
        @Override
        public void onAnimationUpdate(ValueAnimator animation)
        {
            setLevel((Integer) animation.getAnimatedValue());
        }
    });
    animator.start();
}
 
Example 16
Source Project: ReadMark   Source File: RLetterS.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void startAnim() {
    mAnimator = ValueAnimator.ofFloat(0, 1);
    mAnimator.setDuration(mDuration);
    mAnimator.setRepeatCount(0);
    mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float factor = (float) animation.getAnimatedValue();
            mSweepArg = (int) (90 * factor);
            mSecPoint.y = (int) (mFirPoint.y + 2 * MAX_RADIUS_CIRCLE * factor);

        }
    });
    mAnimator.start();
}
 
Example 17
Source Project: LaunchEnr   Source File: DragView.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void animateFilterTo(float[] targetFilter) {
    float[] oldFilter = mCurrentFilter == null ? new ColorMatrix().getArray() : mCurrentFilter;
    mCurrentFilter = Arrays.copyOf(oldFilter, oldFilter.length);

    if (mFilterAnimator != null) {
        mFilterAnimator.cancel();
    }
    mFilterAnimator = ValueAnimator.ofObject(new FloatArrayEvaluator(mCurrentFilter),
            oldFilter, targetFilter);
    mFilterAnimator.setDuration(COLOR_CHANGE_DURATION);
    mFilterAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mPaint.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
            invalidate();
        }
    });
    mFilterAnimator.start();
}
 
Example 18
Source Project: SprintNBA   Source File: MaterialWaveView.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onRefreshing(MaterialRefreshLayout br) {
    setHeadHeight((int) (Util.dip2px(getContext(), DefaulHeadHeight)));
    ValueAnimator animator = ValueAnimator.ofInt(getWaveHeight(),0);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            //Log.i("anim", "value--->" + (int) animation.getAnimatedValue());
            setWaveHeight((int) animation.getAnimatedValue());
            invalidate();
        }
    });
    animator.setInterpolator(new BounceInterpolator());
    animator.setDuration(200);
    animator.start();
}
 
Example 19
Source Project: Slide   Source File: CreateCardView.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static ValueAnimator slideAnimator(int start, int end, final View v) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.setInterpolator(new FastOutSlowInInterpolator());

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            //Update Height
            int value = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
            layoutParams.height = value;
            v.setLayoutParams(layoutParams);
        }
    });
    return animator;
}
 
Example 20
Source Project: BottomNavigation   Source File: BottomNavigationTab.java    License: Apache License 2.0 6 votes vote down vote up
public void unSelect(boolean setActiveColor, int animationDuration) {
    isActive = false;

    ValueAnimator animator = ValueAnimator.ofInt(containerView.getPaddingTop(), paddingTopInActive);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            containerView.setPadding(containerView.getPaddingLeft(),
                    (Integer) valueAnimator.getAnimatedValue(),
                    containerView.getPaddingRight(),
                    containerView.getPaddingBottom());
        }
    });
    animator.setDuration(animationDuration);
    animator.start();

    labelView.setTextColor(mInActiveColor);
    iconView.setSelected(false);

    if (badgeItem != null) {
        badgeItem.unSelect();
    }
}
 
Example 21
Source Project: UltimateAndroid   Source File: DownloadProgressBar.java    License: Apache License 2.0 6 votes vote down vote up
private void setCurrentPlayTimeByStateAndPlay(long[] tab, State mState) {
    switch (mState) {
        case ANIMATING_LINE_TO_DOT:
            mArrowToLineAnimatorSet.start();
            for (int i = 0; i < mArrowToLineAnimatorSet.getChildAnimations().size(); i++) {
                ((ValueAnimator) mArrowToLineAnimatorSet.getChildAnimations().get(i)).setCurrentPlayTime(tab[i]);
            }
            break;
        case ANIMATING_PROGRESS:
            mProgressAnimationSet.start();
            for (int i = 0; i < mProgressAnimationSet.getChildAnimations().size(); i++) {
                ((ValueAnimator) mProgressAnimationSet.getChildAnimations().get(i)).setCurrentPlayTime(tab[i]);
            }
            break;
        case ANIMATING_ERROR:
            mErrorAnimation.start();
            mErrorAnimation.setCurrentPlayTime(tab[0]);
            break;
        case ANIMATING_SUCCESS:
            mSuccessAnimation.start();
            mSuccessAnimation.setCurrentPlayTime(tab[0]);
            break;
    }
}
 
Example 22
Source Project: LaunchEnr   Source File: SwipeHelper.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void snapChild(final View animView, final float targetLeft, float velocity) {
    final boolean canBeDismissed = mCallback.canChildBeDismissed(animView);
    AnimatorUpdateListener updateListener = new AnimatorUpdateListener() {
        public void onAnimationUpdate(ValueAnimator animation) {
            onTranslationUpdate(animView, (float) animation.getAnimatedValue(), canBeDismissed);
        }
    };

    Animator anim = getViewTranslationAnimator(animView, targetLeft, updateListener);
    if (anim == null) {
        return;
    }
    int duration = SNAP_ANIM_LEN;
    anim.setDuration(duration);
    anim.addListener(new AnimatorListenerAdapter() {
        public void onAnimationEnd(Animator animator) {
            mSnappingChild = false;
            updateSwipeProgressFromOffset(animView, canBeDismissed);
            mCallback.onChildSnappedBack(animView, targetLeft);
        }
    });
    prepareSnapBackAnimation(animView, anim);
    mSnappingChild = true;
    anim.start();
}
 
Example 23
Source Project: narrate-android   Source File: PreferenceCard.java    License: 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 24
Source Project: android_9.0.0_r45   Source File: DragState.java    License: Apache License 2.0 6 votes vote down vote up
private ValueAnimator createCancelAnimationLocked() {
    final ValueAnimator animator = ValueAnimator.ofPropertyValuesHolder(
            PropertyValuesHolder.ofFloat(
                    ANIMATED_PROPERTY_X, mCurrentX - mThumbOffsetX, mCurrentX),
            PropertyValuesHolder.ofFloat(
                    ANIMATED_PROPERTY_Y, mCurrentY - mThumbOffsetY, mCurrentY),
            PropertyValuesHolder.ofFloat(ANIMATED_PROPERTY_SCALE, 1, 0),
            PropertyValuesHolder.ofFloat(ANIMATED_PROPERTY_ALPHA, mOriginalAlpha, 0));
    final AnimationListener listener = new AnimationListener();
    animator.setDuration(MIN_ANIMATION_DURATION_MS);
    animator.setInterpolator(mCubicEaseOutInterpolator);
    animator.addListener(listener);
    animator.addUpdateListener(listener);

    mService.mAnimationHandler.post(() -> animator.start());
    return animator;
}
 
Example 25
public void testObjectAnimator(View v) {
    if (v.getId() == R.id.sdi_objectanimator_btn) {
        // 简单示例:View的横向移动
        ObjectAnimator.ofFloat(mAnimView, "translationX", 0.0f, -200.0f)
                .setDuration(C.Int.ANIM_DURATION * 2)
                .start();
    } else {
        // 复合示例:View弹性落下然后弹起,执行一次
        ObjectAnimator yBouncer = ObjectAnimator.ofFloat(mAnimView, "y", mAnimView.getY(), 400.0f);
        yBouncer.setDuration(C.Int.ANIM_DURATION * 2);
        // 设置插值器(用于调节动画执行过程的速度)
        yBouncer.setInterpolator(new BounceInterpolator());
        // 设置重复次数(缺省为0,表示不重复执行)
        yBouncer.setRepeatCount(1);
        // 设置重复模式(RESTART或REVERSE),重复次数大于0或INFINITE生效
        yBouncer.setRepeatMode(ValueAnimator.REVERSE);
        // 设置动画开始的延时时间(200ms)
        yBouncer.setStartDelay(200);
        yBouncer.start();
    }
}
 
Example 26
private void fadeIn() {
    int colorFrom = Color.parseColor("#00000000");
    int colorTo = Color.parseColor("#40000000");
    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
    colorAnimation.setDuration(250); // milliseconds
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            setBackgroundColor((int) animator.getAnimatedValue());
        }

    });
    colorAnimation.start();
}
 
Example 27
Source Project: BeerSwipeRefresh   Source File: BeerView.java    License: Apache License 2.0 5 votes vote down vote up
@Override protected void onDetachedFromWindow() {
  if (mAlphaAnimator != null) {
    mAlphaAnimator.end();
    mAlphaAnimator.removeAllUpdateListeners();
  }
  for (ValueAnimator animator : mFrothAnimators) {
    if (animator != null) {
      animator.end();
      animator.removeAllUpdateListeners();
    }
  }
  super.onDetachedFromWindow();
}
 
Example 28
Source Project: PinchImageView   Source File: PinchImageView.java    License: MIT License 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    //移动图像并给出结果
    boolean result = scrollBy(mVector[0], mVector[1]);
    //衰减速度
    mVector[0] *= FLING_DAMPING_FACTOR;
    mVector[1] *= FLING_DAMPING_FACTOR;
    //速度太小或者不能移动了就结束
    if (!result || MathUtils.getDistance(0, 0, mVector[0], mVector[1]) < 1f) {
        animation.cancel();
    }
}
 
Example 29
public ChartViewportAnimatorV14(Chart chart) {
    this.chart = chart;
    animator = ValueAnimator.ofFloat(0.0f, 1.0f);
    animator.addListener(this);
    animator.addUpdateListener(this);
    animator.setDuration(FAST_ANIMATION_DURATION);
}
 
Example 30
Source Project: PieChartView   Source File: PieChartView.java    License: Apache License 2.0 5 votes vote down vote up
private void startAnim() {
    animator = ValueAnimator.ofFloat(0, 360f * 2);
    animator.setDuration(animDuration);
    animator.setInterpolator(new LinearInterpolator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            if (value < 360f) {
                offRadius = value;
                offLine = 0;
                textAlpha = 0;
            } else if (value >= 360f) {
                offRadius = 360f;
                offLine = (value - 360f) / 360f;
                if (offLine > 0.5f) {
                    textAlpha = (int) (255 * ((offLine - 0.5f) / 0.5f));
                } else {
                    textAlpha = 0;
                }
            } else if (value == 360f * 2) {
                offRadius = 360f;
                offLine = 1.0f;
                textAlpha = 255;
            }
            postInvalidate();
        }
    });
    animator.start();
}