Example usage for android.graphics Canvas CLIP_SAVE_FLAG

List of usage examples for android.graphics Canvas CLIP_SAVE_FLAG

Introduction

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

Prototype

int CLIP_SAVE_FLAG

To view the source code for android.graphics Canvas CLIP_SAVE_FLAG.

Click Source Link

Document

Restore the current clip when restore() is called.

Usage

From source file:vc908.stickerfactory.ui.advancedrecyclerview.decoration.ItemShadowDecorator.java

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    final int childCount = parent.getChildCount();

    if (childCount == 0) {
        return;/*w  w w  .  j  av  a2  s.c om*/
    }

    int savedCount = c.save(Canvas.CLIP_SAVE_FLAG);

    c.clipRect(parent.getLeft() + Math.max(0, parent.getPaddingLeft() - mShadowPadding.left),
            parent.getTop()/* + Math.max(0, parent.getPaddingTop() - mShadowPadding.top)*/,
            parent.getRight() - Math.max(0, parent.getPaddingRight() - mShadowPadding.right),
            parent.getBottom()/* - Math.max(0, parent.getPaddingBottom() - mShadowPadding.bottom)*/);

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

        if (!shouldDrawDropShadow(child)) {
            continue;
        }

        final int tx = (int) (ViewCompat.getTranslationX(child) + 0.5f);
        final int ty = (int) (ViewCompat.getTranslationY(child) + 0.5f);

        final int left = child.getLeft() - mShadowPadding.left;
        final int right = child.getRight() + mShadowPadding.right;
        final int top = child.getTop() - mShadowPadding.top;
        final int bottom = child.getBottom() + mShadowPadding.bottom;

        mShadowDrawable.setBounds(left + tx, top + ty, right + tx, bottom + ty);
        mShadowDrawable.draw(c);
    }

    c.restoreToCount(savedCount);

    ViewCompat.postInvalidateOnAnimation(parent);
}

From source file:com.example.nwilde.myfirstapp.SimpleListDividerDecorator.java

@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    final int childCount = parent.getChildCount();
    final float yPositionThreshold = (mOverlap) ? 1.0f : (mDividerHeight + 1.0f); // [px]
    final float zPositionThreshold = 1.0f; // [px]

    if (childCount == 0) {
        return;/*  w w  w .j av  a 2  s.  c o  m*/
    }

    int savedCount = c.save(Canvas.CLIP_SAVE_FLAG);

    c.clipRect(parent.getLeft() + parent.getPaddingLeft(), parent.getTop() + parent.getPaddingTop(),
            parent.getRight() - parent.getPaddingRight(), parent.getBottom() + parent.getPaddingBottom());

    for (int i = 0; i < childCount - 1; i++) {
        final View child = parent.getChildAt(i);
        final View nextChild = parent.getChildAt(i + 1);

        if ((child.getVisibility() != View.VISIBLE) || (nextChild.getVisibility() != View.VISIBLE)) {
            continue;
        }

        // check if the next item is placed at the bottom
        final float childBottom = child.getBottom() + ViewCompat.getTranslationY(child);
        final float nextChildTop = nextChild.getTop() + ViewCompat.getTranslationY(nextChild);

        if (!(Math.abs(nextChildTop - childBottom) < yPositionThreshold)) {
            continue;
        }

        // check if the next item is placed on the same plane
        final float childZ = ViewCompat.getTranslationZ(child) + ViewCompat.getElevation(child);
        final float nextChildZ = ViewCompat.getTranslationZ(nextChild) + ViewCompat.getElevation(nextChild);

        if (!(Math.abs(nextChildZ - childZ) < zPositionThreshold)) {
            continue;
        }

        final float childAlpha = ViewCompat.getAlpha(child);
        final float nextChildAlpha = ViewCompat.getAlpha(nextChild);

        final int tx = (int) (ViewCompat.getTranslationX(child) + 0.5f);
        final int ty = (int) (ViewCompat.getTranslationY(child) + 0.5f);
        final int left = child.getLeft();
        final int right = child.getRight();
        final int top = child.getBottom();
        final int bottom = top + mDividerHeight;

        mDividerDrawable.setAlpha((int) ((0.5f * 255) * (childAlpha + nextChildAlpha) + 0.5f));
        mDividerDrawable.setBounds(left + tx, top + ty, right + tx, bottom + ty);
        mDividerDrawable.draw(c);
    }

    c.restoreToCount(savedCount);
}

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();//from   www .j a va  2  s. 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: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 ww .java 2s  .  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:me.lizheng.deckview.views.DeckChildViewHeader.java

