Example usage for android.graphics Canvas HAS_ALPHA_LAYER_SAVE_FLAG

List of usage examples for android.graphics Canvas HAS_ALPHA_LAYER_SAVE_FLAG

Introduction

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

Prototype

int HAS_ALPHA_LAYER_SAVE_FLAG

To view the source code for android.graphics Canvas HAS_ALPHA_LAYER_SAVE_FLAG.

Click Source Link

Document

The layer requires a per-pixel alpha channel.

Usage

From source file:ezy.ui.view.ViewPagerIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int flags = Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG
            | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG;
    int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, flags);

    int wg = mItemWidth + mItemGap;
    int x = (getWidth() - mWidth) / 2;
    int y = (getHeight() - mItemHeight) / 2;

    mItemDrawable.setBounds(0, 0, mItemWidth, mItemHeight);
    mItemDrawableSelected.setBounds(0, 0, mItemWidth, mItemHeight);

    for (int i = 0; i < mItemCount; i++) {
        canvas.save();/*from  w w  w  .j a va 2 s.  com*/
        canvas.translate(x + i * wg, y);
        mItemDrawable.draw(canvas);
        canvas.restore();
    }

    canvas.save();
    canvas.translate(x + (mPosition + mPositionOffset) * wg, y);
    mItemDrawableSelected.draw(canvas);
    canvas.restore();

    canvas.restoreToCount(sc);
}

From source file:com.ceabie.EffectiveLib.EffectImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mEffectDrawable == null || mEffectDrawable.getOpacity() == PixelFormat.TRANSPARENT // ?
            || getDrawable() == null) {//from  w w  w  . ja  v a  2s . co m
        super.onDraw(canvas);
        return;
    }

    if (mRectF == null) {
        mRectF = new RectF();
    }

    mRectF.left = 0;
    mRectF.top = 0;
    mRectF.right = getMeasuredWidth();
    mRectF.bottom = getMeasuredHeight();

    int saveBottom = 0;
    //
    if (!mHardware) {
        saveBottom = canvas.saveLayer(mRectF, null,
                Canvas.CLIP_TO_LAYER_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
    }

    super.onDraw(canvas);

    mPaint.setXfermode(mXfermodeDstIn);
    int saveCount = canvas.saveLayer(mRectF, mPaint, Canvas.CLIP_TO_LAYER_SAVE_FLAG);
    mPaint.setXfermode(null);

    mEffectDrawable.draw(canvas);

    canvas.restoreToCount(saveCount);

    if (!mHardware) {
        canvas.restoreToCount(saveBottom);
    }
}

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

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

    int sc = canvas.saveLayer(0, 0, mViewWidthPx, mViewHeightPx, null,
            Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG
                    | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG);

    int mAnimationInValue = (int) mAnimationIn.getAnimatedValue();
    int mAnimationOutValue = mAnimationOut.isRunning() ? (int) mAnimationOut.getAnimatedValue() : 0;

    canvas.drawPaint(mBackgroundPaint);//from   w  w w. ja va2  s  . c om
    canvas.drawArc(mLeftCircleArc, LEFT_START_DEGRE - mAnimationOutValue,
            -mAnimationInValue + mAnimationOutValue, true, mAnimPaint);
    canvas.drawArc(mRightCircleArc, RIGHT_START_DEGRE - mAnimationOutValue,
            -mAnimationInValue + mAnimationOutValue, true, mAnimPaint);
    canvas.drawBitmap(mMaskBitmap, 0, 0, mMaskPaint);
    canvas.restoreToCount(sc);
}

From source file:com.example.zhangyangjing.roundcornerimageview.BezelImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mBounds == null) {
        return;/*from  ww w  . j  a  va  2 s  . co m*/
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
        return;
    }

    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
        // Need to redraw the cache
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            //noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
            generateMaskPath(mCachedWidth, mCachedHeight);
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        int sc = cacheCanvas.save();
        mDesaturatePaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null);
        cacheCanvas.saveLayer(mBoundsF, mDesaturatePaint,
                Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
        super.onDraw(cacheCanvas);
        cacheCanvas.drawPath(this.mMaskedPath, this.mMaskedPaint);
        cacheCanvas.restoreToCount(sc);
    }

    // Draw from cache
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}

From source file:app.geochat.ui.widgets.BezelImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mBounds == null) {
        return;//from   w w w  .j a  v a 2s. c  om
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
        return;
    }

    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
        // Need to redraw the cache
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            //noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        if (mMaskDrawable != null) {
            int sc = cacheCanvas.save();
            mMaskDrawable.draw(cacheCanvas);
            mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else if (mDesaturateOnPress && isPressed()) {
            int sc = cacheCanvas.save();
            cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
            mMaskedPaint.setColorFilter(mDesaturateColorFilter);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else {
            super.onDraw(cacheCanvas);
        }

        if (mBorderDrawable != null) {
            mBorderDrawable.draw(cacheCanvas);
        }
    }

    // Draw from cache
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}

