I am trying to develop an android application (targeting versions 2.1/2.2) which requires the tracking of Path x,y coordinate points and am having a hard time. The basics of the app are similar to FingerPaint, except first a separate thread draws some lines using a Path drawable onto a canvas, then the user tries to draw over those lines, covering them completely with a different Paint and Path object. The user will have a larger Paint brush than the computer. The first auto drawn lines use a separate thread similar to LunarLander example app. Since the lines are not just straight lines I'm struggling finding an approach to do the following:
1. Track the auto points draw. I realize I'm providing the basic points but using path.lineTo
and path.arcTo
and path.quadTo
to really figure out all the points.
My ideal method which obviously doesn't exist would be something like
autoPath.getDrawnPoints().coveredBy(userPath.getDrawnPoints()) == true
?
Any help with this would be greatly appreciated, thank you.
-Ben
All I can say is: Path relies on GeneralPath of Java which relies on Path2dFloat.
If I look at the sourcecode it has a packageReadable transient float floatCoords[];
So the only way I see to get the coordinates you pass in back is more a hack than a solution. Anyway, here it is:
public float[] getPointsFromPath(GeneralPath path){
Class<?> clazz = path.getClass();
while(true){
clazz = clazz .getSuperclass();
if (clazz == Path2D.Float.class){
break;
}
}
try {
Field f = clazz.getDeclaredField("floatCoords");
if (f != null){
if (!f.isAccessible()){
f.setAccessible(true);
}
Object o = f.get(path);
if (o != null && o instanceof float[]){
float[] drawnPoints = (float[])o;
Log.d("TAG", drawnPoints);
return drawnPoints;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With