Example usage for android.graphics Paint Paint

List of usage examples for android.graphics Paint Paint

Introduction

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

Prototype

public Paint() 

Source Link

Document

Create a new paint with default settings.

Usage

From source file:com.richtodd.android.quiltdesign.block.PaperPiecedBlockPiece.java

private Paint createShadowPaint(int left, int top, int width, int height, int shadowStrokeWidth) {
    List<PointF> points = getPoints(width, height);
    PointF fromPoint = new PointF(left + points.get(0).x, top + points.get(0).y);
    PointF toPoint = new PointF(left + points.get(1).x, top + points.get(1).y);

    PointF midpoint = new PointF((fromPoint.x + toPoint.x) * 0.5f, (fromPoint.y + toPoint.y) * 0.5f);

    PointF vector = new PointF(fromPoint.x - midpoint.x, fromPoint.y - midpoint.y);

    PointF rotatedVector = new PointF(vector.y, -vector.x);

    float vectorLength = (float) Math.sqrt((vector.x * vector.x) + (vector.y * vector.y));

    PointF shadowVector = new PointF(rotatedVector.x * (shadowStrokeWidth * 0.5f) / vectorLength,
            rotatedVector.y * (shadowStrokeWidth * 0.5f) / vectorLength);

    LinearGradient gradient = new LinearGradient(midpoint.x, midpoint.y, midpoint.x + shadowVector.x,
            midpoint.y + shadowVector.y, Color.argb(100, 0, 0, 0), Color.argb(0, 0, 0, 0), TileMode.MIRROR);

    Paint paint = new Paint();
    paint.setStyle(Style.STROKE);
    paint.setShader(gradient);//w w w .j  a va  2  s  .  c  om
    paint.setStrokeWidth(shadowStrokeWidth);
    paint.setStrokeCap(Cap.SQUARE);

    return paint;
}

From source file:com.inmobi.ultrapush.AnalyzeActivity.java

public PopupWindow popupMenuCreate(String[] popUpContents, int resId) {

    // initialize a pop up window type
    PopupWindow popupWindow = new PopupWindow(this);

    // the drop down list is a list view
    ListView listView = new ListView(this);

    // set our adapter and pass our pop up window contents
    ArrayAdapter<String> aa = popupMenuAdapter(popUpContents);
    listView.setAdapter(aa);// ww  w .j a v  a2s.  c  om

    // set the item click listener
    listView.setOnItemClickListener(this);

    listView.setTag(resId); // button res ID, so we can trace back which button is pressed

    // get max text width
    Paint mTestPaint = new Paint();
    mTestPaint.setTextSize(listItemTextSize);
    float w = 0;
    float wi; // max text width in pixel
    for (int i = 0; i < popUpContents.length; i++) {
        String sts[] = popUpContents[i].split("::");
        String st = sts[0];
        if (sts.length == 2 && sts[1].equals("0")) {
            mTestPaint.setTextSize(listItemTitleTextSize);
            wi = mTestPaint.measureText(st);
            mTestPaint.setTextSize(listItemTextSize);
        } else {
            wi = mTestPaint.measureText(st);
        }
        if (w < wi) {
            w = wi;
        }
    }

    // left and right padding, at least +7, or the whole app will stop respond, don't know why
    w = w + 20 * DPRatio;
    if (w < 60) {
        w = 60;
    }

    // some other visual settings
    popupWindow.setFocusable(true);
    popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    // Set window width according to max text width
    popupWindow.setWidth((int) w);
    // also set button width
    ((Button) findViewById(resId)).setWidth((int) (w + 4 * DPRatio));
    // Set the text on button in updatePreferenceSaved()

    // set the list view as pop up window content
    popupWindow.setContentView(listView);

    return popupWindow;
}

From source file:android.support.design.widget.TextInputLayout.java

private void updateInputLayoutMargins() {
    // Create/update the LayoutParams so that we can add enough top margin
    // to the EditText so make room for the label
    final LayoutParams lp = (LayoutParams) mInputFrame.getLayoutParams();
    final int newTopMargin;

    if (mHintEnabled) {
        if (mTmpPaint == null) {
            mTmpPaint = new Paint();
        }//from   ww  w  .  j a  v  a2s  .com
        mTmpPaint.setTypeface(mCollapsingTextHelper.getCollapsedTypeface());
        mTmpPaint.setTextSize(mCollapsingTextHelper.getCollapsedTextSize());
        newTopMargin = (int) -mTmpPaint.ascent();
    } else {
        newTopMargin = 0;
    }

    if (newTopMargin != lp.topMargin) {
        lp.topMargin = newTopMargin;
        mInputFrame.requestLayout();
    }
}

