Example usage for android.graphics Paint setStrokeWidth

List of usage examples for android.graphics Paint setStrokeWidth

Introduction

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

Prototype

public void setStrokeWidth(float width) 

Source Link

Document

Set the width for stroking.

Usage

From source file:com.semfapp.adamdilger.semf.Take5PdfDocument.java

/**
 * Draw checkbox//from  w ww  .  j av a2s. c  o  m
 * @param xLoc left location
 * @param yLoc top location
 * @param paint Paint object
 */
private void drawCheck(float xLoc, float yLoc, Paint paint) {
    float x1[] = { 2.3f, 6f, 11.5f };
    float y1[] = { 8f, 11f, 2.2f };
    Path path = new Path();
    path.moveTo(xLoc + x1[0], yLoc + y1[0]);
    path.lineTo(xLoc + x1[1], yLoc + y1[1]);
    path.lineTo(xLoc + x1[2], yLoc + y1[2]);
    paint.setStrokeWidth(3);
    can.drawPath(path, paint);
}

From source file:com.gmail.walles.johan.batterylogger.BatteryPlotFragment.java

private void addPlotData(final XYPlot plot) {
    LineAndPointFormatter medianFormatter = getMedianFormatter();

    try {// www.  j  a  v a  2 s .c  om
        // Add battery drain series to the plot
        History history = new History(getActivity());
        if (history.isEmpty() && BuildConfig.DEBUG && isRunningOnEmulator()) {
            history = History.createFakeHistory();
        }

        drainDots = history.getBatteryDrain();
        enableDrainDots(plot);

        final List<XYSeries> medians = history.getDrainLines();
        for (XYSeries median : medians) {
            plot.addSeries(median, medianFormatter);
        }

        // Add red restart lines to the plot
        Paint restartPaint = new Paint();
        restartPaint.setAntiAlias(true);
        restartPaint.setColor(Color.RED);
        restartPaint.setStrokeWidth(dpToPixels(0.5f));
        plot.addSeries(history.getEvents(), new RestartFormatter(restartPaint));

        // Add events to the plot
        Paint labelPaint = new Paint();
        labelPaint.setAntiAlias(true);
        labelPaint.setColor(Color.WHITE);
        labelPaint.setTextSize(spToPixels(IN_GRAPH_TEXT_SIZE_SP));

        eventFormatter = new EventFormatter(labelPaint);
        plot.addSeries(history.getEvents(), eventFormatter);

        if (history.isEmpty()) {
            showAlertDialogOnce("No Battery History Recorded",
                    "Come back in a few hours to get a graph, or in a week to be able to see patterns.");
        } else if (medians.size() < 5) {
            showAlertDialogOnce("Very Short Battery History Recorded",
                    "If you come back in a week you'll be able to see patterns much better.");
        }
    } catch (IOException e) {
        Log.e(TAG, "Reading battery history failed", e);
        showAlertDialog("Reading Battery History Failed", e.getMessage());
    }
}

From source file:net.line2soft.preambul.views.SlippyMapActivity.java

/**
 * Creates a {@link Paint} object with a certain color
 * @param color The wanted color/*from   w  w  w.j a  v  a2  s.  com*/
 * @param alpha The alpha channel
 * @return The created Paint object
 */
private Paint createPaint(int color, int alpha) {
    Paint pnt = new Paint(Paint.ANTI_ALIAS_FLAG);
    pnt.setColor(color);
    pnt.setAlpha(alpha);
    pnt.setStyle(Paint.Style.STROKE);
    pnt.setStrokeWidth(7);
    pnt.setStrokeJoin(Paint.Join.ROUND);
    pnt.setStrokeCap(Paint.Cap.ROUND);
    //pnt.setPathEffect(new DashPathEffect(new float[] { 20, 20 }, 0));
    return pnt;
}

From source file:org.odk.collect.android.activities.GeoTraceOsmMapActivity.java

