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

Commit 41551849 authored by Alan Viverette's avatar Alan Viverette
Browse files

Add missing accessors on GradientDrawable, NinePatchDrawable

Bug: 13248977
Bug: 13249029
Change-Id: Ia8817a264b7063926e75b2f2a238d5ba36e14ab5
parent c2f61b77
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -12398,9 +12398,17 @@ package android.graphics.drawable {
    ctor public GradientDrawable();
    ctor public GradientDrawable(android.graphics.drawable.GradientDrawable.Orientation, int[]);
    method public void draw(android.graphics.Canvas);
    method public android.content.res.ColorStateList getColor();
    method public int[] getColors();
    method public float[] getCornerRadii();
    method public float getCornerRadius();
    method public float getGradientCenterX();
    method public float getGradientCenterY();
    method public float getGradientRadius();
    method public int getGradientType();
    method public int getOpacity();
    method public android.graphics.drawable.GradientDrawable.Orientation getOrientation();
    method public boolean isUseLevel();
    method public void setAlpha(int);
    method public void setColor(int);
    method public void setColor(android.content.res.ColorStateList);
@@ -12534,10 +12542,12 @@ package android.graphics.drawable {
    ctor public deprecated NinePatchDrawable(android.graphics.NinePatch);
    ctor public NinePatchDrawable(android.content.res.Resources, android.graphics.NinePatch);
    method public void draw(android.graphics.Canvas);
    method public android.graphics.NinePatch getNinePatch();
    method public int getOpacity();
    method public android.graphics.Paint getPaint();
    method public void setAlpha(int);
    method public void setColorFilter(android.graphics.ColorFilter);
    method public void setNinePatch(android.graphics.NinePatch);
    method public void setTargetDensity(android.graphics.Canvas);
    method public void setTargetDensity(android.util.DisplayMetrics);
    method public void setTargetDensity(int);
+10 −0
Original line number Diff line number Diff line
@@ -12735,9 +12735,17 @@ package android.graphics.drawable {
    ctor public GradientDrawable();
    ctor public GradientDrawable(android.graphics.drawable.GradientDrawable.Orientation, int[]);
    method public void draw(android.graphics.Canvas);
    method public android.content.res.ColorStateList getColor();
    method public int[] getColors();
    method public float[] getCornerRadii();
    method public float getCornerRadius();
    method public float getGradientCenterX();
    method public float getGradientCenterY();
    method public float getGradientRadius();
    method public int getGradientType();
    method public int getOpacity();
    method public android.graphics.drawable.GradientDrawable.Orientation getOrientation();
    method public boolean isUseLevel();
    method public void setAlpha(int);
    method public void setColor(int);
    method public void setColor(android.content.res.ColorStateList);
@@ -12871,10 +12879,12 @@ package android.graphics.drawable {
    ctor public deprecated NinePatchDrawable(android.graphics.NinePatch);
    ctor public NinePatchDrawable(android.content.res.Resources, android.graphics.NinePatch);
    method public void draw(android.graphics.Canvas);
    method public android.graphics.NinePatch getNinePatch();
    method public int getOpacity();
    method public android.graphics.Paint getPaint();
    method public void setAlpha(int);
    method public void setColorFilter(android.graphics.ColorFilter);
    method public void setNinePatch(android.graphics.NinePatch);
    method public void setTargetDensity(android.graphics.Canvas);
    method public void setTargetDensity(android.util.DisplayMetrics);
    method public void setTargetDensity(int);
+167 −44
Original line number Diff line number Diff line
@@ -17,10 +17,11 @@
package android.graphics.drawable;

import android.annotation.ColorInt;
import android.annotation.Nullable;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
@@ -198,34 +199,54 @@ public class GradientDrawable extends Drawable {
    }

    /**
     * <p>Specify radii for each of the 4 corners. For each corner, the array
     * contains 2 values, <code>[X_radius, Y_radius]</code>. The corners are ordered
     * top-left, top-right, bottom-right, bottom-left. This property
     * is honored only when the shape is of type {@link #RECTANGLE}.</p>
     * <p><strong>Note</strong>: changing this property will affect all instances
     * Specifies radii for each of the 4 corners. For each corner, the array
     * contains 2 values, <code>[X_radius, Y_radius]</code>. The corners are
     * ordered top-left, top-right, bottom-right, bottom-left. This property
     * is honored only when the shape is of type {@link #RECTANGLE}.
     * <p>
     * <strong>Note</strong>: changing this property will affect all instances
     * of a drawable loaded from a resource. It is recommended to invoke
     * {@link #mutate()} before changing this property.</p>
     * {@link #mutate()} before changing this property.
     *
     * @param radii 4 pairs of X and Y radius for each corner, specified in pixels.
     *              The length of this array must be >= 8
     * @param radii an array of length >= 8 containing 4 pairs of X and Y
     *              radius for each corner, specified in pixels
     *
     * @see #mutate()
     * @see #setCornerRadii(float[])
     * @see #setShape(int)
     * @see #setCornerRadius(float)
     */
    public void setCornerRadii(float[] radii) {
    public void setCornerRadii(@Nullable float[] radii) {
        mGradientState.setCornerRadii(radii);
        mPathIsDirty = true;
        invalidateSelf();
    }

    /**
     * <p>Specify radius for the corners of the gradient. If this is > 0, then the
     * drawable is drawn in a round-rectangle, rather than a rectangle. This property
     * is honored only when the shape is of type {@link #RECTANGLE}.</p>
     * <p><strong>Note</strong>: changing this property will affect all instances
     * Returns the radii for each of the 4 corners. For each corner, the array
     * contains 2 values, <code>[X_radius, Y_radius]</code>. The corners are
     * ordered top-left, top-right, bottom-right, bottom-left.
     * <p>
     * If the radius was previously set with {@link #setCornerRadius(float)},
     * or if the corners are not rounded, this method will return {@code null}.
     *
     * @return an array containing the radii for each of the 4 corners, or
     *         {@code null}
     * @see #setCornerRadii(float[])
     */
    @Nullable
    public float[] getCornerRadii() {
        return mGradientState.mRadiusArray.clone();
    }

    /**
     * Specifies the radius for the corners of the gradient. If this is > 0,
     * then the drawable is drawn in a round-rectangle, rather than a
     * rectangle. This property is honored only when the shape is of type
     * {@link #RECTANGLE}.
     * <p>
     * <strong>Note</strong>: changing this property will affect all instances
     * of a drawable loaded from a resource. It is recommended to invoke
     * {@link #mutate()} before changing this property.</p>
     * {@link #mutate()} before changing this property.
     *
     * @param radius The radius in pixels of the corners of the rectangle shape
     *
@@ -239,6 +260,19 @@ public class GradientDrawable extends Drawable {
        invalidateSelf();
    }

    /**
     * Returns the radius for the corners of the gradient.
     * <p>
     * If the radius was previously set with {@link #setCornerRadii(float[])},
     * or if the corners are not rounded, this method will return {@code null}.
     *
     * @return the radius in pixels of the corners of the rectangle shape, or 0
     * @see #setCornerRadius
     */
    public float getCornerRadius() {
        return mGradientState.mRadius;
    }

    /**
     * <p>Set the stroke width and color for the drawable. If width is zero,
     * then no stroke is drawn.</p>
@@ -376,15 +410,17 @@ public class GradientDrawable extends Drawable {
    }

    /**
     * <p>Sets the type of gradient used by this drawable..</p>
     * <p><strong>Note</strong>: changing this property will affect all instances
     * Sets the type of gradient used by this drawable.
     * <p>
     * <strong>Note</strong>: changing this property will affect all instances
     * of a drawable loaded from a resource. It is recommended to invoke
     * {@link #mutate()} before changing this property.</p>
     * {@link #mutate()} before changing this property.
     *
     * @param gradient The type of the gradient: {@link #LINEAR_GRADIENT},
     *                 {@link #RADIAL_GRADIENT} or {@link #SWEEP_GRADIENT}
     *
     * @see #mutate()
     * @see #getGradientType()
     */
    public void setGradientType(int gradient) {
        mGradientState.setGradientType(gradient);
@@ -393,17 +429,33 @@ public class GradientDrawable extends Drawable {
    }

    /**
     * <p>Sets the center location of the gradient. The radius is honored only when
     * the gradient type is set to {@link #RADIAL_GRADIENT} or {@link #SWEEP_GRADIENT}.</p>
     * <p><strong>Note</strong>: changing this property will affect all instances
     * Returns the type of gradient used by this drawable, one of
     * {@link #LINEAR_GRADIENT}, {@link #RADIAL_GRADIENT}, or
     * {@link #SWEEP_GRADIENT}.
     *
     * @return the type of gradient used by this drawable
     * @see #setGradientType(int)
     */
    public int getGradientType() {
        return mGradientState.mGradient;
    }

    /**
     * Sets the center location in pixels of the gradient. The radius is
     * honored only when the gradient type is set to {@link #RADIAL_GRADIENT}
     * or {@link #SWEEP_GRADIENT}.
     * <p>
     * <strong>Note</strong>: changing this property will affect all instances
     * of a drawable loaded from a resource. It is recommended to invoke
     * {@link #mutate()} before changing this property.</p>
     * {@link #mutate()} before changing this property.
     *
     * @param x The x coordinate of the gradient's center
     * @param y The y coordinate of the gradient's center
     * @param x the x coordinate of the gradient's center in pixels
     * @param y the y coordinate of the gradient's center in pixels
     *
     * @see #mutate()
     * @see #setGradientType(int)
     * @see #getGradientCenterX()
     * @see #getGradientCenterY()
     */
    public void setGradientCenter(float x, float y) {
        mGradientState.setGradientCenter(x, y);
@@ -412,16 +464,38 @@ public class GradientDrawable extends Drawable {
    }

    /**
     * <p>Sets the radius of the gradient. The radius is honored only when the
     * gradient type is set to {@link #RADIAL_GRADIENT}.</p>
     * <p><strong>Note</strong>: changing this property will affect all instances
     * Returns the center X location of this gradient in pixels.
     *
     * @return the center X location of this gradient in pixels
     * @see #setGradientCenter(float, float)
     */
    public float getGradientCenterX() {
        return mGradientState.mCenterX;
    }

    /**
     * Returns the center Y location of this gradient in pixels.
     *
     * @return the center Y location of this gradient in pixels
     * @see #setGradientCenter(float, float)
     */
    public float getGradientCenterY() {
        return mGradientState.mCenterY;
    }

    /**
     * Sets the radius of the gradient. The radius is honored only when the
     * gradient type is set to {@link #RADIAL_GRADIENT}.
     * <p>
     * <strong>Note</strong>: changing this property will affect all instances
     * of a drawable loaded from a resource. It is recommended to invoke
     * {@link #mutate()} before changing this property.</p>
     * {@link #mutate()} before changing this property.
     *
     * @param gradientRadius The radius of the gradient in pixels
     * @param gradientRadius the radius of the gradient in pixels
     *
     * @see #mutate()
     * @see #setGradientType(int)
     * @see #getGradientRadius()
     */
    public void setGradientRadius(float gradientRadius) {
        mGradientState.setGradientRadius(gradientRadius, TypedValue.COMPLEX_UNIT_PX);
@@ -433,7 +507,8 @@ public class GradientDrawable extends Drawable {
     * Returns the radius of the gradient in pixels. The radius is valid only
     * when the gradient type is set to {@link #RADIAL_GRADIENT}.
     *
     * @return Radius in pixels.
     * @return the radius of the gradient in pixels
     * @see #setGradientRadius(float)
     */
    public float getGradientRadius() {
        if (mGradientState.mGradient != RADIAL_GRADIENT) {
@@ -445,17 +520,19 @@ public class GradientDrawable extends Drawable {
    }

    /**
     * <p>Sets whether or not this drawable will honor its <code>level</code>
     * property.</p>
     * <p><strong>Note</strong>: changing this property will affect all instances
     * Sets whether or not this drawable will honor its {@code level} property.
     * <p>
     * <strong>Note</strong>: changing this property will affect all instances
     * of a drawable loaded from a resource. It is recommended to invoke
     * {@link #mutate()} before changing this property.</p>
     * {@link #mutate()} before changing this property.
     *
     * @param useLevel True if this drawable should honor its level, false otherwise
     * @param useLevel {@code true} if this drawable should honor its level,
     *                 {@code false} otherwise
     *
     * @see #mutate()
     * @see #setLevel(int)
     * @see #getLevel()
     * @see #isUseLevel()
     */
    public void setUseLevel(boolean useLevel) {
        mGradientState.mUseLevel = useLevel;
@@ -463,6 +540,18 @@ public class GradientDrawable extends Drawable {
        invalidateSelf();
    }

    /**
     * Returns whether or not this drawable will honor its {@code level}
     * property.
     *
     * @return {@code true} if this drawable should honor its level,
     *         {@code false} otherwise
     * @see #setUseLevel(boolean)
     */
    public boolean isUseLevel() {
        return mGradientState.mUseLevel;
    }

    private int modulateAlpha(int alpha) {
        int scale = mAlpha + (mAlpha >> 7);
        return alpha * scale >> 8;
@@ -470,20 +559,25 @@ public class GradientDrawable extends Drawable {

    /**
     * Returns the orientation of the gradient defined in this drawable.
     *
     * @return the orientation of the gradient defined in this drawable
     * @see #setOrientation(Orientation)
     */
    public Orientation getOrientation() {
        return mGradientState.mOrientation;
    }

    /**
     * <p>Changes the orientation of the gradient defined in this drawable.</p>
     * <p><strong>Note</strong>: changing orientation will affect all instances
     * Sets the orientation of the gradient defined in this drawable.
     * <p>
     * <strong>Note</strong>: changing orientation will affect all instances
     * of a drawable loaded from a resource. It is recommended to invoke
     * {@link #mutate()} before changing the orientation.</p>
     * {@link #mutate()} before changing the orientation.
     *
     * @param orientation The desired orientation (angle) of the gradient
     * @param orientation the desired orientation (angle) of the gradient
     *
     * @see #mutate()
     * @see #getOrientation()
     */
    public void setOrientation(Orientation orientation) {
        mGradientState.mOrientation = orientation;
@@ -511,6 +605,18 @@ public class GradientDrawable extends Drawable {
        invalidateSelf();
    }

    /**
     * Returns the colors used to draw the gradient, or {@code null} if the
     * gradient is drawn using a single color or no colors.
     *
     * @return the colors used to draw the gradient, or {@code null}
     * @see #setColors(int[] colors)
     */
    @Nullable
    public int[] getColors() {
        return mGradientState.mGradientColors.clone();
    }

    @Override
    public void draw(Canvas canvas) {
        if (!ensureValidRect()) {
@@ -707,15 +813,17 @@ public class GradientDrawable extends Drawable {
    }

    /**
     * <p>Changes this drawable to use a single color instead of a gradient.</p>
     * <p><strong>Note</strong>: changing color will affect all instances
     * of a drawable loaded from a resource. It is recommended to invoke
     * {@link #mutate()} before changing the color.</p>
     * Changes this drawable to use a single color instead of a gradient.
     * <p>
     * <strong>Note</strong>: changing color will affect all instances of a
     * drawable loaded from a resource. It is recommended to invoke
     * {@link #mutate()} before changing the color.
     *
     * @param argb The color used to fill the shape
     *
     * @see #mutate()
     * @see #setColors(int[])
     * @see #getColor
     */
    public void setColor(@ColorInt int argb) {
        mGradientState.setSolidColors(ColorStateList.valueOf(argb));
@@ -734,7 +842,9 @@ public class GradientDrawable extends Drawable {
     * {@link #mutate()} before changing the color.</p>
     *
     * @param colorStateList The color state list used to fill the shape
     *
     * @see #mutate()
     * @see #getColor
     */
    public void setColor(ColorStateList colorStateList) {
        mGradientState.setSolidColors(colorStateList);
@@ -749,6 +859,19 @@ public class GradientDrawable extends Drawable {
        invalidateSelf();
    }

    /**
     * Returns the color state list used to fill the shape, or {@code null} if
     * the shape is filled with a gradient or has no fill color.
     *
     * @return the color state list used to fill this gradient, or {@code null}
     *
     * @see #setColor(int)
     * @see #setColor(ColorStateList)
     */
    public ColorStateList getColor() {
        return mGradientState.mSolidColors;
    }

    @Override
    protected boolean onStateChange(int[] stateSet) {
        boolean invalidateSelf = false;
+13 −1
Original line number Diff line number Diff line
@@ -213,7 +213,12 @@ public class NinePatchDrawable extends Drawable {
        }
    }

    private void setNinePatch(NinePatch ninePatch) {
    /**
     * Sets the nine patch used by this drawable.
     *
     * @param ninePatch the nine patch for this drawable
     */
    public void setNinePatch(NinePatch ninePatch) {
        if (mNinePatch != ninePatch) {
            mNinePatch = ninePatch;
            if (ninePatch != null) {
@@ -226,6 +231,13 @@ public class NinePatchDrawable extends Drawable {
        }
    }

    /**
     * @return the nine patch used by this drawable
     */
    public NinePatch getNinePatch() {
        return mNinePatch;
    }

    @Override
    public void draw(Canvas canvas) {
        final Rect bounds = getBounds();