Back to project page AndroidGraph.
The source code is released under:
MIT License
If you think the Android project AndroidGraph listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.nimble.android_graph.Graph; /* ww w . j a v a 2s . c o m*/ import android.content.Context; import android.graphics.*; import java.util.ArrayList; import com.nimble.android_graph.Graph_Base.GraphView; /** * Created by Michael Leith on 22/07/2014. */ public class CurveGraph extends GraphView { ArrayList<Path> paths; // Terribly implemented by google. Grr. Why can't I access only a segment (nicely) of it?!?! ArrayList<Integer> pathColour; ArrayList<com.nimble.android_graph.Graph_Base.Point> previousPoint; int startPoint = 0; CurveGraph(Context context) { super(context); paths = new ArrayList<Path>(); previousPoint = new ArrayList<com.nimble.android_graph.Graph_Base.Point>(); pathColour = new ArrayList<Integer>(); } public int newPath(int colour) { Path path = new Path(); // path.moveTo(start.x, start.y); pathColour.add(colour); paths.add(path); //previousPoint.add(start); return (paths.size() - 1); } public void addPoint(com.nimble.android_graph.Graph_Base.Point point, int path) { com.nimble.android_graph.Graph_Base.Point point1; if(point.x > graphWidth.y) //simplified. Not correct. startPoint++; if(previousPoint.size() > 0) { point1 = previousPoint.get(path); paths.get(path).quadTo(point1.x, point1.y, point.x, point.y); previousPoint.set(path, point); } else { paths.get(path).moveTo(point.x, point.y); previousPoint.add(path, point); } } @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); paint.setStyle(Paint.Style.STROKE); paint.setStrokeCap(Paint.Cap.ROUND); paint.setStrokeWidth(3.0f); paint.setAntiAlias(true); for(int i = 0; i < paths.size(); i++) { paint.setColor(pathColour.get(i)); canvas.drawPath(paths.get(i), paint); } invalidate(); } }