Search in sources :

Example 31 with BitmapShader

use of android.graphics.BitmapShader in project android_frameworks_base by ResurrectionRemix.

the class TaskViewThumbnail method setThumbnail.

/** Sets the thumbnail to a given bitmap. */
void setThumbnail(Bitmap bm, ActivityManager.TaskThumbnailInfo thumbnailInfo) {
    if (bm != null) {
        bm.prepareToDraw();
        float INITIAL_SCALE = 0.75f;
        int h = bm.getHeight();
        int w = bm.getWidth();
        Bitmap cropped = null;
        int mode = currentHandsMode();
        try {
            if (mode == 1) {
                cropped = Bitmap.createBitmap(bm, 0, (int) (h * (1 - INITIAL_SCALE)), (int) (w * INITIAL_SCALE), (int) (h * INITIAL_SCALE));
            } else if (mode == 2) {
                cropped = Bitmap.createBitmap(bm, (int) (w * (1 - INITIAL_SCALE)), (int) (h * (1 - INITIAL_SCALE)), (int) (w * INITIAL_SCALE), (int) (h * INITIAL_SCALE));
            }
        } catch (Exception e) {
            cropped = bm;
        }
        mBitmapShader = new BitmapShader(currentHandsMode() != 0 ? cropped : bm, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        mDrawPaint.setShader(mBitmapShader);
        mThumbnailRect.set(0, 0, currentHandsMode() != 0 ? cropped.getWidth() : w, currentHandsMode() != 0 ? cropped.getHeight() : h);
        mThumbnailInfo = thumbnailInfo;
        updateThumbnailScale();
    } else {
        mBitmapShader = null;
        mDrawPaint.setShader(null);
        mThumbnailRect.setEmpty();
        mThumbnailInfo = null;
    }
}
Also used : Bitmap(android.graphics.Bitmap) BitmapShader(android.graphics.BitmapShader) Paint(android.graphics.Paint)

Example 32 with BitmapShader

use of android.graphics.BitmapShader in project Atom_Android by Rogrand-Dev.

the class CircleImageView method setup.

private void setup() {
    if (!mReady) {
        mSetupPending = true;
        return;
    }
    if (getWidth() == 0 && getHeight() == 0) {
        return;
    }
    if (mBitmap == null) {
        invalidate();
        return;
    }
    mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mBitmapPaint.setAntiAlias(true);
    mBitmapPaint.setShader(mBitmapShader);
    mBorderPaint.setStyle(Paint.Style.STROKE);
    mBorderPaint.setAntiAlias(true);
    mBorderPaint.setColor(mBorderColor);
    mBorderPaint.setStrokeWidth(mBorderWidth);
    mFillPaint.setStyle(Paint.Style.FILL);
    mFillPaint.setAntiAlias(true);
    mFillPaint.setColor(mFillColor);
    mBitmapHeight = mBitmap.getHeight();
    mBitmapWidth = mBitmap.getWidth();
    mBorderRect.set(calculateBounds());
    mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2.0f, (mBorderRect.width() - mBorderWidth) / 2.0f);
    mDrawableRect.set(mBorderRect);
    if (!mBorderOverlay && mBorderWidth > 0) {
        mDrawableRect.inset(mBorderWidth - 1.0f, mBorderWidth - 1.0f);
    }
    mDrawableRadius = Math.min(mDrawableRect.height() / 2.0f, mDrawableRect.width() / 2.0f);
    applyColorFilter();
    updateShaderMatrix();
    invalidate();
}
Also used : BitmapShader(android.graphics.BitmapShader)

Example 33 with BitmapShader

use of android.graphics.BitmapShader in project android_frameworks_base by ResurrectionRemix.

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 34 with BitmapShader

use of android.graphics.BitmapShader in project BaseRecyclerViewAdapterHelper by CymChad.

the class GlideCircleTransform method circleCrop.

private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null)
        return null;
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;
    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    paint.setAntiAlias(true);
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) BitmapShader(android.graphics.BitmapShader) Paint(android.graphics.Paint)

Example 35 with BitmapShader

use of android.graphics.BitmapShader in project Douya by DreaminginCodeZH.

the class SimpleCircleImageView method setup.

private void setup() {
    if (!mReady) {
        mSetupPending = true;
        return;
    }
    if (getWidth() == 0 && getHeight() == 0) {
        return;
    }
    if (mBitmap == null) {
        invalidate();
        return;
    }
    mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mBitmapPaint.setAntiAlias(true);
    mBitmapPaint.setShader(mBitmapShader);
    mBitmapWidth = mBitmap.getWidth();
    mBitmapHeight = mBitmap.getHeight();
    mDrawableRect.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(), getHeight() - getPaddingBottom());
    mDrawableRadius = Math.min(mDrawableRect.height() / 2f, mDrawableRect.width() / 2f);
    updateShaderMatrix();
    invalidate();
}
Also used : 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