private void overlayMapLayerListener() {
    polyline = new Polyline();
    polyline.setColor(Color.RED);
    Paint paint = polyline.getPaint();
    paint.setStrokeWidth(5);
    mapView.getOverlays().add(polyline);
    mapView.invalidate();/*from   w w  w . j  a v a 2 s .c  o m*/
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * //from w w w.ja  va2  s.co m
 * @param bitmap
 * @return
 */
public static Bitmap createRoundImageWithBorder(Context context, Bitmap bitmap) {
    //
    int bitmapWidth = bitmap.getWidth();
    //
    int bitmapHeight = bitmap.getHeight();
    // pixel
    int borderWidthHalf = 20;

    //??
    int bitmapSquareWidth = Math.min(bitmapWidth, bitmapHeight);

    //?
    int newBitmapSquareWidth = bitmapSquareWidth + borderWidthHalf;

    Bitmap roundedBitmap = Bitmap.createBitmap(newBitmapSquareWidth, newBitmapSquareWidth,
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(roundedBitmap);
    int x = borderWidthHalf + bitmapSquareWidth - bitmapWidth;
    int y = borderWidthHalf + bitmapSquareWidth - bitmapHeight;

    //???,?X,Y?2 ??
    canvas.drawBitmap(bitmap, x / 2, y / 2, null);
    Paint borderPaint = new Paint();
    borderPaint.setStyle(Paint.Style.STROKE);
    borderPaint.setStrokeWidth(borderWidthHalf);
    borderPaint.setColor(Color.WHITE);

    //
    canvas.drawCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, newBitmapSquareWidth / 2, borderPaint);

    RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(context.getResources(),
            roundedBitmap);
    roundedBitmapDrawable.setGravity(Gravity.CENTER);
    roundedBitmapDrawable.setCircular(true);
    return getBitmapFromDrawable(roundedBitmapDrawable);
}

From source file:com.cleverzone.zhizhi.capture.CaptureActivity.java

/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of the barcode.
 *
 * @param barcode     A bitmap of the captured image.
 * @param scaleFactor amount by which thumbnail was scaled
 * @param rawResult   The decoded results which contains the points to draw.
 *//*from w  w w  .ja v a 2s. com*/
private void drawResultPoints(Bitmap barcode, float scaleFactor, 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_points));
        if (points.length == 2) {
            paint.setStrokeWidth(4.0f);
            drawLine(canvas, paint, points[0], points[1], scaleFactor);
        } else if (points.length == 4 && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A
                || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
            // Hacky special case -- draw two lines, for the barcode and metadata
            drawLine(canvas, paint, points[0], points[1], scaleFactor);
            drawLine(canvas, paint, points[2], points[3], scaleFactor);
        } else {
            paint.setStrokeWidth(10.0f);
            for (ResultPoint point : points) {
                if (point != null) {
                    canvas.drawPoint(scaleFactor * point.getX(), scaleFactor * point.getY(), paint);
                }
            }
        }
    }
}

From source file:net.exclaimindustries.geohashdroid.util.KnownLocation.java

@NonNull
private Bitmap buildMarkerBitmap(@NonNull Context c) {
    // Oh, this is going to be FUN.
    int dim = c.getResources().getDimensionPixelSize(R.dimen.known_location_marker_canvas_size);
    float radius = c.getResources().getDimension(R.dimen.known_location_pin_head_radius);

    Bitmap bitmap = Bitmap.createBitmap(dim, dim, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setAntiAlias(true);// w  w w .  j  a va 2s .co m

    KnownLocationPinData pinData = new KnownLocationPinData(c, mLocation);

    // Draw the pin line first.  That goes from the bottom-center up to
    // wherever the radius and length take us.
    float topX = Double.valueOf((dim / 2) + (pinData.getLength() * Math.cos(pinData.getAngle()))).floatValue();
    float topY = Double.valueOf(dim - (pinData.getLength() * Math.sin(pinData.getAngle()))).floatValue();
    paint.setStrokeWidth(c.getResources().getDimension(R.dimen.known_location_stroke));
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.BLACK);

    canvas.drawLine(dim / 2, dim, topX, topY, paint);

    // On the top of that line, fill in a circle.
    paint.setColor(pinData.getColor());
    paint.setStyle(Paint.Style.FILL);
    canvas.drawCircle(topX, topY, radius, paint);

    // And outline it.
    paint.setColor(Color.BLACK);
    paint.setStyle(Paint.Style.STROKE);
    canvas.drawCircle(topX, topY, radius, paint);

    return bitmap;
}

From source file:potboiler.client.PotsActivity.java

License:asdf

