Example usage for android.graphics Canvas drawLines

List of usage examples for android.graphics Canvas drawLines

Introduction

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

Prototype

public void drawLines(@Size(multiple = 4) @NonNull float[] pts, @NonNull Paint paint) 

Source Link

Usage

From source file:Main.java

/**
 * Render a path by actually drawing line segments instead. When using a real {@link Path}, then it is first painted
 * into a temporary bitmap by the CPU, before being rendered by the GPU. That simply fails for large paths,
 * therefore we use a synthesis from line segments, since lines are drawn entirely by the GPU.
 *///from  www. j  a  va 2s .  c  o  m
public static void drawPath(final ArrayList<Point> pixelPoints, final Canvas canvas, final Paint paint) {
    final float[] pointData = new float[(pixelPoints.size() - 1) * 4];

    for (int i = 1; i < pixelPoints.size(); i++) {
        final Point last = pixelPoints.get(i - 1);
        final Point current = pixelPoints.get(i);

        final int index = (i - 1) * 4;
        // start point
        pointData[index] = last.x;
        pointData[index + 1] = last.y;

        // end point
        pointData[index + 2] = current.x;
        pointData[index + 3] = current.y;
    }

    canvas.drawLines(pointData, paint);
}

From source file:com.hippo.ehviewer.widget.GalleryGuideView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawColor(mBgColor);/*  www  . j a va  2 s  .c  o  m*/
    if (0 == mStep) {
        canvas.drawLines(mPoints, mPaint);
    }
}

From source file:Main.java

public static Bitmap getColorPreviewBitmap(final Context context, final int color, final boolean border) {
    if (context == null)
        return null;
    final float density = context.getResources().getDisplayMetrics().density;
    final int width = (int) (32 * density), height = (int) (32 * density);

    final Bitmap bm = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    final Canvas canvas = new Canvas(bm);

    final int rectangleSize = (int) (density * 5);
    final int numRectanglesHorizontal = (int) Math.ceil(width / rectangleSize);
    final int numRectanglesVertical = (int) Math.ceil(height / rectangleSize);
    final Rect r = new Rect();
    boolean verticalStartWhite = true;
    for (int i = 0; i <= numRectanglesVertical; i++) {

        boolean isWhite = verticalStartWhite;
        for (int j = 0; j <= numRectanglesHorizontal; j++) {

            r.top = i * rectangleSize;// w w w .  j a v  a 2 s .c o m
            r.left = j * rectangleSize;
            r.bottom = r.top + rectangleSize;
            r.right = r.left + rectangleSize;
            final Paint paint = new Paint();
            paint.setColor(isWhite ? Color.WHITE : Color.GRAY);

            canvas.drawRect(r, paint);

            isWhite = !isWhite;
        }

        verticalStartWhite = !verticalStartWhite;

    }
    canvas.drawColor(color);
    if (border) {
        final Paint paint = new Paint();
        paint.setColor(Color.WHITE);
        paint.setStrokeWidth(1f * density);
        final float[] points = new float[] { 0, 0, width, 0, 0, 0, 0, height, width, 0, width, height, 0,
                height, width, height };
        canvas.drawLines(points, paint);
    }
    return bm;
}

From source file:Main.java

public static Bitmap getColorPreviewBitmap(final Context context, final int color, final boolean border) {
    if (context == null)
        return null;
    final float density = context.getResources().getDisplayMetrics().density;
    final int width = (int) (32 * density), height = (int) (32 * density);

    final Bitmap bm = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    final Canvas canvas = new Canvas(bm);

    final int rectrangleSize = (int) (density * 5);
    final int numRectanglesHorizontal = (int) Math.ceil(width / rectrangleSize);
    final int numRectanglesVertical = (int) Math.ceil(height / rectrangleSize);
    final Rect r = new Rect();
    boolean verticalStartWhite = true;
    for (int i = 0; i <= numRectanglesVertical; i++) {

        boolean isWhite = verticalStartWhite;
        for (int j = 0; j <= numRectanglesHorizontal; j++) {

            r.top = i * rectrangleSize;//ww  w .  ja v a  2s  .c  o  m
            r.left = j * rectrangleSize;
            r.bottom = r.top + rectrangleSize;
            r.right = r.left + rectrangleSize;
            final Paint paint = new Paint();
            paint.setColor(isWhite ? Color.WHITE : Color.GRAY);

            canvas.drawRect(r, paint);

            isWhite = !isWhite;
        }

        verticalStartWhite = !verticalStartWhite;

    }
    canvas.drawColor(color);
    if (border) {
        final Paint paint = new Paint();
        paint.setColor(Color.WHITE);
        paint.setStrokeWidth(1f * density);
        final float[] points = new float[] { 0, 0, width, 0, 0, 0, 0, height, width, 0, width, height, 0,
                height, width, height };
        canvas.drawLines(points, paint);
    }
    return bm;
}

