Example usage for android.graphics Paint setAntiAlias

List of usage examples for android.graphics Paint setAntiAlias

Introduction

In this page you can find the example usage for android.graphics Paint setAntiAlias.

Prototype

public void setAntiAlias(boolean aa) 

Source Link

Document

Helper for setFlags(), setting or clearing the ANTI_ALIAS_FLAG bit AntiAliasing smooths out the edges of what is being drawn, but is has no impact on the interior of the shape.

Usage

From source file:cn.finalteam.galleryfinal.widget.FloatingActionButton.java

private Drawable createCircleDrawable(RectF circleRect, int color) {
    final Bitmap bitmap = Bitmap.createBitmap(mDrawableSize, mDrawableSize, Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);

    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(color);/*from ww  w  .  j ava 2  s .c  o m*/

    canvas.drawOval(circleRect, paint);

    return new BitmapDrawable(getResources(), bitmap);
}

From source file:com.liferay.mobile.screens.viewsets.defaultviews.userportrait.UserPortraitView.java

protected Paint getBorderPaint(float borderWidth, int color) {
    Paint borderPaint = new Paint();
    borderPaint.setAntiAlias(true);
    borderPaint.setColor(ContextCompat.getColor(getContext(), color));
    borderPaint.setStyle(Paint.Style.STROKE);
    borderPaint.setStrokeWidth(borderWidth);
    return borderPaint;
}

From source file:com.nextgis.maplib.display.SimpleLineStyle.java

@Override
public void onDraw(GeoGeometry geoGeometry, GISDisplay display) {
    GeoLineString line = (GeoLineString) geoGeometry;
    Paint lnPaint = new Paint();
    lnPaint.setColor(mColor);// w w  w  .jav  a2s .c om
    lnPaint.setStrokeWidth((float) (mWidth / display.getScale()));
    lnPaint.setStrokeCap(Paint.Cap.ROUND);
    lnPaint.setAntiAlias(true);

    List<GeoPoint> points = line.getPoints();
    float[] pts = new float[points.size() * 2];

    int counter = 0;
    for (GeoPoint pt : points) {
        pts[counter++] = (float) pt.getX();
        pts[counter++] = (float) pt.getY();
    }

    display.drawLines(pts, lnPaint);
}

From source file:com.blogspot.ksoichiro.viewIndicator.ViewIndicator.java

@SuppressLint("DrawAllocation")
@Override//from  ww w.j a va  2  s.co m
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Paint paint = new Paint();
    paint.setStrokeWidth(1);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setColor(Color.BLACK);
    paint.setAntiAlias(true);

    for (int i = 0; i < mNumOfViews; i++) {
        float cx = (getWidth() - (mNumOfViews - 1) * DISTANCE) / 2 + i * DISTANCE;
        float cy = getHeight() / 2.0f;
        if (mPosition == i) {
            paint.setStyle(Paint.Style.FILL_AND_STROKE);
        } else {
            paint.setStyle(Paint.Style.STROKE);
        }
        canvas.drawCircle(cx, cy, RADIUS, paint);
    }
}

From source file:com.snippet.widget.ViewIndicator.java

@SuppressLint("DrawAllocation")
@Override// w  w w .  j  ava2s  . c  o m
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Paint paint = new Paint();
    paint.setStrokeWidth(1);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setColor(Color.BLACK);
    paint.setAntiAlias(true);

    for (int i = 0; i < mNumOfViews; i++) {
        float cx = (getWidth() - (mNumOfViews - 1) * mDistance) / 2 + i * mDistance;
        float cy = getHeight() / 2.0f;
        if (mPosition == i) {
            paint.setStyle(Paint.Style.FILL_AND_STROKE);
        } else {
            paint.setStyle(Paint.Style.STROKE);
        }
        canvas.drawCircle(cx, cy, mRadius, paint);
    }
}

From source file:org.onebusaway.android.map.googlemapsv2.StopOverlay.java

/**
 * Creates a bus stop icon with the given direction arrow, or without a direction arrow if
 * the direction is NO_DIRECTION//from  w w w  .  ja v  a 2 s.com
 *
 * @param direction Bus stop direction, obtained from ObaStop.getDirection() and defined in
 *                  constants in this class, or NO_DIRECTION if the stop icon shouldn't have a
 *                  direction arrow
 * @return a bus stop icon bitmap with the arrow pointing the given direction, or with no arrow
 * if direction is NO_DIRECTION
 */
