FileDocCategorySizeDatePackage
ScrollBarDrawable.javaAPI DocAndroid 5.1 API9583Thu Mar 12 22:22:10 GMT 2015android.widget

ScrollBarDrawable

public class ScrollBarDrawable extends android.graphics.drawable.Drawable
This is only used by View for displaying its scroll bars. It should probably be moved in to the view package since it is used in that lower-level layer. For now, we'll hide it so it can be cleaned up later. {@hide}

Fields Summary
private static final int[]
STATE_ENABLED
private android.graphics.drawable.Drawable
mVerticalTrack
private android.graphics.drawable.Drawable
mHorizontalTrack
private android.graphics.drawable.Drawable
mVerticalThumb
private android.graphics.drawable.Drawable
mHorizontalThumb
private int
mRange
private int
mOffset
private int
mExtent
private boolean
mVertical
private boolean
mChanged
private boolean
mRangeChanged
private final android.graphics.Rect
mTempBounds
private boolean
mAlwaysDrawHorizontalTrack
private boolean
mAlwaysDrawVerticalTrack
private boolean
mMutated
Constructors Summary
public ScrollBarDrawable()


      
    
Methods Summary
public voiddraw(android.graphics.Canvas canvas)

        final boolean vertical = mVertical;
        final int extent = mExtent;
        final int range = mRange;

        boolean drawTrack = true;
        boolean drawThumb = true;
        if (extent <= 0 || range <= extent) {
            drawTrack = vertical ? mAlwaysDrawVerticalTrack : mAlwaysDrawHorizontalTrack;
            drawThumb = false;
        }

        Rect r = getBounds();
        if (canvas.quickReject(r.left, r.top, r.right, r.bottom, Canvas.EdgeType.AA)) {
            return;
        }
        if (drawTrack) {
            drawTrack(canvas, r, vertical);
        }

        if (drawThumb) {
            int size = vertical ? r.height() : r.width();
            int thickness = vertical ? r.width() : r.height();
            int length = Math.round((float) size * extent / range);
            int offset = Math.round((float) (size - length) * mOffset / (range - extent));

            // avoid the tiny thumb
            int minLength = thickness * 2;
            if (length < minLength) {
                length = minLength;
            }
            // avoid the too-big thumb
            if (offset + length > size) {
                offset = size - length;
            }

            drawThumb(canvas, r, offset, length, vertical);
        }
    
protected voiddrawThumb(android.graphics.Canvas canvas, android.graphics.Rect bounds, int offset, int length, boolean vertical)

        final Rect thumbRect = mTempBounds;
        final boolean changed = mRangeChanged || mChanged;
        if (changed) {
            if (vertical) {
                thumbRect.set(bounds.left,  bounds.top + offset,
                        bounds.right, bounds.top + offset + length);
            } else {
                thumbRect.set(bounds.left + offset, bounds.top,
                        bounds.left + offset + length, bounds.bottom);
            }
        }

        if (vertical) {
            if (mVerticalThumb != null) {
                final Drawable thumb = mVerticalThumb;
                if (changed) thumb.setBounds(thumbRect);
                thumb.draw(canvas);
            }
        } else {
            if (mHorizontalThumb != null) {
                final Drawable thumb = mHorizontalThumb;
                if (changed) thumb.setBounds(thumbRect);
                thumb.draw(canvas);
            }
        }
    
protected voiddrawTrack(android.graphics.Canvas canvas, android.graphics.Rect bounds, boolean vertical)

        Drawable track;
        if (vertical) {
            track = mVerticalTrack;
        } else {
            track = mHorizontalTrack;
        }
        if (track != null) {
            if (mChanged) {
                track.setBounds(bounds);
            }
            track.draw(canvas);
        }
    
public intgetAlpha()

        // All elements should have same alpha, just return one of them
        return mVerticalThumb.getAlpha();
    
public booleangetAlwaysDrawHorizontalTrack()
Indicates whether the horizontal scrollbar track should always be drawn regardless of the extent.

        return mAlwaysDrawHorizontalTrack;
    
public booleangetAlwaysDrawVerticalTrack()
Indicates whether the vertical scrollbar track should always be drawn regardless of the extent.

        return mAlwaysDrawVerticalTrack;
    
public intgetOpacity()

        return PixelFormat.TRANSLUCENT;
    
