library/src/main/java/com/lsxiao/library/DraggableLayout.java
/**
     * the dot will be back the origin position by animate.
     */
the dot will be back the origin position by animate.
the dot will be back the origin position by animate .
private void animate(int state, Animator.AnimatorListener animatorListener) {
        if (mAnimator != null && mAnimator.isRunning()) {
            return;
        }
        if (mPointFEvaluator == null) {
            mPointFEvaluator = new PointFEvaluator();
        }
        switch (state) {
            case STATE_FOLLOW_MOVING_TO_TOUCH: {
                mAnimator = ValueAnimator.ofObject(mPointFEvaluator, mFollowCircle.center, mTouchCircle.center);
                mAnimator.setEvaluator(mPointFEvaluator);
                mAnimator.setDuration(200);
                mAnimator.setInterpolator(new FastOutSlowInInterpolator());
                mAnimator.addUpdateListener(this);
                if (animatorListener == null) {
                    mAnimator.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationStart(Animator animation) {
                        }
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            mAnimator = null;
                            if (mCanIntercept) {
                                if (getState() != STATE_DRAGGING && mTouchedDotView.getOnDotStateChangedListener() != null) {
                                    mTouchedDotView.getOnDotStateChangedListener().onDrag(mTouchedDotView);
                                }
                                setState(STATE_DRAGGING);
                            } else {
                                setState(STATE_DISMISSING);
                                animate(STATE_DISMISSING);
                            }
                            postInvalidate();
                        }
                    });
                } else {
                    mAnimator.addListener(animatorListener);
                }
                break;
            }
            case STATE_FOLLOW_MOVING_TO_ORIGIN: {
                mFollowCircle = Circle.clone(mTouchCircle);
                mAnimator = ValueAnimator.ofObject(mPointFEvaluator, mFollowCircle.center, mOriginCircle.center);
                mAnimator.setEvaluator(mPointFEvaluator);
                mAnimator.setDuration(300);
                mAnimator.setInterpolator(new FastOutSlowInInterpolator());
                mAnimator.addUpdateListener(this);
                if (animatorListener == null) {
                    mAnimator.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationStart(Animator animation) {
                        }
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            mAnimator = null;
                            if (mCanIntercept) {
                                if (getState() != STATE_STRETCHING && mTouchedDotView.getOnDotStateChangedListener() != null) {
                                    mTouchedDotView.getOnDotStateChangedListener().onStretch(mTouchedDotView);
                                }
                                setState(STATE_STRETCHING);
                            } else {
                                setState(STATE_TOUCH_MOVING_TO_ORIGIN);
                                animate(STATE_TOUCH_MOVING_TO_ORIGIN);
                            }
                            postInvalidate();
                        }
                    });
                } else {
                    mAnimator.addListener(animatorListener);
                }
                break;
            }
            case STATE_TOUCH_MOVING_TO_ORIGIN: {
                mAnimator = ValueAnimator.ofObject(mPointFEvaluator, mTouchCircle.center, mOriginCircle.center);
                mAnimator.setEvaluator(mPointFEvaluator);
                mAnimator.setDuration(300);
                mAnimator.setInterpolator(new FastOutSlowInInterpolator());
                mAnimator.addUpdateListener(this);
                if (animatorListener == null) {
                    mAnimator.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationStart(Animator animation) {
                        }
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            mAnimator = null;
                            setState(STATE_IDLE);
                            reset();
                        }
                    });
                } else {
                    mAnimator.addListener(animatorListener);
                }
                break;
            }
            case STATE_DISMISSING: {
                mAnimator = ValueAnimator.ofFloat(mTouchCircle.radius, 0);
                mAnimator.setDuration(300);
                mAnimator.setInterpolator(new AnticipateOvershootInterpolator());
                mAnimator.addUpdateListener(this);
                if (animatorListener == null) {
                    mAnimator.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationStart(Animator animation) {
                        }
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            mAnimator = null;
                            if (mTouchedDotView.getOnDotStateChangedListener() != null) {
                                mTouchedDotView.getOnDotStateChangedListener().onDismissed(mTouchedDotView);
                            }
                            dismissed();
                        }
                    });
                } else {
                    mAnimator.addListener(animatorListener);
                }
                break;
            }
        }
        if (mAnimator != null) {
            mAnimator.start();
        }
    }
