Example usage for android.graphics Canvas drawPath

List of usage examples for android.graphics Canvas drawPath

Introduction

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

Prototype

public void drawPath(@NonNull Path path, @NonNull Paint paint) 

Source Link

Document

Draw the specified path using the specified paint.

Usage

From source file:com.example.dengue.dengue_android.InkPageIndicator.java

private void drawUnselected(Canvas canvas) {

    combinedUnselectedPath.rewind();/*from   w w  w  .  ja v a2  s  .c  o  m*/

    // draw any settled, revealing or joining dots
    for (int page = 0; page < pageCount; page++) {
        int nextXIndex = page == pageCount - 1 ? page : page + 1;
        Path unselectedPath = getUnselectedPath(page, dotCenterX[page], dotCenterX[nextXIndex],
                page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page], dotRevealFractions[page]);
        unselectedPath.addPath(combinedUnselectedPath);
        combinedUnselectedPath.addPath(unselectedPath);
    }
    // draw any retreating joins
    if (retreatingJoinX1 != INVALID_FRACTION) {
        Path retreatingJoinPath = getRetreatingJoinPath();
        combinedUnselectedPath.addPath(retreatingJoinPath);
    }

    canvas.drawPath(combinedUnselectedPath, unselectedPaint);
}

From source file:com.lovejjfg.demo.TouchCircleView.java

/**
 * /*from   w ww. jav a2  s. c o  m*/
 */
private void drawError(Canvas canvas) {
    mError.reset();
    mError.moveTo(innerRectf.centerX() + innerRectf.width() * 0.2f * fraction,
            innerRectf.centerY() - innerRectf.height() * 0.2f * fraction);
    mError.lineTo(innerRectf.centerX() - innerRectf.width() * 0.2f * fraction,
            innerRectf.centerY() + innerRectf.height() * 0.2f * fraction);
    mError.moveTo(innerRectf.centerX() - innerRectf.width() * 0.2f * fraction,
            innerRectf.centerY() - innerRectf.height() * 0.2f * fraction);
    mError.lineTo(innerRectf.centerX() + innerRectf.width() * 0.2f * fraction,
            innerRectf.centerY() + innerRectf.height() * 0.2f * fraction);
    mCurrentRectf = outRectF;
    mCurrentPaint = paint;
    resetPoints();
    drawCirclePath(canvas);
    canvas.drawPath(mError, mHookPaint);
}

From source file:com.wanikani.androidnotifier.graph.HistogramPlot.java

protected void drawBar(Canvas canvas, Samples bar, float left, float right) {
    long base, height;
    float top, tbl;
    Paint lpaint;//from www  .j ava  2  s  . c  o  m
    Paint paint;
    Path path;
    RectF rect;

    top = vp.getY(vp.yMax);
    base = 0;
    for (Sample sample : bar.samples) {
        if (sample.value > 0) {
            height = sample.value;

            if (base > vp.yMax)
                ;
            else if (base + height > vp.yMax) {
                path = new Path();
                path.moveTo(left, vp.getY(base));
                path.lineTo(left, top);
                path.lineTo(left + (right - left) / 3, top - 10);
                path.lineTo(left + (right - left) * 2 / 3, top + 5);
                path.lineTo(right, top);
                path.lineTo(right, vp.getY(base));
                path.close();
                canvas.drawPath(path, pas.series.get(sample.series));
            } else {
                rect = new RectF(left, vp.getY(base + height), right, vp.getY(base));
                rect.intersect(meas.plotArea);
                paint = pas.series.get(sample.series);
                paint.setStyle(Style.FILL);
                canvas.drawRect(rect, paint);
                paint.setStyle(Style.STROKE);
                canvas.drawRect(rect, paint);
            }
            base += height;
        }
    }

    if (base <= vp.yMax) {
        lpaint = pas.levelupPaint;
        tbl = vp.getY(base) - meas.headroom / 2;
    } else {
        lpaint = pas.levelupPaintInside;
        tbl = vp.getY(vp.yMax) + meas.margin;
    }

    if (base > 0 && drawTotal)
        canvas.drawText(Long.toString(base), (left + right) / 2, tbl, lpaint);
}

