Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 813d85b8 authored by Alan Viverette's avatar Alan Viverette
Browse files

Fix progress bar tinting, add tint support to ShapeDrawable

Cleans up APIs a little, since I think we may want to add tinting
modes beyond what Porter-Duff can provide. Plus we don't actually
support some of the Porter-Duff modes in hardware.

Change-Id: I2cea1b737cc93607a24842c54eb9f0d8346b29d4
parent ba7d4f56
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -10387,6 +10387,7 @@ package android.graphics.drawable {
    method public final android.graphics.Paint getPaint();
    method public android.graphics.Shader.TileMode getTileModeX();
    method public android.graphics.Shader.TileMode getTileModeY();
    method public android.content.res.ColorStateList getTint();
    method public boolean hasAntiAlias();
    method public boolean hasMipMap();
    method public final boolean isAutoMirrored();
@@ -10402,7 +10403,6 @@ package android.graphics.drawable {
    method public void setTileModeXY(android.graphics.Shader.TileMode, android.graphics.Shader.TileMode);
    method public final void setTileModeY(android.graphics.Shader.TileMode);
    method public void setTint(android.content.res.ColorStateList);
    method public void setTintMode(android.graphics.PorterDuff.Mode);
  }
  public class ClipDrawable extends android.graphics.drawable.Drawable implements android.graphics.drawable.Drawable.Callback {
@@ -10445,6 +10445,7 @@ package android.graphics.drawable {
    method public final android.graphics.Rect getBounds();
    method public android.graphics.drawable.Drawable.Callback getCallback();
    method public int getChangingConfigurations();
    method public android.graphics.ColorFilter getColorFilter();
    method public android.graphics.drawable.Drawable.ConstantState getConstantState();
    method public android.graphics.drawable.Drawable getCurrent();
    method public int getIntrinsicHeight();
@@ -10633,13 +10634,13 @@ package android.graphics.drawable {
    method public void draw(android.graphics.Canvas);
    method public int getOpacity();
    method public android.graphics.Paint getPaint();
    method public android.content.res.ColorStateList getTint();
    method public void setAlpha(int);
    method public void setColorFilter(android.graphics.ColorFilter);
    method public void setTargetDensity(android.graphics.Canvas);
    method public void setTargetDensity(android.util.DisplayMetrics);
    method public void setTargetDensity(int);
    method public void setTint(android.content.res.ColorStateList);
    method public void setTintMode(android.graphics.PorterDuff.Mode);
  }
  public class PaintDrawable extends android.graphics.drawable.ShapeDrawable {
@@ -10708,6 +10709,7 @@ package android.graphics.drawable {
    method public android.graphics.Paint getPaint();
    method public android.graphics.drawable.ShapeDrawable.ShaderFactory getShaderFactory();
    method public android.graphics.drawable.shapes.Shape getShape();
    method public android.content.res.ColorStateList getTint();
    method protected boolean inflateTag(java.lang.String, android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet);
    method protected void onDraw(android.graphics.drawable.shapes.Shape, android.graphics.Canvas, android.graphics.Paint);
    method public void setAlpha(int);
@@ -10718,6 +10720,7 @@ package android.graphics.drawable {
    method public void setPadding(android.graphics.Rect);
    method public void setShaderFactory(android.graphics.drawable.ShapeDrawable.ShaderFactory);
    method public void setShape(android.graphics.drawable.shapes.Shape);
    method public void setTint(android.content.res.ColorStateList);
  }
  public static abstract class ShapeDrawable.ShaderFactory {
+10 −5
Original line number Diff line number Diff line
@@ -346,19 +346,24 @@ public class ProgressBar extends View {
            return out;
            
        } else if (drawable instanceof BitmapDrawable) {
            final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
            final BitmapDrawable bitmap = (BitmapDrawable) drawable;
            final Bitmap tileBitmap = bitmap.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;
            // Ensure the color filter and tint are propagated.
            shapeDrawable.setTint(bitmap.getTint());
            shapeDrawable.setTintMode(bitmap.getTintMode());
            shapeDrawable.setColorFilter(bitmap.getColorFilter());

            return clip ? new ClipDrawable(
                    shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
        }
        
        return drawable;
+26 −0
Original line number Diff line number Diff line
@@ -558,6 +558,11 @@ public class BitmapDrawable extends Drawable {
        invalidateSelf();
    }

    @Override
    public ColorFilter getColorFilter() {
        return mBitmapState.mPaint.getColorFilter();
    }

    /**
     * Specifies a tint for this drawable.
     * <p>
@@ -582,10 +587,21 @@ public class BitmapDrawable extends Drawable {
        invalidateSelf();
    }

    /**
     * Returns the tint color for this drawable.
     *
     * @return Color state list to use for tinting this drawable, or null if
     *         none set
     */
    public ColorStateList getTint() {
        return mBitmapState.mTint;
    }

    /**
     * Specifies the blending mode used to apply tint.
     *
     * @param tintMode A Porter-Duff blending mode
     * @hide Pending finalization of supported Modes
     */
    public void setTintMode(Mode tintMode) {
        mBitmapState.mTintMode = tintMode;
@@ -595,6 +611,16 @@ public class BitmapDrawable extends Drawable {
        invalidateSelf();
    }

    /**
     * Returns the blending mode used to apply tint.
     *
     * @return The Porter-Duff blending mode used to apply tint.
     * @hide Pending finalization of supported Modes
     */
    public Mode getTintMode() {
        return mBitmapState.mTintMode;
    }

    /**
     * @hide Candidate for future API inclusion
     */
+18 −6
Original line number Diff line number Diff line
@@ -453,12 +453,6 @@ public abstract class Drawable {
        return 0xFF;
    }

    /**
     * Specify an optional color filter for the drawable. Pass null to remove
     * any existing color filter.
     */
    public abstract void setColorFilter(ColorFilter cf);

    /**
     * @hide Consider for future API inclusion
     */
@@ -468,6 +462,15 @@ public abstract class Drawable {
        // For right now only BitmapDrawable has it.
    }

    /**
     * Specify an optional color filter for the drawable. Pass {@code null} to
     * remove any existing color filter.
     *
     * @param cf the color filter to apply, or {@code null} to remove the
     *            existing color filter
     */
    public abstract void setColorFilter(ColorFilter cf);

    /**
     * Specify a color and Porter-Duff mode to be the color filter for this
     * drawable.
@@ -476,6 +479,15 @@ public abstract class Drawable {
        setColorFilter(new PorterDuffColorFilter(color, mode));
    }

    /**
     * Returns the current color filter, or {@code null} if none set.
     *
     * @return the current color filter, or {@code null} if none set
     */
    public ColorFilter getColorFilter() {
        return null;
    }

    /**
     * Removes the color filter for this drawable.
     */
+21 −1
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.BitmapDrawable.BitmapState;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.LayoutDirection;
@@ -341,10 +340,21 @@ public class NinePatchDrawable extends Drawable {
        invalidateSelf();
    }

    /**
     * Returns the tint color for this drawable.
     *
     * @return Color state list to use for tinting this drawable, or null if
     *         none set
     */
    public ColorStateList getTint() {
        return mNinePatchState.mTint;
    }

    /**
     * Specifies the blending mode used to apply tint.
     *
     * @param tintMode A Porter-Duff blending mode
     * @hide Pending finalization of supported Modes
     */
    public void setTintMode(Mode tintMode) {
        mNinePatchState.mTintMode = tintMode;
@@ -354,6 +364,16 @@ public class NinePatchDrawable extends Drawable {
        invalidateSelf();
    }

    /**
     * Returns the blending mode used to apply tint.
     *
     * @return The Porter-Duff blending mode used to apply tint.
     * @hide Pending finalization of supported Modes
     */
    public Mode getTintMode() {
        return mNinePatchState.mTintMode;
    }

    @Override
    public void setDither(boolean dither) {
        //noinspection PointlessBooleanExpression
Loading