Example usage for android.graphics Canvas restoreToCount

List of usage examples for android.graphics Canvas restoreToCount

Introduction

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

Prototype

public void restoreToCount(int saveCount) 

Source Link

Document

Efficient way to pop any calls to save() that happened after the save count reached saveCount.

Usage

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 av a  2 s.  co 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:io.palaima.debugdrawer.view.ScrimInsetsFrameLayout.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);

    int width = getWidth();
    int height = getHeight();
    if (insets != null && insetForeground != null) {
        int sc = canvas.save();
        canvas.translate(getScrollX(), getScrollY());

        // Top/*w ww .j a v a2s  .c om*/
        tempRect.set(0, 0, width, insets.top);
        insetForeground.setBounds(tempRect);
        insetForeground.draw(canvas);

        // Bottom
        tempRect.set(0, height - insets.bottom, width, height);
        insetForeground.setBounds(tempRect);
        insetForeground.draw(canvas);

        // Left
        tempRect.set(0, insets.top, insets.left, height - insets.bottom);
        insetForeground.setBounds(tempRect);
        insetForeground.draw(canvas);

        // Right
        tempRect.set(width - insets.right, insets.top, width, height - insets.bottom);
        insetForeground.setBounds(tempRect);
        insetForeground.draw(canvas);

        canvas.restoreToCount(sc);
    }
}

From source file:android.support.design.internal.ScrimInsetsFrameLayout.java

@Override
public void draw(@NonNull Canvas canvas) {
    super.draw(canvas);

    int width = getWidth();
    int height = getHeight();
    if (mInsets != null && mInsetForeground != null) {
        int sc = canvas.save();
        canvas.translate(getScrollX(), getScrollY());

        // Top/* w  ww . j  av a2  s.c  o  m*/
        mTempRect.set(0, 0, width, mInsets.top);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Bottom
        mTempRect.set(0, height - mInsets.bottom, width, height);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Left
        mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Right
        mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        canvas.restoreToCount(sc);
    }
}

From source file:ar.worq.microturistas.view.ScrimInsetsFrameLayout.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);

    int width = getWidth();
    int height = getHeight();
    if (mInsets != null && mInsetForeground != null) {
        int sc = canvas.save();
        canvas.translate(getScrollX(), getScrollY());

        // Top//from  www.jav  a2 s.  c om
        mTempRect.set(0, 0, width, mInsets.top);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Bottom
        mTempRect.set(0, height - mInsets.bottom, width, height);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Left
        mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Right
        mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        canvas.restoreToCount(sc);
    }
}

From source file:com.appeaser.sublimenavigationviewlibrary.ScrimInsetsFrameLayout.java

public void draw(@NonNull Canvas canvas) {
    super.draw(canvas);
    int width = this.getWidth();
    int height = this.getHeight();
    if (mInsets != null && mInsetForeground != null) {
        int sc = canvas.save();
        canvas.translate(getScrollX(), getScrollY());

        this.mTempRect.set(0, 0, width, this.mInsets.top);
        this.mInsetForeground.setBounds(this.mTempRect);
        this.mInsetForeground.draw(canvas);

        this.mTempRect.set(0, height - this.mInsets.bottom, width, height);
        this.mInsetForeground.setBounds(this.mTempRect);
        this.mInsetForeground.draw(canvas);

        this.mTempRect.set(0, this.mInsets.top, this.mInsets.left, height - this.mInsets.bottom);
        this.mInsetForeground.setBounds(this.mTempRect);
        this.mInsetForeground.draw(canvas);

        this.mTempRect.set(width - this.mInsets.right, this.mInsets.top, width, height - this.mInsets.bottom);
        this.mInsetForeground.setBounds(this.mTempRect);
        this.mInsetForeground.draw(canvas);

        canvas.restoreToCount(sc);
    }/* www.ja v  a2 s . co  m*/
}

From source file:com.example.carlitos.swipeitemrecycler.view.animation.swipe_item.swipeable.RemovingItemDecorator.java

private void fillSwipingItemBackground(Canvas c, Drawable drawable, float scale) {
    final Rect bounds = mSwipingItemBounds;
    final int translationX = mTranslationX;
    final int translationY = mTranslationY;
    final float hScale = (mHorizontal) ? 1.0f : scale;
    final float vScale = (mHorizontal) ? scale : 1.0f;

    int width = (int) (hScale * bounds.width() + 0.5f);
    int height = (int) (vScale * bounds.height() + 0.5f);

    if ((height == 0) || (width == 0) || (drawable == null)) {
        return;/*from  ww  w.j a v  a  2  s . c  o m*/
    }

    final int savedCount = c.save();

    c.clipRect(bounds.left + translationX, bounds.top + translationY, bounds.left + translationX + width,
            bounds.top + translationY + height);

    // c.drawColor(0xffff0000); // <-- debug

    c.translate(bounds.left + translationX - (bounds.width() - width) / 2,
            bounds.top + translationY - (bounds.height() - height) / 2);
    drawable.setBounds(0, 0, bounds.width(), bounds.height());

    drawable.draw(c);

    c.restoreToCount(savedCount);
}