From source file:com.example.test2969mediabrowser.UnderlinePageIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mViewPager == null) {
        return;/*from  w  w  w.  j  a  va  2 s.  c  om*/
    }
    final int count = mViewPager.getAdapter().getCount();
    if (count == 0) {
        return;
    }

    if (mCurrentPage >= count) {
        setCurrentItem(count - 1);
        return;
    }
    final int width = getWidth();
    int height = getHeight();

    final int paddingLeft = getPaddingLeft();
    final float pageWidth = (getWidth() - paddingLeft - getPaddingRight()) / (1f * count);
    final float left = paddingLeft + pageWidth * (mCurrentPage + mPositionOffset);
    final float right = left + pageWidth;
    final float top = getPaddingTop();
    final float bottom = getHeight() - getPaddingBottom();
    // canvas.drawRect(left, top, right, bottom, mPaint);
    //===================================add by joe 20150918 start============

    //
    mPath.reset();
    mPath.moveTo(0, height * 4 / 5);
    mPath.lineTo(width, height * 4 / 5);
    mPath.lineTo(width, height);
    mPath.lineTo(0, height);
    mPath.close();
    mPaint.setColor(Color.BLACK);
    canvas.drawPath(mPath, mPaint);

    //
    mPath.reset();
    mPath.moveTo(left + 50, height * 5 / 6);
    mPath.lineTo(right - 50, height * 5 / 6);
    mPath.lineTo(right - 50, height);
    mPath.lineTo(left + 50, height);
    mPath.close();//#ff3b8eb9
    canvas.drawPath(mPath, mPaintFooterLine);

    //?text
    mPaintText.setColor(getResources().getColor(R.color.blue_select));
    mPaintText.setTextSize(22);
    FontMetricsInt fontMetrics = mPaintText.getFontMetricsInt();
    Rect targetRect = new Rect((int) left, (int) top, (int) right, (int) (height * 4 / 5));

    int baseline = targetRect.top
            + (targetRect.bottom - targetRect.top - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;

    // ?drawTexttargetRect.centerX()  
    mPaintText.setTextAlign(Paint.Align.CENTER);
    String tittle = (mCurrentPage + 1) + " / " + mViewPager.getAdapter().getCount();
    canvas.drawText(tittle, (left + right - tittle.length()) / 2, height * 3 / 5, mPaintText);

    //===================================add by joe 20150918 end==================
}

From source file:de.telekom.pde.codelibrary.ui.layout.PDESwipeRefreshLayout.java

private void drawTrigger(Canvas canvas, int cx, int cy) {
    float innerRadius;
    float outerRadius;
    Path circlePath;/*from   www. java  2s . c o m*/

    if (mTriggerPercentage < 0.05f)
        return;

    innerRadius = 0.7f * PDEBuildingUnits.BU();
    outerRadius = 0.9f * PDEBuildingUnits.BU();

    canvas.drawCircle(cx, cy, PDEBuildingUnits.BU(), mPaint);

    circlePath = new Path();

    circlePath.moveTo(cx, cy - innerRadius);
    circlePath.lineTo(cx, cy - outerRadius);

    circlePath.arcTo(new RectF(cx - outerRadius, cy - outerRadius, cx + outerRadius, cy + outerRadius), -90.0f,
            mTriggerPercentage * 360.0f);

    circlePath.lineTo((float) (cx + Math.sin(degreesToRadians(mTriggerPercentage * 360.0f)) * innerRadius),
            (float) (cy - Math.cos(degreesToRadians(mTriggerPercentage * 360.0f)) * innerRadius));

    circlePath.arcTo(new RectF(cx - innerRadius, cy - innerRadius, cx + innerRadius, cy + innerRadius),
            -90.0f + mTriggerPercentage * 360.0f, -mTriggerPercentage * 360.0f);

    canvas.drawPath(circlePath, mWhitePaint);

}

From source file:com.wanikani.androidnotifier.graph.TYPlot.java

/**
 * Draws a segment containins samples/*from  ww w  .  j  a v a 2  s . c om*/
 * @param canvas the canvas
 * @param series the series
 * @param interval the interval
 * @param base a float array initially set to zero, and updated by this method
 * @param samples the samples 
 */
protected void drawPlot(Canvas canvas, Pager.Series series, Pager.Interval interval, float base[],
        float samples[]) {
    Path path;
    Paint p;
    int i, n;

    p = pas.series.get(series);
    n = interval.stop - interval.start + 1;
    if (p == null || samples.length == 0 || n <= 0)
        return;

    path = new Path();

    path.moveTo(vp.getRelPosition(interval.start + n), vp.getY(base[n - 1]));

    for (i = n - 1; i >= 0; i--) {
        path.lineTo(vp.getRelPosition(interval.start + i), vp.getY(base[i]));
        base[i] += samples[i];
    }

    for (i = 0; i < n; i++)
        path.lineTo(vp.getRelPosition(interval.start + i), vp.getY(base[i]));

    path.lineTo(vp.getRelPosition(interval.start + n), vp.getY(base[n - 1]));

    path.close();

    canvas.drawPath(path, p);
}