private void animate ( int state , Animator . AnimatorListener animatorListener ) { if ( mAnimator != null && mAnimator . isRunning ( ) ) { return ; } if ( mPointFEvaluator == null ) { mPointFEvaluator = new PointFEvaluator ( ) ; } switch ( state ) { case STATE_FOLLOW_MOVING_TO_TOUCH : { mAnimator = ValueAnimator . ofObject ( mPointFEvaluator , mFollowCircle . center , mTouchCircle . center ) ; mAnimator . setEvaluator ( mPointFEvaluator ) ; mAnimator . setDuration ( 200 ) ; mAnimator . setInterpolator ( new FastOutSlowInInterpolator ( ) ) ; mAnimator . addUpdateListener ( this ) ; if ( animatorListener == null ) { mAnimator . addListener ( new AnimatorListenerAdapter ( ) { @ Override public void onAnimationStart ( Animator animation ) { } @ Override public void onAnimationEnd ( Animator animation ) { mAnimator = null ; if ( mCanIntercept ) { if ( getState ( ) != STATE_DRAGGING && mTouchedDotView . getOnDotStateChangedListener ( ) != null ) { mTouchedDotView . getOnDotStateChangedListener ( ) . onDrag ( mTouchedDotView ) ; } setState ( STATE_DRAGGING ) ; } else { setState ( STATE_DISMISSING ) ; animate ( STATE_DISMISSING ) ; } postInvalidate ( ) ; } } ) ; } else { mAnimator . addListener ( animatorListener ) ; } break ; } case STATE_FOLLOW_MOVING_TO_ORIGIN : { mFollowCircle = Circle . clone ( mTouchCircle ) ; mAnimator = ValueAnimator . ofObject ( mPointFEvaluator , mFollowCircle . center , mOriginCircle . center ) ; mAnimator . setEvaluator ( mPointFEvaluator ) ; mAnimator . setDuration ( 300 ) ; mAnimator . setInterpolator ( new FastOutSlowInInterpolator ( ) ) ; mAnimator . addUpdateListener ( this ) ; if ( animatorListener == null ) { mAnimator . addListener ( new AnimatorListenerAdapter ( ) { @ Override public void onAnimationStart ( Animator animation ) { } @ Override public void onAnimationEnd ( Animator animation ) { mAnimator = null ; if ( mCanIntercept ) { if ( getState ( ) != STATE_STRETCHING && mTouchedDotView . getOnDotStateChangedListener ( ) != null ) { mTouchedDotView . getOnDotStateChangedListener ( ) . onStretch ( mTouchedDotView ) ; } setState ( STATE_STRETCHING ) ; } else { setState ( STATE_TOUCH_MOVING_TO_ORIGIN ) ; animate ( STATE_TOUCH_MOVING_TO_ORIGIN ) ; } postInvalidate ( ) ; } } ) ; } else { mAnimator . addListener ( animatorListener ) ; } break ; } case STATE_TOUCH_MOVING_TO_ORIGIN : { mAnimator = ValueAnimator . ofObject ( mPointFEvaluator , mTouchCircle . center , mOriginCircle . center ) ; mAnimator . setEvaluator ( mPointFEvaluator ) ; mAnimator . setDuration ( 300 ) ; mAnimator . setInterpolator ( new FastOutSlowInInterpolator ( ) ) ; mAnimator . addUpdateListener ( this ) ; if ( animatorListener == null ) { mAnimator . addListener ( new AnimatorListenerAdapter ( ) { @ Override public void onAnimationStart ( Animator animation ) { } @ Override public void onAnimationEnd ( Animator animation ) { mAnimator = null ; setState ( STATE_IDLE ) ; reset ( ) ; } } ) ; } else { mAnimator . addListener ( animatorListener ) ; } break ; } case STATE_DISMISSING : { mAnimator = ValueAnimator . ofFloat ( mTouchCircle . radius , 0 ) ; mAnimator . setDuration ( 300 ) ; mAnimator . setInterpolator ( new AnticipateOvershootInterpolator ( ) ) ; mAnimator . addUpdateListener ( this ) ; if ( animatorListener == null ) { mAnimator . addListener ( new AnimatorListenerAdapter ( ) { @ Override public void onAnimationStart ( Animator animation ) { } @ Override public void onAnimationEnd ( Animator animation ) { mAnimator = null ; if ( mTouchedDotView . getOnDotStateChangedListener ( ) != null ) { mTouchedDotView . getOnDotStateChangedListener ( ) . onDismissed ( mTouchedDotView ) ; } dismissed ( ) ; } } ) ; } else { mAnimator . addListener ( animatorListener ) ; } break ; } } if ( mAnimator != null ) { mAnimator . start ( ) ; } }
the dot will be back the origin position by animate.
the dot will be back the origin position by animate .
//fixed move to drag