From source file:de.chrthms.chess.board.markers.SourceFieldView.java

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

    Paint paint = new Paint();
    paint.setColor(ContextCompat.getColor(getContext(), R.color.basicFieldPossibleColor));
    paint.setStrokeWidth((getWidth() * 1f) / 100 * STROKE_WIDTH);

    float[] points = { getLeft(), getTop(), getRight(), getTop(), getRight(), getTop(), getRight(), getBottom(),
            getRight(), getBottom(), getLeft(), getBottom(), getLeft(), getBottom(), getLeft(), getTop() };

    canvas.drawLines(points, paint);

}

From source file:com.jjoe64.graphview.series.LineGraphSeries.java

/**
 * just a wrapper to draw lines on canvas
 *
 * @param canvas/*ww w .j ava  2  s .  c o m*/
 * @param pts
 * @param paint
 */
private void renderLine(Canvas canvas, float[] pts, Paint paint) {
    canvas.drawLines(pts, paint);
}

From source file:de.chrthms.chess.board.markers.PossibleFieldView.java

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

    Paint paint = new Paint();

    paint.setColor(ContextCompat.getColor(getContext(), R.color.basicFieldPossibleColor));
    paint.setStrokeWidth((getWidth() * 1f) / 100 * STROKE_WIDTH);

    // transform int (width) to float!
    float space = (getWidth() * 1f) / 100 * MARKER_SPACE;
    float size = (getWidth() * 1f) / 100 * MARKER_SIZE;

    Log.i("MARKER POINTS", "space = " + space + " size = " + size + " width = " + getWidth());

    float[] points = { getLeft() + space, getTop() + space, getLeft() + space + size, getTop() + space,
            getLeft() + space, getTop() + space, getLeft() + space, getTop() + space + size,

            getRight() - space - size, getTop() + space, getRight() - space, getTop() + space,
            getRight() - space, getTop() + space, getRight() - space, getTop() + space + size,

            getLeft() + space, getBottom() - space, getLeft() + space + size, getBottom() - space,
            getLeft() + space, getBottom() - space, getLeft() + space, getBottom() - space - size,

            getRight() - space - size, getBottom() - space, getRight() - space, getBottom() - space,
            getRight() - space, getBottom() - space, getRight() - space, getBottom() - space - size,

    };/*  w w  w .j  ava 2 s  .c  o m*/

    Log.i("MARKER POINTS", "points array = " + Arrays.toString(points));

    canvas.drawLines(points, paint);

}

From source file:cn.androidy.androiddevelopmentpatterns.interactivechart.InteractiveLineGraphView.java

/**
 * Draws the currently visible portion of the data series defined by {@link #fun(float)} to the
 * canvas. This method does not clip its drawing, so users should call {@link Canvas#clipRect
 * before calling this method./*from ww w .  ja v  a  2 s  . com*/
 */
private void drawDataSeriesUnclipped(Canvas canvas) {
    mSeriesLinesBuffer[0] = mContentRect.left;
    mSeriesLinesBuffer[1] = getDrawY(fun(mCurrentViewport.left));
    mSeriesLinesBuffer[2] = mSeriesLinesBuffer[0];
    mSeriesLinesBuffer[3] = mSeriesLinesBuffer[1];
    float x;
    for (int i = 1; i <= DRAW_STEPS; i++) {
        mSeriesLinesBuffer[i * 4 + 0] = mSeriesLinesBuffer[(i - 1) * 4 + 2];
        mSeriesLinesBuffer[i * 4 + 1] = mSeriesLinesBuffer[(i - 1) * 4 + 3];

        x = (mCurrentViewport.left + (mCurrentViewport.width() / DRAW_STEPS * i));
        mSeriesLinesBuffer[i * 4 + 2] = getDrawX(x);
        mSeriesLinesBuffer[i * 4 + 3] = getDrawY(fun(x));
    }
    canvas.drawLines(mSeriesLinesBuffer, mDataPaint);
}

