Methods Summary |
---|
public void | draw(android.graphics.Canvas canvas)
Bitmap bitmap = mBitmap;
if (bitmap != null) {
final BitmapState state = mBitmapState;
if (mRebuildShader) {
Shader.TileMode tmx = state.mTileModeX;
Shader.TileMode tmy = state.mTileModeY;
if (tmx == null && tmy == null) {
state.mPaint.setShader(null);
} else {
Shader s = new BitmapShader(bitmap,
tmx == null ? Shader.TileMode.CLAMP : tmx,
tmy == null ? Shader.TileMode.CLAMP : tmy);
state.mPaint.setShader(s);
}
mRebuildShader = false;
copyBounds(mDstRect);
}
Shader shader = state.mPaint.getShader();
if (shader == null) {
if (mApplyGravity) {
Gravity.apply(state.mGravity, mBitmapWidth, mBitmapHeight,
getBounds(), mDstRect);
mApplyGravity = false;
}
canvas.drawBitmap(bitmap, null, mDstRect, state.mPaint);
} else {
if (mApplyGravity) {
mDstRect.set(getBounds());
mApplyGravity = false;
}
canvas.drawRect(mDstRect, state.mPaint);
}
}
|
public final android.graphics.Bitmap | getBitmap()
return mBitmap;
|
public int | getChangingConfigurations()
return super.getChangingConfigurations() | mBitmapState.mChangingConfigurations;
|
public final ConstantState | getConstantState()
mBitmapState.mChangingConfigurations = super.getChangingConfigurations();
return mBitmapState;
|
public int | getGravity()Get the gravity used to position/stretch the bitmap within its bounds.
See android.view.Gravity
return mBitmapState.mGravity;
|
public int | getIntrinsicHeight()
final Bitmap bitmap = mBitmap;
final BitmapState state = mBitmapState;
if (!state.mAutoScale || state.mBitmapScale == Bitmap.DENSITY_SCALE_UNKNOWN) {
return mBitmapHeight;
} else {
return bitmap != null ? (int) (mBitmapHeight /
(state.mBitmapScale / state.mTargetDensityScale) + 0.5f) : -1;
}
|
public int | getIntrinsicWidth()
final Bitmap bitmap = mBitmap;
final BitmapState state = mBitmapState;
if (!state.mAutoScale || state.mBitmapScale == Bitmap.DENSITY_SCALE_UNKNOWN) {
return mBitmapWidth;
} else {
return bitmap != null ? (int) (mBitmapWidth /
(state.mBitmapScale / state.mTargetDensityScale) + 0.5f) : -1;
}
|
public int | getOpacity()
if (mBitmapState.mGravity != Gravity.FILL) {
return PixelFormat.TRANSLUCENT;
}
Bitmap bm = mBitmap;
return (bm == null || bm.hasAlpha() || mBitmapState.mPaint.getAlpha() < 255) ?
PixelFormat.TRANSLUCENT : PixelFormat.OPAQUE;
|
public final android.graphics.Paint | getPaint()
return mBitmapState.mPaint;
|
public Shader.TileMode | getTileModeX()
return mBitmapState.mTileModeX;
|
public Shader.TileMode | getTileModeY()
return mBitmapState.mTileModeY;
|
public void | inflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs)
super.inflate(r, parser, attrs);
TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.BitmapDrawable);
final int id = a.getResourceId(com.android.internal.R.styleable.BitmapDrawable_src, 0);
if (id == 0) {
throw new XmlPullParserException(parser.getPositionDescription() +
": <bitmap> requires a valid src attribute");
}
final Bitmap bitmap = BitmapFactory.decodeResource(r, id);
if (bitmap == null) {
throw new XmlPullParserException(parser.getPositionDescription() +
": <bitmap> requires a valid src attribute");
}
mBitmapState.mBitmap = bitmap;
setBitmap(bitmap);
setDensityScale(r.getDisplayMetrics());
final Paint paint = mBitmapState.mPaint;
paint.setAntiAlias(a.getBoolean(com.android.internal.R.styleable.BitmapDrawable_antialias,
paint.isAntiAlias()));
paint.setFilterBitmap(a.getBoolean(com.android.internal.R.styleable.BitmapDrawable_filter,
paint.isFilterBitmap()));
paint.setDither(a.getBoolean(com.android.internal.R.styleable.BitmapDrawable_dither,
paint.isDither()));
setGravity(a.getInt(com.android.internal.R.styleable.BitmapDrawable_gravity, Gravity.FILL));
int tileMode = a.getInt(com.android.internal.R.styleable.BitmapDrawable_tileMode, -1);
if (tileMode != -1) {
switch (tileMode) {
case 0:
setTileModeXY(Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
break;
case 1:
setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
break;
case 2:
setTileModeXY(Shader.TileMode.MIRROR, Shader.TileMode.MIRROR);
break;
}
}
a.recycle();
|
public Drawable | mutate()A mutable BitmapDrawable still shares its Bitmap with any other Drawable
that comes from the same resource.
if (!mMutated && super.mutate() == this) {
mBitmapState = new BitmapState(mBitmapState);
mMutated = true;
}
return this;
|
protected void | onBoundsChange(android.graphics.Rect bounds)
super.onBoundsChange(bounds);
mApplyGravity = true;
|
public void | setAlpha(int alpha)
mBitmapState.mPaint.setAlpha(alpha);
|
public void | setAntiAlias(boolean aa)
mBitmapState.mPaint.setAntiAlias(aa);
|
private void | setBitmap(android.graphics.Bitmap bitmap)
mBitmap = bitmap;
if (bitmap != null) {
mBitmapWidth = bitmap.getWidth();
mBitmapHeight = bitmap.getHeight();
} else {
mBitmapWidth = mBitmapHeight = -1;
}
|
public void | setColorFilter(android.graphics.ColorFilter cf)
mBitmapState.mPaint.setColorFilter(cf);
|
public void | setDensityScale(float density)Set the density scale at which this drawable will be rendered.
density = (density == Bitmap.DENSITY_SCALE_UNKNOWN ? 1.0f : density);
mBitmapState.mTargetDensityScale = density;
|
public void | setDensityScale(android.graphics.Canvas canvas)Set the density scale at which this drawable will be rendered. This
method assumes the drawable will be rendered at the same density as the
specified canvas.
setDensityScale(canvas.getDensityScale());
|
public void | setDensityScale(android.util.DisplayMetrics metrics)Set the density scale at which this drawable will be rendered.
setDensityScale(metrics.density);
|
public void | setDither(boolean dither)
mBitmapState.mPaint.setDither(dither);
|
public void | setFilterBitmap(boolean filter)
mBitmapState.mPaint.setFilterBitmap(filter);
|
public void | setGravity(int gravity)Set the gravity used to position/stretch the bitmap within its bounds.
See android.view.Gravity
mBitmapState.mGravity = gravity;
mApplyGravity = true;
|
public void | setTileModeX(Shader.TileMode mode)
setTileModeXY(mode, mBitmapState.mTileModeY);
|
public void | setTileModeXY(Shader.TileMode xmode, Shader.TileMode ymode)
final BitmapState state = mBitmapState;
if (state.mTileModeX != xmode || state.mTileModeY != ymode) {
state.mTileModeX = xmode;
state.mTileModeY = ymode;
mRebuildShader = true;
}
|
public final void | setTileModeY(Shader.TileMode mode)
setTileModeXY(mBitmapState.mTileModeX, mode);
|