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:io.plaidapp.ui.widget.CutoutTextView.java

private void createBitmap() {
    if (cutout != null && !cutout.isRecycled()) {
        cutout.recycle();//w  w  w .j av a  2s  .  co  m
    }
    cutout = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
    cutout.setHasAlpha(true);
    Canvas cutoutCanvas = new Canvas(cutout);
    cutoutCanvas.drawColor(foregroundColor);

    // this is the magic  Clear mode punches out the bitmap
    textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    cutoutCanvas.drawText(text, textX, textY, textPaint);
}

From source file:hu.py82c7.homework.view.BezelImageView.java

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

    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, hu.py82c7.homework.R.styleable.BezelImageView,
            defStyle, hu.py82c7.homework.R.style.BezelImageView);

    mMaskDrawable = a.getDrawable(hu.py82c7.homework.R.styleable.BezelImageView_biv_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }/*from   w w  w  .ja va2 s  .  c o m*/

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

    mSelectorColor = a.getColor(hu.py82c7.homework.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);
    }
}

From source file:com.it.selectphotodemo.PhotoUtils.java

/**
* Get rounded corner images//from ww  w . j a  v a  2  s.  c o m
* 
* @param bitmap
* @param roundPx
* @return
*/
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, w, h);
    final RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}

From source file:potboiler.client.PotsActivity.java

License:asdf

private void createDrawerMenu() {

    mMenuItems = getResources().getStringArray(R.array.menu_sections);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawer = (LinearLayout) findViewById(R.id.left_drawer);
    mCommandsList = (ListView) findViewById(R.id.commands);

    User user = PreferenceUtils.getUser(this);
    ((TextView) findViewById(R.id.name)).setText(user.username);

    Bitmap bitmap = ImageUtils.getImageFromFile(this, FileUtils.getImagesPath(this) + user.serverId);
    if (bitmap != null) {
        /*Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
                /*  w ww  . j a  v  a  2 s.  c  o m*/
        BitmapShader shader = new BitmapShader (bitmap,  Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        Paint paint = new Paint();
        paint.setShader(shader);
        paint.setAntiAlias(true);
        Canvas c = new Canvas(circleBitmap);
        c.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);*/

        int w = bitmap.getWidth();
        int h = bitmap.getHeight();

        int radius = Math.min(h / 2, w / 2);
        Bitmap circleBitmap = Bitmap.createBitmap(w + 8, h + 8, Bitmap.Config.ARGB_8888);

        Paint paint = new Paint();
        paint.setAntiAlias(true);

        Canvas c = new Canvas(circleBitmap);
        c.drawARGB(0, 0, 0, 0);
        paint.setStyle(Paint.Style.FILL);

        c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

        c.drawBitmap(bitmap, 4, 4, paint);
        paint.setXfermode(null);
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.WHITE);
        paint.setStrokeWidth(3);
        c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, paint);

        ((ImageView) findViewById(R.id.avatar)).setImageBitmap(circleBitmap);
    }

    mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent));

    DrawerAdapter adapter = new DrawerAdapter(this, R.layout.item_drawer_list, R.id.title, mMenuItems);
    mCommandsList.setAdapter(adapter);
    mCommandsList.setOnItemClickListener(new DrawerItemClickListener());

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.pots, R.string.pots) {

        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            syncActionBarArrowState();
            //                invalidateOptionsMenu();
            //                mDrawerToggle.syncState();
            //                setRefreshMenu();
        }

        public void onDrawerOpened(View drawerView) {
            //                super.onDrawerClosed(drawerView);
            super.onDrawerOpened(drawerView);
            mDrawerToggle.setDrawerIndicatorEnabled(true);
            //                invalidateOptionsMenu();
            //                mDrawerToggle.syncState();
            //                setRefreshMenu();
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);

            float xPositionOpenDrawer = mCommandsList.getWidth();
            float xPositionWindowContent = (slideOffset * xPositionOpenDrawer);
            FrameLayout mHostFragment = (FrameLayout) findViewById(R.id.content_frame);
            mHostFragment.setX(xPositionWindowContent);
            getActionBarView().setX(xPositionWindowContent);
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();
    getSupportFragmentManager().addOnBackStackChangedListener(mOnBackStackChangedListener);

    findViewById(R.id.signout).setOnClickListener(this);
}

