protected void onTargetFound(View targetView, State state, Action action) { int dx = calculateDxToMakeVisible(targetView, getHorizontalSnapPreference()); int dy = calculateDyToMakeVisible(targetView, getVerticalSnapPreference()); int time = calculateTimeForDeceleration((int) Math.sqrt((double) ((dx * dx) + (dy * dy)))); if (time > 0) { action.update(-dx, -dy, time, this.mDecelerateInterpolator); } }
protected void onSeekTargetStep(int dx, int dy, State state, Action action) { if (getChildCount() == 0) { stop(); return; } this.mInterimTargetDx = clampApplyScroll(this.mInterimTargetDx, dx); this.mInterimTargetDy = clampApplyScroll(this.mInterimTargetDy, dy); if (this.mInterimTargetDx == 0 && this.mInterimTargetDy == 0) { updateActionForInterimTarget(action); } }
protected void updateActionForInterimTarget(Action action) { PointF scrollVector = computeScrollVectorForPosition(getTargetPosition()); if (scrollVector == null || (scrollVector.x == 0.0f && scrollVector.y == 0.0f)) { Log.e(TAG, "To support smooth scrolling, you should override \nLayoutManager#computeScrollVectorForPosition.\nFalling back to instant scroll"); action.jumpTo(getTargetPosition()); stop(); return; } normalize(scrollVector); this.mTargetVector = scrollVector; this.mInterimTargetDx = (int) (scrollVector.x * 10000.0f); this.mInterimTargetDy = (int) (scrollVector.y * 10000.0f); action.update((int) (((float) this.mInterimTargetDx) * TARGET_SEEK_EXTRA_SCROLL_RATIO), (int) (((float) this.mInterimTargetDy) * TARGET_SEEK_EXTRA_SCROLL_RATIO), (int) (((float) calculateTimeForScrolling(10000)) * TARGET_SEEK_EXTRA_SCROLL_RATIO), this.mLinearInterpolator); }