Java Code Examples for android.graphics.Canvas.drawRect()

The following are Jave code examples for showing how to use drawRect() of the android.graphics.Canvas class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: boohee_v5.6   File: AbstractChartRenderer.java   View Source Code Vote up 6 votes
protected void drawLabelTextAndBackground(Canvas canvas, char[] labelBuffer, int startIndex, int numChars, int autoBackgroundColor) {
    float textX;
    float textY;
    if (this.isValueLabelBackgroundEnabled) {
        if (this.isValueLabelBackgroundAuto) {
            this.labelBackgroundPaint.setColor(autoBackgroundColor);
        }
        canvas.drawRect(this.labelBackgroundRect, this.labelBackgroundPaint);
        textX = this.labelBackgroundRect.left + ((float) this.labelMargin);
        textY = this.labelBackgroundRect.bottom - ((float) this.labelMargin);
    } else {
        textX = this.labelBackgroundRect.left;
        textY = this.labelBackgroundRect.bottom;
    }
    if (labelBuffer[startIndex] != '0') {
        canvas.drawText(labelBuffer, startIndex, numChars, textX, textY, this.labelPaint);
    }
}
 
Example 2
Project: mupdf-android-viewer-nui   File: DocPageView.java   View Source Code Vote up 5 votes
private void renderNoPage(Bitmap bitmap, final RenderListener listener, Rect localVisRect, Rect globalVisRect)
{
	//  specify where to draw to and from
	mDrawBitmap = bitmap;
	mDrawSrcRect.set(globalVisRect);
	mDrawDstRect.set(localVisRect);

	//  make a rect representing the entire page in screen coordinates
	int[] locations = new int[2];
	getLocationOnScreen(locations);
	Rect pageRect = new Rect(locations[0], locations[1], locations[0] + getWidth(), locations[1] + getHeight());

	//  draw a yellow page with a red border containing the page number

	Paint p = new Paint();
	Canvas c = new Canvas(bitmap);
	p.setColor(Color.RED);
	p.setStyle(Paint.Style.FILL);
	c.drawRect(pageRect, p);

	Rect smaller = new Rect(pageRect);
	int inset = (int) (40 * mScale);
	smaller.inset(inset, inset);
	p.setColor(Color.YELLOW);
	p.setStyle(Paint.Style.FILL);
	c.drawRect(smaller, p);

	String s = "" + (mPageNum + 1);
	p.setColor(Color.BLACK);
	p.setTextSize(200.0f * mScale);
	c.drawText(s, pageRect.left + (90 * mScale), pageRect.top + (290 * mScale), p);

	invalidate();
	listener.progress(0);
}
 
Example 3
Project: javaide   File: AlphaSlider.java   View Source Code Vote up 5 votes
@Override
protected void drawBar(Canvas barCanvas) {
	int width = barCanvas.getWidth();
	int height = barCanvas.getHeight();

	barCanvas.drawRect(0, 0, width, height, alphaPatternPaint);
	int l = Math.max(2, width / 256);
	for (int x = 0; x <= width; x += l) {
		float alpha = (float) x / (width - 1);
		barPaint.setColor(color);
		barPaint.setAlpha(Math.round(alpha * 255));
		barCanvas.drawRect(x, 0, x + l, height, barPaint);
	}
}
 
Example 4
Project: Multi-SwipeToRefreshLayout   File: CubeTransitionIndicator.java   View Source Code Vote up 5 votes
@Override
public void draw(Canvas canvas, Paint paint) {
    float rWidth=getWidth()/5;
    float rHeight=getHeight()/5;
    for (int i = 0; i < 2; i++) {
        canvas.save();
        canvas.translate(translateX[i], translateY[i]);
        canvas.rotate(degrees);
        canvas.scale(scaleFloat,scaleFloat);
        RectF rectF=new RectF(-rWidth/2,-rHeight/2,rWidth/2,rHeight/2);
        canvas.drawRect(rectF,paint);
        canvas.restore();
    }
}
 
Example 5
Project: Picasso-transformations   File: RoundedCornersTransformation.java   View Source Code Vote up 5 votes
private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
  canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
      paint);
  canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
      paint);
  canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
}
 
