Refine search
private void drawTree(Canvas canvas, float scale, float baseX, float baseY, int colorTrunk, int colorBranch) { canvas.save(); final float dx = baseX - TREE_WIDTH * scale / 2; final float dy = baseY - TREE_HEIGHT * scale; canvas.translate(dx, dy); canvas.scale(scale, scale); mBranchPaint.setColor(colorBranch); canvas.drawPath(mBranch, mBranchPaint); mTrunkPaint.setColor(colorTrunk); canvas.drawPath(mTrunk, mTrunkPaint); mBoarderPaint.setColor(colorTrunk); canvas.drawPath(mBranch, mBoarderPaint); canvas.restore(); }
@Override public void draw(Canvas canvas, float posX, float posY) { MPPointF offset = getOffsetForDrawingAtPoint(posX, posY); int saveId = canvas.save(); // translate to the correct position and draw canvas.translate(posX + offset.x, posY + offset.y); draw(canvas); canvas.restoreToCount(saveId); } }
final int c1 = canvas.save(); final int len = mItemList.size(); final float progress = thisView.isInEditMode() ? 1 : mProgress; canvas.save(); StoreHouseBarItem storeHouseBarItem = mItemList.get(i); float offsetX = mOffsetX + storeHouseBarItem.midPoint.x; canvas.translate(offsetX, offsetY); } else { canvas.translate(offsetX, offsetY); storeHouseBarItem.setAlpha(mBarDarkAlpha); } else { canvas.restore();
@Override protected void dispatchDraw(Canvas canvas) { final View thisView = this; final int width = thisView.getWidth(); final int height = thisView.getHeight(); float radius = (Math.min(width, height) - mCircleSpacing * 2) / 6; float x = width / 2 - (radius * 2 + mCircleSpacing); float y = height / 2; for (int i = 0; i < 3; i++) { canvas.save(); float translateX = x + (radius * 2) * i + mCircleSpacing * i; canvas.translate(translateX, y); canvas.scale(mScaleFloats[i], mScaleFloats[i]); canvas.drawCircle(0, 0, radius, mPaint); canvas.restore(); } super.dispatchDraw(canvas); }
@Override protected void onDraw(Canvas canvas) { if (imageOffset != 0) { final int saveCount = canvas.save(); canvas.translate(0f, imageOffset); super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); canvas.restoreToCount(saveCount); } else { super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); } }
/** * Draws a circle centered in the view. * * @param canvas the canvas to draw on * @param cx the center x coordinate * @param cy the center y coordinate * @param color the color to draw * @param pct the percentage of the view that the circle should cover */ private void drawCircle(Canvas canvas, float cx, float cy, int color, float pct) { mPaint.setColor(color); canvas.save(); canvas.translate(cx, cy); float radiusScale = INTERPOLATOR.getInterpolation(pct); canvas.scale(radiusScale, radiusScale); canvas.drawCircle(0, 0, cx, mPaint); canvas.restore(); }
public static void drawImage(Canvas canvas, Drawable drawable, int x, int y, int width, int height) { MPPointF drawOffset = MPPointF.getInstance(); drawOffset.x = x - (width / 2); drawOffset.y = y - (height / 2); drawable.copyBounds(mDrawableBoundsCache); drawable.setBounds( mDrawableBoundsCache.left, mDrawableBoundsCache.top, mDrawableBoundsCache.left + width, mDrawableBoundsCache.top + width); int saveId = canvas.save(); // translate to the correct position and draw canvas.translate(drawOffset.x, drawOffset.y); drawable.draw(canvas); canvas.restoreToCount(saveId); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final View thisView = this; final int paddingTop = thisView.getPaddingTop(); final int paddingLeft = thisView.getPaddingLeft(); final int paddingBottom = thisView.getPaddingBottom(); final int height = thisView.getHeight(); canvas.save(); if (height <= topCircle.radius * 2 + paddingTop + paddingBottom) { canvas.translate(paddingLeft, height - topCircle.radius * 2 - paddingBottom); canvas.drawCircle(topCircle.x, topCircle.y, topCircle.radius, mPaint); } else { canvas.translate(paddingLeft, paddingTop); makeBezierPath(); canvas.drawPath(mPath, mPaint); // canvas.drawCircle(topCircle.x, topCircle.y, topCircle.radius, mPaint); // canvas.drawCircle(bottomCircle.x, bottomCircle.y, bottomCircle.radius, mPaint); } canvas.restore(); }
private void drawShadowCorners(Canvas canvas, Rect bounds) { int saved = canvas.save(); if (!mHideTopShadow) { // left-top canvas.translate(bounds.left, bounds.top); canvas.drawPath(mCornerShadowTopPath, mCornerShadowPaint); canvas.restoreToCount(saved); // right-top saved = canvas.save(); canvas.translate(bounds.right, bounds.top); canvas.scale(-1f, 1f); canvas.drawPath(mCornerShadowTopPath, mCornerShadowPaint); canvas.restoreToCount(saved); } if (!mHideBottomShadow) { // right-bottom saved = canvas.save(); canvas.translate(bounds.right, bounds.bottom); canvas.scale(-1f, -1f); canvas.drawPath(mCornerShadowBottomPath, mCornerShadowPaint); canvas.restoreToCount(saved); // left-bottom saved = canvas.save(); canvas.translate(bounds.left, bounds.bottom); canvas.scale(1f, -1f); canvas.drawPath(mCornerShadowBottomPath, mCornerShadowPaint); canvas.restoreToCount(saved); } }
private void drawSky(Canvas canvas, int width, int height) { Matrix matrix = mMatrix; matrix.reset(); int bWidth = mDrawableSky.getBounds().width();//mSky.getWidth(); int bHeight = mDrawableSky.getBounds().height();//mSky.getHeight(); float townScale = 1f * width / bWidth; float offsetX = 0; float offsetY = height / 2 - bHeight / 2; // matrix.postScale(townScale, townScale); // matrix.postTranslate(offsetX, offsetY); // // canvas.drawBitmap(mSky, matrix, null); final int saveCount = canvas.getSaveCount(); canvas.save(); canvas.translate(offsetX, offsetY); matrix.postScale(townScale, townScale); mDrawableSky.draw(canvas); canvas.restoreToCount(saveCount); }
private void fillSwipingItemBackground(Canvas c, Drawable drawable, float scale) { final Rect bounds = mSwipingItemBounds; final int translationX = mTranslationX; final int translationY = mTranslationY; final float hScale = (mHorizontal) ? 1.0f : scale; final float vScale = (mHorizontal) ? scale : 1.0f; int width = (int) (hScale * bounds.width() + 0.5f); int height = (int) (vScale * bounds.height() + 0.5f); if ((height == 0) || (width == 0) || (drawable == null)) { return; } final int savedCount = c.save(); c.clipRect( bounds.left + translationX, bounds.top + translationY, bounds.left + translationX + width, bounds.top + translationY + height); // c.drawColor(0xffff0000); // <-- debug c.translate( bounds.left + translationX - (bounds.width() - width) / 2, bounds.top + translationY - (bounds.height() - height) / 2); drawable.setBounds(0, 0, bounds.width(), bounds.height()); drawable.draw(c); c.restoreToCount(savedCount); }
@Override public void draw(Canvas canvas) { if (mDrawable == null) { return; } final Rect bounds = getBounds(); final int saveCount = canvas.save(); canvas.translate(bounds.left, bounds.top); if (mShouldClipRect) { canvas.clipRect(0, 0, bounds.width(), bounds.height()); } if (mMatrix != null) { canvas.concat(mMatrix); } mDrawable.draw(canvas); canvas.restoreToCount(saveCount); }
@Override protected void onDraw(Canvas canvas) { if (imageOffset != 0) { canvas.save(); canvas.translate(0f, imageOffset); canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + imageOffset); super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); canvas.restore(); } else { super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); } }