Example usage for android.graphics Canvas drawRoundRect

List of usage examples for android.graphics Canvas drawRoundRect

Introduction

In this page you can find the example usage for android.graphics Canvas drawRoundRect.

Prototype

public void drawRoundRect(@NonNull RectF rect, float rx, float ry, @NonNull Paint paint) 

Source Link

Document

Draw the specified round-rect using the specified paint.

Usage

From source file:com.qjay.android_widget.badge.BGADragBadgeView.java

private void drawTextBadge(Canvas canvas) {
    // // w  w  w.j  av a2s  . com
    mBadgePaint.setColor(mBadgeViewHelper.getBadgeBgColor());
    // 
    canvas.drawRoundRect(
            new RectF(mStartX, mStartY, mStartX + mBadgeViewHelper.getBadgeRectF().width(),
                    mStartY + mBadgeViewHelper.getBadgeRectF().height()),
            mBadgeViewHelper.getBadgeRectF().height() / 2, mBadgeViewHelper.getBadgeRectF().height() / 2,
            mBadgePaint);

    // 
    mBadgePaint.setColor(mBadgeViewHelper.getBadgeTextColor());
    float x = mStartX + mBadgeViewHelper.getBadgeRectF().width() / 2;
    // ?y?
    float y = mStartY + mBadgeViewHelper.getBadgeRectF().height() - mBadgeViewHelper.getBadgePadding();
    // 
    String badgeText = mBadgeViewHelper.getBadgeText() == null ? "" : mBadgeViewHelper.getBadgeText();
    canvas.drawText(badgeText, x, y, mBadgePaint);
}

From source file:android.support.v17.leanback.widget.SeekBar.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    final int radius = isFocused() ? mActiveRadius : mBarHeight / 2;
    canvas.drawRoundRect(mBackgroundRect, radius, radius, mBackgroundPaint);
    canvas.drawRoundRect(mSecondProgressRect, radius, radius, mProgressPaint);
    canvas.drawRoundRect(mProgressRect, radius, radius, mProgressPaint);
    canvas.drawCircle(mKnobx, getHeight() / 2, radius, mKnobPaint);
}

From source file:com.serchinastico.coolswitch.CoolSwitch.java

private void drawBackground(Canvas canvas) {
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.BLACK);/*from w ww  . j ava2  s.c o  m*/
    paint.setAlpha(backgroundAlpha);
    canvas.drawRoundRect(backgroundRect, selectorRadius, selectorRadius, paint);
}

From source file:com.serchinastico.coolswitch.CoolSwitch.java

private void drawBorder(Canvas canvas) {
    paint.setStrokeWidth(BORDER_WIDTH);/*from   ww  w  . ja  v a2 s .  c  o  m*/
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.WHITE);
    canvas.drawRoundRect(backgroundRect, selectorRadius, selectorRadius, paint);
}

From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java

private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {

    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);
    final float roundPx = pixels;

    paint.setAntiAlias(true);/*from   ww  w  .j  a va 2 s . co  m*/
    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:nuclei.ui.view.GlideImageView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mBorderRect != null && mBorderPaint != null) {
        if (mRadius > 0)
            canvas.drawRoundRect(mBorderRect, mRadius, mRadius, mBorderPaint);
        else if (mCircle)
            canvas.drawCircle(mBorderRect.centerX(), mBorderRect.centerY(), mBorderRect.width() / 2,
                    mBorderPaint);//w  ww.  j  a  v a2 s .  com
        else
            canvas.drawRect(mBorderRect, mBorderPaint);
    }
}

From source file:com.test.slidebutton.SlideButton.java

@Override
protected void onDraw(Canvas canvas) {

    paint.setColor(backCurrentColor);//from   w w  w . j  ava 2s .c  o  m
    canvas.drawRoundRect(rectfBack, backArcRadius, backArcRadius, paint);

    rectfSlider.set(sliderCurrentLeft, RIM_SIZE, sliderCurrentLeft + silderWidth, RIM_SIZE + silderWidth);
    paint.setColor(colorSlider);
    canvas.drawRoundRect(rectfSlider, sliderArcRadius, sliderArcRadius, paint);
}

From source file:com.clov4r.moboplayer.android.nil.codec.activity.MoboThumbnailTestActivity.java

public Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
    try {/*from   w w  w  .jav  a 2 s.com*/
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(output);
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        final RectF rectF = new RectF(new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()));
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(Color.BLACK);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        final Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

        canvas.drawBitmap(bitmap, src, rect, paint);
        return output;
    } catch (Exception e) {
        return bitmap;
    }
}

From source file:me.lizheng.deckview.views.DeckChildViewHeader.java

@SuppressLint("DrawAllocation")
@Override// www .  j a v  a  2  s . com
protected void onDraw(Canvas canvas) {
    // Draw the highlight at the top edge (but put the bottom edge just out of view)
    float offset = (float) Math.ceil(mConfig.taskViewHighlightPx / 2f);
    float radius = mConfig.taskViewRoundedCornerRadiusPx;
    int count = canvas.save(Canvas.CLIP_SAVE_FLAG);
    canvas.clipRect(0, 0, getMeasuredWidth(), getMeasuredHeight());
    canvas.drawRoundRect(
            new RectF(-offset, 0f, (float) getMeasuredWidth() + offset, getMeasuredHeight() + radius), radius,
            radius, sHighlightPaint);
    canvas.restoreToCount(count);
}

From source file:com.bdcorps.videonews.MainActivity.java

public void grabnews(String topicCode) {
    int pos = article;
    try {/*w ww  . j a v a 2s .  c  o m*/

        JSONArray a = Config.initNewsRequest(topicCode);

        //  for (int i = 0; i<json.getInt("num_results");i++)
        {
            final JSONObject b = (JSONObject) a.get(article);
            JSONArray c = b.getJSONArray("multimedia");
            if (c.length() > 4) {
                JSONObject d = (JSONObject) c.get(4);
                String url = d.getString("url");
                final String title = b.getString("title");
                try {
                    new DownloadImageTask(new DownloadImageTask.AsyncResponse() {

                        @Override
                        public void processFinish(Bitmap result) {
                            Paint myRectPaint = new Paint();
                            int x1 = 0;
                            int y1 = 0;
                            int x2 = 500;
                            int y2 = 500;

                            //Create a new image bitmap and attach a brand new canvas to it
                            Bitmap tempBitmap = Bitmap.createBitmap(result.getWidth(), result.getHeight(),
                                    Bitmap.Config.RGB_565);
                            Canvas tempCanvas = new Canvas(tempBitmap);

                            //Draw the image bitmap into the cavas
                            tempCanvas.drawBitmap(result, 0, 0, null);

                            //Draw everything else you want into the canvas, in this example a rectangle with rounded edges
                            tempCanvas.drawRoundRect(new RectF(x1, y1, x2, y2), 2, 2, myRectPaint);
                            titleTextView.setText(title);
                            img.setImageBitmap(tempBitmap);
                        }
                    }, img).execute(url).get();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            text.setText(b.getString("abstract"));
                            Log.i("SSS", "abstract is = " + text.getText().toString());
                            canSpeak = true;
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
            } else {

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getBaseContext(), "multimedia does not exist", Toast.LENGTH_LONG).show();
                    }
                });
                article++;
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

}