Example 6
Project: ColumnAnimViewProject   File: CanvasTestView.java   View Source Code Vote up 5 votes
private void scaleTest02(Canvas canvas) {
    canvas.translate(mWidth / 2, mHeight / 2);
    paint.setColor(Color.RED);
    Rect rect = new Rect(0, -400, 400, 0);
    canvas.drawRect(rect, paint);
    canvas.save();
    canvas.scale(0.5f, 0.5f, 200, 0);
    paint.setColor(Color.BLUE);
    canvas.drawRect(rect, paint);
    canvas.restore();
}
 
Example 7
Project: Bigbang   File: AlphaSlider.java   View Source Code Vote up 5 votes
@Override
protected void drawBar(Canvas barCanvas) {
	int width = barCanvas.getWidth();
	int height = barCanvas.getHeight();

	barCanvas.drawRect(0, 0, width, height, alphaPatternPaint);
	int l = Math.max(2, width / 256);
	for (int x = 0; x <= width; x += l) {
		float alpha = (float) x / (width - 1);
		barPaint.setColor(color);
		barPaint.setAlpha(Math.round(alpha * 255));
		barCanvas.drawRect(x, 0, x + l, height, barPaint);
	}
}
 
Example 8
Project: reflow-animator   File: ReflowTextAnimatorHelper.java   View Source Code Vote up 5 votes
private static void drawLayerBounds(@Nonnull Canvas canvas,
                                    @Nonnull Rect bounds,
                                    int sectionNumber,
                                    @Nonnull Paint fillPaint,
                                    @Nonnull Paint outlinePaint,
                                    @Nonnull Paint textPaint) {
    Rect startRect = new Rect(bounds.left + 1, bounds.top + 1, bounds.right - 1, bounds.bottom - 1);
    canvas.drawRect(startRect, fillPaint);
    canvas.drawRect(startRect, outlinePaint);
    canvas.drawText("" + sectionNumber, bounds.left + 6, bounds.top + 21, textPaint);
}
 
Example 9
Project: Waffle   File: BarGraphView.java   View Source Code Vote up 5 votes
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    int width = this.getWidth();
    int height = this.getHeight();

    double barHeight = 0.0;
    if(mPercent > 0){
        barHeight = mPercent / 100 * height;
    }

    mPaint.setColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
    canvas.drawRect(0, height-(float)barHeight, width, height, mPaint);
}
 
Example 10
Project: Widgets   File: RvDivider.java   View Source Code Vote up 5 votes
private void drawVertical(Canvas c, RecyclerView parent) {
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();

    int childCount = parent.getChildCount();
    int top, bottom;

    View child = null;
    RecyclerView.LayoutParams params = null;
    for (int i = 0; i < childCount; i++) {
        child = parent.getChildAt(i);
        params = (RecyclerView.LayoutParams) child.getLayoutParams();

        if (i == 0) {
            //如果是第一个元素,就绘制上边线
            //child.getTop() - params.topMargin 得到的是child的y起点坐标,需要在该y坐标之前绘制宽度为mWidth的线,所以需要减mWidth
            top = child.getTop() - params.topMargin - mWidthPx;
            bottom = top + mWidthPx;
            //绘制上边线
            c.drawRect(left, top, right, bottom, mPaint);
        }

        top = child.getBottom() + params.bottomMargin;
        bottom = top + mWidthPx;

        c.drawRect(left, top, right, bottom, mPaint);
    }
}
 
Example 11
Project: airgram   File: Emoji.java   View Source Code Vote up 5 votes
@Override
public void draw(Canvas canvas) {
    if (emojiBmp[info.page][info.page2] == null) {
        if (loadingEmoji[info.page][info.page2]) {
            return;
        }
        loadingEmoji[info.page][info.page2] = true;
        Utilities.globalQueue.postRunnable(new Runnable() {
            @Override
            public void run() {
                loadEmoji(info.page, info.page2);
                loadingEmoji[info.page][info.page2] = false;
            }
        });
        canvas.drawRect(getBounds(), placeholderPaint);
        return;
    }

    Rect b;
    if (fullSize) {
        b = getDrawRect();
    } else {
        b = getBounds();
    }

    //if (!canvas.quickReject(b.left, b.top, b.right, b.bottom, Canvas.EdgeType.AA)) {
        canvas.drawBitmap(emojiBmp[info.page][info.page2], info.rect, b, paint);
    //}
}
 
