protected void animateOffsetTo(int position, int duration) { final int startX = (int) mOffsetPixels; final int dx = position - startX; if (dx > 0) { setDrawerState(STATE_OPENING); mScroller.startScroll(startX, 0, dx, 0, duration); } else { setDrawerState(STATE_CLOSING); mScroller.startScroll(startX, 0, dx, 0, duration); } startLayerTranslation(); postAnimationInvalidate(); }
/** * Moves the drawer to the position passed. * * @param position The position the content is moved to. * @param velocity Optional velocity if called by releasing a drag event. * @param animate Whether the move is animated. */ protected void animateOffsetTo(int position, int velocity, boolean animate) { endDrag(); endPeek(); final int startX = (int) mOffsetPixels; final int dx = position - startX; if (dx == 0 || !animate) { setOffsetPixels(position); setDrawerState(position == 0 ? STATE_CLOSED : STATE_OPEN); stopLayerTranslation(); return; } int duration; velocity = Math.abs(velocity); if (velocity > 0) { duration = 4 * Math.round(1000.f * Math.abs((float) dx / velocity)); } else { duration = (int) (600.f * Math.abs((float) dx / mMenuSize)); } duration = Math.min(duration, mMaxAnimationDuration); if (dx > 0) { setDrawerState(STATE_OPENING); mScroller.startScroll(startX, 0, dx, 0, duration); } else { setDrawerState(STATE_CLOSING); mScroller.startScroll(startX, 0, dx, 0, duration); } startLayerTranslation(); postAnimationInvalidate(); }