List of usage examples for android.graphics Canvas clipRect
public boolean clipRect(int left, int top, int right, int bottom)
From source file:Main.java
/** All dimensions are in pixels */ private static Bitmap createColorSwatchBitmap(int widthPixels, int heightPixels, int borderWidthPixels, int fillColor, int borderColor) { final Bitmap bitmap = Bitmap.createBitmap(widthPixels, heightPixels, Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); if (borderWidthPixels > 0) { canvas.drawColor(borderColor);//from w w w . j a v a 2 s . c om canvas.clipRect(borderWidthPixels, borderWidthPixels, widthPixels - borderWidthPixels, heightPixels - borderWidthPixels); } canvas.drawColor(fillColor); return bitmap; }
From source file:app.philm.in.view.BackdropImageView.java
@Override protected void onDraw(Canvas canvas) { if (mOffset != 0) { canvas.save();//from w ww . j ava 2 s.c om canvas.translate(0f, mOffset); canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + mOffset); super.onDraw(canvas); canvas.restore(); } else { super.onDraw(canvas); } }
From source file:com.arbo.gaogao.widget.MyParallaxScrimageView.java
@Override protected void onDraw(Canvas canvas) { if (imageOffset != 0) { canvas.save();/*from w w w.j a v a 2 s .co m*/ canvas.translate(0f, imageOffset); canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + imageOffset); super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); canvas.restore(); } else { super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); } }
From source file:com.ahamed.sample.common.decorator.ArticleItemDecorator.java
@SuppressLint("NewApi") private void draw(Canvas canvas, RecyclerView parent, View child) { canvas.save();/*from w w w . j ava 2 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(); } parent.getDecoratedBoundsWithMargins(child, mBounds); final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child)); final int top = bottom - 16; canvas.drawRect(left, top, right, bottom, myPaint); canvas.restore(); }
From source file:com.lovejjfg.zhifou.ui.widget.ParallaxScrimageView.java
@Override protected void onDraw(Canvas canvas) { if (imageOffset != 0) { canvas.save();/*www . j av a 2 s . c o m*/ canvas.translate(0f, imageOffset); Log.i("imageOffset", "onDraw: " + imageOffset); canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + imageOffset); super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); canvas.restore(); } else { super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); } }
From source file:com.ahamed.sample.common.decorator.ThickItemDecorator.java
@SuppressLint("NewApi") private void drawVertical(Canvas canvas, RecyclerView parent, View child) { canvas.save();//from w ww . ja va 2 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(); } parent.getDecoratedBoundsWithMargins(child, mBounds); final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child)); final int top = bottom - mDivider.getIntrinsicHeight() * 4; mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); canvas.restore(); }
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;//from w ww .jav a 2s. co m } 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.ahamed.multiviewadapter.util.SimpleDividerDecoration.java
@SuppressLint("NewApi") private void drawVertical(Canvas canvas, RecyclerView parent, View child) { canvas.save();/*from w ww . j av a 2 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(); } 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.ahamed.multiviewadapter.util.SimpleDividerDecoration.java
@SuppressLint("NewApi") private void drawHorizontal(Canvas canvas, RecyclerView parent, View child) { canvas.save();//from w w w . j a v a2s.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(); } 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:android.support.v7.widget.DividerItemDecoration.java
private void drawVertical(Canvas canvas, RecyclerView parent) { canvas.save();/* w ww . ja va2s. 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(); }