Example 12
Project: SlidingSwitch   File: SlidingSwitchBase.java   View Source Code Vote up 5 votes
@Override
protected void onDraw(Canvas canvas) {
    if (mShape == SHAPE_RECT) {
        mPaint.setColor(mBgColor);
        canvas.drawRect(mBackRect, mPaint);
        mPaint.setAlpha(mAlpha);
        canvas.drawRect(mBackRect, mPaint);
        mFrontRect.set(mFrontRectLeft, RIM_SIZE, mFrontRectLeft
                + getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight()
                - RIM_SIZE);
        mPaint.setColor(mFgColor);
        canvas.drawRect(mFrontRect, mPaint);

        if (mClippableView != null) {
            ViewCompat.setClipBounds(mClippableView, mFrontRect);
        }
    } else {
        // draw circle
        int radius;
        radius = mBackRect.height() / 2 - RIM_SIZE;
        mPaint.setColor(mBgColor);
        mBackCircleRect.set(mBackRect);
        canvas.drawRoundRect(mBackCircleRect, radius, radius, mPaint);
        mPaint.setColor(mFgColor);
        mPaint.setAlpha(mAlpha);
        canvas.drawRoundRect(mBackCircleRect, radius, radius, mPaint);
        mFrontRect.set(mFrontRectLeft, RIM_SIZE, mFrontRectLeft
                + mBackRect.height() - 2 * RIM_SIZE, mBackRect.height()
                - RIM_SIZE);
        mFrontCircleRect.set(mFrontRect);
        mPaint.setColor(Color.WHITE);
        canvas.drawRoundRect(mFrontCircleRect, radius, radius, mPaint);
    }
}
 
Example 13
Project: SmartChart   File: SmartTabStrip.java   View Source Code Vote up 5 votes
private void drawUnderline(Canvas canvas, int left, int right, int height) {
  if (bottomBorderThickness <= 0) {
    return;
  }
  // Thin underline along the entire bottom edge
  borderPaint.setColor(bottomBorderColor);
  canvas.drawRect(left, height - bottomBorderThickness, right, height, borderPaint);
}
 
Example 14
Project: RLibrary   File: ImageUtils.java   View Source Code Vote up 5 votes
/**
 * 添加倒影
 *
 * @param src              源图片的
 * @param reflectionHeight 倒影高度
 * @param recycle          是否回收
 * @return 带倒影图片
 */