From source file:us.shandian.blacklight.ui.common.SwipeUpAndDownRefreshLayout.java

@Override
public void draw(Canvas canvas) {
    Object progressBar = null;/*from w w  w .  j a v a 2  s  .c om*/

    try {
        progressBar = mProgressBar.get(this);
    } catch (Exception e) {

    }

    Method m = mSetBounds;

    if (m == null && progressBar != null) {
        try {
            m = progressBar.getClass().getDeclaredMethod("setBounds", int.class, int.class, int.class,
                    int.class);
            m.setAccessible(true);
        } catch (Exception e) {

        }
    }

    if (m != null) {
        mSetBounds = m;

        try {
            m.invoke(progressBar, 0, 0, 0, 0);
        } catch (Exception e) {

        }
    }

    super.draw(canvas);

    if (m != null) {
        Paint p = new Paint();
        p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        mCanvas.drawPaint(p);
        try {
            m.invoke(progressBar, 0, 0, mWidth, mProgressBarHeight);

            Method method = mDraw;

            if (method == null) {
                method = progressBar.getClass().getDeclaredMethod("draw", Canvas.class);
                method.setAccessible(true);
            }

            mDraw = method;
            method.invoke(progressBar, mCanvas);
        } catch (Exception e) {

        }

        canvas.drawBitmap(mBitmap, 0, isDown() ? mHeight - mProgressBarHeight : 0, null);
    }
}

From source file:com.ibuildapp.romanblack.FanWallPlugin.data.Statics.java

/**
 * Sets the downloaded avatar./*from  www. j a v  a 2  s.c  o  m*/
 *
 * @param filePath file path to avatar image
 */
public static Bitmap publishAvatar(String filePath) {
    Bitmap bitmap = null;

    if (!TextUtils.isEmpty(filePath)) {
        try {
            BitmapFactory.Options opts = new BitmapFactory.Options();
            opts.inSampleSize = 1;
            bitmap = BitmapFactory.decodeFile(filePath, opts);
            int size = 0;
            if (bitmap.getHeight() > bitmap.getWidth()) {
                size = bitmap.getWidth();
            } else {
                size = bitmap.getHeight();
            }
            Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(output);

            final int color = 0xff424242;
            final Paint paint = new Paint();
            final Rect rect = new Rect(0, 0, size, size);
            final RectF rectF = new RectF(rect);
            final float roundPx = 12;

            paint.setAntiAlias(true);
            canvas.drawARGB(0, 0, 0, 0);
            paint.setColor(color);
            canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

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

            bitmap.recycle();

            return output;
        } catch (Exception e) {

        }
    }
    return null;
}

From source file:com.crazyapk.util.bitmap.ImageWorker.java

public Bitmap toRoundCorner(Bitmap bitmap, int pixels) {

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;
    paint.setAntiAlias(true);// w  w  w .j  av  a 2s . com
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;

}

From source file:de.mrapp.android.util.BitmapUtil.java

/**
 * Clips the corners of a bitmap in order to transform it into a round shape. Additionally, the
 * bitmap is resized to a specific size. Bitmaps, whose width and height are not equal, will be
 * clipped to a square beforehand.//w w w .  j  av a2  s. co m
 *
 * @param bitmap
 *         The bitmap, which should be clipped, as an instance of the class {@link Bitmap}. The
 *         bitmap may not be null
 * @param size
 *         The size, the bitmap should be resized to, as an {@link Integer} value in pixels. The
 *         size must be at least 1
 * @return The clipped bitmap as an instance of the class {@link Bitmap}
 */
