Methods Summary |
---|
public void | clearColorFilter()
setColorFilter(null);
|
public final void | copyBounds(Rect bounds)Return a copy of the drawable's bounds in the specified Rect (allocated
by the caller). The bounds specify where this will draw when its draw()
method is called.
bounds.set(mBounds);
|
public final Rect | copyBounds()Return a copy of the drawable's bounds in a new Rect. This returns the
same values as getBounds(), but the returned object is guaranteed to not
be changed later by the drawable (i.e. it retains no reference to this
rect). If the caller already has a Rect allocated, call copyBounds(rect)
return new Rect(mBounds);
|
public static android.graphics.drawable.Drawable | createFromPath(java.lang.String pathName)Create a drawable from file path name.
if (pathName == null) {
return null;
}
Bitmap bm = BitmapFactory.decodeFile(pathName);
if (bm != null) {
return drawableFromBitmap(null, bm, null, null, pathName);
}
return null;
|
public static android.graphics.drawable.Drawable | createFromResourceStream(android.content.res.Resources res, android.util.TypedValue value, java.io.InputStream is, java.lang.String srcName)Create a drawable from an inputstream
if (is == null) {
return null;
}
/* ugh. The decodeStream contract is that we have already allocated
the pad rect, but if the bitmap does not had a ninepatch chunk,
then the pad will be ignored. If we could change this to lazily
alloc/assign the rect, we could avoid the GC churn of making new
Rects only to drop them on the floor.
*/
Rect pad = new Rect();
Bitmap bm = BitmapFactory.decodeStream(res, value, is, pad, null);
if (bm != null) {
byte[] np = bm.getNinePatchChunk();
if (np == null || !NinePatch.isNinePatchChunk(np)) {
np = null;
pad = null;
}
return drawableFromBitmap(res, bm, np, pad, srcName);
}
return null;
|
public static android.graphics.drawable.Drawable | createFromStream(java.io.InputStream is, java.lang.String srcName)Create a drawable from an inputstream
return createFromResourceStream(null, null, is, srcName);
|
public static android.graphics.drawable.Drawable | createFromXml(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser)Create a drawable from an XML document. For more information on how to
create resources in XML, see
Resources and
Internationalization.
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type=parser.next()) != XmlPullParser.START_TAG &&
type != XmlPullParser.END_DOCUMENT) {
// Empty loop
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException("No start tag found");
}
Drawable drawable = createFromXmlInner(r, parser, attrs);
if (drawable == null) {
throw new RuntimeException("Unknown initial tag: " + parser.getName());
}
return drawable;
|
public static android.graphics.drawable.Drawable | createFromXmlInner(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs)Create from inside an XML document. Called on a parser positioned at
a tag in an XML document, tries to create a Drawable from that tag.
Returns null if the tag is not a valid drawable.
Drawable drawable;
final String name = parser.getName();
if (name.equals("selector")) {
drawable = new StateListDrawable();
} else if (name.equals("level-list")) {
drawable = new LevelListDrawable();
} else if (name.equals("layer-list")) {
drawable = new LayerDrawable();
} else if (name.equals("transition")) {
drawable = new TransitionDrawable();
} else if (name.equals("color")) {
drawable = new ColorDrawable();
} else if (name.equals("shape")) {
drawable = new GradientDrawable();
} else if (name.equals("scale")) {
drawable = new ScaleDrawable();
} else if (name.equals("clip")) {
drawable = new ClipDrawable();
} else if (name.equals("rotate")) {
drawable = new RotateDrawable();
} else if (name.equals("animation-list")) {
drawable = new AnimationDrawable();
} else if (name.equals("inset")) {
drawable = new InsetDrawable();
} else if (name.equals("bitmap")) {
drawable = new BitmapDrawable();
if (r != null) {
((BitmapDrawable) drawable).setDensityScale(r.getDisplayMetrics());
}
} else if (name.equals("nine-patch")) {
drawable = new NinePatchDrawable();
} else {
throw new XmlPullParserException(parser.getPositionDescription() +
": invalid drawable tag " + name);
}
drawable.inflate(r, parser, attrs);
return drawable;
|
public 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).
|
private static android.graphics.drawable.Drawable | drawableFromBitmap(android.content.res.Resources res, Bitmap bm, byte[] np, Rect pad, java.lang.String srcName)
if (np != null) {
return new NinePatchDrawable(bm, np, pad, srcName);
}
final BitmapDrawable drawable = new BitmapDrawable(bm);
if (res != null) {
drawable.setDensityScale(res.getDisplayMetrics());
}
return drawable;
|
public final Rect | getBounds()Return the drawable's bounds Rect. Note: for efficiency, the returned
object may be the same object stored in the drawable (though this is not
guaranteed), so if a persistent copy of the bounds is needed, call
copyBounds(rect) instead.
return mBounds;
|
public int | getChangingConfigurations()Return a mask of the configuration parameters for which this drawable
mau change, requiring that it be re-created. The default implementation
returns whatever was provided through
{@link #setChangingConfigurations(int)} or 0 by default. Subclasses
may extend this to or in the changing configurations of any other
drawables they hold.
return mChangingConfigurations;
|
public android.graphics.drawable.Drawable$ConstantState | getConstantState()
return null;
|
public android.graphics.drawable.Drawable | getCurrent()
return this;
|
public int | getIntrinsicHeight()Return the intrinsic height of the underlying drawable object. Returns
-1 if it has no intrinsic height, such as with a solid color.
return -1;
|
public int | getIntrinsicWidth()Return the intrinsic width of the underlying drawable object. Returns
-1 if it has no intrinsic width, such as with a solid color.
return -1;
|
public final int | getLevel()Retrieve the current level.
return mLevel;
|
public int | getMinimumHeight()Returns the minimum height suggested by this Drawable. If a View uses this
Drawable as a background, it is suggested that the View use at least this
value for its height. (There will be some scenarios where this will not be
possible.) This value should INCLUDE any padding.
final int intrinsicHeight = getIntrinsicHeight();
return intrinsicHeight > 0 ? intrinsicHeight : 0;
|
public int | getMinimumWidth()Returns the minimum width suggested by this Drawable. If a View uses this
Drawable as a background, it is suggested that the View use at least this
value for its width. (There will be some scenarios where this will not be
possible.) This value should INCLUDE any padding.
final int intrinsicWidth = getIntrinsicWidth();
return intrinsicWidth > 0 ? intrinsicWidth : 0;
|
public abstract int | getOpacity()Return the opacity/transparency of this Drawable. The returned value is
one of the abstract format constants in
{@link android.graphics.PixelFormat}:
{@link android.graphics.PixelFormat#UNKNOWN},
{@link android.graphics.PixelFormat#TRANSLUCENT},
{@link android.graphics.PixelFormat#TRANSPARENT}, or
{@link android.graphics.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 {@link #resolveOpacity} 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 {@link #setAlpha} or {@link #setColorFilter} methods.
|
public boolean | getPadding(Rect padding)Return 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 (set Rect.inset). Returns true if this drawable
actually has a padding, else false. When false is returned, the padding
is always set to 0.
padding.set(0, 0, 0, 0);
return false;
|
public int[] | getState()Describes the current state, as a union of primitve states, such as
{@link android.R.attr#state_focused},
{@link android.R.attr#state_selected}, etc.
Some drawables may modify their imagery based on the selected state.
return mStateSet;
|
public Region | getTransparentRegion()Returns a Region representing the part of the Drawable that is completely
transparent. This can be used to perform drawing operations, identifying
which parts of the target will not change when rendering the Drawable.
The default implementation returns null, indicating no transparent
region; subclasses can optionally override this to return an actual
Region if they want to supply this optimization information, but it is
not required that they do so.
return null;
|
public void | inflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs)
TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.Drawable);
inflateWithAttributes(r, parser, a, com.android.internal.R.styleable.Drawable_visible);
a.recycle();
|
void | inflateWithAttributes(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.content.res.TypedArray attrs, int visibleAttr)
mVisible = attrs.getBoolean(visibleAttr, mVisible);
|
public void | invalidateSelf()Use the current {@link Callback} implementation to have this Drawable
redrawn. Does nothing if there is no Callback attached to the
Drawable.
if (mCallback != null) {
mCallback.invalidateDrawable(this);
}
|
public boolean | isStateful()Indicates whether this view will change its appearance based on state.
Clients can use this to determine whether it is necessary to calculate
their state and call setState.
return false;
|
public final boolean | isVisible()
return mVisible;
|
public android.graphics.drawable.Drawable | mutate()Make 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.
return this;
|
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. return false;
|
protected boolean | onStateChange(int[] state)Override this in your subclass to change appearance if you recognize the
specified state. return false;
|
public static int | resolveOpacity(int op1, int op2)Return the appropriate opacity value for two source opacities. If
either is UNKNOWN, that is returned; else, if either is TRANSLUCENT,
that is returned; else, if either is TRANSPARENT, that is returned;
else, OPAQUE is returned.
This is to help in implementing {@link #getOpacity}.
if (op1 == op2) {
return op1;
}
if (op1 == PixelFormat.UNKNOWN || op2 == PixelFormat.UNKNOWN) {
return PixelFormat.UNKNOWN;
}
if (op1 == PixelFormat.TRANSLUCENT || op2 == PixelFormat.TRANSLUCENT) {
return PixelFormat.TRANSLUCENT;
}
if (op1 == PixelFormat.TRANSPARENT || op2 == PixelFormat.TRANSPARENT) {
return PixelFormat.TRANSPARENT;
}
return PixelFormat.OPAQUE;
|
public void | scheduleSelf(java.lang.Runnable what, long when)Use the current {@link Callback} implementation to have this Drawable
scheduled. Does nothing if there is no Callback attached to the
Drawable.
if (mCallback != null) {
mCallback.scheduleDrawable(this, what, when);
}
|
public abstract void | setAlpha(int alpha)Specify an alpha value for the drawable. 0 means fully transparent, and
255 means fully opaque.
|
public void | setBounds(int left, int top, int right, int bottom)Specify a bounding rectangle for the Drawable. This is where the drawable
will draw when its draw() method is called.
Rect oldBounds = mBounds;
if (oldBounds.left != left || oldBounds.top != top ||
oldBounds.right != right || oldBounds.bottom != bottom) {
mBounds.set(left, top, right, bottom);
onBoundsChange(mBounds);
}
|
public void | setBounds(Rect bounds)Specify a bounding rectangle for the Drawable. This is where the drawable
will draw when its draw() method is called.
setBounds(bounds.left, bounds.top, bounds.right, bounds.bottom);
|
public final void | setCallback(android.graphics.drawable.Drawable$Callback cb)Bind a {@link Callback} object to this Drawable. Required for clients
that want to support animated drawables.
mCallback = cb;
|
public void | setChangingConfigurations(int configs)Set a mask of the configuration parameters for which this drawable
may change, requiring that it be re-created.
mChangingConfigurations = configs;
|
public abstract void | setColorFilter(ColorFilter cf)Specify an optional colorFilter for the drawable. Pass null to remove
any filters.
|
public void | setColorFilter(int color, PorterDuff.Mode mode)Specify a color and porterduff mode to be the colorfilter for this
drawable.
setColorFilter(new PorterDuffColorFilter(color, mode));
|
public 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. This can improve the look on
those devices, but can also slow down the drawing a little.
|
public void | setFilterBitmap(boolean filter)Set to true to have the drawable filter its bitmap when scaled or rotated
(for drawables that use bitmaps). If the drawable does not use bitmaps,
this call is ignored. This can improve the look when scaled or rotated,
but also slows down the drawing.
|
public final boolean | setLevel(int level)Specify the level for the drawable. This allows a drawable to vary its
imagery based on a continuous controller, for example to show progress
or volume level.
If the new level you are supplying causes the appearance of the
Drawable to change, then it is responsible for calling
{@link #invalidateSelf} in order to have itself redrawn, and
true will be returned from this function.
if (mLevel != level) {
mLevel = level;
return onLevelChange(level);
}
return false;
|
public boolean | setState(int[] stateSet)Specify a set of states for the drawable. These are use-case specific,
so see the relevant documentation. As an example, the background for
widgets like Button understand the following states:
[{@link android.R.attr#state_focused},
{@link 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
{@link #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.
if (!Arrays.equals(mStateSet, stateSet)) {
mStateSet = stateSet;
return onStateChange(stateSet);
}
return false;
|
public boolean | setVisible(boolean visible, boolean restart)Set 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.
boolean changed = mVisible != visible;
mVisible = visible;
return changed;
|
public void | unscheduleSelf(java.lang.Runnable what)Use the current {@link Callback} implementation to have this Drawable
unscheduled. Does nothing if there is no Callback attached to the
Drawable.
if (mCallback != null) {
mCallback.unscheduleDrawable(this, what);
}
|