Example usage for android.graphics Canvas restore

List of usage examples for android.graphics Canvas restore

Introduction

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

Prototype

public void restore() 

Source Link

Document

This call balances a previous call to save(), and is used to remove all modifications to the matrix/clip state since the last save call.

Usage

From source file:com.github.jdsjlzx.ItemDecoration.StickyHeaderDecoration.java

/**
 * {@inheritDoc}/*from   w  w  w. java  2 s .  c  o m*/
 */
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    final int count = parent.getChildCount();

    for (int layoutPos = 0; layoutPos < count; layoutPos++) {
        final View child = parent.getChildAt(layoutPos);

        final int adapterPos = parent.getChildAdapterPosition(child);

        if (adapterPos != RecyclerView.NO_POSITION && (layoutPos == 0 || hasHeader(adapterPos))) {
            View header = getHeader(parent, adapterPos).itemView;
            c.save();
            final int left = child.getLeft();
            final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos);
            c.translate(left, top);
            header.setTranslationX(left);
            header.setTranslationY(top);
            header.draw(c);
            c.restore();
        }
    }
}

From source file:android.support.design.widget.CircularBorderDrawable.java

@Override
public void draw(Canvas canvas) {
    if (mInvalidateShader) {
        mPaint.setShader(createGradientShader());
        mInvalidateShader = false;//from www.  j a  v  a 2s .co m
    }

    final float halfBorderWidth = mPaint.getStrokeWidth() / 2f;
    final RectF rectF = mRectF;

    // We need to inset the oval bounds by half the border width. This is because stroke draws
    // the center of the border on the dimension. Whereas we want the stroke on the inside.
    copyBounds(mRect);
    rectF.set(mRect);
    rectF.left += halfBorderWidth;
    rectF.top += halfBorderWidth;
    rectF.right -= halfBorderWidth;
    rectF.bottom -= halfBorderWidth;

    canvas.save();
    canvas.rotate(mRotation, rectF.centerX(), rectF.centerY());
    // Draw the oval
    canvas.drawOval(rectF, mPaint);
    canvas.restore();
}

From source file:com.plugin.weight.ripple.RippleLayoutView.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    if (animationRunning) {
        canvas.save();//from  w  w  w .  j  av  a2  s.c  o  m
        if (rippleDuration <= timer * frameRate) {
            animationRunning = false;
            timer = 0;
            durationEmpty = -1;
            timerEmpty = 0;
            // There is problem on Android M where canvas.restore() seems to be called automatically
            // For now, don't call canvas.restore() manually on Android M (API 23)
            if (Build.VERSION.SDK_INT != 23) {
                canvas.restore();
            }
            invalidate();
            if (onCompletionListener != null)
                onCompletionListener.onComplete(this);
            return;
        } else
            canvasHandler.postDelayed(runnable, frameRate);

        if (timer == 0)
            canvas.save();

        canvas.drawCircle(x, y, (radiusMax * (((float) timer * frameRate) / rippleDuration)), paint);

        paint.setColor(Color.parseColor("#ffff4444"));

        if (rippleType == 1 && originBitmap != null && (((float) timer * frameRate) / rippleDuration) > 0.4f) {
            if (durationEmpty == -1)
                durationEmpty = rippleDuration - timer * frameRate;

            timerEmpty++;
            final Bitmap tmpBitmap = getCircleBitmap(
                    (int) ((radiusMax) * (((float) timerEmpty * frameRate) / (durationEmpty))));
            canvas.drawBitmap(tmpBitmap, 0, 0, paint);
            tmpBitmap.recycle();
        }

        paint.setColor(rippleColor);

        if (rippleType == 1) {
            if ((((float) timer * frameRate) / rippleDuration) > 0.6f)
                paint.setAlpha((int) (rippleAlpha
                        - ((rippleAlpha) * (((float) timerEmpty * frameRate) / (durationEmpty)))));
            else
                paint.setAlpha(rippleAlpha);
        } else
            paint.setAlpha(
                    (int) (rippleAlpha - ((rippleAlpha) * (((float) timer * frameRate) / rippleDuration))));

        timer++;
    }
}