From source file:app.axe.imooc.zxing.app.CaptureActivity.java

/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of
 * the barcode./*from ww  w  . j av  a  2  s.c  o m*/
 *
 * @param barcode   A bitmap of the captured image.
 * @param rawResult The decoded results which contains the points to draw.
 */
private void drawResultPoints(Bitmap barcode, Result rawResult) {
    ResultPoint[] points = rawResult.getResultPoints();
    if (points != null && points.length > 0) {
        Canvas canvas = new Canvas(barcode);
        Paint paint = new Paint();
        paint.setColor(getResources().getColor(R.color.result_image_border));
        paint.setStrokeWidth(3.0f);
        paint.setStyle(Paint.Style.STROKE);
        Rect border = new Rect(2, 2, barcode.getWidth() - 2, barcode.getHeight() - 2);
        canvas.drawRect(border, paint);

        paint.setColor(getResources().getColor(R.color.result_points));
        if (points.length == 2) {
            paint.setStrokeWidth(4.0f);
            drawLine(canvas, paint, points[0], points[1]);
        } else if (points.length == 4 && (rawResult.getBarcodeFormat().equals(BarcodeFormat.UPC_A))
                || (rawResult.getBarcodeFormat().equals(BarcodeFormat.EAN_13))) {
            // Hacky special case -- draw two lines, for the barcode and
            // metadata
            drawLine(canvas, paint, points[0], points[1]);
            drawLine(canvas, paint, points[2], points[3]);
        } else {
            paint.setStrokeWidth(10.0f);
            for (ResultPoint point : points) {
                canvas.drawPoint(point.getX(), point.getY(), paint);
            }
        }
    }
}

From source file:com.mappn.gfan.ui.HomeTabActivity.java

private Bitmap drawText(DisplayMetrics dm, Resources res, Bitmap bm, int num) {
    final int height = bm.getScaledHeight(dm);
    final int width = bm.getScaledWidth(dm);
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    canvas.drawBitmap(bm, new Matrix(), new Paint());
    Paint textPainter = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPainter.setColor(res.getColor(R.color.tab_app_num));
    textPainter.setTextSize(dm.scaledDensity * 12);
    textPainter.setTypeface(Typeface.DEFAULT_BOLD);
    float textWidth = textPainter.measureText(String.valueOf(num)) / 2;
    canvas.drawText(String.valueOf(num), width / 2 - textWidth, height / 2 + (dm.scaledDensity * 6),
            textPainter);//from w w w . ja va2  s. c om
    canvas.save();
    return newBitmap;
}

From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java

public static Bitmap createAlphaGradientBitmap(Bitmap orig) {
    final int width = orig.getWidth(), height = orig.getHeight();
    final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);
    final Paint paint = new Paint();
    final LinearGradient shader = new LinearGradient(width / 2, 0, width / 2, height, 0xffffffff, 0x00ffffff,
            Shader.TileMode.CLAMP);/*from  w  ww.  jav a 2  s.co m*/
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawBitmap(orig, 0, 0, null);
    canvas.drawRect(0, 0, width, height, paint);
    return bitmap;
}

From source file:com.berniesanders.fieldthebern.views.MapScreenView.java

private Bitmap colorBitmap(final Bitmap bm, int color) {

    Paint paint = new Paint();
    ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
    paint.setColorFilter(filter);/*from   w w w.  jav  a  2 s . c  om*/
    Bitmap copiedBitmap = bm.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(copiedBitmap);
    canvas.drawBitmap(bm, 0, 0, paint);
    return copiedBitmap;
}

From source file:org.medcare.Dicom.DicomActivity.java

public Paint getInnerPaint() {
    if (innerPaint == null) {
        innerPaint = new Paint();
        innerPaint.setARGB(225, 75, 75, 75); // gray
        innerPaint.setAntiAlias(true);/*from   w ww.  jav a2  s .  co m*/
    }
    return innerPaint;
}

From source file:org.medcare.Dicom.DicomActivity.java

public Paint getBorderPaint() {
    if (borderPaint == null) {
        borderPaint = new Paint();
        borderPaint.setARGB(255, 255, 255, 255);
        borderPaint.setAntiAlias(true);/*  w w  w  .ja v  a 2  s.  c  om*/
        borderPaint.setStyle(Style.STROKE);
        borderPaint.setStrokeWidth(2);
    }
    return borderPaint;
}

From source file:org.medcare.Dicom.DicomActivity.java

public Paint getTextPaint() {
    if (textPaint == null) {
        textPaint = new Paint();
        textPaint.setARGB(255, 255, 255, 255);
        textPaint.setAntiAlias(true);/*from  w  ww  . jav a2s . c  om*/
    }
    return textPaint;
}