I forgot to mention, there were a couple of things I added. An import to the main class:
Using java Syntax Highlighting
import android.view.MotionEvent;
Parsed in 0.030 seconds, using
GeSHi 1.0.8.4
A return to the onTouch method:
Using java Syntax Highlighting
main.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent e) {
float x = e.getX();
float y = e.getY();
FrameLayout flView = (FrameLayout) v;
flView.addView(new Ball(getParent(), x, y, 25));
return true;
}
});
Parsed in 0.030 seconds, using
GeSHi 1.0.8.4
And, I added an extra circle as a test in the Ball class (for fun and test):
Using java Syntax Highlighting
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class Ball extends View {
private final float x;
private final float y;
private final int r;
private final Paint mRed = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint mBlack = new Paint(Paint.ANTI_ALIAS_FLAG);
public Ball(Context context, float x, float y, int r) {
super(context);
this.x = x;
this.y = y;
this.r = r;
mRed.setColor(Color.RED);
mBlack.setColor(Color.BLACK);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(x, y, r, mRed);
canvas.drawCircle(x, y, r/2, mBlack);
}
}
Parsed in 0.037 seconds, using
GeSHi 1.0.8.4