Class DrawableWrapper
- All Implemented Interfaces:
Drawable.Callback
- Direct Known Subclasses:
ClipDrawable,InsetDrawable,ScaleDrawable
-
Nested Class Summary
Nested classes/interfaces inherited from class icyllis.modernui.graphics.drawable.Drawable
Drawable.Callback, Drawable.ConstantState -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new wrapper around the specified drawable. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the mutated state, allowing this drawable to be cached and mutated again.voidDraw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha).intgetAlpha()Gets the current alpha value for the drawable.Return aDrawable.ConstantStateinstance that holds the shared state of this Drawable.voidgetHotspotBounds(Rect outRect) PopulatesoutRectwith the hotspot bounds.intReturns the drawable's intrinsic height.intReturns the drawable's intrinsic width.voidgetOutline(Outline outline) Called to get the drawable to populate the Outline that defines its drawing area.booleangetPadding(Rect padding) Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds.booleanIndicates whether this drawable has at least one state spec explicitly specifying state_focused.voidCalled when the drawable needs to be 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.booleanonLayoutDirectionChanged(int layoutDirection) Called when the drawable's resolved layout direction changes.protected booleanonLevelChange(int level) Override this in your subclass to change appearance if you vary based on level.protected booleanonStateChange(int[] state) Override this in your subclass to change appearance if you recognize the specified state.voidscheduleDrawable(Drawable who, Runnable what, long when) A Drawable can call this to schedule the next frame of its animation.voidsetAlpha(int alpha) Specify an alpha value for the drawable.voidsetDrawable(Drawable dr) Sets the wrapped drawable.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.voidsetTintBlendMode(BlendMode blendMode) Specifies a tint blending mode for this drawable.voidsetTintList(ColorStateList tint) Specifies tint color for this drawable as a color state list.booleansetVisible(boolean visible, boolean restart) Set whether this Drawable is visible.voidunscheduleDrawable(Drawable who, Runnable what) A Drawable can call this to unschedule an action previously scheduled withDrawable.Callback.scheduleDrawable(icyllis.modernui.graphics.drawable.Drawable, java.lang.Runnable, long).Methods inherited from class icyllis.modernui.graphics.drawable.Drawable
applyTheme, canApplyTheme, copyBounds, copyBounds, getBounds, getCallback, getChangingConfigurations, getColorFilter, getCurrent, getDirtyBounds, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getState, invalidateSelf, isAutoMirrored, isVisible, scaleFromDensity, scaleFromDensity, scheduleSelf, setAutoMirrored, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setLayoutDirection, setLevel, setState, setTint, unscheduleSelf
-
Constructor Details
-
DrawableWrapper
Creates a new wrapper around the specified drawable.- Parameters:
dr- the drawable to wrap
-
-
Method Details
-
setDrawable
Sets the wrapped drawable.- Parameters:
dr- the wrapped drawable
-
getDrawable
- Returns:
- the wrapped drawable
-
invalidateDrawable
Description copied from interface:Drawable.CallbackCalled when the drawable needs to be redrawn. A view at this point should invalidate itself (or at least the part of itself where the drawable appears).- Specified by:
invalidateDrawablein interfaceDrawable.Callback- Parameters:
who- The drawable that is requesting the update.
-
scheduleDrawable
Description copied from interface:Drawable.CallbackA Drawable can call this to schedule the next frame of its animation. An implementation can generally simply callHandler.postAtTime(Runnable, Object, long)with the parameters (what, who, when) to perform the scheduling.- Specified by:
scheduleDrawablein interfaceDrawable.Callback- Parameters:
who- The drawable being scheduled.what- The action to execute.when- The time (in milliseconds) to run. The timebase isCore.timeMillis()
-
unscheduleDrawable
Description copied from interface:Drawable.CallbackA Drawable can call this to unschedule an action previously scheduled withDrawable.Callback.scheduleDrawable(icyllis.modernui.graphics.drawable.Drawable, java.lang.Runnable, long). An implementation can generally simply callHandler.removeCallbacks(Runnable, Object)with the parameters (what, who) to unschedule the drawable.- Specified by:
unscheduleDrawablein interfaceDrawable.Callback- Parameters:
who- The drawable being unscheduled.what- The action being unscheduled.
-
draw
Description copied from class:DrawableDraw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha). -
getPadding
Description copied from class:DrawableReturn in padding the insets suggested by this Drawable for placing content inside the drawable's bounds. Positive values move toward the center of the Drawable (setRect.inset(int, int)).- Overrides:
getPaddingin classDrawable- Returns:
- true if this drawable actually has a padding, else false. When false is returned, the padding is always set to 0.
-
setHotspot
public void setHotspot(float x, float y) Description copied from class:DrawableSpecifies the hotspot's location within the drawable.- Overrides:
setHotspotin classDrawable- 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 classDrawable- 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 classDrawable- Parameters:
outRect- the rect to populate with the hotspot bounds- See Also:
-
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 classDrawable- 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.
-
setAlpha
public void setAlpha(int alpha) Description copied from class:DrawableSpecify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque. -
getAlpha
public int getAlpha()Description copied from class:DrawableGets the current alpha value for the drawable. 0 means fully transparent, 255 means fully opaque. This method is implemented by Drawable subclasses and the value returned is specific to how that class treats alpha. The default return value is 255 if the class does not override this method to return a value specific to its use of alpha. -
setTintList
Description copied from class:DrawableSpecifies tint color for this drawable as a color state list.A Drawable's drawing content will be blended together with its tint before it is drawn to the screen.
Note: Setting a color filter via
Drawable.setColorFilter(ColorFilter)overrides tint.- Overrides:
setTintListin classDrawable- Parameters:
tint- Color state list to use for tinting this drawable, ornullto clear the tint- See Also:
-
setTintBlendMode
Description copied from class:DrawableSpecifies a tint blending mode for this drawable.Defines how this drawable's tint color should be blended into the drawable before it is drawn to screen. Default tint mode is
BlendMode.SRC_IN.Note: Setting a color filter via
Drawable.setColorFilter(ColorFilter)- Overrides:
setTintBlendModein classDrawable- Parameters:
blendMode- BlendMode to apply to the drawable, a value of null sets the default blend mode value ofBlendMode.SRC_IN- See Also:
-
onLayoutDirectionChanged
public boolean onLayoutDirectionChanged(int layoutDirection) Description copied from class:DrawableCalled when the drawable's resolved layout direction changes.- Overrides:
onLayoutDirectionChangedin classDrawable- Parameters:
layoutDirection- the new resolved layout direction- Returns:
trueif the layout direction change has caused the appearance of the drawable to change such that it needs to be re-drawn,falseotherwise- See Also:
-
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 classDrawable- 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 classDrawable- Returns:
trueif state_focused is specified for this drawable.
-
onStateChange
Description copied from class:DrawableOverride this in your subclass to change appearance if you recognize the specified state.- Overrides:
onStateChangein classDrawable- 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.
-
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 classDrawable
-
onLevelChange
protected boolean onLevelChange(int level) Description copied from class:DrawableOverride this in your subclass to change appearance if you vary based on level.- Overrides:
onLevelChangein classDrawable- Returns:
- Returns true if the level 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 level.
-
onBoundsChange
Description copied from class:DrawableOverride this in your subclass to change appearance if you vary based on the bounds.- Overrides:
onBoundsChangein classDrawable
-
getIntrinsicWidth
public int getIntrinsicWidth()Description copied from class:DrawableReturns the drawable's intrinsic width.Intrinsic width is the width at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic width, such as a solid color, this method returns -1.
- Overrides:
getIntrinsicWidthin classDrawable- Returns:
- the intrinsic width, or -1 if no intrinsic width
-
getIntrinsicHeight
public int getIntrinsicHeight()Description copied from class:DrawableReturns the drawable's intrinsic height.Intrinsic height is the height at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic height, such as a solid color, this method returns -1.
- Overrides:
getIntrinsicHeightin classDrawable- Returns:
- the intrinsic height, or -1 if no intrinsic height
-
getOutline
Description copied from class:DrawableCalled to get the drawable to populate the Outline that defines its drawing area.This method is called by the default
ViewOutlineProviderto define the outline of the View.The default behavior defines the outline to be the bounding rectangle of 0 alpha. Subclasses that wish to convey a different shape or alpha value must override this method.
- Overrides:
getOutlinein classDrawable- See Also:
-
getConstantState
Description copied from class:DrawableReturn aDrawable.ConstantStateinstance that holds the shared state of this Drawable.- Overrides:
getConstantStatein classDrawable- 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.
-
clearMutated
public void clearMutated()Description copied from class:DrawableClears the mutated state, allowing this drawable to be cached and mutated again.- Overrides:
clearMutatedin classDrawable
-