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; /*from w w w. j a v a2 s . co m*/ import android.graphics.Color; import java.util.ArrayList; import com.nimble.android_graph.Graph_Base.Range2d; import com.nimble.android_graph.Graph_Base.Point; /** * Created by Michael Leith on 18/07/2014. */ public class Line { ArrayList<Point> points; int colour = Color.BLACK; int shadow = Color.DKGRAY; private boolean useShadow; int startPoint = 0, endPoint = 0; boolean incrementStartPoint = true; Range2d widthLimit = new Range2d(); Range2d heightLimit = new Range2d(); Range2d margin = new Range2d(); float distBetweenPoints = 0.5f; public Line() { points = new ArrayList<Point>(); useShadow = false; } public void addPoint(float x, float y) { addPoint( new Point(x, y) ); } public void addPoint(Point point) { if(widthLimit.length <= 0 || heightLimit.length <= 0) return; if(points == null) points = new ArrayList<Point>(); points.add(point); if( outOfBounds(point.x - points.get(startPoint).graphSpaceX )) // Check dimensions have been measured :) FIX incrementStartPoint(); endPoint++; } /** * Add directly beside previous point. * @param y */ public void linearAdd(float y) { if (!points.isEmpty()) { float x = points.get(points.size() - 1).graphSpaceX + distBetweenPoints; addPoint(x, y); } else addPoint(0, y); } public float getNextX() { if(!points.isEmpty()) return points.get(points.size() - 1).graphSpaceX + distBetweenPoints; return 0; } private boolean outOfBounds(float x) //only x-axis for now. { return (x > (widthLimit.length + 20f)); } public void updateWidthLimit(Range2d width, Range2d height, Range2d margin) { widthLimit = width; heightLimit = height; this.margin = margin; } private void incrementStartPoint() { if(incrementStartPoint) startPoint++; } public void modifyStartPoint(int startPointOffset) { int start = startPoint + startPointOffset; if(start < 0 || start >= points.size()) //don't draw line. return; startPoint += startPointOffset; endPoint += startPointOffset > points.size() ? points.size() : startPointOffset ; } public void setIncrementStartPoint(boolean state) { incrementStartPoint = state; } public void setColour(int newColour) { colour = newColour; } public void setShadow(int newShadow) { shadow = newShadow; useShadow = true; } public void setUseShadow(boolean status) { useShadow = status; } public boolean isUseShadow() { return useShadow; } }