use of android.graphics.BitmapShader in project android_frameworks_base by DirtyUnicorns.
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 UltimateAndroid by cymcsg.
the class CircularImageView method updateBitmapShader.
/**
* Re-initializes the shader texture used to fill in
* the Circle upon drawing.
*/
public void updateBitmapShader() {
if (image == null)
return;
shader = new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
if (canvasSize != image.getWidth() || canvasSize != image.getHeight()) {
Matrix matrix = new Matrix();
float scale = (float) canvasSize / (float) image.getWidth();
matrix.setScale(scale, scale);
shader.setLocalMatrix(matrix);
}
}
use of android.graphics.BitmapShader in project android_frameworks_base by ParanoidAndroid.
the class WebViewClassic method drawOverScrollBackground.
/**
* Draw the background when beyond bounds
* @param canvas Canvas to draw into
*/
private void drawOverScrollBackground(Canvas canvas) {
if (mOverScrollBackground == null) {
mOverScrollBackground = new Paint();
Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), com.android.internal.R.drawable.status_bar_background);
mOverScrollBackground.setShader(new BitmapShader(bm, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT));
mOverScrollBorder = new Paint();
mOverScrollBorder.setStyle(Paint.Style.STROKE);
mOverScrollBorder.setStrokeWidth(0);
mOverScrollBorder.setColor(0xffbbbbbb);
}
int top = 0;
int right = computeRealHorizontalScrollRange();
int bottom = top + computeRealVerticalScrollRange();
// first draw the background and anchor to the top of the view
canvas.save();
canvas.translate(getScrollX(), getScrollY());
canvas.clipRect(-getScrollX(), top - getScrollY(), right - getScrollX(), bottom - getScrollY(), Region.Op.DIFFERENCE);
canvas.drawPaint(mOverScrollBackground);
canvas.restore();
// then draw the border
canvas.drawRect(-1, top - 1, right, bottom, mOverScrollBorder);
// next clip the region for the content
canvas.clipRect(0, top, right, bottom);
}
use of android.graphics.BitmapShader in project android_frameworks_base by AOSPA.
the class RippleDrawable 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 Space-Station-Tracker by Kiarasht.
the class Resources method makeCheckerPaint.
public static Paint makeCheckerPaint(Context context) {
Paint paint = new Paint();
final Bitmap checkerBmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.checker_background);
paint.setShader(new BitmapShader(checkerBmp, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT));
paint.setStrokeWidth(dipToPixels(context, LINE_WIDTH_DIP));
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
return paint;
}
Aggregations