Class RippleDrawable
- All Implemented Interfaces:
Drawable.Callback
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 runtime, a single layer may be set as the
mask using setId(..., R.id.mask)
or an existing mask layer
may be replaced using setDrawableByLayerId(R.id.mask, ...)
.
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.
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class icyllis.modernui.graphics.drawable.Drawable
Drawable.Callback, Drawable.ConstantState
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Radius value that specifies the ripple radius should be computed based on the size of the ripple's container.Fields inherited from class icyllis.modernui.graphics.drawable.LayerDrawable
INSET_UNDEFINED, MARKER, PADDING_MODE_NEST, PADDING_MODE_STACK
-
Constructor Summary
ConstructorsConstructorDescriptionRippleDrawable
(ColorStateList color, Drawable content, Drawable mask) Creates a new ripple drawable with the specified ripple color and optional content and mask drawables. -
Method Summary
Modifier and TypeMethodDescriptionboolean
void
Optimized for drawing ripples with a mask layer and optional content.Return aDrawable.ConstantState
instance that holds the shared state of this Drawable.Return the drawable's dirty bounds Rect.void
getHotspotBounds
(Rect outRect) PopulatesoutRect
with the hotspot bounds.void
getOutline
(Outline outline) Populatesoutline
with the first available layer outline, excluding the mask layer.int
boolean
Indicates whether this drawable has at least one state spec explicitly specifying state_focused.void
Use the currentDrawable.Callback
implementation to have this Drawable redrawn.boolean
Indicates whether this drawable will change its appearance based on state.void
If this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations.mutate()
Make this drawable mutable.protected void
onBoundsChange
(Rect bounds) Override this in your subclass to change appearance if you vary based on the bounds.protected boolean
onStateChange
(int[] stateSet) Override this in your subclass to change appearance if you recognize the specified state.void
setBackgroundActive
(boolean hovered, boolean focused, boolean pressed, boolean windowFocused) void
setColor
(ColorStateList color) Sets the ripple color.boolean
setDrawableByLayerId
(int id, Drawable drawable) Replaces theDrawable
for the layer with the given id.void
setEffectColor
(ColorStateList color) Sets the ripple effect color.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
setRadius
(int radius) Sets the radius in pixels of the fully expanded ripple.boolean
setVisible
(boolean visible, boolean restart) Set whether this Drawable is visible.Methods inherited from class icyllis.modernui.graphics.drawable.LayerDrawable
addLayer, clearMutated, findDrawableByLayerId, findIndexByLayerId, getAlpha, 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, setDrawable, setId, setLayerGravity, setLayerHeight, setLayerInset, setLayerInsetBottom, setLayerInsetEnd, setLayerInsetLeft, setLayerInsetRelative, setLayerInsetRight, setLayerInsetStart, setLayerInsetTop, setLayerSize, setLayerWidth, setPadding, setPaddingMode, setPaddingRelative, setTintBlendMode, setTintList, unscheduleDrawable
Methods inherited from class icyllis.modernui.graphics.drawable.Drawable
applyTheme, copyBounds, copyBounds, getBounds, getCallback, getColorFilter, getCurrent, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getState, isVisible, scaleFromDensity, scaleFromDensity, scheduleSelf, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setLayoutDirection, setLevel, setState, setTint, unscheduleSelf
-
Field Details
-
RADIUS_AUTO
public static final int RADIUS_AUTORadius value that specifies the ripple radius should be computed based on the size of the ripple's container.- See Also:
-
-
Constructor Details
-
RippleDrawable
public RippleDrawable(@NonNull ColorStateList color, @Nullable Drawable content, @Nullable Drawable mask) Creates a new ripple drawable with the specified ripple color and optional content and mask drawables.- Parameters:
color
- The ripple colorcontent
- The content drawable, may benull
mask
- The mask drawable, may benull
-
-
Method Details
-
jumpToCurrentState
public void jumpToCurrentState()Description copied from class:Drawable
If this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations.- Overrides:
jumpToCurrentState
in classLayerDrawable
-
onStateChange
Description copied from class:Drawable
Override this in your subclass to change appearance if you recognize the specified state.- Overrides:
onStateChange
in classLayerDrawable
- Returns:
- Returns true if the state change has caused the appearance of the Drawable to change (that is, it needs to be drawn), else false if it looks the same and there is no need to redraw it since its last state.
-
setBackgroundActive
public void setBackgroundActive(boolean hovered, boolean focused, boolean pressed, boolean windowFocused) -
onBoundsChange
Description copied from class:Drawable
Override this in your subclass to change appearance if you vary based on the bounds.- Overrides:
onBoundsChange
in classLayerDrawable
-
setVisible
public boolean setVisible(boolean visible, boolean restart) Description copied from class:Drawable
Set whether this Drawable is visible. This generally does not impact the Drawable's behavior, but is a hint that can be used by some Drawables, for example, to decide whether run animations.- Overrides:
setVisible
in classLayerDrawable
- Parameters:
visible
- Set to true if visible, false if not.restart
- You can supply true here to force the drawable to behave as if it has just become visible, even if it had last been set visible. Used for example to force animations to restart.- Returns:
- true if the new visibility is different from its previous state.
-
isStateful
public boolean isStateful()Description copied from class:Drawable
Indicates whether this drawable will change its appearance based on state. Clients can use this to determine whether it is necessary to calculate their state and call setState.- Overrides:
isStateful
in classLayerDrawable
- Returns:
- True if this drawable changes its appearance based on state, false otherwise.
- See Also:
-
hasFocusStateSpecified
public boolean hasFocusStateSpecified()Description copied from class:Drawable
Indicates whether this drawable has at least one state spec explicitly specifying state_focused.Note: A View uses a
Drawable
instance as its background and it changes its appearance based on a state. On keyboard devices, it should specify its state_focused to make sure the user knows which view is holding the focus.- Overrides:
hasFocusStateSpecified
in classLayerDrawable
- Returns:
true
if state_focused is specified for this drawable.
-
setColor
Sets the ripple color.- Parameters:
color
- Ripple color as a color state list.
-
setEffectColor
Sets the ripple effect color.- Parameters:
color
- Ripple color as a color state list.
-
getEffectColor
- Returns:
- The ripple effect color as a color state list.
-
setRadius
public void setRadius(int radius) Sets the radius in pixels of the fully expanded ripple.- Parameters:
radius
- ripple radius in pixels, orRADIUS_AUTO
to compute the radius based on the container size
-
getRadius
public int getRadius()- Returns:
- the radius in pixels of the fully expanded ripple if an explicit
radius has been set, or
RADIUS_AUTO
if the radius is computed based on the container size
-
setDrawableByLayerId
Description copied from class:LayerDrawable
Replaces theDrawable
for the layer with the given id.- Overrides:
setDrawableByLayerId
in classLayerDrawable
- Parameters:
id
- The layer ID to search for.drawable
- The replacementDrawable
.- Returns:
- Whether the
Drawable
was replaced (could return false if the id was not found).
-
canApplyTheme
public boolean canApplyTheme()- Overrides:
canApplyTheme
in classLayerDrawable
-
setHotspot
public void setHotspot(float x, float y) Description copied from class:Drawable
Specifies the hotspot's location within the drawable.- Overrides:
setHotspot
in classLayerDrawable
- Parameters:
x
- The X coordinate of the center of the hotspoty
- The Y coordinate of the center of the hotspot
-
setHotspotBounds
public void setHotspotBounds(int left, int top, int right, int bottom) Description copied from class:Drawable
Sets the bounds to which the hotspot is constrained, if they should be different from the drawable bounds.- Overrides:
setHotspotBounds
in classLayerDrawable
- Parameters:
left
- position in pixels of the left boundtop
- position in pixels of the top boundright
- position in pixels of the right boundbottom
- position in pixels of the bottom bound- See Also:
-
getHotspotBounds
Description copied from class:Drawable
PopulatesoutRect
with the hotspot bounds.- Overrides:
getHotspotBounds
in classLayerDrawable
- Parameters:
outRect
- the rect to populate with the hotspot bounds- See Also:
-
getOutline
Populatesoutline
with the first available layer outline, excluding the mask layer.- Overrides:
getOutline
in classLayerDrawable
- Parameters:
outline
- Outline in which to place the first available layer outline- See Also:
-
draw
Optimized for drawing ripples with a mask layer and optional content.- Overrides:
draw
in classLayerDrawable
- Parameters:
canvas
- The canvas to draw into
-
getDirtyBounds
Description copied from class:Drawable
Return the drawable's dirty bounds Rect. Note: for efficiency, the returned object may be the same object stored in the drawable (though this is not guaranteed).By default, this returns the full drawable bounds. Custom drawables may override this method to perform more precise invalidation.
- Overrides:
getDirtyBounds
in classDrawable
- Returns:
- The dirty bounds of this drawable (which may change later, so caller beware). DO NOT ALTER the returned object as it may change the stored bounds of this drawable.
-
invalidateSelf
public void invalidateSelf()Description copied from class:Drawable
Use the currentDrawable.Callback
implementation to have this Drawable redrawn. Does nothing if there is no Callback attached to the Drawable.- Overrides:
invalidateSelf
in classDrawable
- See Also:
-
getConstantState
Description copied from class:Drawable
Return aDrawable.ConstantState
instance that holds the shared state of this Drawable.- Overrides:
getConstantState
in classLayerDrawable
- Returns:
- The ConstantState associated to that Drawable.
- See Also:
-
mutate
Description copied from class:Drawable
Make this drawable mutable. This operation cannot be reversed. A mutable drawable is guaranteed to not share its state with any other drawable. This is especially useful when you need to modify properties of drawables loaded from resources. By default, all drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification.Calling this method on a mutable Drawable will have no effect.
- Overrides:
mutate
in classLayerDrawable
- Returns:
- This drawable.
- See Also:
-