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:net.networksaremadeofstring.rhybudd.RhybuddDock.java

private void DrawDevices() {
    Bitmap charty = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
    Canvas DeviceCanvas = new Canvas(charty);
    final Paint paint = new Paint();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(getResources().getColor(R.color.DarkBlue));
    paint.setAntiAlias(true);
    DeviceCanvas.drawOval(new RectF(1, 1, 199, 199), paint);

    RadialGradient gradient = new RadialGradient(100, 50, 150, 0xFF6b7681, 0xFF000000,
            android.graphics.Shader.TileMode.CLAMP);
    paint.setDither(true);/*from   w  w  w. ja  v a 2  s. c  o m*/
    paint.setShader(gradient);
    DeviceCanvas.drawOval(new RectF(6, 6, 194, 194), paint);

    int Scale = 10;

    //Special Bits
    if (DeviceCount < 500)
        Scale = 750;

    if (DeviceCount < 250)
        Scale = 350;

    if (DeviceCount < 100)
        Scale = 150;

    if (DeviceCount < 50)
        Scale = 50;
    try {
        drawScale(DeviceCanvas, false, DeviceCount, Scale);
        drawGaugeTitle(DeviceCanvas, "Device Count");
        drawGaugeNeedle(DeviceCanvas, DeviceCount, Scale);
        //drawGloss(EventsCanvas);
        ((ImageView) findViewById(R.id.DeviceGauge)).setImageBitmap(charty);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.cssweb.android.view.FinanceMini.java

public void drawIndex(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);
    if (quoteData != null) {
        try {// ww  w.  ja  va2 s  . co  m
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("???", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width, -DY * 5);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("a"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("b"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("govbond"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("fund"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("warrant"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("bond"), true), x, y, paint);

        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java

private void drawGaugeTitle(Canvas canvas, String Title) {
    Paint titlePaint = new Paint();
    titlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    titlePaint.setColor(Color.LTGRAY);//0x9f004d0f
    titlePaint.setStrokeWidth(1);//0.005f
    titlePaint.setAntiAlias(true);
    titlePaint.setTextSize(14);//from  w ww.j  a va 2s  .com
    titlePaint.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/chivo.ttf"));

    /*Path titlePath = new Path();
    titlePath.addArc(new RectF(40, 90, 196, 155), -180.0f, -180.0f);
    canvas.drawTextOnPath(Title, titlePath, 0.0f,0.0f, titlePaint);*/

    canvas.drawText(Title, 60, 160, titlePaint);
}

From source file:com.crazyapk.util.bitmap.ImageWorker.java

public Bitmap toRoundCorner(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);
    canvas.drawARGB(0, 0, 0, 0);//from   w  w w.  j  ava 2 s  .c  o  m
    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.cssweb.android.view.FinanceMini.java

public void drawHKPrice(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);
    if (quoteData != null) {
        try {//from   w  ww .j av  a  2 s  .  c o  m
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2, -DY * 4);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint);
            canvas.translate(0, DY);
            //            if(jo.getDouble("wb")<0)
            //               paint.setColor(GlobalColor.colorPriceDown);
            //            else if(jo.getDouble("wb")>0)
            //               paint.setColor(GlobalColor.colorpriceUp);
            //            else 
            //               paint.setColor(GlobalColor.colorPriceEqual);
            //            canvas.drawText(Utils.dataFormation(jo.getDouble("wb")*100, 1)+"%", x-tips, y, paint);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjje"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("msgs"), true), x - tips, y, paint);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, -DY * 3);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            //            canvas.drawText("", x, y, paint);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 3);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint);
            canvas.translate(0, DY);
            //            if(jo.getDouble("wc")<0) {
            //               paint.setColor(GlobalColor.colorPriceDown);
            //               canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x-tips, y, paint);
            //            }
            //            else if(jo.getDouble("wc")>0) {
            //               paint.setColor(GlobalColor.colorpriceUp);
            //               canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint);
            //            }
            //            else {
            //               paint.setColor(GlobalColor.colorPriceEqual);
            //               canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint);
            //            }
            paint.setColor(GlobalColor.colorPriceDown);
            canvas.drawText("", x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint);
            //            paint.setColor(GlobalColor.colorStockName);
            //            canvas.translate(0, DY);
            //            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x-tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

From source file:de.madvertise.android.sdk.MadView.java

/**
 * Draw the ad background for a text banner
 * //  w  w  w .  j  a  v  a2  s. co  m
 * @param canvas
 * @param rectangle
 * @param backgroundColor
 * @param textColor
 */
private void drawTextBannerBackground(Canvas canvas, Rect rectangle, int backgroundColor, int shineColor) {
    Paint paint = new Paint();
    paint.setColor(backgroundColor);
    paint.setAntiAlias(true);
    canvas.drawRect(rectangle, paint);

    int upperColor = Color.argb(GRADIENT_TOP_ALPHA, Color.red(shineColor), Color.green(shineColor),
            Color.blue(shineColor));
    int[] gradientColors = { upperColor, shineColor };
    GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            gradientColors);

    int stop = (int) (rectangle.height() * GRADIENT_STOP) + rectangle.top;
    gradientDrawable.setBounds(rectangle.left, rectangle.top, rectangle.right, stop);
    gradientDrawable.draw(canvas);

    Rect shadowRect = new Rect(rectangle.left, stop, rectangle.right, rectangle.bottom);
    Paint shadowPaint = new Paint();
    shadowPaint.setColor(shineColor);
    canvas.drawRect(shadowRect, shadowPaint);
}

From source file:cn.wyx.android.swipeback.swipe.SwipeBackLayout.java

/**
 * ?//from   ww w.  ja v  a2 s . c  o  m
 *
 * @param canvas canvas
 */
private void drawLastScreenshot(Canvas canvas) {
    if (mLastScreenshot != null && target != null) {
        int right = target.getLeft();
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        Rect src = new Rect(mLastScreenshot.getWidth() - target.getLeft(), 0, mLastScreenshot.getWidth(),
                target.getBottom());
        //target??
        Rect dst = new Rect(0, target.getBottom() - mLastScreenshot.getHeight(), right, target.getBottom());

        int navigationBarHeight = getNavigationBarHeight();

        isFullscreen = target.getHeight() == getResources().getDisplayMetrics().heightPixels
                + navigationBarHeight;

        int statusBarHeight = getStatusBarHeight();

        switch (dragEdge) {
        case LEFT:
            src = new Rect(mLastScreenshot.getWidth() - target.getLeft(), 0, mLastScreenshot.getWidth(),
                    mLastScreenshot.getHeight());
            dst = new Rect(0, isFullscreen ? statusBarHeight : target.getBottom() - mLastScreenshot.getHeight(),
                    right, isFullscreen ? target.getHeight() - navigationBarHeight : target.getBottom());

            break;
        case RIGHT:
            src = new Rect(0, 0, mLastScreenshot.getWidth() - target.getRight(), mLastScreenshot.getHeight());
            dst = new Rect(target.getRight(),
                    isFullscreen ? statusBarHeight : target.getBottom() - mLastScreenshot.getHeight(),
                    mLastScreenshot.getWidth(),
                    isFullscreen ? target.getHeight() - navigationBarHeight : target.getBottom());
            break;

        case TOP:
            src = new Rect(0, mLastScreenshot.getHeight() - target.getTop(), mLastScreenshot.getWidth(),
                    target.getBottom());
            dst = new Rect(0, 0, target.getRight(), target.getTop());
            break;
        case BOTTOM:
            src = new Rect(0, 0, mLastScreenshot.getWidth(), mLastScreenshot.getHeight() - target.getBottom());
            dst = new Rect(0, target.getBottom(), mLastScreenshot.getWidth(), mLastScreenshot.getHeight());
            break;
        }

        canvas.drawBitmap(mLastScreenshot, src, dst, paint);
    }
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java

private void drawGaugeNeedle(Canvas canvas, int count, int Scale) {
    canvas.save(Canvas.MATRIX_SAVE_FLAG);
    float divisor = 360.0f / Scale;

    canvas.rotate((float) (divisor * count), 100, 100);

    //Inside/*w  w w  .ja  va  2s .co m*/
    Paint needleInsidePaint = new Paint();
    needleInsidePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    needleInsidePaint.setColor(Color.WHITE);
    needleInsidePaint.setStrokeWidth(4);
    needleInsidePaint.setAntiAlias(true);

    Paint needleEdgePaint = new Paint();
    needleEdgePaint.setStyle(Paint.Style.STROKE);
    needleEdgePaint.setColor(Color.DKGRAY);
    needleEdgePaint.setStrokeWidth(0.5f);
    needleEdgePaint.setAntiAlias(true);

    canvas.drawOval(new RectF(95, 95, 105, 105), needleInsidePaint);
    canvas.drawOval(new RectF(95, 96, 105, 105), needleEdgePaint);

    Path needleInside = new Path();
    needleInside.moveTo(98, 98);
    needleInside.lineTo(100, 20);
    needleInside.lineTo(102, 102);
    canvas.drawPath(needleInside, needleInsidePaint);

    Path needleEdge = new Path();
    needleInside.moveTo(99, 99);
    needleInside.lineTo(99, 19);
    needleInside.lineTo(103, 103);

    canvas.drawPath(needleEdge, needleEdgePaint);
    canvas.restore();
}

From source file:com.android.andryyu.lifehelper.widget.RippleView.java

private Bitmap getCircleBitmap(final int radius) {
    final Bitmap output = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(),
            Bitmap.Config.ARGB_8888);/*from  w  ww  . jav a2  s.co  m*/
    final Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final Rect rect = new Rect((int) (x - radius), (int) (y - radius), (int) (x + radius), (int) (y + radius));

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(x, y, radius, paint);

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

    return output;
}

From source file:com.cssweb.android.view.FinanceMini.java

private void drawQihuo(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);
    if (quoteData != null) {
        try {/*from ww w .  j  a  v a 2 s .  c o m*/
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText(" ", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2, -DY * 4);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint);

            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrjs"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("zt"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrcc"), 0, jo.getInt("tp")), x - tips, y, paint);

            //            canvas.translate(0, DY);
            //            canvas.drawText(Utils.dataFormation(jo.getDouble("jrkc"), 0), x-tips, y, paint);

            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x, y, paint);

            canvas.translate(0, -DY * 4);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);

            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText(" ", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            canvas.translate(width / 2, -DY * 5);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), false), x - tips, y, paint);

            paint.setColor(GlobalColor.colorPriceEqual);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("zrjs"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("dt"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("zc"), 0, jo.getInt("tp")), x - tips, y, paint);

            //            paint.setColor(GlobalColor.colorStockName);
            //            canvas.translate(0, DY);
            //            canvas.drawText(Utils.dataFormation(jo.getDouble("jrpc"), 0), x-tips, y, paint);   

            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}