Example usage for android.graphics PorterDuffXfermode PorterDuffXfermode

List of usage examples for android.graphics PorterDuffXfermode PorterDuffXfermode

Introduction

In this page you can find the example usage for android.graphics PorterDuffXfermode PorterDuffXfermode.

Prototype

public PorterDuffXfermode(PorterDuff.Mode mode) 

Source Link

Document

Create an xfermode that uses the specified porter-duff mode.

Usage

From source file:me.lizheng.deckview.views.DeckChildViewHeader.java

public DeckChildViewHeader(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mConfig = DeckViewConfig.getInstance();
    setWillNotDraw(false);/*w  ww .j  a v a  2  s .  c  o m*/

    // Load the dismiss resources
    Resources res = context.getResources();
    mLightDismissDrawable = ContextCompat.getDrawable(context, R.drawable.deck_child_view_dismiss_light);
    mDarkDismissDrawable = ContextCompat.getDrawable(context, R.drawable.deck_child_view_dismiss_dark);
    mDismissContentDescription = res.getString(R.string.accessibility_item_will_be_dismissed);

    // Configure the highlight paint
    if (sHighlightPaint == null) {
        sHighlightPaint = new Paint();
        sHighlightPaint.setStyle(Paint.Style.STROKE);
        sHighlightPaint.setStrokeWidth(mConfig.taskViewHighlightPx);
        sHighlightPaint.setColor(mConfig.taskBarViewHighlightColor);
        sHighlightPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.ADD));
        sHighlightPaint.setAntiAlias(true);
    }
}

From source file:org.sfx.catholicjourney.core.view.BezelImageView.java

public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, 0);

    mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_biv_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }//from  w  w  w  .  j a  v a  2  s.  c  o  m

    mSelectorColor = a.getColor(R.styleable.BezelImageView_biv_selectorOnPress, 0);

    a.recycle();

    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    // Create a desaturate color filter for pressed state.
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    mDesaturateColorFilter = new ColorMatrixColorFilter(cm);

    //create a selectorFilter if we already have a color
    if (mSelectorColor != 0) {
        this.mSelectorFilter = new PorterDuffColorFilter(Color.argb(mSelectorAlpha, Color.red(mSelectorColor),
                Color.green(mSelectorColor), Color.blue(mSelectorColor)), PorterDuff.Mode.SRC_ATOP);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        addElevationSupport();
    }
}

From source file:ar.uba.fi.splitapp.MockServer.java

private static Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int color = Color.RED;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);//from  w  w w.j a  v  a  2s  .  c  o  m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    bitmap.recycle();

    return output;
}

From source file:com.popdeem.sdk.uikit.widget.PDUIBezelImageView.java

public PDUIBezelImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, 0);

    mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }//w  ww  .  j  a  v a2  s.  c  o  m

    mBorderDrawable = a.getDrawable(R.styleable.BezelImageView_borderDrawable);
    if (mBorderDrawable != null) {
        mBorderDrawable.setCallback(this);
    }

    mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress, mDesaturateOnPress);

    a.recycle();

    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}

From source file:com.visenze.visearch.camerademo.views.RoundImageView.java

public RoundImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setLayerType(LAYER_TYPE_HARDWARE, null);
    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, styleable.RoundImageView, defStyle, 0);

    mMaskDrawable = a.getDrawable(styleable.RoundImageView_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }/*from  w  ww .jav  a2 s  .c  om*/

    mBorderDrawable = a.getDrawable(styleable.RoundImageView_borderDrawable);
    if (mBorderDrawable != null) {
        mBorderDrawable.setCallback(this);
    }

    mDesaturateOnPress = a.getBoolean(styleable.RoundImageView_desaturateOnPress, mDesaturateOnPress);

    a.recycle();

    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xffff0000);
    mBlackPaint.setAntiAlias(true);

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    mMaskedPaint.setAntiAlias(true);

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}

From source file:com.cooltechworks.views.ScratchTextView.java

/**
 * Initialises the paint drawing elements.
 *///from www. j  a va  2s . c o m
private void init() {

    mTouchPath = new Path();

    mErasePaint = new Paint();
    mErasePaint.setAntiAlias(true);
    mErasePaint.setDither(true);
    mErasePaint.setColor(0xFFFF0000);
    mErasePaint.setStyle(Paint.Style.STROKE);
    mErasePaint.setStrokeJoin(Paint.Join.BEVEL);
    mErasePaint.setStrokeCap(Paint.Cap.ROUND);
    mErasePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    setStrokeWidth(6);

    mGradientBgPaint = new Paint();

    mErasePath = new Path();
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);

    Bitmap scratchBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_scratch_pattern);
    mDrawable = new BitmapDrawable(getResources(), scratchBitmap);
    mDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);

}

From source file:com.android.tabletcustomui.views.LeftCircleContainer.java

