Example usage for android.graphics Canvas save

List of usage examples for android.graphics Canvas save

Introduction

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

Prototype

public int save() 

Source Link

Document

Saves the current matrix and clip onto a private stack.

Usage

From source file:com.mobility.android.ui.widget.MaterialProgressDrawable.java

@Override
public void draw(@NonNull Canvas c) {
    Rect bounds = getBounds();//w  w w.  jav  a  2 s  .c  o m
    int saveCount = c.save();
    c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
    mRing.draw(c, bounds);
    c.restoreToCount(saveCount);
}

From source file:org.wikipedia.page.shareafact.SnippetImage.java

private static void drawTitle(@NonNull Canvas canvas, @NonNull String title, int top, boolean isArticleRTL) {
    final int marginBottom = 0;
    final int maxHeight = 70;
    final int maxLines = 2;
    final float maxFontSize = 30.0f;
    final float spacingMultiplier = 0.7f;

    TextPaint textPaint = new TextPaint();
    textPaint.setAntiAlias(true);//from  www.j  a  v  a  2 s.c  o  m
    textPaint.setColor(Color.WHITE);
    textPaint.setTextSize(maxFontSize);
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setTypeface(SERIF);
    textPaint.setShadowLayer(1.0f, 0.0f, 1.0f, Color.GRAY);

    StaticLayout textLayout = optimizeTextSize(
            new TextLayoutParams(title, textPaint, DESCRIPTION_WIDTH, spacingMultiplier), maxHeight, maxLines,
            maxFontSize, maxFontSize);
    int left = HORIZONTAL_PADDING;
    if (isArticleRTL) {
        left = WIDTH - HORIZONTAL_PADDING - textLayout.getWidth();
    }
    int marginBottomTotal = marginBottom;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        // versions < 5.0 don't compensate for bottom margin correctly when line
        // spacing is less than 1.0, so we'll compensate ourselves
        final int marginBoost = 10;
        marginBottomTotal += marginBoost;
    }

    top = top - marginBottomTotal - textLayout.getHeight();
    canvas.save();
    canvas.translate(left, top);
    textLayout.draw(canvas);
    canvas.restore();
}

From source file:com.achep.acdisplay.ui.widgets.CircleView.java

private void drawCornerIcon(@NonNull Canvas canvas, @NonNull Drawable drawable, int xm, int ym) {
    int width = getMeasuredWidth() - drawable.getBounds().width();
    int height = getMeasuredHeight() - drawable.getBounds().height();
    float margin = (1 - 2 * xm) * mCornerMargin;
    // Draw//  w w w .j  av  a2  s .c  o  m
    canvas.save();
    canvas.translate(xm * width + margin, ym * height + margin);
    drawable.draw(canvas);
    canvas.restore();
}

From source file:com.hgdendi.contactslist.common.FloatingBarItemDecoration.java

@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDrawOver(c, parent, state);
    final int position = ((LinearLayoutManager) parent.getLayoutManager()).findFirstVisibleItemPosition();
    if (position == RecyclerView.NO_POSITION) {
        return;/*from  w  w w  .j av  a 2 s .c o  m*/
    }
    View child = parent.findViewHolderForAdapterPosition(position).itemView;
    String initial = getTag(position);
    if (initial == null) {
        return;
    }

    boolean flag = false;
    if (getTag(position + 1) != null && !initial.equals(getTag(position + 1))) {
        if (child.getHeight() + child.getTop() < mTitleHeight) {
            c.save();
            flag = true;
            c.translate(0, child.getHeight() + child.getTop() - mTitleHeight);
        }
    }

    c.drawRect(parent.getPaddingLeft(), parent.getPaddingTop(), parent.getRight() - parent.getPaddingRight(),
            parent.getPaddingTop() + mTitleHeight, mBackgroundPaint);
    c.drawText(initial, child.getPaddingLeft() + mTextStartMargin,
            parent.getPaddingTop() + mTitleHeight - (mTitleHeight - mTextHeight) / 2 - mTextBaselineOffset,
            mTextPaint);

    if (flag) {
        c.restore();
    }
}

From source file:com.bobomee.android.gank.io.widget.CompactTabLayout.java

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    if (tabCount == 0) {
        return;/*from  w w  w . j  a  v  a2 s. co m*/
    }
    if (lastTabCount != tabCount) {
        measureTabWidths();
        lastTabCount = tabCount;
    }
    int offset = 0;
    for (int i = 0; i < selectedPosition; i++) {
        offset += tabWidths[i];
    }
    int tabWidth = tabWidths[selectedPosition];
    int indicatorWidth = tabWidth / 5;
    canvas.translate(offset, 0); //  N  tab 
    canvas.translate(indicatorLeftOffset * tabWidth, 0); //  N  tab ????
    canvas.save();
    canvas.translate(0, height - INDICATOR_HEIGHT); // ?
    int halfHoverWidth = tabWidth / 2 - indicatorWidth / 2;
    canvas.drawRect(-2, 0, halfHoverWidth, INDICATOR_HEIGHT + 9, hoverPaint);
    canvas.translate((tabWidth / 2 + indicatorWidth / 2), 0);
    canvas.drawRect(0, 0, halfHoverWidth * 2, INDICATOR_HEIGHT + 9, hoverPaint);
    canvas.restore();
}

From source file:com.dm.xz.views.PinnedSectionListView.java

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

    if (mPinnedSection != null) {

        // prepare variables
        int pLeft = getListPaddingLeft();
        int pTop = getListPaddingTop();
        View view = mPinnedSection.view;

        // draw child
        canvas.save();

        int clipHeight = view.getHeight()
                + (mShadowDrawable == null ? 0 : Math.min(mShadowHeight, mSectionsDistanceY));
        canvas.clipRect(pLeft, pTop, pLeft + view.getWidth(), pTop + clipHeight);

        canvas.translate(pLeft, pTop + mTranslateY);
        drawChild(canvas, mPinnedSection.view, getDrawingTime());

        if (mShadowDrawable != null && mSectionsDistanceY > 0) {
            mShadowDrawable.setBounds(mPinnedSection.view.getLeft(), mPinnedSection.view.getBottom(),
                    mPinnedSection.view.getRight(), mPinnedSection.view.getBottom() + mShadowHeight);
            mShadowDrawable.draw(canvas);
        }/*from  w w w.java 2s  . co  m*/

        canvas.restore();
    }
}

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();/*from w  w w  .jav  a2s . c o 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.xfzbd.cqi.widget.srl.ShyaringanProgressDrawable.java

@Override
public void draw(Canvas c) {
    final Rect bounds = getBounds();
    final int saveCount = c.save();
    c.rotate(0f, bounds.exactCenterX(), bounds.exactCenterY());
    mRing.draw(c, bounds);//from  w ww .  jav  a  2s  .  com
    c.restoreToCount(saveCount);
}

From source file:cn.spinsoft.wdq.widget.swipe.MaterialProgressDrawable.java

@Override
public void draw(Canvas c) {
    final Rect bounds = getBounds();
    final int saveCount = c.save();
    c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
    mRing.draw(c, bounds);//w ww  .  j  a va2s  . c  o m
    c.restoreToCount(saveCount);
}

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

@Override
protected void dispatchDraw(Canvas canvas) {
    if (!mSwipeBackEnable) {
        super.dispatchDraw(canvas);
        return;/* w w  w .  ja  va2 s.c  o 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);
}