List of usage examples for android.graphics Canvas restore
public void restore()
From source file:com.by_syk.lib.nanoiconpack.widget.DividerItemDecoration.java
@SuppressLint("NewApi") private void drawVertical(Canvas canvas, RecyclerView parent) { canvas.save();/*from w w w. ja v a2 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++) { // 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.ziv.recyclerview.gridview.vertical.DividerGridItemDecoration.java
/** * Draw horizontal divider//from w w w. j av a 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 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:org.telegram.ui.Cells.HintDialogCell.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result = super.drawChild(canvas, child, drawingTime); if (child == imageView) { if (countLayout != null) { int top = AndroidUtilities.dp(6); int left = AndroidUtilities.dp(54); int x = left - AndroidUtilities.dp(5.5f); if (MessagesController.getInstance().isDialogMuted(dialog_id)) { countDrawableGrey.setBounds(x, top, x + countWidth + AndroidUtilities.dp(11), top + countDrawableGrey.getIntrinsicHeight()); countDrawableGrey.draw(canvas); } else { countDrawable.setBounds(x, top, x + countWidth + AndroidUtilities.dp(11), top + countDrawable.getIntrinsicHeight()); countDrawable.draw(canvas); }//from w w w .j a v a 2s . c o m canvas.save(); canvas.translate(left, top + AndroidUtilities.dp(4)); countLayout.draw(canvas); canvas.restore(); } } return result; }
From source file:com.mark.app.widget.recycler_view.LLMDivider.java
private void drawHorizontal(Canvas canvas, RecyclerView parent) { canvas.save();/*from w w w. ja v a2s.c o m*/ final int top; final int bottom; if (getParentClipToPadding(parent)) { 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 = 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:com.dongdong.wheel.WheelView.java
/** * Draws items// w w w . ja va 2 s . c o m * * @param canvas the canvas for drawing */ private void drawItems(Canvas canvas) { canvas.save(); int top = mItemsLayout.getLineTop(1); canvas.translate(0, -top + mScrollingOffset); mItemsPaint.setColor(ITEMS_TEXT_COLOR); mItemsPaint.drawableState = getDrawableState(); mItemsLayout.draw(canvas); canvas.restore(); }
From source file:com.mark.app.widget.recycler_view.LLMDivider.java
private void drawVertical(Canvas canvas, RecyclerView parent) { canvas.save();/*w w w . j av a 2 s. c om*/ final int left; final int right; if (getParentClipToPadding(parent)) { 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 = 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:im.vector.view.SimpleDividerItemDecoration.java
@Override public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) { if (parent.getLayoutManager() == null) { return;/*from w w w. j a v a 2s . c o m*/ } if (mOrientation == HORIZONTAL || mLeftMargin <= 0) { super.onDraw(canvas, parent, state); } else { canvas.save(); int right = parent.getWidth() - parent.getPaddingRight(); int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); View nextChild = parent.getChildAt(i + 1); if (!String.valueOf(child.getTag()).contains(NO_DIVIDER_TAG) && (nextChild != null && !String.valueOf(nextChild.getTag()).contains(NO_DIVIDER_TAG))) { RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); int top = child.getBottom() + params.bottomMargin; int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(mLeftMargin, top, right, bottom); mDivider.draw(canvas); } } canvas.restore(); } }
From source file:ca.barrenechea.widget.recyclerview.decoration.StickyHeaderDecoration.java
/** * {@inheritDoc}//from w ww .j ava 2 s .c om */ @Override public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) { final int count = parent.getChildCount(); long previousHeaderId = -1; for (int layoutPos = 0; layoutPos < count; layoutPos++) { final View child = parent.getChildAt(layoutPos); final int adapterPos = parent.getChildAdapterPosition(child); if (adapterPos != RecyclerView.NO_POSITION && hasHeader(adapterPos)) { long headerId = mAdapter.getHeaderId(adapterPos); if (headerId != previousHeaderId) { previousHeaderId = headerId; View header = getHeader(parent, adapterPos).itemView; canvas.save(); final int left = child.getLeft(); final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos); canvas.translate(left, top); header.setTranslationX(left); header.setTranslationY(top); header.draw(canvas); canvas.restore(); } } } }
From source file:com.dat.complexrecyclerviewdemo.recyclerviewinsidecardviewdemo.StickyHeaderDecoration.java
/** * {@inheritDoc}/*from w w w. java 2 s . co m*/ */ @Override public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) { final int count = parent.getChildCount(); long previousHeaderId = -1; for (int layoutPos = 0; layoutPos < count; layoutPos++) { final View child = parent.getChildAt(layoutPos); final int adapterPos = parent.getChildAdapterPosition(child); if (adapterPos != RecyclerView.NO_POSITION && hasHeader(adapterPos)) { long headerId = mAdapter.getHeaderId(adapterPos); if (headerId != previousHeaderId) { previousHeaderId = headerId; View header = getHeader(parent, adapterPos).itemView; canvas.save(); final int left = child.getLeft(); final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos); canvas.translate(left, top - 4); header.setTranslationX(left); header.setTranslationY(top); header.draw(canvas); canvas.restore(); } } } }
From source file:org.telegram.ui.Cells.ContextLinkCell.java
@Override protected void onDraw(Canvas canvas) { if (titleLayout != null) { canvas.save();//from w w w .ja v a 2 s. c o m canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), titleY); titleLayout.draw(canvas); canvas.restore(); } if (descriptionLayout != null) { descriptionTextPaint.setColor(DESCRIPTION_TEXT_COLOR/*0xff8a8a8a*/); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), descriptionY); descriptionLayout.draw(canvas); canvas.restore(); } if (linkLayout != null) { descriptionTextPaint.setColor(Theme.MSG_LINK_TEXT_COLOR); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), linkY); linkLayout.draw(canvas); canvas.restore(); } if (!mediaWebpage) { if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) { radialProgress.setProgressColor(buttonPressed ? Theme.MSG_IN_AUDIO_SELECTED_PROGRESS_COLOR : Theme.MSG_IN_AUDIO_PROGRESS_COLOR); radialProgress.draw(canvas); } else if (inlineResult != null && inlineResult.type.equals("file")) { int w = Theme.inlineDocDrawable.getIntrinsicWidth(); int h = Theme.inlineDocDrawable.getIntrinsicHeight(); int x = linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2; int y = linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2; canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + AndroidUtilities.dp(52), linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint); Theme.inlineDocDrawable.setBounds(x, y, x + w, y + h); Theme.inlineDocDrawable.draw(canvas); } else if (inlineResult != null && (inlineResult.type.equals("audio") || inlineResult.type.equals("voice"))) { int w = Theme.inlineAudioDrawable.getIntrinsicWidth(); int h = Theme.inlineAudioDrawable.getIntrinsicHeight(); int x = linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2; int y = linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2; canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + AndroidUtilities.dp(52), linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint); Theme.inlineAudioDrawable.setBounds(x, y, x + w, y + h); Theme.inlineAudioDrawable.draw(canvas); } else if (inlineResult != null && (inlineResult.type.equals("venue") || inlineResult.type.equals("geo"))) { int w = Theme.inlineLocationDrawable.getIntrinsicWidth(); int h = Theme.inlineLocationDrawable.getIntrinsicHeight(); int x = linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2; int y = linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2; canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + AndroidUtilities.dp(52), linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint); Theme.inlineLocationDrawable.setBounds(x, y, x + w, y + h); Theme.inlineLocationDrawable.draw(canvas); } else { letterDrawable.draw(canvas); } } else { if (inlineResult != null && (inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaGeo || inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue)) { int w = Theme.inlineLocationDrawable.getIntrinsicWidth(); int h = Theme.inlineLocationDrawable.getIntrinsicHeight(); int x = linkImageView.getImageX() + (linkImageView.getImageWidth() - w) / 2; int y = linkImageView.getImageY() + (linkImageView.getImageHeight() - h) / 2; canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + linkImageView.getImageWidth(), linkImageView.getImageY() + linkImageView.getImageHeight(), LetterDrawable.paint); Theme.inlineLocationDrawable.setBounds(x, y, x + w, y + h); Theme.inlineLocationDrawable.draw(canvas); } } if (drawLinkImageView) { canvas.save(); if (scaled && scale != 0.8f || !scaled && scale != 1.0f) { long newTime = System.currentTimeMillis(); long dt = (newTime - lastUpdateTime); lastUpdateTime = newTime; if (scaled && scale != 0.8f) { scale -= dt / 400.0f; if (scale < 0.8f) { scale = 0.8f; } } else { scale += dt / 400.0f; if (scale > 1.0f) { scale = 1.0f; } } invalidate(); } canvas.scale(scale, scale, getMeasuredWidth() / 2, getMeasuredHeight() / 2); linkImageView.draw(canvas); canvas.restore(); } if (mediaWebpage && (documentAttachType == DOCUMENT_ATTACH_TYPE_PHOTO || documentAttachType == DOCUMENT_ATTACH_TYPE_GIF)) { radialProgress.setProgressColor(0xffffffff); radialProgress.draw(canvas); } if (needDivider && !mediaWebpage) { if (LocaleController.isRTL) { canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, paint); } else { canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, paint); } } if (needShadow && shadowDrawable != null) { shadowDrawable.setBounds(0, 0, getMeasuredWidth(), AndroidUtilities.dp(3)); shadowDrawable.draw(canvas); } }