Commits

Wolfram Rittmeyer  committed 40dd9d7

Added a strokeWidth to lines. Circles for points adapt as well.

  • Participants
  • Parent commits c42b8a3

Comments (0)

Files changed (2)

File HoloGraphLibrary/src/com/echo/holographlibrary/Line.java

 	private ArrayList<LinePoint> points = new ArrayList<LinePoint>();
 	private int color;
 	private boolean showPoints = true;
-	
-	
+	// 6 has been the default prior to the addition of custom stroke widths
+	private int strokeWidth = 6;
+	// since this is a new addition, it has to default to false to be backwards compatible
+	private boolean isUsingDips = false;
+
+
+	public boolean isUsingDips() {
+		return isUsingDips;
+	}
+	public void setUsingDips(boolean treatSizesAsDips) {
+		this.isUsingDips = treatSizesAsDips;
+	}
+	public int getStrokeWidth() {
+		return strokeWidth;
+	}
+	public void setStrokeWidth(int strokeWidth) {
+		if (strokeWidth < 0) {
+			throw new IllegalArgumentException("strokeWidth must not be less than zero");
+		}
+		this.strokeWidth = strokeWidth;
+	}
 	public int getColor() {
 		return color;
 	}

File HoloGraphLibrary/src/com/echo/holographlibrary/LineGraph.java

 import android.graphics.PorterDuffXfermode;
 import android.graphics.Region;
 import android.util.AttributeSet;
+import android.util.TypedValue;
 import android.view.MotionEvent;
 import android.view.View;
 
 				float lastYPixels = 0, newXPixels = 0;
 				
 				paint.setColor(line.getColor());
-				paint.setStrokeWidth(6);
+				paint.setStrokeWidth(getStrokeWidth(line));
 				
 				for (LinePoint p : line.getPoints()){
 					float yPercent = (p.getY()-minY)/(maxY - minY);
 			for (Line line : lines){
 
 				paint.setColor(line.getColor());
-				paint.setStrokeWidth(6);
+				paint.setStrokeWidth(getStrokeWidth(line));
 				paint.setStrokeCap(Paint.Cap.ROUND);
 				
 				if (line.isShowingPoints()){
 						float xPercent = (p.getX()-minX)/(maxX - minX);
 						float xPixels = sidePadding + (xPercent*usableWidth);
 						float yPixels = getHeight() - bottomPadding - (usableHeight*yPercent);
-						
+
+						int outerRadius;
+						if (line.isUsingDips()) {
+							outerRadius = getPixelForDip(line.getStrokeWidth() + 4);
+						}
+						else {
+							outerRadius = line.getStrokeWidth() + 4;
+						}
+						int innerRadius = outerRadius / 2;
+
 						paint.setColor(Color.GRAY);
-						canvas.drawCircle(xPixels, yPixels, 10, paint);
+						canvas.drawCircle(xPixels, yPixels, outerRadius, paint);
 						paint.setColor(Color.WHITE);
-						canvas.drawCircle(xPixels, yPixels, 5, paint);
+						canvas.drawCircle(xPixels, yPixels, innerRadius, paint);
 						
 						Path path2 = new Path();
 						path2.addCircle(xPixels, yPixels, 30, Direction.CW);
 		
 		
 	}
-	
+
+	private int getStrokeWidth(Line line) {
+		int strokeWidth;
+		if (line.isUsingDips()) {
+			strokeWidth = getPixelForDip(line.getStrokeWidth());
+		}
+		else {
+			strokeWidth = line.getStrokeWidth();
+		}
+		return strokeWidth;
+	}
+
+	private int getPixelForDip(int dipValue) {
+		return (int) TypedValue.applyDimension(
+				TypedValue.COMPLEX_UNIT_DIP,
+				dipValue,
+				getResources().getDisplayMetrics());
+	}
+
 	@Override
 	public boolean onTouchEvent(MotionEvent event) {