List of usage examples for android.graphics Canvas restore
public void restore()
From source file:com.ickphum.android.isoview.IsoCanvas.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.translate(-mOriginX, -mOriginY); for (int x = 0; x < 100; x++) { for (int y = 0; y < 100; y++) { canvas.save();/*from w w w . j av a 2s . c o m*/ canvas.translate(-x * 7, -y * 7); canvas.drawPath(mPaths[0], mPaints[0]); //canvas.drawRect(0.0f, 0.0f, 5.0f, 5.0f, mPaints[0]); canvas.restore(); } } canvas.drawLine(mContentRect.left, mContentRect.top, mContentRect.right, mContentRect.bottom, mBackgroundLinePaint); canvas.drawLine(mContentRect.left, mContentRect.bottom, mContentRect.right, mContentRect.top, mBackgroundLinePaint); for (int x = -1000; x < 1000; x += 200) { for (int y = -1000; y < 1000; y += 200) { canvas.drawText(x + "," + y, x, y, mBackgroundLinePaint); } } }
From source file:com.yanzhenjie.durban.view.OverlayView.java
/** * This method draws dimmed area around the crop bounds. * * @param canvas - valid canvas object// ww w . j a v a 2 s. c om */ protected void drawDimmedLayer(@NonNull Canvas canvas) { canvas.save(); if (mCircleDimmedLayer) canvas.clipPath(mCircularPath, Region.Op.DIFFERENCE); else canvas.clipRect(mCropViewRect, Region.Op.DIFFERENCE); canvas.drawColor(mDimmedColor); canvas.restore(); if (mCircleDimmedLayer) { // Draw 1px stroke to fix antialias canvas.drawCircle(mCropViewRect.centerX(), mCropViewRect.centerY(), Math.min(mCropViewRect.width(), mCropViewRect.height()) / 2.f, mDimmedStrokePaint); } }
From source file:com.example.waitou.rxjava.LoadingView.java
@Override protected void onDraw(Canvas canvas) { if (!mIsAnimatorCancel) { final Rect bounds = getBounds(); final int saveCount = canvas.save(); canvas.rotate(mRotation * 360, bounds.exactCenterX(), bounds.exactCenterY()); drawRing(canvas, bounds);/*from w w w . j a v a 2s . c o m*/ canvas.restoreToCount(saveCount); } else { canvas.restore(); } }
From source file:org.telegram.ui.Cells.SharedLinkCell.java
@Override protected void onDraw(Canvas canvas) { if (titleLayout != null) { canvas.save();/*ww w. j a 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(TEXT_COLOR); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), descriptionY); descriptionLayout.draw(canvas); canvas.restore(); } if (descriptionLayout2 != null) { descriptionTextPaint.setColor(TEXT_COLOR); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), description2Y); descriptionLayout2.draw(canvas); canvas.restore(); } if (!linkLayout.isEmpty()) { descriptionTextPaint.setColor(Theme.MSG_LINK_TEXT_COLOR); int offset = 0; for (int a = 0; a < linkLayout.size(); a++) { StaticLayout layout = linkLayout.get(a); if (layout.getLineCount() > 0) { canvas.save(); canvas.translate( AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), linkY + offset); if (pressedLink == a) { canvas.drawPath(urlPath, urlPaint); } layout.draw(canvas); canvas.restore(); offset += layout.getLineBottom(layout.getLineCount() - 1); } } } letterDrawable.draw(canvas); if (drawLinkImageView) { linkImageView.draw(canvas); } if (needDivider) { 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); } } }
From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java
public void drawQibla(Canvas canvas) { canvas.rotate((float) qiblaInfo.getHeading() - 360, px, py); qiblaPaint.reset();/*from w ww .j a v a 2 s.co m*/ qiblaPaint.setColor(Color.GREEN); qiblaPaint.setStyle(Paint.Style.FILL_AND_STROKE); qiblaPaint.setPathEffect(dashPath); qiblaPaint.setStrokeWidth(5.5f); canvas.drawLine(px, py - Radius, px, py + Radius, qiblaPaint); qiblaPaint.setPathEffect(null); canvas.drawBitmap(kaaba, px - kaaba.getWidth() / 2, py - Radius - kaaba.getHeight() / 2, qiblaPaint); canvas.restore(); }
From source file:com.beijing.fun.view.refreshLayout.BGAStickinessRefreshView.java
@Override public void onDraw(Canvas canvas) { super.onDraw(canvas); mPath.reset();//from w w w . jav a 2 s .com mTopBound.round(mRotateDrawableBound); mRotateDrawable.setBounds(mRotateDrawableBound); if (mIsRotating) { mPath.addOval(mTopBound, Path.Direction.CW); canvas.drawPath(mPath, mPaint); canvas.save(); canvas.rotate(mCurrentDegree, mRotateDrawable.getBounds().centerX(), mRotateDrawable.getBounds().centerY()); mRotateDrawable.draw(canvas); canvas.restore(); } else { // drawable mPath.moveTo(mTopBound.left, mTopBound.top + mTopSize / 2); // drawable? mPath.arcTo(mTopBound, 180, 180); // ? // mPath.quadTo(mTopBound.right - mTopSize / 8, mTopBound.bottom, mBottomBound.right, mBottomBound.bottom - mBottomBound.height() / 2); // mCurrentBottomHeight 0 mMaxBottomHeight // scale 0.2 1 float scale = Math.max(mCurrentBottomHeight * 1.0f / mMaxBottomHeight, 0.2f); float bottomControlXOffset = mTopSize * ((3 + (float) Math.pow(scale, 7) * 16) / 32); float bottomControlY = mTopBound.bottom / 2 + mCenterPoint.y / 2; // ??? mPath.cubicTo(mTopBound.right - mTopSize / 8, mTopBound.bottom, mTopBound.right - bottomControlXOffset, bottomControlY, mBottomBound.right, mBottomBound.bottom - mBottomBound.height() / 2); mPath.arcTo(mBottomBound, 0, 180); // mPath.quadTo(mTopBound.left + mTopSize / 8, mTopBound.bottom, mTopBound.left, mTopBound.bottom - mTopSize / 2); mPath.cubicTo(mTopBound.left + bottomControlXOffset, bottomControlY, mTopBound.left + mTopSize / 8, mTopBound.bottom, mTopBound.left, mTopBound.bottom - mTopSize / 2); canvas.drawPath(mPath, mPaint); mRotateDrawable.draw(canvas); } }
From source file:com.ahamed.sample.common.decorator.ThickItemDecorator.java
@SuppressLint("NewApi") private void drawVertical(Canvas canvas, RecyclerView parent, View child) { canvas.save();/*from ww w.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() * 4; mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); canvas.restore(); }
From source file:net.simno.klingar.ui.widget.DividerItemDecoration.java
private void drawVertical(Canvas canvas, RecyclerView parent) { canvas.save();/*from w ww . j a va 2s . c om*/ // Drawable width defines left/right padding. Drawable height defines divider height. final int left = parent.getPaddingStart() + divider.getIntrinsicWidth(); final int right = parent.getWidth() - parent.getPaddingEnd() - divider.getIntrinsicWidth(); final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); parent.getDecoratedBoundsWithMargins(child, bounds); final int bottom = bounds.bottom + Math.round(ViewCompat.getTranslationY(child)); final int top = bottom - divider.getIntrinsicHeight(); divider.setBounds(left, top, right, bottom); divider.draw(canvas); } canvas.restore(); }
From source file:cn.bingoogolapple.refreshlayout.BGAStickinessRefreshView.java
@Override public void onDraw(Canvas canvas) { if (mRotateDrawable == null) { return;/*from w ww.j a va 2s.c om*/ } mPath.reset(); mTopBound.round(mRotateDrawableBound); mRotateDrawable.setBounds(mRotateDrawableBound); if (mIsRotating) { mPath.addOval(mTopBound, Path.Direction.CW); canvas.drawPath(mPath, mPaint); canvas.save(); canvas.rotate(mCurrentDegree, mRotateDrawable.getBounds().centerX(), mRotateDrawable.getBounds().centerY()); mRotateDrawable.draw(canvas); canvas.restore(); } else { // drawable mPath.moveTo(mTopBound.left, mTopBound.top + mTopSize / 2); // drawable? mPath.arcTo(mTopBound, 180, 180); // ? // mPath.quadTo(mTopBound.right - mTopSize / 8, mTopBound.bottom, mBottomBound.right, mBottomBound.bottom - mBottomBound.height() / 2); // mCurrentBottomHeight 0 mMaxBottomHeight // scale 0.2 1 float scale = Math.max(mCurrentBottomHeight * 1.0f / mMaxBottomHeight, 0.2f); float bottomControlXOffset = mTopSize * ((3 + (float) Math.pow(scale, 7) * 16) / 32); float bottomControlY = mTopBound.bottom / 2 + mCenterPoint.y / 2; // ??? mPath.cubicTo(mTopBound.right - mTopSize / 8, mTopBound.bottom, mTopBound.right - bottomControlXOffset, bottomControlY, mBottomBound.right, mBottomBound.bottom - mBottomBound.height() / 2); mPath.arcTo(mBottomBound, 0, 180); // mPath.quadTo(mTopBound.left + mTopSize / 8, mTopBound.bottom, mTopBound.left, mTopBound.bottom - mTopSize / 2); mPath.cubicTo(mTopBound.left + bottomControlXOffset, bottomControlY, mTopBound.left + mTopSize / 8, mTopBound.bottom, mTopBound.left, mTopBound.bottom - mTopSize / 2); canvas.drawPath(mPath, mPaint); mRotateDrawable.draw(canvas); } }
From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java
@Override public void draw(Canvas canvas) { Rect bounds = getBounds();//from w w w .ja v a2s . c om if (mIsRtl) { canvas.save(); canvas.scale(-1, 1, bounds.centerX(), bounds.centerY()); } float pct = drawArc(canvas, bounds); if (pct < 0) { pct = 0; } else if (pct > 1) { pct = 1; } int y = bounds.bottom - mBottomOffset; canvas.drawLine(bounds.left + mLeftOffset / 2, y, bounds.right - mRightOffset / 2, y, mLinePaint); drawSun(canvas, pct); if (mIsRtl) { canvas.restore(); } }