@SuppressLint("DrawAllocation")
@Override//from w ww.j a va  2 s .c o  m
protected void onDraw(Canvas canvas) {
    // Draw the highlight at the top edge (but put the bottom edge just out of view)
    float offset = (float) Math.ceil(mConfig.taskViewHighlightPx / 2f);
    float radius = mConfig.taskViewRoundedCornerRadiusPx;
    int count = canvas.save(Canvas.CLIP_SAVE_FLAG);
    canvas.clipRect(0, 0, getMeasuredWidth(), getMeasuredHeight());
    canvas.drawRoundRect(
            new RectF(-offset, 0f, (float) getMeasuredWidth() + offset, getMeasuredHeight() + radius), radius,
            radius, sHighlightPaint);
    canvas.restoreToCount(count);
}

From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java

private float drawArc(Canvas canvas, Rect bounds) {
    canvas.drawPath(mArc, mArcPaint);/* www .  ja va  2 s .  c om*/

    int minuteSinceStart = mNowMinutes - mRiseMinutes;
    int totalMinutes = mSetMinutes - mRiseMinutes;
    float pct = (minuteSinceStart / (float) totalMinutes);

    int r = bounds.right - mRightOffset;
    int l = bounds.left + mLeftOffset;

    int px = (int) (pct * (r - l));

    mClipRect.set(0, 0, l + px, bounds.bottom);
    canvas.save(Canvas.CLIP_SAVE_FLAG);
    canvas.clipRect(mClipRect);
    canvas.drawPath(mArcFill, mArcFillPaint);
    canvas.restore();

    return pct;
}

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();/*w w w . j a  v  a  2s.  c  om*/
        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:org.connectbot.TerminalView.java

