public class DrawableContainer extends Drawable implements Drawable.Callback
Drawable
s and selects which one to use.
You can subclass it to create your own DrawableContainers or directly use one its child classes.Modifier and Type | Class and Description |
---|---|
static class |
DrawableContainer.DrawableContainerState
A ConstantState that can contain several
Drawable s. |
Drawable.Callback, Drawable.ConstantState
Constructor and Description |
---|
DrawableContainer() |
Modifier and Type | Method and Description |
---|---|
void |
applyTheme(Resources.Theme theme)
Applies the specified theme to this Drawable and its children.
|
boolean |
canApplyTheme() |
void |
clearMutated()
Clears the mutated state, allowing this drawable to be cached and
mutated again.
|
void |
draw(Canvas canvas)
Draw in its bounds (set via setBounds) respecting optional effects such
as alpha (set via setAlpha) and color filter (set via setColorFilter).
|
int |
getAlpha()
Gets the current alpha value for the drawable. 0 means fully transparent,
255 means fully opaque.
|
int |
getChangingConfigurations()
Return a mask of the configuration parameters for which this drawable
may change, requiring that it be re-created.
|
Drawable.ConstantState |
getConstantState()
Return a
Drawable.ConstantState instance that holds the shared state of this Drawable. |
Drawable |
getCurrent() |
int |
getCurrentIndex() |
void |
getHotspotBounds(Rect outRect)
Populates
outRect with the hotspot bounds. |
int |
getIntrinsicHeight()
Returns the drawable's intrinsic height.
|
int |
getIntrinsicWidth()
Returns the drawable's intrinsic width.
|
int |
getMinimumHeight()
Returns the minimum height suggested by this Drawable.
|
int |
getMinimumWidth()
Returns the minimum width suggested by this Drawable.
|
int |
getOpacity()
Return the opacity/transparency of this Drawable.
|
Insets |
getOpticalInsets()
Return in insets the layout insets suggested by this Drawable for use with alignment
operations during layout.
|
void |
getOutline(Outline outline)
Called to get the drawable to populate the Outline that defines its drawing area.
|
boolean |
getPadding(Rect padding)
Return in padding the insets suggested by this Drawable for placing
content inside the drawable's bounds.
|
void |
invalidateDrawable(Drawable who)
Called when the drawable needs to be redrawn.
|
boolean |
isAutoMirrored()
Tells if this Drawable will be automatically mirrored when its layout direction is RTL
right-to-left.
|
boolean |
isStateful()
Indicates whether this drawable will change its appearance based on
state.
|
void |
jumpToCurrentState()
If this Drawable does transition animations between states, ask that
it immediately jump to the current state and skip any active animations.
|
Drawable |
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.
|
boolean |
onLayoutDirectionChanged(int layoutDirection)
Called when the drawable's resolved layout direction changes.
|
protected boolean |
onLevelChange(int level)
Override this in your subclass to change appearance if you vary based
on level.
|
protected boolean |
onStateChange(int[] state)
Override this in your subclass to change appearance if you recognize the
specified state.
|
void |
scheduleDrawable(Drawable who,
Runnable what,
long when)
A Drawable can call this to schedule the next frame of its
animation.
|
boolean |
selectDrawable(int index)
Sets the currently displayed drawable by index.
|
void |
setAlpha(int alpha)
Specify an alpha value for the drawable. 0 means fully transparent, and
255 means fully opaque.
|
void |
setAutoMirrored(boolean mirrored)
Set whether this Drawable is automatically mirrored when its layout direction is RTL
(right-to left).
|
void |
setColorFilter(ColorFilter colorFilter)
Specify an optional color filter for the drawable.
|
protected void |
setConstantState(DrawableContainer.DrawableContainerState state) |
void |
setCurrentIndex(int index) |
void |
setDither(boolean dither)
Set to true to have the drawable dither its colors when drawn to a
device with fewer than 8-bits per color component.
|
void |
setEnterFadeDuration(int ms)
Change the global fade duration when a new drawable is entering
the scene.
|
void |
setExitFadeDuration(int ms)
Change the global fade duration when a new drawable is leaving
the scene.
|
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 |
setTintList(ColorStateList tint)
Specifies tint color for this drawable as a color state list.
|
void |
setTintMode(PorterDuff.Mode tintMode)
Specifies a tint blending mode for this drawable.
|
boolean |
setVisible(boolean visible,
boolean restart)
Set whether this Drawable is visible.
|
void |
unscheduleDrawable(Drawable who,
Runnable what)
A Drawable can call this to unschedule an action previously
scheduled with
Drawable.Callback.scheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable, long) . |
protected void |
updateDensity(Resources res)
Updates the source density based on the resources used to inflate
density-dependent values.
|
clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXml, createFromXmlInner, createFromXmlInner, getBounds, getCallback, getColorFilter, getDirtyBounds, getLayoutDirection, getLevel, getState, getTransparentRegion, inflate, inflate, invalidateSelf, isFilterBitmap, isProjected, isVisible, obtainAttributes, parseTintMode, resolveOpacity, scheduleSelf, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setFilterBitmap, setLayoutDirection, setLevel, setState, setTint, setXfermode, unscheduleSelf
public void draw(Canvas canvas)
Drawable
public int getChangingConfigurations()
Drawable
Drawable.setChangingConfigurations(int)
or 0 by default. Subclasses
may extend this to or in the changing configurations of any other
drawables they hold.getChangingConfigurations
in class Drawable
ActivityInfo
.ActivityInfo
public boolean getPadding(Rect padding)
Drawable
getPadding
in class Drawable
public Insets getOpticalInsets()
Drawable
getOpticalInsets
in class Drawable
public void getOutline(Outline outline)
Drawable
This method is called by the default ViewOutlineProvider
to 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.
getOutline
in class Drawable
View.setOutlineProvider(android.view.ViewOutlineProvider)
public void setAlpha(int alpha)
Drawable
public int getAlpha()
Drawable
public void setDither(boolean dither)
Drawable
setDither
in class Drawable
Paint.setDither(boolean);
public void setColorFilter(ColorFilter colorFilter)
Drawable
If a Drawable has a ColorFilter, each output pixel of the Drawable's drawing contents will be modified by the color filter before it is blended onto the render target of a Canvas.
Pass null
to remove any existing color filter.
Note: Setting a non-null
color
filter disables tint
.
setColorFilter
in class Drawable
colorFilter
- The color filter to apply, or null
to remove the
existing color filterpublic void setTintList(ColorStateList tint)
Drawable
A Drawable's drawing content will be blended together with its tint
before it is drawn to the screen. This functions similarly to
Drawable.setColorFilter(int, PorterDuff.Mode)
.
Note: Setting a color filter via
Drawable.setColorFilter(ColorFilter)
or
Drawable.setColorFilter(int, PorterDuff.Mode)
overrides tint.
setTintList
in class Drawable
tint
- Color state list to use for tinting this drawable, or
null
to clear the tintDrawable.setTint(int)
,
Drawable.setTintMode(PorterDuff.Mode)
public void setTintMode(PorterDuff.Mode tintMode)
Drawable
Defines how this drawable's tint color should be blended into the drawable
before it is drawn to screen. Default tint mode is PorterDuff.Mode#SRC_IN
.
Note: Setting a color filter via
Drawable.setColorFilter(ColorFilter)
or
Drawable.setColorFilter(int, PorterDuff.Mode)
overrides tint.
setTintMode
in class Drawable
tintMode
- A Porter-Duff blending modeDrawable.setTint(int)
,
Drawable.setTintList(ColorStateList)
public void setEnterFadeDuration(int ms)
ms
- The amount of time to fade in milliseconds.public void setExitFadeDuration(int ms)
ms
- The amount of time to fade in milliseconds.protected void onBoundsChange(Rect bounds)
Drawable
onBoundsChange
in class Drawable
public boolean isStateful()
Drawable
isStateful
in class Drawable
Drawable.setState(int[])
public void setAutoMirrored(boolean mirrored)
Drawable
LayoutDirection
.setAutoMirrored
in class Drawable
mirrored
- Set to true if the Drawable should be mirrored, false if not.public boolean isAutoMirrored()
Drawable
LayoutDirection
.isAutoMirrored
in class Drawable
public void jumpToCurrentState()
Drawable
jumpToCurrentState
in class Drawable
public void setHotspot(float x, float y)
Drawable
setHotspot
in class Drawable
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)
Drawable
setHotspotBounds
in class Drawable
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 boundDrawable.getHotspotBounds(android.graphics.Rect)
public void getHotspotBounds(Rect outRect)
Drawable
outRect
with the hotspot bounds.getHotspotBounds
in class Drawable
outRect
- the rect to populate with the hotspot boundsDrawable.setHotspotBounds(int, int, int, int)
protected boolean onStateChange(int[] state)
Drawable
onStateChange
in class Drawable
protected boolean onLevelChange(int level)
Drawable
onLevelChange
in class Drawable
public boolean onLayoutDirectionChanged(int layoutDirection)
Drawable
onLayoutDirectionChanged
in class Drawable
layoutDirection
- the new resolved layout directiontrue
if the layout direction change has caused the
appearance of the drawable to change such that it needs to be
re-drawn, false
otherwiseDrawable.setLayoutDirection(int)
public int getIntrinsicWidth()
Drawable
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.
getIntrinsicWidth
in class Drawable
public int getIntrinsicHeight()
Drawable
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.
getIntrinsicHeight
in class Drawable
public int getMinimumWidth()
Drawable
getMinimumWidth
in class Drawable
public int getMinimumHeight()
Drawable
getMinimumHeight
in class Drawable
public void invalidateDrawable(Drawable who)
Drawable.Callback
invalidateDrawable
in interface Drawable.Callback
who
- The drawable that is requesting the update.public void scheduleDrawable(Drawable who, Runnable what, long when)
Drawable.Callback
Handler.postAtTime(Runnable, Object, long)
with
the parameters (what, who, when) to perform the
scheduling.scheduleDrawable
in interface Drawable.Callback
who
- The drawable being scheduled.what
- The action to execute.when
- The time (in milliseconds) to run. The timebase is
SystemClock.uptimeMillis()
public void unscheduleDrawable(Drawable who, Runnable what)
Drawable.Callback
Drawable.Callback.scheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable, long)
. An implementation can
generally simply call
Handler.removeCallbacks(Runnable, Object)
with
the parameters (what, who) to unschedule the drawable.unscheduleDrawable
in interface Drawable.Callback
who
- The drawable being unscheduled.what
- The action being unscheduled.public boolean setVisible(boolean visible, boolean restart)
Drawable
setVisible
in class Drawable
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.public int getOpacity()
Drawable
PixelFormat
:
PixelFormat.UNKNOWN
,
PixelFormat.TRANSLUCENT
,
PixelFormat.TRANSPARENT
, or
PixelFormat.OPAQUE
.
An OPAQUE drawable is one that draws all all content within its bounds, completely covering anything behind the drawable. A TRANSPARENT drawable is one that draws nothing within its bounds, allowing everything behind it to show through. A TRANSLUCENT drawable is a drawable in any other state, where the drawable will draw some, but not all, of the content within its bounds and at least some content behind the drawable will be visible. If the visibility of the drawable's contents cannot be determined, the safest/best return value is TRANSLUCENT.
Generally a Drawable should be as conservative as possible with the
value it returns. For example, if it contains multiple child drawables
and only shows one of them at a time, if only one of the children is
TRANSLUCENT and the others are OPAQUE then TRANSLUCENT should be
returned. You can use the method Drawable.resolveOpacity(int, int)
to perform a
standard reduction of two opacities to the appropriate single output.
Note that the returned value does not necessarily take into account a
custom alpha or color filter that has been applied by the client through
the Drawable.setAlpha(int)
or Drawable.setColorFilter(android.graphics.ColorFilter)
methods. Some subclasses,
such as BitmapDrawable
, ColorDrawable
, and GradientDrawable
,
do account for the value of Drawable.setAlpha(int)
, but the general behavior is dependent
upon the implementation of the subclass.
getOpacity
in class Drawable
PixelFormat
public void setCurrentIndex(int index)
public int getCurrentIndex()
public boolean selectDrawable(int index)
If an invalid index is specified, the current drawable will be set to
null
and the index will be set to -1
.
index
- the index of the drawable to displaytrue
if the drawable changed, false
otherwisepublic Drawable getCurrent()
getCurrent
in class Drawable
StateListDrawable
and LevelListDrawable
this will be the child drawable
currently in use.protected final void updateDensity(Resources res)
res
- the resources used to inflate density-dependent valuespublic void applyTheme(Resources.Theme theme)
Drawable
applyTheme
in class Drawable
theme
- the theme to applypublic boolean canApplyTheme()
canApplyTheme
in class Drawable
public Drawable.ConstantState getConstantState()
Drawable
Drawable.ConstantState
instance that holds the shared state of this Drawable.getConstantState
in class Drawable
Drawable.ConstantState
,
Drawable.mutate()
public Drawable mutate()
Drawable
mutate
in class Drawable
Drawable.ConstantState
,
Drawable.getConstantState()
public void clearMutated()
Drawable
This is hidden because only framework drawables can be cached, so custom drawables don't need to support constant state, mutate(), or clearMutated().
clearMutated
in class Drawable
protected void setConstantState(DrawableContainer.DrawableContainerState state)