List of usage examples for android.graphics Canvas drawRoundRect
public void drawRoundRect(@NonNull RectF rect, float rx, float ry, @NonNull Paint paint)
From source file:org.getlantern.firetweet.view.ShapedImageView.java
/** * Given the source bitmap and a canvas, draws the bitmap through a circular * mask. Only draws a circle with diameter equal to the destination width. * * @param bitmap The source bitmap to draw. * @param canvas The canvas to draw it on. * @param source The source bound of the bitmap. * @param dest The destination bound on the canvas. *///from w w w . jav a2 s .co m public void drawBitmapWithCircleOnCanvas(Bitmap bitmap, Canvas canvas, RectF source, @NonNull RectF dest) { if (bitmap == null) { if (getStyle() == SHAPE_CIRCLE) { canvas.drawCircle(dest.centerX(), dest.centerY(), Math.min(dest.width(), dest.height()) / 2f, mSolidColorPaint); } else { final float cornerRadius = getCalculatedCornerRadius(); canvas.drawRoundRect(dest, cornerRadius, cornerRadius, mSolidColorPaint); } return; } // Draw bitmap through shader first. final BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mMatrix.reset(); switch (getScaleType()) { case CENTER_CROP: { final float srcRatio = source.width() / source.height(); final float dstRatio = dest.width() / dest.height(); if (srcRatio > dstRatio) { // Source is wider than destination, fit height mTempDestination.top = dest.top; mTempDestination.bottom = dest.bottom; final float dstWidth = dest.height() * srcRatio; mTempDestination.left = dest.centerX() - dstWidth / 2; mTempDestination.right = dest.centerX() + dstWidth / 2; } else if (srcRatio < dstRatio) { mTempDestination.left = dest.left; mTempDestination.right = dest.right; final float dstHeight = dest.width() / srcRatio; mTempDestination.top = dest.centerY() - dstHeight / 2; mTempDestination.bottom = dest.centerY() + dstHeight / 2; } else { mTempDestination.set(dest); } break; } default: { mTempDestination.set(dest); break; } } // Fit bitmap to bounds. mMatrix.setRectToRect(source, mTempDestination, ScaleToFit.CENTER); shader.setLocalMatrix(mMatrix); mBitmapPaint.setShader(shader); if (mBorderEnabled) { final float inset = mBorderPaint.getStrokeWidth() / 2; if (getStyle() == SHAPE_CIRCLE) { final float circleRadius = Math.min(dest.width(), dest.height()) / 2f - inset / 2; canvas.drawCircle(dest.centerX(), dest.centerY(), circleRadius, mBitmapPaint); } else { final float cornerRadius = getCalculatedCornerRadius(); dest.inset(inset, inset); canvas.drawRoundRect(dest, cornerRadius, cornerRadius, mBitmapPaint); dest.inset(-inset, -inset); } } else { if (getStyle() == SHAPE_CIRCLE) { final float circleRadius = Math.min(dest.width(), dest.height()) / 2f; canvas.drawCircle(dest.centerX(), dest.centerY(), circleRadius, mBitmapPaint); } else { final float cornerRadius = getCalculatedCornerRadius(); canvas.drawRoundRect(dest, cornerRadius, cornerRadius, mBitmapPaint); } } }
From source file:com.wytiger.common.widget.SlideSwitch.java
@Override protected void onDraw(Canvas canvas) { if (mShape == SHAPE_RECT) { paint.setColor(Color.GRAY); canvas.drawRect(backRect, paint); paint.setColor(color_theme);//from w ww .j ava 2 s.c om paint.setAlpha(alpha); canvas.drawRect(backRect, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight() - RIM_SIZE); paint.setColor(Color.WHITE); canvas.drawRect(frontRect, paint); } else { // draw circle int radius; radius = backRect.height() / 2 - RIM_SIZE; paint.setColor(Color.GRAY); backCircleRect.set(backRect); canvas.drawRoundRect(backCircleRect, radius, radius, paint); paint.setColor(color_theme); paint.setAlpha(alpha); canvas.drawRoundRect(backCircleRect, radius, radius, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + backRect.height() - 2 * RIM_SIZE, backRect.height() - RIM_SIZE); frontCircleRect.set(frontRect); paint.setColor(Color.WHITE); canvas.drawRoundRect(frontCircleRect, radius, radius, paint); } }
From source file:com.xcyo.live.view.SlideSwitch.java
@Override protected void onDraw(Canvas canvas) { if (shape == SHAPE_RECT) { paint.setColor(Color.GRAY); canvas.drawRect(backRect, paint); paint.setColor(color_theme);/*from w w w . ja v a2 s .c o m*/ paint.setAlpha(alpha); canvas.drawRect(backRect, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight() - RIM_SIZE); paint.setColor(Color.WHITE); canvas.drawRect(frontRect, paint); } else { // draw circle int radius; radius = backRect.height() / 2; paint.setColor(Color.GRAY); backCircleRect.set(backRect); canvas.drawRoundRect(backCircleRect, radius, radius, paint); paint.setColor(color_theme); paint.setAlpha(alpha); canvas.drawRoundRect(backCircleRect, radius, radius, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + backRect.height() - 2 * RIM_SIZE, backRect.height() - RIM_SIZE); frontCircleRect.set(frontRect); paint.setColor(Color.WHITE); canvas.drawRoundRect(frontCircleRect, radius, radius, paint); } }
From source file:com.example.administrator.iclub21.view.SlideSwitch.java
@Override protected void onDraw(Canvas canvas) { if (shape == SHAPE_RECT) { paint.setColor(Color.GRAY); canvas.drawRect(backRect, paint); paint.setColor(color_theme);/* w w w . ja va2 s . c om*/ paint.setAlpha(alpha); canvas.drawRect(backRect, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight() - RIM_SIZE); paint.setColor(Color.WHITE); canvas.drawRect(frontRect, paint); } else { // draw circle int radius; radius = backRect.height() / 2 - RIM_SIZE; paint.setColor(Color.GRAY); backCircleRect.set(backRect); canvas.drawRoundRect(backCircleRect, radius, radius, paint); paint.setColor(color_theme); paint.setAlpha(alpha); canvas.drawRoundRect(backCircleRect, radius, radius, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + backRect.height() - 2 * RIM_SIZE, backRect.height() - RIM_SIZE); frontCircleRect.set(frontRect); paint.setColor(Color.WHITE); canvas.drawRoundRect(frontCircleRect, radius, radius, paint); } }
From source file:com.tcl.widget.demo.ui.widget.supercleaner.SlideSwitch.java
@Override protected void onDraw(Canvas canvas) { if (shape == SHAPE_RECT) { paint.setColor(Color.GRAY); canvas.drawRect(backRect, paint); paint.setColor(color_theme);//from w ww. jav a 2 s . c om paint.setAlpha(alpha); canvas.drawRect(backRect, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight() - RIM_SIZE); paint.setColor(Color.WHITE); canvas.drawRect(frontRect, paint); } else { // draw circle int radius; radius = backRect.height() / 2 - RIM_SIZE; paint.setColor(Color.GRAY); backCircleRect.set(backRect); canvas.drawRoundRect(backCircleRect, radius, radius, paint); paint.setColor(color_theme); paint.setAlpha(alpha); canvas.drawRoundRect(backCircleRect, radius, radius, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + backRect.height() - 2 * RIM_SIZE, backRect.height() - RIM_SIZE); frontCircleRect.set(frontRect); paint.setColor(Color.WHITE); canvas.drawRoundRect(frontCircleRect, radius, radius, paint); } }
From source file:com.mx.hb.moon.view.SlideSwitch.java
@Override protected void onDraw(Canvas canvas) { if (shape == SHAPE_RECT) {// paint.setColor(Color.LTGRAY); canvas.drawRect(backRect, paint); paint.setColor(color_theme);/*from www. j a va 2s . c o m*/ paint.setAlpha(alpha); canvas.drawRect(backRect, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight() - RIM_SIZE); paint.setColor(Color.WHITE); canvas.drawRect(frontRect, paint); } else {// int radius; radius = backRect.height() / 2 - RIM_SIZE; paint.setColor(Color.LTGRAY); backCircleRect.set(backRect); canvas.drawRoundRect(backCircleRect, radius, radius, paint); paint.setColor(color_theme); paint.setAlpha(alpha); canvas.drawRoundRect(backCircleRect, radius, radius, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + backRect.height() - 2 * RIM_SIZE, backRect.height() - RIM_SIZE); frontCircleRect.set(frontRect); paint.setColor(Color.WHITE); canvas.drawRoundRect(frontCircleRect, radius, radius, paint); } }
From source file:com.dean.phonesafe.ui.SlideSwitch.java
@Override protected void onDraw(Canvas canvas) { if (shape == SHAPE_RECT) { paint.setColor(Color.GRAY); canvas.drawRect(backRect, paint); paint.setColor(color_theme);//from w w w .ja v a 2 s . c om paint.setAlpha(alpha); canvas.drawRect(backRect, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight() - RIM_SIZE); paint.setColor(Color.WHITE); canvas.drawRect(frontRect, paint); } else { // draw circle int radius; radius = backRect.height() / 2 - RIM_SIZE; paint.setColor(Color.GRAY); backCircleRect.set(backRect); canvas.drawRoundRect(backCircleRect, radius, radius, paint); paint.setColor(color_theme); paint.setAlpha(alpha); canvas.drawRoundRect(backCircleRect, radius, radius, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + backRect.height() - 2 * RIM_SIZE, backRect.height() - RIM_SIZE); frontCircleRect.set(frontRect); paint.setColor(Color.WHITE); canvas.drawRoundRect(frontCircleRect, radius, radius, paint); } //?? //? paint.setStrokeWidth(2); paint.setAlpha(alpha); paint.setStyle(Paint.Style.STROKE); float gap = backRect.width() - frontRect.width(); float left = frontRect.left - gap + frontRect.width() / 2; canvas.drawLine(left, backRect.height() / 4, left, backRect.height() / 4 * 3, paint); //?? paint.setAlpha(255 - alpha); left = frontRect.left + gap + frontRect.width() / 2; canvas.drawCircle(left, backRect.height() / 2, frontRect.width() / 5, paint); // paint.setStyle(Paint.Style.FILL); }
From source file:info.awesomedevelopment.tvgrid.library.TVGridView.java
/** * Helper method to paint the canvas used in generate bitmap * * @param canvas the canvas used to draw onto * @param rectF size//from ww w . j av a 2s . c o m * @param paint paint */ private void paintCanvas(Canvas canvas, RectF rectF, Paint paint) { if (mSelectorShape == RECTANGLE) { canvas.drawRoundRect(rectF, mCornerRadiusX, mCornerRadiusY, paint); } else if (mSelectorShape == CIRCLE) { canvas.drawCircle(rectF.centerX(), rectF.centerY(), rectF.width() / 2, paint); } else { throw new IllegalArgumentException("Selector shape must be one of RECTANGLE or CIRCLE"); } }
From source file:com.yk.notification.util.BitmapUtil.java
/** * /*from w w w . ja v a2 s . c o m*/ * * @param bitmap * ?Bitmap * @param roundPx * ? * @return Bitmap */ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:com.gxy.fastscrollrecyclerview.views.FastScroller.java
public void draw(Canvas canvas) { if (mThumbPosition.x < 0 || mThumbPosition.y < 0) { return;// ww w . jav a 2 s . c o m } //Background () // canvas.drawRect(mThumbPosition.x + mOffset.x, mThumbHeight / 2 + mOffset.y, mThumbPosition.x + mOffset.x + mWidthBg, mRecyclerView.getHeight() + mOffset.y - mThumbHeight / 2, mTrack); //Handle ? // canvas.drawRect(mThumbPosition.x + mOffset.x, mThumbPosition.y + mOffset.y, mThumbPosition.x + mOffset.x + mWidth, mThumbPosition.y + mOffset.y + mThumbHeight, mThumb); // ? RectF oval3 = new RectF(mThumbPosition.x + mOffset.x, mThumbPosition.y + mOffset.y, mThumbPosition.x + mOffset.x + mWidth, mThumbPosition.y + mOffset.y + mThumbHeight);// canvas.drawRoundRect(oval3, (float) 2.2, 16, mThumb); //Popup mPopup.draw(canvas); }