public class RippleDrawableICS extends LayerDrawable implements RippleDrawable
setHotspot(float, float)
with the corresponding state
attribute identifier.
A touch feedback drawable may contain multiple child layers, including a
special mask layer that is not drawn to the screen. A single layer may be
set as the mask from XML by specifying its android:id
value as
R.id.mask
. At run time, a single layer may be set as the
mask using setId(..., R.id.carbon_mask)
or an existing mask layer
may be replaced using setDrawableByLayerId(R.id.carbon_mask, ...)
.
<!-- A red ripple masked against an opaque rectangle. --/>
<ripple android:color="#ffff0000">
<item android:id="@android:id/mask"
android:drawable="@android:color/white" />
</ripple>
If a mask layer is set, the ripple effect will be masked against that layer
before it is drawn over the composite of the remaining child layers.
If no mask layer is set, the ripple effect is masked against the composite
of the child layers.
<!-- A green ripple drawn atop a black rectangle. --/>
<ripple android:color="#ff00ff00">
<item android:drawable="@android:color/black" />
</ripple>
<!-- A blue ripple drawn atop a drawable resource. --/>
<ripple android:color="#ff0000ff">
<item android:drawable="@drawable/my_drawable" />
</ripple>
If no child layers or mask is specified and the ripple is set as a View
background, the ripple will be drawn atop the first available parent
background within the View's hierarchy. In this case, the drawing region
may extend outside of the Drawable bounds.
<!-- An unbounded red ripple. --/>
<ripple android:color="#ffff0000" />
android.graphics.drawable.Drawable.Callback, android.graphics.drawable.Drawable.ConstantState
RippleDrawable.Style
Modifier and Type | Field and Description |
---|---|
static int |
RADIUS_AUTO
Radius value that specifies the ripple radius should be computed based
on the size of the ripple's container.
|
PADDING_MODE_NEST, PADDING_MODE_STACK
Constructor and Description |
---|
RippleDrawableICS(android.content.res.ColorStateList color,
android.graphics.drawable.Drawable content,
android.graphics.drawable.Drawable mask)
Creates a new ripple drawable with the specified ripple color and
optional content and mask drawables.
|
RippleDrawableICS(android.content.res.ColorStateList color,
android.graphics.drawable.Drawable background,
RippleDrawable.Style style) |
Modifier and Type | Method and Description |
---|---|
void |
applyTheme(android.content.res.Resources.Theme t)
Applies the specified theme to this Drawable and its children.
|
boolean |
canApplyTheme() |
void |
draw(android.graphics.Canvas canvas)
Optimized for drawing ripples with a mask layer and optional content.
|
int |
getAlpha()
Gets the current alpha value for the drawable. 0 means fully transparent,
255 means fully opaque.
|
android.graphics.drawable.Drawable |
getBackground() |
android.content.res.ColorStateList |
getColor() |
android.graphics.drawable.Drawable.ConstantState |
getConstantState() |
android.graphics.Rect |
getDirtyBounds() |
void |
getHotspotBounds(android.graphics.Rect outRect) |
int |
getOpacity() |
void |
getOutline(android.graphics.Outline outline)
Populates
outline with the first available layer outline,
excluding the mask layer. |
int |
getRadius() |
RippleDrawable.Style |
getStyle() |
void |
inflate(android.content.res.Resources r,
org.xmlpull.v1.XmlPullParser parser,
android.util.AttributeSet attrs,
android.content.res.Resources.Theme theme)
Inflate this Drawable from an XML resource optionally styled by a theme.
|
void |
invalidateSelf() |
boolean |
isHotspotEnabled() |
boolean |
isStateful() |
void |
jumpToCurrentState() |
android.graphics.drawable.Drawable |
mutate() |
protected void |
onBoundsChange(android.graphics.Rect bounds) |
protected boolean |
onStateChange(int[] stateSet) |
void |
setColor(android.content.res.ColorStateList color)
Sets the ripple color.
|
boolean |
setDrawableByLayerId(int id,
android.graphics.drawable.Drawable drawable)
Replaces the
Drawable for the layer with the given id. |
void |
setHotspot(float x,
float y)
Specifies the hotspot's location within the drawable.
|
void |
setHotspotBounds(int left,
int top,
int right,
int bottom)
Sets the bounds to which the hotspot is constrained, if they should be
different from the drawable bounds.
|
void |
setHotspotEnabled(boolean useHotspot) |
void |
setPaddingMode(int mode)
Specifies how layer padding should affect the bounds of subsequent
layers.
|
void |
setRadius(int radius)
Sets the radius in pixels of the fully expanded ripple.
|
boolean |
setVisible(boolean visible,
boolean restart) |
addLayer, findDrawableByLayerId, findIndexByLayerId, getBottomPadding, getChangingConfigurations, getDrawable, getEndPadding, getId, getIntrinsicHeight, getIntrinsicWidth, getLayerGravity, getLayerHeight, getLayerInsetBottom, getLayerInsetEnd, getLayerInsetLeft, getLayerInsetRight, getLayerInsetStart, getLayerInsetTop, getLayerWidth, getLeftPadding, getNumberOfLayers, getPadding, getPaddingMode, getRightPadding, getStartPadding, getTopPadding, invalidateDrawable, isAutoMirrored, onLayoutDirectionChanged, onLevelChange, scheduleDrawable, setAlpha, setAutoMirrored, setColorFilter, setDither, setDrawable, setId, setLayerGravity, setLayerHeight, setLayerInset, setLayerInsetBottom, setLayerInsetEnd, setLayerInsetLeft, setLayerInsetRelative, setLayerInsetRight, setLayerInsetStart, setLayerInsetTop, setLayerSize, setLayerWidth, setOpacity, setPadding, setPaddingRelative, setTintList, setTintMode, unscheduleDrawable
getColorFilter, setTint
clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXml, createFromXmlInner, createFromXmlInner, getBounds, getCallback, getCurrent, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getState, getTransparentRegion, inflate, isFilterBitmap, isVisible, resolveOpacity, scheduleSelf, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setFilterBitmap, setLayoutDirection, setLevel, setState, unscheduleSelf
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setAlpha, setBounds, setBounds, setCallback, setColorFilter, setState
public static final int RADIUS_AUTO
public RippleDrawableICS(android.content.res.ColorStateList color, android.graphics.drawable.Drawable background, RippleDrawable.Style style)
public RippleDrawableICS(@NonNull android.content.res.ColorStateList color, @Nullable android.graphics.drawable.Drawable content, @Nullable android.graphics.drawable.Drawable mask)
color
- The ripple colorcontent
- The content drawable, may be null
mask
- The mask drawable, may be null
public void jumpToCurrentState()
jumpToCurrentState
in interface RippleDrawable
jumpToCurrentState
in class android.graphics.drawable.Drawable
public int getOpacity()
getOpacity
in interface RippleDrawable
getOpacity
in class LayerDrawable
protected boolean onStateChange(int[] stateSet)
onStateChange
in class LayerDrawable
protected void onBoundsChange(android.graphics.Rect bounds)
onBoundsChange
in class LayerDrawable
public boolean setVisible(boolean visible, boolean restart)
setVisible
in class LayerDrawable
public boolean isStateful()
isStateful
in interface RippleDrawable
isStateful
in class LayerDrawable
public void setColor(android.content.res.ColorStateList color)
color
- Ripple color as a color state list.public void setRadius(int radius)
setRadius
in interface RippleDrawable
radius
- ripple radius in pixels, or RADIUS_AUTO
to compute the radius based on
the container sizepublic int getRadius()
getRadius
in interface RippleDrawable
RADIUS_AUTO
if the radius is computed based on the container sizepublic void inflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs, android.content.res.Resources.Theme theme) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
LollipopDrawable
inflate
in class LayerDrawable
r
- Resources used to resolve attribute valuesparser
- XML parser from which to inflate this Drawableattrs
- Base set of attribute valuestheme
- Theme to apply, may be nullorg.xmlpull.v1.XmlPullParserException
java.io.IOException
public boolean setDrawableByLayerId(int id, android.graphics.drawable.Drawable drawable)
LayerDrawable
Drawable
for the layer with the given id.setDrawableByLayerId
in class LayerDrawable
id
- The layer ID to search for.drawable
- The replacement Drawable
.Drawable
was replaced (could return false if the id was not
found).public void setPaddingMode(int mode)
LayerDrawable.PADDING_MODE_STACK
.setPaddingMode
in class LayerDrawable
mode
- padding mode, one of: LayerDrawable.PADDING_MODE_NEST
to nest each layer
inside the padding of the previous layer LayerDrawable.PADDING_MODE_STACK
to stack
each layer directly atop the previous layer LayerDrawable.getPaddingMode()
public void applyTheme(android.content.res.Resources.Theme t)
LollipopDrawable
applyTheme
in class LayerDrawable
public boolean canApplyTheme()
canApplyTheme
in class LayerDrawable
public void setHotspot(float x, float y)
LollipopDrawable
setHotspot
in interface RippleDrawable
setHotspot
in class LayerDrawable
x
- The X coordinate of the center of the hotspoty
- The Y coordinate of the center of the hotspotpublic void setHotspotBounds(int left, int top, int right, int bottom)
LollipopDrawable
setHotspotBounds
in class LayerDrawable
public void getHotspotBounds(android.graphics.Rect outRect)
getHotspotBounds
in class LayerDrawable
public void getOutline(@NonNull android.graphics.Outline outline)
outline
with the first available layer outline,
excluding the mask layer.getOutline
in class LayerDrawable
outline
- Outline in which to place the first available layer outlinepublic void draw(@NonNull android.graphics.Canvas canvas)
draw
in interface RippleDrawable
draw
in class LayerDrawable
public void invalidateSelf()
invalidateSelf
in class android.graphics.drawable.Drawable
public android.graphics.Rect getDirtyBounds()
getDirtyBounds
in class android.graphics.drawable.Drawable
public android.graphics.drawable.Drawable.ConstantState getConstantState()
getConstantState
in class LayerDrawable
public android.graphics.drawable.Drawable mutate()
mutate
in class LayerDrawable
public android.graphics.drawable.Drawable getBackground()
getBackground
in interface RippleDrawable
public RippleDrawable.Style getStyle()
getStyle
in interface RippleDrawable
public boolean isHotspotEnabled()
isHotspotEnabled
in interface RippleDrawable
public void setHotspotEnabled(boolean useHotspot)
setHotspotEnabled
in interface RippleDrawable
public android.content.res.ColorStateList getColor()
getColor
in interface RippleDrawable
public int getAlpha()
LollipopDrawable
getAlpha
in interface AlphaDrawable
getAlpha
in interface RippleDrawable
getAlpha
in class LayerDrawable