Example usage for android.graphics Canvas drawLine

List of usage examples for android.graphics Canvas drawLine

Introduction

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

Prototype

public void drawLine(float startX, float startY, float stopX, float stopY, @NonNull Paint paint) 

Source Link

Document

Draw a line segment with the specified start and stop x,y coordinates, using the specified paint.

Usage

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

@SuppressWarnings("unused")
private Bitmap RenderLineGraph() {
    Bitmap emptyBmap = Bitmap.createBitmap(290, 150, Config.ARGB_8888);

    int width = emptyBmap.getWidth();
    int height = emptyBmap.getHeight();
    Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(charty);
    final int color = 0xff0B0B61;
    final Paint paint = new Paint();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);/*from w w w.j  a  v  a2  s .  co m*/

    //if(warningEvents > )
    canvas.drawText("100", 0, 10, paint);

    //y
    canvas.drawLine(25, 0, 25, 289, paint);
    //x
    canvas.drawLine(25, 149, 289, 149, paint);

    int CritArray[] = { 5, 4, 6, 10, 10, 6, 4, 4 };
    int curX = 25;

    int divisor = 148 / 10;
    paint.setColor(Color.RED);
    int curY = 148 - (CritArray[0] * divisor);

    for (int a : CritArray) {
        canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint);
        curX += 32;
        curY = 148 - (a * divisor);
    }

    int ErrArray[] = { 1, 2, 2, 2, 4, 2, 1, 0 };
    curX = 25;

    paint.setColor(Color.rgb(255, 102, 0));
    curY = 148 - (ErrArray[0] * divisor);

    for (int a : ErrArray) {
        canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint);
        curX += 32;
        curY = 148 - (a * divisor);
    }

    int WarnArray[] = { 0, 2, 4, 8, 10, 4, 2, 2 };
    curX = 25;

    paint.setColor(Color.YELLOW);
    curY = 148 - (WarnArray[0] * divisor);

    Path myPath = new Path();

    for (int a : WarnArray) {
        canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint);
        curX += 32;
        curY = 148 - (a * divisor);
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    charty.compress(CompressFormat.PNG, 50, out);

    return BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size());
}

From source file:com.umeng.comm.ui.imagepicker.widgets.ViewPagerIndicator.java

/**
 * //from   w  ww . j a v a  2  s . c o  m
 */
@Override
protected void dispatchDraw(Canvas canvas) {
    canvas.save();
    // ?
    canvas.translate(mInitTranslationX + mTranslationX, getHeight() + 5);
    canvas.drawPath(mPath, mPaint);
    canvas.restore();

    // tab
    canvas.drawLine(mTranslationX, getHeight() - 3, mTranslationX + mHalfScreenWidth, getHeight() - 3,
            mLinePaint);
    // 
    canvas.drawLine(0, getHeight() - 1, 2 * mHalfScreenWidth, getHeight() - 1, mDividerLinePaint);
    super.dispatchDraw(canvas);
}

From source file:com.crs4.roodin.moduletester.CustomView.java

/**
 * @param canvas/*  w w  w  .  j a  v a  2s .  c  o m*/
 */
private void drawRadar(Canvas canvas) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.RED);
    paint.setAlpha(100);

    float rotation = currentRotation; //gRotationZ_deg + initialMapRotation;

    for (int i = -35; i < 35; i = i + 2) {
        float arrowX1 = (float) (translateX - Math.sin(Math.toRadians(rotation + i)) * 45);
        float arrowY1 = (float) (translateY - Math.cos(Math.toRadians(rotation + i)) * 45);
        canvas.drawLine(translateX, translateY, arrowX1, arrowY1, paint);

    }

    paint.setAlpha(100);
    paint.setColor(Color.RED);
    canvas.drawCircle(translateX, translateY, 7, paint);

    paint.setColor(Color.YELLOW);
    canvas.drawCircle(translateX, translateY, 6, paint);

    paint.setColor(Color.RED);
    canvas.drawCircle(translateX, translateY, 1, paint);
}

From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java

@Override
public void draw(Canvas canvas) {
    Rect bounds = getBounds();/*from w ww  . j av  a2s.  co  m*/
    if (mIsRtl) {
        canvas.save();
        canvas.scale(-1, 1, bounds.centerX(), bounds.centerY());
    }
    float pct = drawArc(canvas, bounds);

    if (pct < 0) {
        pct = 0;
    } else if (pct > 1) {
        pct = 1;
    }

    int y = bounds.bottom - mBottomOffset;
    canvas.drawLine(bounds.left + mLeftOffset / 2, y, bounds.right - mRightOffset / 2, y, mLinePaint);

    drawSun(canvas, pct);

    if (mIsRtl) {
        canvas.restore();
    }

}

From source file:com.googlecode.eyesfree.example.bargraph.BarGraphView.java

