FileDocCategorySizeDatePackage
TintRatingBar.javaAPI DocAndroid 5.1 API5843Thu Mar 12 22:22:56 GMT 2015android.support.v7.internal.widget

TintRatingBar

public class TintRatingBar extends android.widget.RatingBar
An tint aware {@link android.widget.RatingBar}.
hide

Fields Summary
private static final int[]
TINT_ATTRS
private android.graphics.Bitmap
mSampleTile
Constructors Summary
public TintRatingBar(android.content.Context context)


       
        this(context, null);
    
public TintRatingBar(android.content.Context context, android.util.AttributeSet attrs)

        this(context, attrs, android.R.attr.ratingBarStyle);
    
public TintRatingBar(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)

        super(context, attrs, defStyleAttr);

        TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, TINT_ATTRS,
                defStyleAttr, 0);

        Drawable drawable = a.getDrawable(0);
        if (drawable != null) {
            setIndeterminateDrawable(tileifyIndeterminate(drawable));
        }

        drawable = a.getDrawable(1);
        if (drawable != null) {
            setProgressDrawable(tileify(drawable, false));
        }

        a.recycle();
    
Methods Summary
private android.graphics.drawable.shapes.ShapegetDrawableShape()

        final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
        return new RoundRectShape(roundedCorners, null, null);
    
protected synchronized voidonMeasure(int widthMeasureSpec, int heightMeasureSpec)

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        if (mSampleTile != null) {
            final int width = mSampleTile.getWidth() * getNumStars();
            setMeasuredDimension(ViewCompat.resolveSizeAndState(width, widthMeasureSpec, 0),
                    getMeasuredHeight());
        }
    
private android.graphics.drawable.Drawabletileify(android.graphics.drawable.Drawable drawable, boolean clip)
Converts a drawable to a tiled version of itself. It will recursively traverse layer and state list drawables.

        if (drawable instanceof DrawableWrapper) {
            Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable();
            if (inner != null) {
                inner = tileify(inner, clip);
                ((DrawableWrapper) drawable).setWrappedDrawable(inner);
            }
        } else if (drawable instanceof LayerDrawable) {
            LayerDrawable background = (LayerDrawable) drawable;
            final int N = background.getNumberOfLayers();
            Drawable[] outDrawables = new Drawable[N];

            for (int i = 0; i < N; i++) {
                int id = background.getId(i);
                outDrawables[i] = tileify(background.getDrawable(i),
                        (id == android.R.id.progress || id == android.R.id.secondaryProgress));
            }
            LayerDrawable newBg = new LayerDrawable(outDrawables);

            for (int i = 0; i < N; i++) {
                newBg.setId(i, background.getId(i));
            }

            return newBg;

        } else if (drawable instanceof BitmapDrawable) {
            final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
            if (mSampleTile == null) {
                mSampleTile = tileBitmap;
            }

            final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
            final BitmapShader bitmapShader = new BitmapShader(tileBitmap,
                    Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
            shapeDrawable.getPaint().setShader(bitmapShader);
            return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT,
                    ClipDrawable.HORIZONTAL) : shapeDrawable;
        }

        return drawable;
    
private android.graphics.drawable.DrawabletileifyIndeterminate(android.graphics.drawable.Drawable drawable)
Convert a AnimationDrawable for use as a barberpole animation. Each frame of the animation is wrapped in a ClipDrawable and given a tiling BitmapShader.

        if (drawable instanceof AnimationDrawable) {
            AnimationDrawable background = (AnimationDrawable) drawable;
            final int N = background.getNumberOfFrames();
            AnimationDrawable newBg = new AnimationDrawable();
            newBg.setOneShot(background.isOneShot());

            for (int i = 0; i < N; i++) {
                Drawable frame = tileify(background.getFrame(i), true);
                frame.setLevel(10000);
                newBg.addFrame(frame, background.getDuration(i));
            }
            newBg.setLevel(10000);
            drawable = newBg;
        }
        return drawable;