Search in sources :

Example 11 with AnimatorSet

use of android.animation.AnimatorSet in project circular-progress-button by dmytrodanylyk.

the class MorphingAnimation method start.

public void start() {
    ValueAnimator widthAnimation = ValueAnimator.ofInt(mFromWidth, mToWidth);
    final GradientDrawable gradientDrawable = mDrawable.getGradientDrawable();
    widthAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Integer value = (Integer) animation.getAnimatedValue();
            int leftOffset;
            int rightOffset;
            int padding;
            if (mFromWidth > mToWidth) {
                leftOffset = (mFromWidth - value) / 2;
                rightOffset = mFromWidth - leftOffset;
                padding = (int) (mPadding * animation.getAnimatedFraction());
            } else {
                leftOffset = (mToWidth - value) / 2;
                rightOffset = mToWidth - leftOffset;
                padding = (int) (mPadding - mPadding * animation.getAnimatedFraction());
            }
            gradientDrawable.setBounds(leftOffset + padding, padding, rightOffset - padding, mView.getHeight() - padding);
        }
    });
    ObjectAnimator bgColorAnimation = ObjectAnimator.ofInt(gradientDrawable, "color", mFromColor, mToColor);
    bgColorAnimation.setEvaluator(new ArgbEvaluator());
    ObjectAnimator strokeColorAnimation = ObjectAnimator.ofInt(mDrawable, "strokeColor", mFromStrokeColor, mToStrokeColor);
    strokeColorAnimation.setEvaluator(new ArgbEvaluator());
    ObjectAnimator cornerAnimation = ObjectAnimator.ofFloat(gradientDrawable, "cornerRadius", mFromCornerRadius, mToCornerRadius);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(mDuration);
    animatorSet.playTogether(widthAnimation, bgColorAnimation, strokeColorAnimation, cornerAnimation);
    animatorSet.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mListener != null) {
                mListener.onAnimationEnd();
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    animatorSet.start();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) ObjectAnimator(android.animation.ObjectAnimator) ArgbEvaluator(android.animation.ArgbEvaluator) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 12 with AnimatorSet

use of android.animation.AnimatorSet in project UltimateAndroid by cymcsg.

the class KugouLayout method init.

