List of usage examples for android.graphics Canvas save
public int save()
From source file:com.arbo.gaogao.widget.MyParallaxScrimageView.java
@Override protected void onDraw(Canvas canvas) { if (imageOffset != 0) { canvas.save(); 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();/*from w w w .j a va 2 s .c o m*/ } else { super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); } }
From source file:com.by_syk.lib.nanoiconpack.widget.DividerItemDecoration.java
@SuppressLint("NewApi") private void drawVertical(Canvas canvas, RecyclerView parent) { canvas.save(); final int left; final int right; if (parent.getClipToPadding()) { left = parent.getPaddingLeft();/*from w w w. j a v a2s . c o m*/ 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++) { // Remove the last divider // @By_syk for (int i = 0; i < childCount - 1; 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.lovejjfg.zhifou.ui.widget.ParallaxScrimageView.java
@Override protected void onDraw(Canvas canvas) { if (imageOffset != 0) { canvas.save(); 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();// w w w .j a v a2 s. co m } else { super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); } }
From source file:com.tr4android.support.extension.widget.CollapsingDrawableHelper.java
public void draw(Canvas canvas) { final int saveCount = canvas.save(); if (mDrawable != null && mDrawIcon) { // Let the drawable draw to the canvas (bounds are already set) mDrawable.draw(canvas);//from w ww . ja v a2 s. c o m } canvas.restoreToCount(saveCount); }
From source file:org.wikipedia.page.shareafact.SnippetImage.java
@NonNull private static Layout drawTextSnippet(@NonNull Canvas canvas, @NonNull CharSequence textSnippet) { final int top = TOP_PADDING; final int maxHeight = 225; final int maxLines = 5; final float maxFontSize = 195.0f; final float minFontSize = 32.0f; TextPaint textPaint = new TextPaint(); textPaint.setAntiAlias(true);/*from ww w .j av a 2s . c om*/ textPaint.setColor(Color.WHITE); textPaint.setTextSize(maxFontSize); textPaint.setStyle(Paint.Style.FILL); textPaint.setTypeface(Typeface.DEFAULT_BOLD); textPaint.setShadowLayer(1.0f, 1.0f, 1.0f, Color.GRAY); StaticLayout textLayout = optimizeTextSize( new TextLayoutParams(textSnippet, textPaint, TEXT_WIDTH, SPACING_MULTIPLIER), maxHeight, maxLines, maxFontSize, minFontSize); canvas.save(); int horizontalCenterOffset = top + (maxHeight - textLayout.getHeight()) / QUARTER; canvas.translate(HORIZONTAL_PADDING, horizontalCenterOffset); textLayout.draw(canvas); canvas.restore(); return textLayout; }
From source file:com.mark.app.widget.recycler_view.LLMDivider.java
private void drawVertical(Canvas canvas, RecyclerView parent) { canvas.save(); final int left; final int right; if (getParentClipToPadding(parent)) { left = parent.getPaddingLeft();/* w ww . ja v a 2s.c om*/ right = parent.getWidth() - parent.getPaddingRight(); canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom()); } else { left = 0; right = parent.getWidth(); } // ??? final int childCount = mEnableLastItemDivider ? parent.getChildCount() : parent.getChildCount() - 1; for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); parent.getLayoutManager().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.mark.app.widget.recycler_view.LLMDivider.java
private void drawHorizontal(Canvas canvas, RecyclerView parent) { canvas.save(); final int top; final int bottom; if (getParentClipToPadding(parent)) { top = parent.getPaddingTop();//w w w .j a v a2 s.c o m bottom = parent.getHeight() - parent.getPaddingBottom(); canvas.clipRect(parent.getPaddingLeft(), top, parent.getWidth() - parent.getPaddingRight(), bottom); } else { top = 0; bottom = parent.getHeight(); } // ??? final int childCount = mEnableLastItemDivider ? parent.getChildCount() : parent.getChildCount() - 1; 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:org.telegram.ui.Cells.AboutLinkCell.java
@Override protected void onDraw(Canvas canvas) { canvas.save(); canvas.translate(textX = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 71), textY = AndroidUtilities.dp(8)); if (pressedLink != null) { canvas.drawPath(urlPath, urlPaint); }//from w ww. jav a2 s .c o m try { if (textLayout != null) { textLayout.draw(canvas); } } catch (Exception e) { FileLog.e("tmessages", e); } canvas.restore(); }
From source file:com.example.zhangyangjing.roundcornerimageview.BezelImageView.java
@Override protected void onDraw(Canvas canvas) { if (mBounds == null) { return;//from ww w. j a v a2 s . c o m } int width = mBounds.width(); int height = mBounds.height(); if (width == 0 || height == 0) { return; } if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) { // Need to redraw the cache if (width == mCachedWidth && height == mCachedHeight) { // Have a correct-sized bitmap cache already allocated. Just erase it. mCacheBitmap.eraseColor(0); } else { // Allocate a new bitmap with the correct dimensions. mCacheBitmap.recycle(); //noinspection AndroidLintDrawAllocation mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); mCachedWidth = width; mCachedHeight = height; generateMaskPath(mCachedWidth, mCachedHeight); } Canvas cacheCanvas = new Canvas(mCacheBitmap); int sc = cacheCanvas.save(); mDesaturatePaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null); cacheCanvas.saveLayer(mBoundsF, mDesaturatePaint, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG); super.onDraw(cacheCanvas); cacheCanvas.drawPath(this.mMaskedPath, this.mMaskedPaint); cacheCanvas.restoreToCount(sc); } // Draw from cache canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null); }
From source file:com.sinenco.sharednews.listviewremovalanimation.BackgroundContainer.java
@Override protected void onDraw(Canvas canvas) { if (mShowing) { if (mUpdateBounds) { mShadowedBackground.setBounds(0, 0, getWidth(), mOpenAreaHeight); }/* ww w. j ava 2 s . co m*/ canvas.save(); canvas.translate(0, mOpenAreaTop); mShadowedBackground.draw(canvas); canvas.restore(); } }