List of usage examples for android.graphics Canvas restore
public void restore()
From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java
private void drawSun(Canvas canvas, float pct) { // Draw the dots canvas.drawCircle(mBezier1x, mBezier1y, mDotRadius, mDotPaint); canvas.drawCircle(mBezier4x, mBezier4y, mDotRadius, mDotPaint); // calculate the center point of the sun image float x = bezierInterpolation(pct, mBezier1x, mBezier2x, mBezier3x, mBezier4x); float y = bezierInterpolation(pct, mBezier1y, mBezier2y, mBezier3y, mBezier4y); Rect sunBounds = mSunImage.getBounds(); x -= sunBounds.width() / 2;/*from w w w . j av a 2 s . co m*/ y -= sunBounds.height() / 2; // if we are in rtl, we still want to show the image normally // so flip it back canvas.translate(x, y); if (mIsRtl) { canvas.save(); canvas.scale(-1, 1, sunBounds.centerX(), sunBounds.centerY()); } // draw the sun image mSunImage.draw(canvas); // restore the flip again if (mIsRtl) { canvas.restore(); } canvas.translate(-x, -y); }
From source file:com.ttxgps.zoom.GestureImageView.java
@Override protected void onDraw(Canvas canvas) { if (layout) { if (drawable != null && !isRecycled()) { canvas.save();/*from w w w. ja va 2s .co m*/ float adjustedScale = scale * scaleAdjust; canvas.translate(x, y); if (rotation != 0.0f) { canvas.rotate(rotation); } if (adjustedScale != 1.0f) { canvas.scale(adjustedScale, adjustedScale); } drawable.draw(canvas); canvas.restore(); } if (drawLock.availablePermits() <= 0) { drawLock.release(); } } }
From source file:cn.lanmei.com.dingdong_2.ItemDecoration.StickyHeaderDecoration.java
/** * {@inheritDoc}/*from w w w . java 2 s . c o m*/ */ @Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { // final int count = parent.getChildCount(); LRecyclerViewAdapter adapter = (LRecyclerViewAdapter) parent.getAdapter(); RecyclerView.Adapter ra = adapter.getInnerAdapter(); final int count = ra.getItemCount(); for (int layoutPos = 0; layoutPos < count; layoutPos++) { final View child = parent.getChildAt(layoutPos); final int adapterPos = parent.getChildAdapterPosition(child); // L.MyLog("sticky","onDrawOver:"+adapterPos+"getItemCount"+count); if (adapterPos != RecyclerView.NO_POSITION && (layoutPos == 0 || hasHeader(adapterPos))) { View header = getHeader(parent, adapterPos).itemView; c.save(); final int left = child.getLeft(); final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos); c.translate(left, top); header.setTranslationX(left); header.setTranslationY(top); header.draw(c); c.restore(); } } }
From source file:org.chromium.chrome.browser.omnibox.LocationBarPhone.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean needsCanvasRestore = false; if (child == mUrlBar && mUrlActionsContainer.getVisibility() == VISIBLE) { canvas.save();/* ww w. java2 s . com*/ // Clip the URL bar contents to ensure they do not draw under the URL actions during // focus animations. Based on the RTL state of the location bar, the url actions // container can be on the left or right side, so clip accordingly. if (mUrlBar.getLeft() < mUrlActionsContainer.getLeft()) { canvas.clipRect(0, 0, (int) mUrlActionsContainer.getX(), getBottom()); } else { canvas.clipRect(mUrlActionsContainer.getX() + mUrlActionsContainer.getWidth(), 0, getWidth(), getBottom()); } needsCanvasRestore = true; } boolean retVal = super.drawChild(canvas, child, drawingTime); if (needsCanvasRestore) { canvas.restore(); } return retVal; }
From source file:com.example.view.wheel.WheelView.java
/** * Draws value and label layout/*from w w w . j av a 2s .c om*/ * @param canvas the canvas for drawing */ private void drawValue(Canvas canvas) { valuePaint.setColor(VALUE_TEXT_COLOR); valuePaint.drawableState = getDrawableState(); Rect bounds = new Rect(); itemsLayout.getLineBounds(visibleItems / 2, bounds); // draw label if (labelLayout != null) { canvas.save(); canvas.translate(itemsLayout.getWidth() + LABEL_OFFSET, bounds.top); labelLayout.draw(canvas); canvas.restore(); } // draw current value if (valueLayout != null) { canvas.save(); canvas.translate(0, bounds.top + scrollingOffset); valueLayout.draw(canvas); canvas.restore(); } }
From source file:com.example.gatsu.theevent.HighlightView.java
protected void draw(Canvas canvas) { if (mHidden) { return;//from w ww. ja va 2 s .c o m } Path path = new Path(); if (!hasFocus()) { mOutlinePaint.setColor(0xFF000000); canvas.drawRect(mDrawRect, mOutlinePaint); } else { Rect viewDrawingRect = new Rect(); mContext.getDrawingRect(viewDrawingRect); if (mCircle) { canvas.save(); float width = mDrawRect.width(); float height = mDrawRect.height(); path.addCircle(mDrawRect.left + (width / 2), mDrawRect.top + (height / 2), width / 2, Path.Direction.CW); mOutlinePaint.setColor(0xFFEF04D6); canvas.clipPath(path, Region.Op.DIFFERENCE); canvas.drawRect(viewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint); canvas.restore(); } else { Rect topRect = new Rect(viewDrawingRect.left, viewDrawingRect.top, viewDrawingRect.right, mDrawRect.top); if (topRect.width() > 0 && topRect.height() > 0) { canvas.drawRect(topRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } Rect bottomRect = new Rect(viewDrawingRect.left, mDrawRect.bottom, viewDrawingRect.right, viewDrawingRect.bottom); if (bottomRect.width() > 0 && bottomRect.height() > 0) { canvas.drawRect(bottomRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } Rect leftRect = new Rect(viewDrawingRect.left, topRect.bottom, mDrawRect.left, bottomRect.top); if (leftRect.width() > 0 && leftRect.height() > 0) { canvas.drawRect(leftRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } Rect rightRect = new Rect(mDrawRect.right, topRect.bottom, viewDrawingRect.right, bottomRect.top); if (rightRect.width() > 0 && rightRect.height() > 0) { canvas.drawRect(rightRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } path.addRect(new RectF(mDrawRect), Path.Direction.CW); mOutlinePaint.setColor(0xFFFF8A00); } canvas.drawPath(path, mOutlinePaint); if (mMode == ModifyMode.Grow) { if (mCircle) { int width = mResizeDrawableDiagonal.getIntrinsicWidth(); int height = mResizeDrawableDiagonal.getIntrinsicHeight(); int d = (int) Math.round(Math.cos(/*45deg*/Math.PI / 4D) * (mDrawRect.width() / 2D)); int x = mDrawRect.left + (mDrawRect.width() / 2) + d - width / 2; int y = mDrawRect.top + (mDrawRect.height() / 2) - d - height / 2; mResizeDrawableDiagonal.setBounds(x, y, x + mResizeDrawableDiagonal.getIntrinsicWidth(), y + mResizeDrawableDiagonal.getIntrinsicHeight()); mResizeDrawableDiagonal.draw(canvas); } else { int left = mDrawRect.left + 1; int right = mDrawRect.right + 1; int top = mDrawRect.top + 4; int bottom = mDrawRect.bottom + 3; int widthWidth = mResizeDrawableWidth.getIntrinsicWidth() / 2; int widthHeight = mResizeDrawableWidth.getIntrinsicHeight() / 2; int heightHeight = mResizeDrawableHeight.getIntrinsicHeight() / 2; int heightWidth = mResizeDrawableHeight.getIntrinsicWidth() / 2; int xMiddle = mDrawRect.left + ((mDrawRect.right - mDrawRect.left) / 2); int yMiddle = mDrawRect.top + ((mDrawRect.bottom - mDrawRect.top) / 2); mResizeDrawableWidth.setBounds(left - widthWidth, yMiddle - widthHeight, left + widthWidth, yMiddle + widthHeight); mResizeDrawableWidth.draw(canvas); mResizeDrawableWidth.setBounds(right - widthWidth, yMiddle - widthHeight, right + widthWidth, yMiddle + widthHeight); mResizeDrawableWidth.draw(canvas); mResizeDrawableHeight.setBounds(xMiddle - heightWidth, top - heightHeight, xMiddle + heightWidth, top + heightHeight); mResizeDrawableHeight.draw(canvas); mResizeDrawableHeight.setBounds(xMiddle - heightWidth, bottom - heightHeight, xMiddle + heightWidth, bottom + heightHeight); mResizeDrawableHeight.draw(canvas); } } } }
From source file:com.chartiq.chartiqsample.ui.StickyHeaderDecoration.java
/** * {@inheritDoc}//ww w .ja v a 2s .c o 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 (child.getVisibility() == View.GONE) { continue; } 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:org.caojun.library.cropimage.HighlightView.java
protected void draw(Canvas canvas) { if (mHidden) { return;/*from w ww .j a va 2 s . c om*/ } Path path = new Path(); if (!hasFocus()) { mOutlinePaint.setColor(0xFF000000); canvas.drawRect(mDrawRect, mOutlinePaint); } else { Rect viewDrawingRect = new Rect(); mView.getDrawingRect(viewDrawingRect); if (mCircle) { canvas.save(); float width = mDrawRect.width(); float height = mDrawRect.height(); path.addCircle(mDrawRect.left + (width / 2), mDrawRect.top + (height / 2), width / 2, Path.Direction.CW); mOutlinePaint.setColor(0xFFEF04D6); canvas.clipPath(path, Region.Op.DIFFERENCE); canvas.drawRect(viewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint); canvas.restore(); } else { Rect topRect = new Rect(viewDrawingRect.left, viewDrawingRect.top, viewDrawingRect.right, mDrawRect.top); if (topRect.width() > 0 && topRect.height() > 0) { canvas.drawRect(topRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } Rect bottomRect = new Rect(viewDrawingRect.left, mDrawRect.bottom, viewDrawingRect.right, viewDrawingRect.bottom); if (bottomRect.width() > 0 && bottomRect.height() > 0) { canvas.drawRect(bottomRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } Rect leftRect = new Rect(viewDrawingRect.left, topRect.bottom, mDrawRect.left, bottomRect.top); if (leftRect.width() > 0 && leftRect.height() > 0) { canvas.drawRect(leftRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } Rect rightRect = new Rect(mDrawRect.right, topRect.bottom, viewDrawingRect.right, bottomRect.top); if (rightRect.width() > 0 && rightRect.height() > 0) { canvas.drawRect(rightRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } path.addRect(new RectF(mDrawRect), Path.Direction.CW); mOutlinePaint.setColor(0xFFFF8A00); } canvas.drawPath(path, mOutlinePaint); if (mMode == ModifyMode.Grow) { if (mCircle) { int width = mResizeDrawableDiagonal.getIntrinsicWidth(); int height = mResizeDrawableDiagonal.getIntrinsicHeight(); int d = (int) Math.round(Math.cos(/*45deg*/Math.PI / 4D) * (mDrawRect.width() / 2D)); int x = mDrawRect.left + (mDrawRect.width() / 2) + d - width / 2; int y = mDrawRect.top + (mDrawRect.height() / 2) - d - height / 2; mResizeDrawableDiagonal.setBounds(x, y, x + mResizeDrawableDiagonal.getIntrinsicWidth(), y + mResizeDrawableDiagonal.getIntrinsicHeight()); mResizeDrawableDiagonal.draw(canvas); } else { int left = mDrawRect.left + 1; int right = mDrawRect.right + 1; int top = mDrawRect.top + 4; int bottom = mDrawRect.bottom + 3; int widthWidth = mResizeDrawableWidth.getIntrinsicWidth() / 2; int widthHeight = mResizeDrawableWidth.getIntrinsicHeight() / 2; int heightHeight = mResizeDrawableHeight.getIntrinsicHeight() / 2; int heightWidth = mResizeDrawableHeight.getIntrinsicWidth() / 2; int xMiddle = mDrawRect.left + ((mDrawRect.right - mDrawRect.left) / 2); int yMiddle = mDrawRect.top + ((mDrawRect.bottom - mDrawRect.top) / 2); mResizeDrawableWidth.setBounds(left - widthWidth, yMiddle - widthHeight, left + widthWidth, yMiddle + widthHeight); mResizeDrawableWidth.draw(canvas); mResizeDrawableWidth.setBounds(right - widthWidth, yMiddle - widthHeight, right + widthWidth, yMiddle + widthHeight); mResizeDrawableWidth.draw(canvas); mResizeDrawableHeight.setBounds(xMiddle - heightWidth, top - heightHeight, xMiddle + heightWidth, top + heightHeight); mResizeDrawableHeight.draw(canvas); mResizeDrawableHeight.setBounds(xMiddle - heightWidth, bottom - heightHeight, xMiddle + heightWidth, bottom + heightHeight); mResizeDrawableHeight.draw(canvas); } } } }
From source file:com.evilduck.piano.views.instrument.PianoView.java
@Override protected void onDraw(Canvas canvas) { if (isInEditMode()) { canvas.drawColor(Color.GRAY); return;//from w w w. j av a 2 s .c o m } if (measurementChanged) { measurementChanged = false; keyboard.initializeInstrument(getMeasuredHeight(), getContext()); float oldInstrumentWidth = instrumentWidth; instrumentWidth = keyboard.getWidth(); float ratio = (float) instrumentWidth / oldInstrumentWidth; xOffset = (int) (xOffset * ratio); } int localXOffset = getOffsetInsideOfBounds(); canvas.save(); canvas.scale(scaleX, 1.0f); canvas.translate(-localXOffset, 0); keyboard.updateBounds(localXOffset, canvasWidth + localXOffset); keyboard.draw(canvas); if (!notesToDraw.isEmpty()) { keyboard.drawOverlays(notesToDraw, canvas); } canvas.restore(); }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw card value and small suit below value * in both top left and bottom right corners * bottom right is reversed/upside down/*from w w w . j a va2 s . c o m*/ * @param paint paint styled for card value and small suit * @param canvas canvas to draw on * @param value card value * @param smallSuit small card suit * @param suitIdx suit index */ private void drawCardValue(final Paint paint, final Canvas canvas, final String value, final Bitmap smallSuit, final int suitIdx) { if ((suitIdx & 1) == 1) { paint.setARGB(255, 255, 0, 0); } else { paint.setARGB(255, 0, 0, 0); } canvas.drawText(value, mSuitsSize4th, mSuitsSize, paint); canvas.drawBitmap(smallSuit, mSuitsSize4th, mSuitsSize4th + mSuitsSize, mSuitPaint); canvas.save(); canvas.rotate(180, Card.WIDTH / 2, Card.HEIGHT / 2); canvas.drawBitmap(smallSuit, mSuitsSize4th, mSuitsSize4th + mSuitsSize, mSuitPaint); canvas.drawText(value, mSuitsSize4th, mSuitsSize, paint); canvas.restore(); }