Methods Summary |
---|
private void | computeBitmapSize()
mBitmapWidth = mBitmap.getScaledWidth(mTargetDensity);
mBitmapHeight = mBitmap.getScaledHeight(mTargetDensity);
|
public void | draw(android.graphics.Canvas canvas)
final Bitmap bitmap = mBitmap;
if (bitmap == null) {
return;
}
updateDstRect();
final Paint paint = mPaint;
final Shader shader = paint.getShader();
if (shader == null) {
canvas.drawBitmap(bitmap, null, mDstRect, paint);
} else {
canvas.drawRoundRect(mDstRectF, mCornerRadius, mCornerRadius, paint);
}
|
public int | getAlpha()
return mPaint.getAlpha();
|
public final android.graphics.Bitmap | getBitmap()Returns the bitmap used by this drawable to render. May be null.
return mBitmap;
|
public android.graphics.ColorFilter | getColorFilter()
return mPaint.getColorFilter();
|
public float | getCornerRadius()
return mCornerRadius;
|
public int | getGravity()Get the gravity used to position/stretch the bitmap within its bounds.
return mGravity;
|
public int | getIntrinsicHeight()
return mBitmapHeight;
|
public int | getIntrinsicWidth()
return mBitmapWidth;
|
public int | getOpacity()
if (mGravity != Gravity.FILL) {
return PixelFormat.TRANSLUCENT;
}
Bitmap bm = mBitmap;
return (bm == null
|| bm.hasAlpha()
|| mPaint.getAlpha() < 255
|| isGreaterThanZero(mCornerRadius))
? PixelFormat.TRANSLUCENT : PixelFormat.OPAQUE;
|
public final android.graphics.Paint | getPaint()Returns the paint used to render this drawable.
return mPaint;
|
void | gravityCompatApply(int gravity, int bitmapWidth, int bitmapHeight, android.graphics.Rect bounds, android.graphics.Rect outRect)
throw new UnsupportedOperationException();
|
public boolean | hasAntiAlias()Indicates whether anti-aliasing is enabled for this drawable.
return mPaint.isAntiAlias();
|
public boolean | hasMipMap()Indicates whether the mipmap hint is enabled on this drawable's bitmap.
throw new UnsupportedOperationException(); // must be overridden in subclasses
|
private static boolean | isGreaterThanZero(float toCompare)
return Float.compare(toCompare, +0.0f) > 0;
|
public void | setAlpha(int alpha)
final int oldAlpha = mPaint.getAlpha();
if (alpha != oldAlpha) {
mPaint.setAlpha(alpha);
invalidateSelf();
}
|
public void | setAntiAlias(boolean aa)Enables or disables anti-aliasing for this drawable. Anti-aliasing affects
the edges of the bitmap only so it applies only when the drawable is rotated.
mPaint.setAntiAlias(aa);
invalidateSelf();
|
public void | setColorFilter(android.graphics.ColorFilter cf)
mPaint.setColorFilter(cf);
invalidateSelf();
|
public void | setCornerRadius(float cornerRadius)Sets the corner radius to be applied when drawing the bitmap.
if (isGreaterThanZero(cornerRadius)) {
mPaint.setShader(mBitmapShader);
} else {
mPaint.setShader(null);
}
mCornerRadius = cornerRadius;
|
public void | setDither(boolean dither)
mPaint.setDither(dither);
invalidateSelf();
|
public void | setFilterBitmap(boolean filter)
mPaint.setFilterBitmap(filter);
invalidateSelf();
|
public void | setGravity(int gravity)Set the gravity used to position/stretch the bitmap within its bounds.
if (mGravity != gravity) {
mGravity = gravity;
mApplyGravity = true;
invalidateSelf();
}
|
public void | setMipMap(boolean mipMap)Enables or disables the mipmap hint for this drawable's bitmap.
See {@link Bitmap#setHasMipMap(boolean)} for more information.
If the bitmap is null, or the current API version does not support setting a mipmap hint,
calling this method has no effect.
throw new UnsupportedOperationException(); // must be overridden in subclasses
|
public void | setTargetDensity(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.
setTargetDensity(canvas.getDensity());
|
public void | setTargetDensity(android.util.DisplayMetrics metrics)Set the density scale at which this drawable will be rendered.
setTargetDensity(metrics.densityDpi);
|
public void | setTargetDensity(int density)Set the density at which this drawable will be rendered.
if (mTargetDensity != density) {
mTargetDensity = density == 0 ? DisplayMetrics.DENSITY_DEFAULT : density;
if (mBitmap != null) {
computeBitmapSize();
}
invalidateSelf();
}
|
void | updateDstRect()
if (mApplyGravity) {
gravityCompatApply(mGravity, mBitmapWidth, mBitmapHeight,
getBounds(), mDstRect);
mDstRectF.set(mDstRect);
mApplyGravity = false;
}
|