@Override
public void onDraw(Canvas canvas) {
    if (bridge.bitmap != null) {
        // draw the bitmap
        bridge.onDraw();//from w w  w . j  ava 2s.  c o  m

        // draw the bridge bitmap if it exists
        canvas.drawBitmap(bridge.bitmap, 0, 0, paint);

        // also draw cursor if visible
        if (bridge.buffer.isCursorVisible()) {
            int cursorColumn = bridge.buffer.getCursorColumn();
            final int cursorRow = bridge.buffer.getCursorRow();

            final int columns = bridge.buffer.getColumns();

            if (cursorColumn == columns)
                cursorColumn = columns - 1;

            if (cursorColumn < 0 || cursorRow < 0)
                return;

            int currentAttribute = bridge.buffer.getAttributes(cursorColumn, cursorRow);
            boolean onWideCharacter = (currentAttribute & VDUBuffer.FULLWIDTH) != 0;

            int x = cursorColumn * bridge.charWidth;
            int y = (bridge.buffer.getCursorRow() + bridge.buffer.screenBase - bridge.buffer.windowBase)
                    * bridge.charHeight;

            // Save the current clip and translation
            canvas.save();

            canvas.translate(x, y);
            canvas.clipRect(0, 0, bridge.charWidth * (onWideCharacter ? 2 : 1), bridge.charHeight);
            canvas.drawPaint(cursorPaint);

            final int deadKey = bridge.getKeyHandler().getDeadKey();
            if (deadKey != 0) {
                canvas.drawText(new char[] { (char) deadKey }, 0, 1, 0, 0, cursorStrokePaint);
            }

            // Make sure we scale our decorations to the correct size.
            canvas.concat(scaleMatrix);

            int metaState = bridge.getKeyHandler().getMetaState();

            if ((metaState & TerminalKeyListener.OUR_SHIFT_ON) != 0)
                canvas.drawPath(shiftCursor, cursorStrokePaint);
            else if ((metaState & TerminalKeyListener.OUR_SHIFT_LOCK) != 0)
                canvas.drawPath(shiftCursor, cursorPaint);

            if ((metaState & TerminalKeyListener.OUR_ALT_ON) != 0)
                canvas.drawPath(altCursor, cursorStrokePaint);
            else if ((metaState & TerminalKeyListener.OUR_ALT_LOCK) != 0)
                canvas.drawPath(altCursor, cursorPaint);

            if ((metaState & TerminalKeyListener.OUR_CTRL_ON) != 0)
                canvas.drawPath(ctrlCursor, cursorStrokePaint);
            else if ((metaState & TerminalKeyListener.OUR_CTRL_LOCK) != 0)
                canvas.drawPath(ctrlCursor, cursorPaint);

            // Restore previous clip region
            canvas.restore();
        }

        // draw any highlighted area
        if (bridge.isSelectingForCopy()) {
            SelectionArea area = bridge.getSelectionArea();
            canvas.save(Canvas.CLIP_SAVE_FLAG);
            canvas.clipRect(area.getLeft() * bridge.charWidth, area.getTop() * bridge.charHeight,
                    (area.getRight() + 1) * bridge.charWidth, (area.getBottom() + 1) * bridge.charHeight);
            canvas.drawPaint(cursorPaint);
            canvas.restore();
        }
    }
}

From source file:com.github.shareme.gwsmaterialuikit.library.advancerv.draggable.DraggingItemDecorator.java

private Bitmap createDraggingItemImage(View v, NinePatchDrawable shadow) {
    int width = v.getWidth() + mShadowPadding.left + mShadowPadding.right;
    int height = v.getHeight() + mShadowPadding.top + mShadowPadding.bottom;

    final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    final Canvas canvas = new Canvas(bitmap);

    if (shadow != null) {
        shadow.setBounds(0, 0, width, height);
        shadow.draw(canvas);//from  w  ww  .  j a  v  a2 s. c  om
    }

    final int savedCount = canvas.save(Canvas.CLIP_SAVE_FLAG | Canvas.MATRIX_SAVE_FLAG);
    // NOTE: Explicitly set clipping rect. This is required on Gingerbread.
    canvas.clipRect(mShadowPadding.left, mShadowPadding.top, width - mShadowPadding.right,
            height - mShadowPadding.bottom);
    canvas.translate(mShadowPadding.left, mShadowPadding.top);
    v.draw(canvas);
    canvas.restoreToCount(savedCount);

    return bitmap;
}

From source file:uk.ac.kent.jb509.shopper.utils.SlidingUpPanelLayout.java

@Override
protected boolean drawChild(final Canvas canvas, final View child, final long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    boolean drawScrim = false;

    if (mCanSlide && !lp.slideable && mSlideableView != null) {
        // Clip against the slider; no sense drawing what will immediately
        // be covered.
        canvas.getClipBounds(mTmpRect);/*ww w. j ava  2  s . c o  m*/
        mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());

        if (!mIsTransparent) {
            canvas.clipRect(mTmpRect);
        }

        if (mSlideOffset < 1) {
            drawScrim = true;
        }
    }

    result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(save);

    if (drawScrim) {
        final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24;
        final int imag = (int) (baseAlpha * (1 - mSlideOffset));
        final int color = imag << 24 | mCoveredFadeColor & 0xffffff;
        mCoveredFadePaint.setColor(color);
        canvas.drawRect(mTmpRect, mCoveredFadePaint);
    }

    return result;
}