public static Bitmap addReflection(Bitmap src, int reflectionHeight, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    // 原图与倒影之间的间距
    final int REFLECTION_GAP = 0;
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight - reflectionHeight,
            srcWidth, reflectionHeight, matrix, false);
    Bitmap ret = Bitmap.createBitmap(srcWidth, srcHeight + reflectionHeight, src.getConfig());
    Canvas canvas = new Canvas(ret);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.drawBitmap(reflectionBitmap, 0, srcHeight + REFLECTION_GAP, null);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    LinearGradient shader = new LinearGradient(0, srcHeight,
            0, ret.getHeight() + REFLECTION_GAP,
            0x70FFFFFF, 0x00FFFFFF, Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawRect(0, srcHeight + REFLECTION_GAP,
            srcWidth, ret.getHeight(), paint);
    if (!reflectionBitmap.isRecycled()) reflectionBitmap.recycle();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 15
Project: FriendBook   File: PagerSlidingTabStrip.java   View Source Code Vote up 4 votes
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);

	if (isInEditMode() || tabCount == 0) {
		return;
	}

	final int height = getHeight();

	// draw indicator line

	rectPaint.setColor(indicatorColor);

	// default: line below current tab
	View currentTab = tabsContainer.getChildAt(currentPosition);

	float textViewContentWidth = getTextViewContentWidth((TextView) currentTab);
	int indicatorSpac = (int) ((TextView) currentTab).getWidth();

	float lineLeft = currentTab.getLeft();
	float lineRight = currentTab.getRight();

	// if there is an offset, start interpolating left and right coordinates
	// between current and next tab
	if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

		View nextTab = tabsContainer.getChildAt(currentPosition + 1);
		textViewContentWidth = getTextViewContentWidth((TextView) currentTab);
		indicatorSpac = (int) ((TextView) currentTab).getWidth();

		final float nextTabLeft = nextTab.getLeft();
		final float nextTabRight = nextTab.getRight();

		lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset)
				* lineLeft);
		lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset)
				* lineRight);
	}
	if (indicatorWrapContent) { 
		canvas.drawRect(lineLeft - wrapAddWidth+getPaddingLeft()
				+ (indicatorSpac - textViewContentWidth) / 2, height
				- indicatorHeight,
				lineRight+getPaddingLeft() - (indicatorSpac - textViewContentWidth) / 2
						+ wrapAddWidth, height, rectPaint);

	} else {
		canvas.drawRect(lineLeft+getPaddingLeft(), height - indicatorHeight, lineRight+getPaddingLeft(),
				height, rectPaint);
	}
	// draw underline

	rectPaint.setColor(underlineColor);
	canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(),
			height, rectPaint);

	// draw divider

	dividerPaint.setColor(dividerColor);
	for (int i = 0; i < tabCount - 1; i++) {
		View tab = tabsContainer.getChildAt(i);
		canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(),
				height - dividerPadding, dividerPaint);
	}
}
 
Example 16
Project: chat-sdk-android-push-firebase   File: PagerSlidingTabStrip.java   View Source Code Vote up 4 votes
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);

	if (isInEditMode() || tabCount == 0) {
		return;
	}

	final int height = getHeight();

	// draw indicator line

	rectPaint.setColor(indicatorColor);

	// default: line below current tab
	View currentTab = tabsContainer.getChildAt(currentPosition);
	float lineLeft = currentTab.getLeft();
	float lineRight = currentTab.getRight();

	// if there is an offset, start interpolating left and right coordinates between current and next tab
	if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

		View nextTab = tabsContainer.getChildAt(currentPosition + 1);
		final float nextTabLeft = nextTab.getLeft();
		final float nextTabRight = nextTab.getRight();

		lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
		lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
	}

	canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);

	// draw underline

	rectPaint.setColor(underlineColor);
	canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

	// draw divider

	dividerPaint.setColor(dividerColor);
	for (int i = 0; i < tabCount - 1; i++) {
		View tab = tabsContainer.getChildAt(i);
		canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
	}
}
 
Example 17
Project: LaunchEnr   File: HolographicOutlineHelper.java   View Source Code Vote up 4 votes
/**
 * Applies a more expensive and accurate outline to whatever is currently drawn in a specified
 * bitmap.
 */