From source file:com.jungle.toolbaractivity.layout.HorizontalSwipeBackLayout.java

@Override
protected void dispatchDraw(Canvas canvas) {
    if (!mSwipeBackEnable) {
        super.dispatchDraw(canvas);
        return;/*from   w w w  .j ava2s.  co m*/
    }

    final int width = getMeasuredWidth();
    final int height = getMeasuredHeight();

    if (mBkgDrawable != null) {
        mBkgDrawable.setBounds((int) (mTranslationX + 0.5f), 0, width, height);
        mBkgDrawable.draw(canvas);
    } else {
        Paint paint = new Paint();
        paint.setColor(Color.WHITE);
        canvas.drawRect(mTranslationX, 0, width, height, paint);
    }

    if (mTranslationX > 0) {
        canvas.save();
        canvas.translate(mTranslationX - mShadowWidth, 0);
        mEdgeShadowDrawable.setBounds(0, 0, mShadowWidth, height);
        mEdgeShadowDrawable.draw(canvas);
        canvas.restore();
    }

    super.dispatchDraw(canvas);
}

From source file:io.github.sin3hz.fastjumper.FastJumperDecoration.java

@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDrawOver(c, parent, state);
    mDirtyBounds.setEmpty();// w  ww  .ja v a2s .co  m
    if (mState == STATE_GONE) {
        return;
    }
    c.save();
    updateBounds();
    c.clipRect(mSelfBounds);
    mThumbDrawable.setBounds(mThumbBounds);
    mThumbDrawable.draw(c);
    mLabelDrawable.setBounds(mLabelBounds);
    mLabelDrawable.draw(c);
    c.restore();
}

From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java

public void drawTrueNorthArrow(Canvas canvas, float drawnAngle) {
    trueNorthArrowPaint.reset();//w  w  w.j  av  a2  s  .c  om
    trueNorthArrowPaint.setColor(Color.RED);
    trueNorthArrowPaint.setStyle(Paint.Style.FILL);
    trueNorthArrowPaint.setAlpha(100);
    int r = Radius / 12;
    // Construct a wedge-shaped path
    mPath.reset();
    mPath.moveTo(px, py - px);
    mPath.lineTo(px - r, py);
    mPath.lineTo(px, py + r);
    mPath.lineTo(px + r, py);
    mPath.addCircle(px, py, r, Path.Direction.CCW);
    mPath.close();
    canvas.drawPath(mPath, trueNorthArrowPaint);
    dashedPaint.setColor(Color.RED);
    canvas.drawLine(px, py - px, px, py + Radius, dashedPaint);
    canvas.drawCircle(px, py, 5, dashedPaint);
    canvas.restore();
}

From source file:com.github.pedrovgs.nox.NoxView.java

/**
 * Given a List<NoxItem> instances configured previously gets the associated resource to draw the
 * view./*from   ww w.  j a va 2 s. co m*/
 */
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (noxItemCatalog == null) {
        wasInvalidatedBefore = false;
        return;
    }
    updateShapeOffset();
    for (int i = 0; i < noxItemCatalog.size(); i++) {
        if (shape.isItemInsideView(i)) {
            loadNoxItem(i);
            float left = shape.getXForItemAtPosition(i);
            float top = shape.getYForItemAtPosition(i);
            drawNoxItem(canvas, i, left, top);
        }
    }
    canvas.restore();
    wasInvalidatedBefore = false;
}

From source file:com.mukesh.OtpView.java

@Override
protected void onDraw(Canvas canvas) {
    canvas.save();
    updatePaints();
    drawOtpView(canvas);
    canvas.restore();
}

From source file:com.ssn.currency.convertor.WheelView.java

/**
 * Draws items/*from  ww w.jav  a 2 s  .  c  o m*/
 * @param canvas the canvas for drawing
 */
private void drawItems(Canvas canvas) {
    canvas.save();

    int top = (currentItem - firstItem) * getItemHeight() + (getItemHeight() - getHeight()) / 2;
    canvas.translate(PADDING, -top + scrollingOffset);

    itemsLayout.draw(canvas);

    canvas.restore();
}

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  www  .  j av  a 2s  .c  om
        canvas.restore();
    }
    return bitmap;
}