private void init(Context context) {
    setBackgroundColor(0x0);
    /**
         * Distance in pixels a touch can wander before we think the user is scrolling
         * */
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMaxVelocity = configuration.getScaledMaximumFlingVelocity();
    mContentContainer = new UnClickableFrameLayout(context);
    mContentContainer.setId(R.id.kugou_layout_md__content);
    /**
         * init Property Animation
         * */
    mAnimatorSet = new AnimatorSet();
    mOffsetAnimator = ObjectAnimator.ofFloat(this, aOffset, 0, 0);
    mOffsetAnimator.setDuration(ANIM_DURATION);
    mAnimatorSet.playTogether(mOffsetAnimator);
    mAnimatorSet.setInterpolator(mInterpolator);
    mOffsetAnimator.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            float endValue = (Float) mOffsetAnimator.getAnimatedValue();
            if ((endValue == getWidth() || endValue == -getWidth())) {
                setVisibility(INVISIBLE);
                if (null != mLayoutCloseListener) {
                    mLayoutCloseListener.onLayoutClose();
                }
            } else if (endValue == 0 && showingChangeAlpha) {
                showingChangeAlpha = false;
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    /**
         * create rebound animator
         * */
    mSpringSystem = SpringSystem.create();
    mSpring = mSpringSystem.createSpring();
    SpringConfig config = new SpringConfig(70, 9);
    mSpring.setSpringConfig(config);
    mSpring.setCurrentValue(0);
    mSpring.addListener(new SpringListener() {

        @Override
        public void onSpringUpdate(Spring spring) {
            if (doAnim) {
                double newValue = 1 - spring.getCurrentValue();
                mOffsetPixels = (float) newValue * mBeginOffsetX;
                moveContent();
                if (showingChangeAlpha) {
                    changeAlpha();
                }
            }
        }

        @Override
        public void onSpringAtRest(Spring spring) {
        }

        @Override
        public void onSpringActivate(Spring spring) {
        }

        @Override
        public void onSpringEndStateChange(Spring spring) {
        }
    });
    /**
         * add frame_layout mContentContainer as the parent of the activity's content view
         * */
    super.addView(mContentContainer, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    mContentContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
Also used : ViewConfiguration(android.view.ViewConfiguration) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) SpringListener(com.marshalchen.common.uimodule.rebound.SpringListener) AnimatorSet(android.animation.AnimatorSet) SpringConfig(com.marshalchen.common.uimodule.rebound.SpringConfig) Spring(com.marshalchen.common.uimodule.rebound.Spring)

Example 13 with AnimatorSet

use of android.animation.AnimatorSet in project UltimateAndroid by cymcsg.

the class MenuCircleShowingAnimation method closePromotedActions.

/**
     * Set close animation for promoted actions
     */
public AnimatorSet closePromotedActions() {
    if (objectAnimator == null) {
        objectAnimatorSetup();
    }
    AnimatorSet animation = new AnimatorSet();
    for (int i = 0; i < promotedActions.size(); i++) {
        objectAnimator[i] = setCloseAnimation(promotedActions.get(i), i);
    }
    if (objectAnimator.length == 0) {
        objectAnimator = null;
    }
    animation.playTogether(objectAnimator);
    animation.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animator) {
            mainImageButton.startAnimation(rotateCloseAnimation);
            mainImageButton.setClickable(false);
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            mainImageButton.setClickable(true);
            hidePromotedActions();
        }

        @Override
        public void onAnimationCancel(Animator animator) {
            mainImageButton.setClickable(true);
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
    return animation;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) AnimatorSet(android.animation.AnimatorSet)

Example 14 with AnimatorSet

use of android.animation.AnimatorSet in project UltimateAndroid by cymcsg.

the class MenuCircleShowingAnimation method openPromotedActions.

public AnimatorSet openPromotedActions() {
    if (objectAnimator == null) {
        objectAnimatorSetup();
    }
    AnimatorSet animation = new AnimatorSet();
    for (int i = 0; i < promotedActions.size(); i++) {
        objectAnimator[i] = setOpenAnimation(promotedActions.get(i), i);
    }
    if (objectAnimator.length == 0) {
        objectAnimator = null;
    }
    animation.playTogether(objectAnimator);
    animation.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animator) {
            mainImageButton.startAnimation(rotateOpenAnimation);
            mainImageButton.setClickable(false);
            showPromotedActions();
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            mainImageButton.setClickable(true);
        }

        @Override
        public void onAnimationCancel(Animator animator) {
            mainImageButton.setClickable(true);
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
    return animation;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) AnimatorSet(android.animation.AnimatorSet)

Example 15 with AnimatorSet

use of android.animation.AnimatorSet in project UltimateAndroid by cymcsg.

the class DownloadProgressBar method setupAnimations.

private void setupAnimations() {
    mOvershootInterpolator = new OvershootInterpolator(mOvershootValue);
    mArrowLineToDot = ValueAnimator.ofFloat(0, mRadius / 4);
    mArrowLineToDot.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mArrowLineToDotAnimatedValue = (float) valueAnimator.getAnimatedValue();
            invalidate();
        }
    });
    mArrowLineToDot.setDuration(200);
    mArrowLineToDot.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animator) {
            mState = State.ANIMATING_LINE_TO_DOT;
            if (mOnProgressUpdateListener != null) {
                mOnProgressUpdateListener.onAnimationStarted();
            }
        }

        @Override
        public void onAnimationEnd(Animator animator) {
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
    mArrowLineToDot.setInterpolator(new AccelerateInterpolator());
    mArrowLineToHorizontalLine = ValueAnimator.ofFloat(0, mRadius / 2);
    mArrowLineToHorizontalLine.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mArrowLineToHorizontalLineAnimatedValue = (float) valueAnimator.getAnimatedValue();
            invalidate();
        }
    });
    mArrowLineToHorizontalLine.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animator) {
        }

        @Override
        public void onAnimationEnd(Animator animator) {
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
    mArrowLineToHorizontalLine.setDuration(600);
    mArrowLineToHorizontalLine.setStartDelay(400);
    mArrowLineToHorizontalLine.setInterpolator(mOvershootInterpolator);
    mDotToProgressAnimation = ValueAnimator.ofFloat(0, mRadius);
    mDotToProgressAnimation.setDuration(600);
    mDotToProgressAnimation.setStartDelay(600);
    mDotToProgressAnimation.setInterpolator(mOvershootInterpolator);
    mDotToProgressAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mDotToProgressAnimatedValue = (float) valueAnimator.getAnimatedValue();
            invalidate();
        }
    });
    mDotToProgressAnimation.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animator) {
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            if (mWhichProgress == State.ANIMATING_PROGRESS)
                mProgressAnimationSet.start();
            else if (mWhichProgress == State.ANIMATING_MANUAL_PROGRESS)
                mManualProgressAnimationSet.start();
            mState = mWhichProgress;
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
    mArrowToLineAnimatorSet = new AnimatorSet();
    mArrowToLineAnimatorSet.playTogether(mArrowLineToDot, mArrowLineToHorizontalLine, mDotToProgressAnimation);
    mProgressAnimation = ValueAnimator.ofFloat(0, 360f);
    mProgressAnimation.setStartDelay(500);
    mProgressAnimation.setInterpolator(new LinearInterpolator());
    mProgressAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mCurrentGlobalProgressValue = (float) valueAnimator.getAnimatedValue();
            if (mOnProgressUpdateListener != null) {
                mOnProgressUpdateListener.onProgressUpdate(mCurrentGlobalProgressValue);
            }
            invalidate();
        }
    });
    mProgressAnimation.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animator) {
            mDotToProgressAnimatedValue = 0;
        }

        @Override
        public void onAnimationEnd(Animator animator) {
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
    mProgressAnimation.setDuration(mProgressDuration);
    mManualProgressAnimation = ValueAnimator.ofFloat(mFromArc, mToArc);
    mManualProgressAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mCurrentGlobalManualProgressValue = (float) valueAnimator.getAnimatedValue();
            invalidate();
        }
    });
    mManualProgressAnimation.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animator) {
            if (mOnProgressUpdateListener != null) {
                mOnProgressUpdateListener.onManualProgressStarted();
            }
            mDotToProgressAnimatedValue = 0;
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            if (mOnProgressUpdateListener != null) {
                mOnProgressUpdateListener.onManualProgressEnded();
            }
            if (mToArc > 359) {
                mCollapseAnimation.start();
            }
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
    mExpandAnimation = ValueAnimator.ofFloat(0, mRadius / 6);
    mExpandAnimation.setDuration(300);
    mExpandAnimation.setInterpolator(new DecelerateInterpolator());
    mExpandAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mExpandCollapseValue = (float) animation.getAnimatedValue();
            invalidate();
        }
    });
    mCollapseAnimation = ValueAnimator.ofFloat(mRadius / 6, mStrokeWidth / 2);
    mCollapseAnimation.setDuration(300);
    mCollapseAnimation.setStartDelay(300);
    mCollapseAnimation.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animator) {
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            if (mState == State.ANIMATING_MANUAL_PROGRESS) {
                if (mResultState == State.ANIMATING_ERROR) {
                    mErrorAnimation.start();
                } else if (mResultState == State.ANIMATING_SUCCESS) {
                    mSuccessAnimation.start();
                }
            }
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
    mCollapseAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    mCollapseAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mExpandCollapseValue = (float) animation.getAnimatedValue();
            invalidate();
        }
    });
    mManualProgressAnimationSet = new AnimatorSet();
    mManualProgressAnimationSet.playSequentially(mExpandAnimation, mManualProgressAnimation);
    mProgressAnimationSet = new AnimatorSet();
    mProgressAnimationSet.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mResultState == State.ANIMATING_ERROR) {
                mErrorAnimation.start();
            } else if (mResultState == State.ANIMATING_SUCCESS) {
                mSuccessAnimation.start();
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    mProgressAnimationSet.playSequentially(mExpandAnimation, mProgressAnimation, mCollapseAnimation);
    mErrorAnimation = ValueAnimator.ofFloat(0, mRadius / 4);
    mErrorAnimation.setDuration(600);
    mErrorAnimation.setStartDelay(500);
    mErrorAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    mErrorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mErrorValue = (float) valueAnimator.getAnimatedValue();
            invalidate();
        }
    });
    mErrorAnimation.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animator) {
            mState = State.ANIMATING_ERROR;
            if (mOnProgressUpdateListener != null) {
                mOnProgressUpdateListener.onAnimationError();
            }
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (mOnProgressUpdateListener != null) {
                        mOnProgressUpdateListener.onAnimationEnded();
                    }
                    mState = State.IDLE;
                    resetValues();
                    invalidate();
                }
            }, mResultDuration);
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
    mSuccessAnimation = ValueAnimator.ofFloat(0, mRadius / 4);
    mSuccessAnimation.setDuration(600);
    mSuccessAnimation.setStartDelay(500);
    mSuccessAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    mSuccessAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mSuccessValue = (float) valueAnimator.getAnimatedValue();
            invalidate();
        }
    });
    mSuccessAnimation.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animator) {
            mState = State.ANIMATING_SUCCESS;
            if (mOnProgressUpdateListener != null) {
                mOnProgressUpdateListener.onAnimationSuccess();
            }
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (mOnProgressUpdateListener != null) {
                        mOnProgressUpdateListener.onAnimationEnded();
                    }
                    mState = State.IDLE;
                    resetValues();
                    invalidate();
                }
            }, mResultDuration);
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
}
Also used : AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) OvershootInterpolator(android.view.animation.OvershootInterpolator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) LinearInterpolator(android.view.animation.LinearInterpolator) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator)

Aggregations

AnimatorSet (android.animation.AnimatorSet)480 ObjectAnimator (android.animation.ObjectAnimator)336 Animator (android.animation.Animator)278 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)139 View (android.view.View)107 ValueAnimator (android.animation.ValueAnimator)103 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)52 ArrayList (java.util.ArrayList)47 Rect (android.graphics.Rect)43 ViewGroup (android.view.ViewGroup)42 ImageView (android.widget.ImageView)36 TextView (android.widget.TextView)32 PropertyValuesHolder (android.animation.PropertyValuesHolder)25 Paint (android.graphics.Paint)25 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)25 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)23 Bitmap (android.graphics.Bitmap)17 LinearInterpolator (android.view.animation.LinearInterpolator)15 OvershootInterpolator (android.view.animation.OvershootInterpolator)15 Point (android.graphics.Point)14