Back to project page unknown-pleasures.
The source code is released under:
Creative Commons Attribution NonCommercial NoDerivs (CC-NC-ND) THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTE...
If you think the Android project unknown-pleasures listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * SimpleLineRenderer.java/*w w w . j a va 2 s. c o m*/ * Author: marek.brodziak@gmail.com * Created: May 6, 2014 * Copyright 2014 by miniti */ package pl.miniti.android.pleasures.line; import android.graphics.Canvas; import android.graphics.CornerPathEffect; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; /** * Implementation of the {@see LineRenderer} for translating the path to the * outpuot {@see Rect} on the canvas with basic coloring. * * At the moment this is the only available implementation. */ public class SimpleLineRenderer implements LineRenderer { /** * Normal line width */ private static final float NORMAL = 1f; /** * Stronger line width */ private static final float STRONG = 2f; /** * Paint object for the path foreground */ private Paint foregroundPaint; /** * Paint object for the background */ private Paint backgroundPaint; /** * Default no-arg constructor */ public SimpleLineRenderer() { foregroundPaint = new Paint(); foregroundPaint.setStyle(Paint.Style.STROKE); foregroundPaint.setDither(true); foregroundPaint.setStyle(Paint.Style.STROKE); foregroundPaint.setStrokeJoin(Paint.Join.ROUND); foregroundPaint.setStrokeCap(Paint.Cap.ROUND); foregroundPaint.setPathEffect(new CornerPathEffect(10)); foregroundPaint.setAntiAlias(true); foregroundPaint.setStrokeWidth(STRONG); backgroundPaint = new Paint(); backgroundPaint.setDither(true); backgroundPaint.setStyle(Paint.Style.FILL); backgroundPaint.setStrokeJoin(Paint.Join.ROUND); backgroundPaint.setStrokeCap(Paint.Cap.ROUND); backgroundPaint.setPathEffect(new CornerPathEffect(10)); backgroundPaint.setAntiAlias(true); } /* * (non-Javadoc) * * @see pl.miniti.android.pleasures.line.LineRenderer#setStrong(boolean) */ @Override public void setStrong(boolean strong) { foregroundPaint.setStrokeWidth(strong ? STRONG : NORMAL); } /* * (non-Javadoc) * * @see * pl.miniti.android.pleasures.line.LineRenderer#render(android.graphics * .Canvas, android.graphics.Rect, android.graphics.Path, int, int, int, * int) */ @Override public void render(final Canvas canvas, Rect rectangle, Path line, int index, int of, int fColor, int bColor) { foregroundPaint.setColor(fColor); backgroundPaint.setColor(bColor); final Path translated = new Path(); final float diff_y = index * rectangle.height() / of; // tranformation matrix final Matrix m = new Matrix(); m.setValues(new float[]{rectangle.width(), 0f, rectangle.left, 0f, rectangle.height(), rectangle.top + diff_y, 0f, 0f, 1f}); line.transform(m, translated); final Path copy = new Path(translated); final float bottom = rectangle.top + diff_y + .1f; translated.lineTo(rectangle.right, bottom); translated.lineTo(rectangle.left, bottom); translated.close(); canvas.drawPath(translated, backgroundPaint); canvas.drawPath(copy, foregroundPaint); canvas.clipRect(new Rect(rectangle.left, 0, rectangle.right, rectangle.bottom)); } }