private void createDrawerMenu() {

    mMenuItems = getResources().getStringArray(R.array.menu_sections);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawer = (LinearLayout) findViewById(R.id.left_drawer);
    mCommandsList = (ListView) findViewById(R.id.commands);

    User user = PreferenceUtils.getUser(this);
    ((TextView) findViewById(R.id.name)).setText(user.username);

    Bitmap bitmap = ImageUtils.getImageFromFile(this, FileUtils.getImagesPath(this) + user.serverId);
    if (bitmap != null) {
        /*Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
                //www  .j  a  v  a 2s .  co  m
        BitmapShader shader = new BitmapShader (bitmap,  Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        Paint paint = new Paint();
        paint.setShader(shader);
        paint.setAntiAlias(true);
        Canvas c = new Canvas(circleBitmap);
        c.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);*/

        int w = bitmap.getWidth();
        int h = bitmap.getHeight();

        int radius = Math.min(h / 2, w / 2);
        Bitmap circleBitmap = Bitmap.createBitmap(w + 8, h + 8, Bitmap.Config.ARGB_8888);

        Paint paint = new Paint();
        paint.setAntiAlias(true);

        Canvas c = new Canvas(circleBitmap);
        c.drawARGB(0, 0, 0, 0);
        paint.setStyle(Paint.Style.FILL);

        c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

        c.drawBitmap(bitmap, 4, 4, paint);
        paint.setXfermode(null);
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.WHITE);
        paint.setStrokeWidth(3);
        c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, paint);

        ((ImageView) findViewById(R.id.avatar)).setImageBitmap(circleBitmap);
    }

    mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent));

    DrawerAdapter adapter = new DrawerAdapter(this, R.layout.item_drawer_list, R.id.title, mMenuItems);
    mCommandsList.setAdapter(adapter);
    mCommandsList.setOnItemClickListener(new DrawerItemClickListener());

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.pots, R.string.pots) {

        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            syncActionBarArrowState();
            //                invalidateOptionsMenu();
            //                mDrawerToggle.syncState();
            //                setRefreshMenu();
        }

        public void onDrawerOpened(View drawerView) {
            //                super.onDrawerClosed(drawerView);
            super.onDrawerOpened(drawerView);
            mDrawerToggle.setDrawerIndicatorEnabled(true);
            //                invalidateOptionsMenu();
            //                mDrawerToggle.syncState();
            //                setRefreshMenu();
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);

            float xPositionOpenDrawer = mCommandsList.getWidth();
            float xPositionWindowContent = (slideOffset * xPositionOpenDrawer);
            FrameLayout mHostFragment = (FrameLayout) findViewById(R.id.content_frame);
            mHostFragment.setX(xPositionWindowContent);
            getActionBarView().setX(xPositionWindowContent);
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();
    getSupportFragmentManager().addOnBackStackChangedListener(mOnBackStackChangedListener);

    findViewById(R.id.signout).setOnClickListener(this);
}

From source file:org.navitproject.navit.NavitGraphics.java

protected void draw_polygon(Paint paint, int[] c) {
    paint.setStrokeWidth(c[0]);
    paint.setARGB(c[1], c[2], c[3], c[4]);
    paint.setStyle(Paint.Style.FILL);
    //paint.setAntiAlias(true);
    //paint.setStrokeWidth(0);
    Path path = new Path();
    path.moveTo(c[5], c[6]);/*from   ww w  .  j  a  v  a2s  .  c  o  m*/
    for (int i = 7; i < c.length; i += 2) {
        path.lineTo(c[i], c[i + 1]);
    }
    //global_path.close();
    draw_canvas.drawPath(path, paint);
}

From source file:com.wiipu.bimu.adapter.AreaSelect.WheelView.java

/**
 * Draws rect for current value/*from   ww w . ja v a2s.  c o m*/
 * @param canvas the canvas for drawing
 */
private void drawCenterRect(Canvas canvas) {
    int center = getHeight() / 2;
    int offset = (int) (getItemHeight() / 2 * 1.2);
    /*/ Remarked by wulianghuan 2014-11-27  ???
    Rect rect = new Rect(left, top, right, bottom)
    centerDrawable.setBounds(bounds)
    centerDrawable.setBounds(0, center - offset, getWidth(), center + offset);
    centerDrawable.draw(canvas);
    //*/
    Paint paint = new Paint();
    paint.setColor(Color.parseColor("#999999"));
    // 
    paint.setStrokeWidth((float) 3);
    // 
    canvas.drawLine(0, center - offset, getWidth(), center - offset, paint);
    // 
    canvas.drawLine(0, center + offset, getWidth(), center + offset, paint);
    //*/
}