public intgetSize(boolean vertical)

        if (vertical) {
            return mVerticalTrack != null ? mVerticalTrack.getIntrinsicWidth() :
                    mVerticalThumb != null ? mVerticalThumb.getIntrinsicWidth() : 0;
        } else {
            return mHorizontalTrack != null ? mHorizontalTrack.getIntrinsicHeight() :
                    mHorizontalThumb != null ? mHorizontalThumb.getIntrinsicHeight() : 0;
        }
    
public android.widget.ScrollBarDrawablemutate()

        if (!mMutated && super.mutate() == this) {
            if (mVerticalTrack != null) {
                mVerticalTrack.mutate();
            }
            if (mVerticalThumb != null) {
                mVerticalThumb.mutate();
            }
            if (mHorizontalTrack != null) {
                mHorizontalTrack.mutate();
            }
            if (mHorizontalThumb != null) {
                mHorizontalThumb.mutate();
            }
            mMutated = true;
        }
        return this;
    
protected voidonBoundsChange(android.graphics.Rect bounds)

        super.onBoundsChange(bounds);
        mChanged = true;
    
public voidsetAlpha(int alpha)

        if (mVerticalTrack != null) {
            mVerticalTrack.setAlpha(alpha);
        }
        if (mVerticalThumb != null) {
            mVerticalThumb.setAlpha(alpha);
        }
        if (mHorizontalTrack != null) {
            mHorizontalTrack.setAlpha(alpha);
        }
        if (mHorizontalThumb != null) {
            mHorizontalThumb.setAlpha(alpha);
        }
    
public voidsetAlwaysDrawHorizontalTrack(boolean alwaysDrawTrack)
Indicate whether the horizontal scrollbar track should always be drawn regardless of the extent. Defaults to false.

param
alwaysDrawTrack Set to true if the track should always be drawn

        mAlwaysDrawHorizontalTrack = alwaysDrawTrack;
    
public voidsetAlwaysDrawVerticalTrack(boolean alwaysDrawTrack)
Indicate whether the vertical scrollbar track should always be drawn regardless of the extent. Defaults to false.

param
alwaysDrawTrack Set to true if the track should always be drawn

        mAlwaysDrawVerticalTrack = alwaysDrawTrack;
    
public voidsetColorFilter(android.graphics.ColorFilter cf)

        if (mVerticalTrack != null) {
            mVerticalTrack.setColorFilter(cf);
        }
        if (mVerticalThumb != null) {
            mVerticalThumb.setColorFilter(cf);
        }
        if (mHorizontalTrack != null) {
            mHorizontalTrack.setColorFilter(cf);
        }
        if (mHorizontalThumb != null) {
            mHorizontalThumb.setColorFilter(cf);
        }
    
public voidsetHorizontalThumbDrawable(android.graphics.drawable.Drawable thumb)

        if (thumb != null) {
            if (mMutated) {
                thumb.mutate();
            }
            thumb.setState(STATE_ENABLED);
            mHorizontalThumb = thumb;
        }
    
public voidsetHorizontalTrackDrawable(android.graphics.drawable.Drawable track)

        if (track != null) {
            if (mMutated) {
                track.mutate();
            }
            track.setState(STATE_ENABLED);
        }
        mHorizontalTrack = track;
    
public voidsetParameters(int range, int offset, int extent, boolean vertical)

        if (mVertical != vertical) {
            mChanged = true;
        }

        if (mRange != range || mOffset != offset || mExtent != extent) {
            mRangeChanged = true;
        }

        mRange = range;
        mOffset = offset;
        mExtent = extent;
        mVertical = vertical;
    
public voidsetVerticalThumbDrawable(android.graphics.drawable.Drawable thumb)

        if (thumb != null) {
            if (mMutated) {
                thumb.mutate();
            }
            thumb.setState(STATE_ENABLED);
            mVerticalThumb = thumb;
        }
    
public voidsetVerticalTrackDrawable(android.graphics.drawable.Drawable track)

        if (track != null) {
            if (mMutated) {
                track.mutate();
            }
            track.setState(STATE_ENABLED);
        }
        mVerticalTrack = track;
    
public java.lang.StringtoString()

        return "ScrollBarDrawable: range=" + mRange + " offset=" + mOffset +
               " extent=" + mExtent + (mVertical ? " V" : " H");