public void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas) {

    // We start by removing most of the alpha channel so as to ignore shadows, and
    // other types of partial transparency when defining the shape of the object
    byte[] pixels = new byte[srcDst.getWidth() * srcDst.getHeight()];
    ByteBuffer buffer = ByteBuffer.wrap(pixels);
    buffer.rewind();
    srcDst.copyPixelsToBuffer(buffer);

    for (int i = 0; i < pixels.length; i++) {
        if ((pixels[i] & 0xFF) < 188) {
            pixels[i] = 0;
        }
    }

    buffer.rewind();
    srcDst.copyPixelsFromBuffer(buffer);

    // calculate the outer blur first
    mBlurPaint.setMaskFilter(mMediumOuterBlurMaskFilter);
    int[] outerBlurOffset = new int[2];
    Bitmap thickOuterBlur = srcDst.extractAlpha(mBlurPaint, outerBlurOffset);

    mBlurPaint.setMaskFilter(mThinOuterBlurMaskFilter);
    int[] brightOutlineOffset = new int[2];
    Bitmap brightOutline = srcDst.extractAlpha(mBlurPaint, brightOutlineOffset);

    // calculate the inner blur
    srcDstCanvas.setBitmap(srcDst);
    srcDstCanvas.drawColor(0xFF000000, PorterDuff.Mode.SRC_OUT);
    mBlurPaint.setMaskFilter(mMediumInnerBlurMaskFilter);
    int[] thickInnerBlurOffset = new int[2];
    Bitmap thickInnerBlur = srcDst.extractAlpha(mBlurPaint, thickInnerBlurOffset);

    // mask out the inner blur
    srcDstCanvas.setBitmap(thickInnerBlur);
    srcDstCanvas.drawBitmap(srcDst, -thickInnerBlurOffset[0],
            -thickInnerBlurOffset[1], mErasePaint);
    srcDstCanvas.drawRect(0, 0, -thickInnerBlurOffset[0], thickInnerBlur.getHeight(),
            mErasePaint);
    srcDstCanvas.drawRect(0, 0, thickInnerBlur.getWidth(), -thickInnerBlurOffset[1],
            mErasePaint);

    // draw the inner and outer blur
    srcDstCanvas.setBitmap(srcDst);
    srcDstCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
    srcDstCanvas.drawBitmap(thickInnerBlur, thickInnerBlurOffset[0], thickInnerBlurOffset[1],
            mDrawPaint);
    srcDstCanvas.drawBitmap(thickOuterBlur, outerBlurOffset[0], outerBlurOffset[1],
            mDrawPaint);

    // draw the bright outline
    srcDstCanvas.drawBitmap(brightOutline, brightOutlineOffset[0], brightOutlineOffset[1],
            mDrawPaint);

    // cleanup
    srcDstCanvas.setBitmap(null);
    brightOutline.recycle();
    thickOuterBlur.recycle();
    thickInnerBlur.recycle();
}
 
Example 18
Project: XERUNG   File: MaterialSpinner.java   View Source Code Vote up 4 votes
@Override
protected void onDraw(Canvas canvas) {

    super.onDraw(canvas);

    int startX = 0;
    int endX = getWidth();
    int lineHeight;

    int startYLine = getHeight() - getPaddingBottom() + underlineTopSpacing;
    int startYFloatingLabel = (int) (getPaddingTop() - floatingLabelPercent * floatingLabelBottomSpacing);

    if (error != null) {
        lineHeight = dpToPx(thicknessError);
        int startYErrorLabel = startYLine + errorLabelSpacing + lineHeight;
        paint.setColor(errorColor);
        textPaint.setColor(errorColor);
        //Error Label Drawing
        if (multiline) {
            canvas.save();
            canvas.translate(startX + rightLeftSpinnerPadding, startYErrorLabel - errorLabelSpacing);
            staticLayout.draw(canvas);
            canvas.restore();

        } else {
            //scrolling
            canvas.drawText(error.toString(), startX + rightLeftSpinnerPadding - errorLabelPosX, startYErrorLabel, textPaint);
            canvas.save();
            canvas.translate(textPaint.measureText(error.toString()) + getWidth() / 2, 0);
            canvas.drawText(error.toString(), startX + rightLeftSpinnerPadding - errorLabelPosX, startYErrorLabel, textPaint);
            canvas.restore();
        }

    } else {
        lineHeight = dpToPx(thickness);
        if (isSelected) {
            paint.setColor(highlightColor);
        } else {
            paint.setColor(isEnabled() ? baseColor : disabledColor);
        }
    }

    // Underline Drawing
    canvas.drawRect(startX, startYLine, endX, startYLine + lineHeight, paint);

    //Floating Label Drawing
    if (hint != null || floatingLabelText != null) {
        if (isSelected) {
            textPaint.setColor(highlightColor);
        } else {
            textPaint.setColor(isEnabled() ? floatingLabelColor : disabledColor);
        }
        if (floatingLabelAnimator.isRunning() || !floatingLabelVisible) {
            textPaint.setAlpha((int) ((0.8 * floatingLabelPercent + 0.2) * baseAlpha * floatingLabelPercent));
        }
        String textToDraw = floatingLabelText != null ? floatingLabelText.toString() : hint.toString();
        canvas.drawText(textToDraw, startX + rightLeftSpinnerPadding, startYFloatingLabel, textPaint);
    }

    drawSelector(canvas, getWidth() - rightLeftSpinnerPadding, getPaddingTop() + dpToPx(8));


}
 
