@Override public void handleEntryTransition(IDecoratorState fromState) { mStateListener.onOverScrollStateChange(OverScrollBounceEffectDecoratorBase.this, fromState.getStateId(), this.getStateId()); Animator bounceBackAnim = createAnimator(); bounceBackAnim.addListener(this); bounceBackAnim.start(); }
protected Animator createAnimator() { final View view = mViewAdapter.getView(); mAnimAttributes.init(view); // Set up a low-duration slow-down animation IN the drag direction. // Exception: If wasn't dragging in 'forward' direction (or velocity=0 -- i.e. not dragging at all), // skip slow-down anim directly to the bounce-back. if (mVelocity == 0f || (mVelocity < 0 && mStartAttr.mDir) || (mVelocity > 0 && !mStartAttr.mDir)) { return createBounceBackAnimator(mAnimAttributes.mAbsOffset); } // dt = (Vt - Vo) / a; Vt=0 ==> dt = -Vo / a float slowdownDuration = -mVelocity / mDecelerateFactor; slowdownDuration = (slowdownDuration < 0 ? 0 : slowdownDuration); // Happens in counter-direction dragging // dx = (Vt^2 - Vo^2) / 2a; Vt=0 ==> dx = -Vo^2 / 2a float slowdownDistance = -mVelocity * mVelocity / mDoubleDecelerateFactor; float slowdownEndOffset = mAnimAttributes.mAbsOffset + slowdownDistance; ObjectAnimator slowdownAnim = createSlowdownAnimator(view, (int) slowdownDuration, slowdownEndOffset); // Set up the bounce back animation, bringing the view back into the original, pre-overscroll position (translation=0). ObjectAnimator bounceBackAnim = createBounceBackAnimator(slowdownEndOffset); // Play the 2 animations as a sequence. AnimatorSet wholeAnim = new AnimatorSet(); wholeAnim.playSequentially(slowdownAnim, bounceBackAnim); return wholeAnim; }
public OverScrollBounceEffectDecoratorBase(IOverScrollDecoratorAdapter viewAdapter, float decelerateFactor, float touchDragRatioFwd, float touchDragRatioBck) { mViewAdapter = viewAdapter; mBounceBackState = new BounceBackState(decelerateFactor); mOverScrollingState = new OverScrollingState(touchDragRatioFwd, touchDragRatioBck); mIdleState = new IdleState(); mCurrentState = mIdleState; attach(); }