Yeah, I know… Google suggests taking questions about Android app development to Stack Overflow, but time and time again I’ve gotten better results here on the Dope.
I’m wanting to programatically draw a graph, and I’m having a bit of trouble even getting as far as the X axis. More specifically, I’m having trouble passing a color to the line I’m drawing.
For drawing lines, I’ve created a class called DrawnLine. Here’s the constructor:
public DrawnLine(Context context, int offsetX, int offsetY, int width, int height, int color) {
super(context);
mDrawable=new ShapeDrawable(new RectShape());
mDrawable.getPaint().setColor(color);
mDrawable.setBounds(offsetX, offsetY, width, height);
}
In addition to the context argument, it takes five integer arguments: 2 for position, 2 for size, and 1 for color. Creating an instance of DrawnLine gets me expected results if I pass a hard-coded color, like this:
DrawnLine mLine=new DrawnLine(this, 0, 0, 5, 500, 0xffCC0000);
But if I refer to a colors.xml, like this
DrawnLine mLine=new DrawnLine(this, 0, 0, 5, 500, R.color.axes);
I get nothing. It seems I need to do another step to make #ffCC0000 something that can be passed to DrawnLine (e.g. 0xffCC0000), but what is it?
Also puzzling: the second argument, setting the x offset of the line to any number greater than 5 causes the line to not be visible. Seems this doesn’t do what I think it does (although the y offset behaves exactly as I’d expect).
I’m new to both android development and Java, so I’m sure what I’m overlooking is really basic…
ETA: When I try tracing the value of R.color.axes as a decimal integer (at least, I think that’s what I’m getting), the xml version gives me 2130968576; hard coded I get -3407872. Yes, a negative number.