Example usage for android.graphics Canvas saveLayer

List of usage examples for android.graphics Canvas saveLayer

Introduction

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

Prototype

public int saveLayer(float left, float top, float right, float bottom, @Nullable Paint paint,
        @Saveflags int saveFlags) 

Source Link

Document

Helper version of saveLayer() that takes 4 values rather than a RectF.

Usage

From source file:com.rks.musicx.misc.widgets.DiagonalLayout.java

@Override
protected void dispatchDraw(Canvas canvas) {
    int saveCount = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG);

    super.dispatchDraw(canvas);

    paint.setXfermode(pdMode);//  ww w  .j  a v a  2 s . c  o  m
    canvas.drawPath(clipPath, paint);

    canvas.restoreToCount(saveCount);
    paint.setXfermode(null);
}

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 .  j a  v  a2s  .  c o m
    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: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();// w  w w .j a v  a  2s .  co  m
        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.gj.administrator.gjerp.view.CircleIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    Log.e("CircleIndicator", "onDraw()");
    super.onDraw(canvas);
    int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), 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);
    for (ShapeHolder item : tabItems) {
        canvas.save();/*from w w  w.j  a  v a 2 s .com*/
        canvas.translate(item.getX(), item.getY());
        item.getShape().draw(canvas);
        canvas.restore();
    }

    if (movingItem != null) {
        canvas.save();
        canvas.translate(movingItem.getX(), movingItem.getY());
        movingItem.getShape().draw(canvas);
        canvas.restore();
    }
    canvas.restoreToCount(sc);
}

From source file:com.google.android.apps.muzei.settings.ChooseSourceFragment.java

private Bitmap generateSourceImage(Drawable image) {
    Bitmap bitmap = Bitmap.createBitmap(mItemImageSize, mItemImageSize, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    mTempRectF.set(0, 0, mItemImageSize, mItemImageSize);
    canvas.drawOval(mTempRectF, mImageFillPaint);
    if (image != null) {
        canvas.saveLayer(0, 0, mItemImageSize, mItemImageSize, mAlphaPaint, Canvas.ALL_SAVE_FLAG);
        image.setBounds(0, 0, mItemImageSize, mItemImageSize);
        image.draw(canvas);/*from   w w  w .  ja va 2  s .c om*/
        canvas.restore();
    }
    return bitmap;
}