List of usage examples for android.graphics Canvas translate
public void translate(float dx, float dy)
From source file:com.blestep.sportsbracelet.view.TimelineChartView.java
private void drawTickLabels(Canvas c, SparseArray<Object[]> data) { final int size = data.size() - 1; final float graphCenterX = mGraphArea.left + (mGraphArea.width() / 2); final float halfItemBarWidth = mBarItemWidth / 2; for (int i = mItemsOnScreen[1]; i >= mItemsOnScreen[0] && i <= data.size(); i--) { final float barCenterX = graphCenterX + mCurrentOffset - (mBarWidth * (size - i)); float barLeft = barCenterX - halfItemBarWidth; float barRight = barCenterX + halfItemBarWidth; // Update the dynamic layout String label = (String) data.valueAt(i)[0]; // //from w w w . j a v a2 s . co m // Calculate the x position and draw the layout final float x = graphCenterX + mCurrentOffset - (mBarWidth * (size - i)) - (mLabelFgPaint.measureText(label) / 2); final int restoreCount = c.save(); c.translate(x, mFooterArea.top + (mFooterArea.height() / 2 - mTickLabelMinHeight / 2)); final Paint paint; // ? paint = barLeft < graphCenterX && barRight > graphCenterX && (mLastPosition == mCurrentPosition || (mState != STATE_SCROLLING)) ? mHighlightLabelFgPaint : mLabelFgPaint; c.drawText(label, 0, 0, paint); c.restoreToCount(restoreCount); } }
From source file:com.pdftron.pdf.tools.Tool.java
@Override public boolean onDrawEdgeEffects(Canvas canvas, int width, int verticalOffset) { boolean needsInvalidate = false; if (!mEdgeEffectLeft.isFinished()) { canvas.save();/* w w w . java 2s. co m*/ try { canvas.translate(0, canvas.getHeight() + verticalOffset); canvas.rotate(-90, 0, 0); mEdgeEffectLeft.setSize(canvas.getHeight(), canvas.getWidth()); if (mEdgeEffectLeft.draw(canvas)) { needsInvalidate = true; } } finally { canvas.restore(); } } if (!mEdgeEffectRight.isFinished()) { canvas.save(); try { canvas.translate(width, verticalOffset); canvas.rotate(90, 0, 0); mEdgeEffectRight.setSize(canvas.getHeight(), canvas.getWidth()); if (mEdgeEffectRight.draw(canvas)) { needsInvalidate = true; } } finally { canvas.restore(); } } return needsInvalidate; }
From source file:com.skumar.flexibleciruclarseekbar.CircularSeekBar.java
@Override protected void onDraw(Canvas canvas) { if (!mClockwise) { canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY()); }//from w w w. j a va2s. c o m // Set for the gradient color if (hasGradientColor) setShader(); // Draw the arcs final int arcStart = mStartAngle + mAngleOffset + mRotation; final int arcSweep = mSweepAngle; canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint); // Draw the needle scale if (drawMarkings) { drawNeedleMarkings(canvas); // Draw dot markers if (hasDotMarkers) drawDotMarker(canvas); } if (mEnabled) { // Draw the thumb nail canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos); mThumb.draw(canvas); if (hasPopupIn) { // Draw the popup canvas.translate(-mThumb.getIntrinsicWidth() / 2, -mThumb.getIntrinsicHeight() - mHeightForPopup); mPopup.draw(canvas); } } }
From source file:com.android.slidingmenu.HorizontalListView.java
/** * Draws the overscroll edge glow effect on the left and right sides of the * horizontal list//from www. ja va 2 s . com */ private void drawEdgeGlow(Canvas canvas) { if (mEdgeGlowLeft != null && !mEdgeGlowLeft.isFinished() && isEdgeGlowEnabled()) { // The Edge glow is meant to come from the top of the screen, so // rotate it to draw on the left side. final int restoreCount = canvas.save(); final int height = getHeight(); canvas.rotate(-90, 0, 0); canvas.translate(-height + getPaddingBottom(), 0); mEdgeGlowLeft.setSize(getRenderHeight(), getRenderWidth()); if (mEdgeGlowLeft.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } else if (mEdgeGlowRight != null && !mEdgeGlowRight.isFinished() && isEdgeGlowEnabled()) { // The Edge glow is meant to come from the top of the screen, so // rotate it to draw on the right side. final int restoreCount = canvas.save(); final int width = getWidth(); canvas.rotate(90, 0, 0); canvas.translate(getPaddingTop(), -width); mEdgeGlowRight.setSize(getRenderHeight(), getRenderWidth()); if (mEdgeGlowRight.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } }
From source file:com.grottworkshop.gwsvectorsandboxlib.VectorDrawable.java
@Override public void draw(Canvas canvas) { final Rect bounds = getBounds(); if (bounds.width() == 0 || bounds.height() == 0) { // too small to draw return;//from ww w . j av a 2 s . c om } final int saveCount = canvas.save(); final boolean needMirroring = needMirroring(); canvas.translate(bounds.left, bounds.top); if (needMirroring) { canvas.translate(bounds.width(), 0); canvas.scale(-1.0f, 1.0f); } // Color filters always override tint filters. final ColorFilter colorFilter = mColorFilter == null ? mTintFilter : mColorFilter; if (!mAllowCaching) { // AnimatedVectorDrawable if (!mVectorState.hasTranslucentRoot()) { mVectorState.mVPathRenderer.draw(canvas, bounds.width(), bounds.height(), colorFilter); } else { mVectorState.createCachedBitmapIfNeeded(bounds); mVectorState.updateCachedBitmap(bounds); mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter); } } else { // Static Vector Drawable case. mVectorState.createCachedBitmapIfNeeded(bounds); if (!mVectorState.canReuseCache()) { mVectorState.updateCachedBitmap(bounds); mVectorState.updateCacheStates(); } mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter); } canvas.restoreToCount(saveCount); }
From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java
private void drawEdges(Canvas canvas) { if (mEdgeGlowLeft != null) { final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); if (!mEdgeGlowLeft.isFinished()) { final int restoreCount = canvas.save(); canvas.rotate(270);//from w w w . j a v a 2s . c om canvas.translate(-height + getPaddingTop(), 0); mEdgeGlowLeft.setSize(height, width); if (mEdgeGlowLeft.draw(canvas)) { postInvalidate(); } canvas.restoreToCount(restoreCount); } if (!mEdgeGlowRight.isFinished()) { final int restoreCount = canvas.save(); canvas.rotate(90); canvas.translate(-getPaddingTop(), -(mTouchX + width)); mEdgeGlowRight.setSize(height, width); if (mEdgeGlowRight.draw(canvas)) { postInvalidate(); } canvas.restoreToCount(restoreCount); } } }
From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { canvas.save();//from w w w.j a v a2s . c o m //set matrix to child's transformation setChildTransformation(child, mMatrix); //Generate child bitmap Bitmap bitmap = child.getDrawingCache(); //initialize canvas state. Child 0,0 coordinates will match canvas 0,0 canvas.translate(child.getLeft(), child.getTop()); //set child transformation on canvas canvas.concat(mMatrix); final Bitmap rfCache = ((CoverFrame) child).mReflectionCache; if (mReflectionBackgroundColor != Color.TRANSPARENT) { final int top = bitmap.getHeight() + mReflectionGap - 2; final float frame = 1.0f; mReflectionPaint.setColor(mReflectionBackgroundColor); canvas.drawRect(frame, top + frame, rfCache.getWidth() - frame, top + rfCache.getHeight() - frame, mReflectionPaint); } mPaint.reset(); mPaint.setAntiAlias(true); mPaint.setFilterBitmap(true); //Draw child bitmap with applied transforms canvas.drawBitmap(bitmap, 0.0f, 0.0f, mPaint); //Draw reflection canvas.drawBitmap(rfCache, 0.0f, bitmap.getHeight() - 2 + mReflectionGap, mPaint); canvas.restore(); return false; }
From source file:com.android.mail.browse.ConversationItemView.java
private void drawSendersImage(final Canvas canvas) { if (!mSendersImageView.isFlipping()) { final boolean showSenders = !mChecked; mSendersImageView.reset(showSenders); }//from w w w. ja v a2s. c o m canvas.translate(mCoordinates.contactImagesX, mCoordinates.contactImagesY); if (mPhotoBitmap == null) { mSendersImageView.draw(canvas); } else { canvas.drawBitmap(mPhotoBitmap, null, mPhotoRect, sPaint); } }
From source file:com.android.leanlauncher.Workspace.java
/** * Draw the View v into the given Canvas. * * @param v the view to draw/*from ww w. j a v a2s . c om*/ * @param destCanvas the canvas to draw on * @param padding the horizontal and vertical padding to use when drawing */ private static void drawDragView(View v, Canvas destCanvas, int padding) { final Rect clipRect = sTempRect; v.getDrawingRect(clipRect); destCanvas.save(); if (v instanceof TextView) { Drawable d = ((TextView) v).getCompoundDrawables()[1]; Rect bounds = getDrawableBounds(d); clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding); destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top); d.draw(destCanvas); } else { destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2); destCanvas.clipRect(clipRect, Op.REPLACE); v.draw(destCanvas); } destCanvas.restore(); }
From source file:com.example.mylibrary.utils.decoration.StickyHeaderDecoration.java
/** * {@inheritDoc}/*from ww w . ja va 2 s . 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); int adapterPos = parent.getChildAdapterPosition(child); if (!mIncludeHeader) { if (parent.getAdapter() instanceof RecyclerArrayAdapter) { int headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount(); int footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount(); int dataCount = ((RecyclerArrayAdapter) parent.getAdapter()).getCount(); if (adapterPos < headerCount) { continue; } if (adapterPos >= headerCount + dataCount) { continue; } if (adapterPos >= headerCount) { adapterPos -= headerCount; } } } 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(); } } } }