From source file:com.yanzhenjie.durban.view.OverlayView.java

/**
 * This method draws crop bounds (empty rectangle)
 * and crop guidelines (vertical and horizontal lines inside the crop bounds) if needed.
 *
 * @param canvas - valid canvas object//from w  w  w  .j a v  a2  s . c o  m
 */
protected void drawCropGrid(@NonNull Canvas canvas) {
    if (mShowCropGrid) {
        if (mGridPoints == null && !mCropViewRect.isEmpty()) {

            mGridPoints = new float[(mCropGridRowCount) * 4 + (mCropGridColumnCount) * 4];

            int index = 0;
            for (int i = 0; i < mCropGridRowCount; i++) {
                mGridPoints[index++] = mCropViewRect.left;
                mGridPoints[index++] = (mCropViewRect.height()
                        * (((float) i + 1.0f) / (float) (mCropGridRowCount + 1))) + mCropViewRect.top;
                mGridPoints[index++] = mCropViewRect.right;
                mGridPoints[index++] = (mCropViewRect.height()
                        * (((float) i + 1.0f) / (float) (mCropGridRowCount + 1))) + mCropViewRect.top;
            }

            for (int i = 0; i < mCropGridColumnCount; i++) {
                mGridPoints[index++] = (mCropViewRect.width()
                        * (((float) i + 1.0f) / (float) (mCropGridColumnCount + 1))) + mCropViewRect.left;
                mGridPoints[index++] = mCropViewRect.top;
                mGridPoints[index++] = (mCropViewRect.width()
                        * (((float) i + 1.0f) / (float) (mCropGridColumnCount + 1))) + mCropViewRect.left;
                mGridPoints[index++] = mCropViewRect.bottom;
            }
        }

        if (mGridPoints != null)
            canvas.drawLines(mGridPoints, mCropGridPaint);
    }

    if (mShowCropFrame)
        canvas.drawRect(mCropViewRect, mCropFramePaint);

    if (mFreestyleCropMode != FREESTYLE_CROP_MODE_DISABLE) {
        canvas.save();

        mTempRect.set(mCropViewRect);
        mTempRect.inset(mCropRectCornerTouchAreaLineLength, -mCropRectCornerTouchAreaLineLength);
        canvas.clipRect(mTempRect, Region.Op.DIFFERENCE);

        mTempRect.set(mCropViewRect);
        mTempRect.inset(-mCropRectCornerTouchAreaLineLength, mCropRectCornerTouchAreaLineLength);
        canvas.clipRect(mTempRect, Region.Op.DIFFERENCE);

        canvas.drawRect(mCropViewRect, mCropFrameCornersPaint);

        canvas.restore();
    }
}

From source file:com.futureinst.widget.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//from  ww  w  . ja  va 2  s.  com
    }
    screenWidth = getWidth();

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    if (currentTab == null)
        return;
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }
    //        canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
    float[] pts = new float[] { 0, height - underlineHeight, lineLeft + (lineRight - lineLeft) / 3,
            height - underlineHeight, lineLeft + (lineRight - lineLeft) / 3, height - underlineHeight,
            lineLeft + (lineRight - lineLeft) / 2, height - indicatorHeight / 2,
            lineLeft + (lineRight - lineLeft) / 2, height - indicatorHeight / 2,
            lineLeft + 2 * (lineRight - lineLeft) / 3, height - underlineHeight,
            lineLeft + 2 * (lineRight - lineLeft) / 3, height - underlineHeight, tabsContainer.getWidth(),
            height - underlineHeight };
    rectPaint.setColor(underlineColor);
    canvas.drawLines(pts, rectPaint);

    // draw underline

    //        rectPaint.setColor(underlineColor);
    //        canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider

    //      dividerPaint.setColor(dividerColor);
    //      for (int i = 0; i < tabCount - 1; i++) {
    //         View tab = tabsContainer.getChildAt(i);
    //         canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    //      }
}