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 intRadius 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 TypeMethodDescriptionbooleanvoidOptimized for drawing ripples with a mask layer and optional content.Return aDrawable.ConstantStateinstance that holds the shared state of this Drawable.Return the drawable's dirty bounds Rect.voidgetHotspotBounds(Rect outRect) PopulatesoutRectwith the hotspot bounds.voidgetOutline(Outline outline) Populatesoutlinewith the first available layer outline, excluding the mask layer.intbooleanIndicates whether this drawable has at least one state spec explicitly specifying state_focused.voidUse the currentDrawable.Callbackimplementation to have this Drawable redrawn.booleanIndicates whether this drawable will change its appearance based on state.voidIf 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 voidonBoundsChange(Rect bounds) Override this in your subclass to change appearance if you vary based on the bounds.protected booleanonStateChange(int[] stateSet) Override this in your subclass to change appearance if you recognize the specified state.voidsetBackgroundActive(boolean hovered, boolean focused, boolean pressed, boolean windowFocused) voidsetColor(ColorStateList color) Sets the ripple color.booleansetDrawableByLayerId(int id, Drawable drawable) Replaces theDrawablefor the layer with the given id.voidsetEffectColor(ColorStateList color) Sets the ripple effect color.voidsetHotspot(float x, float y) Specifies the hotspot's location within the drawable.voidsetHotspotBounds(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.voidsetRadius(int radius) Sets the radius in pixels of the fully expanded ripple.booleansetVisible(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, unscheduleDrawableMethods 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 benullmask- The mask drawable, may benull
-
-
Method Details
-
jumpToCurrentState
public void jumpToCurrentState()Description copied from class:DrawableIf this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations.- Overrides:
jumpToCurrentStatein classLayerDrawable
-
onStateChange
Description copied from class:DrawableOverride this in your subclass to change appearance if you recognize the specified state.- Overrides:
onStateChangein 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:DrawableOverride this in your subclass to change appearance if you vary based on the bounds.- Overrides:
onBoundsChangein classLayerDrawable
-
setVisible
public boolean setVisible(boolean visible, boolean restart) Description copied from class:DrawableSet 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:
setVisiblein 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:DrawableIndicates 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:
isStatefulin classLayerDrawable- Returns:
- True if this drawable changes its appearance based on state, false otherwise.
- See Also:
-
hasFocusStateSpecified
public boolean hasFocusStateSpecified()Description copied from class:DrawableIndicates whether this drawable has at least one state spec explicitly specifying state_focused.Note: A View uses a
Drawableinstance 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:
hasFocusStateSpecifiedin classLayerDrawable- Returns:
trueif 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_AUTOto 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_AUTOif the radius is computed based on the container size
-
setDrawableByLayerId
Description copied from class:LayerDrawableReplaces theDrawablefor the layer with the given id.- Overrides:
setDrawableByLayerIdin classLayerDrawable- Parameters:
id- The layer ID to search for.drawable- The replacementDrawable.- Returns:
- Whether the
Drawablewas replaced (could return false if the id was not found).
-
canApplyTheme
public boolean canApplyTheme()- Overrides:
canApplyThemein classLayerDrawable
-
setHotspot
public void setHotspot(float x, float y) Description copied from class:DrawableSpecifies the hotspot's location within the drawable.- Overrides:
setHotspotin 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:DrawableSets the bounds to which the hotspot is constrained, if they should be different from the drawable bounds.- Overrides:
setHotspotBoundsin 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:DrawablePopulatesoutRectwith the hotspot bounds.- Overrides:
getHotspotBoundsin classLayerDrawable- Parameters:
outRect- the rect to populate with the hotspot bounds- See Also:
-
getOutline
Populatesoutlinewith the first available layer outline, excluding the mask layer.- Overrides:
getOutlinein 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:
drawin classLayerDrawable- Parameters:
canvas- The canvas to draw into
-
getDirtyBounds
Description copied from class:DrawableReturn 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:
getDirtyBoundsin 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:DrawableUse the currentDrawable.Callbackimplementation to have this Drawable redrawn. Does nothing if there is no Callback attached to the Drawable.- Overrides:
invalidateSelfin classDrawable- See Also:
-
getConstantState
Description copied from class:DrawableReturn aDrawable.ConstantStateinstance that holds the shared state of this Drawable.- Overrides:
getConstantStatein classLayerDrawable- Returns:
- The ConstantState associated to that Drawable.
- See Also:
-
mutate
Description copied from class:DrawableMake 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:
mutatein classLayerDrawable- Returns:
- This drawable.
- See Also:
-