Java Code Examples for android.graphics.Paint.getPathEffect()

The following are Jave code examples for showing how to use getPathEffect() of the android.graphics.Paint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: TPlayer   File: BorderShape.java   View Source Code Vote up 4 votes
@SuppressWarnings("SuspiciousNameCombination")
@Override
public void draw(Canvas canvas, Paint paint) {
    if (mBorder == null)
        return;

    float width = getWidth();
    float height = getHeight();

    if (mPathEffect == null) {

        // left
        if (mBorder.left > 0)
            canvas.drawRect(0, 0, mBorder.left, height, paint);

        // top
        if (mBorder.top > 0)
            canvas.drawRect(0, 0, width, mBorder.top, paint);

        // right
        if (mBorder.right > 0)
            canvas.drawRect(width - mBorder.right, 0, width, height, paint);

        // bottom
        if (mBorder.bottom > 0)
            canvas.drawRect(0, height - mBorder.bottom, width, height, paint);

    } else {
        if (paint.getPathEffect() != mPathEffect) {
            paint.setStyle(Paint.Style.STROKE);
            paint.setPathEffect(mPathEffect);
        }

        // left
        if (mBorder.left > 0) {
            paint.setStrokeWidth(mBorder.left);
            initPath(mBorder.left / 2, 0, mBorder.left / 2, height);
            canvas.drawPath(mPath, paint);
        }

        // top
        if (mBorder.top > 0) {
            paint.setStrokeWidth(mBorder.top);
            initPath(0, mBorder.top / 2, width, mBorder.top / 2);
            canvas.drawPath(mPath, paint);
        }

        // right
        if (mBorder.right > 0) {
            paint.setStrokeWidth(mBorder.right);
            initPath(width - mBorder.right / 2, 0, width - mBorder.right / 2, height);
            canvas.drawPath(mPath, paint);
        }

        // bottom
        if (mBorder.bottom > 0) {
            paint.setStrokeWidth(mBorder.bottom);
            initPath(0, height - mBorder.bottom / 2, width, height - mBorder.bottom / 2);
            canvas.drawPath(mPath, paint);
        }
    }
}
 
Example 2
Project: SmartMath   File: FlatChart.java   View Source Code Vote up 4 votes
public void drawLine(Canvas canvas, Position3D p3PrevPoint, Position3D p3NextPoint, Paint paint, LineStyle lineStyle)	{
	if (lineStyle.menumLinePattern == LINEPATTERN.LINEPATTERN_NON)	{
		return;
	}
	int nOriginalColor = paint.getColor();
	Style styleOriginal = paint.getStyle();
	float fOriginalStrokeWidth = paint.getStrokeWidth();
	PathEffect pathEffectOriginal = paint.getPathEffect();

	if (lineStyle.mclr != null)	{
		paint.setColor(lineStyle.mclr.getARGB());
	}
	paint.setStyle(Style.STROKE);
	paint.setStrokeWidth((float)lineStyle.mdLineWidth);
	switch (lineStyle.menumLinePattern)	{
	case LINEPATTERN_DASH:
	{
		paint.setPathEffect(new DashPathEffect(new float[]{(float)mdVerySmallSize, (float)mdTinySize}, 0));
		break;
	}
	case LINEPATTERN_DOT:
	{
		paint.setPathEffect(new DashPathEffect(new float[]{(float)mdVeryTinySize, (float)mdTinySize}, 0));
		break;
	}
	case LINEPATTERN_DASH_DOT:
	{
		paint.setPathEffect(new DashPathEffect(new float[]{(float)mdVerySmallSize, (float)mdTinySize, (float)mdVeryTinySize, (float)mdTinySize}, 0));
		break;
	}
	/* case LINEPATTERN_NON:	// need not to consider LINEPATTERN_NON
	{
		paint.setPathEffect(new DashPathEffect(new float[]{0, (float)mdMediumSize}, 0));
		break;
	} */
	default:	// solid
		paint.setPathEffect(new PathEffect());
	}
	
	float fX0 = (float)p3PrevPoint.getX(), fY0 = (float)p3PrevPoint.getY(),
			fX1 = (float)p3NextPoint.getX(), fY1 = (float)p3NextPoint.getY();
	canvas.drawLine(fX0, fY0, fX1, fY1, paint);
	
	paint.setColor(nOriginalColor);
	paint.setStyle(styleOriginal);
	paint.setStrokeWidth(fOriginalStrokeWidth);
	paint.setPathEffect(pathEffectOriginal);
}