List of usage examples for android.graphics Canvas clipRect
public boolean clipRect(int left, int top, int right, int bottom)
From source file:com.ziv.recyclerview.gridview.vertical.DividerGridItemDecoration.java
/** * Draw vertical divider//from ww w .j a va 2s .co 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.ziv.recyclerview.gridview.vertical.DividerGridItemDecoration.java
/** * Draw horizontal divider//from w w w . j ava2 s .com * * @param canvas Canvas to draw into * @param parent RecyclerView this ItemDecoration is drawing into */ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void drawHorizontal(Canvas canvas, RecyclerView parent) { canvas.save(); 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.ameron32.apps.tapnotes._trial.ui.CollapsingTitleLayout.java
@Override public void draw(Canvas canvas) { final int saveCount = canvas.save(); final int toolbarHeight = mToolbar.getHeight(); canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, mScrollOffset)); // Now call super and let it draw the background, etc super.draw(canvas); if (mTitleToDraw != null) { float x = mTextLeft; float y = mTextTop; final float ascent = mTextPaint.ascent() * mScale; final float descent = mTextPaint.descent() * mScale; final float h = descent - ascent; if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mTextLeft, y - h + descent, mTextRight, y + descent, DEBUG_DRAW_PAINT); }// ww w .j a v a 2 s . c om if (mUseTexture) { y = y - h + descent; } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (mUseTexture && mExpandedTitleTexture != null) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTitleToDraw, x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:com.android.launcher3.allapps.AllAppsRecyclerView.java
@Override public void onDraw(Canvas c) { // Draw the background if (mEmptySearchBackground != null && mEmptySearchBackground.getAlpha() > 0) { c.clipRect(mBackgroundPadding.left, mBackgroundPadding.top, getWidth() - mBackgroundPadding.right, getHeight() - mBackgroundPadding.bottom); mEmptySearchBackground.draw(c);/*w ww.ja v a 2 s.c o m*/ } super.onDraw(c); }
From source file:me.lizheng.deckview.views.DeckChildViewHeader.java
@SuppressLint("DrawAllocation") @Override/*from ww w . ja v a 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:au.com.zacher.popularmovies.activity.layout.CollapsingTitleLayout.java
@Override public void draw(@NonNull Canvas canvas) { final int saveCount = canvas.save(); final int toolbarHeight = this.mToolbar.getHeight(); canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, this.mScrollOffset)); // Now call super and let it draw the background, etc super.draw(canvas); if (this.mTitleToDraw != null) { float x = this.mTextLeft; float y = this.mTextTop; final float ascent = this.mTextPaint.ascent() * this.mScale; final float descent = this.mTextPaint.descent() * this.mScale; final float h = descent - ascent; if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(this.mTextLeft, y - h + descent, this.mTextRight, y + descent, DEBUG_DRAW_PAINT); }//from w ww. j a v a2s .c o m if (this.mUseTexture) { y = y - h + descent; } if (this.mScale != 1f) { canvas.scale(this.mScale, this.mScale, x, y); } if (this.mUseTexture && this.mExpandedTitleTexture != null) { // If we should use a texture, draw it instead of text canvas.drawBitmap(this.mExpandedTitleTexture, x, y, this.mTexturePaint); } else { canvas.drawText(this.mTitleToDraw, x, y, this.mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:vc908.stickerfactory.ui.advancedrecyclerview.swipeable.RemovingItemDecorator.java
private void fillSwipingItemBackground(Canvas c, Drawable drawable, int height) { final Rect bounds = mSwipingItemBounds; final int translationX = mInitialTranslationX; final int translationY = mTranslationY; if (height < 0) { height = bounds.height();/*w w w .j a v a2 s. co m*/ } if ((height == 0) || (drawable == null)) { return; } final int savedCount = c.save(); c.clipRect(bounds.left + translationX, bounds.top + translationY, bounds.right + translationX, bounds.top + translationY + height); // c.drawColor(0xffff0000); // <-- debug c.translate(bounds.left + translationX, 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.amitupadhyay.aboutexample.ui.widget.CollapsingTitleLayout.java
@Override public void draw(Canvas canvas) { super.draw(canvas); if (lineCount == 1) { collapsingText.draw(canvas);/*from ww w .ja va 2s . c o m*/ } else { float x = titleInsetStart; float y = Math.max(textTop - scrollOffset, titleInsetTop); canvas.translate(x, y); canvas.clipRect(0, 0, getWidth() - titleInsetStart - titleInsetEnd, Math.max(getHeight() - scrollOffset, collapsedHeight) - y); layout.draw(canvas); } }
From source file:com.yanzhenjie.recyclerview.swipe.widget.StickyNestedScrollView.java
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (currentlyStickingView != null) { canvas.save();//from w w w . jav a 2 s . c o m canvas.translate(getPaddingLeft() + stickyViewLeftOffset, getScrollY() + stickyViewTopOffset + (clippingToPadding ? getPaddingTop() : 0)); canvas.clipRect(0, (clippingToPadding ? -stickyViewTopOffset : 0), getWidth() - stickyViewLeftOffset, currentlyStickingView.getHeight() + mShadowHeight + 1); if (mShadowDrawable != null) { int left = 0; int top = currentlyStickingView.getHeight(); int right = currentlyStickingView.getWidth(); int bottom = currentlyStickingView.getHeight() + mShadowHeight; mShadowDrawable.setBounds(left, top, right, bottom); mShadowDrawable.draw(canvas); } canvas.clipRect(0, (clippingToPadding ? -stickyViewTopOffset : 0), getWidth(), currentlyStickingView.getHeight()); if (getStringTagForView(currentlyStickingView).contains(FLAG_HASTRANSPARENCY)) { showView(currentlyStickingView); currentlyStickingView.draw(canvas); hideView(currentlyStickingView); } else { currentlyStickingView.draw(canvas); } 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 www .ja va 2s . 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; }