Class PositionableGradientDrawable
- java.lang.Object
-
- android.graphics.drawable.Drawable
-
- com.batch.android.messaging.view.PositionableGradientDrawable
-
public class PositionableGradientDrawable extends android.graphics.drawable.DrawableA Drawable with a color gradient for buttons, backgrounds, etc.Tweaked for Batch: No XML support, added support for setting the color positions Tinting is also broken, due to private APIs
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPositionableGradientDrawable.OrientationControls how the gradient is oriented relative to the drawable's bounds
-
Field Summary
Fields Modifier and Type Field Description static intLINEShape is a linestatic intLINEAR_GRADIENTGradient is linear (default.)static intOVALShape is an ellipsestatic intRADIAL_GRADIENTGradient is circular.static intRECTANGLEShape is a rectangle, possibly with rounded cornersstatic intRINGShape is a ring.static intSWEEP_GRADIENTGradient is a sweep.
-
Constructor Summary
Constructors Constructor Description PositionableGradientDrawable()PositionableGradientDrawable(PositionableGradientDrawable.Orientation orientation, int[] colors, float[] positions)Create a new gradient drawable given an orientation and an array of colors for the gradient.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearMutated()voiddraw(android.graphics.Canvas canvas)intgetAlpha()intgetChangingConfigurations()android.graphics.ColorFiltergetColorFilter()android.graphics.drawable.Drawable.ConstantStategetConstantState()floatgetGradientRadius()Returns the radius of the gradient in pixels.intgetIntrinsicHeight()intgetIntrinsicWidth()intgetOpacity()PositionableGradientDrawable.OrientationgetOrientation()Returns the orientation of the gradient defined in this drawable.voidgetOutline(android.graphics.Outline outline)booleangetPadding(android.graphics.Rect padding)booleanisStateful()android.graphics.drawable.Drawablemutate()protected voidonBoundsChange(android.graphics.Rect r)protected booleanonLevelChange(int level)protected booleanonStateChange(int[] stateSet)voidsetAlpha(int alpha)voidsetColor(int argb)Changes this drawable to use a single color instead of a gradient.voidsetColor(android.content.res.ColorStateList colorStateList)Changes this drawable to use a single color state list instead of a gradient.voidsetColorFilter(android.graphics.ColorFilter colorFilter)voidsetColors(int[] colors, float[] positions)Sets the colors used to draw the gradient.voidsetCornerRadii(float[] radii)Specify radii for each of the 4 corners.voidsetCornerRadius(float radius)Specify radius for the corners of the gradient.voidsetDither(boolean dither)voidsetGradientCenter(float x, float y)Sets the center location of the gradient.voidsetGradientRadius(float gradientRadius)Sets the radius of the gradient.voidsetGradientType(int gradient)Sets the type of gradient used by this drawable..voidsetOrientation(PositionableGradientDrawable.Orientation orientation)Changes the orientation of the gradient defined in this drawable.voidsetShape(int shape)Sets the type of shape used to draw the gradient.voidsetSize(int width, int height)Sets the size of the shape drawn by this drawable.voidsetStroke(int width, int color)Set the stroke width and color for the drawable.voidsetStroke(int width, int color, float dashWidth, float dashGap)Set the stroke width and color for the drawable.voidsetStroke(int width, android.content.res.ColorStateList colorStateList)Set the stroke width and color state list for the drawable.voidsetStroke(int width, android.content.res.ColorStateList colorStateList, float dashWidth, float dashGap)Set the stroke width and color state list for the drawable.voidsetTintList(android.content.res.ColorStateList tint)voidsetTintMode(android.graphics.PorterDuff.Mode tintMode)voidsetUseLevel(boolean useLevel)Sets whether or not this drawable will honor itslevelproperty.-
Methods inherited from class android.graphics.drawable.Drawable
applyTheme, canApplyTheme, clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXml, createFromXmlInner, createFromXmlInner, getBounds, getCallback, getCurrent, getDirtyBounds, getHotspotBounds, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getOpticalInsets, getState, getTransparentRegion, hasFocusStateSpecified, inflate, inflate, invalidateSelf, isAutoMirrored, isFilterBitmap, isProjected, isVisible, jumpToCurrentState, onLayoutDirectionChanged, resolveOpacity, scheduleSelf, setAutoMirrored, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setFilterBitmap, setHotspot, setHotspotBounds, setLayoutDirection, setLevel, setState, setTint, setTintBlendMode, setVisible, unscheduleSelf
-
-
-
-
Field Detail
-
RECTANGLE
public static final int RECTANGLE
Shape is a rectangle, possibly with rounded corners- See Also:
- Constant Field Values
-
OVAL
public static final int OVAL
Shape is an ellipse- See Also:
- Constant Field Values
-
LINE
public static final int LINE
Shape is a line- See Also:
- Constant Field Values
-
RING
public static final int RING
Shape is a ring.- See Also:
- Constant Field Values
-
LINEAR_GRADIENT
public static final int LINEAR_GRADIENT
Gradient is linear (default.)- See Also:
- Constant Field Values
-
RADIAL_GRADIENT
public static final int RADIAL_GRADIENT
Gradient is circular.- See Also:
- Constant Field Values
-
SWEEP_GRADIENT
public static final int SWEEP_GRADIENT
Gradient is a sweep.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PositionableGradientDrawable
public PositionableGradientDrawable()
-
PositionableGradientDrawable
public PositionableGradientDrawable(PositionableGradientDrawable.Orientation orientation, int[] colors, float[] positions)
Create a new gradient drawable given an orientation and an array of colors for the gradient.
-
-
Method Detail
-
getPadding
public boolean getPadding(android.graphics.Rect padding)
- Overrides:
getPaddingin classandroid.graphics.drawable.Drawable
-
setCornerRadii
public void setCornerRadii(float[] radii)
Specify radii for each of the 4 corners. For each corner, the array contains 2 values,
[X_radius, Y_radius]. The corners are ordered top-left, top-right, bottom-right, bottom-left. This property is honored only when the shape is of typeRECTANGLE.Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing this property.- Parameters:
radii- 4 pairs of X and Y radius for each corner, specified in pixels. The length of this array must be >= 8- See Also:
mutate(),setCornerRadii(float[]),setShape(int)
-
setCornerRadius
public void setCornerRadius(float radius)
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
RECTANGLE.Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing this property.- Parameters:
radius- The radius in pixels of the corners of the rectangle shape- See Also:
mutate(),setCornerRadii(float[]),setShape(int)
-
setStroke
public void setStroke(int width, int color)Set the stroke width and color for the drawable. If width is zero, then no stroke is drawn.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing this property.- Parameters:
width- The width in pixels of the strokecolor- The color of the stroke- See Also:
mutate(),setStroke(int, int, float, float)
-
setStroke
public void setStroke(int width, android.content.res.ColorStateList colorStateList)Set the stroke width and color state list for the drawable. If width is zero, then no stroke is drawn.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing this property.- Parameters:
width- The width in pixels of the strokecolorStateList- The color state list of the stroke- See Also:
mutate(),setStroke(int, ColorStateList, float, float)
-
setStroke
public void setStroke(int width, int color, float dashWidth, float dashGap)Set the stroke width and color for the drawable. If width is zero, then no stroke is drawn. This method can also be used to dash the stroke.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing this property.- Parameters:
width- The width in pixels of the strokecolor- The color of the strokedashWidth- The length in pixels of the dashes, set to 0 to disable dashesdashGap- The gap in pixels between dashes- See Also:
mutate(),setStroke(int, int)
-
setStroke
public void setStroke(int width, android.content.res.ColorStateList colorStateList, float dashWidth, float dashGap)Set the stroke width and color state list for the drawable. If width is zero, then no stroke is drawn. This method can also be used to dash the stroke.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing this property.- Parameters:
width- The width in pixels of the strokecolorStateList- The color state list of the strokedashWidth- The length in pixels of the dashes, set to 0 to disable dashesdashGap- The gap in pixels between dashes- See Also:
mutate(),setStroke(int, ColorStateList)
-
setSize
public void setSize(int width, int height)Sets the size of the shape drawn by this drawable.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing this property.- Parameters:
width- The width of the shape used by this drawableheight- The height of the shape used by this drawable- See Also:
mutate(),setGradientType(int)
-
setShape
public void setShape(int shape)
Sets the type of shape used to draw the gradient.
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing this property.
-
setGradientType
public void setGradientType(int gradient)
Sets the type of gradient used by this drawable..
Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing this property.- Parameters:
gradient- The type of the gradient:LINEAR_GRADIENT,RADIAL_GRADIENTorSWEEP_GRADIENT- See Also:
mutate()
-
setGradientCenter
public void setGradientCenter(float x, float y)Sets the center location of the gradient. The radius is honored only when the gradient type is set to
RADIAL_GRADIENTorSWEEP_GRADIENT.Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing this property.- Parameters:
x- The x coordinate of the gradient's centery- The y coordinate of the gradient's center- See Also:
mutate(),setGradientType(int)
-
setGradientRadius
public void setGradientRadius(float gradientRadius)
Sets the radius of the gradient. The radius is honored only when the gradient type is set to
RADIAL_GRADIENT.Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing this property.- Parameters:
gradientRadius- The radius of the gradient in pixels- See Also:
mutate(),setGradientType(int)
-
getGradientRadius
public float getGradientRadius()
Returns the radius of the gradient in pixels. The radius is valid only when the gradient type is set toRADIAL_GRADIENT.- Returns:
- Radius in pixels.
-
setUseLevel
public void setUseLevel(boolean useLevel)
Sets whether or not this drawable will honor its
levelproperty.Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing this property.- Parameters:
useLevel- True if this drawable should honor its level, false otherwise- See Also:
mutate(),Drawable.setLevel(int),Drawable.getLevel()
-
getOrientation
public PositionableGradientDrawable.Orientation getOrientation()
Returns the orientation of the gradient defined in this drawable.
-
setOrientation
public void setOrientation(PositionableGradientDrawable.Orientation orientation)
Changes the orientation of the gradient defined in this drawable.
Note: changing orientation will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing the orientation.- Parameters:
orientation- The desired orientation (angle) of the gradient- See Also:
mutate()
-
setColors
public void setColors(int[] colors, float[] positions)Sets the colors used to draw the gradient.Each color is specified as an ARGB integer and the array must contain at least 2 colors.
Note: changing colors will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing the colors.- Parameters:
colors- an array containing 2 or more ARGB colors- See Also:
mutate(),setColor(int)
-
draw
public void draw(android.graphics.Canvas canvas)
- Specified by:
drawin classandroid.graphics.drawable.Drawable
-
setColor
public void setColor(int argb)
Changes this drawable to use a single color instead of a gradient.
Note: changing color will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing the color.- Parameters:
argb- The color used to fill the shape- See Also:
mutate(),setColors(int[], float[])
-
setColor
public void setColor(android.content.res.ColorStateList colorStateList)
Changes this drawable to use a single color state list instead of a gradient. Calling this method with a null argument will clear the color and is equivalent to callingsetColor(int)with the argumentColor.TRANSPARENT.Note: changing color will affect all instances of a drawable loaded from a resource. It is recommended to invoke
mutate()before changing the color.- Parameters:
colorStateList- The color state list used to fill the shape- See Also:
mutate()
-
onStateChange
protected boolean onStateChange(int[] stateSet)
- Overrides:
onStateChangein classandroid.graphics.drawable.Drawable
-
isStateful
public boolean isStateful()
- Overrides:
isStatefulin classandroid.graphics.drawable.Drawable
-
getChangingConfigurations
public int getChangingConfigurations()
- Overrides:
getChangingConfigurationsin classandroid.graphics.drawable.Drawable
-
setAlpha
public void setAlpha(int alpha)
- Specified by:
setAlphain classandroid.graphics.drawable.Drawable
-
getAlpha
public int getAlpha()
- Overrides:
getAlphain classandroid.graphics.drawable.Drawable
-
setDither
public void setDither(boolean dither)
- Overrides:
setDitherin classandroid.graphics.drawable.Drawable
-
getColorFilter
public android.graphics.ColorFilter getColorFilter()
- Overrides:
getColorFilterin classandroid.graphics.drawable.Drawable
-
setColorFilter
public void setColorFilter(android.graphics.ColorFilter colorFilter)
- Specified by:
setColorFilterin classandroid.graphics.drawable.Drawable
-
setTintList
public void setTintList(android.content.res.ColorStateList tint)
- Overrides:
setTintListin classandroid.graphics.drawable.Drawable
-
setTintMode
public void setTintMode(android.graphics.PorterDuff.Mode tintMode)
- Overrides:
setTintModein classandroid.graphics.drawable.Drawable
-
getOpacity
public int getOpacity()
- Specified by:
getOpacityin classandroid.graphics.drawable.Drawable
-
onBoundsChange
protected void onBoundsChange(android.graphics.Rect r)
- Overrides:
onBoundsChangein classandroid.graphics.drawable.Drawable
-
onLevelChange
protected boolean onLevelChange(int level)
- Overrides:
onLevelChangein classandroid.graphics.drawable.Drawable
-
getIntrinsicWidth
public int getIntrinsicWidth()
- Overrides:
getIntrinsicWidthin classandroid.graphics.drawable.Drawable
-
getIntrinsicHeight
public int getIntrinsicHeight()
- Overrides:
getIntrinsicHeightin classandroid.graphics.drawable.Drawable
-
getConstantState
public android.graphics.drawable.Drawable.ConstantState getConstantState()
- Overrides:
getConstantStatein classandroid.graphics.drawable.Drawable
-
getOutline
public void getOutline(android.graphics.Outline outline)
- Overrides:
getOutlinein classandroid.graphics.drawable.Drawable
-
mutate
public android.graphics.drawable.Drawable mutate()
- Overrides:
mutatein classandroid.graphics.drawable.Drawable
-
clearMutated
public void clearMutated()
-
-