Search in sources :

Example 61 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project UltimateAndroid by cymcsg.

the class DraggableFlagView method startRollBackAnimation.

/**
     * 回滚状态动画
     */
private void startRollBackAnimation(long duration) {
    ValueAnimator rollBackAnim = ValueAnimator.ofFloat(curRadius, originRadius);
    rollBackAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            curRadius = (int) value;
            postInvalidate();
        }
    });
    // 反弹效果
    rollBackAnim.setInterpolator(new BounceInterpolator());
    rollBackAnim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            DraggableFlagView.this.clearAnimation();
        }
    });
    rollBackAnim.setDuration(duration);
    rollBackAnim.start();
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) BounceInterpolator(android.view.animation.BounceInterpolator) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 62 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project SimplifyReader by chentao0707.

the class SmoothImageView method startTransform.

private void startTransform(final int state) {
    if (mTransfrom == null) {
        return;
    }
    ValueAnimator valueAnimator = new ValueAnimator();
    valueAnimator.setDuration(300);
    valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    if (state == STATE_TRANSFORM_IN) {
        PropertyValuesHolder scaleHolder = PropertyValuesHolder.ofFloat("scale", mTransfrom.startScale, mTransfrom.endScale);
        PropertyValuesHolder leftHolder = PropertyValuesHolder.ofFloat("left", mTransfrom.startRect.left, mTransfrom.endRect.left);
        PropertyValuesHolder topHolder = PropertyValuesHolder.ofFloat("top", mTransfrom.startRect.top, mTransfrom.endRect.top);
        PropertyValuesHolder widthHolder = PropertyValuesHolder.ofFloat("width", mTransfrom.startRect.width, mTransfrom.endRect.width);
        PropertyValuesHolder heightHolder = PropertyValuesHolder.ofFloat("height", mTransfrom.startRect.height, mTransfrom.endRect.height);
        PropertyValuesHolder alphaHolder = PropertyValuesHolder.ofInt("alpha", 0, 255);
        valueAnimator.setValues(scaleHolder, leftHolder, topHolder, widthHolder, heightHolder, alphaHolder);
    } else {
        PropertyValuesHolder scaleHolder = PropertyValuesHolder.ofFloat("scale", mTransfrom.endScale, mTransfrom.startScale);
        PropertyValuesHolder leftHolder = PropertyValuesHolder.ofFloat("left", mTransfrom.endRect.left, mTransfrom.startRect.left);
        PropertyValuesHolder topHolder = PropertyValuesHolder.ofFloat("top", mTransfrom.endRect.top, mTransfrom.startRect.top);
        PropertyValuesHolder widthHolder = PropertyValuesHolder.ofFloat("width", mTransfrom.endRect.width, mTransfrom.startRect.width);
        PropertyValuesHolder heightHolder = PropertyValuesHolder.ofFloat("height", mTransfrom.endRect.height, mTransfrom.startRect.height);
        PropertyValuesHolder alphaHolder = PropertyValuesHolder.ofInt("alpha", 255, 0);
        valueAnimator.setValues(scaleHolder, leftHolder, topHolder, widthHolder, heightHolder, alphaHolder);
    }
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public synchronized void onAnimationUpdate(ValueAnimator animation) {
            mTransfrom.scale = (Float) animation.getAnimatedValue("scale");
            mTransfrom.rect.left = (Float) animation.getAnimatedValue("left");
            mTransfrom.rect.top = (Float) animation.getAnimatedValue("top");
            mTransfrom.rect.width = (Float) animation.getAnimatedValue("width");
            mTransfrom.rect.height = (Float) animation.getAnimatedValue("height");
            mBgAlpha = (Integer) animation.getAnimatedValue("alpha");
            invalidate();
            ((Activity) getContext()).getWindow().getDecorView().invalidate();
        }
    });
    valueAnimator.addListener(new ValueAnimator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // TODO 这个可以根据实际需求来修改
            if (state == STATE_TRANSFORM_IN) {
                mState = STATE_NORMAL;
            }
            if (mTransformListener != null) {
                mTransformListener.onTransformComplete(state);
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }
    });
    valueAnimator.start();
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) PropertyValuesHolder(com.nineoldandroids.animation.PropertyValuesHolder) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 63 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project SimplifyReader by chentao0707.

the class PlayerDiscView method startDiscAnimator.