public static Bitmap clipCircle(@NonNull final Bitmap bitmap, final int size) {
    Bitmap squareBitmap = clipSquare(bitmap, size);
    int squareSize = squareBitmap.getWidth();
    float radius = (float) squareSize / 2.0f;
    Bitmap clippedBitmap = Bitmap.createBitmap(squareSize, squareSize, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(clippedBitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.BLACK);
    canvas.drawCircle(radius, radius, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(squareBitmap, new Rect(0, 0, squareSize, squareSize),
            new Rect(0, 0, squareSize, squareSize), paint);
    return clippedBitmap;
}

From source file:fr.francetv.zoom.share.loader.ZoomLoaderView.java

private void init() {
    mIsRunning = false;/*from w w  w .  ja va2  s  . co  m*/

    mViewWidthPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, VIEW_WIDTH_DP,
            getResources().getDisplayMetrics());
    mViewHeightPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, VIEW_HEIGHT_DP,
            getResources().getDisplayMetrics());

    mRadiusPx = mViewHeightPx / 2;

    mMaskBitmap = Bitmap.createBitmap(mViewWidthPx, mViewHeightPx, Bitmap.Config.ARGB_8888);
    new Canvas(mMaskBitmap).drawBitmap(
            BitmapFactory.decodeResource(getContext().getResources(), R.drawable.img_loader_mask), 0, 0, null);

    mMaskPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mMaskPaint.setFilterBitmap(false);
    mMaskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBackgroundPaint.setFilterBitmap(false);
    mBackgroundPaint.setXfermode(null);
    mBackgroundPaint.setColor(ContextCompat.getColor(getContext(), android.R.color.darker_gray));

    // Circles
    mAnimPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mAnimPaint.setXfermode(null);
    mAnimPaint.setColor(ContextCompat.getColor(getContext(), android.R.color.holo_green_light));

    mLeftCircleArc = new RectF(0, 0, 2 * mRadiusPx, 2 * mRadiusPx);
    mRightCircleArc = new RectF(mViewWidthPx - 2 * mRadiusPx, 0, mViewWidthPx, 2 * mRadiusPx);

    //Anims
    mAnimationIn = ValueAnimator.ofInt(0, 361 + LEFT_START_DEGRE);
    mAnimationIn.setInterpolator(new FastOutSlowInInterpolator());
    mAnimationIn.addUpdateListener(mAnimationInUpdateListener);
    mAnimationIn.addListener(mAnimationInListener);
    mAnimationIn.setDuration(ANIMATION_IN_DURATION_MS);

    mAnimationOut = ValueAnimator.ofInt(0, 361 + LEFT_START_DEGRE);
    mAnimationOut.setInterpolator(new FastOutSlowInInterpolator());
    mAnimationOut.addUpdateListener(mAnimationOutUpdateListener);
    mAnimationOut.addListener(mAnimationOutListener);
    mAnimationOut.setDuration(ANIMATION_OUT_DURATION_MS);

    mDelayHandler = new DelayHandler(mAnimationOut);
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static Bitmap composeIcon(Drawable icon, Drawable maskIcon, int width, int height) {
    Bitmap app_mask_icon_scaled = Bitmap.createScaledBitmap(((BitmapDrawable) maskIcon).getBitmap(), width,
            height, false);/*from  w w  w . java2s  .co m*/
    Bitmap icon_scaled = Bitmap.createScaledBitmap(((BitmapDrawable) icon).getBitmap(), width, height, false);
    Paint paint = new Paint();
    PorterDuffXfermode porterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(app_mask_icon_scaled, 0, 0, paint);
    paint.setXfermode(porterDuffXfermode);
    canvas.drawBitmap(icon_scaled, 0, 0, paint);
    canvas.setBitmap(null);
    return bitmap;
}