private static Bitmap createBusStopIcon(String direction) throws NullPointerException {
    if (direction == null) {
        throw new IllegalArgumentException(direction);
    }

    Resources r = Application.get().getResources();
    Context context = Application.get();

    Float directionAngle = null; // 0-360 degrees
    Bitmap bm;
    Canvas c;
    Drawable shape;
    Float rotationX = null, rotationY = null; // Point around which to rotate the arrow

    Paint arrowPaintFill = new Paint();
    arrowPaintFill.setStyle(Paint.Style.FILL);
    arrowPaintFill.setAntiAlias(true);

    if (direction.equals(NO_DIRECTION)) {
        // Don't draw the arrow
        bm = Bitmap.createBitmap(mPx, mPx, Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, bm.getWidth(), bm.getHeight());
    } else if (direction.equals(NORTH)) {
        directionAngle = 0f;
        bm = Bitmap.createBitmap(mPx, (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, (int) mBuffer, mPx, bm.getHeight());
        // Shade with darkest color at tip of arrow
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth() / 2, 0, bm.getWidth() / 2, mArrowHeightPx,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // For NORTH, no rotation occurs - use center of image anyway so we have some value
        rotationX = bm.getWidth() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(NORTH_WEST)) {
        directionAngle = 315f; // Arrow is drawn N, rotate 315 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds((int) mBuffer, (int) mBuffer, bm.getWidth(), bm.getHeight());
        // Shade with darkest color at tip of arrow
        arrowPaintFill.setShader(new LinearGradient(0, 0, mBuffer, mBuffer, r.getColor(R.color.theme_primary),
                r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // Rotate around below coordinates (trial and error)
        rotationX = mPx / 2f + mBuffer / 2f;
        rotationY = bm.getHeight() / 2f - mBuffer / 2f;
    } else if (direction.equals(WEST)) {
        directionAngle = 0f; // Arrow is drawn pointing West, so no rotation
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), mPx, Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds((int) mBuffer, 0, bm.getWidth(), bm.getHeight());
        arrowPaintFill.setShader(new LinearGradient(0, bm.getHeight() / 2, mArrowHeightPx, bm.getHeight() / 2,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // For WEST
        rotationX = bm.getHeight() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(SOUTH_WEST)) {
        directionAngle = 225f; // Arrow is drawn N, rotate 225 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds((int) mBuffer, 0, bm.getWidth(), mPx);
        arrowPaintFill.setShader(new LinearGradient(0, bm.getHeight(), mBuffer, bm.getHeight() - mBuffer,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // Rotate around below coordinates (trial and error)
        rotationX = bm.getWidth() / 2f - mBuffer / 4f;
        rotationY = mPx / 2f + mBuffer / 4f;
    } else if (direction.equals(SOUTH)) {
        directionAngle = 180f; // Arrow is drawn N, rotate 180 degrees
        bm = Bitmap.createBitmap(mPx, (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, bm.getWidth(), (int) (bm.getHeight() - mBuffer));
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth() / 2, bm.getHeight(), bm.getWidth() / 2,
                bm.getHeight() - mArrowHeightPx, r.getColor(R.color.theme_primary),
                r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        rotationX = bm.getWidth() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(SOUTH_EAST)) {
        directionAngle = 135f; // Arrow is drawn N, rotate 135 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, mPx, mPx);
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), bm.getHeight(), bm.getWidth() - mBuffer,
                bm.getHeight() - mBuffer, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent),
                Shader.TileMode.MIRROR));
        // Rotate around below coordinates (trial and error)
        rotationX = (mPx + mBuffer / 2) / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(EAST)) {
        directionAngle = 180f; // Arrow is drawn pointing West, so rotate 180
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), mPx, Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, mPx, bm.getHeight());
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), bm.getHeight() / 2,
                bm.getWidth() - mArrowHeightPx, bm.getHeight() / 2, r.getColor(R.color.theme_primary),
                r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        rotationX = bm.getWidth() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(NORTH_EAST)) {
        directionAngle = 45f; // Arrow is drawn pointing N, so rotate 45 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, (int) mBuffer, mPx, bm.getHeight());
        // Shade with darkest color at tip of arrow
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), 0, bm.getWidth() - mBuffer, mBuffer,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // Rotate around middle of circle
        rotationX = (float) mPx / 2;
        rotationY = bm.getHeight() - (float) mPx / 2;
    } else {
        throw new IllegalArgumentException(direction);
    }

    shape.draw(c);

    if (direction.equals(NO_DIRECTION)) {
        // Everything after this point is for drawing the arrow image, so return the bitmap as-is for no arrow
        return bm;
    }

    /**
     * Draw the arrow - all dimensions should be relative to px so the arrow is drawn the same
     * size for all orientations
     */
    // Height of the cutout in the bottom of the triangle that makes it an arrow (0=triangle)
    final float CUTOUT_HEIGHT = mPx / 12;
    Path path = new Path();
    float x1 = 0, y1 = 0; // Tip of arrow
    float x2 = 0, y2 = 0; // lower left
    float x3 = 0, y3 = 0; // cutout in arrow bottom
    float x4 = 0, y4 = 0; // lower right

    if (direction.equals(NORTH) || direction.equals(SOUTH) || direction.equals(NORTH_EAST)
            || direction.equals(SOUTH_EAST) || direction.equals(NORTH_WEST) || direction.equals(SOUTH_WEST)) {
        // Arrow is drawn pointing NORTH
        // Tip of arrow
        x1 = mPx / 2;
        y1 = 0;

        // lower left
        x2 = (mPx / 2) - (mArrowWidthPx / 2);
        y2 = mArrowHeightPx;

        // cutout in arrow bottom
        x3 = mPx / 2;
        y3 = mArrowHeightPx - CUTOUT_HEIGHT;

        // lower right
        x4 = (mPx / 2) + (mArrowWidthPx / 2);
        y4 = mArrowHeightPx;
    } else if (direction.equals(EAST) || direction.equals(WEST)) {
        // Arrow is drawn pointing WEST
        // Tip of arrow
        x1 = 0;
        y1 = mPx / 2;

        // lower left
        x2 = mArrowHeightPx;
        y2 = (mPx / 2) - (mArrowWidthPx / 2);

        // cutout in arrow bottom
        x3 = mArrowHeightPx - CUTOUT_HEIGHT;
        y3 = mPx / 2;

        // lower right
        x4 = mArrowHeightPx;
        y4 = (mPx / 2) + (mArrowWidthPx / 2);
    }

    path.setFillType(Path.FillType.EVEN_ODD);
    path.moveTo(x1, y1);
    path.lineTo(x2, y2);
    path.lineTo(x3, y3);
    path.lineTo(x4, y4);
    path.lineTo(x1, y1);
    path.close();

    // Rotate arrow around (rotationX, rotationY) point
    Matrix matrix = new Matrix();
    matrix.postRotate(directionAngle, rotationX, rotationY);
    path.transform(matrix);

    c.drawPath(path, arrowPaintFill);
    c.drawPath(path, mArrowPaintStroke);

    return bm;
}

