Search in sources :

Example 41 with BitmapShader

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;
}
Also used : BitmapShader(android.graphics.BitmapShader)

Example 42 with BitmapShader

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);
    }
}
Also used : Matrix(android.graphics.Matrix) BitmapShader(android.graphics.BitmapShader)

Example 43 with BitmapShader

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);
}
Also used : Bitmap(android.graphics.Bitmap) Paint(android.graphics.Paint) BitmapShader(android.graphics.BitmapShader) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 44 with BitmapShader

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);
}
Also used : Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) BitmapShader(android.graphics.BitmapShader) Paint(android.graphics.Paint)

Example 45 with BitmapShader

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;
}
Also used : Bitmap(android.graphics.Bitmap) Paint(android.graphics.Paint) BitmapShader(android.graphics.BitmapShader)

Aggregations

BitmapShader (android.graphics.BitmapShader)137 Bitmap (android.graphics.Bitmap)86 Paint (android.graphics.Paint)69 Canvas (android.graphics.Canvas)60 Matrix (android.graphics.Matrix)20 BitmapDrawable (android.graphics.drawable.BitmapDrawable)15 RectF (android.graphics.RectF)14 ShapeDrawable (android.graphics.drawable.ShapeDrawable)14 AnimationDrawable (android.graphics.drawable.AnimationDrawable)13 ClipDrawable (android.graphics.drawable.ClipDrawable)13 Drawable (android.graphics.drawable.Drawable)13 LayerDrawable (android.graphics.drawable.LayerDrawable)13 Rect (android.graphics.Rect)9 Shader (android.graphics.Shader)8 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)6 StateListDrawable (android.graphics.drawable.StateListDrawable)4 Point (android.graphics.Point)3 SuppressLint (android.annotation.SuppressLint)2 ColorMatrix (android.graphics.ColorMatrix)2 TypedArray (android.content.res.TypedArray)1