List of usage examples for android.graphics Canvas save
public int save()
From source file:android.support.designox.widget.CollapsingTextHelper.java
public void draw(Canvas canvas) { final int saveCount = canvas.save(); if (mTextToDraw != null && mDrawTitle) { float x = mCurrentDrawX; float y = mCurrentDrawY; final boolean drawTexture = mUseTexture && mExpandedTitleTexture != null; final float ascent; final float descent; if (drawTexture) { ascent = mTextureAscent * mScale; descent = mTextureDescent * mScale; } else {//from www. ja v a 2 s. co m ascent = mTextPaint.ascent() * mScale; descent = mTextPaint.descent() * mScale; } if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mCurrentBounds.left, y + ascent, mCurrentBounds.right, y + descent, DEBUG_DRAW_PAINT); } if (drawTexture) { y += ascent; } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (drawTexture) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTextToDraw, 0, mTextToDraw.length(), x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:org.buffer.android.buffertextinputlayout.util.CollapsingTextHelper.java
public void draw(Canvas canvas) { final int saveCount = canvas.save(); if (mTextToDraw != null && mDrawTitle) { float x = mCurrentDrawX; float y = mCurrentDrawY; final boolean drawTexture = mUseTexture && mExpandedTitleTexture != null; final float ascent; final float descent; if (drawTexture) { ascent = mTextureAscent * mScale; descent = mTextureDescent * mScale; } else {/* w w w . ja va 2s.c om*/ ascent = mTextPaint.ascent() * mScale; descent = mTextPaint.descent() * mScale; } if (DEBUG_DRAW) { // Just a debug tool, which drawn a magenta rect in the text bounds canvas.drawRect(mCurrentBounds.left, y + ascent, mCurrentBounds.right, y + descent, DEBUG_DRAW_PAINT); } if (drawTexture) { y += ascent; } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (drawTexture) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTextToDraw, 0, mTextToDraw.length(), x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:eu.davidea.flexibleadapter.common.FlexibleItemDecoration.java
@SuppressLint("NewApi") private void drawVertical(Canvas canvas, RecyclerView parent) { canvas.save(); final int left; final int right; if (parent.getClipToPadding()) { left = parent.getPaddingLeft();// w ww.jav a 2 s. 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 itemCount = parent.getChildCount(); for (int i = 0; i < itemCount - 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:eu.davidea.flexibleadapter.common.FlexibleItemDecoration.java
@SuppressLint("NewApi") private void drawHorizontal(Canvas canvas, RecyclerView parent) { canvas.save(); final int top; final int bottom; if (parent.getClipToPadding()) { top = parent.getPaddingTop();//from w w w . ja v a 2s . com bottom = parent.getHeight() - parent.getPaddingBottom(); canvas.clipRect(parent.getPaddingLeft(), top, parent.getWidth() - parent.getPaddingRight(), bottom); } else { top = 0; bottom = parent.getHeight(); } final int itemCount = parent.getChildCount(); for (int i = 0; i < itemCount - 1; 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.github.shareme.gwsmaterialuikit.library.material.drawable.LineMorphingDrawable.java
@Override public void draw(Canvas canvas) { int restoreCount = canvas.save(); float degrees = (mClockwise ? 180 : -180) * ((mPrevState < mCurState ? 0f : 1f) + mAnimProgress); if (mIsRtl)//from w ww. j a v a2 s. co m canvas.scale(-1f, 1f, mDrawBound.centerX(), mDrawBound.centerY()); canvas.rotate(degrees, mDrawBound.centerX(), mDrawBound.centerY()); canvas.drawPath(mPath, mPaint); canvas.restoreToCount(restoreCount); }
From source file:com.nicodelee.ptr.header.StickinessView.java
@Override public void onDraw(Canvas canvas) { super.onDraw(canvas); if (mRotateDrawable == null) { return;//www. j a v a 2 s . co m } 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.hippo.refreshlayout.SwipeProgressBar.java
private boolean draw(Canvas canvas, boolean first) { Rect bounds = mBounds;//from w w w. j a v a 2s .c o m final int width = bounds.width(); final int cx = bounds.centerX(); final int cy = bounds.centerY(); final int colors = mColors.length; boolean drawTriggerWhileFinishing = false; boolean drawAgain = false; int restoreCount = canvas.save(); canvas.clipRect(bounds); if (mRunning || (mFinishTime > 0)) { long now = AnimationUtils.currentAnimationTimeMillis(); long elapsed = (now - mStartTime) % mAnimationDuration; long iterations = (now - mStartTime) / ANIMATION_DURATION_MS_PER_COLOR; float rawProgress = (elapsed / (mAnimationDuration / (float) colors)); // If we're not running anymore, that means we're running through // the finish animation. if (!mRunning) { // If the finish animation is done, don't draw anything, and // don't repost. if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) { mFinishTime = 0; return false; } // Otherwise, use a 0 opacity alpha layer to clear the animation // from the inside out. This layer will prevent the circles from // drawing within its bounds. long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS; float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f)); float pct = (finishProgress / 100f); // Radius of the circle is half of the screen. float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct); if (SUPPORT_CLIP_RECT_DIFFERENCE) { mClipRect.set(cx - clearRadius, bounds.top, cx + clearRadius, bounds.bottom); canvas.clipRect(mClipRect, Region.Op.DIFFERENCE); } else { if (first) { // First time left drawAgain = true; mClipRect.set(bounds.left, bounds.top, cx - clearRadius, bounds.bottom); } else { // Second time right mClipRect.set(cx + clearRadius, bounds.top, bounds.right, bounds.bottom); } canvas.clipRect(mClipRect); } // Only draw the trigger if there is a space in the center of // this refreshing view that needs to be filled in by the // trigger. If the progress view is just still animating, let it // continue animating. drawTriggerWhileFinishing = true; } // First fill in with the last color that would have finished drawing. if (iterations == 0) { canvas.drawColor(mColors[0]); } else { int index = colors - 1; float left = 0.0f; float right = 1.0f; for (int i = 0; i < colors; ++i) { if ((rawProgress >= left && rawProgress < right) || i == colors - 1) { canvas.drawColor(mColors[index]); break; } index = (index + 1) % colors; left += 1.0f; right += 1.0f; } } // Then draw up to 4 overlapping concentric circles of varying radii, based on how far // along we are in the cycle. // progress 0-50 draw mColor2 // progress 25-75 draw mColor3 // progress 50-100 draw mColor4 // progress 75 (wrap to 25) draw mColor1 if (colors > 1) { if ((rawProgress >= 0.0f && rawProgress <= 1.0f)) { float pct = (rawProgress + 1.0f) / 2; drawCircle(canvas, cx, cy, mColors[0], pct); } float left = 0.0f; float right = 2.0f; for (int i = 1; i < colors; ++i) { if (rawProgress >= left && rawProgress <= right) { float pct = (rawProgress - i + 1.0f) / 2; drawCircle(canvas, cx, cy, mColors[i], pct); } left += 1.0f; right += 1.0f; } if ((rawProgress >= colors - 1.0f && rawProgress <= colors)) { float pct = (rawProgress - colors + 1.0f) / 2; drawCircle(canvas, cx, cy, mColors[0], pct); } } if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) { // There is some portion of trigger to draw. Restore the canvas, // then draw the trigger. Otherwise, the trigger does not appear // until after the bar has finished animating and appears to // just jump in at a larger width than expected. canvas.restoreToCount(restoreCount); restoreCount = canvas.save(); canvas.clipRect(bounds); drawTrigger(canvas, cx, cy); } // Keep running until we finish out the last cycle. ViewCompat.postInvalidateOnAnimation(mParent, bounds.left, bounds.top, bounds.right, bounds.bottom); } else { // Otherwise if we're in the middle of a trigger, draw that. if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) { drawTrigger(canvas, cx, cy); } } canvas.restoreToCount(restoreCount); return drawAgain; }
From source file:com.taobao.weex.ui.view.WXScrollView.java
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (mCurrentStickyView != null) { canvas.save(); mCurrentStickyView.getLocationOnScreen(mStickyP); int realOffset = (mStickyOffset <= 0 ? mStickyOffset : 0); canvas.translate(mStickyP[0], getScrollY() + realOffset); canvas.clipRect(0, realOffset, mCurrentStickyView.getWidth(), mCurrentStickyView.getHeight()); mCurrentStickyView.draw(canvas); canvas.restore();/*www. j av a 2s . co m*/ } }
From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java
@Override protected void onDraw(Canvas canvas) { this.Radius = Math.min(px, py); this.r = Radius / 10; // Sun Moon radius; // over here/*from ww w . j av a 2 s. co m*/ qiblaInfo = sunMoonPosition.getDestinationHeading(); textPaint.setTextAlign(Paint.Align.LEFT); textPaint.setColor(ContextCompat.getColor(getContext(), (R.color.qibla_color))); canvas.rotate(-bearing, px, py);// Attach and Detach capability lies canvas.save(); drawDial(canvas); if (isLongLatAvailable()) { canvas.save(); drawQibla(canvas); } canvas.save(); drawTrueNorthArrow(canvas, bearing); if (isLongLatAvailable()) { canvas.save(); drawMoon(canvas); canvas.save(); drawSun(canvas); } canvas.save(); }
From source file:com.tr4android.support.extension.widget.CollapsingTextHelper.java
public void draw(Canvas canvas) { final int saveCount = canvas.save(); if (mTextToDraw != null && mDrawTitle) { float x = mCurrentDrawX; float y = mCurrentDrawY; final boolean drawTexture = mUseTexture && mExpandedTitleTexture != null; final float ascent; final float descent; // Update the TextPaint to the current text size mTextPaint.setTextSize(mCurrentTextSize); if (drawTexture) { ascent = mTextureAscent * mScale; descent = mTextureDescent * mScale; } else {//from w w w .j av a 2 s .c o m ascent = mTextPaint.ascent() * mScale; descent = mTextPaint.descent() * mScale; } if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mCurrentBounds.left, y + ascent, mCurrentBounds.right, y + descent, DEBUG_DRAW_PAINT); } if (drawTexture) { y += ascent; } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (drawTexture) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTextToDraw, 0, mTextToDraw.length(), x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }