|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.graphics.drawable.Drawable
public abstract class Drawable
A Drawable is a general abstraction for "something that can be drawn." Most
often you will deal with Drawable as the type of resource retrieved for
drawing things to the screen; the Drawable class provides a generic API for
dealing with an underlying visual resource that may take a variety of forms.
Unlike a View, a Drawable does not have any facility to
receive events or otherwise interact with the user.
In addition to simple drawing, Drawable provides a number of generic mechanisms for its client to interact with what is being drawn:
setBounds(int, int, int, int) method must be called to tell the
Drawable where it is drawn and how large it should be. All Drawables
should respect the requested size, often simply by scaling their
imagery. A client can find the preferred size for some Drawables with
the getIntrinsicHeight() and getIntrinsicWidth() methods.
getPadding(android.graphics.Rect) method can return from some Drawables
information about how to frame content that is placed inside of them.
For example, a Drawable that is intended to be the frame for a button
widget would need to return padding that correctly places the label
inside of itself.
setState(int[]) method allows the client to tell the Drawable
in which state it is to be drawn, such as "focused", "selected", etc.
Some drawables may modify their imagery based on the selected state.
setLevel(int) method allows the client to supply a single
continuous controller that can modify the Drawable is displayed, such as
a battery level or progress level. Some drawables may modify their
imagery based on the current level.
Drawable.Callback interface. All clients should support this
interface (via setCallback(android.graphics.drawable.Drawable.Callback)) so that animations will work. A
simple way to do this is through the system facilities such as
View.setBackgroundDrawable(Drawable) and
ImageView.
For information and examples of creating drawable resources (XML or bitmap files that can be loaded in code), see Resources and Internationalization.
| Nested Class Summary | |
|---|---|
static interface |
Drawable.Callback
Implement this interface if you want to create an animated drawable that extends Drawable. |
static class |
Drawable.ConstantState
|
| Field Summary | |
|---|---|
(package private) Drawable.Callback |
mCallback
|
| Constructor Summary | |
|---|---|
Drawable()
|
|
| Method Summary | |
|---|---|
void |
clearColorFilter()
|
Rect |
copyBounds()
Return a copy of the drawable's bounds in a new Rect. |
void |
copyBounds(Rect bounds)
Return a copy of the drawable's bounds in the specified Rect (allocated by the caller). |
static Drawable |
createFromPath(String pathName)
Create a drawable from file path name. |
static Drawable |
createFromStream(InputStream is,
String srcName)
Create a drawable from an inputstream |
static Drawable |
createFromXml(Resources r,
XmlPullParser parser)
Create a drawable from an XML document. |
static Drawable |
createFromXmlInner(Resources r,
XmlPullParser parser,
AttributeSet attrs)
Create from inside an XML document. |
abstract 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). |
Rect |
getBounds()
Return the drawable's bounds Rect. |
int |
getChangingConfigurations()
Return a mask of the configuration parameters for which this drawable mau change, requiring that it be re-created. |
Drawable.ConstantState |
getConstantState()
|
Drawable |
getCurrent()
|
int |
getIntrinsicHeight()
Return the intrinsic height of the underlying drawable object. |
int |
getIntrinsicWidth()
Return the intrinsic width of the underlying drawable object. |
int |
getLevel()
Retrieve the current level. |
int |
getMinimumHeight()
Returns the minimum height suggested by this Drawable. |
int |
getMinimumWidth()
Returns the minimum width suggested by this Drawable. |
abstract 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 R.attr.state_focused,
R.attr.state_selected, etc. |
Region |
getTransparentRegion()
Returns a Region representing the part of the Drawable that is completely transparent. |
void |
inflate(Resources r,
XmlPullParser parser,
AttributeSet attrs)
|
(package private) void |
inflateWithAttributes(Resources r,
XmlPullParser parser,
TypedArray attrs,
int visibleAttr)
|
void |
invalidateSelf()
Use the current Drawable.Callback implementation to have this Drawable
redrawn. |
boolean |
isStateful()
Indicates whether this view will change its appearance based on state. |
boolean |
isVisible()
|
protected void |
onBoundsChange(Rect bounds)
Override this in your subclass to change appearance if you recognize the specified state. |
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. |
static int |
resolveOpacity(int op1,
int op2)
Return the appropriate opacity value for two source opacities. |
void |
scheduleSelf(Runnable what,
long when)
Use the current Drawable.Callback implementation to have this Drawable
scheduled. |
abstract void |
setAlpha(int alpha)
Specify an alpha value for the drawable. |
void |
setBounds(int left,
int top,
int right,
int bottom)
Specify a bounding rectangle for the Drawable. |
void |
setBounds(Rect bounds)
Specify a bounding rectangle for the Drawable. |
void |
setCallback(Drawable.Callback cb)
Bind a Drawable.Callback object to this Drawable. |
void |
setChangingConfigurations(int configs)
Set a mask of the configuration parameters for which this drawable may change, requiring that it be re-created. |
abstract void |
setColorFilter(ColorFilter cf)
Specify an optional colorFilter for the drawable. |
void |
setColorFilter(int color,
PorterDuff.Mode mode)
Specify a color and porterduff mode to be the colorfilter for this 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 bitmap when scaled or rotated (for drawables that use bitmaps). |
boolean |
setLevel(int level)
Specify the level for the drawable. |
boolean |
setState(int[] stateSet)
Specify a set of states for the drawable. |
boolean |
setVisible(boolean visible,
boolean restart)
Set whether this Drawable is visible. |
void |
unscheduleSelf(Runnable what)
Use the current Drawable.Callback implementation to have this Drawable
unscheduled. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
Drawable.Callback mCallback
| Constructor Detail |
|---|
public Drawable()
| Method Detail |
|---|
public abstract void draw(Canvas canvas)
canvas - The canvas to draw into
public void setBounds(int left,
int top,
int right,
int bottom)
public void setBounds(Rect bounds)
public final void copyBounds(Rect bounds)
bounds - Rect to receive the drawable's bounds (allocated by the
caller).public final Rect copyBounds()
public final Rect getBounds()
public void setChangingConfigurations(int configs)
configs - A mask of the changing configuration parameters, as
defined by Configuration.Configurationpublic int getChangingConfigurations()
setChangingConfigurations(int) or 0 by default. Subclasses
may extend this to or in the changing configurations of any other
drawables they hold.
Configuration.Configurationpublic void setDither(boolean dither)
public void setFilterBitmap(boolean filter)
public final void setCallback(Drawable.Callback cb)
Drawable.Callback object to this Drawable. Required for clients
that want to support animated drawables.
cb - The client's Callback implementation.public void invalidateSelf()
Drawable.Callback implementation to have this Drawable
redrawn. Does nothing if there is no Callback attached to the
Drawable.
Drawable.Callback.invalidateDrawable(android.graphics.drawable.Drawable)
public void scheduleSelf(Runnable what,
long when)
Drawable.Callback implementation to have this Drawable
scheduled. Does nothing if there is no Callback attached to the
Drawable.
what - The action being scheduled.when - The time (in milliseconds) to run.Drawable.Callback.scheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable, long)public void unscheduleSelf(Runnable what)
Drawable.Callback implementation to have this Drawable
unscheduled. Does nothing if there is no Callback attached to the
Drawable.
what - The runnable that you no longer want called.Drawable.Callback.unscheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable)public abstract void setAlpha(int alpha)
public abstract void setColorFilter(ColorFilter cf)
public void setColorFilter(int color,
PorterDuff.Mode mode)
public void clearColorFilter()
public boolean isStateful()
setState(int[])public boolean setState(int[] stateSet)
R.attr.state_focused,
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
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.
stateSet - The new set of states to be displayed.
public int[] getState()
R.attr.state_focused,
R.attr.state_selected, etc.
Some drawables may modify their imagery based on the selected state.
public Drawable getCurrent()
StateListDrawable and LevelListDrawable this will be the child drawable
currently in use.public final boolean setLevel(int level)
If the new level you are supplying causes the appearance of the
Drawable to change, then it is responsible for calling
invalidateSelf() in order to have itself redrawn, and
true will be returned from this function.
level - The new level, from 0 (minimum) to 10000 (maximum).
public final int getLevel()
public boolean setVisible(boolean visible,
boolean restart)
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 final boolean isVisible()
public abstract int getOpacity()
PixelFormat:
PixelFormat.UNKNOWN,
PixelFormat.TRANSLUCENT,
PixelFormat.TRANSPARENT, or
PixelFormat.OPAQUE.
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 resolveOpacity(int, int) to perform a
standard reduction of two opacities to the appropriate single output.
Note that the returned value does not take into account a
custom alpha or color filter that has been applied by the client through
the setAlpha(int) or setColorFilter(android.graphics.ColorFilter) methods.
PixelFormat
public static int resolveOpacity(int op1,
int op2)
This is to help in implementing getOpacity().
op1 - One opacity value.op2 - Another opacity value.
getOpacity()public Region getTransparentRegion()
protected boolean onStateChange(int[] state)
protected boolean onLevelChange(int level)
protected void onBoundsChange(Rect bounds)
public int getIntrinsicWidth()
public int getIntrinsicHeight()
public int getMinimumWidth()
public int getMinimumHeight()
public boolean getPadding(Rect padding)
public static Drawable createFromStream(InputStream is,
String srcName)
public static Drawable createFromXml(Resources r,
XmlPullParser parser)
throws XmlPullParserException,
IOException
XmlPullParserException
IOException
public static Drawable createFromXmlInner(Resources r,
XmlPullParser parser,
AttributeSet attrs)
throws XmlPullParserException,
IOException
XmlPullParserException
IOExceptionpublic static Drawable createFromPath(String pathName)
public void inflate(Resources r,
XmlPullParser parser,
AttributeSet attrs)
throws XmlPullParserException,
IOException
XmlPullParserException
IOException
void inflateWithAttributes(Resources r,
XmlPullParser parser,
TypedArray attrs,
int visibleAttr)
throws XmlPullParserException,
IOException
XmlPullParserException
IOExceptionpublic Drawable.ConstantState getConstantState()
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||