AnderWeb / discreteSeekBar

Apache License 2.0
2.11k stars 400 forks source link

partially fill background of progress #76

Open aacanakin opened 8 years ago

aacanakin commented 8 years ago

I need to partially fill progress background using a PartialDrawable class. However, setProgressDrawable is not available in discrete seek bar. Can you help me how to partially draw the background of progress bar? PartialDrawable class is the following;

public class PartialDrawable extends Drawable {

    private float mStart;
    private float mEnd;
    private Paint mPaint;

    List<Pair<Float, Float>> mPairs;

    public PartialDrawable(List<Pair<Float, Float>> parts) {
        mPairs = parts;
        mPaint = new Paint();
    }

    @Override
    public void draw(Canvas canvas) {
        for (int i = 0; i < mPairs.size(); i++) {

            float start = mPairs.get(i).first;
            float end = mPairs.get(i).second;

            Rect b = getBounds();
            mPaint.setColor(Color.RED);
            canvas.drawRect(b, mPaint);
            mPaint.setColor(Color.RED);
            canvas.drawRect(b.width() * start, b.top, b.width() * end, b.bottom, mPaint);
        }
    }

    @Override
    public void setAlpha(int alpha) {
    }

    @Override
    public void setColorFilter(ColorFilter cf) {
    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }
}