Example 19
Project: exciting-app   File: MyHighlightView.java   View Source Code Vote up 4 votes
private void drawAnchors(Canvas canvas) {
      // 获取经matrix映射之后的值
      RectF handleRectF = caclelateRect();
      canvas.drawRect(mAuthorRect, mRectPaint);

      // 绘制操作按钮
      final int left = (int) (handleRectF.left);
      final int right = (int) (handleRectF.right);
      final int top = (int) (handleRectF.top);
      final int bottom = (int) (handleRectF.bottom);

      //前景
      if (stickerPaint.getType() == ConstantsPath.STICKER_TYPE_FOREGROUND) {
          mAnchorScale.draw(canvas);
          return;
      }

      if (mAnchorScale != null && canmovedepth) {
          // 右下角
          mAnchorScale.setBounds(right - mAnchorScaleWidth, bottom - mAnchorScaleHeight,
                  right + mAnchorScaleWidth, bottom + mAnchorScaleHeight);
          mAnchorScale.draw(canvas);
      }

/*// 左上角
       * setBounds(left - mAnchorDeleteWidth, top - mAnchorDeleteHeight, left + mAnchorDeleteWidth,
			top + mAnchorDeleteHeight)
 * */

      if (mAnchorReverse != null && canmovedepth && stickerPaint.getType() != ConstantsPath.COMMONTEXTSTICKER) {
          // 左下角
          mAnchorReverse.setBounds(left - mAnchorReverseWidth, bottom - mAnchorReverseHeight,
                  left + mAnchorReverseWidth, bottom + mAnchorReverseHeight);
          mAnchorReverse.draw(canvas);
      }

      if (mTextButton != null && canmovedepth
              && (textSrcRect != null || stickerPaint.getType() == ConstantsPath.COMMONTEXTSTICKER)) {
          // 正下方
          mTextButton.setBounds(left - mAnchorTextWidth + (right - left) / 2, bottom,
                  left + mAnchorTextWidth + (right - left) / 2, bottom + 2 * mAnchorTextHeight);
          mTextButton.draw(canvas);
      }

      if (mAnchorRotate != null && stickerPaint.getType() != ConstantsPath.COMMONTEXTSTICKER) {
          // 右上角
          mAnchorRotate.setBounds(right - mAnchorRotateWidth, top - mAnchorRotateHeight, right + mAnchorRotateWidth,
                  top + mAnchorRotateHeight);
          mAnchorRotate.draw(canvas);
      }
  }
 
Example 20
Project: pius1   File: RoundRectDrawableWithShadow.java   View Source Code Vote up 4 votes
private void drawShadow(Canvas canvas) {
    final float edgeShadowTop = -mCornerRadius - mShadowSize;
    final float inset = mCornerRadius + mInsetShadow + mRawShadowSize / 2;
    final boolean drawHorizontalEdges = mCardBounds.width() - 2 * inset > 0;
    final boolean drawVerticalEdges = mCardBounds.height() - 2 * inset > 0;
    // LT
    int saved = canvas.save();
    canvas.translate(mCardBounds.left + inset, mCardBounds.top + inset);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawHorizontalEdges) {
        canvas.drawRect(0, edgeShadowTop,
                mCardBounds.width() - 2 * inset, -mCornerRadius,
                mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
    // RB
    saved = canvas.save();
    canvas.translate(mCardBounds.right - inset, mCardBounds.bottom - inset);
    canvas.rotate(180f);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawHorizontalEdges) {
        canvas.drawRect(0, edgeShadowTop,
                mCardBounds.width() - 2 * inset, -mCornerRadius + mShadowSize,
                mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
    // LB
    saved = canvas.save();
    canvas.translate(mCardBounds.left + inset, mCardBounds.bottom - inset);
    canvas.rotate(270f);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawVerticalEdges) {
        canvas.drawRect(0, edgeShadowTop,
                mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
    // RT
    saved = canvas.save();
    canvas.translate(mCardBounds.right - inset, mCardBounds.top + inset);
    canvas.rotate(90f);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawVerticalEdges) {
        canvas.drawRect(0, edgeShadowTop,
                mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
}