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.taobao.weex.ui.view.WXScrollView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    if (mCurrentStickyView != null) {
        canvas.save();/*from  w w w. j  a v a2s .c o  m*/
        mCurrentStickyView.getLocationOnScreen(mStickyP);
        int realOffset = (mStickyOffset <= 0 ? mStickyOffset : 0);
        canvas.translate(mStickyP[0], getScrollY() + realOffset);
        canvas.clipRect(0, realOffset, mCurrentStickyView.getWidth(), mCurrentStickyView.getHeight());
        mCurrentStickyView.draw(canvas);
        canvas.restore();
    }
}

From source file:android.support.v7.widget.DividerItemDecoration.java

private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();/*from   www. ja  v a2  s. c om*/
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child));
        final int top = bottom - mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}

From source file:com.by_syk.schttable.widget.DividerItemDecoration.java

@SuppressLint("NewApi")
private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();/*from www .  j a  va2  s  .c  o  m*/
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child));
        final int top = bottom - mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}

From source file:android.support.v7.widget.DividerItemDecoration.java

private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();//from   w  w w.  j a va  2  s.co  m
    final int top;
    final int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top, parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(ViewCompat.getTranslationX(child));
        final int left = right - mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}

From source file:com.by_syk.lib.nanoiconpack.widget.DividerItemDecoration.java

@SuppressLint("NewApi")
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();/*from  w w  w  .ja v a2s  .c  om*/
    final int top;
    final int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top, parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(ViewCompat.getTranslationX(child));
        final int left = right - mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}

From source file:it.ndorigatti.android.view.MulticolorProgressBar.java

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

    Drawable d = mCurrentDrawable;/*from   w w  w.j  a  va2s  .  c o  m*/
    if (d != null) {
        // Translate canvas so a indeterminate circular progress bar with padding
        // rotates properly in its animation
        canvas.save();
        canvas.translate(getPaddingLeft(), getPaddingTop());
        d.draw(canvas);
        canvas.restore();
    }
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * ?? ??//w  w w  . j  a v  a  2s . co m
 * 
 * @param src
 *            the bitmap object you want proecss
 * @param watermark
 *            the water mark above the src
 * @return return a bitmap object ,if paramter's length is 0,return null
 */
public static Bitmap createWatermarkBitmap(Bitmap src, Bitmap watermark) {
    if (src == null) {
        return null;
    }

    int w = src.getWidth();
    int h = src.getHeight();
    int ww = watermark.getWidth();
    int wh = watermark.getHeight();
    // create the new blank bitmap
    Bitmap newb = Bitmap.createBitmap(w, h, Config.ARGB_8888);// SRC?
    Canvas cv = new Canvas(newb);
    // draw src into
    cv.drawBitmap(src, 0, 0, null);//  00??src
    // draw watermark into
    cv.drawBitmap(watermark, w - ww + 5, h - wh + 5, null);// src??
    // save all clip
    cv.save(Canvas.ALL_SAVE_FLAG);// ?
    // store
    cv.restore();// 
    return newb;
}

From source file:com.example.view.wheel.WheelView.java

/**
 * Draws items//from w  ww. j  a  v a2  s  .co m
 * @param canvas the canvas for drawing
 */
private void drawItems(Canvas canvas) {
    canvas.save();

    int top = itemsLayout.getLineTop(1);
    canvas.translate(0, -top + scrollingOffset);

    itemsPaint.setColor(ITEMS_TEXT_COLOR);
    itemsPaint.drawableState = getDrawableState();
    itemsLayout.draw(canvas);

    canvas.restore();
}

From source file:com.ziv.recyclerview.gridview.vertical.DividerGridItemDecoration.java

/**
 * Draw vertical divider//  ww w  .  ja va 2  s  . c  o m
 *
 * @param canvas Canvas to draw into
 * @param parent RecyclerView this ItemDecoration is drawing into
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child));
        final int top = bottom - mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.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 ww  w . j a  v a 2  s . com
    }
    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();
}