private void startDiscAnimator(float animatedValue) {
    mDiscLayoutAnimator = ObjectAnimator.ofFloat(mDiscLayout, "rotation", animatedValue, 360 + animatedValue);
    mDiscLayoutAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator arg0) {
            mDiscLayoutAnimatorValue = (Float) arg0.getAnimatedValue();
        }
    });
    mDiscLayoutAnimator.setDuration(DISC_ANIMATOR_TIME);
    mDiscLayoutAnimator.setRepeatCount(DISC_ANIMATOR_REPEAT_COUNT);
    mDiscLayoutAnimator.setInterpolator(new LinearInterpolator());
    if (mDiscLayoutAnimator.isRunning() || mDiscLayoutAnimator.isStarted()) {
        mDiscLayoutAnimator.cancel();
    }
    mDiscLayoutAnimator.start();
}
Also used : LinearInterpolator(android.view.animation.LinearInterpolator) AnimatorUpdateListener(com.nineoldandroids.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 64 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project EazeGraph by blackfizz.

the class PieChart method initializeGraph.

/**
     * This is the main entry point after the graph has been inflated. Used to initialize the graph
     * and its corresponding members.
     */
@Override
protected void initializeGraph() {
    super.initializeGraph();
    Utils.setLayerToSW(this);
    mPieData = new ArrayList<PieModel>();
    mTotalValue = 0;
    mGraphPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLegendPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLegendPaint.setTextSize(mLegendTextSize);
    mLegendPaint.setColor(mLegendColor);
    mLegendPaint.setStyle(Paint.Style.FILL);
    mValuePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mValuePaint.setTextSize(mValueTextSize);
    mValuePaint.setColor(mValueTextColor);
    mValuePaint.setStyle(Paint.Style.FILL);
    mGraph.rotateTo(mPieRotation);
    mGraph.decelerate();
    mRevealAnimator = ValueAnimator.ofFloat(0, 1);
    mRevealAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mRevealValue = animation.getAnimatedFraction();
            invalidateGlobal();
        }
    });
    mRevealAnimator.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mStartedAnimation = false;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    if (mUsePieRotation) {
        // Set up an animator to animate the PieRotation property. This is used to
        // correct the pie's orientation after the user lets go of it.
        mAutoCenterAnimator = ObjectAnimator.ofInt(PieChart.this, "PieRotation", 0);
        // Add a listener to hook the onAnimationEnd event so that we can do
        // some cleanup when the pie stops moving.
        mAutoCenterAnimator.addListener(new Animator.AnimatorListener() {

            public void onAnimationStart(Animator animator) {
            }

            public void onAnimationEnd(Animator animator) {
                mGraph.decelerate();
            }

            public void onAnimationCancel(Animator animator) {
            }

            public void onAnimationRepeat(Animator animator) {
            }
        });
        // Create a Scroller to handle the fling gesture.
        if (Build.VERSION.SDK_INT < 11) {
            mScroller = new Scroller(getContext());
        } else {
            mScroller = new Scroller(getContext(), null, true);
        }
        // The scroller doesn't have any built-in animation functions--it just supplies
        // values when we ask it to. So we have to have a way to call it every frame
        // until the fling ends. This code (ab)uses a ValueAnimator object to generate
        // a callback on every animation frame. We don't use the animated value at all.
        mScrollAnimator = ValueAnimator.ofFloat(0, 1);
        mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                tickScrollAnimation();
            }
        });
        // Create a gesture detector to handle onTouch messages
        mDetector = new GestureDetector(PieChart.this.getContext(), new GestureListener());
        // Turn off long press--this control doesn't use it, and if long press is enabled,
        // you can't scroll for a bit, pause, then scroll some more (the pause is interpreted
        // as a long press, apparently)
        mDetector.setIsLongpressEnabled(false);
    }
    if (this.isInEditMode()) {
        addPieSlice(new PieModel("Breakfast", 15, Color.parseColor("#FE6DA8")));
        addPieSlice(new PieModel("Lunch", 25, Color.parseColor("#56B7F1")));
        addPieSlice(new PieModel("Dinner", 35, Color.parseColor("#CDA67F")));
        addPieSlice(new PieModel("Snack", 25, Color.parseColor("#FED70E")));
    }
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) GestureDetector(android.view.GestureDetector) PieModel(org.eazegraph.lib.models.PieModel) Paint(android.graphics.Paint) Scroller(android.widget.Scroller) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 65 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project EazeGraph by blackfizz.

the class ValueLineChart method initializeGraph.

/**
     * This is the main entry point after the graph has been inflated. Used to initialize the graph
     * and its corresponding members.
     */
