List of usage examples for android.graphics Canvas restore
public void restore()
From source file:com.gj.administrator.gjerp.view.CircleIndicator.java
@Override protected void onDraw(Canvas canvas) { Log.e("CircleIndicator", "onDraw()"); super.onDraw(canvas); int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); for (ShapeHolder item : tabItems) { canvas.save();//from ww w . j a v a 2s. co m canvas.translate(item.getX(), item.getY()); item.getShape().draw(canvas); canvas.restore(); } if (movingItem != null) { canvas.save(); canvas.translate(movingItem.getX(), movingItem.getY()); movingItem.getShape().draw(canvas); canvas.restore(); } canvas.restoreToCount(sc); }
From source file:com.keylesspalace.tusky.view.ProgressImageView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); float angle = (progress / 100f) * 360 - 90; float halfWidth = canvas.getWidth() / 2; float halfHeight = canvas.getHeight() / 2; progressRect.set(halfWidth * 0.75f, halfHeight * 0.75f, halfWidth * 1.25f, halfHeight * 1.25f); biggerRect.set(progressRect);//w w w .ja v a 2 s . co m int margin = 8; biggerRect.set(progressRect.left - margin, progressRect.top - margin, progressRect.right + margin, progressRect.bottom + margin); canvas.saveLayer(biggerRect, null, Canvas.ALL_SAVE_FLAG); if (progress != -1) { canvas.drawOval(progressRect, circlePaint); canvas.drawArc(biggerRect, angle, 360 - angle - 90, true, clearPaint); } canvas.restore(); int circleRadius = Utils.dpToPx(getContext(), 14); int circleMargin = Utils.dpToPx(getContext(), 14); int circleY = canvas.getHeight() - circleMargin - circleRadius / 2; int circleX = canvas.getWidth() - circleMargin - circleRadius / 2; canvas.drawCircle(circleX, circleY, circleRadius, markBgPaint); captionDrawable.setBounds(canvas.getWidth() - circleMargin - circleRadius, canvas.getHeight() - circleMargin - circleRadius, canvas.getWidth() - circleMargin, canvas.getHeight() - circleMargin); DrawableCompat.setTint(captionDrawable, Color.WHITE); captionDrawable.draw(canvas); }
From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java
private float drawArc(Canvas canvas, Rect bounds) { canvas.drawPath(mArc, mArcPaint);// w w w . ja v a 2s .co m int minuteSinceStart = mNowMinutes - mRiseMinutes; int totalMinutes = mSetMinutes - mRiseMinutes; float pct = (minuteSinceStart / (float) totalMinutes); int r = bounds.right - mRightOffset; int l = bounds.left + mLeftOffset; int px = (int) (pct * (r - l)); mClipRect.set(0, 0, l + px, bounds.bottom); canvas.save(Canvas.CLIP_SAVE_FLAG); canvas.clipRect(mClipRect); canvas.drawPath(mArcFill, mArcFillPaint); canvas.restore(); return pct; }
From source file:org.wikipedia.page.shareafact.SnippetImage.java
private static void drawTitle(@NonNull Canvas canvas, @NonNull String title, int top, boolean isArticleRTL) { final int marginBottom = 0; final int maxHeight = 70; final int maxLines = 2; final float maxFontSize = 30.0f; final float spacingMultiplier = 0.7f; TextPaint textPaint = new TextPaint(); textPaint.setAntiAlias(true);//from w w w . ja va2 s . co m textPaint.setColor(Color.WHITE); textPaint.setTextSize(maxFontSize); textPaint.setStyle(Paint.Style.FILL); textPaint.setTypeface(SERIF); textPaint.setShadowLayer(1.0f, 0.0f, 1.0f, Color.GRAY); StaticLayout textLayout = optimizeTextSize( new TextLayoutParams(title, textPaint, DESCRIPTION_WIDTH, spacingMultiplier), maxHeight, maxLines, maxFontSize, maxFontSize); int left = HORIZONTAL_PADDING; if (isArticleRTL) { left = WIDTH - HORIZONTAL_PADDING - textLayout.getWidth(); } int marginBottomTotal = marginBottom; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // versions < 5.0 don't compensate for bottom margin correctly when line // spacing is less than 1.0, so we'll compensate ourselves final int marginBoost = 10; marginBottomTotal += marginBoost; } top = top - marginBottomTotal - textLayout.getHeight(); canvas.save(); canvas.translate(left, top); textLayout.draw(canvas); canvas.restore(); }
From source file:com.ahamed.multiviewadapter.util.SimpleDividerDecoration.java
@SuppressLint("NewApi") private void drawVertical(Canvas canvas, RecyclerView parent, View child) { canvas.save();/*from ww w. j a v a 2 s . com*/ 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:ezy.ui.view.ViewPagerIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int flags = Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG; int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, flags); int wg = mItemWidth + mItemGap; int x = (getWidth() - mWidth) / 2; int y = (getHeight() - mItemHeight) / 2; mItemDrawable.setBounds(0, 0, mItemWidth, mItemHeight); mItemDrawableSelected.setBounds(0, 0, mItemWidth, mItemHeight); for (int i = 0; i < mItemCount; i++) { canvas.save();/*from w ww.j av a 2 s. c om*/ canvas.translate(x + i * wg, y); mItemDrawable.draw(canvas); canvas.restore(); } canvas.save(); canvas.translate(x + (mPosition + mPositionOffset) * wg, y); mItemDrawableSelected.draw(canvas); canvas.restore(); canvas.restoreToCount(sc); }
From source file:com.nicodelee.ptr.header.StickinessView.java
@Override public void onDraw(Canvas canvas) { super.onDraw(canvas); if (mRotateDrawable == null) { return;//from w w w .j a v a 2 s . c o 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.ahamed.multiviewadapter.util.SimpleDividerDecoration.java
@SuppressLint("NewApi") private void drawHorizontal(Canvas canvas, RecyclerView parent, View child) { canvas.save();/*from w ww.j ava2 s . c o 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:com.achep.acdisplay.ui.widgets.CircleView.java
private void drawCornerIcon(@NonNull Canvas canvas, @NonNull Drawable drawable, int xm, int ym) { int width = getMeasuredWidth() - drawable.getBounds().width(); int height = getMeasuredHeight() - drawable.getBounds().height(); float margin = (1 - 2 * xm) * mCornerMargin; // Draw/*from www. j a va 2 s .co m*/ canvas.save(); canvas.translate(xm * width + margin, ym * height + margin); drawable.draw(canvas); canvas.restore(); }
From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java
public void drawSun(Canvas canvas) { sunPaint.reset();//from ww w .j a v a 2 s. c o m sunPaint.setColor(Color.YELLOW); sunPaint.setStyle(Paint.Style.FILL_AND_STROKE); // Horizontal sunPosition = new Horizontal(225, 45); if (sunPosition.getElevation() > -10) { canvas.rotate((float) sunPosition.getAzimuth() - 360, px, py); sunPaint.setPathEffect(dashPath); int ry = (int) (((90 - sunPosition.getElevation()) / 90) * Radius); canvas.drawCircle(px, py - ry, r, sunPaint); dashedPaint.setColor(Color.YELLOW); canvas.drawLine(px, py - Radius, px, py + Radius, dashedPaint); sunPaint.setPathEffect(null); canvas.restore(); } }