From source file:com.udacity.adcs.app.goodintents.ui.view.BezelImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mBounds == null) {
        return;//  ww w  . j a va 2  s. c om
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
        return;
    }

    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
        // Need to redraw the cache
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            // noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        if (mMaskDrawable != null) {
            int sc = cacheCanvas.save();
            mMaskDrawable.draw(cacheCanvas);
            mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else if (mDesaturateOnPress && isPressed()) {
            int sc = cacheCanvas.save();
            cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
            mMaskedPaint.setColorFilter(mDesaturateColorFilter);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else {
            super.onDraw(cacheCanvas);
        }

        if (mBorderDrawable != null) {
            mBorderDrawable.draw(cacheCanvas);
        }
    }

    // Draw from cache
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}

From source file:cl.monsoon.s1next.widget.BezelImageView.java

@Override
protected void onDraw(@NonNull Canvas canvas) {
    if (mBounds == null) {
        return;//from   w w w .java2s  .  c  om
    }

    int width = mBounds.width();
    int height = mBounds.height();
    if (width == 0 || height == 0) {
        return;
    }

    if (!mCacheValid || mCachedWidth != width || mCachedHeight != height) {
        // need to redraw the cache
        if (mCachedWidth == width && mCachedHeight == height) {
            // have a correct-sized bitmap cache already allocated
            // just erase it
            mCacheBitmap.eraseColor(Color.TRANSPARENT);
        } else {
            // allocate a new bitmap with the correct dimensions
            mCacheBitmap.recycle();
            //noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        if (mMaskDrawable != null) {
            int saveCount = cacheCanvas.save();
            mMaskDrawable.draw(cacheCanvas);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(saveCount);
        } else {
            super.onDraw(cacheCanvas);
        }

        if (mBorderDrawable != null) {
            mBorderDrawable.draw(cacheCanvas);
        }
    }

    // draw from cache
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}

From source file:com.p2p.ui.BezelImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mBounds == null) {
        return;/*  ww w  .  j  a  va  2 s.  c o  m*/
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
        return;
    }
    if (isInEditMode()) {
        return;
    }
    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
        // Need to redraw the cache
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            //noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        if (mMaskDrawable != null) {
            int sc = cacheCanvas.save();
            mMaskDrawable.draw(cacheCanvas);
            mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else if (mDesaturateOnPress && isPressed()) {
            int sc = cacheCanvas.save();
            cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
            mMaskedPaint.setColorFilter(mDesaturateColorFilter);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else {
            super.onDraw(cacheCanvas);
        }

        if (mBorderDrawable != null) {
            mBorderDrawable.draw(cacheCanvas);
        }
    }

    // Draw from cache
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}

From source file:com.aprz.easy_iosched.ui.widget.BezelImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mBounds == null) {
        return;/*from  w w w .j  ava2 s  .  c o m*/
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
        return;
    }

    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
        // Need to redraw the cache.
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            //noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        if (mMaskDrawable != null) {
            int sc = cacheCanvas.save();
            mMaskDrawable.draw(cacheCanvas);
            mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else if (mDesaturateOnPress && isPressed()) {
            int sc = cacheCanvas.save();
            cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
            mMaskedPaint.setColorFilter(mDesaturateColorFilter);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else {
            super.onDraw(cacheCanvas);
        }

        if (mBorderDrawable != null) {
            mBorderDrawable.draw(cacheCanvas);
        }
    }

    // Draw from cache.
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}

From source file:com.dream.yzbb.wolfkiller.widget.BezelImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mBounds == null) {
        return;/*from w  w w .  j a va  2s.com*/
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
        return;
    }

    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
        // Need to redraw the cache.
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            //noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        if (mMaskDrawable != null) {
            int sc = cacheCanvas.save();
            mMaskDrawable.draw(cacheCanvas);
            mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed())
                    ? mDesaturateColorFilter : null);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else if (mDesaturateOnPress && isPressed()) {
            int sc = cacheCanvas.save();
            cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
            mMaskedPaint.setColorFilter(mDesaturateColorFilter);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else {
            super.onDraw(cacheCanvas);
        }

        if (mBorderDrawable != null) {
            mBorderDrawable.draw(cacheCanvas);
        }
    }

    // Draw from cache.
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}