private void addCircle(int position, final int value, float diff, double ratio) {
    final int radius = value / 2;
    final RectF mOval = new RectF();
    mOval.set(0 + diff, 0 + diff, value - diff, value - diff);

    final Paint mPaintClip = new Paint();
    mPaintClip.setStyle(Paint.Style.FILL);
    mPaintClip.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.OVERLAY));
    mPaintClip.setAntiAlias(true);//from w  ww  .  jav a2  s  .  c  o m

    final PointF pointF = new PointF(mOval.centerX(), mOval.centerY());
    final Path clipPath = new Path();
    clipPath.addCircle(pointF.x, pointF.y, (float) (radius * ratio), Path.Direction.CW);

    View circleView;
    if (position == 0) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 330, 10, true, mPaintClip);
                canvas.drawArc(mOval, 342, 20, true, mPaintClip);
                canvas.drawArc(mOval, 4, 10, true, mPaintClip);

                canvas.drawArc(mOval, 240, 10, true, mPaintClip);
                canvas.drawArc(mOval, 252, 20, true, mPaintClip);
                canvas.drawArc(mOval, 275, 10, true, mPaintClip);

                canvas.drawArc(mOval, 150, 10, true, mPaintClip);
                canvas.drawArc(mOval, 162, 20, true, mPaintClip);
                canvas.drawArc(mOval, 185, 10, true, mPaintClip);

                canvas.drawArc(mOval, 60, 10, true, mPaintClip);
                canvas.drawArc(mOval, 72, 20, true, mPaintClip);
                canvas.drawArc(mOval, 95, 10, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);

        animateClockWise(circleView);

    } else if (position == 1) {

        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawCircle(pointF.x, pointF.y, radius, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 2) {

        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 55, 190, true, mPaintClip);

            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 3) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 240, 190, true, mPaintClip);
                canvas.drawArc(mOval, 80, 150, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 4) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 335, 150, true, mPaintClip);
                canvas.drawArc(mOval, 140, 180, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 5) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_grey));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 330, 150, true, mPaintClip);
                canvas.drawArc(mOval, 140, 150, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 6) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_purple_color));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 290, 5, true, mPaintClip);
                canvas.drawArc(mOval, 297, 20, true, mPaintClip);
                canvas.drawArc(mOval, 319, 20, true, mPaintClip);

                canvas.drawArc(mOval, 60, 15, true, mPaintClip);
                canvas.drawArc(mOval, 77, 8, true, mPaintClip);

            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);

        animateClockWise(circleView);

    } else if (position == 7) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 160, 10, true, mPaintClip);
                canvas.drawArc(mOval, 172, 30, true, mPaintClip);
                canvas.drawArc(mOval, 204, 30, true, mPaintClip);
                canvas.drawArc(mOval, 236, 10, true, mPaintClip);

                canvas.drawArc(mOval, 20, 20, true, mPaintClip);
                canvas.drawArc(mOval, 42, 8, true, mPaintClip);

            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateAntiClockWise(circleView);
    }
}

From source file:com.micabytes.gfx.ImageHandler.java

@SuppressWarnings("unused")
@Nullable//from  ww w  .  j av a  2  s .  c  om
public static Bitmap getSceneBitmap(int bkg, int left, int right) {
    Bitmap bitmap = get(bkg);
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    int color = COLOR_RED;
    paint.setColor(color);
    float roundPx = PIXEL_ROUNDING;
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    if (left > 0) {
        canvas.drawBitmap(get(left), 0, 0, null);
    }
    if (right > 0) {
        canvas.drawBitmap(get(right), 0, 0, null);
        // canvas.drawBitmap(get(right), bitmap.getWidth()/2, 0, null);
    }
    return output;
}

From source file:com.github.czy1121.view.CornerLabelView.java

public void init(Context context, AttributeSet attrs) {

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CornerLabelView);

    mPaddingTop = ta.getDimension(R.styleable.CornerLabelView_clvPaddingTop, dp2px(10));
    mPaddingCenter = ta.getDimension(R.styleable.CornerLabelView_clvPaddingCenter, dp2px(0));
    mPaddingBottom = ta.getDimension(R.styleable.CornerLabelView_clvPaddingBottom, dp2px(3));

    mText1.text = ta.getString(R.styleable.CornerLabelView_clvText1);
    mText1.height = ta.getDimension(R.styleable.CornerLabelView_clvText1Height, dp2px(12));
    mText1.color = ta.getColor(R.styleable.CornerLabelView_clvText1Color, 0xffffffff);
    mText1.init();/*w w w.  j a v  a 2s. co m*/
    mText1.reset();

    mText2.text = ta.getString(R.styleable.CornerLabelView_clvText2);
    mText2.height = ta.getDimension(R.styleable.CornerLabelView_clvText2Height, dp2px(8));
    mText2.color = ta.getColor(R.styleable.CornerLabelView_clvText2Color, 0x66ffffff);
    mText2.init();
    mText2.reset();

    int fillColor = ta.getColor(R.styleable.CornerLabelView_clvFillColor, 0x66000000);
    int flags = ta.getInteger(R.styleable.CornerLabelView_clvFlags, 0);

    ta.recycle();

    mIsLeft = (flags & 1) == 0;
    mIsTop = (flags & 2) == 0;
    mIsTriangle = (flags & 4) > 0;

    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
    mPaint.setAntiAlias(true);
    mPaint.setColor(fillColor);

}

From source file:com.cnh.library.materialdrawer.view.BezelImageView.java

public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle,
            R.style.BezelImageView);//from  w w  w  . j  a va  2s .com

    mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_biv_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }

    mDrawCircularShadow = a.getBoolean(R.styleable.BezelImageView_biv_drawCircularShadow, true);

    mSelectorColor = a.getColor(R.styleable.BezelImageView_biv_selectorOnPress, 0);

    a.recycle();

    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    // Create a desaturate color filter for pressed state.
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    mDesaturateColorFilter = new ColorMatrixColorFilter(cm);

    //create a selectorFilter if we already have a color
    if (mSelectorColor != 0) {
        this.mSelectorFilter = new PorterDuffColorFilter(Color.argb(mSelectorAlpha, Color.red(mSelectorColor),
                Color.green(mSelectorColor), Color.blue(mSelectorColor)), PorterDuff.Mode.SRC_ATOP);
    }
}