Java Code Examples for android.graphics.Paint#getXfermode()

The following examples show how to use android.graphics.Paint#getXfermode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoundedImageView.java    From blurkit-android with MIT License 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    Drawable myDrawable = getDrawable();
    if (myDrawable!=null && myDrawable instanceof BitmapDrawable && mCornerRadius > 0) {
        rectF.set(myDrawable.getBounds());
        int prevCount = canvas.saveLayer(rectF, null, Canvas.ALL_SAVE_FLAG);
        getImageMatrix().mapRect(rectF);

        Paint paint = ((BitmapDrawable) myDrawable).getPaint();
        paint.setAntiAlias(true);
        paint.setColor(DEFAULT_COLOR);
        Xfermode prevMode = paint.getXfermode();

        canvas.drawARGB(DEFAULT_RGB, DEFAULT_RGB, DEFAULT_RGB, DEFAULT_RGB);
        canvas.drawRoundRect(rectF, mCornerRadius, mCornerRadius, paint);

        paint.setXfermode(porterDuffXfermode);
        super.onDraw(canvas);

        paint.setXfermode(prevMode);
        canvas.restoreToCount(prevCount);
    } else {
        super.onDraw(canvas);
    }
}
 
Example 2
Source File: LoadingDrawable.java    From Genius-Android with Apache License 2.0 6 votes vote down vote up
@Override
public int getOpacity() {
    final Paint bPaint = mBackgroundPaint;
    final Paint fPaint = mForegroundPaint;
    if (bPaint.getXfermode() == null && fPaint.getXfermode() == null) {
        final int alpha = Color.alpha(fPaint.getColor());
        if (alpha == 0) {
            return PixelFormat.TRANSPARENT;
        }
        if (alpha == 255) {
            return PixelFormat.OPAQUE;
        }
    }
    // not sure, so be safe
    return PixelFormat.TRANSLUCENT;
}
 
Example 3
Source File: StatePaintDrawable.java    From Genius-Android with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    final Paint paint = mPaint;
    final int prevAlpha = paint.getAlpha();
    paint.setAlpha(Ui.modulateAlpha(prevAlpha, getAlpha()));
    // only draw shape if it may affect output
    if (paint.getAlpha() != 0 || paint.getXfermode() != null /*|| paint.hasShadowLayer()*/) {
        final boolean clearColorFilter;
        if (mTintFilter != null && paint.getColorFilter() == null) {
            paint.setColorFilter(mTintFilter);
            clearColorFilter = true;
        } else {
            clearColorFilter = false;
        }

        // call draw
        draw(canvas, mPaint);

        if (clearColorFilter) {
            paint.setColorFilter(null);
        }
    }
    // restore
    paint.setAlpha(prevAlpha);
}
 
Example 4
Source File: CircleCheckDrawable.java    From Genius-Android with Apache License 2.0 6 votes vote down vote up
@Override
public int getOpacity() {
    final Paint circlePaint = mCirclePaint;
    final Paint ringPaint = mRingPaint;
    if (circlePaint.getXfermode() == null && ringPaint.getXfermode() == null) {
        final int alpha = Color.alpha(getColor());
        if (alpha == 0) {
            return PixelFormat.TRANSPARENT;
        }
        if (alpha == 255) {
            return PixelFormat.OPAQUE;
        }
    }
    // not sure, so be safe
    return PixelFormat.TRANSLUCENT;
}
 
Example 5
Source File: Spans.java    From Pioneer with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(@NonNull Rect outRect, @NonNull Canvas canvas, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(frame.right - frame.left, frame.bottom - frame.top, Bitmap.Config.ARGB_8888);
        bitmapCanvas = new Canvas(bitmap);
    }
    bitmapCanvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR);
    bitmapCanvas.translate(-x, 0);
    super.draw(outRect, bitmapCanvas, text, start, end, x, top, y, bottom, paint);
    Xfermode oldXfermode = paint.getXfermode();
    paint.setXfermode(this.xfermode);
    srcGroup.draw(outRect, bitmapCanvas, text, start, end, x, top, y, bottom, paint);
    paint.setXfermode(oldXfermode);
    canvas.drawBitmap(bitmap, x, 0, null);
}
 
Example 6
Source File: Spans.java    From Pioneer with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(@NonNull Rect outRect, @NonNull Canvas canvas, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(frame.right - frame.left, frame.bottom - frame.top, Bitmap.Config.ARGB_8888);
        bitmapCanvas = new Canvas(bitmap);
    }
    bitmapCanvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR);
    bitmapCanvas.translate(-x, 0);
    super.draw(outRect, bitmapCanvas, text, start, end, x, top, y, bottom, paint);
    Xfermode oldXfermode = paint.getXfermode();
    paint.setXfermode(this.xfermode);
    srcGroup.draw(outRect, bitmapCanvas, text, start, end, x, top, y, bottom, paint);
    paint.setXfermode(oldXfermode);
    canvas.drawBitmap(bitmap, x, 0, null);
}
 
Example 7
Source File: StatePaintDrawable.java    From Genius-Android with Apache License 2.0 5 votes vote down vote up
@Override
public int getOpacity() {
    final Paint p = mPaint;
    if (p.getXfermode() == null) {
        final int alpha = p.getAlpha();
        if (alpha == 0) {
            return PixelFormat.TRANSPARENT;
        }
        if (alpha == 255) {
            return PixelFormat.OPAQUE;
        }
    }
    // not sure, so be safe
    return PixelFormat.TRANSLUCENT;
}