From source file:com.evilduck.piano.views.instrument.PianoView.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    boolean needsInvalidate = false;

    final int overScrollMode = ViewCompat.getOverScrollMode(this);
    if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS
            || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS)) {
        if (!leftEdgeEffect.isFinished()) {
            final int restoreCount = canvas.save();
            final int height = getHeight() - getPaddingTop() - getPaddingBottom();
            final int width = getWidth();

            canvas.rotate(270);/*  w w  w.ja  v a2 s. c om*/
            canvas.translate(-height + getPaddingTop(), 0);
            leftEdgeEffect.setSize(height, width);
            needsInvalidate |= leftEdgeEffect.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
        if (!rightEdgeEffect.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = getWidth();
            final int height = getHeight() - getPaddingTop() - getPaddingBottom();

            canvas.rotate(90);
            canvas.translate(-getPaddingTop(), -width);
            rightEdgeEffect.setSize(height, width);
            needsInvalidate |= rightEdgeEffect.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
    } else {
        leftEdgeEffect.finish();
        rightEdgeEffect.finish();
    }

    if (needsInvalidate) {
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

From source file:com.android.photos.views.GalleryThumbnailView.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);

    if (!mLeftEdge.isFinished()) {
        final int restoreCount = canvas.save();
        final int height = getHeight() - getPaddingTop() - getPaddingBottom();

        canvas.rotate(270);//from  www.j a va  2s  . c  om
        canvas.translate(-height + getPaddingTop(), 0);
        mLeftEdge.setSize(height, getWidth());
        if (mLeftEdge.draw(canvas)) {
            postInvalidateOnAnimation();
        }
        canvas.restoreToCount(restoreCount);
    }
    if (!mRightEdge.isFinished()) {
        final int restoreCount = canvas.save();
        final int width = getWidth();
        final int height = getHeight() - getPaddingTop() - getPaddingBottom();

        canvas.rotate(90);
        canvas.translate(-getPaddingTop(), width);
        mRightEdge.setSize(height, width);
        if (mRightEdge.draw(canvas)) {
            postInvalidateOnAnimation();
        }
        canvas.restoreToCount(restoreCount);
    }
}

From source file:com.justplay1.shoppist.features.search.widget.internal.SuggestionItemDecorator.java

@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    int visibleCount = parent.getChildCount();
    int count = state.getItemCount();
    RecyclerView.Adapter adapter = parent.getAdapter();
    int adapterCount = adapter != null ? adapter.getItemCount() : 0;

    for (int i = 0; i < visibleCount; i++) {
        View view = parent.getChildAt(i);
        int position = parent.getChildAdapterPosition(view);
        float translationX = ViewCompat.getTranslationX(view);
        float translationY = ViewCompat.getTranslationY(view);
        float alpha = ViewCompat.getAlpha(view);
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();

        int shadows = LEFT | RIGHT;
        if (position == count - 1 && adapterCount != 0)
            shadows |= BOTTOM;/*w  w w . ja va 2 s  .c  om*/

        drawable.setAlpha((int) (255 * alpha));
        drawable.setShadow(shadows);
        drawable.setBounds(0, 0, parent.getWidth(), view.getHeight());
        int saved = canvas.save();
        canvas.translate(parent.getPaddingLeft() + translationX,
                view.getTop() + params.topMargin + translationY);
        drawable.draw(canvas);
        canvas.restoreToCount(saved);
    }
}

From source file:com.simplecity.amp_library.ui.views.ScrimInsetsFrameLayout.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);

    //Don't do anything special if we're not allowed to tint the status bar
    if (!ShuttleUtils.hasKitKat()) {
        return;//from   www. j a v  a 2s  . c o m
    }

    int width = getWidth();
    int height = getHeight();
    if (mInsets != null && mInsetForeground != null) {
        int sc = canvas.save();
        canvas.translate(getScrollX(), getScrollY());

        // Top
        mTempRect.set(0, 0, width, mInsets.top);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Bottom
        mTempRect.set(0, height - mInsets.bottom, width, height);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Left
        mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Right
        mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        canvas.restoreToCount(sc);
    }
}