public class DrawableWrapper extends Drawable implements Drawable.Callback
Drawable.Callback, Drawable.ConstantState
Constructor and Description |
---|
DrawableWrapper(Drawable drawable) |
Modifier and Type | Method and Description |
---|---|
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 |
getChangingConfigurations()
Return a mask of the configuration parameters for which this drawable
may change, requiring that it be re-created.
|
Drawable |
getCurrent() |
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.
|
boolean |
getPadding(Rect padding)
Return in padding the insets suggested by this Drawable for placing
content inside the drawable's bounds.
|
int[] |
getState()
Describes the current state, as a union of primitve states, such as
android.R.attr#state_focused ,
android.R.attr#state_selected , etc. |
Region |
getTransparentRegion()
Returns a Region representing the part of the Drawable that is completely
transparent.
|
Drawable |
getWrappedDrawable() |
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.
|
protected void |
onBoundsChange(Rect bounds)
Override this in your subclass to change appearance if you vary based on
the bounds.
|
protected boolean |
onLevelChange(int level)
Override this in your subclass to change appearance if you vary based
on level.
|
void |
scheduleDrawable(Drawable who,
Runnable what,
long when)
A Drawable can call this to schedule the next frame of its
animation.
|
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 |
setChangingConfigurations(int configs)
Set a mask of the configuration parameters for which this drawable
may change, requiring that it be re-created.
|
void |
setColorFilter(ColorFilter cf)
Specify an optional color filter for the drawable.
|
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 |
setFilterBitmap(boolean filter)
Set to true to have the drawable filter its bitmaps with bilinear
sampling when they are scaled or rotated.
|
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.
|
boolean |
setState(int[] stateSet)
Specify a set of states for the drawable.
|
void |
setTint(int tint)
Specifies tint color for this drawable.
|
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 |
setWrappedDrawable(Drawable drawable) |
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) . |
applyTheme, canApplyTheme, clearColorFilter, clearMutated, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXml, createFromXmlInner, createFromXmlInner, getAlpha, getBounds, getCallback, getColorFilter, getConstantState, getDirtyBounds, getHotspotBounds, getLayoutDirection, getLevel, getOpticalInsets, getOutline, inflate, inflate, invalidateSelf, isFilterBitmap, isProjected, isVisible, mutate, obtainAttributes, onLayoutDirectionChanged, onStateChange, parseTintMode, resolveOpacity, scheduleSelf, setBounds, setBounds, setCallback, setColorFilter, setLayoutDirection, setLevel, setXfermode, unscheduleSelf
public DrawableWrapper(Drawable drawable)
public void draw(Canvas canvas)
Drawable
protected void onBoundsChange(Rect bounds)
Drawable
onBoundsChange
in class Drawable
public void setChangingConfigurations(int configs)
Drawable
setChangingConfigurations
in class Drawable
configs
- A mask of the changing configuration parameters, as
defined by ActivityInfo
.ActivityInfo
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 void setDither(boolean dither)
Drawable
setDither
in class Drawable
Paint.setDither(boolean);
public void setFilterBitmap(boolean filter)
Drawable
This can improve appearance when bitmaps are rotated. If the drawable does not use bitmaps, this call is ignored.
setFilterBitmap
in class Drawable
Drawable.isFilterBitmap()
,
Paint.setFilterBitmap(boolean);
public void setAlpha(int alpha)
Drawable
public void setColorFilter(ColorFilter cf)
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
cf
- The color filter to apply, or null
to remove the
existing color filterpublic boolean isStateful()
Drawable
isStateful
in class Drawable
Drawable.setState(int[])
public boolean setState(int[] stateSet)
Drawable
android.R.attr#state_focused
,
android.R.attr#state_pressed
].
If the new state you are supplying causes the appearance of the
Drawable to change, then it is responsible for calling
Drawable.invalidateSelf()
in order to have itself redrawn, and
true will be returned from this function.
Note: The Drawable holds a reference on to stateSet until a new state array is given to it, so you must not modify this array during that time.
public int[] getState()
Drawable
android.R.attr#state_focused
,
android.R.attr#state_selected
, etc.
Some drawables may modify their imagery based on the selected state.public void jumpToCurrentState()
Drawable
jumpToCurrentState
in class Drawable
public Drawable getCurrent()
getCurrent
in class Drawable
StateListDrawable
and LevelListDrawable
this will be the child drawable
currently in use.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 Region getTransparentRegion()
Drawable
getTransparentRegion
in class Drawable
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 boolean getPadding(Rect padding)
Drawable
getPadding
in class Drawable
public void invalidateDrawable(Drawable who)
invalidateDrawable
in interface Drawable.Callback
who
- The drawable that is requesting the update.public void scheduleDrawable(Drawable who, Runnable what, long when)
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.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.protected boolean onLevelChange(int level)
Drawable
onLevelChange
in class Drawable
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 setTint(int 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)
.
To clear the tint, pass null
to
Drawable.setTintList(ColorStateList)
.
Note: Setting a color filter via
Drawable.setColorFilter(ColorFilter)
or
Drawable.setColorFilter(int, PorterDuff.Mode)
overrides tint.
setTint
in class Drawable
tint
- Color to use for tinting this drawableDrawable.setTintList(ColorStateList)
,
Drawable.setTintMode(PorterDuff.Mode)
public 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 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 Drawable getWrappedDrawable()
public void setWrappedDrawable(Drawable drawable)