From source file:com.madgag.android.lazydrawables.samples.DemoListActivity.java

private ImageResourceDownloader<String, Bitmap> slowImageMaker() {
    return new ImageResourceDownloader<String, Bitmap>() {
        public Bitmap get(String key) {
            Log.d(TAG, "Asked to download " + key);
            try {
                Thread.sleep(4000L);
            } catch (InterruptedException e) {
            }//from w  ww  .  j  ava  2  s .  co  m
            Bitmap bitmap = Bitmap.createBitmap(80, 80, Bitmap.Config.ARGB_8888);
            Canvas c = new Canvas(bitmap);
            Paint paint = new Paint();
            paint.setColor(0xff0000ff);
            c.drawCircle(0, 0, 50, paint);

            paint.setColor(0xffff007f);
            paint.setStyle(Paint.Style.FILL);
            paint.setAntiAlias(true);
            paint.setTextSize(30);
            c.drawText(key, 0, 3, 0, 60, paint);
            Log.d(TAG, "Done drawing... " + key);
            return bitmap;
        }
    };
}

From source file:id.satusatudua.sigap.ui.fragment.GuardingLocationFragment.java

private Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int color = Color.RED;
    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);/*  w  w w. j  a va2  s. co m*/
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    bitmap.recycle();

    return output;
}

From source file:com.alex.view.loop.IndicatorView.java

/**
 * //from  w ww .  ja  v  a2  s  .c om
 *
 * @param color ??
 * @return
 */
private Bitmap makeIndicatorBp(int color) {
    Bitmap normalBp = Bitmap.createBitmap(mRadius * 2, mRadius * 2, Bitmap.Config.ARGB_8888);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(color);
    Canvas canvas = new Canvas(normalBp);
    canvas.drawCircle(mRadius, mRadius, mRadius, paint);
    return normalBp;
}

From source file:com.bamobile.fdtks.util.Tools.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output;//from  w  w w . java2 s .  c  om

    if (bitmap.getWidth() > bitmap.getHeight()) {
        output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Config.ARGB_8888);
    } else {
        output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), 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());

    float r = 0;

    if (bitmap.getWidth() > bitmap.getHeight()) {
        r = bitmap.getHeight() / 2;
    } else {
        r = bitmap.getWidth() / 2;
    }

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawCircle(r, r, r, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;

}