@Override
protected void initializeGraph() {
    super.initializeGraph();
    mDrawMatrix.setValues(mDrawMatrixValues);
    mGraphOverlay.decelerate();
    mSeries = new ArrayList<ValueLineSeries>();
    mLegendList = new ArrayList<LegendModel>();
    mLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLinePaint.setStrokeWidth(mLineStroke);
    mLegendPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLegendPaint.setColor(mLegendColor);
    mLegendPaint.setTextSize(mLegendTextSize);
    mLegendPaint.setStrokeWidth(2);
    mLegendPaint.setStyle(Paint.Style.FILL);
    mMaxFontHeight = Utils.calculateMaxTextHeight(mLegendPaint, null);
    mIndicatorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mIndicatorPaint.setColor(mIndicatorLineColor);
    mIndicatorPaint.setTextSize(mIndicatorTextSize);
    mIndicatorPaint.setStrokeWidth(mIndicatorWidth);
    mIndicatorPaint.setStyle(Paint.Style.FILL);
    mScaleGestureDetector = new ScaleGestureDetector(getContext(), mScaleGestureListener);
    mGestureDetector = new GestureDetector(getContext(), mGestureListener);
    mScroller = new Scroller(getContext());
    mRevealAnimator = ValueAnimator.ofFloat(0, 1);
    mRevealAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mRevealValue = animation.getAnimatedFraction();
            mDrawMatrix.reset();
            mDrawMatrix.setScale(1, 1.f * mRevealValue, 0, mGraphHeight - mNegativeOffset);
            mGraph.invalidate();
        }
    });
    mRevealAnimator.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mStartedAnimation = false;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    // The scroller doesn't have any built-in animation functions--it just supplies
    // values when we ask it to. So we have to have a way to call it every frame
    // until the fling ends. This code (ab)uses a ValueAnimator object to generate
    // a callback on every animation frame. We don't use the animated value at all.
    mScrollAnimator = ValueAnimator.ofFloat(0, 1);
    mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            tickScrollAnimation();
            invalidateGlobal();
        }
    });
    if (this.isInEditMode()) {
        ValueLineSeries series1 = new ValueLineSeries();
        series1.setColor(0xFF63CBB0);
        series1.addPoint(new ValueLinePoint(1.4f));
        series1.addPoint(new ValueLinePoint(4.4f));
        series1.addPoint(new ValueLinePoint(2.4f));
        series1.addPoint(new ValueLinePoint(3.2f));
        series1.addPoint(new ValueLinePoint(2.6f));
        series1.addPoint(new ValueLinePoint(5.0f));
        series1.addPoint(new ValueLinePoint(3.5f));
        series1.addPoint(new ValueLinePoint(2.4f));
        series1.addPoint(new ValueLinePoint(0.4f));
        series1.addPoint(new ValueLinePoint(3.4f));
        series1.addPoint(new ValueLinePoint(2.5f));
        series1.addPoint(new ValueLinePoint(1.0f));
        series1.addPoint(new ValueLinePoint(4.2f));
        series1.addPoint(new ValueLinePoint(2.4f));
        series1.addPoint(new ValueLinePoint(3.6f));
        series1.addPoint(new ValueLinePoint(1.0f));
        series1.addPoint(new ValueLinePoint(2.5f));
        series1.addPoint(new ValueLinePoint(1.4f));
        addSeries(series1);
    }
}
Also used : GestureDetector(android.view.GestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) Paint(android.graphics.Paint) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) ValueLinePoint(org.eazegraph.lib.models.ValueLinePoint) ValueLineSeries(org.eazegraph.lib.models.ValueLineSeries) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) ScaleGestureDetector(android.view.ScaleGestureDetector) Scroller(android.widget.Scroller) LegendModel(org.eazegraph.lib.models.LegendModel)

Aggregations

ValueAnimator (com.nineoldandroids.animation.ValueAnimator)105 Animator (com.nineoldandroids.animation.Animator)55 AnimatorListenerAdapter (com.nineoldandroids.animation.AnimatorListenerAdapter)46 StateAnimator (carbon.animation.StateAnimator)30 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)19 View (android.view.View)17 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)15 Interpolator (android.view.animation.Interpolator)11 Reveal (carbon.internal.Reveal)11 Paint (android.graphics.Paint)7 ObjectAnimator (com.nineoldandroids.animation.ObjectAnimator)6 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)5 RecyclerView (android.support.v7.widget.RecyclerView)4 SimpleItemAnimator (android.support.v7.widget.SimpleItemAnimator)4 FrameLayout (android.widget.FrameLayout)4 ImageView (android.widget.ImageView)4 ArrayList (java.util.ArrayList)4 MotionEvent (android.view.MotionEvent)3 TouchInterceptionFrameLayout (com.github.ksoichiro.android.observablescrollview.TouchInterceptionFrameLayout)3 AnimatorUpdateListener (com.nineoldandroids.animation.ValueAnimator.AnimatorUpdateListener)3