/**
 * Draws the Y-axis.//from   ww w . j a va  2  s .c  om
 *
 * @param c The canvas on which to draw.
 */
private void drawAxisY(Canvas c) {
    mPaint.reset();
    mPaint.setColor(mAxisColor);

    final float[] x = mScaleX.transform(0, (mSize + 1));
    final float y = mScaleY.transform(0);

    c.drawLine(x[0], y, x[1], y, mPaint);
}

From source file:com.mn.tiger.widget.viewpager.TGPagerSlidingTabStrip.java

/**
 * //from   www  . j  a  v  a  2  s .  c om
 * @param canvas
 * @param dividerPaint
 */
protected void onDrawDivider(Canvas canvas, Paint dividerPaint) {
    // 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(), getHeight() - dividerPadding,
                dividerPaint);
    }
}

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  w  ww  .  j  a  v a  2s  .co  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:com.mad.splitlist.util.DividerItemDecoration.java

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    final int offset = (int) (mPaint.getStrokeWidth() / DIVIDE_OFFSET);

    for (int i = 0; i < parent.getChildCount(); i++) {
        final View view = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();

        final int position = params.getViewAdapterPosition();

        // Draw separator using paint.
        if (position < state.getItemCount()) {
            // apply alpha to support animations
            mPaint.setAlpha((int) (view.getAlpha() * mAlpha));

            float positionY = view.getBottom() + offset + view.getTranslationY();
            // do the drawing
            c.drawLine(view.getLeft() + view.getTranslationX(), positionY,
                    view.getRight() + view.getTranslationX(), positionY, mPaint);
        }/*  www . j  av  a2  s .  c om*/
    }
}

From source file:org.telegram.ui.Cells.ProfileSearchCell.java

@Override
protected void onDraw(Canvas canvas) {
    if (user == null && chat == null && encryptedChat == null) {
        return;//w w w  .  j a v  a 2  s .  co  m
    }

    if (useSeparator) {
        if (LocaleController.isRTL) {
            canvas.drawLine(0, getMeasuredHeight() - 1,
                    getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline),
                    getMeasuredHeight() - 1, linePaint);
        } else {
            canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1,
                    getMeasuredWidth(), getMeasuredHeight() - 1, linePaint);
        }
    }

    if (drawAlpha != 1) {
        canvas.saveLayerAlpha(0, 0, canvas.getWidth(), canvas.getHeight(), (int) (255 * drawAlpha),
                Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
    }

    if (drawNameLock) {
        setDrawableBounds(lockDrawable, nameLockLeft, nameLockTop);
        lockDrawable.draw(canvas);
    } else if (drawNameGroup) {
        setDrawableBounds(groupDrawable, nameLockLeft, nameLockTop);
        groupDrawable.draw(canvas);
    } else if (drawNameBroadcast) {
        setDrawableBounds(broadcastDrawable, nameLockLeft, nameLockTop);
        broadcastDrawable.draw(canvas);
    } else if (drawNameBot) {
        setDrawableBounds(botDrawable, nameLockLeft, nameLockTop);
        botDrawable.draw(canvas);
    }

    if (nameLayout != null) {
        canvas.save();
        canvas.translate(nameLeft, nameTop);
        nameLayout.draw(canvas);
        canvas.restore();
        if (drawCheck) {
            if (LocaleController.isRTL) {
                setDrawableBounds(checkDrawable,
                        nameLeft - AndroidUtilities.dp(4) - checkDrawable.getIntrinsicWidth(), nameLockTop);
            } else {
                setDrawableBounds(checkDrawable,
                        nameLeft + (int) nameLayout.getLineWidth(0) + AndroidUtilities.dp(4), nameLockTop);
            }
            checkDrawable.draw(canvas);
        }
    }

    if (onlineLayout != null) {
        canvas.save();
        canvas.translate(onlineLeft, AndroidUtilities.dp(40));
        onlineLayout.draw(canvas);
        canvas.restore();
    }

    if (countLayout != null) {
        if (MessagesController.getInstance().isDialogMuted(dialog_id)) {
            setDrawableBounds(countDrawableGrey, countLeft - AndroidUtilities.dp(5.5f), countTop,
                    countWidth + AndroidUtilities.dp(11), countDrawableGrey.getIntrinsicHeight());
            countDrawableGrey.draw(canvas);
        } else {
            setDrawableBounds(countDrawable, countLeft - AndroidUtilities.dp(5.5f), countTop,
                    countWidth + AndroidUtilities.dp(11), countDrawable.getIntrinsicHeight());
            countDrawable.draw(canvas);
        }
        canvas.save();
        canvas.translate(countLeft, countTop + AndroidUtilities.dp(4));
        countLayout.draw(canvas);
        canvas.restore();
    }

    avatarImage.draw(canvas);
}