public virtual void draw(android.graphics.Canvas canvas) { if (mState == STATE_NONE) { // No need to draw anything return; } int y = mThumbY; int viewWidth = mList.getWidth(); android.widget.FastScroller.ScrollFade scrollFade = mScrollFade; int alpha = -1; if (mState == STATE_EXIT) { alpha = scrollFade.getAlpha(); if (alpha < android.widget.FastScroller.ScrollFade.ALPHA_MAX / 2) { mThumbDrawable.setAlpha(alpha * 2); } int left = 0; switch (mPosition) { case android.view.View.SCROLLBAR_POSITION_DEFAULT: case android.view.View.SCROLLBAR_POSITION_RIGHT: { left = viewWidth - (mThumbW * alpha) / android.widget.FastScroller.ScrollFade.ALPHA_MAX; break; } case android.view.View.SCROLLBAR_POSITION_LEFT: { left = -mThumbW + (mThumbW * alpha) / android.widget.FastScroller.ScrollFade.ALPHA_MAX; break; } } mThumbDrawable.setBounds(left, 0, left + mThumbW, mThumbH); mChangedBounds = true; } if (mTrackDrawable != null) { android.graphics.Rect thumbBounds = mThumbDrawable.getBounds(); int left = thumbBounds.left; int halfThumbHeight = (thumbBounds.bottom - thumbBounds.top) / 2; int trackWidth = mTrackDrawable.getIntrinsicWidth(); int trackLeft = (left + mThumbW / 2) - trackWidth / 2; mTrackDrawable.setBounds(trackLeft, halfThumbHeight, trackLeft + trackWidth, mList .getHeight() - halfThumbHeight); mTrackDrawable.draw(canvas); } canvas.translate(0, y); mThumbDrawable.draw(canvas); canvas.translate(0, -y); // If user is dragging the scroll bar, draw the alphabet overlay if (mState == STATE_DRAGGING && mDrawOverlay) { if (mOverlayPosition == OVERLAY_AT_THUMB) { int left = 0; switch (mPosition) { case android.view.View.SCROLLBAR_POSITION_DEFAULT: case android.view.View.SCROLLBAR_POSITION_RIGHT: default: { left = System.Math.Max(0, mThumbDrawable.getBounds().left - mThumbW - mOverlaySize ); break; } case android.view.View.SCROLLBAR_POSITION_LEFT: { left = System.Math.Min(mThumbDrawable.getBounds().right + mThumbW, mList.getWidth () - mOverlaySize); break; } } int top = System.Math.Max(0, System.Math.Min(y + (mThumbH - mOverlaySize) / 2, mList .getHeight() - mOverlaySize)); android.graphics.RectF pos = mOverlayPos; pos.left = left; pos.right = pos.left + mOverlaySize; pos.top = top; pos.bottom = pos.top + mOverlaySize; if (mOverlayDrawable != null) { mOverlayDrawable.setBounds((int)pos.left, (int)pos.top, (int)pos.right, (int)pos. bottom); } } mOverlayDrawable.draw(canvas); android.graphics.Paint paint = mPaint; float descent = paint.descent(); android.graphics.RectF rectF = mOverlayPos; android.graphics.Rect tmpRect = mTmpRect; mOverlayDrawable.getPadding(tmpRect); int hOff = (tmpRect.right - tmpRect.left) / 2; int vOff = (tmpRect.bottom - tmpRect.top) / 2; canvas.drawText(mSectionText, (int)(rectF.left + rectF.right) / 2 - hOff, (int)(rectF .bottom + rectF.top) / 2 + mOverlaySize / 4 - descent - vOff, paint); } else { if (mState == STATE_EXIT) { if (alpha == 0) { // Done with exit setState(STATE_NONE); } else { if (mTrackDrawable != null) { mList.invalidate(viewWidth - mThumbW, 0, viewWidth, mList.getHeight()); } else { mList.invalidate(viewWidth - mThumbW, y, viewWidth, y + mThumbH); } } } } }