From source file:com.savvasdalkitsis.betwixt.demo.InterpolatorView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawColor(Color.WHITE);
    int inset = (getHeight() - rectHeight()) / 2;
    canvas.drawRect(getPaddingLeft(), getPaddingTop() + inset, getWidth() - getPaddingRight(),
            getHeight() - inset - getPaddingBottom(), rectPaint);
    float x = 0;//from   www.j a  va2s  .c  o m
    float y = 0;
    for (int i = 0; i < STEPS; i++) {
        float newX = i / (float) STEPS;
        float newY = interpolator.getInterpolation(newX);
        if (i == 0) {
            x = newX;
            y = newY;
        }
        canvas.drawLine(x(x), y(y), x(newX), y(newY), paint);
        x = newX;
        y = newY;
    }
    canvas.drawText(description, getPaddingLeft() + textPaddingLeft, getHeight() - textHeight, textPaint);
    if (animating) {
        canvas.drawRect(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(),
                getHeight() - getPaddingBottom(), dim);
        int areaWidth = getWidth() - getPaddingLeft() - getPaddingRight() - animationInset * 2;
        float circleX = getPaddingLeft() + animationInset + areaWidth * progress;
        linePath.reset();
        linePath.moveTo(getPaddingLeft() + animationInset, getPaddingTop());
        linePath.lineTo(getPaddingLeft() + animationInset, getHeight() - getPaddingBottom());
        linePath.moveTo(getWidth() - getPaddingRight() - animationInset, getPaddingTop());
        linePath.lineTo(getWidth() - getPaddingRight() - animationInset, getHeight() - getPaddingBottom());
        canvas.drawPath(linePath, linePaint);
        canvas.drawCircle(circleX, getHeight() / 2, radius, circlePaint);
    }
}

From source file:org.androfarsh.widget.DragGridLayout.java

@Override
protected void dispatchDraw(Canvas canvas) {
    if (mDebugMode) {
        mPaint.setStyle(Style.FILL_AND_STROKE);
        final Path path = new Path();

        path.reset();//  w  w w . j  a  v a 2s .  c o m
        mCellsRegion.getBoundaryPath(path);
        path.close();
        mPaint.setColor(0x660000cc);
        canvas.drawPath(path, mPaint);

        path.reset();
        mFreeCellsRegion.getBoundaryPath(path);
        path.close();
        mPaint.setColor(0x66cc0000);
        canvas.drawPath(path, mPaint);
    }

    if (mRootView == null) {
        drawCellGrid(canvas);
    }
    super.dispatchDraw(canvas);
}

From source file:com.mukesh.OtpView.java

private void drawOtpLine(Canvas canvas, int i) {
    if (getText() != null && hideLineWhenFilled && i < getText().length()) {
        return;//from  ww w .j av  a 2 s. c o  m
    }
    boolean drawLeft;
    boolean drawRight;
    drawLeft = drawRight = true;
    if (otpViewItemSpacing == 0 && otpViewItemCount > 1) {
        if (i == 0) {
            drawRight = false;
        } else if (i == otpViewItemCount - 1) {
            drawLeft = false;
        } else {
            drawLeft = drawRight = false;
        }
    }
    paint.setStyle(Paint.Style.FILL);
    paint.setStrokeWidth(((float) lineWidth) / 10);
    float halfLineWidth = ((float) lineWidth) / 2;
    itemLineRect.set(itemBorderRect.left - halfLineWidth, itemBorderRect.bottom - halfLineWidth,
            itemBorderRect.right + halfLineWidth, itemBorderRect.bottom + halfLineWidth);

    updateRoundRectPath(itemLineRect, otpViewItemRadius, otpViewItemRadius, drawLeft, drawRight);
    canvas.drawPath(path, paint);
}

From source file:com.heinrichreimersoftware.materialintro.view.InkPageIndicator.java

private void drawUnselected(Canvas canvas) {

    combinedUnselectedPath.rewind();/* w  w  w  .j av a 2  s  .  co  m*/

    // draw any settled, revealing or joining dots
    for (int page = 0; page < pageCount; page++) {
        int nextXIndex = page == pageCount - 1 ? page : page + 1;
        Path unselectedPath = getUnselectedPath(page, dotCenterX[page], dotCenterX[nextXIndex],
                page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page], dotRevealFractions[page]);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            combinedUnselectedPath.op(unselectedPath, Path.Op.UNION);
        } else {
            combinedUnselectedPath.addPath(unselectedPath);
        }
    }
    // draw any retreating joins
    if (retreatingJoinX1 != INVALID_FRACTION) {
        Path retreatingJoinPath = getRetreatingJoinPath();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            combinedUnselectedPath.op(retreatingJoinPath, Path.Op.UNION);
        } else {
            combinedUnselectedPath.addPath(retreatingJoinPath);
        }
    }
    canvas.drawPath(combinedUnselectedPath, unselectedPaint);
}