use of android.graphics.BitmapShader in project Carbon by ZieIony.
the class RippleDrawableFroyo method updateMaskShaderIfNeeded.
/**
* @return whether we need to use a mask
*/
private void updateMaskShaderIfNeeded() {
if (mHasValidMask) {
return;
}
final int maskType = getMaskType();
if (maskType == MASK_UNKNOWN) {
return;
}
mHasValidMask = true;
final Rect bounds = getBounds();
if (maskType == MASK_NONE || bounds.isEmpty()) {
if (mMaskBuffer != null) {
mMaskBuffer.recycle();
mMaskBuffer = null;
mMaskShader = null;
mMaskCanvas = null;
}
mMaskMatrix = null;
mMaskColorFilter = null;
return;
}
// Ensure we have a correctly-sized buffer.
if (mMaskBuffer == null || mMaskBuffer.getWidth() != bounds.width() || mMaskBuffer.getHeight() != bounds.height()) {
if (mMaskBuffer != null) {
mMaskBuffer.recycle();
}
mMaskBuffer = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ALPHA_8);
mMaskShader = new BitmapShader(mMaskBuffer, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mMaskCanvas = new Canvas(mMaskBuffer);
} else {
mMaskBuffer.eraseColor(Color.TRANSPARENT);
}
if (mMaskMatrix == null) {
mMaskMatrix = new Matrix();
} else {
mMaskMatrix.reset();
}
if (mMaskColorFilter == null) {
mMaskColorFilter = new PorterDuffColorFilter(0, PorterDuff.Mode.SRC_IN);
}
// Draw the appropriate mask anchored to (0,0).
final int left = bounds.left;
final int top = bounds.top;
mMaskCanvas.translate(-left, -top);
if (maskType == MASK_EXPLICIT) {
drawMask(mMaskCanvas);
} else if (maskType == MASK_CONTENT) {
drawContent(mMaskCanvas);
}
mMaskCanvas.translate(left, top);
}
use of android.graphics.BitmapShader in project remusic by aa112901.
the class RoundImageView method make.
private void make(Bitmap bitmap) {
mBitmap = getCroppedRoundBitmap(bitmap, 255, 15);
mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mBitmapPaint.setAntiAlias(true);
mBitmapPaint.setShader(mBitmapShader);
mDrawableRect.set(0, 0, getWidth(), getHeight());
mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);
mBitmapHeight = mBitmap.getHeight();
mBitmapWidth = mBitmap.getWidth();
updateShaderMatrix();
invalidate();
}
use of android.graphics.BitmapShader in project Signal-Android by WhisperSystems.
the class RoundedCorners method round.
private Bitmap round(@NonNull BitmapPool pool, @Nullable Bitmap toRound) {
if (toRound == null) {
return null;
}
Bitmap result = pool.get(toRound.getWidth(), toRound.getHeight(), getSafeConfig(toRound));
if (result == null) {
result = Bitmap.createBitmap(toRound.getWidth(), toRound.getHeight(), getSafeConfig(toRound));
}
Canvas canvas = new Canvas(result);
if (Config.RGB_565.equals(result.getConfig())) {
Paint cornerPaint = new Paint();
cornerPaint.setColor(colorHint);
canvas.drawRect(0, 0, radius, radius, cornerPaint);
canvas.drawRect(0, toRound.getHeight() - radius, radius, toRound.getHeight(), cornerPaint);
canvas.drawRect(toRound.getWidth() - radius, 0, toRound.getWidth(), radius, cornerPaint);
canvas.drawRect(toRound.getWidth() - radius, toRound.getHeight() - radius, toRound.getWidth(), toRound.getHeight(), cornerPaint);
}
Paint shaderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
shaderPaint.setShader(new BitmapShader(toRound, TileMode.CLAMP, TileMode.CLAMP));
canvas.drawRoundRect(new RectF(0, 0, toRound.getWidth(), toRound.getHeight()), radius, radius, shaderPaint);
return result;
}
use of android.graphics.BitmapShader in project platform_frameworks_base by android.
the class UserIconDrawable method setIcon.
public UserIconDrawable setIcon(Bitmap icon) {
if (mUserDrawable != null) {
mUserDrawable.setCallback(null);
mUserDrawable = null;
}
mUserIcon = icon;
if (mUserIcon == null) {
mIconPaint.setShader(null);
mBitmap = null;
} else {
mIconPaint.setShader(new BitmapShader(icon, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
}
onBoundsChange(getBounds());
return this;
}
use of android.graphics.BitmapShader in project NotificationPeekPort by lzanita09.
the class NotificationPeekViewUtils method getRoundedShape.
/**
* Get rounded icon from the Bitmap object, with shade. The shade will only be drawn if
* the Bitmap is larger than the ImageView's size.
*
* @param resources Resources object for getting size and color.
* @param scaleBitmapImage Source Bitmap.
* @return Rounded BitmapDrawable with shade (if possible).
*/
public static Drawable getRoundedShape(Resources resources, Bitmap scaleBitmapImage) {
final int shadowSize = resources.getDimensionPixelSize(R.dimen.shadow_size);
final int shadowColor = resources.getColor(R.color.background_color);
int targetWidth = scaleBitmapImage.getWidth();
int targetHeight = scaleBitmapImage.getHeight();
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setDither(true);
Paint shadowPaint = new Paint(paint);
RectF rectF = new RectF(0, 0, targetWidth, targetHeight);
Canvas canvas = new Canvas(targetBitmap);
final BitmapShader shader = new BitmapShader(scaleBitmapImage, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setShader(shader);
// Only apply shadow if the icon is large enough.
if (scaleBitmapImage.getWidth() > resources.getDimensionPixelSize(R.dimen.notification_icon_size)) {
rectF.inset(shadowSize, shadowSize);
shadowPaint.setShadowLayer(shadowSize, 0f, 0f, shadowColor);
shadowPaint.setColor(Color.BLACK);
canvas.drawOval(rectF, shadowPaint);
}
canvas.drawOval(rectF, paint);
return new BitmapDrawable(resources, targetBitmap);
}
Aggregations